From 5ab04ddc83e128cfcea96e0fc3a7cee8a50d146d Mon Sep 17 00:00:00 2001 From: anhgelus Date: Sun, 8 Sep 2024 11:51:35 +0000 Subject: style(method name): more descriptive method name and follow yarn convention --- src/main/java/world/anhgelus/molehunt/Molehunt.java | 18 +++++++++--------- src/main/java/world/anhgelus/molehunt/game/Game.java | 14 +++++++------- .../java/world/anhgelus/molehunt/utils/TimeUtils.java | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src/main/java/world') diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index 83309a0..7fa10a3 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -128,12 +128,12 @@ public class Molehunt implements ModInitializer { var player = context.getSource().getPlayer(); assert player != null; - if (game == null || !game.hasStarted()) { + if (game == null || !game.started()) { player.networkHandler.sendPacket(new OverlayMessageS2CPacket( Text.translatable("commands.molehunt.error.game_not_started").formatted(Formatting.RED) )); } else { - player.networkHandler.sendPacket(new OverlayMessageS2CPacket(Text.of(game.getShortRemainingText()))); + player.networkHandler.sendPacket(new OverlayMessageS2CPacket(Text.of(game.getRemainingText()))); } return Command.SINGLE_SUCCESS; @@ -146,7 +146,7 @@ public class Molehunt implements ModInitializer { }) )); command.then(literal("role").requires(ServerCommandSource::isExecutedByPlayer).executes(context -> { - if (game == null || !game.hasStarted()) { + if (game == null || !game.started()) { throw (new SimpleCommandExceptionType(Text.translatable("commands.molehunt.error.game_not_started"))).create(); } @@ -154,7 +154,7 @@ public class Molehunt implements ModInitializer { final var player = source.getPlayer(); assert player != null; - if (game.isAMole(player)) { + if (game.isMole(player)) { source.sendFeedback( () -> Text.translatable("commands.molehunt.role.mole") .append("\n\n") @@ -175,7 +175,7 @@ public class Molehunt implements ModInitializer { return Command.SINGLE_SUCCESS; })); command.then(literal("stop").requires(source -> source.hasPermissionLevel(1)).executes(context -> { - if (game == null || !game.hasStarted()) { + if (game == null || !game.started()) { throw (new SimpleCommandExceptionType(Text.translatable("commands.molehunt.error.game_not_started"))).create(); } @@ -192,13 +192,13 @@ public class Molehunt implements ModInitializer { ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource) -> { if (!(entity instanceof ServerPlayerEntity) || game == null) return; - if (!game.hasStarted()) return; - if (game.gameWonByMoles()) game.end(); + if (!game.started()) return; + if (game.wonByMoles()) game.end(); }); ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> { if (game == null) return; - if (!game.hasStarted()) return; + if (!game.started()) return; if (game.getMoles().contains(oldPlayer)) game.updateMole(oldPlayer, newPlayer); newPlayer.changeGameMode(GameMode.SPECTATOR); }); @@ -210,7 +210,7 @@ public class Molehunt implements ModInitializer { ); ServerPlayNetworking.send( handler.player, - new GamePayload(game != null && game.hasStarted()) + new GamePayload(game != null && game.started()) ); }); diff --git a/src/main/java/world/anhgelus/molehunt/game/Game.java b/src/main/java/world/anhgelus/molehunt/game/Game.java index 915e7d3..58ea4ee 100644 --- a/src/main/java/world/anhgelus/molehunt/game/Game.java +++ b/src/main/java/world/anhgelus/molehunt/game/Game.java @@ -117,7 +117,7 @@ public class Game { remaining--; playerManager.getPlayerList().forEach(player -> { if (Molehunt.timerVisibility.getOrDefault(player, true)) { - player.networkHandler.sendPacket(new OverlayMessageS2CPacket(Text.of(getShortRemainingText()))); + player.networkHandler.sendPacket(new OverlayMessageS2CPacket(Text.of(getRemainingText()))); } }); playerManager.sendToAll(timing); @@ -153,7 +153,7 @@ public class Game { @Override public void run() { TitleS2CPacket winner; - if (gameWonByMoles()) { + if (wonByMoles()) { winner = new TitleS2CPacket(Text.translatable("molehunt.game.end.winners.moles.title")); } else { winner = new TitleS2CPacket(Text.translatable("molehunt.game.end.winners.survivors.title")); @@ -166,8 +166,8 @@ public class Game { }, 4*1000); } - public Text getShortRemainingText() { - return Text.of("§c" + TimeUtils.printShortTime(remaining)); + public Text getRemainingText() { + return Text.of("§c" + TimeUtils.generateShortString(remaining)); } public List getMoles() { @@ -182,11 +182,11 @@ public class Game { .collect(Collectors.joining(", ")); } - public boolean isAMole(ServerPlayerEntity player) { + public boolean isMole(ServerPlayerEntity player) { return moles.contains(player); } - public boolean gameWonByMoles() { + public boolean wonByMoles() { return new HashSet<>(moles).containsAll( server.getPlayerManager() .getPlayerList() @@ -201,7 +201,7 @@ public class Game { moles.add(newPlayer); } - public boolean hasStarted() { + public boolean started() { return started; } diff --git a/src/main/java/world/anhgelus/molehunt/utils/TimeUtils.java b/src/main/java/world/anhgelus/molehunt/utils/TimeUtils.java index 859f574..2b96606 100644 --- a/src/main/java/world/anhgelus/molehunt/utils/TimeUtils.java +++ b/src/main/java/world/anhgelus/molehunt/utils/TimeUtils.java @@ -4,7 +4,7 @@ public class TimeUtils { private record Time(long hours, long minutes, long seconds) {} - public static String printTime(long time) { + public static String generateString(long time) { final var pt = generateTime(time); StringBuilder sb = new StringBuilder(); @@ -19,7 +19,7 @@ public class TimeUtils { return sb.toString(); } - public static String printShortTime(long time) { + public static String generateShortString(long time) { final var pt = generateTime(time); return padLeft(pt.hours) + ":" + -- cgit v1.2.3