Commit c0b1ec1b authored by KingRainbow44's avatar KingRainbow44
Browse files

Convert to the superior language system. (pt. 2)

parent 7a084100
......@@ -64,6 +64,4 @@ mitmdump.exe
!lib/*.jar
mongod.exe
/src/generated/
/*.sh
language/
languages/
/*.sh
\ No newline at end of file
......@@ -6,7 +6,6 @@ import emu.grasscutter.Grasscutter.ServerRunMode;
import emu.grasscutter.game.mail.Mail;
public final class Config {
public String DatabaseUrl = "mongodb://localhost:27017";
public String DatabaseCollection = "grasscutter";
......
......@@ -8,6 +8,8 @@ import org.reflections.Reflections;
import java.util.*;
import static emu.grasscutter.utils.Language.translate;
@SuppressWarnings({"UnusedReturnValue", "unused"})
public final class CommandMap {
private final Map<String, CommandHandler> commands = new HashMap<>();
......@@ -109,7 +111,7 @@ public final class CommandMap {
public void invoke(Player player, Player targetPlayer, String rawMessage) {
rawMessage = rawMessage.trim();
if (rawMessage.length() == 0) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().No_command_specified);
CommandHandler.sendMessage(player, translate("commands.generic.not_specified"));
return;
}
......@@ -118,11 +120,12 @@ public final class CommandMap {
List<String> args = new LinkedList<>(Arrays.asList(split));
String label = args.remove(0);
String playerId = (player == null) ? consoleId : player.getAccount().getId();
// Check for special cases - currently only target command
// Check for special cases - currently only target command.
String targetUidStr = null;
if (label.startsWith("@")) { // @[UID]
if (label.startsWith("@")) { // @[UID]
targetUidStr = label.substring(1);
} else if (label.equalsIgnoreCase("target")) { // target [[@]UID]
} else if (label.equalsIgnoreCase("target")) { // target [[@]UID]
if (args.size() > 0) {
targetUidStr = args.get(0);
if (targetUidStr.startsWith("@")) {
......@@ -133,68 +136,64 @@ public final class CommandMap {
}
}
if (targetUidStr != null) {
if (targetUidStr.equals("")) { // Clears default targetPlayer
if (targetUidStr.equals("")) { // Clears the default targetPlayer.
targetPlayerIds.remove(playerId);
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Target_cleared);
return;
} else { // Sets default targetPlayer to the UID given
CommandHandler.sendMessage(player, translate("commands.execution.clear_target"));
} else { // Sets default targetPlayer to the UID provided.
try {
int uid = Integer.parseInt(targetUidStr);
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid);
if (targetPlayer == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline);
CommandHandler.sendMessage(player, translate("commands.generic.execution.player_exist_offline_error"));
} else {
targetPlayerIds.put(playerId, uid);
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Target_set.replace("{uid}", targetUidStr));
CommandHandler.sendMessage(player, translate("commands.execution.set_target", targetUidStr));
}
} catch (NumberFormatException e) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Invalid_UID);
CommandHandler.sendMessage(player, translate("commands.execution.uid_error"));
}
return;
}
return;
}
// Get command handler.
CommandHandler handler = this.commands.get(label);
if (handler == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Unknown_command + label);
CommandHandler.sendMessage(player, translate("commands.generic.unknown_command", label));
return;
}
// If any @UID argument is present, override targetPlayer with it
// If any @UID argument is present, override targetPlayer with it.
for (int i = 0; i < args.size(); i++) {
String arg = args.get(i);
if (!arg.startsWith("@")) {
continue;
} else {
if (arg.startsWith("@")) {
arg = args.remove(i).substring(1);
try {
int uid = Integer.parseInt(arg);
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid);
if (targetPlayer == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline);
CommandHandler.sendMessage(player, translate("commands.generic.execution.player_exist_offline_error"));
return;
}
break;
} catch (NumberFormatException e) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Invalid_UID);
CommandHandler.sendMessage(player, translate("commands.execution.uid_error"));
return;
}
}
}
// If there's still no targetPlayer at this point, use previously-set target
if (targetPlayer == null) {
if (targetPlayerIds.containsKey(playerId)) {
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(targetPlayerIds.get(playerId)); // We check every time in case the target goes offline after being targeted
if (targetPlayer == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline);
CommandHandler.sendMessage(player, translate("commands.generic.execution.player_exist_offline_error"));
return;
}
} else {
// If there's still no targetPlayer at this point, use local player
if (targetPlayer == null) {
targetPlayer = player;
}
// If there's still no targetPlayer at this point, use executor.
targetPlayer = player;
}
}
......@@ -205,12 +204,12 @@ public final class CommandMap {
Account account = player.getAccount();
if (player != targetPlayer) { // Additional permission required for targeting another player
if (!permissionNodeTargeted.isEmpty() && !account.hasPermission(permissionNodeTargeted)) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().You_not_permission_run_command);
CommandHandler.sendMessage(player, translate("commands.generic.permission_error"));
return;
}
}
if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().You_not_permission_run_command);
CommandHandler.sendMessage(player, translate("commands.generic.permission_error"));
return;
}
}
......@@ -220,10 +219,8 @@ public final class CommandMap {
final Player targetPlayerF = targetPlayer; // Is there a better way to do this?
Runnable runnable = () -> handler.execute(player, targetPlayerF, args);
if(threading) {
Thread command = new Thread(runnable);
command.start();
}
else {
new Thread(runnable).start();
} else {
runnable.run();
}
}
......
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.database.DatabaseHelper;
......@@ -8,18 +7,20 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "account", usage = "account <create|delete> <username> [uid]", description = "Modify user accounts")
public final class AccountCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender != null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().This_command_can_only_run_from_console);
CommandHandler.sendMessage(sender, translate("commands.generic.console_execute_error"));
return;
}
if (args.size() < 2) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_command_usage);
CommandHandler.sendMessage(null, translate("commands.account.command_usage"));
return;
}
......@@ -28,7 +29,7 @@ public final class AccountCommand implements CommandHandler {
switch (action) {
default:
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_command_usage);
CommandHandler.sendMessage(null, translate("commands.account.command_usage"));
return;
case "create":
int uid = 0;
......@@ -36,27 +37,27 @@ public final class AccountCommand implements CommandHandler {
try {
uid = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Invalid_UID);
CommandHandler.sendMessage(null, translate("commands.account.invalid"));
return;
}
}
emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid);
if (account == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_exists);
CommandHandler.sendMessage(null, translate("commands.account.exists"));
return;
} else {
account.addPermission("*");
account.save(); // Save account to database.
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_create_UID.replace("{uid}", Integer.toString(account.getPlayerUid())));
CommandHandler.sendMessage(null, translate("commands.account.create", Integer.toString(account.getPlayerUid())));
}
return;
case "delete":
if (DatabaseHelper.deleteAccount(username)) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_delete);
CommandHandler.sendMessage(null, translate("commands.account.delete"));
} else {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_not_find);
CommandHandler.sendMessage(null, translate("commands.account.no_account"));
}
}
}
......
......@@ -7,6 +7,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "broadcast", usage = "broadcast <message>",
description = "Sends a message to all the players", aliases = {"b"}, permission = "server.broadcast")
public final class BroadcastCommand implements CommandHandler {
......@@ -14,7 +16,7 @@ public final class BroadcastCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_command_usage);
CommandHandler.sendMessage(sender, translate("commands.broadcast.command_usage"));
return;
}
......@@ -24,6 +26,6 @@ public final class BroadcastCommand implements CommandHandler {
CommandHandler.sendMessage(p, message);
}
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_message_sent);
CommandHandler.sendMessage(sender, translate("commands.broadcast.message_sent"));
}
}
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 = "changescene", usage = "changescene <scene id>",
description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene")
public final class ChangeSceneCommand 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().Change_screen_usage);
CommandHandler.sendMessage(sender, translate("commands.changescene.usage"));
return;
}
try {
int sceneId = Integer.parseInt(args.get(0));
if (sceneId == targetPlayer.getSceneId()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_you_in_that_screen);
CommandHandler.sendMessage(sender, translate("commands.changescene.already_in_scene"));
return;
}
boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, targetPlayer.getPos());
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen + sceneId);
CommandHandler.sendMessage(sender, translate("commands.changescene.result", Integer.toString(sceneId)));
if (!result) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_not_exist);
CommandHandler.sendMessage(sender, translate("commands.changescene.exists_error"));
}
} catch (Exception e) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments);
CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
}
}
}
......@@ -10,6 +10,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "clear", usage = "clear <all|wp|art|mat>", //Merged /clearartifacts and /clearweapons to /clear <args> [uid]
description = "Deletes unequipped unlocked items, including yellow rarity ones from your inventory",
aliases = {"clear"}, permission = "player.clearinv")
......@@ -19,11 +21,11 @@ public final class ClearCommand 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().Clear_usage);
CommandHandler.sendMessage(sender, translate("commands.clear.command_usage"));
return;
}
Inventory playerInventory = targetPlayer.getInventory();
......@@ -35,7 +37,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getItemType() == ItemType.ITEM_WEAPON)
.filter(item -> !item.isLocked() && !item.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_weapons.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.weapons", targetPlayer.getNickname()));
}
case "art" -> {
toDelete = playerInventory.getItems().values().stream()
......@@ -43,7 +45,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.artifacts", targetPlayer.getNickname()));
}
case "mat" -> {
toDelete = playerInventory.getItems().values().stream()
......@@ -51,7 +53,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.materials", targetPlayer.getNickname()));
}
case "all" -> {
toDelete = playerInventory.getItems().values().stream()
......@@ -59,34 +61,44 @@ public final class ClearCommand implements CommandHandler {
.filter(item1 -> item1.getLevel() == 1 && item1.getExp() == 0)
.filter(item1 -> !item1.isLocked() && !item1.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.artifacts", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
toDelete = playerInventory.getItems().values().stream()
.filter(item2 -> item2.getItemType() == ItemType.ITEM_MATERIAL)
.filter(item2 -> !item2.isLocked() && !item2.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.materials", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream()
.filter(item3 -> item3.getItemType() == ItemType.ITEM_WEAPON)
.filter(item3 -> item3.getLevel() == 1 && item3.getExp() == 0)
.filter(item3 -> !item3.isLocked() && !item3.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.weapons", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream()
.filter(item4 -> item4.getItemType() == ItemType.ITEM_FURNITURE)
.filter(item4 -> !item4.isLocked() && !item4.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_furniture.replace("{name}", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.furniture", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream()
.filter(item5 -> item5.getItemType() == ItemType.ITEM_DISPLAY)
.filter(item5 -> !item5.isLocked() && !item5.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_displays.replace("{name}", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.displays", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream()
.filter(item6 -> item6.getItemType() == ItemType.ITEM_VIRTUAL)
.filter(item6 -> !item6.isLocked() && !item6.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_virtuals.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_everything.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.virtuals", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.everything", targetPlayer.getNickname()));
}
}
......
......@@ -13,7 +13,7 @@ public final class CoopCommand 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;
}
......
......@@ -11,6 +11,8 @@ import emu.grasscutter.utils.Position;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "drop", usage = "drop <itemId|itemName> [amount]",
description = "Drops an item near you", aliases = {"d", "dropitem"}, permission = "server.drop")
public final class DropCommand implements CommandHandler {
......@@ -18,7 +20,7 @@ public final class DropCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(null, translate("commands.execution.need_target"));
return;
}
......@@ -30,25 +32,25 @@ public final class DropCommand implements CommandHandler {
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;
} // Slightly cheeky here: no break so it falls through to initialize the first argument too
} // Slightly cheeky here: no break, so it falls through to initialize the first argument too
case 1:
try {
item = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId"));
return;
}
break;
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Drop_usage);
CommandHandler.sendMessage(sender, translate("commands.drop.command_usage"));
return;
}
ItemData itemData = GameData.getItemDataMap().get(item);
if (itemData == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId"));
return;
}
if (itemData.isEquip()) {
......@@ -62,6 +64,6 @@ public final class DropCommand implements CommandHandler {
EntityItem entity = new EntityItem(targetPlayer.getScene(), targetPlayer, itemData, targetPlayer.getPos().clone().addY(3f), amount);
targetPlayer.getScene().addEntity(entity);
}
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Drop_dropped_of.replace("{amount}", Integer.toString(amount)).replace("{item}", Integer.toString(item)));
CommandHandler.sendMessage(sender, translate("commands.drop.success", Integer.toString(amount), Integer.toString(item)));
}
}
\ No newline at end of file
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 = "enterdungeon", usage = "enterdungeon <dungeon id>",
description = "Enter a dungeon", aliases = {"dungeon"}, permission = "player.enterdungeon")
public final class EnterDungeonCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(null, translate("commands.execution.need_target"));
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_usage);
CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.usage"));
return;
}
try {
int dungeonId = Integer.parseInt(args.get(0));
if (dungeonId == targetPlayer.getSceneId()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_you_in_that_dungeon);
CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.in_dungeon_error"));
return;
}
boolean result = targetPlayer.getServer().getDungeonManager().enterDungeon(targetPlayer.getSession().getPlayer(), 0, dungeonId);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_changed_to_dungeon + dungeonId);
CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.changed", dungeonId));
if (!result) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_dungeon_not_found);
CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.not_found_error"));
}
} catch (Exception e) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_usage);
CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.usage"));
}
}
}
......@@ -20,7 +20,7 @@ public final class GiveAllCommand 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;
}
int amount = 99999;
......
......@@ -19,7 +19,7 @@ public final class GiveArtifactCommand 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;
}
......
......@@ -10,6 +10,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "givechar", usage = "givechar <avatarId> [level]",
description = "Gives the player a specified character", aliases = {"givec"}, permission = "player.givechar")
public final class GiveCharCommand implements CommandHandler {
......@@ -17,7 +19,7 @@ public final class GiveCharCommand 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,7 +32,7 @@ public final class GiveCharCommand implements CommandHandler {
level = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook.
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_avatar_level);
CommandHandler.sendMessage(sender, translate("commands.execution.invalid.avatarLevel"));
return;
} // Cheeky fall-through to parse first argument too
case 1:
......@@ -38,24 +40,24 @@ public final class GiveCharCommand implements CommandHandler {
avatarId = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook.
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_avatar_id);
CommandHandler.sendMessage(sender, translate("commands.execution.invalid.avatarId"));
return;
}
break;
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_usage);
CommandHandler.sendMessage(sender, translate("commands.giveChar.usage"));
return;
}
AvatarData avatarData = GameData.getAvatarDataMap().get(avatarId);
if (avatarData == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_avatar_id);
CommandHandler.sendMessage(sender, translate("commands.execution.invalid.avatarId"));
return;
}
// Check level.
if (level > 90) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_avatar_level);
CommandHandler.sendMessage(sender, translate("commands.execution.invalid.avatarLevel"));
return;
}
......@@ -75,6 +77,6 @@ public final class GiveCharCommand implements CommandHandler {
avatar.recalcStats();
targetPlayer.addAvatar(avatar);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_given.replace("{avatarId}", Integer.toString(avatarId)).replace("{level}", Integer.toString(level)).replace("{target}", Integer.toString(targetPlayer.getUid())));
CommandHandler.sendMessage(sender, translate("commands.execution.giveChar.given", Integer.toString(avatarId), Integer.toString(level), Integer.toString(targetPlayer.getUid())));
}
}
......@@ -15,6 +15,8 @@ import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "give", usage = "give <itemId|itemName> [amount] [level]", description = "Gives an item to you or the specified player", aliases = {
"g", "item", "giveitem"}, permission = "player.give")
public final class GiveCommand implements CommandHandler {
......@@ -33,7 +35,7 @@ public final class GiveCommand 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;
}
int item;
......@@ -67,21 +69,21 @@ public final class GiveCommand 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>
......@@ -89,30 +91,28 @@ public final class GiveCommand 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;
}
ItemData itemData = GameData.getItemDataMap().get(item);
if (itemData == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId"));
return;
}
if (refinement != 0) {
if (itemData.getItemType() == ItemType.ITEM_WEAPON) {
if (refinement < 1 || refinement > 5) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_refinement_must_between_1_and_5);
CommandHandler.sendMessage(sender, translate("commands.give.refinement_must_between_1_and_5"));
return;
}
} else {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_refinement_only_applicable_weapons);
CommandHandler.sendMessage(sender, translate("commands.give.refinement_only_applicable_weapons"));
return;
}
}
......@@ -120,11 +120,11 @@ public final class GiveCommand implements CommandHandler {
this.item(targetPlayer, itemData, amount, lvl, refinement);
if (!itemData.isEquip()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_given.replace("{amount}", Integer.toString(amount)).replace("{item}", Integer.toString(item)).replace("{target}", Integer.toString(targetPlayer.getUid())));
CommandHandler.sendMessage(sender, translate("commands.give.given", Integer.toString(amount), Integer.toString(item), Integer.toString(targetPlayer.getUid())));
} else if (itemData.getItemType() == ItemType.ITEM_WEAPON) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_given_with_level_and_refinement.replace("{item}", Integer.toString(item)).replace("{lvl}", Integer.toString(lvl)).replace("{refinement}", Integer.toString(refinement)).replace("{amount}", Integer.toString(amount)).replace("{target}", Integer.toString(targetPlayer.getUid())));
CommandHandler.sendMessage(sender, translate("commands.give.given_with_level_and_refinement", Integer.toString(item), Integer.toString(lvl), Integer.toString(refinement), Integer.toString(amount), Integer.toString(targetPlayer.getUid())));
} else {
CommandHandler.sendMessage(sender,Grasscutter.getLanguage().Give_given_level.replace("{item}", Integer.toString(item)).replace("{lvl}", Integer.toString(lvl)).replace("{amount}", Integer.toString(amount)));
CommandHandler.sendMessage(sender, translate("commands.give.given_level", Integer.toString(item), Integer.toString(lvl), Integer.toString(amount)));
}
}
......
......@@ -7,6 +7,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "godmode", usage = "godmode [on|off|toggle]",
description = "Prevents you from taking damage. Defaults to toggle.", permission = "player.godmode")
public final class GodModeCommand implements CommandHandler {
......@@ -14,7 +16,7 @@ public final class GodModeCommand 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,11 +32,11 @@ public final class GodModeCommand implements CommandHandler {
case "toggle":
break; // Already toggled
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Godmode_status);
break;
}
}
targetPlayer.setGodmode(enabled);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Godmode_status.replace("{status}", (enabled ? Grasscutter.getLanguage().Enabled : Grasscutter.getLanguage().Disabled)).replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.godmode.success", (enabled ? translate("commands.status.enabled") : translate("commands.status.disabled")), targetPlayer.getNickname()));
}
}
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;
......@@ -10,13 +9,15 @@ import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "heal", usage = "heal|h", aliases = {"h"},
description = "Heal all characters in your current team.", permission = "player.heal")
public final class HealCommand 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;
}
......@@ -31,6 +32,6 @@ public final class HealCommand implements CommandHandler {
entity.getWorld().broadcastPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar()));
}
});
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Heal_message);
CommandHandler.sendMessage(sender, translate("commands.heal.success"));
}
}
......@@ -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())));
}
}
......@@ -19,7 +19,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;
}
......
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