diff --git a/src/main/java/emu/grasscutter/command/Command.java b/src/main/java/emu/grasscutter/command/Command.java index 734f454ea..c94804678 100644 --- a/src/main/java/emu/grasscutter/command/Command.java +++ b/src/main/java/emu/grasscutter/command/Command.java @@ -9,8 +9,6 @@ public @interface Command { String usage() default "No usage specified"; - String description() default "No description specified"; - String[] aliases() default {}; String permission() default ""; diff --git a/src/main/java/emu/grasscutter/command/CommandHandler.java b/src/main/java/emu/grasscutter/command/CommandHandler.java index ffe21c9be..dadb87bb3 100644 --- a/src/main/java/emu/grasscutter/command/CommandHandler.java +++ b/src/main/java/emu/grasscutter/command/CommandHandler.java @@ -6,6 +6,9 @@ import emu.grasscutter.game.player.Player; import java.util.List; public interface CommandHandler { + + String description(); + /** * Send a message to the target. * diff --git a/src/main/java/emu/grasscutter/command/CommandMap.java b/src/main/java/emu/grasscutter/command/CommandMap.java index a183c6ac3..6b6a852af 100644 --- a/src/main/java/emu/grasscutter/command/CommandMap.java +++ b/src/main/java/emu/grasscutter/command/CommandMap.java @@ -85,6 +85,14 @@ public final class CommandMap { return new LinkedHashMap<>(this.annotations); } + public HashMap getHandlersAndAnnotations() { + HashMap hashMap = new HashMap<>(); + this.commands.forEach((key, handler) -> { + hashMap.put(handler, this.annotations.get(key)); + }); + return hashMap; + } + /** * Returns a list of all registered commands. * diff --git a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java index 627f4680f..1c5c8228e 100644 --- a/src/main/java/emu/grasscutter/command/commands/AccountCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/AccountCommand.java @@ -9,9 +9,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "account", usage = "account [uid]", description = "Modify user accounts") +@Command(label = "account", usage = "account [uid]") public final class AccountCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.account.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (sender != null) { diff --git a/src/main/java/emu/grasscutter/command/commands/BroadcastCommand.java b/src/main/java/emu/grasscutter/command/commands/BroadcastCommand.java index 1aa234919..fcabb131c 100644 --- a/src/main/java/emu/grasscutter/command/commands/BroadcastCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/BroadcastCommand.java @@ -9,10 +9,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "broadcast", usage = "broadcast ", - description = "Sends a message to all the players", aliases = {"b"}, permission = "server.broadcast") +@Command(label = "broadcast", usage = "broadcast ", aliases = {"b"}, permission = "server.broadcast") public final class BroadcastCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.broadcast.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (args.size() < 1) { diff --git a/src/main/java/emu/grasscutter/command/commands/ChangeSceneCommand.java b/src/main/java/emu/grasscutter/command/commands/ChangeSceneCommand.java index 1a4e97927..ea7bfe0f6 100644 --- a/src/main/java/emu/grasscutter/command/commands/ChangeSceneCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/ChangeSceneCommand.java @@ -8,9 +8,13 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "changescene", usage = "changescene ", - description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene") +@Command(label = "changescene", usage = "changescene ", aliases = {"scene"}, permission = "player.changescene") public final class ChangeSceneCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.changescene.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/ClearCommand.java b/src/main/java/emu/grasscutter/command/commands/ClearCommand.java index 47d9f2c0d..d416bec52 100644 --- a/src/main/java/emu/grasscutter/command/commands/ClearCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/ClearCommand.java @@ -13,11 +13,15 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; @Command(label = "clear", usage = "clear ", //Merged /clearartifacts and /clearweapons to /clear [uid] - description = "Deletes unequipped unlocked items, including yellow rarity ones from your inventory", aliases = {"clear"}, permission = "player.clearinv") public final class ClearCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.clear.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/CoopCommand.java b/src/main/java/emu/grasscutter/command/commands/CoopCommand.java index 96411019b..120665b76 100644 --- a/src/main/java/emu/grasscutter/command/commands/CoopCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/CoopCommand.java @@ -9,9 +9,13 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "coop", usage = "coop [host UID]", - description = "Forces someone to join the world of others", permission = "server.coop") +@Command(label = "coop", usage = "coop [host UID]", permission = "server.coop") public final class CoopCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.coop.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/DropCommand.java b/src/main/java/emu/grasscutter/command/commands/DropCommand.java index a33a32603..a187cfda8 100644 --- a/src/main/java/emu/grasscutter/command/commands/DropCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/DropCommand.java @@ -13,10 +13,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "drop", usage = "drop [amount]", - description = "Drops an item near you", aliases = {"d", "dropitem"}, permission = "server.drop") +@Command(label = "drop", usage = "drop [amount]", aliases = {"d", "dropitem"}, permission = "server.drop") public final class DropCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.drop.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java b/src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java index 434e80c8f..d92d537e9 100644 --- a/src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/EnterDungeonCommand.java @@ -8,9 +8,13 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "enterdungeon", usage = "enterdungeon ", - description = "Enter a dungeon", aliases = {"dungeon"}, permission = "player.enterdungeon") +@Command(label = "enterdungeon", usage = "enterdungeon ", aliases = {"dungeon"}, permission = "player.enterdungeon") public final class EnterDungeonCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.enter_dungeon.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java index bb11de3c2..5009a4462 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveAllCommand.java @@ -15,10 +15,14 @@ import java.util.*; import static emu.grasscutter.utils.Language.translate; -@Command(label = "giveall", usage = "giveall [amount]", - description = "Gives all items", aliases = {"givea"}, permission = "player.giveall", threading = true) +@Command(label = "giveall", usage = "giveall [amount]", aliases = {"givea"}, permission = "player.giveall", threading = true) public final class GiveAllCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.giveAll.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/GiveArtifactCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveArtifactCommand.java index 541cc440e..d41e83671 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveArtifactCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveArtifactCommand.java @@ -16,8 +16,13 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "giveart", usage = "giveart [[,]]... [level]", description = "Gives the player a specified artifact", aliases = {"gart"}, permission = "player.giveart") +@Command(label = "giveart", usage = "giveart [[,]]... [level]", aliases = {"gart"}, permission = "player.giveart") public final class GiveArtifactCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.giveArtifact.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/GiveCharCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveCharCommand.java index 4b3279202..0e784639d 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveCharCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveCharCommand.java @@ -12,10 +12,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "givechar", usage = "givechar [level]", - description = "Gives the player a specified character", aliases = {"givec"}, permission = "player.givechar") +@Command(label = "givechar", usage = "givechar [level]", aliases = {"givec"}, permission = "player.givechar") public final class GiveCharCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.giveChar.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java index 2f020f7b3..3daa2dff3 100644 --- a/src/main/java/emu/grasscutter/command/commands/GiveCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GiveCommand.java @@ -1,6 +1,5 @@ package emu.grasscutter.command.commands; -import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.data.GameData; @@ -12,12 +11,12 @@ import emu.grasscutter.game.props.ActionReason; import java.util.LinkedList; import java.util.List; -import java.util.regex.Pattern; import java.util.regex.Matcher; +import java.util.regex.Pattern; import static emu.grasscutter.utils.Language.translate; -@Command(label = "give", usage = "give [amount] [level]", description = "Gives an item to you or the specified player", aliases = { +@Command(label = "give", usage = "give [amount] [level]", aliases = { "g", "item", "giveitem"}, permission = "player.give") public final class GiveCommand implements CommandHandler { Pattern lvlRegex = Pattern.compile("l(?:vl?)?(\\d+)"); // Java is a joke of a proglang that doesn't have raw string literals @@ -32,6 +31,11 @@ public final class GiveCommand implements CommandHandler { return -1; } + @Override + public String description() { + return translate("commands.give.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java b/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java index 9abebb8db..4fd2999a6 100644 --- a/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/GodModeCommand.java @@ -1,6 +1,5 @@ package emu.grasscutter.command.commands; -import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.game.player.Player; @@ -9,10 +8,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "godmode", usage = "godmode [on|off|toggle]", - description = "Prevents you from taking damage. Defaults to toggle.", permission = "player.godmode") +@Command(label = "godmode", usage = "godmode [on|off|toggle]", permission = "player.godmode") public final class GodModeCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.godmode.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/HealCommand.java b/src/main/java/emu/grasscutter/command/commands/HealCommand.java index bb0b861b0..b459ecb8c 100644 --- a/src/main/java/emu/grasscutter/command/commands/HealCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/HealCommand.java @@ -11,9 +11,13 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "heal", usage = "heal|h", aliases = {"h"}, - description = "Heal all characters in your current team.", permission = "player.heal") +@Command(label = "heal", usage = "heal|h", aliases = {"h"}, permission = "player.heal") public final class HealCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.heal.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/HelpCommand.java b/src/main/java/emu/grasscutter/command/commands/HelpCommand.java index 93ac831b3..dbb85bf9d 100644 --- a/src/main/java/emu/grasscutter/command/commands/HelpCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/HelpCommand.java @@ -10,22 +10,26 @@ import java.util.*; import static emu.grasscutter.utils.Language.translate; -@Command(label = "help", usage = "help [command]", - description = "Sends the help message or shows information about a specified command") +@Command(label = "help", usage = "help [command]") public final class HelpCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.help.description"); + } + @Override public void execute(Player player, Player targetPlayer, List args) { if (args.size() < 1) { HashMap handlers = CommandMap.getInstance().getHandlers(); - List annotations = new ArrayList<>(); + HashMap annotations = new HashMap<>(); for (String key : handlers.keySet()) { Command annotation = handlers.get(key).getClass().getAnnotation(Command.class); if (!Arrays.asList(annotation.aliases()).contains(key)) { if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) continue; - annotations.add(annotation); + annotations.put(annotation, handlers.get(key)); } } @@ -39,7 +43,7 @@ public final class HelpCommand implements CommandHandler { } else { Command annotation = handler.getClass().getAnnotation(Command.class); - builder.append(" ").append(annotation.description()).append("\n"); + builder.append(" ").append(handler.description()).append("\n"); builder.append(translate("commands.help.usage")).append(annotation.usage()); if (annotation.aliases().length >= 1) { builder.append("\n").append(translate("commands.help.aliases")); @@ -56,12 +60,12 @@ public final class HelpCommand implements CommandHandler { } } - void SendAllHelpMessage(Player player, List annotations) { + void SendAllHelpMessage(Player player, HashMap annotations) { if (player == null) { StringBuilder builder = new StringBuilder("\n" + translate("commands.help.available_commands") + "\n"); - annotations.forEach(annotation -> { + annotations.forEach((annotation, handler) -> { builder.append(annotation.label()).append("\n"); - builder.append(" ").append(annotation.description()).append("\n"); + builder.append(" ").append(handler.description()).append("\n"); builder.append(translate("commands.help.usage")).append(annotation.usage()); if (annotation.aliases().length >= 1) { builder.append("\n").append(translate("commands.help.aliases")); @@ -76,9 +80,9 @@ public final class HelpCommand implements CommandHandler { CommandHandler.sendMessage(null, builder.toString()); } else { CommandHandler.sendMessage(player, translate("commands.help.available_commands")); - annotations.forEach(annotation -> { + annotations.forEach((annotation, handler) -> { StringBuilder builder = new StringBuilder(annotation.label()).append("\n"); - builder.append(" ").append(annotation.description()).append("\n"); + builder.append(" ").append(handler.description()).append("\n"); builder.append(translate("commands.help.usage")).append(annotation.usage()); if (annotation.aliases().length >= 1) { builder.append("\n").append(translate("commands.help.aliases")); diff --git a/src/main/java/emu/grasscutter/command/commands/KickCommand.java b/src/main/java/emu/grasscutter/command/commands/KickCommand.java index 270e28150..71b487cc4 100644 --- a/src/main/java/emu/grasscutter/command/commands/KickCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/KickCommand.java @@ -8,10 +8,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "kick", usage = "kick", - description = "Kicks the specified player from the server (WIP)", permission = "server.kick") +@Command(label = "kick", usage = "kick", permission = "server.kick") public final class KickCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.kick.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/KillAllCommand.java b/src/main/java/emu/grasscutter/command/commands/KillAllCommand.java index 423c60bbd..1fa51eec4 100644 --- a/src/main/java/emu/grasscutter/command/commands/KillAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/KillAllCommand.java @@ -12,10 +12,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "killall", usage = "killall [sceneId]", - description = "Kill all entities", permission = "server.killall") +@Command(label = "killall", usage = "killall [sceneId]", permission = "server.killall") public final class KillAllCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.kill.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/KillCharacterCommand.java b/src/main/java/emu/grasscutter/command/commands/KillCharacterCommand.java index f1e0f0f8c..f3fdb4998 100644 --- a/src/main/java/emu/grasscutter/command/commands/KillCharacterCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/KillCharacterCommand.java @@ -13,10 +13,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "killcharacter", usage = "killcharacter", aliases = {"suicide", "kill"}, - description = "Kills the players current character", permission = "player.killcharacter") +@Command(label = "killcharacter", usage = "killcharacter", aliases = {"suicide", "kill"}, permission = "player.killcharacter") public final class KillCharacterCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.killCharacter.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/ListCommand.java b/src/main/java/emu/grasscutter/command/commands/ListCommand.java index bc35e65e1..7834d2467 100644 --- a/src/main/java/emu/grasscutter/command/commands/ListCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/ListCommand.java @@ -10,10 +10,14 @@ import java.util.Map; import static emu.grasscutter.utils.Language.translate; -@Command(label = "list", usage = "list [uid]", - description = "List online players", aliases = {"players"}) +@Command(label = "list", usage = "list [uid]", aliases = {"players"}) public final class ListCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.list.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { Map playersMap = Grasscutter.getGameServer().getPlayers(); diff --git a/src/main/java/emu/grasscutter/command/commands/PermissionCommand.java b/src/main/java/emu/grasscutter/command/commands/PermissionCommand.java index 69c8ce899..309451945 100644 --- a/src/main/java/emu/grasscutter/command/commands/PermissionCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/PermissionCommand.java @@ -10,10 +10,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "permission", usage = "permission ", - description = "Grants or removes a permission for a user", permission = "*") +@Command(label = "permission", usage = "permission ", permission = "*") public final class PermissionCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.permission.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/PositionCommand.java b/src/main/java/emu/grasscutter/command/commands/PositionCommand.java index 7f6548c5b..3a3b40a3f 100644 --- a/src/main/java/emu/grasscutter/command/commands/PositionCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/PositionCommand.java @@ -9,10 +9,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "position", usage = "position", aliases = {"pos"}, - description = "Get coordinates.") +@Command(label = "position", usage = "position", aliases = {"pos"}) public final class PositionCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.position.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/ReloadCommand.java b/src/main/java/emu/grasscutter/command/commands/ReloadCommand.java index 6c85d2024..8e3e5e5aa 100644 --- a/src/main/java/emu/grasscutter/command/commands/ReloadCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/ReloadCommand.java @@ -9,10 +9,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "reload", usage = "reload", - description = "Reload server config", permission = "server.reload") +@Command(label = "reload", usage = "reload", permission = "server.reload") public final class ReloadCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.reload.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { CommandHandler.sendMessage(sender, translate("commands.reload.reload_start")); diff --git a/src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java b/src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java index 706fb95e0..9eba8e4c4 100644 --- a/src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/ResetConstCommand.java @@ -11,10 +11,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; @Command(label = "resetconst", usage = "resetconst [all]", - description = "Resets the constellation level on your current active character, will need to relog after using the command to see any changes.", aliases = {"resetconstellation"}, permission = "player.resetconstellation") public final class ResetConstCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.resetConst.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/ResetShopLimitCommand.java b/src/main/java/emu/grasscutter/command/commands/ResetShopLimitCommand.java index aeae0abbf..bba8da32c 100644 --- a/src/main/java/emu/grasscutter/command/commands/ResetShopLimitCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/ResetShopLimitCommand.java @@ -9,9 +9,13 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "resetshop", usage = "resetshop", - description = "Reset target player's shop refresh time.", permission = "server.resetshop") +@Command(label = "resetshop", usage = "resetshop", permission = "server.resetshop") public final class ResetShopLimitCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.status.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/RestartCommand.java b/src/main/java/emu/grasscutter/command/commands/RestartCommand.java index e3b8b2747..2c56ae443 100644 --- a/src/main/java/emu/grasscutter/command/commands/RestartCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/RestartCommand.java @@ -6,9 +6,16 @@ import emu.grasscutter.game.player.Player; import java.util.List; -@Command(label = "restart", usage = "restart - Restarts the current session") +import static emu.grasscutter.utils.Language.translate; + +@Command(label = "restart", usage = "restart") public final class RestartCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.restart.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (sender == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java index 838bea567..a56d68165 100644 --- a/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SendMailCommand.java @@ -13,8 +13,7 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; @SuppressWarnings("ConstantConditions") -@Command(label = "sendmail", usage = "sendmail [templateId]", - description = "Sends mail to the specified user. The usage of this command changes based on it's composition state.", permission = "server.sendmail") +@Command(label = "sendmail", usage = "sendmail [templateId]", permission = "server.sendmail") public final class SendMailCommand implements CommandHandler { // TODO: You should be able to do /sendmail and then just send subsequent messages until you finish @@ -24,6 +23,11 @@ public final class SendMailCommand implements CommandHandler { // Key = User that is constructing the mail. private static final HashMap mailBeingConstructed = new HashMap(); + @Override + public String description() { + return translate("commands.sendMail.description"); + } + // Yes this is awful and I hate it. @Override public void execute(Player sender, Player targetPlayer, List args) { @@ -40,7 +44,7 @@ public final class SendMailCommand implements CommandHandler { MailBuilder mailBuilder; switch (args.get(0).toLowerCase()) { case "help" -> { - CommandHandler.sendMessage(sender, this.getClass().getAnnotation(Command.class).description() + "\nUsage: " + this.getClass().getAnnotation(Command.class).usage()); + CommandHandler.sendMessage(sender, this.description() + "\nUsage: " + this.getClass().getAnnotation(Command.class).usage()); return; } case "all" -> mailBuilder = new MailBuilder(true, new Mail()); diff --git a/src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java b/src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java index acf63dea0..36e53de10 100644 --- a/src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SendMessageCommand.java @@ -8,10 +8,15 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "say", usage = "say ", description = "Sends a message to a player as the server", +@Command(label = "say", usage = "say ", aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage") public final class SendMessageCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.sendMessage.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java b/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java index 7184c679c..e098d99a5 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SetFetterLevelCommand.java @@ -12,10 +12,14 @@ import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; import static emu.grasscutter.utils.Language.translate; @Command(label = "setfetterlevel", usage = "setfetterlevel ", - description = "Sets your fetter level for your current active character", aliases = {"setfetterlvl", "setfriendship"}, permission = "player.setfetterlevel") public final class SetFetterLevelCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.setFetterLevel.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java b/src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java index 233eb4d73..11cb8ab80 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SetStatsCommand.java @@ -15,8 +15,7 @@ import emu.grasscutter.utils.Language; import static emu.grasscutter.utils.Language.translate; -@Command(label = "setstats", usage = "setstats|stats ", - description = "Set fight property for your current active character", aliases = {"stats"}, permission = "player.setstats") +@Command(label = "setstats", usage = "setstats|stats ", aliases = {"stats"}, permission = "player.setstats") public final class SetStatsCommand implements CommandHandler { static class Stat { String name; @@ -174,6 +173,11 @@ public final class SetStatsCommand implements CommandHandler { stats.put("_nonextra_physical_add_hurt", new Stat("NONEXTRA_PHYSICAL_ADD_HURT", FightProperty.FIGHT_PROP_NONEXTRA_PHYSICAL_ADD_HURT, true)); } + @Override + public String description() { + return translate("commands.setStats.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { String syntax = sender == null ? translate("commands.setStats.usage_console") : translate("commands.setStats.ingame"); diff --git a/src/main/java/emu/grasscutter/command/commands/SetWorldLevelCommand.java b/src/main/java/emu/grasscutter/command/commands/SetWorldLevelCommand.java index 914d8cecc..16b10bc6c 100644 --- a/src/main/java/emu/grasscutter/command/commands/SetWorldLevelCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SetWorldLevelCommand.java @@ -10,10 +10,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; @Command(label = "setworldlevel", usage = "setworldlevel ", - description = "Sets your world level (Relog to see proper effects)", aliases = {"setworldlvl"}, permission = "player.setworldlevel") public final class SetWorldLevelCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.setWorldLevel.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java index c66a45b50..8a995402b 100644 --- a/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/SpawnCommand.java @@ -22,10 +22,14 @@ import java.util.Random; import static emu.grasscutter.utils.Language.translate; -@Command(label = "spawn", usage = "spawn [amount] [level(monster only)]", - description = "Spawns an entity near you", permission = "server.spawn") +@Command(label = "spawn", usage = "spawn [amount] [level(monster only)]", permission = "server.spawn") public final class SpawnCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.spawn.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/StopCommand.java b/src/main/java/emu/grasscutter/command/commands/StopCommand.java index ad4903107..64326a748 100644 --- a/src/main/java/emu/grasscutter/command/commands/StopCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/StopCommand.java @@ -9,10 +9,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "stop", usage = "stop", - description = "Stops the server", permission = "server.stop") +@Command(label = "stop", usage = "stop", permission = "server.stop") public final class StopCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.stop.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { CommandHandler.sendMessage(null, translate("commands.stop.success")); diff --git a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java index c9b2e8931..ca1bff76d 100644 --- a/src/main/java/emu/grasscutter/command/commands/TalentCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TalentCommand.java @@ -14,8 +14,7 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "talent", usage = "talent ", - description = "Set talent level for your current active character", permission = "player.settalent") +@Command(label = "talent", usage = "talent ", permission = "player.settalent") public final class TalentCommand implements CommandHandler { private void setTalentLevel(Player sender, Player player, Avatar avatar, int talentId, int talentLevel) { int oldLevel = avatar.getSkillLevelMap().get(talentId); @@ -44,6 +43,11 @@ public final class TalentCommand implements CommandHandler { CommandHandler.sendMessage(sender, translate(successMessage, talentLevel)); } + @Override + public String description() { + return translate("commands.talent.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java b/src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java index 54c6101f7..d25e73f96 100644 --- a/src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TeleportAllCommand.java @@ -10,9 +10,13 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "tpall", usage = "tpall", - description = "Teleports all players in your world to your position", permission = "player.tpall") +@Command(label = "tpall", usage = "tpall", permission = "player.tpall") public final class TeleportAllCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.teleportAll.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java b/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java index 06b669a17..364e4188f 100644 --- a/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java @@ -10,8 +10,7 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "teleport", usage = "teleport [scene id]", aliases = {"tp"}, - description = "Change the player's position.", permission = "player.teleport") +@Command(label = "teleport", usage = "teleport [scene id]", aliases = {"tp"}, permission = "player.teleport") public final class TeleportCommand implements CommandHandler { private float parseRelative(String input, Float current) { // TODO: Maybe this will be useful elsewhere later @@ -25,6 +24,11 @@ public final class TeleportCommand implements CommandHandler { return current; } + @Override + public String description() { + return translate("commands.teleport.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/command/commands/WeatherCommand.java b/src/main/java/emu/grasscutter/command/commands/WeatherCommand.java index df8a6a01f..d2a6c5f64 100644 --- a/src/main/java/emu/grasscutter/command/commands/WeatherCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/WeatherCommand.java @@ -11,10 +11,14 @@ import java.util.List; import static emu.grasscutter.utils.Language.translate; -@Command(label = "weather", usage = "weather [climateId]", - description = "Changes the weather.", aliases = {"w"}, permission = "player.weather") +@Command(label = "weather", usage = "weather [climateId]", aliases = {"w"}, permission = "player.weather") public final class WeatherCommand implements CommandHandler { + @Override + public String description() { + return translate("commands.weather.description"); + } + @Override public void execute(Player sender, Player targetPlayer, List args) { if (targetPlayer == null) { diff --git a/src/main/java/emu/grasscutter/tools/Tools.java b/src/main/java/emu/grasscutter/tools/Tools.java index d9923a656..b5558833f 100644 --- a/src/main/java/emu/grasscutter/tools/Tools.java +++ b/src/main/java/emu/grasscutter/tools/Tools.java @@ -21,6 +21,7 @@ import com.google.gson.reflect.TypeToken; import emu.grasscutter.GameConstants; import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandMap; import emu.grasscutter.data.GameData; import emu.grasscutter.data.ResourceLoader; @@ -112,17 +113,16 @@ final class ToolsWithLanguageOption { writer.println("// Created " + dtf.format(now) + System.lineSeparator() + System.lineSeparator()); CommandMap cmdMap = new CommandMap(true); - List cmdList = new ArrayList<>(cmdMap.getAnnotationsAsList()); + HashMap cmdList = cmdMap.getHandlersAndAnnotations(); writer.println("// Commands"); - for (Command cmd : cmdList) { - String cmdName = cmd.label(); + cmdList.forEach((handler, command) -> { + String cmdName = command.label(); while (cmdName.length() <= 15) { cmdName = " " + cmdName; } - writer.println(cmdName + " : " + cmd.description()); - } - + writer.println(cmdName + " : " + handler.description()); + }); writer.println(); list = new ArrayList<>(GameData.getAvatarDataMap().keySet()); diff --git a/src/main/resources/languages/en-US.json b/src/main/resources/languages/en-US.json index fb33ba287..438674e9c 100644 --- a/src/main/resources/languages/en-US.json +++ b/src/main/resources/languages/en-US.json @@ -95,17 +95,20 @@ "create": "Account created with UID %s.", "delete": "Account deleted.", "no_account": "Account not found.", - "command_usage": "Usage: account [uid]" + "command_usage": "Usage: account [uid]", + "description": "Modify user accounts" }, "broadcast": { "command_usage": "Usage: broadcast ", - "message_sent": "Message sent." + "message_sent": "Message sent.", + "description": "Sends a message to all the players" }, "changescene": { "usage": "Usage: changescene ", "already_in_scene": "You are already in that scene.", "success": "Changed to scene %s.", - "exists_error": "The specified scene does not exist." + "exists_error": "The specified scene does not exist.", + "description": "Changes your scene" }, "clear": { "command_usage": "Usage: clear ", @@ -115,35 +118,41 @@ "furniture": "Cleared furniture for %s.", "displays": "Cleared displays for %s.", "virtuals": "Cleared virtuals for %s.", - "everything": "Cleared everything for %s." + "everything": "Cleared everything for %s.", + "description": "Deletes unequipped unlocked items, including yellow rarity ones from your inventory" }, "coop": { "usage": "Usage: coop ", - "success": "Summoned %s to %s's world." + "success": "Summoned %s to %s's world.", + "description": "Forces someone to join the world of others" }, "enter_dungeon": { "usage": "Usage: enterdungeon ", "changed": "Changed to dungeon %s", "not_found_error": "Dungeon does not exist", - "in_dungeon_error": "You are already in that dungeon" + "in_dungeon_error": "You are already in that dungeon", + "description": "Enter a dungeon" }, "giveAll": { "usage": "Usage: giveall [player] [amount]", "started": "Receiving all items...", "success": "Successfully gave all items to %s.", - "invalid_amount_or_playerId": "Invalid amount or player ID." + "invalid_amount_or_playerId": "Invalid amount or player ID.", + "description": "Gives all items" }, "giveArtifact": { "usage": "Usage: giveart|gart [player] [[,]]... [level]", "id_error": "Invalid artifact ID.", - "success": "Given %s to %s." + "success": "Given %s to %s.", + "description": "Gives the player a specified artifact" }, "giveChar": { "usage": "Usage: givechar [amount]", "given": "Given %s with level %s to %s.", "invalid_avatar_id": "Invalid avatar id.", "invalid_avatar_level": "Invalid avatar level.", - "invalid_avatar_or_player_id": "Invalid avatar or player ID." + "invalid_avatar_or_player_id": "Invalid avatar or player ID.", + "description": "Gives the player a specified character" }, "give": { "usage": "Usage: give [amount] [level]", @@ -151,29 +160,36 @@ "refinement_must_between_1_and_5": "Refinement must be between 1 and 5.", "given": "Given %s of %s to %s.", "given_with_level_and_refinement": "Given %s with level %s, refinement %s %s times to %s", - "given_level": "Given %s with level %s %s times to %s" + "given_level": "Given %s with level %s %s times to %s", + "description": "Gives an item to you or the specified player" }, "godmode": { - "success": "Godmode is now %s for %s." + "success": "Godmode is now %s for %s.", + "description": "Prevents you from taking damage. Defaults to toggle." }, "heal": { - "success": "All characters have been healed." + "success": "All characters have been healed.", + "description": "Heal all characters in your current team." }, "kick": { "player_kick_player": "Player [%s:%s] has kicked player [%s:%s]", - "server_kick_player": "Kicking player [%s:%s]" + "server_kick_player": "Kicking player [%s:%s]", + "description": "Kicks the specified player from the server (WIP)" }, "kill": { "usage": "Usage: killall [playerUid] [sceneId]", "scene_not_found_in_player_world": "Scene not found in player world", - "kill_monsters_in_scene": "Killing %s monsters in scene %s" + "kill_monsters_in_scene": "Killing %s monsters in scene %s", + "description": "Kill all entities" }, "killCharacter": { "usage": "Usage: /killcharacter [playerId]", - "success": "Killed %s's current character." + "success": "Killed %s's current character.", + "description": "Kills the players current character" }, "list": { - "success": "There are %s player(s) online:" + "success": "There are %s player(s) online:", + "description": "List online players" }, "permission": { "usage": "Usage: permission ", @@ -181,21 +197,26 @@ "has_error": "They already have this permission!", "remove": "Permission removed.", "not_have_error": "They don't have this permission!", - "account_error": "The account cannot be found." + "account_error": "The account cannot be found.", + "description": "Grants or removes a permission for a user" }, "position": { - "success": "Coordinates: %s, %s, %s\nScene id: %s" + "success": "Coordinates: %s, %s, %s\nScene id: %s", + "description": "Get coordinates." }, "reload": { "reload_start": "Reloading config.", - "reload_done": "Reload complete." + "reload_done": "Reload complete.", + "description": "Reload server config" }, "resetConst": { "reset_all": "Reset all avatars' constellations.", - "success": "Constellations for %s have been reset. Please relog to see changes." + "success": "Constellations for %s have been reset. Please relog to see changes.", + "description": "Resets the constellation level on your current active character, will need to relog after using the command to see any changes." }, "resetShopLimit": { - "usage": "Usage: /resetshop " + "usage": "Usage: /resetshop ", + "description": "Reset target player's shop refresh time." }, "sendMail": { "usage": "Usage: give [player] [amount]", @@ -217,17 +238,20 @@ "message": "", "sender": "", "arguments": " [amount] [level]", - "error": "ERROR: invalid construction stage %s. Check console for stacktrace." + "error": "ERROR: invalid construction stage %s. Check console for stacktrace.", + "description": "Sends mail to the specified user. The usage of this command changes based on it's composition state." }, "sendMessage": { "usage": "Usage: sendmessage ", - "success": "Message sent." + "success": "Message sent.", + "description": "Sends a message to a player as the server" }, "setFetterLevel": { "usage": "Usage: setfetterlevel ", "range_error": "Fetter level must be between 0 and 10.", "success": "Fetter level set to %s", - "level_error": "Invalid fetter level." + "level_error": "Invalid fetter level.", + "description": "Sets your fetter level for your current active character" }, "setStats": { "usage_console": "Usage: setstats|stats @ ", @@ -238,20 +262,24 @@ "player_error": "Player not found or offline.", "set_self": "%s set to %s.", "set_for_uid": "%s for %s set to %s.", - "set_max_hp": "MAX HP set to %s." + "set_max_hp": "MAX HP set to %s.", + "description": "Set fight property for your current active character" }, "setWorldLevel": { "usage": "Usage: setworldlevel ", "value_error": "World level must be between 0-8", "success": "World level set to %s.", - "invalid_world_level": "Invalid world level." + "invalid_world_level": "Invalid world level.", + "description": "Sets your world level (Relog to see proper effects)" }, "spawn": { "usage": "Usage: spawn [amount] [level(monster only)]", - "success": "Spawned %s of %s." + "success": "Spawned %s of %s.", + "description": "Spawns an entity near you" }, "stop": { - "success": "Server shutting down..." + "success": "Server shutting down...", + "description": "Stops the server" }, "talent": { "usage_1": "To set talent level: /talent set ", @@ -267,32 +295,41 @@ "invalid_level": "Invalid talent level.", "normal_attack_id": "Normal Attack ID %s.", "e_skill_id": "E skill ID %s.", - "q_skill_id": "Q skill ID %s." + "q_skill_id": "Q skill ID %s.", + "description": "Set talent level for your current active character" }, "teleportAll": { "success": "Summoned all players to your location.", - "error": "You only can use this command in MP mode." + "error": "You only can use this command in MP mode.", + "description": "Teleports all players in your world to your position" }, "teleport": { "usage_server": "Usage: /tp @ [scene id]", "usage": "Usage: /tp [@] [scene id]", "specify_player_id": "You must specify a player id.", "invalid_position": "Invalid position.", - "success": "Teleported %s to %s, %s, %s in scene %s" + "success": "Teleported %s to %s, %s, %s in scene %s", + "description": "Change the player's position." }, "weather": { "usage": "Usage: weather [climateId]", "success": "Changed weather to %s with climate %s", - "invalid_id": "Invalid ID." + "invalid_id": "Invalid ID.", + "description": "Changes the weather." }, "drop": { "command_usage": "Usage: drop [amount]", - "success": "Dropped %s of %s." + "success": "Dropped %s of %s.", + "description": "Drops an item near you" }, "help": { "usage": "Usage: ", "aliases": "Aliases: ", - "available_commands": "Available commands: " + "available_commands": "Available commands: ", + "description": "Sends the help message or shows information about a specified command" + }, + "restart": { + "description": "Restarts the current session" } } }