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

Add multilingual support

Add multilingual support
parent 86e6eef4
...@@ -21,6 +21,7 @@ public final class Config { ...@@ -21,6 +21,7 @@ public final class Config {
public ServerRunMode RunMode = ServerRunMode.HYBRID; // HYBRID, DISPATCH_ONLY, GAME_ONLY public ServerRunMode RunMode = ServerRunMode.HYBRID; // HYBRID, DISPATCH_ONLY, GAME_ONLY
public GameServerOptions GameServer = new GameServerOptions(); public GameServerOptions GameServer = new GameServerOptions();
public DispatchServerOptions DispatchServer = new DispatchServerOptions(); public DispatchServerOptions DispatchServer = new DispatchServerOptions();
public String Language = "en_us";
public GameServerOptions getGameServerOptions() { public GameServerOptions getGameServerOptions() {
return GameServer; return GameServer;
......
...@@ -30,6 +30,7 @@ import emu.grasscutter.utils.Crypto; ...@@ -30,6 +30,7 @@ import emu.grasscutter.utils.Crypto;
public final class Grasscutter { public final class Grasscutter {
private static final Logger log = (Logger) LoggerFactory.getLogger(Grasscutter.class); private static final Logger log = (Logger) LoggerFactory.getLogger(Grasscutter.class);
private static Config config; private static Config config;
private static Language language;
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static final File configFile = new File("./config.json"); private static final File configFile = new File("./config.json");
...@@ -49,6 +50,9 @@ public final class Grasscutter { ...@@ -49,6 +50,9 @@ public final class Grasscutter {
// Load server configuration. // Load server configuration.
Grasscutter.loadConfig(); Grasscutter.loadConfig();
// Load Language
Grasscutter.loadLanguage();
// Check server structure. // Check server structure.
Utils.startupCheck(); Utils.startupCheck();
} }
...@@ -68,7 +72,7 @@ public final class Grasscutter { ...@@ -68,7 +72,7 @@ public final class Grasscutter {
} }
// Initialize server. // Initialize server.
Grasscutter.getLogger().info("Starting Grasscutter..."); Grasscutter.getLogger().info(language.Starting_Grasscutter);
// Load all resources. // Load all resources.
Grasscutter.updateDayOfWeek(); Grasscutter.updateDayOfWeek();
...@@ -96,9 +100,9 @@ public final class Grasscutter { ...@@ -96,9 +100,9 @@ public final class Grasscutter {
} else if (getConfig().RunMode == ServerRunMode.GAME_ONLY) { } else if (getConfig().RunMode == ServerRunMode.GAME_ONLY) {
gameServer.start(); gameServer.start();
} else { } else {
getLogger().error("Invalid server run mode. " + getConfig().RunMode); getLogger().error(language.Invalid_server_run_mode + " " + getConfig().RunMode);
getLogger().error("Server run mode must be 'HYBRID', 'DISPATCH_ONLY', or 'GAME_ONLY'. Unable to start Grasscutter..."); getLogger().error(language.Server_run_mode);
getLogger().error("Shutting down..."); getLogger().error(language.Shutting_down);
System.exit(1); System.exit(1);
} }
...@@ -129,6 +133,31 @@ public final class Grasscutter { ...@@ -129,6 +133,31 @@ public final class Grasscutter {
} }
} }
public static void loadLanguage() {
try (FileReader file = new FileReader(String.format("./language/%s.json", Grasscutter.config.Language))) {
language = gson.fromJson(file, Language.class);
} catch (Exception e) {
Grasscutter.language = new Language();
Grasscutter.config.Language = "en_us";
saveConfig();
try {
File folder = new File("./language");
if (!folder.exists() && !folder.isDirectory()) {
//noinspection ResultOfMethodCallIgnored
folder.mkdirs();
}
} catch (Exception ee) {
Grasscutter.getLogger().error("Unable to create language folder.");
}
try (FileWriter file = new FileWriter("./language/en_us.json")) {
file.write(gson.toJson(language));
} catch (Exception ee) {
Grasscutter.getLogger().error("Unable to create language file.");
}
}
}
public static void saveConfig() { public static void saveConfig() {
try (FileWriter file = new FileWriter(configFile)) { try (FileWriter file = new FileWriter(configFile)) {
file.write(gson.toJson(config)); file.write(gson.toJson(config));
...@@ -139,22 +168,22 @@ public final class Grasscutter { ...@@ -139,22 +168,22 @@ public final class Grasscutter {
public static void startConsole() { public static void startConsole() {
String input; String input;
getLogger().info("Done! For help, type \"help\""); getLogger().info(language.Start_done);
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
while ((input = br.readLine()) != null) { while ((input = br.readLine()) != null) {
try { try {
if (getConfig().RunMode == ServerRunMode.DISPATCH_ONLY) { if (getConfig().RunMode == ServerRunMode.DISPATCH_ONLY) {
getLogger().error("Commands are not supported in dispatch only mode."); getLogger().error(language.Dispatch_mode_not_support_command);
return; return;
} }
CommandMap.getInstance().invoke(null, input); CommandMap.getInstance().invoke(null, input);
} catch (Exception e) { } catch (Exception e) {
Grasscutter.getLogger().error("Command error:", e); Grasscutter.getLogger().error(language.Command_error, e);
} }
} }
} catch (Exception e) { } catch (Exception e) {
Grasscutter.getLogger().error("An error occurred.", e); Grasscutter.getLogger().error(language.error, e);
} }
} }
...@@ -162,6 +191,10 @@ public final class Grasscutter { ...@@ -162,6 +191,10 @@ public final class Grasscutter {
return config; return config;
} }
public static Language getLanguage() {
return language;
}
public static Logger getLogger() { public static Logger getLogger() {
return log; return log;
} }
......
package emu.grasscutter;
public final class Language {
public String An_error_occurred_during_game_update = "An error occurred during game update.";
public String Starting_Grasscutter = "Starting Grasscutter...";
public String Invalid_server_run_mode = "Invalid server run mode.";
public String Server_run_mode = "Server run mode must be 'HYBRID', 'DISPATCH_ONLY', or 'GAME_ONLY'. Unable to start Grasscutter...";
public String Shutting_down = "Shutting down...";
public String Start_done = "Done! For help, type \"help\"";
public String Dispatch_mode_not_support_command = "Commands are not supported in dispatch only mode.";
public String Command_error = "Command error:";
public String error = "An error occurred.";
public String grasscutter_is_free = "Grasscutter is FREE software. If you have paid for this, you may have been scammed. Homepage: https://github.com/Grasscutters/Grasscutter";
public String Game_start_port = "Game Server started on port %s";
public String Client_connect = "Client connected from %s";
public String Client_disconnect = "Client disconnected from %s";
public String Client_request = "[Dispatch] Client %s %s request: %s";
public String Not_load_keystore = "[Dispatch] Unable to load keystore. Trying default keystore password...";
public String Use_default_keystore = "[Dispatch] The default keystore password was loaded successfully. Please consider setting the password to 123456 in config.json.";
public String Load_keystore_error = "[Dispatch] Error while loading keystore!";
public String Not_find_ssl_cert = "[Dispatch] No SSL cert found! Falling back to HTTP server.";
public String Welcome = "Welcome to Grasscutter";
public String Potential_unhandled_request = "[Dispatch] Potential unhandled %s request: %s";
public String Client_login_token = "[Dispatch] Client %s is trying to log in via token";
public String Client_token_login_failed = "[Dispatch] Client %s failed to log in via token";
public String Client_login_in_token = "[Dispatch] Client %s logged in via token as %s";
public String Game_account_cache_error = "Game account cache information error";
public String Wrong_session_key = "Wrong session key.";
public String Client_exchange_combo_token = "[Dispatch] Client %s succeed to exchange combo token";
public String Client_failed_exchange_combo_token = "[Dispatch] Client %s failed to exchange combo token";
public String Dispatch_start_server_port = "[Dispatch] Dispatch server started on port %s";
public String Client_failed_login_account_create = "[Dispatch] Client %s failed to log in: Account %s created";
public String Client_failed_login_account_create_failed = "[Dispatch] Client %s failed to log in: Account create failed";
public String Client_failed_login_account_no_found = "[Dispatch] Client %s failed to log in: Account no found";
public String Client_login = "[Dispatch] Client %s logged in as %s";
public String Username_not_found = "Username not found.";
public String Username_not_found_create_failed = "Username not found, create failed.";
// Command
public String No_command_specified = "No command specified.";
public String Unknown_command = "Unknown command: ";
public String You_not_permission_run_command = "You do not have permission to run this command.";
public String This_command_can_only_run_from_console = "This command can only be run from the console.";
public String Run_this_command_in_game = "Run this command in-game.";
public String Invalid_playerId = "Invalid playerId.";
public String Player_not_found = "Player not found.";
public String Player_is_offline = "Player is offline.";
public String Invalid_item_id = "Invalid item id.";
public String Invalid_item_or_player_id = "Invalid item or player ID.";
public String Enabled = "enabled";
public String Disabled = "disabled";
public String No_command_found = "No command found.";
public String Help = "Help";
public String Player_not_found_or_offline = "Player not found or offline.";
public String Invalid_arguments = "Invalid arguments.";
public String Success = "Success";
public String Invalid_entity_id = "Invalid entity id.";
// Help
public String Help_usage = " Usage: ";
public String Help_aliases = " Aliases: ";
public String Help_available_command = "Available commands:";
// Account
public String Modify_user_account = "Modify user accounts";
public String Invalid_UID = "Invalid UID.";
public String Account_exists = "Account already exists.";
public String Account_create_UID = "Account created with UID %s.";
public String Account_delete = "Account deleted.";
public String Account_not_find = "Account not found.";
public String Account_command_usage = "Usage: account <create|delete> <username> [uid]";
// Broadcast
public String Broadcast_command_usage = "Usage: broadcast <message>";
public String Broadcast_message_sent = "Message sent.";
// ChangeScene
public String Change_screen_usage = "Usage: changescene <scene id>";
public String Change_screen_you_in_that_screen = "You are already in that scene";
public String Change_screen = "Changed to scene ";
public String Change_screen_not_exist = "Scene does not exist";
// Clear
public String Clear_weapons = "Cleared weapons for %s .";
public String Clear_artifacts = "Cleared artifacts for %s .";
public String Clear_materials = "Cleared materials for %s .";
public String Clear_furniture = "Cleared furniture for %s .";
public String Clear_displays = "Cleared displays for %s .";
public String Clear_virtuals = "Cleared virtuals for %s .";
public String Clear_everything = "Cleared everything for %s .";
// Coop
public String Coop_usage = "Usage: coop <playerId> <target playerId>";
// Drop
public String Drop_usage = "Usage: drop <itemId|itemName> [amount]";
public String Drop_dropped_of = "Dropped %s of %s.";
// EnterDungeon
public String EnterDungeon_usage = "Usage: enterdungeon <dungeon id>";
public String EnterDungeon_changed_to_dungeon = "Changed to dungeon ";
public String EnterDungeon_dungeon_not_found = "Dungeon does not exist";
public String EnterDungeon_you_in_that_dungeon = "You are already in that dungeon";
// GiveAll
public String GiveAll_usage = "Usage: giveall [player] [amount]";
public String GiveAll_item = "Giving all items...";
public String GiveAll_done = "Giving all items done";
public String GiveAll_invalid_amount_or_playerId = "Invalid amount or player ID.";
// GiveArtifact
public String GiveArtifact_usage = "Usage: giveart|gart [player] <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]";
public String GiveArtifact_invalid_artifact_id = "Invalid artifact ID.";
public String GiveArtifact_given = "Given %s to %s.";
// GiveChar
public String GiveChar_usage = "Usage: givechar <player> <itemId|itemName> [amount]";
public String GiveChar_given = "Given %s with level %s to %s.";
public String GiveChar_invalid_avatar_id = "Invalid avatar id.";
public String GiveChar_invalid_avatar_level = "Invalid avatar level.";
public String GiveChar_invalid_avatar_or_player_id = "Invalid avatar or player ID.";
// Give
public String Give_usage = "Usage: give <player> <itemId|itemName> [amount] [level]";
public String Give_refinement_only_applicable_weapons = "Refinement is only applicable to weapons.";
public String Give_refinement_must_between_1_and_5 = "Refinement must be between 1 and 5.";
public String Give_given = "Given %s of %s to %s.";
public String Give_given_with_level_and_refinement = "Given %s with level %s, refinement %s %s times to %s";
public String Give_given_level = "Given %s with level %s %s times to %s";
// GodMode
public String Godmode_status = "Godmode is now %s for %s .";
// Heal
public String Heal_message = "All characters have been healed.";
// Kick
public String Kick_player_kick_player = "Player [%s:%s] has kicked player [%s:%s]";
public String Kick_server_player = "Kicking player [%s:%s]";
// Kill
public String Kill_usage = "Usage: killall [playerUid] [sceneId]";
public String Kill_scene_not_found_in_player_world = "Scene not found in player world";
public String Kill_kill_monsters_in_scene = "Killing %s monsters in scene %s";
// KillCharacter
public String KillCharacter_usage = "Usage: /killcharacter [playerId]";
public String KillCharacter_kill_current_character = "Killed %s current character.";
// List
public String List_message = "There are %s player(s) online:";
// Permission
public String Permission_usage = "Usage: permission <add|remove> <username> <permission>";
public String Permission_add = "Permission added.";
public String Permission_have_permission = "They already have this permission!";
public String Permission_remove = "Permission removed.";
public String Permission_not_have_permission = "They don't have this permission!";
// Position
public String Position_message = "Coord: %.3f, %.3f, %.3f\nScene id: %d";
// Reload
public String Reload_reload_start = "Reloading config.";
public String Reload_reload_done = "Reload complete.";
// ResetConst
public String ResetConst_reset_all = "Reset all avatars' constellations.";
public String ResetConst_reset_all_done = "Constellations for %s have been reset. Please relog to see changes.";
// ResetShopLimit
public String ResetShopLimit_usage = "Usage: /resetshop <player id>";
// SendMail
public String SendMail_usage = "Usage: give [player] <itemId|itemName> [amount]";
public String SendMail_user_not_exist = "The user with an id of '%s' does not exist";
public String SendMail_start_composition = "Starting composition of message.\nPlease use `/sendmail <title>` to continue.\nYou can use `/sendmail stop` at any time";
public String SendMail_templates = "Mail templates coming soon implemented...";
public String SendMail_invalid_arguments = "Invalid arguments.\nUsage `/sendmail <userId|all|help> [templateId]`";
public String SendMail_send_cancel = "Message sending cancelled";
public String SendMail_send_done = "Message sent to user %s!";
public String SendMail_send_all_done = "Message sent to all users!";
public String SendMail_not_composition_end = "Message composition not at final stage.\nPlease use `/sendmail %s` or `/sendmail stop` to cancel";
public String SendMail_Please_use = "Please use `/sendmail %s`";
public String SendMail_set_title = "Message title set as '%s'.\nUse '/sendmail <content>' to continue.";
public String SendMail_set_contents = "Message contents set as '%s'.\nUse '/sendmail <sender>' to continue.";
public String SendMail_set_message_sender = "Message sender set as '%s'.\nUse '/sendmail <itemId|itemName|finish> [amount] [level]' to continue.";
public String SendMail_send = "Attached %s of %s (level %s) to the message.\nContinue adding more items or use `/sendmail finish` to send the message.";
public String SendMail_invalid_arguments_please_use = "Invalid arguments \n Please use `/sendmail %s`";
public String SendMail_title = "<title>";
public String SendMail_message = "<message>";
public String SendMail_sender = "<sender>";
public String SendMail_arguments = "<itemId|itemName|finish> [amount] [level]";
public String SendMail_error = "ERROR: invalid construction stage %s. Check console for stacktrace.";
// SendMessage
public String SendMessage_usage = "Usage: sendmessage <player> <message>";
public String SenaMessage_message_sent = "Message sent.";
// SetFetterLevel
public String SetFetterLevel_usage = "Usage: setfetterlevel <level>";
public String SetFetterLevel_fetter_level_must_between_0_and_10 = "Fetter level must be between 0 and 10.";
public String SetFetterLevel_fetter_set_level = "Fetter level set to %s";
public String SetFetterLevel_invalid_fetter_level = "Invalid fetter level.";
// SetStats
public String SetStats_usage = "Usage: setstats|stats <stat> <value>";
public String SetStats_setstats_help_message = "Usage: /setstats|stats <hp | mhp | def | atk | em | er | crate | cdmg> <value> for basic stats";
public String SetStats_stats_help_message = "Usage: /stats <epyro | ecryo | ehydro | egeo | edend | eelec | ephys> <amount> for elemental bonus";
public String SetStats_set_max_hp = "MAX HP set to %s.";
public String SetStats_set_max_hp_error = "Invalid Max HP value.";
public String SetStats_set_hp = "HP set to %s.";
public String SetStats_set_hp_error = "Invalid HP value.";
public String SetStats_set_def = "DEF set to %s.";
public String SetStats_set_def_error = "Invalid DEF value.";
public String SetStats_set_atk = "ATK set to %s.";
public String SetStats_set_atk_error = "Invalid ATK value.";
public String SetStats_set_em = "Elemental Mastery set to %s.";
public String SetStats_set_em_error = "Invalid EM value.";
public String SetStats_set_er = "Energy recharge set to %s%.";
public String SetStats_set_er_error = "Invalid ER value.";
public String SetStats_set_cr = "Crit Rate set to %s%.";
public String SetStats_set_cr_error = "Invalid Crit Rate value.";
public String SetStats_set_cd = "Crit DMG set to %s%.";
public String SetStats_set_cd_error = "Invalid Crit DMG value.";
public String SetStats_set_pdb = "Pyro DMG Bonus set to %s%.";
public String SetStats_set_pdb_error = "Invalid Pyro DMG Bonus value.";
public String SetStats_set_cdb = "Cyro DMG Bonus set to %s%.";
public String SetStats_set_cdb_error = "Invalid Cyro DMG Bonus value.";
public String SetStats_set_hdb = "Hydro DMG Bonus set to %s%.";
public String SetStats_set_hdb_error = "Invalid Hydro DMG Bonus value.";
public String SetStats_set_adb = "Anemo DMG Bonus set to %s%.";
public String SetStats_set_adb_error = "Invalid Anemo DMG Bonus value.";
public String SetStats_set_gdb = "Geo DMG Bonus set to %s%.";
public String SetStats_set_gdb_error = "Invalid Geo DMG Bonus value.";
public String SetStats_set_edb = "Electro DMG Bonus set to %s%.";
public String SetStats_set_edb_error = "Invalid Electro DMG Bonus value.";
public String SetStats_set_physdb = "Physical DMG Bonus set to %s%.";
public String SetStats_set_physdb_error = "Invalid Physical DMG Bonus value.";
public String SetStats_set_ddb = "Dendro DMG Bonus set to %s%.";
public String SetStats_set_ddb_error = "Invalid Dendro DMG Bonus value.";
// SetWorldLevel
public String SetWorldLevel_usage = "Usage: setworldlevel <level>";
public String SetWorldLevel_world_level_must_between_0_and_8 = "World level must be between 0-8";
public String SetWorldLevel_set_world_level = "World level set to %s.";
public String SetWorldLevel_invalid_world_level = "Invalid world level.";
// Spawn
public String Spawn_usage = "Usage: spawn <entityId> [amount] [level(monster only)]";
public String Spawn_message = "Spawned %s of %s.";
// Stop
public String Stop_message = "Server shutting down...";
// Talent
public String Talent_usage_1 = "To set talent level: /talent set <talentID> <value>";
public String Talent_usage_2 = "Another way to set talent level: /talent <n or e or q> <value>";
public String Talent_usage_3 = "To get talent ID: /talent getid";
public String Talent_lower_16 = "Invalid talent level. Level should be lower than 16";
public String Talent_set_atk = "Set talent Normal ATK to %s.";
public String Talent_set_e = "Set talent E to %s.";
public String Talent_set_q = "Set talent Q to %s.";
public String Talent_invalid_skill_id = "Invalid skill ID.";
public String Talent_set_this = "Set this talent to %s.";
public String Talent_invalid_talent_level = "Invalid talent level.";
public String Talent_normal_attack_id = "Normal Attack ID %s.";
public String Talent_e_skill_id = "E skill ID %s.";
public String Talent_q_skill_id = "Q skill ID %s.";
// TeleportAll
public String TeleportAll_message = "You only can use this command in MP mode.";
// Teleport
public String Teleport_usage_server = "Usage: /tp @<player id> <x> <y> <z> [scene id]";
public String Teleport_usage = "Usage: /tp [@<player id>] <x> <y> <z> [scene id]";
public String Teleport_specify_player_id = "You must specify a player id.";
public String Teleport_invalid_position = "Invalid position.";
public String Teleport_message = "Teleported %s to %s,%s,%s in scene %s";
// Weather
public String Weather_usage = "Usage: weather <weatherId> [climateId]";
public String Weather_message = "Changed weather to %s with climate %s";
public String Weather_invalid_id = "Invalid ID.";
}
...@@ -107,7 +107,7 @@ public final class CommandMap { ...@@ -107,7 +107,7 @@ public final class CommandMap {
public void invoke(Player player, String rawMessage) { public void invoke(Player player, String rawMessage) {
rawMessage = rawMessage.trim(); rawMessage = rawMessage.trim();
if (rawMessage.length() == 0) { if (rawMessage.length() == 0) {
CommandHandler.sendMessage(player, "No command specified."); CommandHandler.sendMessage(player, Grasscutter.getLanguage().No_command_specified);
return; return;
} }
...@@ -122,7 +122,7 @@ public final class CommandMap { ...@@ -122,7 +122,7 @@ public final class CommandMap {
// Get command handler. // Get command handler.
CommandHandler handler = this.commands.get(label); CommandHandler handler = this.commands.get(label);
if (handler == null) { if (handler == null) {
CommandHandler.sendMessage(player, "Unknown command: " + label); CommandHandler.sendMessage(player, Grasscutter.getLanguage().Unknown_command + label);
return; return;
} }
...@@ -131,7 +131,7 @@ public final class CommandMap { ...@@ -131,7 +131,7 @@ public final class CommandMap {
String permissionNode = this.annotations.get(label).permission(); String permissionNode = this.annotations.get(label).permission();
Account account = player.getAccount(); Account account = player.getAccount();
if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) { if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) {
CommandHandler.sendMessage(player, "You do not have permission to run this command."); CommandHandler.sendMessage(player, Grasscutter.getLanguage().You_not_permission_run_command);
return; return;
} }
} }
......
...@@ -14,12 +14,12 @@ public final class AccountCommand implements CommandHandler { ...@@ -14,12 +14,12 @@ public final class AccountCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (sender != null) { if (sender != null) {
CommandHandler.sendMessage(sender, "This command can only be run from the console."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().This_command_can_only_run_from_console);
return; return;
} }
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: account <create|delete> <username> [uid]"); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_command_usage);
return; return;
} }
...@@ -28,7 +28,7 @@ public final class AccountCommand implements CommandHandler { ...@@ -28,7 +28,7 @@ public final class AccountCommand implements CommandHandler {
switch (action) { switch (action) {
default: default:
CommandHandler.sendMessage(null, "Usage: account <create|delete> <username> [uid]"); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_command_usage);
return; return;
case "create": case "create":
int uid = 0; int uid = 0;
...@@ -36,27 +36,27 @@ public final class AccountCommand implements CommandHandler { ...@@ -36,27 +36,27 @@ public final class AccountCommand implements CommandHandler {
try { try {
uid = Integer.parseInt(args.get(2)); uid = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid UID."); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Invalid_UID);
return; return;
} }
} }
emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid); emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid);
if (account == null) { if (account == null) {
CommandHandler.sendMessage(null, "Account already exists."); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_exists);
return; return;
} else { } else {
account.addPermission("*"); account.addPermission("*");
account.save(); // Save account to database. account.save(); // Save account to database.
CommandHandler.sendMessage(null, "Account created with UID " + account.getPlayerUid() + "."); CommandHandler.sendMessage(null, String.format(Grasscutter.getLanguage().Account_create_UID, account.getPlayerUid()));
} }
return; return;
case "delete": case "delete":
if (DatabaseHelper.deleteAccount(username)) { if (DatabaseHelper.deleteAccount(username)) {
CommandHandler.sendMessage(null, "Account deleted."); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_delete);
} else { } else {
CommandHandler.sendMessage(null, "Account not found."); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_not_find);
} }
} }
} }
......
...@@ -14,7 +14,7 @@ public final class BroadcastCommand implements CommandHandler { ...@@ -14,7 +14,7 @@ public final class BroadcastCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: broadcast <message>"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_command_usage);
return; return;
} }
...@@ -24,6 +24,6 @@ public final class BroadcastCommand implements CommandHandler { ...@@ -24,6 +24,6 @@ public final class BroadcastCommand implements CommandHandler {
CommandHandler.sendMessage(p, message); CommandHandler.sendMessage(p, message);
} }
CommandHandler.sendMessage(sender, "Message sent."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_message_sent);
} }
} }
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.gacha.GachaRecord;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
...@@ -12,12 +14,12 @@ public final class ChangeSceneCommand implements CommandHandler { ...@@ -12,12 +14,12 @@ public final class ChangeSceneCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game."); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
} }
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: changescene <scene id>"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_usage);
return; return;
} }
...@@ -25,18 +27,18 @@ public final class ChangeSceneCommand implements CommandHandler { ...@@ -25,18 +27,18 @@ public final class ChangeSceneCommand implements CommandHandler {
int sceneId = Integer.parseInt(args.get(0)); int sceneId = Integer.parseInt(args.get(0));
if (sceneId == sender.getSceneId()) { if (sceneId == sender.getSceneId()) {
CommandHandler.sendMessage(sender, "You are already in that scene"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_you_in_that_screen);
return; return;
} }
boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, sender.getPos()); boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, sender.getPos());
CommandHandler.sendMessage(sender, "Changed to scene " + sceneId); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen + sceneId);
if (!result) { if (!result) {
CommandHandler.sendMessage(sender, "Scene does not exist"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_not_exist);
} }
} catch (Exception e) { } catch (Exception e) {
CommandHandler.sendMessage(sender, "Usage: changescene <scene id>"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_usage);
} }
} }
} }
...@@ -20,7 +20,7 @@ public final class ClearCommand implements CommandHandler { ...@@ -20,7 +20,7 @@ public final class ClearCommand implements CommandHandler {
int target; int target;
String cmdSwitch = ""; String cmdSwitch = "";
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game."); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
} }
Inventory playerInventory = sender.getInventory(); Inventory playerInventory = sender.getInventory();
...@@ -39,7 +39,7 @@ public final class ClearCommand implements CommandHandler { ...@@ -39,7 +39,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getItemType() == ItemType.ITEM_WEAPON) .filter(item -> item.getItemType() == ItemType.ITEM_WEAPON)
.filter(item -> !item.isLocked() && !item.isEquipped()) .filter(item -> !item.isLocked() && !item.isEquipped())
.forEach(item -> playerInventory.removeItem(item, item.getCount())); .forEach(item -> playerInventory.removeItem(item, item.getCount()));
sender.dropMessage("Cleared weapons for " + targetPlayer.getNickname() + " ."); sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_weapons, targetPlayer.getNickname()));
} }
case "art" -> { case "art" -> {
playerInventory.getItems().values().stream() playerInventory.getItems().values().stream()
...@@ -47,7 +47,7 @@ public final class ClearCommand implements CommandHandler { ...@@ -47,7 +47,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getLevel() == 1 && item.getExp() == 0) .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped()) .filter(item -> !item.isLocked() && !item.isEquipped())
.forEach(item -> playerInventory.removeItem(item, item.getCount())); .forEach(item -> playerInventory.removeItem(item, item.getCount()));
sender.dropMessage("Cleared artifacts for " + targetPlayer.getNickname() + " ."); sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_artifacts, targetPlayer.getNickname()));
} }
case "mat" -> { case "mat" -> {
playerInventory.getItems().values().stream() playerInventory.getItems().values().stream()
...@@ -55,7 +55,7 @@ public final class ClearCommand implements CommandHandler { ...@@ -55,7 +55,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getLevel() == 1 && item.getExp() == 0) .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped()) .filter(item -> !item.isLocked() && !item.isEquipped())
.forEach(item -> playerInventory.removeItem(item, item.getCount())); .forEach(item -> playerInventory.removeItem(item, item.getCount()));
sender.dropMessage("Cleared artifacts for " + targetPlayer.getNickname() + " ."); sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_artifacts, targetPlayer.getNickname()));
} }
case "all" -> { case "all" -> {
playerInventory.getItems().values().stream() playerInventory.getItems().values().stream()
...@@ -63,45 +63,45 @@ public final class ClearCommand implements CommandHandler { ...@@ -63,45 +63,45 @@ public final class ClearCommand implements CommandHandler {
.filter(item1 -> item1.getLevel() == 1 && item1.getExp() == 0) .filter(item1 -> item1.getLevel() == 1 && item1.getExp() == 0)
.filter(item1 -> !item1.isLocked() && !item1.isEquipped()) .filter(item1 -> !item1.isLocked() && !item1.isEquipped())
.forEach(item1 -> playerInventory.removeItem(item1, item1.getCount())); .forEach(item1 -> playerInventory.removeItem(item1, item1.getCount()));
sender.dropMessage("Cleared artifacts for " + targetPlayer.getNickname() + " ."); sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_artifacts, targetPlayer.getNickname()));
playerInventory.getItems().values().stream() playerInventory.getItems().values().stream()
.filter(item2 -> item2.getItemType() == ItemType.ITEM_MATERIAL) .filter(item2 -> item2.getItemType() == ItemType.ITEM_MATERIAL)
.filter(item2 -> !item2.isLocked() && !item2.isEquipped()) .filter(item2 -> !item2.isLocked() && !item2.isEquipped())
.forEach(item2 -> playerInventory.removeItem(item2, item2.getCount())); .forEach(item2 -> playerInventory.removeItem(item2, item2.getCount()));
sender.dropMessage("Cleared materials for " + targetPlayer.getNickname() + " ."); sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_materials, targetPlayer.getNickname()));
playerInventory.getItems().values().stream() playerInventory.getItems().values().stream()
.filter(item3 -> item3.getItemType() == ItemType.ITEM_WEAPON) .filter(item3 -> item3.getItemType() == ItemType.ITEM_WEAPON)
.filter(item3 -> item3.getLevel() == 1 && item3.getExp() == 0) .filter(item3 -> item3.getLevel() == 1 && item3.getExp() == 0)
.filter(item3 -> !item3.isLocked() && !item3.isEquipped()) .filter(item3 -> !item3.isLocked() && !item3.isEquipped())
.forEach(item3 -> playerInventory.removeItem(item3, item3.getCount())); .forEach(item3 -> playerInventory.removeItem(item3, item3.getCount()));
sender.dropMessage("Cleared weapons for " + targetPlayer.getNickname() + " ."); sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_artifacts, targetPlayer.getNickname()));
playerInventory.getItems().values().stream() playerInventory.getItems().values().stream()
.filter(item4 -> item4.getItemType() == ItemType.ITEM_FURNITURE) .filter(item4 -> item4.getItemType() == ItemType.ITEM_FURNITURE)
.filter(item4 -> !item4.isLocked() && !item4.isEquipped()) .filter(item4 -> !item4.isLocked() && !item4.isEquipped())
.forEach(item4 -> playerInventory.removeItem(item4, item4.getCount())); .forEach(item4 -> playerInventory.removeItem(item4, item4.getCount()));
sender.dropMessage("Cleared furniture for " + targetPlayer.getNickname() + " ."); sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_furniture, targetPlayer.getNickname()));
playerInventory.getItems().values().stream() playerInventory.getItems().values().stream()
.filter(item5 -> item5.getItemType() == ItemType.ITEM_DISPLAY) .filter(item5 -> item5.getItemType() == ItemType.ITEM_DISPLAY)
.filter(item5 -> !item5.isLocked() && !item5.isEquipped()) .filter(item5 -> !item5.isLocked() && !item5.isEquipped())
.forEach(item5 -> playerInventory.removeItem(item5, item5.getCount())); .forEach(item5 -> playerInventory.removeItem(item5, item5.getCount()));
sender.dropMessage("Cleared displays for " + targetPlayer.getNickname() + " ."); sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_displays, targetPlayer.getNickname()));
playerInventory.getItems().values().stream() playerInventory.getItems().values().stream()
.filter(item6 -> item6.getItemType() == ItemType.ITEM_VIRTUAL) .filter(item6 -> item6.getItemType() == ItemType.ITEM_VIRTUAL)
.filter(item6 -> !item6.isLocked() && !item6.isEquipped()) .filter(item6 -> !item6.isLocked() && !item6.isEquipped())
.forEach(item6 -> playerInventory.removeItem(item6, item6.getCount())); .forEach(item6 -> playerInventory.removeItem(item6, item6.getCount()));
sender.dropMessage("Cleared virtuals for " + targetPlayer.getNickname() + " ."); sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_virtuals, targetPlayer.getNickname()));
sender.dropMessage("Cleared everything for " + targetPlayer.getNickname() + " ."); sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_everything, targetPlayer.getNickname()));
} }
} }
} 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, "Invalid playerId."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return; return;
} }
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return; return;
} }
} }
......
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;
...@@ -12,7 +13,7 @@ public final class CoopCommand implements CommandHandler { ...@@ -12,7 +13,7 @@ public final class CoopCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(sender, "Usage: coop <playerId> <target playerId>"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Coop_usage);
return; return;
} }
...@@ -22,7 +23,7 @@ public final class CoopCommand implements CommandHandler { ...@@ -22,7 +23,7 @@ public final class CoopCommand implements CommandHandler {
Player host = sender.getServer().getPlayerByUid(hostId); Player host = sender.getServer().getPlayerByUid(hostId);
Player want = sender.getServer().getPlayerByUid(tid); Player want = sender.getServer().getPlayerByUid(tid);
if (host == null || want == null) { if (host == null || want == null) {
CommandHandler.sendMessage(sender, "Player is offline."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_is_offline);
return; return;
} }
if (want.isInMultiplayer()) { if (want.isInMultiplayer()) {
...@@ -31,7 +32,7 @@ public final class CoopCommand implements CommandHandler { ...@@ -31,7 +32,7 @@ public final class CoopCommand implements CommandHandler {
sender.getServer().getMultiplayerManager().applyEnterMp(want, hostId); sender.getServer().getMultiplayerManager().applyEnterMp(want, hostId);
sender.getServer().getMultiplayerManager().applyEnterMpReply(host, tid, true); sender.getServer().getMultiplayerManager().applyEnterMpReply(host, tid, true);
} catch (Exception e) { } catch (Exception e) {
CommandHandler.sendMessage(sender, "Player id is not valid."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
} }
} }
} }
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData; import emu.grasscutter.data.GameData;
...@@ -17,12 +18,12 @@ public final class DropCommand implements CommandHandler { ...@@ -17,12 +18,12 @@ public final class DropCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game."); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
} }
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: drop <itemId|itemName> [amount]"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Drop_usage);
return; return;
} }
...@@ -33,7 +34,7 @@ public final class DropCommand implements CommandHandler { ...@@ -33,7 +34,7 @@ public final class DropCommand implements CommandHandler {
ItemData itemData = GameData.getItemDataMap().get(item); ItemData itemData = GameData.getItemDataMap().get(item);
if (itemData == null) { if (itemData == null) {
CommandHandler.sendMessage(sender, "Invalid item id."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
return; return;
} }
...@@ -48,9 +49,9 @@ public final class DropCommand implements CommandHandler { ...@@ -48,9 +49,9 @@ public final class DropCommand implements CommandHandler {
EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, sender.getPos().clone().addY(3f), amount); EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, sender.getPos().clone().addY(3f), amount);
sender.getScene().addEntity(entity); sender.getScene().addEntity(entity);
} }
CommandHandler.sendMessage(sender, String.format("Dropped %s of %s.", amount, item)); CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Drop_dropped_of, amount, item));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid item or player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_or_player_id);
} }
} }
} }
\ No newline at end of file
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;
...@@ -12,12 +13,12 @@ public final class EnterDungeonCommand implements CommandHandler { ...@@ -12,12 +13,12 @@ public final class EnterDungeonCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game."); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
} }
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: enterdungeon <dungeon id>"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_usage);
return; return;
} }
...@@ -25,18 +26,18 @@ public final class EnterDungeonCommand implements CommandHandler { ...@@ -25,18 +26,18 @@ public final class EnterDungeonCommand implements CommandHandler {
int dungeonId = Integer.parseInt(args.get(0)); int dungeonId = Integer.parseInt(args.get(0));
if (dungeonId == sender.getSceneId()) { if (dungeonId == sender.getSceneId()) {
CommandHandler.sendMessage(sender, "You are already in that dungeon"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_you_in_that_dungeon);
return; return;
} }
boolean result = sender.getServer().getDungeonManager().enterDungeon(sender.getSession().getPlayer(), 0, dungeonId); boolean result = sender.getServer().getDungeonManager().enterDungeon(sender.getSession().getPlayer(), 0, dungeonId);
CommandHandler.sendMessage(sender, "Changed to dungeon " + dungeonId); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_changed_to_dungeon + dungeonId);
if (!result) { if (!result) {
CommandHandler.sendMessage(sender, "Dungeon does not exist"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_dungeon_not_found);
} }
} catch (Exception e) { } catch (Exception e) {
CommandHandler.sendMessage(sender, "Usage: enterdungeon <dungeon id>"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_usage);
} }
} }
} }
...@@ -24,7 +24,7 @@ public final class GiveAllCommand implements CommandHandler { ...@@ -24,7 +24,7 @@ public final class GiveAllCommand implements CommandHandler {
switch (args.size()) { switch (args.size()) {
case 0: // *no args* case 0: // *no args*
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, "This usage can only be run in-game"); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
} }
target = sender.getUid(); target = sender.getUid();
...@@ -34,11 +34,11 @@ public final class GiveAllCommand implements CommandHandler { ...@@ -34,11 +34,11 @@ public final class GiveAllCommand implements CommandHandler {
try { try {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(sender, "Invalid player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return; return;
} }
}catch (NumberFormatException ignored){ }catch (NumberFormatException ignored){
CommandHandler.sendMessage(sender, "Invalid player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return; return;
} }
break; break;
...@@ -53,28 +53,28 @@ public final class GiveAllCommand implements CommandHandler { ...@@ -53,28 +53,28 @@ public final class GiveAllCommand implements CommandHandler {
amount = Integer.parseInt(args.get(1)); amount = Integer.parseInt(args.get(1));
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid amount or player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveAll_invalid_amount_or_playerId);
return; return;
} }
break; break;
default: // invalid default: // invalid
CommandHandler.sendMessage(null, "Usage: giveall [player] [amount]"); CommandHandler.sendMessage(null, Grasscutter.getLanguage().GiveAll_usage);
return; return;
} }
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return; return;
} }
this.giveAllItems(targetPlayer, amount); this.giveAllItems(targetPlayer, amount);
CommandHandler.sendMessage(sender, "Giving all items done"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveAll_done);
} }
public void giveAllItems(Player player, int amount) { public void giveAllItems(Player player, int amount) {
CommandHandler.sendMessage(player, "Giving all items..."); CommandHandler.sendMessage(player, Grasscutter.getLanguage().GiveAll_item);
for (AvatarData avatarData: GameData.getAvatarDataMap().values()) { for (AvatarData avatarData: GameData.getAvatarDataMap().values()) {
//Exclude test avatar //Exclude test avatar
......
...@@ -20,7 +20,7 @@ public final class GiveArtifactCommand implements CommandHandler { ...@@ -20,7 +20,7 @@ public final class GiveArtifactCommand implements CommandHandler {
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
int size = args.size(), target, itemId, mainPropId, level = 1; int size = args.size(), target, itemId, mainPropId, level = 1;
ArrayList<Integer> appendPropIdList = new ArrayList<>(); ArrayList<Integer> appendPropIdList = new ArrayList<>();
String msg = "Usage: giveart|gart [player] <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]"; String msg = Grasscutter.getLanguage().GiveArtifact_usage;
if (sender == null && size < 2) { if (sender == null && size < 2) {
CommandHandler.sendMessage(null, msg); CommandHandler.sendMessage(null, msg);
...@@ -70,14 +70,14 @@ public final class GiveArtifactCommand implements CommandHandler { ...@@ -70,14 +70,14 @@ public final class GiveArtifactCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return; return;
} }
ItemData itemData = GameData.getItemDataMap().get(itemId); ItemData itemData = GameData.getItemDataMap().get(itemId);
if (itemData.getItemType() != ItemType.ITEM_RELIQUARY) { if (itemData.getItemType() != ItemType.ITEM_RELIQUARY) {
CommandHandler.sendMessage(sender, "Invalid artifact ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveArtifact_invalid_artifact_id);
return; return;
} }
...@@ -88,7 +88,7 @@ public final class GiveArtifactCommand implements CommandHandler { ...@@ -88,7 +88,7 @@ public final class GiveArtifactCommand implements CommandHandler {
item.getAppendPropIdList().addAll(appendPropIdList); item.getAppendPropIdList().addAll(appendPropIdList);
targetPlayer.getInventory().addItem(item, ActionReason.SubfieldDrop); targetPlayer.getInventory().addItem(item, ActionReason.SubfieldDrop);
CommandHandler.sendMessage(sender, String.format("Given %s to %s.", itemId, target)); CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().GiveArtifact_given, itemId, target));
} }
} }
...@@ -19,13 +19,13 @@ public final class GiveCharCommand implements CommandHandler { ...@@ -19,13 +19,13 @@ public final class GiveCharCommand implements CommandHandler {
int target, avatarId, level = 1, ascension; int target, avatarId, level = 1, ascension;
if (sender == null && args.size() < 2) { if (sender == null && args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: givechar <player> <itemId|itemName> [amount]"); CommandHandler.sendMessage(null, Grasscutter.getLanguage().GiveChar_usage);
return; return;
} }
switch (args.size()) { switch (args.size()) {
default: default:
CommandHandler.sendMessage(sender, "Usage: givechar <player> <avatarId> [level]"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_usage);
return; return;
case 2: case 2:
try { try {
...@@ -39,7 +39,7 @@ public final class GiveCharCommand implements CommandHandler { ...@@ -39,7 +39,7 @@ public final class GiveCharCommand implements CommandHandler {
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook. // TODO: Parse from avatar name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid avatar or player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_invalid_avatar_or_player_id);
return; return;
} }
break; break;
...@@ -47,7 +47,7 @@ public final class GiveCharCommand implements CommandHandler { ...@@ -47,7 +47,7 @@ public final class GiveCharCommand implements CommandHandler {
try { try {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(sender, "Invalid player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return; return;
} }
...@@ -55,7 +55,7 @@ public final class GiveCharCommand implements CommandHandler { ...@@ -55,7 +55,7 @@ public final class GiveCharCommand implements CommandHandler {
level = Integer.parseInt(args.get(2)); level = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook. // TODO: Parse from avatar name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid avatar or player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_invalid_avatar_or_player_id);
return; return;
} }
break; break;
...@@ -63,19 +63,19 @@ public final class GiveCharCommand implements CommandHandler { ...@@ -63,19 +63,19 @@ public final class GiveCharCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return; return;
} }
AvatarData avatarData = GameData.getAvatarDataMap().get(avatarId); AvatarData avatarData = GameData.getAvatarDataMap().get(avatarId);
if (avatarData == null) { if (avatarData == null) {
CommandHandler.sendMessage(sender, "Invalid avatar id."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_invalid_avatar_id);
return; return;
} }
// Check level. // Check level.
if (level > 90) { if (level > 90) {
CommandHandler.sendMessage(sender, "Invalid avatar level."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_invalid_avatar_level);
return; return;
} }
...@@ -94,6 +94,6 @@ public final class GiveCharCommand implements CommandHandler { ...@@ -94,6 +94,6 @@ public final class GiveCharCommand implements CommandHandler {
avatar.recalcStats(); avatar.recalcStats();
targetPlayer.addAvatar(avatar); targetPlayer.addAvatar(avatar);
CommandHandler.sendMessage(sender, String.format("Given %s with level %s to %s.", avatarId, level, target)); CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().GiveChar_given, avatarId, level, target));
} }
} }
...@@ -21,13 +21,13 @@ public final class GiveCommand implements CommandHandler { ...@@ -21,13 +21,13 @@ public final class GiveCommand implements CommandHandler {
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
int target, item, lvl, amount = 1, refinement = 0; int target, item, lvl, amount = 1, refinement = 0;
if (sender == null && args.size() < 2) { if (sender == null && args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount] [level]"); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Give_usage);
return; return;
} }
switch (args.size()) { switch (args.size()) {
default: // *No args* default: // *No args*
CommandHandler.sendMessage(sender, "Usage: give [player] <itemId|itemName> [amount]"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_usage);
return; return;
case 1: // <itemId|itemName> case 1: // <itemId|itemName>
try { try {
...@@ -36,7 +36,7 @@ public final class GiveCommand implements CommandHandler { ...@@ -36,7 +36,7 @@ public final class GiveCommand implements CommandHandler {
lvl = 1; lvl = 1;
} 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, "Invalid item id."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
return; return;
} }
break; break;
...@@ -54,7 +54,7 @@ public final class GiveCommand implements CommandHandler { ...@@ -54,7 +54,7 @@ public final class GiveCommand implements CommandHandler {
} }
} 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, "Invalid item or player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_or_player_id);
return; return;
} }
break; break;
...@@ -75,7 +75,7 @@ public final class GiveCommand implements CommandHandler { ...@@ -75,7 +75,7 @@ public final class GiveCommand implements CommandHandler {
} 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, "Invalid item or player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_or_player_id);
return; return;
} }
break; break;
...@@ -96,7 +96,7 @@ public final class GiveCommand implements CommandHandler { ...@@ -96,7 +96,7 @@ public final class GiveCommand implements CommandHandler {
} }
} 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, "Invalid item or player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_or_player_id);
return; return;
} }
break; break;
...@@ -105,7 +105,7 @@ public final class GiveCommand implements CommandHandler { ...@@ -105,7 +105,7 @@ public final class GiveCommand implements CommandHandler {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(sender, "Invalid player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return; return;
} else { } else {
item = Integer.parseInt(args.get(1)); item = Integer.parseInt(args.get(1));
...@@ -115,7 +115,7 @@ public final class GiveCommand implements CommandHandler { ...@@ -115,7 +115,7 @@ public final class GiveCommand implements CommandHandler {
} }
} 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, "Invalid item or player ID."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_or_player_id);
return; return;
} }
break; break;
...@@ -124,23 +124,23 @@ public final class GiveCommand implements CommandHandler { ...@@ -124,23 +124,23 @@ public final class GiveCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return; return;
} }
ItemData itemData = GameData.getItemDataMap().get(item); ItemData itemData = GameData.getItemDataMap().get(item);
if (itemData == null) { if (itemData == null) {
CommandHandler.sendMessage(sender, "Invalid item id."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
return; return;
} }
if (refinement != 0) { if (refinement != 0) {
if (itemData.getItemType() == ItemType.ITEM_WEAPON) { if (itemData.getItemType() == ItemType.ITEM_WEAPON) {
if (refinement < 1 || refinement > 5) { if (refinement < 1 || refinement > 5) {
CommandHandler.sendMessage(sender, "Refinement must be between 1 and 5."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_refinement_must_between_1_and_5);
return; return;
} }
} else { } else {
CommandHandler.sendMessage(sender, "Refinement is only applicable to weapons."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_refinement_only_applicable_weapons);
return; return;
} }
} }
...@@ -148,13 +148,13 @@ public final class GiveCommand implements CommandHandler { ...@@ -148,13 +148,13 @@ public final class GiveCommand implements CommandHandler {
this.item(targetPlayer, itemData, amount, lvl, refinement); this.item(targetPlayer, itemData, amount, lvl, refinement);
if (!itemData.isEquip()) { if (!itemData.isEquip()) {
CommandHandler.sendMessage(sender, String.format("Given %s of %s to %s.", amount, item, target)); CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Give_given, amount, item, target));
} else if (itemData.getItemType() == ItemType.ITEM_WEAPON) { } else if (itemData.getItemType() == ItemType.ITEM_WEAPON) {
CommandHandler.sendMessage(sender, CommandHandler.sendMessage(sender,
String.format("Given %s with level %s, refinement %s %s times to %s", item, lvl, refinement, amount, target)); String.format(Grasscutter.getLanguage().Give_given_with_level_and_refinement, item, lvl, refinement, amount, target));
} else { } else {
CommandHandler.sendMessage(sender, CommandHandler.sendMessage(sender,
String.format("Given %s with level %s %s times to %s", item, lvl, amount, target)); String.format(Grasscutter.getLanguage().Give_given_level, item, lvl, amount, target));
} }
} }
......
...@@ -14,7 +14,7 @@ public final class GodModeCommand implements CommandHandler { ...@@ -14,7 +14,7 @@ public final class GodModeCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game."); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; // TODO: toggle player's godmode statue from console or other players return; // TODO: toggle player's godmode statue from console or other players
} }
...@@ -26,7 +26,7 @@ public final class GodModeCommand implements CommandHandler { ...@@ -26,7 +26,7 @@ public final class GodModeCommand implements CommandHandler {
target = sender.getUid(); target = sender.getUid();
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
CommandHandler.sendMessage(sender, "Invalid player id."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return; return;
} }
} else { } else {
...@@ -34,12 +34,14 @@ public final class GodModeCommand implements CommandHandler { ...@@ -34,12 +34,14 @@ public final class GodModeCommand implements CommandHandler {
} }
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return; return;
} }
targetPlayer.setGodmode(!targetPlayer.inGodmode()); targetPlayer.setGodmode(!targetPlayer.inGodmode());
sender.dropMessage("Godmode is now " + (targetPlayer.inGodmode() ? "enabled" : "disabled") + sender.dropMessage(String.format(Grasscutter.getLanguage().Godmode_status,
"for " + targetPlayer.getNickname() + " ."); (targetPlayer.inGodmode() ? Grasscutter.getLanguage().Enabled : Grasscutter.getLanguage().Disabled),
targetPlayer.getNickname()
));
} }
} }
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;
...@@ -15,7 +16,7 @@ public final class HealCommand implements CommandHandler { ...@@ -15,7 +16,7 @@ public final class HealCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, List<String> args) { public void execute(Player sender, List<String> args) {
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game."); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; return;
} }
...@@ -30,6 +31,6 @@ public final class HealCommand implements CommandHandler { ...@@ -30,6 +31,6 @@ public final class HealCommand implements CommandHandler {
entity.getWorld().broadcastPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar())); entity.getWorld().broadcastPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar()));
} }
}); });
CommandHandler.sendMessage(sender, "All characters have been healed."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Heal_message);
} }
} }
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.command.CommandMap; import emu.grasscutter.command.CommandMap;
...@@ -30,16 +31,16 @@ public final class HelpCommand implements CommandHandler { ...@@ -30,16 +31,16 @@ public final class HelpCommand implements CommandHandler {
} else { } else {
String command = args.get(0); String command = args.get(0);
CommandHandler handler = CommandMap.getInstance().getHandler(command); CommandHandler handler = CommandMap.getInstance().getHandler(command);
StringBuilder builder = new StringBuilder(player == null ? "\nHelp - " : "Help - ").append(command).append(": \n"); StringBuilder builder = new StringBuilder(player == null ? "\n" + Grasscutter.getLanguage().Help + " - " : Grasscutter.getLanguage().Help + " - ").append(command).append(": \n");
if (handler == null) { if (handler == null) {
builder.append("No command found."); builder.append(Grasscutter.getLanguage().No_command_found);
} else { } else {
Command annotation = handler.getClass().getAnnotation(Command.class); Command annotation = handler.getClass().getAnnotation(Command.class);
builder.append(" ").append(annotation.description()).append("\n"); builder.append(" ").append(annotation.description()).append("\n");
builder.append(" Usage: ").append(annotation.usage()); builder.append(Grasscutter.getLanguage().Help_usage).append(annotation.usage());
if (annotation.aliases().length >= 1) { if (annotation.aliases().length >= 1) {
builder.append("\n").append(" Aliases: "); builder.append("\n").append(Grasscutter.getLanguage().Help_aliases);
for (String alias : annotation.aliases()) { for (String alias : annotation.aliases()) {
builder.append(alias).append(" "); builder.append(alias).append(" ");
} }
...@@ -55,13 +56,13 @@ public final class HelpCommand implements CommandHandler { ...@@ -55,13 +56,13 @@ public final class HelpCommand implements CommandHandler {
void SendAllHelpMessage(Player player, List<Command> annotations) { void SendAllHelpMessage(Player player, List<Command> annotations) {
if (player == null) { if (player == null) {
StringBuilder builder = new StringBuilder("\nAvailable commands:\n"); StringBuilder builder = new StringBuilder("\n" + Grasscutter.getLanguage().Help_available_command + "\n");
annotations.forEach(annotation -> { annotations.forEach(annotation -> {
builder.append(annotation.label()).append("\n"); builder.append(annotation.label()).append("\n");
builder.append(" ").append(annotation.description()).append("\n"); builder.append(" ").append(annotation.description()).append("\n");
builder.append(" Usage: ").append(annotation.usage()); builder.append(Grasscutter.getLanguage().Help_usage).append(annotation.usage());
if (annotation.aliases().length >= 1) { if (annotation.aliases().length >= 1) {
builder.append("\n").append(" Aliases: "); builder.append("\n").append(Grasscutter.getLanguage().Help_aliases);
for (String alias : annotation.aliases()) { for (String alias : annotation.aliases()) {
builder.append(alias).append(" "); builder.append(alias).append(" ");
} }
...@@ -72,13 +73,13 @@ public final class HelpCommand implements CommandHandler { ...@@ -72,13 +73,13 @@ public final class HelpCommand implements CommandHandler {
CommandHandler.sendMessage(null, builder.toString()); CommandHandler.sendMessage(null, builder.toString());
} else { } else {
CommandHandler.sendMessage(player, "Available commands:"); CommandHandler.sendMessage(player, Grasscutter.getLanguage().Help_available_command);
annotations.forEach(annotation -> { annotations.forEach(annotation -> {
StringBuilder builder = new StringBuilder(annotation.label()).append("\n"); StringBuilder builder = new StringBuilder(annotation.label()).append("\n");
builder.append(" ").append(annotation.description()).append("\n"); builder.append(" ").append(annotation.description()).append("\n");
builder.append(" Usage: ").append(annotation.usage()); builder.append(Grasscutter.getLanguage().Help_usage).append(annotation.usage());
if (annotation.aliases().length >= 1) { if (annotation.aliases().length >= 1) {
builder.append("\n").append(" Aliases: "); builder.append("\n").append(Grasscutter.getLanguage().Help_aliases);
for (String alias : annotation.aliases()) { for (String alias : annotation.aliases()) {
builder.append(alias).append(" "); builder.append(alias).append(" ");
} }
......
...@@ -17,14 +17,14 @@ public final class KickCommand implements CommandHandler { ...@@ -17,14 +17,14 @@ public final class KickCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return; return;
} }
if (sender != null) { if (sender != null) {
CommandHandler.sendMessage(sender, String.format("Player [%s:%s] has kicked player [%s:%s]", sender.getAccount().getPlayerUid(), sender.getAccount().getUsername(), target, targetPlayer.getAccount().getUsername())); CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Kick_player_kick_player, sender.getAccount().getPlayerUid(), sender.getAccount().getUsername(), target, targetPlayer.getAccount().getUsername()));
} }
CommandHandler.sendMessage(sender, String.format("Kicking player [%s:%s]", target, targetPlayer.getAccount().getUsername())); CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Kick_server_player, target, targetPlayer.getAccount().getUsername()));
targetPlayer.getSession().close(); targetPlayer.getSession().close();
} }
......
...@@ -23,7 +23,7 @@ public final class KillAllCommand implements CommandHandler { ...@@ -23,7 +23,7 @@ public final class KillAllCommand implements CommandHandler {
switch (args.size()) { switch (args.size()) {
case 0: // *No args* case 0: // *No args*
if (sender == null) { if (sender == null) {
CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]"); CommandHandler.sendMessage(null, Grasscutter.getLanguage().Kill_usage);
return; return;
} }
mainScene = sender.getScene(); mainScene = sender.getScene();
...@@ -31,7 +31,7 @@ public final class KillAllCommand implements CommandHandler { ...@@ -31,7 +31,7 @@ public final class KillAllCommand implements CommandHandler {
case 1: // [playerUid] case 1: // [playerUid]
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0))); targetPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0)));
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
return; return;
} }
mainScene = targetPlayer.getScene(); mainScene = targetPlayer.getScene();
...@@ -39,18 +39,18 @@ public final class KillAllCommand implements CommandHandler { ...@@ -39,18 +39,18 @@ public final class KillAllCommand implements CommandHandler {
case 2: // [playerUid] [sceneId] case 2: // [playerUid] [sceneId]
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0))); targetPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0)));
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
return; return;
} }
Scene scene = sender.getWorld().getSceneById(Integer.parseInt(args.get(1))); Scene scene = sender.getWorld().getSceneById(Integer.parseInt(args.get(1)));
if (scene == null) { if (scene == null) {
CommandHandler.sendMessage(sender, "Scene not found in player world"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Kill_scene_not_found_in_player_world);
return; return;
} }
mainScene = scene; mainScene = scene;
break; break;
default: default:
CommandHandler.sendMessage(sender, "Usage: killall [playerUid] [sceneId]"); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Kill_usage);
return; return;
} }
...@@ -59,9 +59,9 @@ public final class KillAllCommand implements CommandHandler { ...@@ -59,9 +59,9 @@ public final class KillAllCommand implements CommandHandler {
.filter(entity -> entity instanceof EntityMonster) .filter(entity -> entity instanceof EntityMonster)
.toList(); .toList();
toKill.stream().forEach(entity -> mainScene.killEntity(entity, 0)); toKill.stream().forEach(entity -> mainScene.killEntity(entity, 0));
CommandHandler.sendMessage(sender, "Killing " + toKill.size() + " monsters in scene " + mainScene.getId()); CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Kill_kill_monsters_in_scene, toKill.size(), mainScene.getId()));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid arguments."); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments);
} }
} }
} }
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