Commit 711ae2f5 authored by Magix's avatar Magix Committed by GitHub
Browse files

Merge branch 'development' into development

parents 79babcc5 38fd7bb7
......@@ -8,6 +8,8 @@ import emu.grasscutter.game.player.Player;
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")
public final class HelpCommand implements CommandHandler {
......@@ -31,16 +33,16 @@ public final class HelpCommand implements CommandHandler {
} else {
String command = args.get(0);
CommandHandler handler = CommandMap.getInstance().getHandler(command);
StringBuilder builder = new StringBuilder(player == null ? "\n" + Grasscutter.getLanguage().Help + " - " : Grasscutter.getLanguage().Help + " - ").append(command).append(": \n");
StringBuilder builder = new StringBuilder(player == null ? "\n" + translate("commands.status.help") + " - " : translate("commands.status.help") + " - ").append(command).append(": \n");
if (handler == null) {
builder.append(Grasscutter.getLanguage().No_command_found);
builder.append(translate("commands.generic.command_exist_error"));
} else {
Command annotation = handler.getClass().getAnnotation(Command.class);
builder.append(" ").append(annotation.description()).append("\n");
builder.append(Grasscutter.getLanguage().Help_usage).append(annotation.usage());
builder.append(translate("commands.help.usage")).append(annotation.usage());
if (annotation.aliases().length >= 1) {
builder.append("\n").append(Grasscutter.getLanguage().Help_aliases);
builder.append("\n").append(translate("commands.help.aliases"));
for (String alias : annotation.aliases()) {
builder.append(alias).append(" ");
}
......@@ -56,13 +58,13 @@ public final class HelpCommand implements CommandHandler {
void SendAllHelpMessage(Player player, List<Command> annotations) {
if (player == null) {
StringBuilder builder = new StringBuilder("\n" + Grasscutter.getLanguage().Help_available_command + "\n");
StringBuilder builder = new StringBuilder("\n" + translate("commands.help.available_commands") + "\n");
annotations.forEach(annotation -> {
builder.append(annotation.label()).append("\n");
builder.append(" ").append(annotation.description()).append("\n");
builder.append(Grasscutter.getLanguage().Help_usage).append(annotation.usage());
builder.append(translate("commands.help.usage")).append(annotation.usage());
if (annotation.aliases().length >= 1) {
builder.append("\n").append(Grasscutter.getLanguage().Help_aliases);
builder.append("\n").append(translate("commands.help.aliases"));
for (String alias : annotation.aliases()) {
builder.append(alias).append(" ");
}
......@@ -73,13 +75,13 @@ public final class HelpCommand implements CommandHandler {
CommandHandler.sendMessage(null, builder.toString());
} else {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Help_available_command);
CommandHandler.sendMessage(player, translate("commands.help.available_commands"));
annotations.forEach(annotation -> {
StringBuilder builder = new StringBuilder(annotation.label()).append("\n");
builder.append(" ").append(annotation.description()).append("\n");
builder.append(Grasscutter.getLanguage().Help_usage).append(annotation.usage());
builder.append(translate("commands.help.usage")).append(annotation.usage());
if (annotation.aliases().length >= 1) {
builder.append("\n").append(Grasscutter.getLanguage().Help_aliases);
builder.append("\n").append(translate("commands.help.aliases"));
for (String alias : annotation.aliases()) {
builder.append(alias).append(" ");
}
......
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;
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")
public final class KickCommand implements CommandHandler {
......@@ -14,14 +15,16 @@ public final class KickCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (sender != null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Kick_player_kick_player.replace("{sendUid}", Integer.toString(sender.getAccount().getPlayerUid())).replace("{sendName}", sender.getAccount().getUsername()).replace("kickUid", Integer.toString(targetPlayer.getUid())).replace("{kickName}", targetPlayer.getAccount().getUsername()));
CommandHandler.sendMessage(sender, translate("commands.kick.player_kick_player",
Integer.toString(sender.getAccount().getPlayerUid()), sender.getAccount().getUsername(),
Integer.toString(targetPlayer.getUid()), targetPlayer.getAccount().getUsername()));
} else {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Kick_server_player.replace("{kickUid}", Integer.toString(targetPlayer.getUid())).replace("{kickName}", targetPlayer.getAccount().getUsername()));
CommandHandler.sendMessage(null, translate("commands.kick.server_kick_player", Integer.toString(targetPlayer.getUid()), targetPlayer.getAccount().getUsername()));
}
targetPlayer.getSession().close();
......
......@@ -10,6 +10,8 @@ import emu.grasscutter.game.world.Scene;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "killall", usage = "killall [sceneId]",
description = "Kill all entities", permission = "server.killall")
public final class KillAllCommand implements CommandHandler {
......@@ -17,7 +19,7 @@ public final class KillAllCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
......@@ -30,14 +32,14 @@ public final class KillAllCommand implements CommandHandler {
scene = targetPlayer.getWorld().getSceneById(Integer.parseInt(args.get(0)));
break;
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Kill_usage);
CommandHandler.sendMessage(sender, translate("commands.kill.usage"));
return;
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments);
CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
}
if (scene == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Kill_scene_not_found_in_player_world);
CommandHandler.sendMessage(sender, translate("commands.kill.scene_not_found_in_player_world"));
return;
}
......@@ -46,7 +48,7 @@ public final class KillAllCommand implements CommandHandler {
List<GameEntity> toKill = sceneF.getEntities().values().stream()
.filter(entity -> entity instanceof EntityMonster)
.toList();
toKill.stream().forEach(entity -> sceneF.killEntity(entity, 0));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Kill_kill_monsters_in_scene.replace("{size}", Integer.toString(toKill.size())).replace("{id}", Integer.toString(scene.getId())));
toKill.forEach(entity -> sceneF.killEntity(entity, 0));
CommandHandler.sendMessage(sender, translate("commands.kill.kill_monsters_in_scene", Integer.toString(toKill.size()), Integer.toString(scene.getId())));
}
}
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.entity.EntityAvatar;
......@@ -12,6 +11,8 @@ import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify;
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")
public final class KillCharacterCommand implements CommandHandler {
......@@ -19,7 +20,7 @@ public final class KillCharacterCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
......@@ -32,6 +33,6 @@ public final class KillCharacterCommand implements CommandHandler {
targetPlayer.getScene().removeEntity(entity);
entity.onDeath(0);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().KillCharacter_kill_current_character.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.killCharacter.success", targetPlayer.getNickname()));
}
}
......@@ -8,6 +8,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import java.util.Map;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "list", usage = "list [uid]",
description = "List online players", aliases = {"players"})
public final class ListCommand implements CommandHandler {
......@@ -21,7 +23,7 @@ public final class ListCommand implements CommandHandler {
needUID = args.get(0).equals("uid");
}
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().List_message.replace("{size}", Integer.toString(playersMap.size())));
CommandHandler.sendMessage(sender, translate("commands.list.success", Integer.toString(playersMap.size())));
if (playersMap.size() != 0) {
StringBuilder playerSet = new StringBuilder();
......
......@@ -8,6 +8,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "permission", usage = "permission <add|remove> <permission>",
description = "Grants or removes a permission for a user", permission = "*")
public final class PermissionCommand implements CommandHandler {
......@@ -15,12 +17,12 @@ public final class PermissionCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() != 2) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage);
CommandHandler.sendMessage(sender, translate("commands.permission.usage"));
return;
}
......@@ -29,23 +31,23 @@ public final class PermissionCommand implements CommandHandler {
Account account = targetPlayer.getAccount();
if (account == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Account_not_find);
CommandHandler.sendMessage(sender, translate("commands.permission.account_error"));
return;
}
switch (action) {
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage);
CommandHandler.sendMessage(sender, translate("commands.permission.usage"));
break;
case "add":
if (account.addPermission(permission)) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_add);
} else CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_have_permission);
CommandHandler.sendMessage(sender, translate("commands.permission.add"));
} else CommandHandler.sendMessage(sender, translate("commands.permission.has_error"));
break;
case "remove":
if (account.removePermission(permission)) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_remove);
} else CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_not_have_permission);
CommandHandler.sendMessage(sender, translate("commands.permission.remove"));
} else CommandHandler.sendMessage(sender, translate("commands.permission.not_have_error"));
break;
}
......
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;
......@@ -8,6 +7,8 @@ import emu.grasscutter.utils.Position;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "position", usage = "position", aliases = {"pos"},
description = "Get coordinates.")
public final class PositionCommand implements CommandHandler {
......@@ -15,11 +16,13 @@ public final class PositionCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
Position pos = targetPlayer.getPos();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Position_message.replace("{x}", Float.toString(pos.getX())).replace("{y}", Float.toString(pos.getY())).replace("{z}", Float.toString(pos.getZ())).replace("{id}", Integer.toString(targetPlayer.getSceneId())));
CommandHandler.sendMessage(sender, translate("commands.position.success",
Float.toString(pos.getX()), Float.toString(pos.getY()), Float.toString(pos.getZ()),
Integer.toString(targetPlayer.getSceneId())));
}
}
......@@ -7,19 +7,23 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "reload", usage = "reload",
description = "Reload server config", permission = "server.reload")
public final class ReloadCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Reload_reload_start);
CommandHandler.sendMessage(sender, translate("commands.reload.reload_start"));
Grasscutter.loadConfig();
Grasscutter.loadLanguage();
Grasscutter.getGameServer().getGachaManager().load();
Grasscutter.getGameServer().getDropManager().load();
Grasscutter.getGameServer().getShopManager().load();
Grasscutter.getDispatchServer().loadQueries();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Reload_reload_done);
CommandHandler.sendMessage(sender, translate("commands.reload.reload_done"));
}
}
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.avatar.Avatar;
......@@ -9,6 +8,8 @@ import emu.grasscutter.game.player.Player;
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")
......@@ -17,13 +18,13 @@ public final class ResetConstCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
targetPlayer.getAvatars().forEach(this::resetConstellation);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().ResetConst_reset_all);
CommandHandler.sendMessage(sender, translate("commands.resetConst.reset_all"));
} else {
EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
if (entity == null) {
......@@ -33,7 +34,7 @@ public final class ResetConstCommand implements CommandHandler {
Avatar avatar = entity.getAvatar();
this.resetConstellation(avatar);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().ResetConst_reset_all_done.replace("{name}", avatar.getAvatarData().getName()));
CommandHandler.sendMessage(sender, translate("commands.resetConst.success", avatar.getAvatarData().getName()));
}
}
......
......@@ -7,18 +7,20 @@ import emu.grasscutter.game.player.Player;
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")
public final class ResetShopLimitCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
targetPlayer.getShopLimit().forEach(x -> x.setNextRefreshTime(0));
targetPlayer.save();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Success);
CommandHandler.sendMessage(sender, translate("commands.status.success"));
}
}
......@@ -10,6 +10,9 @@ import emu.grasscutter.game.player.Player;
import java.util.HashMap;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@SuppressWarnings("ConstantConditions")
@Command(label = "sendmail", usage = "sendmail <userId|all|help> [templateId]",
description = "Sends mail to the specified user. The usage of this command changes based on it's composition state.", permission = "server.sendmail")
public final class SendMailCommand implements CommandHandler {
......@@ -45,16 +48,16 @@ public final class SendMailCommand implements CommandHandler {
if (DatabaseHelper.getPlayerById(Integer.parseInt(args.get(0))) != null) {
mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail());
} else {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_user_not_exist.replace("{id}", args.get(0)));
CommandHandler.sendMessage(sender, translate("commands.sendMail.user_not_exist", args.get(0)));
return;
}
}
}
mailBeingConstructed.put(senderId, mailBuilder);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_start_composition);
CommandHandler.sendMessage(sender, translate("commands.sendMail.start_composition"));
}
case 2 -> CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_templates);
default -> CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_invalid_arguments);
case 2 -> CommandHandler.sendMessage(sender, translate("commands.sendMail.templates"));
default -> CommandHandler.sendMessage(sender, translate("commands.sendMail.invalid_arguments"));
}
} else {
MailBuilder mailBuilder = mailBeingConstructed.get(senderId);
......@@ -63,28 +66,28 @@ public final class SendMailCommand implements CommandHandler {
switch (args.get(0).toLowerCase()) {
case "stop" -> {
mailBeingConstructed.remove(senderId);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_send_cancel);
CommandHandler.sendMessage(sender, translate("commands.sendMail.sendCancel"));
return;
}
case "finish" -> {
if (mailBuilder.constructionStage == 3) {
if (!mailBuilder.sendToAll) {
Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_send_done.replace("{name}", Integer.toString(mailBuilder.recipient)));
CommandHandler.sendMessage(sender, translate("commands.sendMail.send_done", Integer.toString(mailBuilder.recipient)));
} else {
for (Player player : DatabaseHelper.getAllPlayers()) {
Grasscutter.getGameServer().getPlayerByUid(player.getUid(), true).sendMail(mailBuilder.mail);
}
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_send_all_done);
CommandHandler.sendMessage(sender, translate("commands.sendMail.send_all_done"));
}
mailBeingConstructed.remove(senderId);
} else {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_not_composition_end.replace("{args}", getConstructionArgs(mailBuilder.constructionStage)));
CommandHandler.sendMessage(sender, translate("commands.sendMail.not_composition_end", getConstructionArgs(mailBuilder.constructionStage)));
}
return;
}
case "help" -> {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_please_use.replace("{args}", getConstructionArgs(mailBuilder.constructionStage)));
CommandHandler.sendMessage(sender, translate("commands.sendMail.please_use", getConstructionArgs(mailBuilder.constructionStage)));
return;
}
default -> {
......@@ -92,19 +95,19 @@ public final class SendMailCommand implements CommandHandler {
case 0 -> {
String title = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.title = title;
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_set_title.replace("{title}", title));
CommandHandler.sendMessage(sender, translate("commands.sendMail.set_title", title));
mailBuilder.constructionStage++;
}
case 1 -> {
String contents = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.content = contents;
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_set_contents.replace("{contents}", contents));
CommandHandler.sendMessage(sender, translate("commands.sendMail.set_contents", contents));
mailBuilder.constructionStage++;
}
case 2 -> {
String msgSender = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.sender = msgSender;
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_set_message_sender.replace("{send}", msgSender));
CommandHandler.sendMessage(sender, translate("commands.sendMail.set_message_sender", msgSender));
mailBuilder.constructionStage++;
}
case 3 -> {
......@@ -117,21 +120,21 @@ public final class SendMailCommand implements CommandHandler {
try {
refinement = Integer.parseInt(args.get(3));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_refinement);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemRefinement"));
return;
} // Fallthrough
case 3: // <itemId|itemName> [amount] [level]
try {
lvl = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_level);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemLevel"));
return;
} // Fallthrough
case 2: // <itemId|itemName> [amount]
try {
amount = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_amount);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.amount"));
return;
} // Fallthrough
case 1: // <itemId|itemName>
......@@ -139,46 +142,34 @@ public final class SendMailCommand implements CommandHandler {
item = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId"));
return;
}
break;
default: // *No args*
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_usage);
CommandHandler.sendMessage(sender, translate("commands.give.usage"));
return;
}
mailBuilder.mail.itemList.add(new Mail.MailItem(item, amount, lvl));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_send.replace("{amount}", Integer.toString(amount)).replace("{item}", Integer.toString(item)).replace("{lvl}", Integer.toString(lvl)));
CommandHandler.sendMessage(sender, translate("commands.sendMail.send", Integer.toString(amount), Integer.toString(item), Integer.toString(lvl)));
}
}
}
}
} else {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_invalid_arguments_please_use.replace("{args}", getConstructionArgs(mailBuilder.constructionStage)));
CommandHandler.sendMessage(sender, translate("commands.sendMail.invalid_arguments_please_use", getConstructionArgs(mailBuilder.constructionStage)));
}
}
}
private String getConstructionArgs(int stage) {
switch (stage) {
case 0 -> {
return Grasscutter.getLanguage().SendMail_title;
}
case 1 -> {
return Grasscutter.getLanguage().SendMail_message;
}
case 2 -> {
return Grasscutter.getLanguage().SendMail_sender;
}
case 3 -> {
return Grasscutter.getLanguage().SendMail_arguments;
}
default -> {
Thread.dumpStack();
return Grasscutter.getLanguage().SendMail_error.replace("{stage}", Integer.toString(stage));
}
}
return switch(stage) {
case 0 -> translate("commands.sendMail.title");
case 1 -> translate("commands.sendMail.message");
case 2 -> translate("commands.sendMail.sender");
case 3 -> translate("commands.sendMail.arguments");
default -> translate("commands.sendMail.error", Integer.toString(stage));
};
}
public static class MailBuilder {
......
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;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "say", usage = "say <message>", description = "Sends a message to a player as the server",
aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage")
public final class SendMessageCommand implements CommandHandler {
......@@ -14,16 +15,16 @@ public final class SendMessageCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() == 0) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SendMessage_usage);
CommandHandler.sendMessage(null, translate("commands.sendMessage.usage"));
return;
}
String message = String.join(" ", args);
CommandHandler.sendMessage(targetPlayer, message);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SenaMessage_message_sent);
CommandHandler.sendMessage(sender, translate("commands.sendMessage.success"));
}
}
\ No newline at end of file
......@@ -2,7 +2,6 @@ package emu.grasscutter.command.commands;
import java.util.List;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData;
......@@ -10,6 +9,8 @@ import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "setfetterlevel", usage = "setfetterlevel <level>",
description = "Sets your fetter level for your current active character",
aliases = {"setfetterlvl", "setfriendship"}, permission = "player.setfetterlevel")
......@@ -18,19 +19,19 @@ public final class SetFetterLevelCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() != 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_usage);
CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.usage"));
return;
}
try {
int fetterLevel = Integer.parseInt(args.get(0));
if (fetterLevel < 0 || fetterLevel > 10) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_fetter_level_must_between_0_and_10);
CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.range_error"));
return;
}
Avatar avatar = targetPlayer.getTeamManager().getCurrentAvatarEntity().getAvatar();
......@@ -42,9 +43,9 @@ public final class SetFetterLevelCommand implements CommandHandler {
avatar.save();
targetPlayer.sendPacket(new PacketAvatarFetterDataNotify(avatar));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_fetter_set_level.replace("{level}", Integer.toString(fetterLevel)));
CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.success", fetterLevel));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_invalid_fetter_level);
CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.level_error"));
}
}
......
......@@ -10,13 +10,15 @@ import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.languages.Language;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import emu.grasscutter.utils.Language;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "setstats", usage = "setstats|stats <stat> <value>",
description = "Set fight property for your current active character", aliases = {"stats"}, permission = "player.setstats")
public final class SetStatsCommand implements CommandHandler {
class Stat {
static class Stat {
String name;
FightProperty prop;
boolean percent;
......@@ -27,44 +29,43 @@ public final class SetStatsCommand implements CommandHandler {
this.percent = percent;
}
}
Map<String, Stat> stats;
Map<String, Stat> stats = new HashMap<>();
public SetStatsCommand() {
Language lang = Grasscutter.getLanguage();
stats = new HashMap<String, Stat>();
// Default stats
stats.put("maxhp", new Stat(lang.Stats_FIGHT_PROP_MAX_HP, FightProperty.FIGHT_PROP_MAX_HP, false));
stats.put("hp", new Stat(lang.Stats_FIGHT_PROP_CUR_HP, FightProperty.FIGHT_PROP_CUR_HP, false));
stats.put("atk", new Stat(lang.Stats_FIGHT_PROP_CUR_ATTACK, FightProperty.FIGHT_PROP_CUR_ATTACK, false));
stats.put("atkb", new Stat(lang.Stats_FIGHT_PROP_BASE_ATTACK, FightProperty.FIGHT_PROP_BASE_ATTACK, false)); // This doesn't seem to get used to recalculate ATK, so it's only useful for stuff like Bennett's buff.
stats.put("def", new Stat(lang.Stats_FIGHT_PROP_DEFENSE, FightProperty.FIGHT_PROP_DEFENSE, false));
stats.put("em", new Stat(lang.Stats_FIGHT_PROP_ELEMENT_MASTERY, FightProperty.FIGHT_PROP_ELEMENT_MASTERY, false));
stats.put("er", new Stat(lang.Stats_FIGHT_PROP_CHARGE_EFFICIENCY, FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, true));
stats.put("crate", new Stat(lang.Stats_FIGHT_PROP_CRITICAL, FightProperty.FIGHT_PROP_CRITICAL, true));
stats.put("cdmg", new Stat(lang.Stats_FIGHT_PROP_CRITICAL_HURT, FightProperty.FIGHT_PROP_CRITICAL_HURT, true));
stats.put("dmg", new Stat(lang.Stats_FIGHT_PROP_ADD_HURT, FightProperty.FIGHT_PROP_ADD_HURT, true)); // This seems to get reset after attacks
stats.put("eanemo", new Stat(lang.Stats_FIGHT_PROP_WIND_ADD_HURT, FightProperty.FIGHT_PROP_WIND_ADD_HURT, true));
stats.put("ecryo", new Stat(lang.Stats_FIGHT_PROP_ICE_ADD_HURT, FightProperty.FIGHT_PROP_ICE_ADD_HURT, true));
stats.put("edendro", new Stat(lang.Stats_FIGHT_PROP_GRASS_ADD_HURT, FightProperty.FIGHT_PROP_GRASS_ADD_HURT, true));
stats.put("eelectro", new Stat(lang.Stats_FIGHT_PROP_ELEC_ADD_HURT, FightProperty.FIGHT_PROP_ELEC_ADD_HURT, true));
stats.put("egeo", new Stat(lang.Stats_FIGHT_PROP_ROCK_ADD_HURT, FightProperty.FIGHT_PROP_ROCK_ADD_HURT, true));
stats.put("ehydro", new Stat(lang.Stats_FIGHT_PROP_WATER_ADD_HURT, FightProperty.FIGHT_PROP_WATER_ADD_HURT, true));
stats.put("epyro", new Stat(lang.Stats_FIGHT_PROP_FIRE_ADD_HURT, FightProperty.FIGHT_PROP_FIRE_ADD_HURT, true));
stats.put("ephys", new Stat(lang.Stats_FIGHT_PROP_PHYSICAL_ADD_HURT, FightProperty.FIGHT_PROP_PHYSICAL_ADD_HURT, true));
stats.put("resall", new Stat(lang.Stats_FIGHT_PROP_SUB_HURT, FightProperty.FIGHT_PROP_SUB_HURT, true)); // This seems to get reset after attacks
stats.put("resanemo", new Stat(lang.Stats_FIGHT_PROP_WIND_SUB_HURT, FightProperty.FIGHT_PROP_WIND_SUB_HURT, true));
stats.put("rescryo", new Stat(lang.Stats_FIGHT_PROP_ICE_SUB_HURT, FightProperty.FIGHT_PROP_ICE_SUB_HURT, true));
stats.put("resdendro", new Stat(lang.Stats_FIGHT_PROP_GRASS_SUB_HURT, FightProperty.FIGHT_PROP_GRASS_SUB_HURT, true));
stats.put("reselectro", new Stat(lang.Stats_FIGHT_PROP_ELEC_SUB_HURT, FightProperty.FIGHT_PROP_ELEC_SUB_HURT, true));
stats.put("resgeo", new Stat(lang.Stats_FIGHT_PROP_ROCK_SUB_HURT, FightProperty.FIGHT_PROP_ROCK_SUB_HURT, true));
stats.put("reshydro", new Stat(lang.Stats_FIGHT_PROP_WATER_SUB_HURT, FightProperty.FIGHT_PROP_WATER_SUB_HURT, true));
stats.put("respyro", new Stat(lang.Stats_FIGHT_PROP_FIRE_SUB_HURT, FightProperty.FIGHT_PROP_FIRE_SUB_HURT, true));
stats.put("resphys", new Stat(lang.Stats_FIGHT_PROP_PHYSICAL_SUB_HURT, FightProperty.FIGHT_PROP_PHYSICAL_SUB_HURT, true));
stats.put("cdr", new Stat(lang.Stats_FIGHT_PROP_SKILL_CD_MINUS_RATIO, FightProperty.FIGHT_PROP_SKILL_CD_MINUS_RATIO, true));
stats.put("heal", new Stat(lang.Stats_FIGHT_PROP_HEAL_ADD, FightProperty.FIGHT_PROP_HEAL_ADD, true));
stats.put("heali", new Stat(lang.Stats_FIGHT_PROP_HEALED_ADD, FightProperty.FIGHT_PROP_HEALED_ADD, true));
stats.put("shield", new Stat(lang.Stats_FIGHT_PROP_SHIELD_COST_MINUS_RATIO, FightProperty.FIGHT_PROP_SHIELD_COST_MINUS_RATIO, true));
stats.put("defi", new Stat(lang.Stats_FIGHT_PROP_DEFENCE_IGNORE_RATIO, FightProperty.FIGHT_PROP_DEFENCE_IGNORE_RATIO, true));
stats.put("maxhp", new Stat(FightProperty.FIGHT_PROP_MAX_HP.toString(), FightProperty.FIGHT_PROP_MAX_HP, false));
stats.put("hp", new Stat(FightProperty.FIGHT_PROP_CUR_HP.toString(), FightProperty.FIGHT_PROP_CUR_HP, false));
stats.put("atk", new Stat(FightProperty.FIGHT_PROP_CUR_ATTACK.toString(), FightProperty.FIGHT_PROP_CUR_ATTACK, false));
stats.put("atkb", new Stat(FightProperty.FIGHT_PROP_BASE_ATTACK.toString(), FightProperty.FIGHT_PROP_BASE_ATTACK, false)); // This doesn't seem to get used to recalculate ATK, so it's only useful for stuff like Bennett's buff.
stats.put("def", new Stat(FightProperty.FIGHT_PROP_DEFENSE.toString(), FightProperty.FIGHT_PROP_DEFENSE, false));
stats.put("em", new Stat(FightProperty.FIGHT_PROP_ELEMENT_MASTERY.toString(), FightProperty.FIGHT_PROP_ELEMENT_MASTERY, false));
stats.put("er", new Stat(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY.toString(), FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, true));
stats.put("crate", new Stat(FightProperty.FIGHT_PROP_CRITICAL.toString(), FightProperty.FIGHT_PROP_CRITICAL, true));
stats.put("cdmg", new Stat(FightProperty.FIGHT_PROP_CRITICAL_HURT.toString(), FightProperty.FIGHT_PROP_CRITICAL_HURT, true));
stats.put("dmg", new Stat(FightProperty.FIGHT_PROP_ADD_HURT.toString(), FightProperty.FIGHT_PROP_ADD_HURT, true)); // This seems to get reset after attacks
stats.put("eanemo", new Stat(FightProperty.FIGHT_PROP_WIND_ADD_HURT.toString(), FightProperty.FIGHT_PROP_WIND_ADD_HURT, true));
stats.put("ecryo", new Stat(FightProperty.FIGHT_PROP_ICE_ADD_HURT.toString(), FightProperty.FIGHT_PROP_ICE_ADD_HURT, true));
stats.put("edendro", new Stat(FightProperty.FIGHT_PROP_GRASS_ADD_HURT.toString(), FightProperty.FIGHT_PROP_GRASS_ADD_HURT, true));
stats.put("eelectro", new Stat(FightProperty.FIGHT_PROP_ELEC_ADD_HURT.toString(), FightProperty.FIGHT_PROP_ELEC_ADD_HURT, true));
stats.put("egeo", new Stat(FightProperty.FIGHT_PROP_ROCK_ADD_HURT.toString(), FightProperty.FIGHT_PROP_ROCK_ADD_HURT, true));
stats.put("ehydro", new Stat(FightProperty.FIGHT_PROP_WATER_ADD_HURT.toString(), FightProperty.FIGHT_PROP_WATER_ADD_HURT, true));
stats.put("epyro", new Stat(FightProperty.FIGHT_PROP_FIRE_ADD_HURT.toString(), FightProperty.FIGHT_PROP_FIRE_ADD_HURT, true));
stats.put("ephys", new Stat(FightProperty.FIGHT_PROP_PHYSICAL_ADD_HURT.toString(), FightProperty.FIGHT_PROP_PHYSICAL_ADD_HURT, true));
stats.put("resall", new Stat(FightProperty.FIGHT_PROP_SUB_HURT.toString(), FightProperty.FIGHT_PROP_SUB_HURT, true)); // This seems to get reset after attacks
stats.put("resanemo", new Stat(FightProperty.FIGHT_PROP_WIND_SUB_HURT.toString(), FightProperty.FIGHT_PROP_WIND_SUB_HURT, true));
stats.put("rescryo", new Stat(FightProperty.FIGHT_PROP_ICE_SUB_HURT.toString(), FightProperty.FIGHT_PROP_ICE_SUB_HURT, true));
stats.put("resdendro", new Stat(FightProperty.FIGHT_PROP_GRASS_SUB_HURT.toString(), FightProperty.FIGHT_PROP_GRASS_SUB_HURT, true));
stats.put("reselectro", new Stat(FightProperty.FIGHT_PROP_ELEC_SUB_HURT.toString(), FightProperty.FIGHT_PROP_ELEC_SUB_HURT, true));
stats.put("resgeo", new Stat(FightProperty.FIGHT_PROP_ROCK_SUB_HURT.toString(), FightProperty.FIGHT_PROP_ROCK_SUB_HURT, true));
stats.put("reshydro", new Stat(FightProperty.FIGHT_PROP_WATER_SUB_HURT.toString(), FightProperty.FIGHT_PROP_WATER_SUB_HURT, true));
stats.put("respyro", new Stat(FightProperty.FIGHT_PROP_FIRE_SUB_HURT.toString(), FightProperty.FIGHT_PROP_FIRE_SUB_HURT, true));
stats.put("resphys", new Stat(FightProperty.FIGHT_PROP_PHYSICAL_SUB_HURT.toString(), FightProperty.FIGHT_PROP_PHYSICAL_SUB_HURT, true));
stats.put("cdr", new Stat(FightProperty.FIGHT_PROP_SKILL_CD_MINUS_RATIO.toString(), FightProperty.FIGHT_PROP_SKILL_CD_MINUS_RATIO, true));
stats.put("heal", new Stat(FightProperty.FIGHT_PROP_HEAL_ADD.toString(), FightProperty.FIGHT_PROP_HEAL_ADD, true));
stats.put("heali", new Stat(FightProperty.FIGHT_PROP_HEALED_ADD.toString(), FightProperty.FIGHT_PROP_HEALED_ADD, true));
stats.put("shield", new Stat(FightProperty.FIGHT_PROP_SHIELD_COST_MINUS_RATIO.toString(), FightProperty.FIGHT_PROP_SHIELD_COST_MINUS_RATIO, true));
stats.put("defi", new Stat(FightProperty.FIGHT_PROP_DEFENCE_IGNORE_RATIO.toString(), FightProperty.FIGHT_PROP_DEFENCE_IGNORE_RATIO, true));
// Compatibility aliases
stats.put("mhp", stats.get("maxhp"));
stats.put("cr", stats.get("crate"));
......@@ -175,26 +176,23 @@ public final class SetStatsCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
Language lang = Grasscutter.getLanguage();
String syntax = sender == null ? lang.SetStats_usage_console : lang.SetStats_usage_console;
String usage = syntax + lang.SetStats_help_message;
String syntax = sender == null ? translate("commands.setStats.usage_console") : translate("commands.setStats.ingame");
String usage = syntax + translate("commands.setStats.help_message");
String statStr;
String valueStr;
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, lang.Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
switch (args.size()) {
default:
CommandHandler.sendMessage(sender, usage);
return;
case 2:
statStr = args.get(0).toLowerCase();
valueStr = args.get(1);
break;
};
if (args.size() == 2) {
statStr = args.get(0).toLowerCase();
valueStr = args.get(1);
} else {
CommandHandler.sendMessage(sender, usage);
return;
}
EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
......@@ -206,7 +204,7 @@ public final class SetStatsCommand implements CommandHandler {
value = Float.parseFloat(valueStr);
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, lang.SetStats_value_error);
CommandHandler.sendMessage(sender, translate("commands.setStats.value_error"));
return;
}
......@@ -220,15 +218,14 @@ public final class SetStatsCommand implements CommandHandler {
valueStr = String.format("%.0f", value);
}
if (targetPlayer == sender) {
CommandHandler.sendMessage(sender, lang.SetStats_set_self.replace("{name}", stat.name).replace("{value}", valueStr));
CommandHandler.sendMessage(sender, translate("commands.setStats.set_self", stat.name, valueStr));
} else {
String uidStr = targetPlayer.getAccount().getId();
CommandHandler.sendMessage(sender, lang.SetStats_set_for_uid.replace("{name}", stat.name).replace("{uid}", uidStr).replace("{value}", valueStr));
CommandHandler.sendMessage(sender, translate("commands.setStats.set_self", stat.name, uidStr, valueStr));
}
return;
} else {
CommandHandler.sendMessage(sender, usage);
return;
}
return;
}
}
......@@ -7,6 +7,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "setworldlevel", usage = "setworldlevel <level>",
description = "Sets your world level (Relog to see proper effects)",
aliases = {"setworldlvl"}, permission = "player.setworldlevel")
......@@ -15,19 +17,19 @@ public final class SetWorldLevelCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetWorldLevel_usage);
CommandHandler.sendMessage(sender, translate("commands.setWorldLevel.usage"));
return;
}
try {
int level = Integer.parseInt(args.get(0));
if (level > 8 || level < 0) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetWorldLevel_world_level_must_between_0_and_8);
CommandHandler.sendMessage(sender, translate("commands.setWorldLevel.value_error"));
return;
}
......@@ -35,9 +37,9 @@ public final class SetWorldLevelCommand implements CommandHandler {
targetPlayer.getWorld().setWorldLevel(level);
targetPlayer.setWorldLevel(level);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetWorldLevel_set_world_level.replace("{level}", Integer.toString(level)));
CommandHandler.sendMessage(sender, translate("commands.setWorldLevel.success", Integer.toString(level)));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SetWorldLevel_invalid_world_level);
CommandHandler.sendMessage(null, translate("commands.setWorldLevel.invalid_world_level"));
}
}
}
......@@ -20,6 +20,8 @@ import javax.swing.text.html.parser.Entity;
import java.util.List;
import java.util.Random;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "spawn", usage = "spawn <entityId> [amount] [level(monster only)]",
description = "Spawns an entity near you", permission = "server.spawn")
public final class SpawnCommand implements CommandHandler {
......@@ -27,7 +29,7 @@ public final class SpawnCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
......@@ -39,23 +41,23 @@ public final class SpawnCommand implements CommandHandler {
try {
level = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments);
CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
} // Fallthrough
case 2:
try {
amount = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_amount);
CommandHandler.sendMessage(sender, translate("commands.generic.error.amount"));
} // Fallthrough
case 1:
try {
id = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id);
CommandHandler.sendMessage(sender, translate("commands.generic.error.entityId"));
}
break;
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Spawn_usage);
CommandHandler.sendMessage(sender, translate("commands.spawn.usage"));
return;
}
......@@ -63,7 +65,7 @@ public final class SpawnCommand implements CommandHandler {
GadgetData gadgetData = GameData.getGadgetDataMap().get(id);
ItemData itemData = GameData.getItemDataMap().get(id);
if (monsterData == null && gadgetData == null && itemData == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id);
CommandHandler.sendMessage(sender, translate("commands.generic.error.entityId"));
return;
}
Scene scene = targetPlayer.getScene();
......@@ -99,7 +101,7 @@ public final class SpawnCommand implements CommandHandler {
scene.addEntity(entity);
}
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Spawn_message.replace("{amount}", Integer.toString(amount)).replace("{id}", Integer.toString(id)));
CommandHandler.sendMessage(sender, translate("commands.spawn.success", Integer.toString(amount), Integer.toString(id)));
}
private Position GetRandomPositionInCircle(Position origin, double radius){
......
......@@ -7,17 +7,19 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "stop", usage = "stop",
description = "Stops the server", permission = "server.stop")
public final class StopCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Stop_message);
CommandHandler.sendMessage(null, translate("commands.stop.success"));
for (Player p : Grasscutter.getGameServer().getPlayers().values()) {
CommandHandler.sendMessage(p, Grasscutter.getLanguage().Stop_message);
CommandHandler.sendMessage(p, translate("commands.stop.success"));
}
System.exit(1);
System.exit(1000);
}
}
......@@ -12,13 +12,15 @@ import emu.grasscutter.server.packet.send.PacketAvatarSkillUpgradeRsp;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "talent", usage = "talent <talentID> <value>",
description = "Set talent level for your current active character", 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);
if (talentLevel < 0 || talentLevel > 15) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_lower_16);
CommandHandler.sendMessage(sender, translate("commands.talent.lower_16"));
return;
}
......@@ -30,29 +32,29 @@ public final class TalentCommand implements CommandHandler {
player.sendPacket(new PacketAvatarSkillChangeNotify(avatar, talentId, oldLevel, talentLevel));
player.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, talentId, oldLevel, talentLevel));
String successMessage = Grasscutter.getLanguage().Talent_set_id.replace("{id}", Integer.toString(talentId));
String successMessage = "commands.talent.set_id";
AvatarSkillDepotData depot = avatar.getData().getSkillDepot();
if (talentId == depot.getSkills().get(0)) {
successMessage = Grasscutter.getLanguage().Talent_set_atk;
successMessage = "commands.talent.set_atk";
} else if (talentId == depot.getSkills().get(1)) {
successMessage = Grasscutter.getLanguage().Talent_set_e;
successMessage = "commands.talent.set_e";
} else if (talentId == depot.getEnergySkill()) {
successMessage = Grasscutter.getLanguage().Talent_set_q;
successMessage = "commands.talent.set_q";
}
CommandHandler.sendMessage(sender, successMessage.replace("{level}", Integer.toString(talentLevel)));
CommandHandler.sendMessage(sender, translate(successMessage, talentLevel));
}
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() < 1){
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
CommandHandler.sendMessage(sender, translate("commands.talent.usage_1"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_2"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_3"));
return;
}
......@@ -60,66 +62,54 @@ public final class TalentCommand implements CommandHandler {
Avatar avatar = entity.getAvatar();
String cmdSwitch = args.get(0);
switch (cmdSwitch) {
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
return;
case "set":
if (args.size() < 3){
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
default -> {
CommandHandler.sendMessage(sender, translate("commands.talent.usage_1"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_2"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_3"));
return;
}
case "set" -> {
if (args.size() < 3) {
CommandHandler.sendMessage(sender, translate("commands.talent.usage_1"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_3"));
return;
}
try {
int skillId = Integer.parseInt(args.get(1));
int newLevel = Integer.parseInt(args.get(2));
setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel);
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_skill_id);
CommandHandler.sendMessage(sender, translate("commands.talent.invalid_skill_id"));
return;
}
break;
case "n":
case "e":
case "q":
if (args.size() < 2){
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
}
case "n", "e", "q" -> {
if (args.size() < 2) {
CommandHandler.sendMessage(sender, translate("commands.talent.usage_2"));
return;
}
AvatarSkillDepotData SkillDepot = avatar.getData().getSkillDepot();
int skillId;
switch (cmdSwitch) {
default:
skillId = SkillDepot.getSkills().get(0);
break;
case "e":
skillId = SkillDepot.getSkills().get(1);
break;
case "q":
skillId = SkillDepot.getEnergySkill();
break;
}
int skillId = switch (cmdSwitch) {
default -> SkillDepot.getSkills().get(0);
case "e" -> SkillDepot.getSkills().get(1);
case "q" -> SkillDepot.getEnergySkill();
};
try {
int newLevel = Integer.parseInt(args.get(1));
setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel);
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_talent_level);
CommandHandler.sendMessage(sender, translate("commands.talent.invalid_level"));
return;
}
break;
case "getid":
}
case "getid" -> {
int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0);
int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1);
int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_normal_attack_id.replace("{id}", Integer.toString(skillIdNorAtk)));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_e_skill_id.replace("{id}", Integer.toString(skillIdE)));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_q_skill_id.replace("{id}", Integer.toString(skillIdQ)));
break;
CommandHandler.sendMessage(sender, translate("commands.talent.normal_attack_id", Integer.toString(skillIdNorAtk)));
CommandHandler.sendMessage(sender, translate("commands.talent.e_skill_id", Integer.toString(skillIdE)));
CommandHandler.sendMessage(sender, translate("commands.talent.q_skill_id", Integer.toString(skillIdQ)));
}
}
}
}
......@@ -8,18 +8,20 @@ import emu.grasscutter.utils.Position;
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")
public final class TeleportAllCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (!targetPlayer.getWorld().isMultiplayer()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().TeleportAll_message);
CommandHandler.sendMessage(sender, translate("commands.teleportAll.error"));
return;
}
......@@ -30,5 +32,7 @@ public final class TeleportAllCommand implements CommandHandler {
player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), pos);
}
CommandHandler.sendMessage(sender, translate("commands.teleportAll.success"));
}
}
......@@ -8,6 +8,8 @@ import emu.grasscutter.utils.Position;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "teleport", usage = "teleport <x> <y> <z> [scene id]", aliases = {"tp"},
description = "Change the player's position.", permission = "player.teleport")
public final class TeleportCommand implements CommandHandler {
......@@ -26,7 +28,7 @@ public final class TeleportCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
......@@ -41,7 +43,7 @@ public final class TeleportCommand implements CommandHandler {
try {
sceneId = Integer.parseInt(args.get(3));
}catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments);
CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
} // Fallthrough
case 3:
try {
......@@ -49,20 +51,23 @@ public final class TeleportCommand implements CommandHandler {
y = parseRelative(args.get(1), y);
z = parseRelative(args.get(2), z);
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
CommandHandler.sendMessage(sender, translate("commands.teleport.invalid_position"));
}
break;
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_usage);
CommandHandler.sendMessage(sender, translate("commands.teleport.usage"));
return;
}
Position target_pos = new Position(x, y, z);
boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, target_pos);
if (!result) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
CommandHandler.sendMessage(sender, translate("commands.teleport.invalid_position"));
} else {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_message.replace("{name}", targetPlayer.getNickname()).replace("{x}", Float.toString(x)).replace("{y}", Float.toString(y)).replace("{z}", Float.toString(z)).replace("{id}", Integer.toString(sceneId)));
CommandHandler.sendMessage(sender, translate("commands.teleport.success",
targetPlayer.getNickname(), Float.toString(x), Float.toString(y),
Float.toString(z), Integer.toString(sceneId))
);
}
}
......
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