Commit a46d58e5 authored by 方块君's avatar 方块君 Committed by Melledy
Browse files

Add command description multilingual

parent 257a92f3
...@@ -9,8 +9,6 @@ public @interface Command { ...@@ -9,8 +9,6 @@ public @interface Command {
String usage() default "No usage specified"; String usage() default "No usage specified";
String description() default "No description specified";
String[] aliases() default {}; String[] aliases() default {};
String permission() default ""; String permission() default "";
......
...@@ -6,6 +6,9 @@ import emu.grasscutter.game.player.Player; ...@@ -6,6 +6,9 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
public interface CommandHandler { public interface CommandHandler {
String description();
/** /**
* Send a message to the target. * Send a message to the target.
* *
......
...@@ -85,6 +85,14 @@ public final class CommandMap { ...@@ -85,6 +85,14 @@ public final class CommandMap {
return new LinkedHashMap<>(this.annotations); return new LinkedHashMap<>(this.annotations);
} }
public HashMap<CommandHandler, Command> getHandlersAndAnnotations() {
HashMap<CommandHandler, Command> hashMap = new HashMap<>();
this.commands.forEach((key, handler) -> {
hashMap.put(handler, this.annotations.get(key));
});
return hashMap;
}
/** /**
* Returns a list of all registered commands. * Returns a list of all registered commands.
* *
......
...@@ -9,9 +9,14 @@ import java.util.List; ...@@ -9,9 +9,14 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "account", usage = "account <create|delete> <username> [uid]", description = "Modify user accounts") @Command(label = "account", usage = "account <create|delete> <username> [uid]")
public final class AccountCommand implements CommandHandler { public final class AccountCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.account.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender != null) { if (sender != null) {
......
...@@ -9,10 +9,14 @@ import java.util.List; ...@@ -9,10 +9,14 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "broadcast", usage = "broadcast <message>", @Command(label = "broadcast", usage = "broadcast <message>", aliases = {"b"}, permission = "server.broadcast")
description = "Sends a message to all the players", aliases = {"b"}, permission = "server.broadcast")
public final class BroadcastCommand implements CommandHandler { public final class BroadcastCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.broadcast.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 1) { if (args.size() < 1) {
......
...@@ -8,9 +8,13 @@ import java.util.List; ...@@ -8,9 +8,13 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "changescene", usage = "changescene <scene id>", @Command(label = "changescene", usage = "changescene <scene id>", aliases = {"scene"}, permission = "player.changescene")
description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene")
public final class ChangeSceneCommand implements CommandHandler { public final class ChangeSceneCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.changescene.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -13,11 +13,15 @@ import java.util.List; ...@@ -13,11 +13,15 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "clear", usage = "clear <all|wp|art|mat>", //Merged /clearartifacts and /clearweapons to /clear <args> [uid] @Command(label = "clear", usage = "clear <all|wp|art|mat>", //Merged /clearartifacts and /clearweapons to /clear <args> [uid]
description = "Deletes unequipped unlocked items, including yellow rarity ones from your inventory",
aliases = {"clear"}, permission = "player.clearinv") aliases = {"clear"}, permission = "player.clearinv")
public final class ClearCommand implements CommandHandler { public final class ClearCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.clear.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -9,9 +9,13 @@ import java.util.List; ...@@ -9,9 +9,13 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "coop", usage = "coop [host UID]", @Command(label = "coop", usage = "coop [host UID]", permission = "server.coop")
description = "Forces someone to join the world of others", permission = "server.coop")
public final class CoopCommand implements CommandHandler { public final class CoopCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.coop.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -13,10 +13,14 @@ import java.util.List; ...@@ -13,10 +13,14 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "drop", usage = "drop <itemId|itemName> [amount]", @Command(label = "drop", usage = "drop <itemId|itemName> [amount]", aliases = {"d", "dropitem"}, permission = "server.drop")
description = "Drops an item near you", aliases = {"d", "dropitem"}, permission = "server.drop")
public final class DropCommand implements CommandHandler { public final class DropCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.drop.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -8,9 +8,13 @@ import java.util.List; ...@@ -8,9 +8,13 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "enterdungeon", usage = "enterdungeon <dungeon id>", @Command(label = "enterdungeon", usage = "enterdungeon <dungeon id>", aliases = {"dungeon"}, permission = "player.enterdungeon")
description = "Enter a dungeon", aliases = {"dungeon"}, permission = "player.enterdungeon")
public final class EnterDungeonCommand implements CommandHandler { public final class EnterDungeonCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.enter_dungeon.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -15,10 +15,14 @@ import java.util.*; ...@@ -15,10 +15,14 @@ import java.util.*;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "giveall", usage = "giveall [amount]", @Command(label = "giveall", usage = "giveall [amount]", aliases = {"givea"}, permission = "player.giveall", threading = true)
description = "Gives all items", aliases = {"givea"}, permission = "player.giveall", threading = true)
public final class GiveAllCommand implements CommandHandler { public final class GiveAllCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.giveAll.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -16,8 +16,13 @@ import java.util.List; ...@@ -16,8 +16,13 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "giveart", usage = "giveart <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]", description = "Gives the player a specified artifact", aliases = {"gart"}, permission = "player.giveart") @Command(label = "giveart", usage = "giveart <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]", aliases = {"gart"}, permission = "player.giveart")
public final class GiveArtifactCommand implements CommandHandler { public final class GiveArtifactCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.giveArtifact.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -12,10 +12,14 @@ import java.util.List; ...@@ -12,10 +12,14 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "givechar", usage = "givechar <avatarId> [level]", @Command(label = "givechar", usage = "givechar <avatarId> [level]", aliases = {"givec"}, permission = "player.givechar")
description = "Gives the player a specified character", aliases = {"givec"}, permission = "player.givechar")
public final class GiveCharCommand implements CommandHandler { public final class GiveCharCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.giveChar.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
...@@ -12,12 +11,12 @@ import emu.grasscutter.game.props.ActionReason; ...@@ -12,12 +11,12 @@ import emu.grasscutter.game.props.ActionReason;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "give", usage = "give <itemId|itemName> [amount] [level]", description = "Gives an item to you or the specified player", aliases = { @Command(label = "give", usage = "give <itemId|itemName> [amount] [level]", aliases = {
"g", "item", "giveitem"}, permission = "player.give") "g", "item", "giveitem"}, permission = "player.give")
public final class GiveCommand implements CommandHandler { 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 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 { ...@@ -32,6 +31,11 @@ public final class GiveCommand implements CommandHandler {
return -1; return -1;
} }
@Override
public String description() {
return translate("commands.give.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
...@@ -9,10 +8,14 @@ import java.util.List; ...@@ -9,10 +8,14 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "godmode", usage = "godmode [on|off|toggle]", @Command(label = "godmode", usage = "godmode [on|off|toggle]", permission = "player.godmode")
description = "Prevents you from taking damage. Defaults to toggle.", permission = "player.godmode")
public final class GodModeCommand implements CommandHandler { public final class GodModeCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.godmode.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -11,9 +11,13 @@ import java.util.List; ...@@ -11,9 +11,13 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "heal", usage = "heal|h", aliases = {"h"}, @Command(label = "heal", usage = "heal|h", aliases = {"h"}, permission = "player.heal")
description = "Heal all characters in your current team.", permission = "player.heal")
public final class HealCommand implements CommandHandler { public final class HealCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.heal.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -10,22 +10,26 @@ import java.util.*; ...@@ -10,22 +10,26 @@ import java.util.*;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "help", usage = "help [command]", @Command(label = "help", usage = "help [command]")
description = "Sends the help message or shows information about a specified command")
public final class HelpCommand implements CommandHandler { public final class HelpCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.help.description");
}
@Override @Override
public void execute(Player player, Player targetPlayer, List<String> args) { public void execute(Player player, Player targetPlayer, List<String> args) {
if (args.size() < 1) { if (args.size() < 1) {
HashMap<String, CommandHandler> handlers = CommandMap.getInstance().getHandlers(); HashMap<String, CommandHandler> handlers = CommandMap.getInstance().getHandlers();
List<Command> annotations = new ArrayList<>(); HashMap<Command, CommandHandler> annotations = new HashMap<>();
for (String key : handlers.keySet()) { for (String key : handlers.keySet()) {
Command annotation = handlers.get(key).getClass().getAnnotation(Command.class); Command annotation = handlers.get(key).getClass().getAnnotation(Command.class);
if (!Arrays.asList(annotation.aliases()).contains(key)) { if (!Arrays.asList(annotation.aliases()).contains(key)) {
if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission()))
continue; continue;
annotations.add(annotation); annotations.put(annotation, handlers.get(key));
} }
} }
...@@ -39,7 +43,7 @@ public final class HelpCommand implements CommandHandler { ...@@ -39,7 +43,7 @@ public final class HelpCommand implements CommandHandler {
} else { } else {
Command annotation = handler.getClass().getAnnotation(Command.class); 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()); builder.append(translate("commands.help.usage")).append(annotation.usage());
if (annotation.aliases().length >= 1) { if (annotation.aliases().length >= 1) {
builder.append("\n").append(translate("commands.help.aliases")); builder.append("\n").append(translate("commands.help.aliases"));
...@@ -56,12 +60,12 @@ public final class HelpCommand implements CommandHandler { ...@@ -56,12 +60,12 @@ public final class HelpCommand implements CommandHandler {
} }
} }
void SendAllHelpMessage(Player player, List<Command> annotations) { void SendAllHelpMessage(Player player, HashMap<Command, CommandHandler> annotations) {
if (player == null) { if (player == null) {
StringBuilder builder = new StringBuilder("\n" + translate("commands.help.available_commands") + "\n"); 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(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()); builder.append(translate("commands.help.usage")).append(annotation.usage());
if (annotation.aliases().length >= 1) { if (annotation.aliases().length >= 1) {
builder.append("\n").append(translate("commands.help.aliases")); builder.append("\n").append(translate("commands.help.aliases"));
...@@ -76,9 +80,9 @@ public final class HelpCommand implements CommandHandler { ...@@ -76,9 +80,9 @@ public final class HelpCommand implements CommandHandler {
CommandHandler.sendMessage(null, builder.toString()); CommandHandler.sendMessage(null, builder.toString());
} else { } else {
CommandHandler.sendMessage(player, translate("commands.help.available_commands")); CommandHandler.sendMessage(player, translate("commands.help.available_commands"));
annotations.forEach(annotation -> { annotations.forEach((annotation, handler) -> {
StringBuilder builder = new StringBuilder(annotation.label()).append("\n"); 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()); builder.append(translate("commands.help.usage")).append(annotation.usage());
if (annotation.aliases().length >= 1) { if (annotation.aliases().length >= 1) {
builder.append("\n").append(translate("commands.help.aliases")); builder.append("\n").append(translate("commands.help.aliases"));
......
...@@ -8,10 +8,14 @@ import java.util.List; ...@@ -8,10 +8,14 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "kick", usage = "kick", @Command(label = "kick", usage = "kick", permission = "server.kick")
description = "Kicks the specified player from the server (WIP)", permission = "server.kick")
public final class KickCommand implements CommandHandler { public final class KickCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.kick.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -12,10 +12,14 @@ import java.util.List; ...@@ -12,10 +12,14 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "killall", usage = "killall [sceneId]", @Command(label = "killall", usage = "killall [sceneId]", permission = "server.killall")
description = "Kill all entities", permission = "server.killall")
public final class KillAllCommand implements CommandHandler { public final class KillAllCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.kill.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
...@@ -13,10 +13,14 @@ import java.util.List; ...@@ -13,10 +13,14 @@ import java.util.List;
import static emu.grasscutter.utils.Language.translate; import static emu.grasscutter.utils.Language.translate;
@Command(label = "killcharacter", usage = "killcharacter", aliases = {"suicide", "kill"}, @Command(label = "killcharacter", usage = "killcharacter", aliases = {"suicide", "kill"}, permission = "player.killcharacter")
description = "Kills the players current character", permission = "player.killcharacter")
public final class KillCharacterCommand implements CommandHandler { public final class KillCharacterCommand implements CommandHandler {
@Override
public String description() {
return translate("commands.killCharacter.description");
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment