From e27217bbdfa2ab48ad9f8c758fcf03e8cf8c953c Mon Sep 17 00:00:00 2001 From: Netherwhal Date: Sun, 10 Mar 2024 21:24:21 +0100 Subject: [PATCH] Change order to match vanilla (#33) * Change order to match vanilla * minor * test --- build.gradle | 2 +- .../commands/TeamCommandExecutor.java | 91 ++++++++----------- src/main/resources/plugin.yml | 8 +- 3 files changed, 43 insertions(+), 58 deletions(-) diff --git a/build.gradle b/build.gradle index 340961d..a63bca9 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'net.simplyvanilla' -version = '0.3.0' +version = '0.3.1' java { toolchain.languageVersion.set(JavaLanguageVersion.of(17)) diff --git a/src/main/java/net/simplyvanilla/simplynicks/commands/TeamCommandExecutor.java b/src/main/java/net/simplyvanilla/simplynicks/commands/TeamCommandExecutor.java index 32a6490..78cb9c4 100644 --- a/src/main/java/net/simplyvanilla/simplynicks/commands/TeamCommandExecutor.java +++ b/src/main/java/net/simplyvanilla/simplynicks/commands/TeamCommandExecutor.java @@ -31,46 +31,36 @@ public boolean onCommand( return false; } - String subCommand = args[0]; - switch (subCommand.toLowerCase(Locale.ROOT)) { - case "create": { + String subCommand = args[0].toLowerCase(Locale.ROOT); + switch (subCommand) { + case "remove", "add": if (args.length < 2) { return false; } - String name = args[1]; - return handleCreate(sender, name); - } - case "modify": { - if (args.length < 3) { - return false; + if (subCommand.equals("remove")) { + handleDelete(sender, args[1]); + } else { + handleCreate(sender, args[1]); } - String name = args[1]; - String modifyType = args[2]; - String value = args.length > 3 ? args[3] : ""; - return handleModify(sender, name, modifyType, value); - } - case "join": { + return true; + + case "modify": if (args.length < 3) { return false; } - String member = args[1]; - String name = args[2]; - return handleJoin(sender, member, name); - } - case "leave": { + handleModify(sender, args[1], args[2], args.length > 3 ? args[3] : ""); + return true; + + case "leave", "join": if (args.length < 3) { return false; } - String leaver = args[1]; - String name = args[2]; - return handleLeave(sender, leaver, name); - } - case "delete": - if (args.length < 2) { - return false; + if (subCommand.equals("join")) { + handleJoin(sender, args[2], args[1]); + } else { + handleLeave(sender, args[2], args[1]); } - String name = args[1]; - return handleDelete(sender, name); + return true; } return false; @@ -89,105 +79,100 @@ private UUID getPlayerId(String input) { } // /team delete - private boolean handleDelete(CommandSender sender, String name) { + private void handleDelete(CommandSender sender, String name) { int teamId = this.plugin.getTeamDatabase().getTeamId(name); if (teamId < 0) { this.plugin.sendConfigMessage(sender, "messages.error.teamNotFound"); - return false; + return; } if (!this.plugin.getTeamDatabase().deleteTeam(teamId)) { - return false; + return; } this.plugin.sendConfigMessage(sender, "messages.teamDeletedMessage"); - return true; } // /team leave - private boolean handleLeave(CommandSender sender, String leaver, String name) { + private void handleLeave(CommandSender sender, String leaver, String name) { UUID leaverId = getPlayerId(leaver); if (leaverId == null) { this.plugin.sendConfigMessage(sender, "messages.error.playerCannotFoundErrorMessage"); - return false; + return; } TeamMySQL.PlayerTeam playerTeam = this.plugin.getTeamCache().getTeam(leaverId); if (playerTeam == null) { this.plugin.sendConfigMessage(sender, "messages.error.teamNotInTeam"); - return false; + return; } if (!playerTeam.getName().equals(name)) { this.plugin.sendConfigMessage(sender, "messages.error.teamNotInTeam"); - return false; + return; } if (!this.plugin.getTeamDatabase().leaveTeam(leaverId, playerTeam.getTeamId())) { - return false; + return; } this.plugin.sendConfigMessage(sender, "messages.teamLeftMessage"); - return true; } // /team join - private boolean handleJoin(CommandSender sender, String member, String name) { + private void handleJoin(CommandSender sender, String member, String name) { UUID memberId = getPlayerId(member); if (memberId == null) { this.plugin.sendConfigMessage(sender, "messages.error.playerCannotFoundErrorMessage"); - return false; + return; } if (this.plugin.getTeamCache().getTeam(memberId) != null) { this.plugin.sendConfigMessage(sender, "messages.error.teamAlreadyInTeam"); - return false; + return; } int teamId = this.plugin.getTeamDatabase().getTeamId(name); if (teamId < 0) { this.plugin.sendConfigMessage(sender, "messages.error.teamNotFound"); - return false; + return; } if (!this.plugin.getTeamDatabase().joinTeam(memberId, teamId)) { - return false; + return; } this.plugin.sendConfigMessage(sender, "messages.teamJoinedMessage"); - return true; } // /team modify [value] // modifyType: name, color - private boolean handleModify(CommandSender sender, String name, String modifyType, String value) { + private void handleModify(CommandSender sender, String name, String modifyType, String value) { int teamId = this.plugin.getTeamDatabase().getTeamId(name); if (teamId < 0) { this.plugin.sendConfigMessage(sender, "messages.error.teamNotFound"); - return false; + return; } if (!this.plugin.getTeamDatabase().modifyTeam(teamId, modifyType, value)) { - return false; + return; } this.plugin.sendConfigMessage(sender, "messages.teamModifiedMessage"); - return true; } // /team create - private boolean handleCreate(CommandSender sender, String teamName) { + private void handleCreate(CommandSender sender, String teamName) { int teamId = this.plugin.getTeamDatabase().getTeamId(teamName); if (teamId >= 0) { this.plugin.sendConfigMessage(sender, "messages.error.teamAlreadyExists"); - return false; + return; } if (!this.plugin.getTeamDatabase().createTeam(teamName)) { - return false; + return; } this.plugin.sendConfigMessage(sender, "messages.teamCreatedMessage", Map.of("team", teamName)); - return true; } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b564a89..282ea06 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -26,11 +26,11 @@ commands: team: description: Commands for managing teams usage: | - /team create - Create a team - /team delete - Delete a team + /team add - Create a team + /team remove - Delete a team /team modify - Modify a team - /team join - Join a team - /team leave - Leave a team + /team join - Join a team + /team leave - Leave a team permission: simplynicks.team permissions: