aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-03-18 19:12:34 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-03-18 19:12:34 +0100
commit9d17887623730efb3215329424a3246abb84c3b7 (patch)
treea018dc17701a04672560c1465d325465f54db08e
parent03b350e8de25749b7bdab8b281f5bdffc1d835ae (diff)
perf(game): use set instead of arraylist26.1
-rw-r--r--src/main/java/world/anhgelus/molehunt/Molehunt.java4
-rw-r--r--src/main/java/world/anhgelus/molehunt/game/Game.java10
2 files changed, 7 insertions, 7 deletions
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<UUID> moles = new ArrayList<>();
+ private final Set<UUID> 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() {