Skip to content

Commit 141c17c

Browse files
Improve performance on extremely long queues making one full loop
1 parent 92d2268 commit 141c17c

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/main/java/net/pistonmaster/pistonqueue/shared/QueueListenerShared.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.time.Instant;
3535
import java.util.*;
3636
import java.util.concurrent.ThreadLocalRandom;
37-
import java.util.concurrent.atomic.AtomicInteger;
3837

3938
@RequiredArgsConstructor
4039
public abstract class QueueListenerShared {
@@ -296,17 +295,19 @@ private void connectPlayer(QueueType type) {
296295
}
297296
}
298297

298+
@SuppressWarnings("UnstableApiUsage")
299299
private void sendXPSoundToQueueType(QueueType type) {
300-
@SuppressWarnings("UnstableApiUsage")
301300
ByteArrayDataOutput out = ByteStreams.newDataOutput();
302301
out.writeUTF("xp");
303302

304-
AtomicInteger counter = new AtomicInteger(0);
305-
type.getQueueMap().forEach((uuid, server) -> {
306-
if (counter.incrementAndGet() <= 5) {
307-
out.writeUTF(uuid.toString());
303+
int counter = 0;
304+
for (UUID uuid : type.getQueueMap().keySet()) {
305+
if (++counter > 5) {
306+
break;
308307
}
309-
});
308+
309+
out.writeUTF(uuid.toString());
310+
}
310311

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

0 commit comments

Comments
 (0)