Skip to content

Commit

Permalink
New Update
Browse files Browse the repository at this point in the history
1. Fix #309
  • Loading branch information
megoRU committed Jan 27, 2024
1 parent b343abf commit c467d40
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/main/java/main/giveaway/Giveaway.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,21 @@ public class Giveaway {
private final ConcurrentLinkedQueue<Participants> 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
Expand Down Expand Up @@ -169,6 +175,10 @@ public void addParticipantToList(Participants participants) {
participantsList.add(participants);
}

public void clearParticipant() {
participantsList.clear();
}

public int getListUsersSize() {
return listUsersHash.size();
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/main/giveaway/GiveawayEnd.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/main/giveaway/GiveawayRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
9 changes: 3 additions & 6 deletions src/main/java/main/giveaway/GiveawaySaving.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void addUser(Giveaway giveaway, final User user) {

public void saveParticipants(long guildId, ConcurrentLinkedQueue<Participants> 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<Participants> arrayList = new ArrayList<>(150);
Expand All @@ -111,10 +111,7 @@ public void saveParticipants(long guildId, ConcurrentLinkedQueue<Participants> p
}
}
try {
hasGiveaway = giveawayRegistry.hasGiveaway(guildId);
if (hasGiveaway) {
participantsRepository.saveAll(arrayList);
}
participantsRepository.saveAll(arrayList);
} catch (Exception e) {
LOGGER.log(Level.WARNING, e.getMessage(), e);
}
Expand Down

0 comments on commit c467d40

Please sign in to comment.