Skip to content

Commit

Permalink
Improve performance on extremely long queues making one full loop
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 1, 2022
1 parent 92d2268 commit 141c17c
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;

@RequiredArgsConstructor
public abstract class QueueListenerShared {
Expand Down Expand Up @@ -296,17 +295,19 @@ private void connectPlayer(QueueType type) {
}
}

@SuppressWarnings("UnstableApiUsage")
private void sendXPSoundToQueueType(QueueType type) {
@SuppressWarnings("UnstableApiUsage")
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("xp");

AtomicInteger counter = new AtomicInteger(0);
type.getQueueMap().forEach((uuid, server) -> {
if (counter.incrementAndGet() <= 5) {
out.writeUTF(uuid.toString());
int counter = 0;
for (UUID uuid : type.getQueueMap().keySet()) {
if (++counter > 5) {
break;
}
});

out.writeUTF(uuid.toString());
}

plugin.getServer(Config.QUEUE_SERVER).ifPresent(server ->
server.sendPluginMessage("piston:queue", out.toByteArray()));
Expand Down

0 comments on commit 141c17c

Please sign in to comment.