mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-25 04:15:34 +08:00
Refactor Command usage and description strings
This commit is contained in:
parent
e9464784bb
commit
2cfbe78184
@ -7,14 +7,12 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
public @interface Command {
|
public @interface Command {
|
||||||
String label() default "";
|
String label() default "";
|
||||||
|
|
||||||
String usage() default "commands.generic.no_usage_specified";
|
|
||||||
|
|
||||||
String description() default "commands.generic.no_description_specified";
|
|
||||||
|
|
||||||
String[] aliases() default {};
|
String[] aliases() default {};
|
||||||
|
|
||||||
|
String[] usage() default {""};
|
||||||
|
|
||||||
String permission() default "";
|
String permission() default "";
|
||||||
|
|
||||||
String permissionTargeted() default "";
|
String permissionTargeted() default "";
|
||||||
|
|
||||||
public enum TargetRequirement {
|
public enum TargetRequirement {
|
||||||
|
@ -2,12 +2,11 @@ package emu.grasscutter.command;
|
|||||||
|
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.server.event.game.CommandResponseEvent;
|
|
||||||
import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent;
|
import emu.grasscutter.server.event.game.ReceiveCommandFeedbackEvent;
|
||||||
import emu.grasscutter.server.event.types.ServerEvent;
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
public interface CommandHandler {
|
public interface CommandHandler {
|
||||||
|
|
||||||
@ -37,6 +36,42 @@ public interface CommandHandler {
|
|||||||
sendMessage(player, translate(player, messageKey, args));
|
sendMessage(player, translate(player, messageKey, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default String getUsageString(Player player, String... args) {
|
||||||
|
Command annotation = this.getClass().getAnnotation(Command.class);
|
||||||
|
String usage_prefix = translate(player, "commands.execution.usage_prefix");
|
||||||
|
String command = annotation.label();
|
||||||
|
for (String alias : annotation.aliases()) {
|
||||||
|
if (alias.length() < command.length())
|
||||||
|
command = alias;
|
||||||
|
}
|
||||||
|
String target = switch (annotation.targetRequirement()) {
|
||||||
|
case NONE -> "";
|
||||||
|
case OFFLINE -> "@<UID> "; // TODO: make translation keys for offline and online players
|
||||||
|
case ONLINE -> (player == null) ? "@<UID> " : "[@<UID>] "; // TODO: make translation keys for offline and online players
|
||||||
|
case PLAYER -> (player == null) ? "@<UID> " : "[@<UID>] ";
|
||||||
|
};
|
||||||
|
String[] usages = annotation.usage();
|
||||||
|
StringJoiner joiner = new StringJoiner("\n\t");
|
||||||
|
for (String usage : usages)
|
||||||
|
joiner.add(usage_prefix + command + " " + target + usage);
|
||||||
|
return joiner.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
default void sendUsageMessage(Player player, String... args) {
|
||||||
|
sendMessage(player, getUsageString(player, args));
|
||||||
|
}
|
||||||
|
|
||||||
|
default String getLabel() {
|
||||||
|
return this.getClass().getAnnotation(Command.class).label();
|
||||||
|
}
|
||||||
|
|
||||||
|
default String getDescriptionString(Player player) {
|
||||||
|
Command annotation = this.getClass().getAnnotation(Command.class);
|
||||||
|
String key = "commands.%s.description".formatted(annotation.label());
|
||||||
|
// TODO: fallback to "commands.generic.no_description_specified"
|
||||||
|
return translate(player, key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player/console invokes a command.
|
* Called when a player/console invokes a command.
|
||||||
* @param sender The player/console that invoked the command.
|
* @param sender The player/console that invoked the command.
|
||||||
|
@ -8,9 +8,9 @@ import java.util.*;
|
|||||||
|
|
||||||
@SuppressWarnings({"UnusedReturnValue", "unused"})
|
@SuppressWarnings({"UnusedReturnValue", "unused"})
|
||||||
public final class CommandMap {
|
public final class CommandMap {
|
||||||
private final Map<String, CommandHandler> commands = new HashMap<>();
|
private final Map<String, CommandHandler> commands = new LinkedHashMap<>();
|
||||||
private final Map<String, CommandHandler> aliases = new HashMap<>();
|
private final Map<String, CommandHandler> aliases = new LinkedHashMap<>();
|
||||||
private final Map<String, Command> annotations = new HashMap<>();
|
private final Map<String, Command> annotations = new LinkedHashMap<>();
|
||||||
private final Map<String, Integer> targetPlayerIds = new HashMap<>();
|
private final Map<String, Integer> targetPlayerIds = new HashMap<>();
|
||||||
private static final String consoleId = "console";
|
private static final String consoleId = "console";
|
||||||
|
|
||||||
|
@ -13,18 +13,24 @@ 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|resetpass> <username> [uid|password] [uid] ", description = "commands.account.description", targetRequirement = Command.TargetRequirement.NONE)
|
@Command(
|
||||||
|
label = "account",
|
||||||
|
usage = {
|
||||||
|
"create <username> [<UID>]", // Only with EXPERIMENTAL_RealPassword == false
|
||||||
|
"delete <username>",
|
||||||
|
"create <username> <password> [<UID>]", // Only with EXPERIMENTAL_RealPassword == true
|
||||||
|
"resetpass <username> <password>"}, // Only with EXPERIMENTAL_RealPassword == true
|
||||||
|
targetRequirement = Command.TargetRequirement.NONE)
|
||||||
public final class AccountCommand implements CommandHandler {
|
public final class AccountCommand implements CommandHandler {
|
||||||
|
|
||||||
@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) {
|
||||||
CommandHandler.sendMessage(sender, translate(sender, "commands.generic.console_execute_error"));
|
CommandHandler.sendTranslatedMessage(sender, "commands.generic.console_execute_error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size() < 2) {
|
if (args.size() < 2) {
|
||||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.command_usage"));
|
CommandHandler.sendTranslatedMessage(sender, "commands.account.command_usage");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,17 +39,16 @@ public final class AccountCommand implements CommandHandler {
|
|||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
default:
|
default:
|
||||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.command_usage"));
|
CommandHandler.sendTranslatedMessage(sender, "commands.account.command_usage");
|
||||||
return;
|
return;
|
||||||
case "create":
|
case "create":
|
||||||
int uid = 0;
|
int uid = 0;
|
||||||
String password = "";
|
String password = "";
|
||||||
|
|
||||||
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
if(Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
||||||
if (args.size() < 3) {
|
if(args.size() < 3) {
|
||||||
CommandHandler.sendMessage(null, "EXPERIMENTAL_RealPassword requires a password argument");
|
CommandHandler.sendMessage(sender, "EXPERIMENTAL_RealPassword requires a password argument");
|
||||||
CommandHandler.sendMessage(null, "Usage: account create <username> <password> [uid]");
|
CommandHandler.sendMessage(sender, "Usage: account create <username> <password> [uid]");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
password = args.get(2);
|
password = args.get(2);
|
||||||
@ -52,10 +57,10 @@ public final class AccountCommand implements CommandHandler {
|
|||||||
try {
|
try {
|
||||||
uid = Integer.parseInt(args.get(3));
|
uid = Integer.parseInt(args.get(3));
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.invalid"));
|
CommandHandler.sendMessage(sender, translate(sender, "commands.account.invalid"));
|
||||||
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
if(Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
||||||
CommandHandler.sendMessage(null, "EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid");
|
CommandHandler.sendMessage(sender, "EXPERIMENTAL_RealPassword requires argument 2 to be a password, not a uid");
|
||||||
CommandHandler.sendMessage(null, "Usage: account create <username> <password> [uid]");
|
CommandHandler.sendMessage(sender, "Usage: account create <username> <password> [uid]");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -65,7 +70,7 @@ public final class AccountCommand implements CommandHandler {
|
|||||||
try {
|
try {
|
||||||
uid = Integer.parseInt(args.get(2));
|
uid = Integer.parseInt(args.get(2));
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.invalid"));
|
CommandHandler.sendMessage(sender, translate(sender, "commands.account.invalid"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,7 +78,7 @@ public final class AccountCommand implements CommandHandler {
|
|||||||
|
|
||||||
emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithUid(username, uid);
|
emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithUid(username, uid);
|
||||||
if (account == null) {
|
if (account == null) {
|
||||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.exists"));
|
CommandHandler.sendMessage(sender, translate(sender, "commands.account.exists"));
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword == true) {
|
||||||
@ -82,7 +87,7 @@ public final class AccountCommand implements CommandHandler {
|
|||||||
account.addPermission("*");
|
account.addPermission("*");
|
||||||
account.save(); // Save account to database.
|
account.save(); // Save account to database.
|
||||||
|
|
||||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.create", Integer.toString(account.getReservedPlayerUid())));
|
CommandHandler.sendMessage(sender, translate(sender, "commands.account.create", Integer.toString(account.getReservedPlayerUid())));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case "delete":
|
case "delete":
|
||||||
@ -90,51 +95,50 @@ public final class AccountCommand implements CommandHandler {
|
|||||||
Account toDelete = DatabaseHelper.getAccountByName(username);
|
Account toDelete = DatabaseHelper.getAccountByName(username);
|
||||||
|
|
||||||
if (toDelete == null) {
|
if (toDelete == null) {
|
||||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.no_account"));
|
CommandHandler.sendMessage(sender, translate(sender, "commands.account.no_account"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the player for the account.
|
// Make sure player isn't online as we delete their account.
|
||||||
// If that player is currently online, we kick them before proceeding with the deletion.
|
kickAccount(toDelete);
|
||||||
Player player = Grasscutter.getGameServer().getPlayerByAccountId(toDelete.getId());
|
|
||||||
if (player != null) {
|
|
||||||
player.getSession().close();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, we do the actual deletion.
|
// Finally, we do the actual deletion.
|
||||||
DatabaseHelper.deleteAccount(toDelete);
|
DatabaseHelper.deleteAccount(toDelete);
|
||||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.delete"));
|
CommandHandler.sendMessage(sender, translate(sender, "commands.account.delete"));
|
||||||
return;
|
return;
|
||||||
case "resetpass":
|
case "resetpass":
|
||||||
if (Configuration.ACCOUNT.EXPERIMENTAL_RealPassword != true) {
|
if(Configuration.ACCOUNT.EXPERIMENTAL_RealPassword != true) {
|
||||||
CommandHandler.sendMessage(null, "resetpass requires EXPERIMENTAL_RealPassword to be true.");
|
CommandHandler.sendMessage(sender, "resetpass requires EXPERIMENTAL_RealPassword to be true.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.size() != 3) {
|
if(args.size() != 3) {
|
||||||
CommandHandler.sendMessage(null, "Invalid Args");
|
CommandHandler.sendMessage(sender, "Invalid Args");
|
||||||
CommandHandler.sendMessage(null, "Usage: account resetpass <username> <password>");
|
CommandHandler.sendMessage(sender, "Usage: account resetpass <username> <password>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Account toUpdate = DatabaseHelper.getAccountByName(username);
|
Account toUpdate = DatabaseHelper.getAccountByName(username);
|
||||||
|
|
||||||
if (toUpdate == null) {
|
if (toUpdate == null) {
|
||||||
CommandHandler.sendMessage(null, translate(sender, "commands.account.no_account"));
|
CommandHandler.sendMessage(sender, translate(sender, "commands.account.no_account"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the player for the account.
|
// Make sure player can't stay logged in with old password.
|
||||||
// If that player is currently online, we kick them before proceeding with the deletion.
|
kickAccount(toUpdate);
|
||||||
Player uPlayer = Grasscutter.getGameServer().getPlayerByAccountId(toUpdate.getId());
|
|
||||||
if (uPlayer != null) {
|
|
||||||
uPlayer.getSession().close();
|
|
||||||
}
|
|
||||||
|
|
||||||
toUpdate.setPassword(BCrypt.withDefaults().hashToString(12, args.get(2).toCharArray()));
|
toUpdate.setPassword(BCrypt.withDefaults().hashToString(12, args.get(2).toCharArray()));
|
||||||
toUpdate.save();
|
toUpdate.save();
|
||||||
CommandHandler.sendMessage(null, "Password Updated.");
|
CommandHandler.sendMessage(sender, "Password Updated.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void kickAccount(Account account) {
|
||||||
|
Player player = Grasscutter.getGameServer().getPlayerByAccountId(account.getId());
|
||||||
|
if (player != null) {
|
||||||
|
player.getSession().close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,9 @@ import java.util.Random;
|
|||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "announce",
|
@Command(label = "announce",
|
||||||
usage = "announce|a <\"tpl\" templateId|\"refresh\"|\"revoke\" templateId|content>",
|
usage = {"<content>", "refresh", "(tpl|revoke) <templateId>"},
|
||||||
permission = "server.announce",
|
permission = "server.announce",
|
||||||
aliases = {"a"},
|
aliases = {"a"},
|
||||||
description = "commands.announce.description",
|
|
||||||
targetRequirement = Command.TargetRequirement.NONE)
|
targetRequirement = Command.TargetRequirement.NONE)
|
||||||
public final class AnnounceCommand implements CommandHandler {
|
public final class AnnounceCommand implements CommandHandler {
|
||||||
|
|
||||||
|
@ -10,8 +10,7 @@ import emu.grasscutter.server.game.GameSession;
|
|||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
label = "ban",
|
label = "ban",
|
||||||
usage = "ban <@player> [time] [reason]",
|
usage = {"[<time> [<reason>]]"},
|
||||||
description = "commands.ban.description",
|
|
||||||
permission = "server.ban",
|
permission = "server.ban",
|
||||||
targetRequirement = Command.TargetRequirement.PLAYER
|
targetRequirement = Command.TargetRequirement.PLAYER
|
||||||
)
|
)
|
||||||
|
@ -12,10 +12,11 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Command(label = "clear", usage = "clear <all|wp|art|mat> [lv<max level>] [r<max refinement>] [<max rarity>*]",
|
@Command(
|
||||||
description = "commands.clear.description",
|
label = "clear",
|
||||||
aliases = {"clear"}, permission = "player.clearinv", permissionTargeted = "player.clearinv.others")
|
usage = {"(all|wp|art|mat) [lv<max level>] [r<max refinement>] [<max rarity>*]"},
|
||||||
|
permission = "player.clearinv",
|
||||||
|
permissionTargeted = "player.clearinv.others")
|
||||||
public final class ClearCommand implements CommandHandler {
|
public final class ClearCommand implements CommandHandler {
|
||||||
private static Pattern lvlRegex = Pattern.compile("l(?:vl?)?(\\d+)"); // Java doesn't have raw string literals :(
|
private static Pattern lvlRegex = Pattern.compile("l(?:vl?)?(\\d+)"); // Java doesn't have raw string literals :(
|
||||||
private static Pattern refineRegex = Pattern.compile("r(\\d+)");
|
private static Pattern refineRegex = Pattern.compile("r(\\d+)");
|
||||||
|
@ -9,7 +9,7 @@ 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]", permission = "server.coop", permissionTargeted = "server.coop.others", description = "commands.coop.description")
|
@Command(label = "coop", usage = {"[<host UID>]"}, permission = "server.coop", permissionTargeted = "server.coop.others")
|
||||||
public final class CoopCommand implements CommandHandler {
|
public final class CoopCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -8,7 +8,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "enterdungeon", usage = "enterdungeon <dungeonId>", aliases = {"dungeon"}, permission = "player.enterdungeon", permissionTargeted = "player.enterdungeon.others", description = "commands.enter_dungeon.description")
|
@Command(label = "enter_dungeon", aliases = {"enterdungeon", "dungeon"}, usage = {"<dungeonId>"}, permission = "player.enterdungeon", permissionTargeted = "player.enterdungeon.others")
|
||||||
public final class EnterDungeonCommand implements CommandHandler {
|
public final class EnterDungeonCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -23,8 +23,15 @@ import java.util.List;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Command(label = "give", usage = "give <itemId|avatarId|\"all\"|\"weapons\"|\"mats\"|\"avatars\"> [lv<level>] [r<refinement>] [x<amount>] | give <artifactId> [lv<level>] [x<amount>] [mainPropId] [<appendPropId>[,<times>]]...", aliases = {
|
@Command(
|
||||||
"g", "item", "giveitem"}, permission = "player.give", permissionTargeted = "player.give.others", description = "commands.give.description")
|
label = "give",
|
||||||
|
aliases = {"g", "item", "giveitem"},
|
||||||
|
usage = {
|
||||||
|
"(<itemId>|<avatarId>|all|weapons|mats|avatars) [lv<level>] [r<refinement>] [x<amount>] [c<constellation>]",
|
||||||
|
"<artifactId> [lv<level>] [x<amount>] [<mainPropId>] [<appendPropId>[,<times>]]..."},
|
||||||
|
permission = "player.give",
|
||||||
|
permissionTargeted = "player.give.others",
|
||||||
|
threading = true)
|
||||||
public final class GiveCommand implements CommandHandler {
|
public final class GiveCommand implements CommandHandler {
|
||||||
private static Pattern lvlRegex = Pattern.compile("l(?:vl?)?(\\d+)"); // Java doesn't have raw string literals :(
|
private static Pattern lvlRegex = Pattern.compile("l(?:vl?)?(\\d+)"); // Java doesn't have raw string literals :(
|
||||||
private static Pattern refineRegex = Pattern.compile("r(\\d+)");
|
private static Pattern refineRegex = Pattern.compile("r(\\d+)");
|
||||||
|
@ -11,7 +11,7 @@ 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"}, permission = "player.heal", permissionTargeted = "player.heal.others", description = "commands.heal.description")
|
@Command(label = "heal", aliases = {"h"}, permission = "player.heal", permissionTargeted = "player.heal.others")
|
||||||
public final class HealCommand implements CommandHandler {
|
public final class HealCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,80 +3,80 @@ package emu.grasscutter.command.commands;
|
|||||||
import emu.grasscutter.command.Command;
|
import emu.grasscutter.command.Command;
|
||||||
import emu.grasscutter.command.CommandHandler;
|
import emu.grasscutter.command.CommandHandler;
|
||||||
import emu.grasscutter.command.CommandMap;
|
import emu.grasscutter.command.CommandMap;
|
||||||
|
import emu.grasscutter.game.Account;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "help", usage = "help [command]", description = "commands.help.description", targetRequirement = Command.TargetRequirement.NONE)
|
@Command(label = "help", usage = {"[<command>]"}, targetRequirement = Command.TargetRequirement.NONE)
|
||||||
public final class HelpCommand implements CommandHandler {
|
public final class HelpCommand implements CommandHandler {
|
||||||
|
private final boolean SHOW_COMMANDS_WITHOUT_PERMISSIONS = false; // TODO: Make this into a server config key
|
||||||
|
|
||||||
private void createCommand(StringBuilder builder, Player player, Command annotation) {
|
private String createCommand(Player player, CommandHandler command, List<String> args) {
|
||||||
builder.append("\n").append(annotation.label()).append(" - ").append(translate(player, annotation.description()));
|
StringBuilder builder = new StringBuilder(command.getLabel())
|
||||||
builder.append("\n\t").append(translate(player, "commands.help.usage"));
|
.append(" - ")
|
||||||
if (annotation.aliases().length >= 1) {
|
.append(command.getDescriptionString(player))
|
||||||
|
.append("\n\t")
|
||||||
|
.append(command.getUsageString(player, args.toArray(new String[0])));
|
||||||
|
|
||||||
|
Command annotation = command.getClass().getAnnotation(Command.class);
|
||||||
|
if (annotation.aliases().length > 0) {
|
||||||
builder.append("\n\t").append(translate(player, "commands.help.aliases"));
|
builder.append("\n\t").append(translate(player, "commands.help.aliases"));
|
||||||
for (String alias : annotation.aliases()) {
|
for (String alias : annotation.aliases()) {
|
||||||
builder.append(alias).append(" ");
|
builder.append(alias).append(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append("\n\t").append(translate(player, "commands.help.tip_need_permission"));
|
builder.append("\n\t").append(translate(player, "commands.help.tip_need_permission"));
|
||||||
if (annotation.permission().isEmpty() || annotation.permission().isBlank()) {
|
if (!annotation.permission().isEmpty()) {
|
||||||
builder.append(translate(player, "commands.help.tip_need_no_permission"));
|
|
||||||
} else {
|
|
||||||
builder.append(annotation.permission());
|
builder.append(annotation.permission());
|
||||||
|
} else {
|
||||||
|
builder.append(translate(player, "commands.help.tip_need_no_permission"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!annotation.permissionTargeted().isEmpty() && !annotation.permissionTargeted().isBlank()) {
|
if (!annotation.permissionTargeted().isEmpty()) {
|
||||||
String permissionTargeted = annotation.permissionTargeted();
|
String permissionTargeted = annotation.permissionTargeted();
|
||||||
builder.append(" ").append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted));
|
builder.append(" ").append(translate(player, "commands.help.tip_permission_targeted", permissionTargeted));
|
||||||
}
|
}
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
Account account = (player == null) ? null : player.getAccount();
|
||||||
HashMap<String, CommandHandler> handlers = CommandMap.getInstance().getHandlers();
|
Map<String, CommandHandler> handlers = CommandMap.getInstance().getHandlers();
|
||||||
List<Command> annotations = new ArrayList<>();
|
List<String> commands = new ArrayList<>();
|
||||||
|
List<String> commands_no_permission = new ArrayList<>();
|
||||||
|
if (args.isEmpty()) {
|
||||||
for (String key : handlers.keySet()) {
|
for (String key : handlers.keySet()) {
|
||||||
Command annotation = handlers.get(key).getClass().getAnnotation(Command.class);
|
CommandHandler command = handlers.get(key);
|
||||||
|
Command annotation = command.getClass().getAnnotation(Command.class);
|
||||||
if (!Arrays.asList(annotation.aliases()).contains(key)) {
|
if (player == null || account.hasPermission(annotation.permission())) {
|
||||||
if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission()))
|
commands.add(createCommand(player, command, args));
|
||||||
continue;
|
} else if (SHOW_COMMANDS_WITHOUT_PERMISSIONS) {
|
||||||
annotations.add(annotation);
|
commands_no_permission.add(createCommand(player, command, args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SendAllHelpMessage(player, annotations);
|
|
||||||
} else {
|
} else {
|
||||||
String command = args.get(0);
|
String command_str = args.remove(0);
|
||||||
CommandHandler handler = CommandMap.getInstance().getHandler(command);
|
CommandHandler command = handlers.get(command_str);
|
||||||
StringBuilder builder = new StringBuilder("");
|
if (command == null) {
|
||||||
if (handler == null) {
|
CommandHandler.sendTranslatedMessage(player, "commands.generic.command_exist_error");
|
||||||
builder.append(translate(player, "commands.generic.command_exist_error"));
|
return;
|
||||||
} else {
|
} else {
|
||||||
Command annotation = handler.getClass().getAnnotation(Command.class);
|
Command annotation = command.getClass().getAnnotation(Command.class);
|
||||||
|
if (player == null || account.hasPermission(annotation.permission())) {
|
||||||
this.createCommand(builder, player, annotation);
|
commands.add(createCommand(player, command, args));
|
||||||
|
} else {
|
||||||
if (player != null && !Objects.equals(annotation.permission(), "") && !player.getAccount().hasPermission(annotation.permission())) {
|
commands_no_permission.add(createCommand(player, command, args));
|
||||||
builder.append("\n\t").append(translate(player, "commands.help.warn_player_has_no_permission"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandHandler.sendMessage(player, builder.toString());
|
|
||||||
}
|
}
|
||||||
}
|
for (String s : commands)
|
||||||
|
CommandHandler.sendMessage(player, s);
|
||||||
void SendAllHelpMessage(Player player, List<Command> annotations) {
|
for (String s : commands_no_permission)
|
||||||
StringBuilder builder = new StringBuilder(translate(player, "commands.help.available_commands"));
|
CommandHandler.sendMessage(player, s + "\n\t" + translate(player, "commands.help.warn_player_has_no_permission"));
|
||||||
annotations.forEach(annotation -> {
|
|
||||||
this.createCommand(builder, player, annotation);
|
|
||||||
builder.append("\n");
|
|
||||||
});
|
|
||||||
|
|
||||||
CommandHandler.sendMessage(player, builder.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,19 +6,18 @@ import emu.grasscutter.game.player.Player;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
@Command(label = "kick", aliases = {"restart"}, permissionTargeted = "server.kick")
|
||||||
|
|
||||||
@Command(label = "kick", usage = "kick", aliases = {"restart"}, permissionTargeted = "server.kick", description = "commands.kick.description")
|
|
||||||
public final class KickCommand implements CommandHandler {
|
public final class KickCommand implements CommandHandler {
|
||||||
|
|
||||||
@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) {
|
||||||
CommandHandler.sendMessage(sender, translate(sender, "commands.kick.player_kick_player",
|
CommandHandler.sendTranslatedMessage(sender, "commands.kick.player_kick_player",
|
||||||
Integer.toString(sender.getUid()), sender.getAccount().getUsername(),
|
Integer.toString(sender.getUid()), sender.getAccount().getUsername(),
|
||||||
Integer.toString(targetPlayer.getUid()), targetPlayer.getAccount().getUsername()));
|
Integer.toString(targetPlayer.getUid()), targetPlayer.getAccount().getUsername());
|
||||||
} else {
|
} else {
|
||||||
CommandHandler.sendMessage(null, translate(sender, "commands.kick.server_kick_player", Integer.toString(targetPlayer.getUid()), targetPlayer.getAccount().getUsername()));
|
CommandHandler.sendTranslatedMessage(sender, "commands.kick.server_kick_player",
|
||||||
|
Integer.toString(targetPlayer.getUid()), targetPlayer.getAccount().getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
targetPlayer.getSession().close();
|
targetPlayer.getSession().close();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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.entity.EntityMonster;
|
import emu.grasscutter.game.entity.EntityMonster;
|
||||||
@ -12,7 +11,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "killall", usage = "killall [sceneId]", permission = "server.killall", permissionTargeted = "server.killall.others", description = "commands.killall.description")
|
@Command(label = "killall", usage = {"[<sceneId>]"}, permission = "server.killall", permissionTargeted = "server.killall.others")
|
||||||
public final class KillAllCommand implements CommandHandler {
|
public final class KillAllCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,7 +13,7 @@ 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"}, permission = "player.killcharacter", permissionTargeted = "player.killcharacter.others", description = "commands.killCharacter.description")
|
@Command(label = "killCharacter", aliases = {"suicide", "kill"}, permission = "player.killcharacter", permissionTargeted = "player.killcharacter.others")
|
||||||
public final class KillCharacterCommand implements CommandHandler {
|
public final class KillCharacterCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,8 +3,6 @@ package emu.grasscutter.command.commands;
|
|||||||
import emu.grasscutter.Grasscutter;
|
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.database.DatabaseHelper;
|
|
||||||
import emu.grasscutter.game.Account;
|
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
|
|
||||||
@ -13,7 +11,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "language", usage = "language [language code]", description = "commands.language.description", aliases = {"lang"}, targetRequirement = Command.TargetRequirement.NONE)
|
@Command(label = "language", usage = {"[<language code>]"}, aliases = {"lang"}, targetRequirement = Command.TargetRequirement.NONE)
|
||||||
public final class LanguageCommand implements CommandHandler {
|
public final class LanguageCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -10,7 +10,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "list", usage = "list [uid]", aliases = {"players"}, description = "commands.list.description", targetRequirement = Command.TargetRequirement.NONE)
|
@Command(label = "list", aliases = {"players"}, usage = {"[<UID>]"}, targetRequirement = Command.TargetRequirement.NONE)
|
||||||
public final class ListCommand implements CommandHandler {
|
public final class ListCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,7 +11,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "permission", usage = "permission <add|remove> <permission>", permission = "permission", description = "commands.permission.description", targetRequirement = TargetRequirement.PLAYER)
|
@Command(label = "permission", usage = "(add|remove) <permission>", permission = "permission", targetRequirement = TargetRequirement.PLAYER)
|
||||||
public final class PermissionCommand implements CommandHandler {
|
public final class PermissionCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -7,16 +7,14 @@ import emu.grasscutter.utils.Position;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
@Command(label = "position", aliases = {"pos"})
|
||||||
|
|
||||||
@Command(label = "position", usage = "position", aliases = {"pos"}, description = "commands.position.description")
|
|
||||||
public final class PositionCommand implements CommandHandler {
|
public final class PositionCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||||
Position pos = targetPlayer.getPosition();
|
Position pos = targetPlayer.getPosition();
|
||||||
CommandHandler.sendMessage(sender, translate(sender, "commands.position.success",
|
CommandHandler.sendTranslatedMessage(sender, "commands.position.success",
|
||||||
Float.toString(pos.getX()), Float.toString(pos.getY()), Float.toString(pos.getZ()),
|
Float.toString(pos.getX()), Float.toString(pos.getY()), Float.toString(pos.getZ()),
|
||||||
Integer.toString(targetPlayer.getSceneId())));
|
Integer.toString(targetPlayer.getSceneId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@ -10,7 +9,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "quest", usage = "quest <add|finish> [questId]", permission = "player.quest", permissionTargeted = "player.quest.others", description = "commands.quest.description")
|
@Command(label = "quest", usage = {"(add|finish) [<questId>]"}, permission = "player.quest", permissionTargeted = "player.quest.others")
|
||||||
public final class QuestCommand implements CommandHandler {
|
public final class QuestCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "reload", usage = "reload", permission = "server.reload", description = "commands.reload.description", targetRequirement = Command.TargetRequirement.NONE)
|
@Command(label = "reload", permission = "server.reload", targetRequirement = Command.TargetRequirement.NONE)
|
||||||
public final class ReloadCommand implements CommandHandler {
|
public final class ReloadCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -10,8 +10,12 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "resetconst", usage = "resetconst [all]",
|
@Command(
|
||||||
aliases = {"resetconstellation"}, permission = "player.resetconstellation", permissionTargeted = "player.resetconstellation.others", description = "commands.resetConst.description")
|
label = "resetConst",
|
||||||
|
aliases = {"resetconstellation"},
|
||||||
|
usage = "[all]",
|
||||||
|
permission = "player.resetconstellation",
|
||||||
|
permissionTargeted = "player.resetconstellation.others")
|
||||||
public final class ResetConstCommand implements CommandHandler {
|
public final class ResetConstCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "resetshop", usage = "resetshop", permission = "server.resetshop", permissionTargeted = "server.resetshop.others", description = "commands.resetShopLimit.description")
|
@Command(label = "resetShopLimit", aliases = {"resetshop"}, permission = "server.resetshop", permissionTargeted = "server.resetshop.others")
|
||||||
public final class ResetShopLimitCommand implements CommandHandler {
|
public final class ResetShopLimitCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,7 +13,11 @@ import java.util.List;
|
|||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
@Command(label = "sendmail", usage = "sendmail <userId|all|help> [templateId]", permission = "server.sendmail", description = "commands.sendMail.description", targetRequirement = Command.TargetRequirement.NONE)
|
@Command(
|
||||||
|
label = "sendMail",
|
||||||
|
usage = {"(<userId>|all) [<templateId>]", "help"},
|
||||||
|
permission = "server.sendmail",
|
||||||
|
targetRequirement = Command.TargetRequirement.NONE)
|
||||||
public final class SendMailCommand implements CommandHandler {
|
public final class SendMailCommand implements CommandHandler {
|
||||||
|
|
||||||
// TODO: You should be able to do /sendmail and then just send subsequent messages until you finish
|
// TODO: You should be able to do /sendmail and then just send subsequent messages until you finish
|
||||||
|
@ -10,8 +10,13 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "sendmessage", usage = "sendmessage <message>",
|
@Command(
|
||||||
aliases = {"say", "sendservmsg", "sendservermessage", "b", "broadcast"}, permission = "server.sendmessage", permissionTargeted = "server.sendmessage.others", description = "commands.sendMessage.description", targetRequirement = TargetRequirement.NONE)
|
label = "sendMessage",
|
||||||
|
aliases = {"say", "sendservmsg", "sendservermessage", "b", "broadcast"},
|
||||||
|
usage = {"<message>"},
|
||||||
|
permission = "server.sendmessage",
|
||||||
|
permissionTargeted = "server.sendmessage.others",
|
||||||
|
targetRequirement = TargetRequirement.NONE)
|
||||||
public final class SendMessageCommand implements CommandHandler {
|
public final class SendMessageCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,8 +11,12 @@ import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "setfetterlevel", usage = "setfetterlevel <level>",
|
@Command(
|
||||||
aliases = {"setfetterlvl", "setfriendship"}, permission = "player.setfetterlevel", permissionTargeted = "player.setfetterlevel.others", description = "commands.setFetterLevel.description")
|
label = "setFetterLevel",
|
||||||
|
usage = {"<level>"},
|
||||||
|
aliases = {"setfetterlvl", "setfriendship"},
|
||||||
|
permission = "player.setfetterlevel",
|
||||||
|
permissionTargeted = "player.setfetterlevel.others")
|
||||||
public final class SetFetterLevelCommand implements CommandHandler {
|
public final class SetFetterLevelCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -10,7 +10,7 @@ import emu.grasscutter.game.player.Player;
|
|||||||
import emu.grasscutter.game.props.PlayerProperty;
|
import emu.grasscutter.game.props.PlayerProperty;
|
||||||
import emu.grasscutter.game.tower.TowerLevelRecord;
|
import emu.grasscutter.game.tower.TowerLevelRecord;
|
||||||
|
|
||||||
@Command(label = "setprop", usage = "setprop|prop <prop> <value>", aliases = {"prop"}, permission = "player.setprop", permissionTargeted = "player.setprop.others", description = "commands.setProp.description")
|
@Command(label = "setProp", aliases = {"prop"}, usage = {"<prop> <value>"}, permission = "player.setprop", permissionTargeted = "player.setprop.others")
|
||||||
public final class SetPropCommand implements CommandHandler {
|
public final class SetPropCommand implements CommandHandler {
|
||||||
static enum PseudoProp {
|
static enum PseudoProp {
|
||||||
NONE,
|
NONE,
|
||||||
|
@ -11,7 +11,7 @@ import emu.grasscutter.game.player.Player;
|
|||||||
import emu.grasscutter.game.props.FightProperty;
|
import emu.grasscutter.game.props.FightProperty;
|
||||||
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
|
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
|
||||||
|
|
||||||
@Command(label = "setstats", usage = "setstats|stats <stat> <value>", aliases = {"stats"}, permission = "player.setstats", permissionTargeted = "player.setstats.others", description = "commands.setStats.description")
|
@Command(label = "setStats", aliases = {"stats", "stat"}, usage = {"<stat> <value>"}, permission = "player.setstats", permissionTargeted = "player.setstats.others")
|
||||||
public final class SetStatsCommand implements CommandHandler {
|
public final class SetStatsCommand implements CommandHandler {
|
||||||
static class Stat {
|
static class Stat {
|
||||||
String name;
|
String name;
|
||||||
|
@ -1,29 +1,28 @@
|
|||||||
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;
|
||||||
import emu.grasscutter.data.excels.AvatarData;
|
|
||||||
import emu.grasscutter.data.excels.GadgetData;
|
import emu.grasscutter.data.excels.GadgetData;
|
||||||
import emu.grasscutter.data.excels.ItemData;
|
import emu.grasscutter.data.excels.ItemData;
|
||||||
import emu.grasscutter.data.excels.MonsterData;
|
import emu.grasscutter.data.excels.MonsterData;
|
||||||
import emu.grasscutter.game.avatar.Avatar;
|
|
||||||
import emu.grasscutter.game.entity.*;
|
import emu.grasscutter.game.entity.*;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.game.props.EntityType;
|
|
||||||
import emu.grasscutter.game.props.FightProperty;
|
import emu.grasscutter.game.props.FightProperty;
|
||||||
import emu.grasscutter.utils.Position;
|
import emu.grasscutter.utils.Position;
|
||||||
import emu.grasscutter.game.world.Scene;
|
import emu.grasscutter.game.world.Scene;
|
||||||
|
|
||||||
import javax.swing.text.html.parser.Entity;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static emu.grasscutter.config.Configuration.*;
|
import static emu.grasscutter.config.Configuration.*;
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "spawn", usage = "spawn <entityId> [amount] [level(monster only)] [<x> <y> <z>(monster only, optional)]", aliases = {"drop"}, permission = "server.spawn", permissionTargeted = "server.spawn.others", description = "commands.spawn.description")
|
@Command(
|
||||||
|
label = "spawn",
|
||||||
|
usage = {"spawn <entityId> [amount] [level(monster only)] [<x> <y> <z>(monster only)]"},
|
||||||
|
aliases = {"drop"},
|
||||||
|
permission = "server.spawn",
|
||||||
|
permissionTargeted = "server.spawn.others")
|
||||||
public final class SpawnCommand implements CommandHandler {
|
public final class SpawnCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "stop", usage = "stop", permission = "server.stop", description = "commands.stop.description", targetRequirement = Command.TargetRequirement.NONE)
|
@Command(label = "stop", permission = "server.stop", targetRequirement = Command.TargetRequirement.NONE)
|
||||||
public final class StopCommand implements CommandHandler {
|
public final class StopCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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.excels.AvatarSkillDepotData;
|
import emu.grasscutter.data.excels.AvatarSkillDepotData;
|
||||||
@ -14,7 +13,11 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "talent", usage = "talent <talentId> <value>", permission = "player.settalent", permissionTargeted = "player.settalent.others", description = "commands.talent.description")
|
@Command(
|
||||||
|
label = "talent",
|
||||||
|
usage = {"set <talentId> <level>", "(n|e|q) <level>", "getid"},
|
||||||
|
permission = "player.settalent",
|
||||||
|
permissionTargeted = "player.settalent.others")
|
||||||
public final class TalentCommand implements CommandHandler {
|
public final class TalentCommand implements CommandHandler {
|
||||||
private void setTalentLevel(Player sender, Player player, Avatar avatar, int talentId, int talentLevel) {
|
private void setTalentLevel(Player sender, Player player, Avatar avatar, int talentId, int talentLevel) {
|
||||||
int oldLevel = avatar.getSkillLevelMap().get(talentId);
|
int oldLevel = avatar.getSkillLevelMap().get(talentId);
|
||||||
|
@ -12,8 +12,13 @@ import static emu.grasscutter.config.Configuration.*;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
@Command(label = "team", usage = "team <add|remove|set> [avatarId,...] [index|first|last|index-index,...]",
|
import static emu.grasscutter.Configuration.*;
|
||||||
permission = "player.team", permissionTargeted = "player.team.others", description = "commands.team.description")
|
|
||||||
|
@Command(
|
||||||
|
label = "team",
|
||||||
|
usage = {"add <avatarId,...>", "(remove|set) [index|first|last|index-index,...]"},
|
||||||
|
permission = "player.team",
|
||||||
|
permissionTargeted = "player.team.others")
|
||||||
public final class TeamCommand implements CommandHandler {
|
public final class TeamCommand implements CommandHandler {
|
||||||
private static final int BASE_AVATARID = 10000000;
|
private static final int BASE_AVATARID = 10000000;
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@ -10,7 +9,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "tpall", usage = "tpall", permission = "player.tpall", permissionTargeted = "player.tpall.others", description = "commands.teleportAll.description")
|
@Command(label = "teleportAll", aliases = {"tpall"}, permission = "player.tpall", permissionTargeted = "player.tpall.others")
|
||||||
public final class TeleportAllCommand implements CommandHandler {
|
public final class TeleportAllCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@ -10,7 +9,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static emu.grasscutter.utils.Language.translate;
|
import static emu.grasscutter.utils.Language.translate;
|
||||||
|
|
||||||
@Command(label = "teleport", usage = "teleport <x> <y> <z> [sceneId]", aliases = {"tp"}, permission = "player.teleport", permissionTargeted = "player.teleport.others", description = "commands.teleport.description")
|
@Command(label = "teleport", aliases = {"tp"}, usage = {"<x> <y> <z> [sceneId]"}, permission = "player.teleport", permissionTargeted = "player.teleport.others")
|
||||||
public final class TeleportCommand implements CommandHandler {
|
public final class TeleportCommand implements CommandHandler {
|
||||||
|
|
||||||
private float parseRelative(String input, Float current) { // TODO: Maybe this will be useful elsewhere later
|
private float parseRelative(String input, Float current) { // TODO: Maybe this will be useful elsewhere later
|
||||||
|
@ -9,8 +9,6 @@ import emu.grasscutter.game.player.Player;
|
|||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
label = "unban",
|
label = "unban",
|
||||||
usage = "unban <@player>",
|
|
||||||
description = "commands.unban.description",
|
|
||||||
permission = "server.ban",
|
permission = "server.ban",
|
||||||
targetRequirement = Command.TargetRequirement.PLAYER
|
targetRequirement = Command.TargetRequirement.PLAYER
|
||||||
)
|
)
|
||||||
|
@ -4,11 +4,10 @@ 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;
|
||||||
import emu.grasscutter.game.props.ClimateType;
|
import emu.grasscutter.game.props.ClimateType;
|
||||||
import emu.grasscutter.game.world.Scene;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Command(label = "weather", usage = "weather [weatherId] [climateType]", aliases = {"w"}, permission = "player.weather", permissionTargeted = "player.weather.others", description = "commands.weather.description")
|
@Command(label = "weather", aliases = {"w"}, usage = {"weather [<weatherId>] [<climateType>]"}, permission = "player.weather", permissionTargeted = "player.weather.others")
|
||||||
public final class WeatherCommand implements CommandHandler {
|
public final class WeatherCommand implements CommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -187,6 +187,7 @@ public class Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPermission(String permission) {
|
public boolean hasPermission(String permission) {
|
||||||
|
if (permission.isEmpty()) return true;
|
||||||
if (this.permissions.contains("*") && this.permissions.size() == 1) return true;
|
if (this.permissions.contains("*") && this.permissions.size() == 1) return true;
|
||||||
|
|
||||||
// Add default permissions if it doesn't exist
|
// Add default permissions if it doesn't exist
|
||||||
|
@ -81,10 +81,10 @@ final class HandbookRequestHandler implements DocumentationHandler {
|
|||||||
.replace("{{HEADER_SCENE}}", translate("documentation.handbook.header_scene"))
|
.replace("{{HEADER_SCENE}}", translate("documentation.handbook.header_scene"))
|
||||||
.replace("{{HEADER_MONSTER}}", translate("documentation.handbook.header_monster"))
|
.replace("{{HEADER_MONSTER}}", translate("documentation.handbook.header_monster"))
|
||||||
// Commands table
|
// Commands table
|
||||||
.replace("{{COMMANDS_TABLE}}", cmdMap.getAnnotationsAsList()
|
.replace("{{COMMANDS_TABLE}}", cmdMap.getHandlersAsList()
|
||||||
.stream()
|
.stream()
|
||||||
.map(cmd -> "<tr><td><code>" + cmd.label() + "</code></td><td>" +
|
.map(cmd -> "<tr><td><code>" + cmd.getLabel() + "</code></td><td>" +
|
||||||
cmd.description() + "</td></tr>")
|
cmd.getDescriptionString(null) + "</td></tr>")
|
||||||
.collect(Collectors.joining("\n")))
|
.collect(Collectors.joining("\n")))
|
||||||
// Avatars table
|
// Avatars table
|
||||||
.replace("{{AVATARS_TABLE}}", GameData.getAvatarDataMap().keySet()
|
.replace("{{AVATARS_TABLE}}", GameData.getAvatarDataMap().keySet()
|
||||||
|
@ -16,6 +16,7 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
import emu.grasscutter.GameConstants;
|
import emu.grasscutter.GameConstants;
|
||||||
import emu.grasscutter.Grasscutter;
|
import emu.grasscutter.Grasscutter;
|
||||||
import emu.grasscutter.command.Command;
|
import emu.grasscutter.command.Command;
|
||||||
|
import emu.grasscutter.command.CommandHandler;
|
||||||
import emu.grasscutter.command.CommandMap;
|
import emu.grasscutter.command.CommandMap;
|
||||||
import emu.grasscutter.data.GameData;
|
import emu.grasscutter.data.GameData;
|
||||||
import emu.grasscutter.data.ResourceLoader;
|
import emu.grasscutter.data.ResourceLoader;
|
||||||
@ -106,16 +107,15 @@ final class ToolsWithLanguageOption {
|
|||||||
writer.println("// Grasscutter " + GameConstants.VERSION + " GM Handbook");
|
writer.println("// Grasscutter " + GameConstants.VERSION + " GM Handbook");
|
||||||
writer.println("// Created " + dtf.format(now) + System.lineSeparator() + System.lineSeparator());
|
writer.println("// Created " + dtf.format(now) + System.lineSeparator() + System.lineSeparator());
|
||||||
|
|
||||||
CommandMap cmdMap = new CommandMap(true);
|
List<CommandHandler> cmdList = new CommandMap(true).getHandlersAsList();
|
||||||
List<Command> cmdList = new ArrayList<>(cmdMap.getAnnotationsAsList());
|
|
||||||
|
|
||||||
writer.println("// Commands");
|
writer.println("// Commands");
|
||||||
for (Command cmd : cmdList) {
|
for (CommandHandler cmd : cmdList) {
|
||||||
StringBuilder cmdName = new StringBuilder(cmd.label());
|
StringBuilder cmdName = new StringBuilder(cmd.getLabel());
|
||||||
while (cmdName.length() <= 15) {
|
while (cmdName.length() <= 15) {
|
||||||
cmdName.insert(0, " ");
|
cmdName.insert(0, " ");
|
||||||
}
|
}
|
||||||
writer.println(cmdName + " : " + translate(cmd.description()));
|
writer.println(cmdName + " : " + translate(cmd.getDescriptionString(null)));
|
||||||
}
|
}
|
||||||
writer.println();
|
writer.println();
|
||||||
|
|
||||||
|
@ -94,6 +94,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"execution": {
|
"execution": {
|
||||||
|
"usage_prefix": "Usage: ",
|
||||||
"player_exist_error": "Player not found.",
|
"player_exist_error": "Player not found.",
|
||||||
"player_offline_error": "Player is not online.",
|
"player_offline_error": "Player is not online.",
|
||||||
"item_player_exist_error": "Invalid item or UID.",
|
"item_player_exist_error": "Invalid item or UID.",
|
||||||
|
Loading…
Reference in New Issue
Block a user