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
This commit is contained in:
Kristian Knarvik 2024-04-04 04:28:44 +02:00
parent 09f29e5f67
commit c8fbdec64f
4 changed files with 18 additions and 22 deletions

View File

@ -34,11 +34,11 @@ public enum DropperArenaGameMode implements ConfigurationSerializable, ArenaGame
* @param gameMode <p>The game-mode string to match</p>
* @return <p>The specified arena game-mode</p>
*/
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;

View File

@ -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 <p>The arena the player wants to join</p>
* @param player <p>The player joining the arena</p>
* @param arguments <p>The arguments given</p>
* @return <p>Whether the arena was joined successfully</p>
*/
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;
}
}

View File

@ -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 <p>The arena the player wants to join</p>
* @param player <p>The player joining the arena</p>
* @param arguments <p>The arguments given</p>
* @return <p>Whether the arena was joined successfully</p>
*/
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;
}
}

View File

@ -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);
}
}