Skip to content

Commit

Permalink
Fix position display issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Jan 14, 2022
1 parent f429776 commit a85388f
Showing 1 changed file with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,39 +164,28 @@ default void scheduleTasks(QueueListenerShared queueListener) {

default void sendMessage(QueueType queue, boolean bool, MessageType type) {
if (bool) {
int position = 0;
AtomicInteger position = new AtomicInteger();

for (Map.Entry<UUID, String> entry : new LinkedHashMap<>(queue.getQueueMap()).entrySet()) {
Optional<PlayerWrapper> player = getPlayer(entry.getKey());
if (!player.isPresent()) {
continue;
}

position++;

player.get().sendMessage(type, Config.QUEUE_POSITION
.replace("%position%", String.valueOf(position))
.replace("%total%", String.valueOf(queue.getQueueMap().size())));
getPlayer(entry.getKey()).ifPresent(player ->
player.sendMessage(type, Config.QUEUE_POSITION
.replace("%position%", String.valueOf(position.incrementAndGet()))
.replace("%total%", String.valueOf(queue.getQueueMap().size()))));
}
}
}

default void updateTab(QueueType queue, List<String> header, List<String> footer) {
int position = 0;
AtomicInteger position = new AtomicInteger();

for (Map.Entry<UUID, String> entry : new LinkedHashMap<>(queue.getQueueMap()).entrySet()) {
Optional<PlayerWrapper> player = getPlayer(entry.getKey());
if (!player.isPresent()) {
continue;
}
getPlayer(entry.getKey()).ifPresent(player -> {
int incrementedPosition = position.incrementAndGet();

position++;

int finalPosition = position;
header = header.stream().map(str -> replacePosition(str, finalPosition, queue)).collect(Collectors.toList());
footer = footer.stream().map(str -> replacePosition(str, finalPosition, queue)).collect(Collectors.toList());

player.get().sendPlayerListHeaderAndFooter(header, footer);
player.sendPlayerListHeaderAndFooter(
header.stream().map(str -> replacePosition(str, incrementedPosition, queue)).collect(Collectors.toList()),
footer.stream().map(str -> replacePosition(str, incrementedPosition, queue)).collect(Collectors.toList()));
});
}
}

Expand Down

0 comments on commit a85388f

Please sign in to comment.