From c8fbdec64fb0adc2921127d5d7b63386281d034c Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Thu, 4 Apr 2024 04:28:44 +0200 Subject: [PATCH] Fixes some minor issues Fixes the tab-completion for the randomly inverted game-mode not being properly matched. Prevents the usage text from displaying for some join errors --- .../arena/dropper/DropperArenaGameMode.java | 4 ++-- .../dropper/JoinDropperArenaCommand.java | 18 ++++++++---------- .../parkour/JoinParkourArenaCommand.java | 16 +++++++--------- .../placeholder/DropperRecordExpansion.java | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArenaGameMode.java b/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArenaGameMode.java index 9e43f85..1a60463 100644 --- a/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArenaGameMode.java +++ b/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArenaGameMode.java @@ -34,11 +34,11 @@ public enum DropperArenaGameMode implements ConfigurationSerializable, ArenaGame * @param gameMode

The game-mode string to match

* @return

The specified arena game-mode

*/ - public static @NotNull DropperArenaGameMode matchGamemode(@NotNull String gameMode) { + public static @NotNull DropperArenaGameMode matchGameMode(@NotNull String gameMode) { String sanitized = gameMode.trim().toLowerCase(); if (sanitized.matches("(invert(ed)?|inverse)")) { return DropperArenaGameMode.INVERTED; - } else if (sanitized.matches("rand(om)?")) { + } else if (sanitized.matches("rand(om)?_?(inverted)?")) { return DropperArenaGameMode.RANDOM_INVERTED; } else { return DropperArenaGameMode.DEFAULT; diff --git a/src/main/java/net/knarcraft/minigames/command/dropper/JoinDropperArenaCommand.java b/src/main/java/net/knarcraft/minigames/command/dropper/JoinDropperArenaCommand.java index 11c7fe9..098d854 100644 --- a/src/main/java/net/knarcraft/minigames/command/dropper/JoinDropperArenaCommand.java +++ b/src/main/java/net/knarcraft/minigames/command/dropper/JoinDropperArenaCommand.java @@ -38,7 +38,7 @@ public class JoinDropperArenaCommand implements CommandExecutor { // Disallow joining if the player is already in a mini-game arena if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) { stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ALREADY_PLAYING); - return false; + return true; } // Make sure the arena exists @@ -51,10 +51,11 @@ public class JoinDropperArenaCommand implements CommandExecutor { // Deny vehicles as allowing this is tricky, and will cause problems in some cases if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) { stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER); - return false; + return true; } - return joinArena(specifiedArena, player, arguments); + joinArena(specifiedArena, player, arguments); + return true; } /** @@ -63,13 +64,12 @@ public class JoinDropperArenaCommand implements CommandExecutor { * @param specifiedArena

The arena the player wants to join

* @param player

The player joining the arena

* @param arguments

The arguments given

- * @return

Whether the arena was joined successfully

*/ - private boolean joinArena(DropperArena specifiedArena, Player player, String[] arguments) { + private void joinArena(DropperArena specifiedArena, Player player, String[] arguments) { // Find the specified game-mode DropperArenaGameMode gameMode; if (arguments.length > 1) { - gameMode = DropperArenaGameMode.matchGamemode(arguments[1]); + gameMode = DropperArenaGameMode.matchGameMode(arguments[1]); } else { gameMode = DropperArenaGameMode.DEFAULT; } @@ -77,7 +77,7 @@ public class JoinDropperArenaCommand implements CommandExecutor { // Make sure the player has beaten the necessary levels DropperArenaGroup arenaGroup = MiniGames.getInstance().getDropperArenaHandler().getGroup(specifiedArena.getArenaId()); if (arenaGroup != null && !doGroupChecks(specifiedArena, arenaGroup, gameMode, player)) { - return false; + return; } StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter(); @@ -87,7 +87,7 @@ public class JoinDropperArenaCommand implements CommandExecutor { gameMode != DropperArenaGameMode.DEFAULT && specifiedArena.getData().hasNotCompleted(DropperArenaGameMode.DEFAULT, player)) { stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_NORMAL_MODE_REQUIRED); - return false; + return; } // Register the player's session @@ -103,14 +103,12 @@ public class JoinDropperArenaCommand implements CommandExecutor { if (!teleported) { stringFormatter.displayErrorMessage(player, MiniGameMessage.ERROR_ARENA_TELEPORT_FAILED); newSession.triggerQuit(false, true); - return false; } else { // Update the player's state to follow the arena's rules newSession.getEntryState().setArenaState(); player.getInventory().addItem(GUIHelper.getGUIOpenItem()); stringFormatter.displaySuccessMessage(player, MiniGameMessage.SUCCESS_ARENA_JOINED); - return true; } } diff --git a/src/main/java/net/knarcraft/minigames/command/parkour/JoinParkourArenaCommand.java b/src/main/java/net/knarcraft/minigames/command/parkour/JoinParkourArenaCommand.java index 2f931bd..a78cb8d 100644 --- a/src/main/java/net/knarcraft/minigames/command/parkour/JoinParkourArenaCommand.java +++ b/src/main/java/net/knarcraft/minigames/command/parkour/JoinParkourArenaCommand.java @@ -38,7 +38,7 @@ public class JoinParkourArenaCommand implements CommandExecutor { // Disallow joining if the player is already in a mini-game arena if (MiniGames.getInstance().getSession(player.getUniqueId()) != null) { stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_ALREADY_PLAYING); - return false; + return true; } // Make sure the arena exists @@ -51,10 +51,11 @@ public class JoinParkourArenaCommand implements CommandExecutor { // Deny vehicles as allowing this is tricky, and will cause problems in some cases if (player.isInsideVehicle() || !player.getPassengers().isEmpty()) { stringFormatter.displayErrorMessage(commandSender, MiniGameMessage.ERROR_JOIN_IN_VEHICLE_OR_PASSENGER); - return false; + return true; } - return joinArena(specifiedArena, player, arguments); + joinArena(specifiedArena, player, arguments); + return true; } /** @@ -63,9 +64,8 @@ public class JoinParkourArenaCommand implements CommandExecutor { * @param specifiedArena

The arena the player wants to join

* @param player

The player joining the arena

* @param arguments

The arguments given

- * @return

Whether the arena was joined successfully

*/ - private boolean joinArena(ParkourArena specifiedArena, Player player, String[] arguments) { + private void joinArena(ParkourArena specifiedArena, Player player, String[] arguments) { // Find the specified game-mode ParkourArenaGameMode gameMode; if (arguments.length > 1) { @@ -78,13 +78,13 @@ public class JoinParkourArenaCommand implements CommandExecutor { if (specifiedArena.hasNoCheckpoints() && gameMode == ParkourArenaGameMode.HARDCORE) { MiniGames.getInstance().getStringFormatter().displayErrorMessage(player, MiniGameMessage.ERROR_HARDCORE_NO_CHECKPOINTS); - return false; + return; } // Make sure the player has beaten the necessary levels ParkourArenaGroup arenaGroup = MiniGames.getInstance().getParkourArenaHandler().getGroup(specifiedArena.getArenaId()); if (arenaGroup != null && !doGroupChecks(specifiedArena, arenaGroup, gameMode, player)) { - return false; + return; } // Register the player's session @@ -101,7 +101,6 @@ public class JoinParkourArenaCommand implements CommandExecutor { MiniGames.getInstance().getStringFormatter().displayErrorMessage(player, MiniGameMessage.ERROR_ARENA_TELEPORT_FAILED); newSession.triggerQuit(false, true); - return false; } else { // Update the player's state to follow the arena's rules newSession.getEntryState().setArenaState(); @@ -109,7 +108,6 @@ public class JoinParkourArenaCommand implements CommandExecutor { player.getInventory().addItem(GUIHelper.getGUIOpenItem()); MiniGames.getInstance().getStringFormatter().displaySuccessMessage(player, MiniGameMessage.SUCCESS_ARENA_JOINED); - return true; } } diff --git a/src/main/java/net/knarcraft/minigames/placeholder/DropperRecordExpansion.java b/src/main/java/net/knarcraft/minigames/placeholder/DropperRecordExpansion.java index 3357f68..885b954 100644 --- a/src/main/java/net/knarcraft/minigames/placeholder/DropperRecordExpansion.java +++ b/src/main/java/net/knarcraft/minigames/placeholder/DropperRecordExpansion.java @@ -26,7 +26,7 @@ public class DropperRecordExpansion extends RecordExpansion { @Override protected @NotNull ArenaGameMode parseGameMode(@NotNull String gameMode) { - return DropperArenaGameMode.matchGamemode(gameMode); + return DropperArenaGameMode.matchGameMode(gameMode); } }