From 9d17887623730efb3215329424a3246abb84c3b7 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Wed, 18 Mar 2026 19:12:34 +0100 Subject: perf(game): use set instead of arraylist --- src/main/java/world/anhgelus/molehunt/Molehunt.java | 4 ++-- src/main/java/world/anhgelus/molehunt/game/Game.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/main') diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index f3153d5..67d20f2 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -170,13 +170,13 @@ public class Molehunt implements ModInitializer { false); } else if (player.isSpectator()) { source.sendSuccess( - () -> Component.translatable("commands.molehunt.role.survivor.mole_count", game.getMoles().size()), + () -> Component.translatable("commands.molehunt.role.survivor.mole_count", game.getMolesCount()), false); } else { source.sendSuccess( () -> Component.translatable("commands.molehunt.role.survivor") .append("\n\n") - .append(Component.translatable("commands.molehunt.role.survivor.mole_count", game.getMoles().size())), + .append(Component.translatable("commands.molehunt.role.survivor.mole_count", game.getMolesCount())), false); } diff --git a/src/main/java/world/anhgelus/molehunt/game/Game.java b/src/main/java/world/anhgelus/molehunt/game/Game.java index 9f44f77..810b755 100644 --- a/src/main/java/world/anhgelus/molehunt/game/Game.java +++ b/src/main/java/world/anhgelus/molehunt/game/Game.java @@ -28,7 +28,7 @@ public class Game { public final int DEFAULT_TIME = Molehunt.CONFIG.getGameDuration() * 60; private final MinecraftServer server; - private final List moles = new ArrayList<>(); + private final Set moles = new HashSet<>(); private final ClientboundSetTitlesAnimationPacket timing = new ClientboundSetTitlesAnimationPacket(20, 40, 20); private boolean started = false; private int remaining = DEFAULT_TIME; @@ -87,7 +87,7 @@ public class Game { timer.dds_runTask(new TickTask(() -> { playerManager.getPlayers().forEach(p -> { p.connection.send(timing); - if (moles.contains(p.getUUID())) { + if (isMole(p)) { p.connection.send(new ClientboundSetTitleTextPacket(Component.translatable("molehunt.game.start.mole.title"))); p.connection.send(new ClientboundSetSubtitleTextPacket(Component.translatable("molehunt.game.start.mole.subtitle"))); } else { @@ -182,8 +182,8 @@ public class Game { } public boolean wonByMoles() { - final var moles = getMoles().map(Player::getUUID).toList(); - return !moles.isEmpty() && new HashSet<>(moles).containsAll( + final var moles = getMoles().map(Player::getUUID).collect(Collectors.toSet()); + return !moles.isEmpty() && moles.containsAll( server.getPlayerList() .getPlayers() .stream() @@ -196,7 +196,7 @@ public class Game { private void changeState(boolean hasStarted) { started = hasStarted; final var payload = new GamePayload(hasStarted); - server.getPlayerList().getPlayers().forEach(p -> ServerPlayNetworking.send(p, payload)); + server.getPlayerList().broadcastAll(ServerPlayNetworking.createClientboundPacket(payload)); } public boolean started() { -- cgit v1.2.3