aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLéo Kosman <leo.kosman@proton.me>2024-08-23 14:27:22 +0200
committerLéo Kosman <leo.kosman@proton.me>2024-08-23 14:27:22 +0200
commitd89d380f3229ab22a47e43e6cef50c604629bda1 (patch)
tree5bec67efb5b92dca64659d040ba76f1200ae6159
parentf2537409c7705f53f8a612a67b2af2497cd3830d (diff)
style: improve code as suggested by @anhgelus
-rw-r--r--src/main/java/world/anhgelus/molehunt/Game.java11
-rw-r--r--src/main/java/world/anhgelus/molehunt/Molehunt.java5
2 files changed, 7 insertions, 9 deletions
diff --git a/src/main/java/world/anhgelus/molehunt/Game.java b/src/main/java/world/anhgelus/molehunt/Game.java
index 32dea83..54e5c3a 100644
--- a/src/main/java/world/anhgelus/molehunt/Game.java
+++ b/src/main/java/world/anhgelus/molehunt/Game.java
@@ -44,10 +44,7 @@ public class Game {
final var playerManager = server.getPlayerManager();
final var players = new ArrayList<>(playerManager.getPlayerList());
- for (int i = 0; i < n; i++) {
- // Can happen if the mole count is greater than the player count
- if (players.isEmpty()) break;
-
+ for (int i = 0; i < n && !players.isEmpty(); i++) {
final var r = ThreadLocalRandom.current().nextInt(0, players.size());
final var mole = players.get(r);
if (mole == null) throw new IllegalStateException("Mole is null!");
@@ -160,7 +157,11 @@ public class Game {
}
public String getMolesAsString() {
- return moles.stream().map(ServerPlayerEntity::getDisplayName).filter(Objects::nonNull).map(Text::toString).collect(Collectors.joining(", "));
+ return moles.stream()
+ .map(ServerPlayerEntity::getDisplayName)
+ .filter(Objects::nonNull)
+ .map(Text::toString)
+ .collect(Collectors.joining(", "));
}
public boolean isAMole(ServerPlayerEntity player) {
diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java
index 1752d26..5df63b1 100644
--- a/src/main/java/world/anhgelus/molehunt/Molehunt.java
+++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java
@@ -34,7 +34,6 @@ public class Molehunt implements ModInitializer {
@Override
public void onInitialize() {
LOGGER.info("Initializing Molehunt");
- LOGGER.info(String.valueOf(CONFIG.GAME_DURATION));
final var command = literal("molehunt");
command.then(literal("start").requires(source -> source.hasPermissionLevel(1)).executes(context -> {
@@ -71,9 +70,7 @@ public class Molehunt implements ModInitializer {
}));
command.then(literal("stop").requires(source -> source.hasPermissionLevel(1)).executes(context -> {
if (game == null || !game.hasStarted()) {
- var e = new SimpleCommandExceptionType(Text.translatable("commands.molehunt.stop.failed"));
-
- throw e.create();
+ throw (new SimpleCommandExceptionType(Text.translatable("commands.molehunt.stop.failed"))).create();
}
game.stop();