Commit 38fd7bb7 authored by Magix's avatar Magix Committed by GitHub
Browse files

Merge pull request #567 from Grasscutters/localization

Implement a proper language system
parents 6d678557 c11e83c4
...@@ -10,6 +10,8 @@ import emu.grasscutter.game.world.Scene; ...@@ -10,6 +10,8 @@ import emu.grasscutter.game.world.Scene;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "killall", usage = "killall [sceneId]", @Command(label = "killall", usage = "killall [sceneId]",
description = "Kill all entities", permission = "server.killall") description = "Kill all entities", permission = "server.killall")
public final class KillAllCommand implements CommandHandler { public final class KillAllCommand implements CommandHandler {
...@@ -17,7 +19,7 @@ public final class KillAllCommand implements CommandHandler { ...@@ -17,7 +19,7 @@ public final class KillAllCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
...@@ -30,14 +32,14 @@ public final class KillAllCommand implements CommandHandler { ...@@ -30,14 +32,14 @@ public final class KillAllCommand implements CommandHandler {
scene = targetPlayer.getWorld().getSceneById(Integer.parseInt(args.get(0))); scene = targetPlayer.getWorld().getSceneById(Integer.parseInt(args.get(0)));
break; break;
default: default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Kill_usage); CommandHandler.sendMessage(sender, translate("commands.kill.usage"));
return; return;
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments); CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
} }
if (scene == null) { 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; return;
} }
...@@ -46,7 +48,7 @@ public final class KillAllCommand implements CommandHandler { ...@@ -46,7 +48,7 @@ public final class KillAllCommand implements CommandHandler {
List<GameEntity> toKill = sceneF.getEntities().values().stream() List<GameEntity> toKill = sceneF.getEntities().values().stream()
.filter(entity -> entity instanceof EntityMonster) .filter(entity -> entity instanceof EntityMonster)
.toList(); .toList();
toKill.stream().forEach(entity -> sceneF.killEntity(entity, 0)); toKill.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()))); CommandHandler.sendMessage(sender, translate("commands.kill.kill_monsters_in_scene", Integer.toString(toKill.size()), Integer.toString(scene.getId())));
} }
} }
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.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
...@@ -12,6 +11,8 @@ import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify; ...@@ -12,6 +11,8 @@ import emu.grasscutter.server.packet.send.PacketLifeStateChangeNotify;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "killcharacter", usage = "killcharacter", aliases = {"suicide", "kill"}, @Command(label = "killcharacter", usage = "killcharacter", aliases = {"suicide", "kill"},
description = "Kills the players current character", permission = "player.killcharacter") description = "Kills the players current character", permission = "player.killcharacter")
public final class KillCharacterCommand implements CommandHandler { public final class KillCharacterCommand implements CommandHandler {
...@@ -19,7 +20,7 @@ public final class KillCharacterCommand implements CommandHandler { ...@@ -19,7 +20,7 @@ public final class KillCharacterCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
...@@ -32,6 +33,6 @@ public final class KillCharacterCommand implements CommandHandler { ...@@ -32,6 +33,6 @@ public final class KillCharacterCommand implements CommandHandler {
targetPlayer.getScene().removeEntity(entity); targetPlayer.getScene().removeEntity(entity);
entity.onDeath(0); 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; ...@@ -8,6 +8,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "list", usage = "list [uid]", @Command(label = "list", usage = "list [uid]",
description = "List online players", aliases = {"players"}) description = "List online players", aliases = {"players"})
public final class ListCommand implements CommandHandler { public final class ListCommand implements CommandHandler {
...@@ -21,7 +23,7 @@ public final class ListCommand implements CommandHandler { ...@@ -21,7 +23,7 @@ public final class ListCommand implements CommandHandler {
needUID = args.get(0).equals("uid"); 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) { if (playersMap.size() != 0) {
StringBuilder playerSet = new StringBuilder(); StringBuilder playerSet = new StringBuilder();
......
...@@ -8,6 +8,8 @@ import emu.grasscutter.game.player.Player; ...@@ -8,6 +8,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "permission", usage = "permission <add|remove> <permission>", @Command(label = "permission", usage = "permission <add|remove> <permission>",
description = "Grants or removes a permission for a user", permission = "*") description = "Grants or removes a permission for a user", permission = "*")
public final class PermissionCommand implements CommandHandler { public final class PermissionCommand implements CommandHandler {
...@@ -15,12 +17,12 @@ public final class PermissionCommand implements CommandHandler { ...@@ -15,12 +17,12 @@ public final class PermissionCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
if (args.size() != 2) { if (args.size() != 2) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage); CommandHandler.sendMessage(sender, translate("commands.permission.usage"));
return; return;
} }
...@@ -29,23 +31,23 @@ public final class PermissionCommand implements CommandHandler { ...@@ -29,23 +31,23 @@ public final class PermissionCommand implements CommandHandler {
Account account = targetPlayer.getAccount(); Account account = targetPlayer.getAccount();
if (account == null) { if (account == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Account_not_find); CommandHandler.sendMessage(sender, translate("commands.permission.account_error"));
return; return;
} }
switch (action) { switch (action) {
default: default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage); CommandHandler.sendMessage(sender, translate("commands.permission.usage"));
break; break;
case "add": case "add":
if (account.addPermission(permission)) { if (account.addPermission(permission)) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_add); CommandHandler.sendMessage(sender, translate("commands.permission.add"));
} else CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_have_permission); } else CommandHandler.sendMessage(sender, translate("commands.permission.has_error"));
break; break;
case "remove": case "remove":
if (account.removePermission(permission)) { if (account.removePermission(permission)) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_remove); CommandHandler.sendMessage(sender, translate("commands.permission.remove"));
} else CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_not_have_permission); } else CommandHandler.sendMessage(sender, translate("commands.permission.not_have_error"));
break; break;
} }
......
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;
...@@ -8,6 +7,8 @@ import emu.grasscutter.utils.Position; ...@@ -8,6 +7,8 @@ import emu.grasscutter.utils.Position;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "position", usage = "position", aliases = {"pos"}, @Command(label = "position", usage = "position", aliases = {"pos"},
description = "Get coordinates.") description = "Get coordinates.")
public final class PositionCommand implements CommandHandler { public final class PositionCommand implements CommandHandler {
...@@ -15,11 +16,13 @@ public final class PositionCommand implements CommandHandler { ...@@ -15,11 +16,13 @@ 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) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
Position pos = targetPlayer.getPos(); 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; ...@@ -7,19 +7,23 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "reload", usage = "reload", @Command(label = "reload", usage = "reload",
description = "Reload server config", permission = "server.reload") description = "Reload server config", permission = "server.reload")
public final class ReloadCommand implements CommandHandler { public final class ReloadCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { 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.loadConfig();
Grasscutter.loadLanguage(); Grasscutter.loadLanguage();
Grasscutter.getGameServer().getGachaManager().load(); Grasscutter.getGameServer().getGachaManager().load();
Grasscutter.getGameServer().getDropManager().load(); Grasscutter.getGameServer().getDropManager().load();
Grasscutter.getGameServer().getShopManager().load(); Grasscutter.getGameServer().getShopManager().load();
Grasscutter.getDispatchServer().loadQueries(); Grasscutter.getDispatchServer().loadQueries();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Reload_reload_done);
CommandHandler.sendMessage(sender, translate("commands.reload.reload_done"));
} }
} }
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.avatar.Avatar; import emu.grasscutter.game.avatar.Avatar;
...@@ -9,6 +8,8 @@ import emu.grasscutter.game.player.Player; ...@@ -9,6 +8,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "resetconst", usage = "resetconst [all]", @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.", 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") aliases = {"resetconstellation"}, permission = "player.resetconstellation")
...@@ -17,13 +18,13 @@ public final class ResetConstCommand implements CommandHandler { ...@@ -17,13 +18,13 @@ public final class ResetConstCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) { if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
targetPlayer.getAvatars().forEach(this::resetConstellation); targetPlayer.getAvatars().forEach(this::resetConstellation);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().ResetConst_reset_all); CommandHandler.sendMessage(sender, translate("commands.resetConst.reset_all"));
} else { } else {
EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
if (entity == null) { if (entity == null) {
...@@ -33,7 +34,7 @@ public final class ResetConstCommand implements CommandHandler { ...@@ -33,7 +34,7 @@ public final class ResetConstCommand implements CommandHandler {
Avatar avatar = entity.getAvatar(); Avatar avatar = entity.getAvatar();
this.resetConstellation(avatar); 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; ...@@ -7,18 +7,20 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "resetshop", usage = "resetshop", @Command(label = "resetshop", usage = "resetshop",
description = "Reset target player's shop refresh time.", permission = "server.resetshop") description = "Reset target player's shop refresh time.", permission = "server.resetshop")
public final class ResetShopLimitCommand implements CommandHandler { public final class ResetShopLimitCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
targetPlayer.getShopLimit().forEach(x -> x.setNextRefreshTime(0)); targetPlayer.getShopLimit().forEach(x -> x.setNextRefreshTime(0));
targetPlayer.save(); 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; ...@@ -10,6 +10,9 @@ import emu.grasscutter.game.player.Player;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@SuppressWarnings("ConstantConditions")
@Command(label = "sendmail", usage = "sendmail <userId|all|help> [templateId]", @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") 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 { public final class SendMailCommand implements CommandHandler {
...@@ -45,16 +48,16 @@ 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) { if (DatabaseHelper.getPlayerById(Integer.parseInt(args.get(0))) != null) {
mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail()); mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail());
} else { } 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; return;
} }
} }
} }
mailBeingConstructed.put(senderId, mailBuilder); 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); case 2 -> CommandHandler.sendMessage(sender, translate("commands.sendMail.templates"));
default -> CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_invalid_arguments); default -> CommandHandler.sendMessage(sender, translate("commands.sendMail.invalid_arguments"));
} }
} else { } else {
MailBuilder mailBuilder = mailBeingConstructed.get(senderId); MailBuilder mailBuilder = mailBeingConstructed.get(senderId);
...@@ -63,28 +66,28 @@ public final class SendMailCommand implements CommandHandler { ...@@ -63,28 +66,28 @@ public final class SendMailCommand implements CommandHandler {
switch (args.get(0).toLowerCase()) { switch (args.get(0).toLowerCase()) {
case "stop" -> { case "stop" -> {
mailBeingConstructed.remove(senderId); mailBeingConstructed.remove(senderId);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_send_cancel); CommandHandler.sendMessage(sender, translate("commands.sendMail.sendCancel"));
return; return;
} }
case "finish" -> { case "finish" -> {
if (mailBuilder.constructionStage == 3) { if (mailBuilder.constructionStage == 3) {
if (!mailBuilder.sendToAll) { if (!mailBuilder.sendToAll) {
Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail); 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 { } else {
for (Player player : DatabaseHelper.getAllPlayers()) { for (Player player : DatabaseHelper.getAllPlayers()) {
Grasscutter.getGameServer().getPlayerByUid(player.getUid(), true).sendMail(mailBuilder.mail); 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); mailBeingConstructed.remove(senderId);
} else { } 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; return;
} }
case "help" -> { 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; return;
} }
default -> { default -> {
...@@ -92,19 +95,19 @@ public final class SendMailCommand implements CommandHandler { ...@@ -92,19 +95,19 @@ public final class SendMailCommand implements CommandHandler {
case 0 -> { case 0 -> {
String title = String.join(" ", args.subList(0, args.size())); String title = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.title = title; 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++; mailBuilder.constructionStage++;
} }
case 1 -> { case 1 -> {
String contents = String.join(" ", args.subList(0, args.size())); String contents = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.content = contents; 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++; mailBuilder.constructionStage++;
} }
case 2 -> { case 2 -> {
String msgSender = String.join(" ", args.subList(0, args.size())); String msgSender = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.sender = msgSender; 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++; mailBuilder.constructionStage++;
} }
case 3 -> { case 3 -> {
...@@ -117,21 +120,21 @@ public final class SendMailCommand implements CommandHandler { ...@@ -117,21 +120,21 @@ public final class SendMailCommand implements CommandHandler {
try { try {
refinement = Integer.parseInt(args.get(3)); refinement = Integer.parseInt(args.get(3));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_refinement); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemRefinement"));
return; return;
} // Fallthrough } // Fallthrough
case 3: // <itemId|itemName> [amount] [level] case 3: // <itemId|itemName> [amount] [level]
try { try {
lvl = Integer.parseInt(args.get(2)); lvl = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_level); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemLevel"));
return; return;
} // Fallthrough } // Fallthrough
case 2: // <itemId|itemName> [amount] case 2: // <itemId|itemName> [amount]
try { try {
amount = Integer.parseInt(args.get(1)); amount = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_amount); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.amount"));
return; return;
} // Fallthrough } // Fallthrough
case 1: // <itemId|itemName> case 1: // <itemId|itemName>
...@@ -139,46 +142,34 @@ public final class SendMailCommand implements CommandHandler { ...@@ -139,46 +142,34 @@ public final class SendMailCommand implements CommandHandler {
item = Integer.parseInt(args.get(0)); item = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook. // 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; return;
} }
break; break;
default: // *No args* default: // *No args*
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_usage); CommandHandler.sendMessage(sender, translate("commands.give.usage"));
return; return;
} }
mailBuilder.mail.itemList.add(new Mail.MailItem(item, amount, lvl)); 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 { } 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) { private String getConstructionArgs(int stage) {
switch (stage) { return switch(stage) {
case 0 -> { case 0 -> translate("commands.sendMail.title");
return Grasscutter.getLanguage().SendMail_title; case 1 -> translate("commands.sendMail.message");
} case 2 -> translate("commands.sendMail.sender");
case 1 -> { case 3 -> translate("commands.sendMail.arguments");
return Grasscutter.getLanguage().SendMail_message; default -> translate("commands.sendMail.error", Integer.toString(stage));
} };
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));
}
}
} }
public static class MailBuilder { public static class MailBuilder {
......
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;
import java.util.List; 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", @Command(label = "say", usage = "say <message>", description = "Sends a message to a player as the server",
aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage") aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage")
public final class SendMessageCommand implements CommandHandler { public final class SendMessageCommand implements CommandHandler {
...@@ -14,16 +15,16 @@ public final class SendMessageCommand implements CommandHandler { ...@@ -14,16 +15,16 @@ public final class SendMessageCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
if (args.size() == 0) { if (args.size() == 0) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SendMessage_usage); CommandHandler.sendMessage(null, translate("commands.sendMessage.usage"));
return; return;
} }
String message = String.join(" ", args); String message = String.join(" ", args);
CommandHandler.sendMessage(targetPlayer, message); 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; ...@@ -2,7 +2,6 @@ package emu.grasscutter.command.commands;
import java.util.List; import java.util.List;
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;
...@@ -10,6 +9,8 @@ import emu.grasscutter.game.avatar.Avatar; ...@@ -10,6 +9,8 @@ import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify; import emu.grasscutter.server.packet.send.PacketAvatarFetterDataNotify;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "setfetterlevel", usage = "setfetterlevel <level>", @Command(label = "setfetterlevel", usage = "setfetterlevel <level>",
description = "Sets your fetter level for your current active character", description = "Sets your fetter level for your current active character",
aliases = {"setfetterlvl", "setfriendship"}, permission = "player.setfetterlevel") aliases = {"setfetterlvl", "setfriendship"}, permission = "player.setfetterlevel")
...@@ -18,19 +19,19 @@ public final class SetFetterLevelCommand implements CommandHandler { ...@@ -18,19 +19,19 @@ public final class SetFetterLevelCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
if (args.size() != 1) { if (args.size() != 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_usage); CommandHandler.sendMessage(sender, translate("commands.setFetterLevel.usage"));
return; return;
} }
try { try {
int fetterLevel = Integer.parseInt(args.get(0)); int fetterLevel = Integer.parseInt(args.get(0));
if (fetterLevel < 0 || fetterLevel > 10) { 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; return;
} }
Avatar avatar = targetPlayer.getTeamManager().getCurrentAvatarEntity().getAvatar(); Avatar avatar = targetPlayer.getTeamManager().getCurrentAvatarEntity().getAvatar();
...@@ -42,9 +43,9 @@ public final class SetFetterLevelCommand implements CommandHandler { ...@@ -42,9 +43,9 @@ public final class SetFetterLevelCommand implements CommandHandler {
avatar.save(); avatar.save();
targetPlayer.sendPacket(new PacketAvatarFetterDataNotify(avatar)); 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) { } 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; ...@@ -10,13 +10,15 @@ import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.languages.Language;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; 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>", @Command(label = "setstats", usage = "setstats|stats <stat> <value>",
description = "Set fight property for your current active character", aliases = {"stats"}, permission = "player.setstats") description = "Set fight property for your current active character", aliases = {"stats"}, permission = "player.setstats")
public final class SetStatsCommand implements CommandHandler { public final class SetStatsCommand implements CommandHandler {
class Stat { static class Stat {
String name; String name;
FightProperty prop; FightProperty prop;
boolean percent; boolean percent;
...@@ -27,44 +29,43 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -27,44 +29,43 @@ public final class SetStatsCommand implements CommandHandler {
this.percent = percent; this.percent = percent;
} }
} }
Map<String, Stat> stats;
Map<String, Stat> stats = new HashMap<>();
public SetStatsCommand() { public SetStatsCommand() {
Language lang = Grasscutter.getLanguage();
stats = new HashMap<String, Stat>();
// Default stats // Default stats
stats.put("maxhp", new Stat(lang.Stats_FIGHT_PROP_MAX_HP, FightProperty.FIGHT_PROP_MAX_HP, false)); stats.put("maxhp", new Stat(FightProperty.FIGHT_PROP_MAX_HP.toString(), 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("hp", new Stat(FightProperty.FIGHT_PROP_CUR_HP.toString(), 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("atk", new Stat(FightProperty.FIGHT_PROP_CUR_ATTACK.toString(), 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("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(lang.Stats_FIGHT_PROP_DEFENSE, FightProperty.FIGHT_PROP_DEFENSE, false)); stats.put("def", new Stat(FightProperty.FIGHT_PROP_DEFENSE.toString(), FightProperty.FIGHT_PROP_DEFENSE, false));
stats.put("em", new Stat(lang.Stats_FIGHT_PROP_ELEMENT_MASTERY, FightProperty.FIGHT_PROP_ELEMENT_MASTERY, false)); stats.put("em", new Stat(FightProperty.FIGHT_PROP_ELEMENT_MASTERY.toString(), 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("er", new Stat(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY.toString(), FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, true));
stats.put("crate", new Stat(lang.Stats_FIGHT_PROP_CRITICAL, FightProperty.FIGHT_PROP_CRITICAL, true)); stats.put("crate", new Stat(FightProperty.FIGHT_PROP_CRITICAL.toString(), FightProperty.FIGHT_PROP_CRITICAL, true));
stats.put("cdmg", new Stat(lang.Stats_FIGHT_PROP_CRITICAL_HURT, FightProperty.FIGHT_PROP_CRITICAL_HURT, true)); stats.put("cdmg", new Stat(FightProperty.FIGHT_PROP_CRITICAL_HURT.toString(), 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("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(lang.Stats_FIGHT_PROP_WIND_ADD_HURT, FightProperty.FIGHT_PROP_WIND_ADD_HURT, true)); stats.put("eanemo", new Stat(FightProperty.FIGHT_PROP_WIND_ADD_HURT.toString(), 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("ecryo", new Stat(FightProperty.FIGHT_PROP_ICE_ADD_HURT.toString(), 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("edendro", new Stat(FightProperty.FIGHT_PROP_GRASS_ADD_HURT.toString(), 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("eelectro", new Stat(FightProperty.FIGHT_PROP_ELEC_ADD_HURT.toString(), 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("egeo", new Stat(FightProperty.FIGHT_PROP_ROCK_ADD_HURT.toString(), 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("ehydro", new Stat(FightProperty.FIGHT_PROP_WATER_ADD_HURT.toString(), 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("epyro", new Stat(FightProperty.FIGHT_PROP_FIRE_ADD_HURT.toString(), 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("ephys", new Stat(FightProperty.FIGHT_PROP_PHYSICAL_ADD_HURT.toString(), 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("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(lang.Stats_FIGHT_PROP_WIND_SUB_HURT, FightProperty.FIGHT_PROP_WIND_SUB_HURT, true)); stats.put("resanemo", new Stat(FightProperty.FIGHT_PROP_WIND_SUB_HURT.toString(), 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("rescryo", new Stat(FightProperty.FIGHT_PROP_ICE_SUB_HURT.toString(), 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("resdendro", new Stat(FightProperty.FIGHT_PROP_GRASS_SUB_HURT.toString(), 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("reselectro", new Stat(FightProperty.FIGHT_PROP_ELEC_SUB_HURT.toString(), 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("resgeo", new Stat(FightProperty.FIGHT_PROP_ROCK_SUB_HURT.toString(), 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("reshydro", new Stat(FightProperty.FIGHT_PROP_WATER_SUB_HURT.toString(), 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("respyro", new Stat(FightProperty.FIGHT_PROP_FIRE_SUB_HURT.toString(), 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("resphys", new Stat(FightProperty.FIGHT_PROP_PHYSICAL_SUB_HURT.toString(), 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("cdr", new Stat(FightProperty.FIGHT_PROP_SKILL_CD_MINUS_RATIO.toString(), 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("heal", new Stat(FightProperty.FIGHT_PROP_HEAL_ADD.toString(), 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("heali", new Stat(FightProperty.FIGHT_PROP_HEALED_ADD.toString(), 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("shield", new Stat(FightProperty.FIGHT_PROP_SHIELD_COST_MINUS_RATIO.toString(), 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("defi", new Stat(FightProperty.FIGHT_PROP_DEFENCE_IGNORE_RATIO.toString(), FightProperty.FIGHT_PROP_DEFENCE_IGNORE_RATIO, true));
// Compatibility aliases // Compatibility aliases
stats.put("mhp", stats.get("maxhp")); stats.put("mhp", stats.get("maxhp"));
stats.put("cr", stats.get("crate")); stats.put("cr", stats.get("crate"));
...@@ -175,26 +176,23 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -175,26 +176,23 @@ public final class SetStatsCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
Language lang = Grasscutter.getLanguage(); String syntax = sender == null ? translate("commands.setStats.usage_console") : translate("commands.setStats.ingame");
String syntax = sender == null ? lang.SetStats_usage_console : lang.SetStats_usage_console; String usage = syntax + translate("commands.setStats.help_message");
String usage = syntax + lang.SetStats_help_message;
String statStr; String statStr;
String valueStr; String valueStr;
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, lang.Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
switch (args.size()) { if (args.size() == 2) {
default:
CommandHandler.sendMessage(sender, usage);
return;
case 2:
statStr = args.get(0).toLowerCase(); statStr = args.get(0).toLowerCase();
valueStr = args.get(1); valueStr = args.get(1);
break; } else {
}; CommandHandler.sendMessage(sender, usage);
return;
}
EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity(); EntityAvatar entity = targetPlayer.getTeamManager().getCurrentAvatarEntity();
...@@ -206,7 +204,7 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -206,7 +204,7 @@ public final class SetStatsCommand implements CommandHandler {
value = Float.parseFloat(valueStr); value = Float.parseFloat(valueStr);
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, lang.SetStats_value_error); CommandHandler.sendMessage(sender, translate("commands.setStats.value_error"));
return; return;
} }
...@@ -220,15 +218,14 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -220,15 +218,14 @@ public final class SetStatsCommand implements CommandHandler {
valueStr = String.format("%.0f", value); valueStr = String.format("%.0f", value);
} }
if (targetPlayer == sender) { 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 { } else {
String uidStr = targetPlayer.getAccount().getId(); 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 { } else {
CommandHandler.sendMessage(sender, usage); CommandHandler.sendMessage(sender, usage);
return;
} }
return;
} }
} }
...@@ -7,6 +7,8 @@ import emu.grasscutter.game.player.Player; ...@@ -7,6 +7,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "setworldlevel", usage = "setworldlevel <level>", @Command(label = "setworldlevel", usage = "setworldlevel <level>",
description = "Sets your world level (Relog to see proper effects)", description = "Sets your world level (Relog to see proper effects)",
aliases = {"setworldlvl"}, permission = "player.setworldlevel") aliases = {"setworldlvl"}, permission = "player.setworldlevel")
...@@ -15,19 +17,19 @@ public final class SetWorldLevelCommand implements CommandHandler { ...@@ -15,19 +17,19 @@ public final class SetWorldLevelCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetWorldLevel_usage); CommandHandler.sendMessage(sender, translate("commands.setWorldLevel.usage"));
return; return;
} }
try { try {
int level = Integer.parseInt(args.get(0)); int level = Integer.parseInt(args.get(0));
if (level > 8 || level < 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; return;
} }
...@@ -35,9 +37,9 @@ public final class SetWorldLevelCommand implements CommandHandler { ...@@ -35,9 +37,9 @@ public final class SetWorldLevelCommand implements CommandHandler {
targetPlayer.getWorld().setWorldLevel(level); targetPlayer.getWorld().setWorldLevel(level);
targetPlayer.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) { } 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; ...@@ -20,6 +20,8 @@ import javax.swing.text.html.parser.Entity;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "spawn", usage = "spawn <entityId> [amount] [level(monster only)]", @Command(label = "spawn", usage = "spawn <entityId> [amount] [level(monster only)]",
description = "Spawns an entity near you", permission = "server.spawn") description = "Spawns an entity near you", permission = "server.spawn")
public final class SpawnCommand implements CommandHandler { public final class SpawnCommand implements CommandHandler {
...@@ -27,7 +29,7 @@ public final class SpawnCommand implements CommandHandler { ...@@ -27,7 +29,7 @@ public final class SpawnCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
...@@ -39,23 +41,23 @@ public final class SpawnCommand implements CommandHandler { ...@@ -39,23 +41,23 @@ public final class SpawnCommand implements CommandHandler {
try { try {
level = Integer.parseInt(args.get(2)); level = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments); CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
} // Fallthrough } // Fallthrough
case 2: case 2:
try { try {
amount = Integer.parseInt(args.get(1)); amount = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_amount); CommandHandler.sendMessage(sender, translate("commands.generic.error.amount"));
} // Fallthrough } // Fallthrough
case 1: case 1:
try { try {
id = Integer.parseInt(args.get(0)); id = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id); CommandHandler.sendMessage(sender, translate("commands.generic.error.entityId"));
} }
break; break;
default: default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Spawn_usage); CommandHandler.sendMessage(sender, translate("commands.spawn.usage"));
return; return;
} }
...@@ -63,7 +65,7 @@ public final class SpawnCommand implements CommandHandler { ...@@ -63,7 +65,7 @@ public final class SpawnCommand implements CommandHandler {
GadgetData gadgetData = GameData.getGadgetDataMap().get(id); GadgetData gadgetData = GameData.getGadgetDataMap().get(id);
ItemData itemData = GameData.getItemDataMap().get(id); ItemData itemData = GameData.getItemDataMap().get(id);
if (monsterData == null && gadgetData == null && itemData == null) { if (monsterData == null && gadgetData == null && itemData == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id); CommandHandler.sendMessage(sender, translate("commands.generic.error.entityId"));
return; return;
} }
Scene scene = targetPlayer.getScene(); Scene scene = targetPlayer.getScene();
...@@ -99,7 +101,7 @@ public final class SpawnCommand implements CommandHandler { ...@@ -99,7 +101,7 @@ public final class SpawnCommand implements CommandHandler {
scene.addEntity(entity); 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){ private Position GetRandomPositionInCircle(Position origin, double radius){
......
...@@ -7,17 +7,19 @@ import emu.grasscutter.game.player.Player; ...@@ -7,17 +7,19 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "stop", usage = "stop", @Command(label = "stop", usage = "stop",
description = "Stops the server", permission = "server.stop") description = "Stops the server", permission = "server.stop")
public final class StopCommand implements CommandHandler { public final class StopCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { 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()) { 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; ...@@ -12,13 +12,15 @@ import emu.grasscutter.server.packet.send.PacketAvatarSkillUpgradeRsp;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "talent", usage = "talent <talentID> <value>", @Command(label = "talent", usage = "talent <talentID> <value>",
description = "Set talent level for your current active character", permission = "player.settalent") description = "Set talent level for your current active character", permission = "player.settalent")
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);
if (talentLevel < 0 || talentLevel > 15) { if (talentLevel < 0 || talentLevel > 15) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_lower_16); CommandHandler.sendMessage(sender, translate("commands.talent.lower_16"));
return; return;
} }
...@@ -30,29 +32,29 @@ public final class TalentCommand implements CommandHandler { ...@@ -30,29 +32,29 @@ public final class TalentCommand implements CommandHandler {
player.sendPacket(new PacketAvatarSkillChangeNotify(avatar, talentId, oldLevel, talentLevel)); player.sendPacket(new PacketAvatarSkillChangeNotify(avatar, talentId, oldLevel, talentLevel));
player.sendPacket(new PacketAvatarSkillUpgradeRsp(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(); AvatarSkillDepotData depot = avatar.getData().getSkillDepot();
if (talentId == depot.getSkills().get(0)) { if (talentId == depot.getSkills().get(0)) {
successMessage = Grasscutter.getLanguage().Talent_set_atk; successMessage = "commands.talent.set_atk";
} else if (talentId == depot.getSkills().get(1)) { } else if (talentId == depot.getSkills().get(1)) {
successMessage = Grasscutter.getLanguage().Talent_set_e; successMessage = "commands.talent.set_e";
} else if (talentId == depot.getEnergySkill()) { } 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 @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
if (args.size() < 1){ if (args.size() < 1){
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1); CommandHandler.sendMessage(sender, translate("commands.talent.usage_1"));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2); CommandHandler.sendMessage(sender, translate("commands.talent.usage_2"));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3); CommandHandler.sendMessage(sender, translate("commands.talent.usage_3"));
return; return;
} }
...@@ -60,66 +62,54 @@ public final class TalentCommand implements CommandHandler { ...@@ -60,66 +62,54 @@ public final class TalentCommand implements CommandHandler {
Avatar avatar = entity.getAvatar(); Avatar avatar = entity.getAvatar();
String cmdSwitch = args.get(0); String cmdSwitch = args.get(0);
switch (cmdSwitch) { switch (cmdSwitch) {
default: default -> {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1); CommandHandler.sendMessage(sender, translate("commands.talent.usage_1"));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2); CommandHandler.sendMessage(sender, translate("commands.talent.usage_2"));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3); CommandHandler.sendMessage(sender, translate("commands.talent.usage_3"));
return; return;
case "set": }
if (args.size() < 3){ case "set" -> {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1); if (args.size() < 3) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3); CommandHandler.sendMessage(sender, translate("commands.talent.usage_1"));
CommandHandler.sendMessage(sender, translate("commands.talent.usage_3"));
return; return;
} }
try { try {
int skillId = Integer.parseInt(args.get(1)); int skillId = Integer.parseInt(args.get(1));
int newLevel = Integer.parseInt(args.get(2)); int newLevel = Integer.parseInt(args.get(2));
setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel); setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_skill_id); CommandHandler.sendMessage(sender, translate("commands.talent.invalid_skill_id"));
return; return;
} }
break; }
case "n": case "n", "e", "q" -> {
case "e": if (args.size() < 2) {
case "q": CommandHandler.sendMessage(sender, translate("commands.talent.usage_2"));
if (args.size() < 2){
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
return; return;
} }
AvatarSkillDepotData SkillDepot = avatar.getData().getSkillDepot(); AvatarSkillDepotData SkillDepot = avatar.getData().getSkillDepot();
int skillId; int skillId = switch (cmdSwitch) {
switch (cmdSwitch) { default -> SkillDepot.getSkills().get(0);
default: case "e" -> SkillDepot.getSkills().get(1);
skillId = SkillDepot.getSkills().get(0); case "q" -> SkillDepot.getEnergySkill();
break; };
case "e":
skillId = SkillDepot.getSkills().get(1);
break;
case "q":
skillId = SkillDepot.getEnergySkill();
break;
}
try { try {
int newLevel = Integer.parseInt(args.get(1)); int newLevel = Integer.parseInt(args.get(1));
setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel); setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_talent_level); CommandHandler.sendMessage(sender, translate("commands.talent.invalid_level"));
return; return;
} }
break; }
case "getid": case "getid" -> {
int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0); int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0);
int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1); int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1);
int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill(); int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill();
CommandHandler.sendMessage(sender, translate("commands.talent.normal_attack_id", Integer.toString(skillIdNorAtk)));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_normal_attack_id.replace("{id}", Integer.toString(skillIdNorAtk))); CommandHandler.sendMessage(sender, translate("commands.talent.e_skill_id", Integer.toString(skillIdE)));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_e_skill_id.replace("{id}", Integer.toString(skillIdE))); CommandHandler.sendMessage(sender, translate("commands.talent.q_skill_id", Integer.toString(skillIdQ)));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_q_skill_id.replace("{id}", Integer.toString(skillIdQ))); }
break;
} }
} }
} }
...@@ -8,18 +8,20 @@ import emu.grasscutter.utils.Position; ...@@ -8,18 +8,20 @@ import emu.grasscutter.utils.Position;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "tpall", usage = "tpall", @Command(label = "tpall", usage = "tpall",
description = "Teleports all players in your world to your position", permission = "player.tpall") description = "Teleports all players in your world to your position", permission = "player.tpall")
public final class TeleportAllCommand implements CommandHandler { public final class TeleportAllCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
if (!targetPlayer.getWorld().isMultiplayer()) { if (!targetPlayer.getWorld().isMultiplayer()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().TeleportAll_message); CommandHandler.sendMessage(sender, translate("commands.teleportAll.error"));
return; return;
} }
...@@ -30,5 +32,7 @@ public final class TeleportAllCommand implements CommandHandler { ...@@ -30,5 +32,7 @@ public final class TeleportAllCommand implements CommandHandler {
player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), pos); player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), pos);
} }
CommandHandler.sendMessage(sender, translate("commands.teleportAll.success"));
} }
} }
...@@ -8,6 +8,8 @@ import emu.grasscutter.utils.Position; ...@@ -8,6 +8,8 @@ import emu.grasscutter.utils.Position;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "teleport", usage = "teleport <x> <y> <z> [scene id]", aliases = {"tp"}, @Command(label = "teleport", usage = "teleport <x> <y> <z> [scene id]", aliases = {"tp"},
description = "Change the player's position.", permission = "player.teleport") description = "Change the player's position.", permission = "player.teleport")
public final class TeleportCommand implements CommandHandler { public final class TeleportCommand implements CommandHandler {
...@@ -26,7 +28,7 @@ public final class TeleportCommand implements CommandHandler { ...@@ -26,7 +28,7 @@ public final class TeleportCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
...@@ -41,7 +43,7 @@ public final class TeleportCommand implements CommandHandler { ...@@ -41,7 +43,7 @@ public final class TeleportCommand implements CommandHandler {
try { try {
sceneId = Integer.parseInt(args.get(3)); sceneId = Integer.parseInt(args.get(3));
}catch (NumberFormatException ignored) { }catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments); CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
} // Fallthrough } // Fallthrough
case 3: case 3:
try { try {
...@@ -49,20 +51,23 @@ public final class TeleportCommand implements CommandHandler { ...@@ -49,20 +51,23 @@ public final class TeleportCommand implements CommandHandler {
y = parseRelative(args.get(1), y); y = parseRelative(args.get(1), y);
z = parseRelative(args.get(2), z); z = parseRelative(args.get(2), z);
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position); CommandHandler.sendMessage(sender, translate("commands.teleport.invalid_position"));
} }
break; break;
default: default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_usage); CommandHandler.sendMessage(sender, translate("commands.teleport.usage"));
return; return;
} }
Position target_pos = new Position(x, y, z); Position target_pos = new Position(x, y, z);
boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, target_pos); boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, target_pos);
if (!result) { if (!result) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position); CommandHandler.sendMessage(sender, translate("commands.teleport.invalid_position"));
} else { } 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))
);
} }
} }
......
...@@ -9,6 +9,8 @@ import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify; ...@@ -9,6 +9,8 @@ import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "weather", usage = "weather <weatherId> [climateId]", @Command(label = "weather", usage = "weather <weatherId> [climateId]",
description = "Changes the weather.", aliases = {"w"}, permission = "player.weather") description = "Changes the weather.", aliases = {"w"}, permission = "player.weather")
public final class WeatherCommand implements CommandHandler { public final class WeatherCommand implements CommandHandler {
...@@ -16,7 +18,7 @@ public final class WeatherCommand implements CommandHandler { ...@@ -16,7 +18,7 @@ public final class WeatherCommand 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 (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
...@@ -27,17 +29,17 @@ public final class WeatherCommand implements CommandHandler { ...@@ -27,17 +29,17 @@ public final class WeatherCommand implements CommandHandler {
try { try {
climateId = Integer.parseInt(args.get(1)); climateId = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id); CommandHandler.sendMessage(sender, translate("commands.weather.invalid_id"));
} }
case 1: case 1:
try { try {
weatherId = Integer.parseInt(args.get(0)); weatherId = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id); CommandHandler.sendMessage(sender, translate("commands.weather.invalid_id"));
} }
break; break;
default: default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_usage); CommandHandler.sendMessage(sender, translate("commands.weather.usage"));
return; return;
} }
...@@ -46,7 +48,6 @@ public final class WeatherCommand implements CommandHandler { ...@@ -46,7 +48,6 @@ public final class WeatherCommand implements CommandHandler {
targetPlayer.getScene().setWeather(weatherId); targetPlayer.getScene().setWeather(weatherId);
targetPlayer.getScene().setClimate(climate); targetPlayer.getScene().setClimate(climate);
targetPlayer.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(targetPlayer)); targetPlayer.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(targetPlayer));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_message.replace("{weatherId}", Integer.toString(weatherId)).replace("{climateId}", Integer.toString(climateId))); CommandHandler.sendMessage(sender, translate("commands.weather.success", Integer.toString(weatherId), Integer.toString(climateId)));
} }
} }
...@@ -4,13 +4,7 @@ import com.google.gson.reflect.TypeToken; ...@@ -4,13 +4,7 @@ import com.google.gson.reflect.TypeToken;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
import emu.grasscutter.data.common.ItemParamData; import emu.grasscutter.data.common.ItemParamData;
import emu.grasscutter.data.def.ItemData;
import emu.grasscutter.data.def.ShopGoodsData; import emu.grasscutter.data.def.ShopGoodsData;
import emu.grasscutter.game.inventory.GameItem;
import emu.grasscutter.game.managers.InventoryManager;
import emu.grasscutter.game.props.ActionReason;
import emu.grasscutter.net.proto.ItemParamOuterClass;
import emu.grasscutter.net.proto.ShopGoodsOuterClass;
import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.utils.Utils; import emu.grasscutter.utils.Utils;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
...@@ -54,9 +48,9 @@ public class ShopManager { ...@@ -54,9 +48,9 @@ public class ShopManager {
public static int getShopNextRefreshTime(ShopInfo shopInfo) { public static int getShopNextRefreshTime(ShopInfo shopInfo) {
return switch (shopInfo.getShopRefreshType()) { return switch (shopInfo.getShopRefreshType()) {
case SHOP_REFRESH_DAILY -> Utils.GetNextTimestampOfThisHour(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam()); case SHOP_REFRESH_DAILY -> Utils.getNextTimestampOfThisHour(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
case SHOP_REFRESH_WEEKLY -> Utils.GetNextTimestampOfThisHourInNextWeek(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam()); case SHOP_REFRESH_WEEKLY -> Utils.getNextTimestampOfThisHourInNextWeek(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
case SHOP_REFRESH_MONTHLY -> Utils.GetNextTimestampOfThisHourInNextMonth(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam()); case SHOP_REFRESH_MONTHLY -> Utils.getNextTimestampOfThisHourInNextMonth(REFRESH_HOUR, TIME_ZONE, shopInfo.getShopRefreshParam());
default -> 0; default -> 0;
}; };
} }
......
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