diff --git a/src/main/java/main/giveaway/Giveaway.java b/src/main/java/main/giveaway/Giveaway.java index 15c1a3e..860ba10 100644 --- a/src/main/java/main/giveaway/Giveaway.java +++ b/src/main/java/main/giveaway/Giveaway.java @@ -58,15 +58,21 @@ public class Giveaway { private final ConcurrentLinkedQueue participantsList; //REPO + @Getter(AccessLevel.NONE) private final ActiveGiveawayRepository activeGiveawayRepository; + @Getter(AccessLevel.NONE) private final ParticipantsRepository participantsRepository; + @Getter(AccessLevel.NONE) private final ListUsersRepository listUsersRepository; //Service + @Getter(AccessLevel.NONE) private final GiveawayMessageHandler giveawayMessageHandler; + @Getter(AccessLevel.NONE) private final GiveawaySaving giveawaySaving; + @Getter(AccessLevel.NONE) private final GiveawayEnd giveawayEnd; - + @Getter(AccessLevel.NONE) private final GiveawayTimeHandler giveawayTimeHandler; @Autowired @@ -169,6 +175,10 @@ public void addParticipantToList(Participants participants) { participantsList.add(participants); } + public void clearParticipant() { + participantsList.clear(); + } + public int getListUsersSize() { return listUsersHash.size(); } diff --git a/src/main/java/main/giveaway/GiveawayEnd.java b/src/main/java/main/giveaway/GiveawayEnd.java index c770a43..34c2ff7 100644 --- a/src/main/java/main/giveaway/GiveawayEnd.java +++ b/src/main/java/main/giveaway/GiveawayEnd.java @@ -62,6 +62,7 @@ public void stop(Giveaway giveaway, int countWinner) { notEnoughUsers.setColor(Color.GREEN); notEnoughUsers.setTitle(giftNotEnoughUsers); notEnoughUsers.setDescription(giftGiveawayDeleted); + giveaway.clearParticipant(); //Отправляет сообщение giveawayMessageHandler.editMessage(notEnoughUsers, guildId, textChannelId); @@ -170,6 +171,7 @@ public void stop(Giveaway giveaway, int countWinner) { giveawayMessageHandler.editMessage(embedBuilder, guildId, textChannelId); } + giveaway.clearParticipant(); //Удаляет данные из коллекций GiveawayRegistry instance = GiveawayRegistry.getInstance(); instance.removeGiveaway(guildId); diff --git a/src/main/java/main/giveaway/GiveawayRegistry.java b/src/main/java/main/giveaway/GiveawayRegistry.java index 9615ab4..e8358f4 100644 --- a/src/main/java/main/giveaway/GiveawayRegistry.java +++ b/src/main/java/main/giveaway/GiveawayRegistry.java @@ -43,7 +43,7 @@ public void putGift(long guildId, Giveaway giveaway) { giveawayMap.put(guildId, giveaway); } - public void removeGiveaway(long guildId) { + public void removeGiveaway(Long guildId) { giveawayMap.remove(guildId); } } \ No newline at end of file diff --git a/src/main/java/main/giveaway/GiveawaySaving.java b/src/main/java/main/giveaway/GiveawaySaving.java index bac1b12..f6479c2 100644 --- a/src/main/java/main/giveaway/GiveawaySaving.java +++ b/src/main/java/main/giveaway/GiveawaySaving.java @@ -99,8 +99,8 @@ public void addUser(Giveaway giveaway, final User user) { public void saveParticipants(long guildId, ConcurrentLinkedQueue participantsList) { GiveawayRegistry giveawayRegistry = GiveawayRegistry.getInstance(); - boolean hasGiveaway = giveawayRegistry.hasGiveaway(guildId); - if (!hasGiveaway) return; + Giveaway giveaway = giveawayRegistry.getGiveaway(guildId); + if (giveaway == null) return; if (!participantsList.isEmpty()) { List arrayList = new ArrayList<>(150); @@ -111,10 +111,7 @@ public void saveParticipants(long guildId, ConcurrentLinkedQueue p } } try { - hasGiveaway = giveawayRegistry.hasGiveaway(guildId); - if (hasGiveaway) { - participantsRepository.saveAll(arrayList); - } + participantsRepository.saveAll(arrayList); } catch (Exception e) { LOGGER.log(Level.WARNING, e.getMessage(), e); }