Add multilingual support

Add multilingual support
This commit is contained in:
方块君 2022-05-03 14:23:25 +08:00 committed by Melledy
parent 86e6eef4e2
commit 0eab44f51f
43 changed files with 619 additions and 281 deletions

View File

@ -21,6 +21,7 @@ public final class Config {
public ServerRunMode RunMode = ServerRunMode.HYBRID; // HYBRID, DISPATCH_ONLY, GAME_ONLY
public GameServerOptions GameServer = new GameServerOptions();
public DispatchServerOptions DispatchServer = new DispatchServerOptions();
public String Language = "en_us";
public GameServerOptions getGameServerOptions() {
return GameServer;

View File

@ -30,6 +30,7 @@ import emu.grasscutter.utils.Crypto;
public final class Grasscutter {
private static final Logger log = (Logger) LoggerFactory.getLogger(Grasscutter.class);
private static Config config;
private static Language language;
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static final File configFile = new File("./config.json");
@ -48,6 +49,9 @@ public final class Grasscutter {
// Load server configuration.
Grasscutter.loadConfig();
// Load Language
Grasscutter.loadLanguage();
// Check server structure.
Utils.startupCheck();
@ -68,7 +72,7 @@ public final class Grasscutter {
}
// Initialize server.
Grasscutter.getLogger().info("Starting Grasscutter...");
Grasscutter.getLogger().info(language.Starting_Grasscutter);
// Load all resources.
Grasscutter.updateDayOfWeek();
@ -96,9 +100,9 @@ public final class Grasscutter {
} else if (getConfig().RunMode == ServerRunMode.GAME_ONLY) {
gameServer.start();
} else {
getLogger().error("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("Shutting down...");
getLogger().error(language.Invalid_server_run_mode + " " + getConfig().RunMode);
getLogger().error(language.Server_run_mode);
getLogger().error(language.Shutting_down);
System.exit(1);
}
@ -128,6 +132,31 @@ public final class Grasscutter {
saveConfig();
}
}
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() {
try (FileWriter file = new FileWriter(configFile)) {
@ -139,22 +168,22 @@ public final class Grasscutter {
public static void startConsole() {
String input;
getLogger().info("Done! For help, type \"help\"");
getLogger().info(language.Start_done);
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
while ((input = br.readLine()) != null) {
try {
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;
}
CommandMap.getInstance().invoke(null, input);
} catch (Exception e) {
Grasscutter.getLogger().error("Command error:", e);
Grasscutter.getLogger().error(language.Command_error, 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 {
return config;
}
public static Language getLanguage() {
return language;
}
public static Logger getLogger() {
return log;
}

View File

@ -0,0 +1,285 @@
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.";
}

View File

@ -107,7 +107,7 @@ public final class CommandMap {
public void invoke(Player player, String rawMessage) {
rawMessage = rawMessage.trim();
if (rawMessage.length() == 0) {
CommandHandler.sendMessage(player, "No command specified.");
CommandHandler.sendMessage(player, Grasscutter.getLanguage().No_command_specified);
return;
}
@ -122,7 +122,7 @@ public final class CommandMap {
// Get command handler.
CommandHandler handler = this.commands.get(label);
if (handler == null) {
CommandHandler.sendMessage(player, "Unknown command: " + label);
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Unknown_command + label);
return;
}
@ -131,7 +131,7 @@ public final class CommandMap {
String permissionNode = this.annotations.get(label).permission();
Account account = player.getAccount();
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;
}
}

View File

@ -14,12 +14,12 @@ public final class AccountCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
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;
}
if (args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: account <create|delete> <username> [uid]");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_command_usage);
return;
}
@ -28,7 +28,7 @@ public final class AccountCommand implements CommandHandler {
switch (action) {
default:
CommandHandler.sendMessage(null, "Usage: account <create|delete> <username> [uid]");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_command_usage);
return;
case "create":
int uid = 0;
@ -36,27 +36,27 @@ public final class AccountCommand implements CommandHandler {
try {
uid = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid UID.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Invalid_UID);
return;
}
}
emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid);
if (account == null) {
CommandHandler.sendMessage(null, "Account already exists.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_exists);
return;
} else {
account.addPermission("*");
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;
case "delete":
if (DatabaseHelper.deleteAccount(username)) {
CommandHandler.sendMessage(null, "Account deleted.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_delete);
} else {
CommandHandler.sendMessage(null, "Account not found.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_not_find);
}
}
}

View File

@ -14,7 +14,7 @@ public final class BroadcastCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: broadcast <message>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_command_usage);
return;
}
@ -24,6 +24,6 @@ public final class BroadcastCommand implements CommandHandler {
CommandHandler.sendMessage(p, message);
}
CommandHandler.sendMessage(sender, "Message sent.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_message_sent);
}
}

View File

@ -1,7 +1,9 @@
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.gacha.GachaRecord;
import emu.grasscutter.game.player.Player;
import java.util.List;
@ -12,12 +14,12 @@ public final class ChangeSceneCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: changescene <scene id>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_usage);
return;
}
@ -25,18 +27,18 @@ public final class ChangeSceneCommand implements CommandHandler {
int sceneId = Integer.parseInt(args.get(0));
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;
}
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) {
CommandHandler.sendMessage(sender, "Scene does not exist");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_not_exist);
}
} catch (Exception e) {
CommandHandler.sendMessage(sender, "Usage: changescene <scene id>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_usage);
}
}
}

View File

@ -20,7 +20,7 @@ public final class ClearCommand implements CommandHandler {
int target;
String cmdSwitch = "";
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
Inventory playerInventory = sender.getInventory();
@ -39,7 +39,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getItemType() == ItemType.ITEM_WEAPON)
.filter(item -> !item.isLocked() && !item.isEquipped())
.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" -> {
playerInventory.getItems().values().stream()
@ -47,7 +47,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped())
.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" -> {
playerInventory.getItems().values().stream()
@ -55,7 +55,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped())
.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" -> {
playerInventory.getItems().values().stream()
@ -63,45 +63,45 @@ public final class ClearCommand implements CommandHandler {
.filter(item1 -> item1.getLevel() == 1 && item1.getExp() == 0)
.filter(item1 -> !item1.isLocked() && !item1.isEquipped())
.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()
.filter(item2 -> item2.getItemType() == ItemType.ITEM_MATERIAL)
.filter(item2 -> !item2.isLocked() && !item2.isEquipped())
.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()
.filter(item3 -> item3.getItemType() == ItemType.ITEM_WEAPON)
.filter(item3 -> item3.getLevel() == 1 && item3.getExp() == 0)
.filter(item3 -> !item3.isLocked() && !item3.isEquipped())
.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()
.filter(item4 -> item4.getItemType() == ItemType.ITEM_FURNITURE)
.filter(item4 -> !item4.isLocked() && !item4.isEquipped())
.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()
.filter(item5 -> item5.getItemType() == ItemType.ITEM_DISPLAY)
.filter(item5 -> !item5.isLocked() && !item5.isEquipped())
.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()
.filter(item6 -> item6.getItemType() == ItemType.ITEM_VIRTUAL)
.filter(item6 -> !item6.isLocked() && !item6.isEquipped())
.forEach(item6 -> playerInventory.removeItem(item6, item6.getCount()));
sender.dropMessage("Cleared virtuals for " + targetPlayer.getNickname() + " .");
sender.dropMessage("Cleared everything for " + targetPlayer.getNickname() + " .");
sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_virtuals, targetPlayer.getNickname()));
sender.dropMessage(String.format(Grasscutter.getLanguage().Clear_everything, targetPlayer.getNickname()));
}
}
} catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid playerId.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
}
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
}

View File

@ -1,5 +1,6 @@
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;
@ -12,7 +13,7 @@ public final class CoopCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (args.size() < 2) {
CommandHandler.sendMessage(sender, "Usage: coop <playerId> <target playerId>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Coop_usage);
return;
}
@ -22,7 +23,7 @@ public final class CoopCommand implements CommandHandler {
Player host = sender.getServer().getPlayerByUid(hostId);
Player want = sender.getServer().getPlayerByUid(tid);
if (host == null || want == null) {
CommandHandler.sendMessage(sender, "Player is offline.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_is_offline);
return;
}
if (want.isInMultiplayer()) {
@ -31,7 +32,7 @@ public final class CoopCommand implements CommandHandler {
sender.getServer().getMultiplayerManager().applyEnterMp(want, hostId);
sender.getServer().getMultiplayerManager().applyEnterMpReply(host, tid, true);
} catch (Exception e) {
CommandHandler.sendMessage(sender, "Player id is not valid.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
}
}
}

View File

@ -1,5 +1,6 @@
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData;
@ -17,12 +18,12 @@ public final class DropCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: drop <itemId|itemName> [amount]");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Drop_usage);
return;
}
@ -33,7 +34,7 @@ public final class DropCommand implements CommandHandler {
ItemData itemData = GameData.getItemDataMap().get(item);
if (itemData == null) {
CommandHandler.sendMessage(sender, "Invalid item id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
return;
}
@ -48,9 +49,9 @@ public final class DropCommand implements CommandHandler {
EntityItem entity = new EntityItem(sender.getScene(), sender, itemData, sender.getPos().clone().addY(3f), amount);
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) {
CommandHandler.sendMessage(sender, "Invalid item or player ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_or_player_id);
}
}
}

View File

@ -1,5 +1,6 @@
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;
@ -12,12 +13,12 @@ public final class EnterDungeonCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: enterdungeon <dungeon id>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_usage);
return;
}
@ -25,18 +26,18 @@ public final class EnterDungeonCommand implements CommandHandler {
int dungeonId = Integer.parseInt(args.get(0));
if (dungeonId == sender.getSceneId()) {
CommandHandler.sendMessage(sender, "You are already in that dungeon");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_you_in_that_dungeon);
return;
}
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) {
CommandHandler.sendMessage(sender, "Dungeon does not exist");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_dungeon_not_found);
}
} catch (Exception e) {
CommandHandler.sendMessage(sender, "Usage: enterdungeon <dungeon id>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_usage);
}
}
}

View File

@ -24,7 +24,7 @@ public final class GiveAllCommand implements CommandHandler {
switch (args.size()) {
case 0: // *no args*
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;
}
target = sender.getUid();
@ -34,11 +34,11 @@ public final class GiveAllCommand implements CommandHandler {
try {
target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(sender, "Invalid player ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
}
}catch (NumberFormatException ignored){
CommandHandler.sendMessage(sender, "Invalid player ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
}
break;
@ -53,28 +53,28 @@ public final class GiveAllCommand implements CommandHandler {
amount = Integer.parseInt(args.get(1));
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid amount or player ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveAll_invalid_amount_or_playerId);
return;
}
break;
default: // invalid
CommandHandler.sendMessage(null, "Usage: giveall [player] [amount]");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().GiveAll_usage);
return;
}
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
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) {
CommandHandler.sendMessage(player, "Giving all items...");
CommandHandler.sendMessage(player, Grasscutter.getLanguage().GiveAll_item);
for (AvatarData avatarData: GameData.getAvatarDataMap().values()) {
//Exclude test avatar

View File

@ -20,7 +20,7 @@ public final class GiveArtifactCommand implements CommandHandler {
public void execute(Player sender, List<String> args) {
int size = args.size(), target, itemId, mainPropId, level = 1;
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) {
CommandHandler.sendMessage(null, msg);
@ -70,14 +70,14 @@ public final class GiveArtifactCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
ItemData itemData = GameData.getItemDataMap().get(itemId);
if (itemData.getItemType() != ItemType.ITEM_RELIQUARY) {
CommandHandler.sendMessage(sender, "Invalid artifact ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveArtifact_invalid_artifact_id);
return;
}
@ -88,7 +88,7 @@ public final class GiveArtifactCommand implements CommandHandler {
item.getAppendPropIdList().addAll(appendPropIdList);
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));
}
}

View File

@ -19,13 +19,13 @@ public final class GiveCharCommand implements CommandHandler {
int target, avatarId, level = 1, ascension;
if (sender == null && args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: givechar <player> <itemId|itemName> [amount]");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().GiveChar_usage);
return;
}
switch (args.size()) {
default:
CommandHandler.sendMessage(sender, "Usage: givechar <player> <avatarId> [level]");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_usage);
return;
case 2:
try {
@ -39,7 +39,7 @@ public final class GiveCharCommand implements CommandHandler {
}
} catch (NumberFormatException ignored) {
// 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;
}
break;
@ -47,7 +47,7 @@ public final class GiveCharCommand implements CommandHandler {
try {
target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(sender, "Invalid player ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
}
@ -55,7 +55,7 @@ public final class GiveCharCommand implements CommandHandler {
level = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
// 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;
}
break;
@ -63,19 +63,19 @@ public final class GiveCharCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
AvatarData avatarData = GameData.getAvatarDataMap().get(avatarId);
if (avatarData == null) {
CommandHandler.sendMessage(sender, "Invalid avatar id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_invalid_avatar_id);
return;
}
// Check level.
if (level > 90) {
CommandHandler.sendMessage(sender, "Invalid avatar level.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_invalid_avatar_level);
return;
}
@ -94,6 +94,6 @@ public final class GiveCharCommand implements CommandHandler {
avatar.recalcStats();
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));
}
}

View File

@ -21,13 +21,13 @@ public final class GiveCommand implements CommandHandler {
public void execute(Player sender, List<String> args) {
int target, item, lvl, amount = 1, refinement = 0;
if (sender == null && args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount] [level]");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Give_usage);
return;
}
switch (args.size()) {
default: // *No args*
CommandHandler.sendMessage(sender, "Usage: give [player] <itemId|itemName> [amount]");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_usage);
return;
case 1: // <itemId|itemName>
try {
@ -36,7 +36,7 @@ public final class GiveCommand implements CommandHandler {
lvl = 1;
} catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid item id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
return;
}
break;
@ -54,7 +54,7 @@ public final class GiveCommand implements CommandHandler {
}
} catch (NumberFormatException ignored) {
// 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;
}
break;
@ -75,7 +75,7 @@ public final class GiveCommand implements CommandHandler {
} catch (NumberFormatException ignored) {
// 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;
}
break;
@ -96,7 +96,7 @@ public final class GiveCommand implements CommandHandler {
}
} catch (NumberFormatException ignored) {
// 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;
}
break;
@ -105,7 +105,7 @@ public final class GiveCommand implements CommandHandler {
target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(sender, "Invalid player ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
} else {
item = Integer.parseInt(args.get(1));
@ -115,7 +115,7 @@ public final class GiveCommand implements CommandHandler {
}
} catch (NumberFormatException ignored) {
// 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;
}
break;
@ -124,23 +124,23 @@ public final class GiveCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
ItemData itemData = GameData.getItemDataMap().get(item);
if (itemData == null) {
CommandHandler.sendMessage(sender, "Invalid item id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
return;
}
if (refinement != 0) {
if (itemData.getItemType() == ItemType.ITEM_WEAPON) {
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;
}
} else {
CommandHandler.sendMessage(sender, "Refinement is only applicable to weapons.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_refinement_only_applicable_weapons);
return;
}
}
@ -148,13 +148,13 @@ public final class GiveCommand implements CommandHandler {
this.item(targetPlayer, itemData, amount, lvl, refinement);
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) {
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 {
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));
}
}

View File

@ -14,7 +14,7 @@ public final class GodModeCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
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
}
@ -26,7 +26,7 @@ public final class GodModeCommand implements CommandHandler {
target = sender.getUid();
}
} catch (NumberFormatException e) {
CommandHandler.sendMessage(sender, "Invalid player id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
}
} else {
@ -34,12 +34,14 @@ public final class GodModeCommand implements CommandHandler {
}
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
targetPlayer.setGodmode(!targetPlayer.inGodmode());
sender.dropMessage("Godmode is now " + (targetPlayer.inGodmode() ? "enabled" : "disabled") +
"for " + targetPlayer.getNickname() + " .");
sender.dropMessage(String.format(Grasscutter.getLanguage().Godmode_status,
(targetPlayer.inGodmode() ? Grasscutter.getLanguage().Enabled : Grasscutter.getLanguage().Disabled),
targetPlayer.getNickname()
));
}
}

View File

@ -1,5 +1,6 @@
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;
@ -15,7 +16,7 @@ public final class HealCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
@ -30,6 +31,6 @@ public final class HealCommand implements CommandHandler {
entity.getWorld().broadcastPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar()));
}
});
CommandHandler.sendMessage(sender, "All characters have been healed.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Heal_message);
}
}

View File

@ -1,5 +1,6 @@
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.command.CommandMap;
@ -30,16 +31,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 ? "\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) {
builder.append("No command found.");
builder.append(Grasscutter.getLanguage().No_command_found);
} else {
Command annotation = handler.getClass().getAnnotation(Command.class);
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) {
builder.append("\n").append(" Aliases: ");
builder.append("\n").append(Grasscutter.getLanguage().Help_aliases);
for (String alias : annotation.aliases()) {
builder.append(alias).append(" ");
}
@ -55,13 +56,13 @@ public final class HelpCommand implements CommandHandler {
void SendAllHelpMessage(Player player, List<Command> annotations) {
if (player == null) {
StringBuilder builder = new StringBuilder("\nAvailable commands:\n");
StringBuilder builder = new StringBuilder("\n" + Grasscutter.getLanguage().Help_available_command + "\n");
annotations.forEach(annotation -> {
builder.append(annotation.label()).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) {
builder.append("\n").append(" Aliases: ");
builder.append("\n").append(Grasscutter.getLanguage().Help_aliases);
for (String alias : annotation.aliases()) {
builder.append(alias).append(" ");
}
@ -72,13 +73,13 @@ public final class HelpCommand implements CommandHandler {
CommandHandler.sendMessage(null, builder.toString());
} else {
CommandHandler.sendMessage(player, "Available commands:");
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Help_available_command);
annotations.forEach(annotation -> {
StringBuilder builder = new StringBuilder(annotation.label()).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) {
builder.append("\n").append(" Aliases: ");
builder.append("\n").append(Grasscutter.getLanguage().Help_aliases);
for (String alias : annotation.aliases()) {
builder.append(alias).append(" ");
}

View File

@ -17,14 +17,14 @@ public final class KickCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
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();
}

View File

@ -23,7 +23,7 @@ public final class KillAllCommand implements CommandHandler {
switch (args.size()) {
case 0: // *No args*
if (sender == null) {
CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Kill_usage);
return;
}
mainScene = sender.getScene();
@ -31,7 +31,7 @@ public final class KillAllCommand implements CommandHandler {
case 1: // [playerUid]
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0)));
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
return;
}
mainScene = targetPlayer.getScene();
@ -39,18 +39,18 @@ public final class KillAllCommand implements CommandHandler {
case 2: // [playerUid] [sceneId]
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(Integer.parseInt(args.get(0)));
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
return;
}
Scene scene = sender.getWorld().getSceneById(Integer.parseInt(args.get(1)));
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;
}
mainScene = scene;
break;
default:
CommandHandler.sendMessage(sender, "Usage: killall [playerUid] [sceneId]");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Kill_usage);
return;
}
@ -59,9 +59,9 @@ public final class KillAllCommand implements CommandHandler {
.filter(entity -> entity instanceof EntityMonster)
.toList();
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) {
CommandHandler.sendMessage(sender, "Invalid arguments.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments);
}
}
}

View File

@ -25,11 +25,11 @@ public final class KillCharacterCommand implements CommandHandler {
try {
target = Integer.parseInt(args.get(0));
} catch (NumberFormatException e) {
CommandHandler.sendMessage(null, "Invalid player id.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Invalid_playerId);
return;
}
} else {
CommandHandler.sendMessage(null, "Usage: /killcharacter [playerId]");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().KillCharacter_usage);
return;
}
} else {
@ -40,7 +40,7 @@ public final class KillCharacterCommand implements CommandHandler {
target = sender.getUid();
}
} catch (NumberFormatException e) {
CommandHandler.sendMessage(sender, "Invalid player id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
}
} else {
@ -50,7 +50,7 @@ public final class KillCharacterCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
return;
}
@ -63,6 +63,6 @@ public final class KillCharacterCommand implements CommandHandler {
targetPlayer.getScene().removeEntity(entity);
entity.onDeath(0);
CommandHandler.sendMessage(sender, "Killed " + targetPlayer.getNickname() + " current character.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().KillCharacter_kill_current_character, targetPlayer.getNickname()));
}
}

View File

@ -21,7 +21,7 @@ public final class ListCommand implements CommandHandler {
needUID = args.get(0).equals("uid");
}
CommandHandler.sendMessage(sender, String.format("There are %s player(s) online:", playersMap.size()));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().List_message, playersMap.size()));
if (playersMap.size() != 0) {
StringBuilder playerSet = new StringBuilder();

View File

@ -15,7 +15,7 @@ public final class PermissionCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (args.size() < 3) {
CommandHandler.sendMessage(sender, "Usage: permission <add|remove> <username> <permission>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage);
return;
}
@ -25,23 +25,23 @@ public final class PermissionCommand implements CommandHandler {
Account account = Grasscutter.getGameServer().getAccountByName(username);
if (account == null) {
CommandHandler.sendMessage(sender, "Account not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Account_not_find);
return;
}
switch (action) {
default:
CommandHandler.sendMessage(sender, "Usage: permission <add|remove> <username> <permission>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_usage);
break;
case "add":
if (account.addPermission(permission)) {
CommandHandler.sendMessage(sender, "Permission added.");
} else CommandHandler.sendMessage(sender, "They already have this permission!");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_add);
} else CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_have_permission);
break;
case "remove":
if (account.removePermission(permission)) {
CommandHandler.sendMessage(sender, "Permission removed.");
} else CommandHandler.sendMessage(sender, "They don't have this permission!");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_remove);
} else CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Permission_not_have_permission);
break;
}

View File

@ -1,5 +1,6 @@
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;
@ -13,11 +14,11 @@ public final class PositionCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f\nScene id: %d",
sender.dropMessage(String.format(Grasscutter.getLanguage().Position_message,
sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ(), sender.getSceneId()));
}
}

View File

@ -13,12 +13,13 @@ public final class ReloadCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
CommandHandler.sendMessage(sender, "Reloading config.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Reload_reload_start);
Grasscutter.loadConfig();
Grasscutter.loadLanguage();
Grasscutter.getGameServer().getGachaManager().load();
Grasscutter.getGameServer().getDropManager().load();
Grasscutter.getGameServer().getShopManager().load();
Grasscutter.getDispatchServer().loadQueries();
CommandHandler.sendMessage(sender, "Reload complete.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Reload_reload_done);
}
}

View File

@ -1,5 +1,6 @@
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.avatar.Avatar;
@ -16,13 +17,13 @@ public final class ResetConstCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() > 0 && args.get(0).equalsIgnoreCase("all")) {
sender.getAvatars().forEach(this::resetConstellation);
sender.dropMessage("Reset all avatars' constellations.");
sender.dropMessage(Grasscutter.getLanguage().ResetConst_reset_all);
} else {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
if (entity == null) {
@ -32,7 +33,7 @@ public final class ResetConstCommand implements CommandHandler {
Avatar avatar = entity.getAvatar();
this.resetConstellation(avatar);
sender.dropMessage("Constellations for " + avatar.getAvatarData().getName() + " have been reset. Please relog to see changes.");
sender.dropMessage(String.format(Grasscutter.getLanguage().ResetConst_reset_all_done, avatar.getAvatarData().getName()));
}
}

View File

@ -13,19 +13,19 @@ public final class ResetShopLimitCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (args.size() < 1) {
CommandHandler.sendMessage(sender,"Usage: /resetshop <player id>");
CommandHandler.sendMessage(sender,Grasscutter.getLanguage().ResetShopLimit_usage);
return;
}
int target = Integer.parseInt(args.get(0));
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
targetPlayer.getShopLimit().forEach(x -> x.setNextRefreshTime(0));
targetPlayer.save();
CommandHandler.sendMessage(sender, "Success");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Success);
}
}

View File

@ -45,16 +45,16 @@ public final class SendMailCommand implements CommandHandler {
if (DatabaseHelper.getPlayerById(Integer.parseInt(args.get(0))) != null) {
mailBuilder = new MailBuilder(Integer.parseInt(args.get(0)), new Mail());
} else {
CommandHandler.sendMessage(sender, "The user with an id of '" + args.get(0) + "' does not exist");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_user_not_exist, args.get(0)));
return;
}
}
}
mailBeingConstructed.put(senderId, mailBuilder);
CommandHandler.sendMessage(sender, "Starting composition of message.\nPlease use `/sendmail <title>` to continue.\nYou can use `/sendmail stop` at any time");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_start_composition);
}
case 2 -> CommandHandler.sendMessage(sender, "Mail templates coming soon implemented...");
default -> CommandHandler.sendMessage(sender, "Invalid arguments.\nUsage `/sendmail <userId|all|help> [templateId]`");
case 2 -> CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_templates);
default -> CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_invalid_arguments);
}
} else {
MailBuilder mailBuilder = mailBeingConstructed.get(senderId);
@ -63,28 +63,28 @@ public final class SendMailCommand implements CommandHandler {
switch (args.get(0).toLowerCase()) {
case "stop" -> {
mailBeingConstructed.remove(senderId);
CommandHandler.sendMessage(sender, "Message sending cancelled");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_send_cancel);
return;
}
case "finish" -> {
if (mailBuilder.constructionStage == 3) {
if (!mailBuilder.sendToAll) {
Grasscutter.getGameServer().getPlayerByUid(mailBuilder.recipient, true).sendMail(mailBuilder.mail);
CommandHandler.sendMessage(sender, "Message sent to user " + mailBuilder.recipient + "!");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_send_done, mailBuilder.recipient));
} else {
for (Player player : DatabaseHelper.getAllPlayers()) {
Grasscutter.getGameServer().getPlayerByUid(player.getUid(), true).sendMail(mailBuilder.mail);
}
CommandHandler.sendMessage(sender, "Message sent to all users!");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_send_all_done);
}
mailBeingConstructed.remove(senderId);
} else {
CommandHandler.sendMessage(sender, "Message composition not at final stage.\nPlease use `/sendmail " + getConstructionArgs(mailBuilder.constructionStage) + "` or `/sendmail stop` to cancel");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_not_composition_end, getConstructionArgs(mailBuilder.constructionStage)));
}
return;
}
case "help" -> {
CommandHandler.sendMessage(sender, "Please use `/sendmail " + getConstructionArgs(mailBuilder.constructionStage) + "`");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_Please_use, getConstructionArgs(mailBuilder.constructionStage)));
return;
}
default -> {
@ -92,19 +92,19 @@ public final class SendMailCommand implements CommandHandler {
case 0 -> {
String title = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.title = title;
CommandHandler.sendMessage(sender, "Message title set as '" + title + "'.\nUse '/sendmail <content>' to continue.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_set_title, title));
mailBuilder.constructionStage++;
}
case 1 -> {
String contents = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.content = contents;
CommandHandler.sendMessage(sender, "Message contents set as '" + contents + "'.\nUse '/sendmail <sender>' to continue.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_set_contents, contents));
mailBuilder.constructionStage++;
}
case 2 -> {
String msgSender = String.join(" ", args.subList(0, args.size()));
mailBuilder.mail.mailContent.sender = msgSender;
CommandHandler.sendMessage(sender, "Message sender set as '" + msgSender + "'.\nUse '/sendmail <itemId|itemName|finish> [amount] [level]' to continue.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_set_message_sender, msgSender));
mailBuilder.constructionStage++;
}
case 3 -> {
@ -112,7 +112,7 @@ public final class SendMailCommand implements CommandHandler {
int item, lvl, amount = 1;
switch (args.size()) {
default -> { // *No args*
CommandHandler.sendMessage(sender, "Usage: give [player] <itemId|itemName> [amount]");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SendMail_usage);
return;
}
case 1 -> { // <itemId|itemName>
@ -121,7 +121,7 @@ public final class SendMailCommand implements CommandHandler {
lvl = 1;
} catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, "Invalid item id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
return;
}
}
@ -138,19 +138,19 @@ public final class SendMailCommand implements CommandHandler {
} catch (NumberFormatException ignored) {
// 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;
}
}
}
mailBuilder.mail.itemList.add(new Mail.MailItem(item, amount, lvl));
CommandHandler.sendMessage(sender, String.format("Attached %s of %s (level %s) to the message.\nContinue adding more items or use `/sendmail finish` to send the message.", amount, item, lvl));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_send, amount, item, lvl));
}
}
}
}
} else {
CommandHandler.sendMessage(sender, "Invalid arguments \n Please use `/sendmail " + getConstructionArgs(mailBuilder.constructionStage));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SendMail_invalid_arguments_please_use, getConstructionArgs(mailBuilder.constructionStage)));
}
}
}
@ -158,21 +158,21 @@ public final class SendMailCommand implements CommandHandler {
private String getConstructionArgs(int stage) {
switch (stage) {
case 0 -> {
return "<title>";
return Grasscutter.getLanguage().SendMail_title;
}
case 1 -> {
return "<message>";
return Grasscutter.getLanguage().SendMail_message;
}
case 2 -> {
return "<sender>";
return Grasscutter.getLanguage().SendMail_sender;
}
case 3 -> {
return "<itemId|itemName|finish> [amount] [level]";
return Grasscutter.getLanguage().SendMail_arguments;
}
default -> {
Thread.dumpStack();
return "ERROR: invalid construction stage " + stage + ". Check console for stacktrace.";
return String.format(Grasscutter.getLanguage().SendMail_error, stage);
}
}
}

View File

@ -14,7 +14,7 @@ public final class SendMessageCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: sendmessage <player> <message>");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SendMessage_usage);
return;
}
@ -24,14 +24,14 @@ public final class SendMessageCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
CommandHandler.sendMessage(targetPlayer, message);
CommandHandler.sendMessage(sender, "Message sent.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SenaMessage_message_sent);
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid player ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
}
}
}

View File

@ -2,6 +2,7 @@ package emu.grasscutter.command.commands;
import java.util.List;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData;
@ -17,19 +18,19 @@ public final class SetFetterLevelCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: setfetterlevel <level>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_usage);
return;
}
try {
int fetterLevel = Integer.parseInt(args.get(0));
if (fetterLevel < 0 || fetterLevel > 10) {
CommandHandler.sendMessage(sender, "Fetter level must be between 0 and 10.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_fetter_level_must_between_0_and_10);
return;
}
Avatar avatar = sender.getTeamManager().getCurrentAvatarEntity().getAvatar();
@ -41,9 +42,9 @@ public final class SetFetterLevelCommand implements CommandHandler {
avatar.save();
sender.sendPacket(new PacketAvatarFetterDataNotify(avatar));
CommandHandler.sendMessage(sender, "Fetter level set to " + fetterLevel);
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetFetterLevel_fetter_set_level, fetterLevel));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid fetter level.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_invalid_fetter_level);
}
}

View File

@ -1,5 +1,6 @@
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.entity.EntityAvatar;
@ -16,20 +17,20 @@ public final class SetStatsCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 2){
CommandHandler.sendMessage(sender, "Usage: setstats|stats <stat> <value>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_usage);
return;
}
String stat = args.get(0);
switch (stat) {
default:
CommandHandler.sendMessage(sender, "Usage: /setstats|stats <hp | mhp | def | atk | em | er | crate | cdmg> <value> for basic stats");
CommandHandler.sendMessage(sender, "Usage: /stats <epyro | ecryo | ehydro | egeo | edend | eelec | ephys> <amount> for elemental bonus");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_setstats_help_message);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_stats_help_message);
return;
case "mhp":
try {
@ -37,9 +38,9 @@ public final class SetStatsCommand implements CommandHandler {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_MAX_HP, health);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_MAX_HP));
CommandHandler.sendMessage(sender, "MAX HP set to " + health + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_max_hp, health));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Max HP value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_max_hp_error);
return;
}
break;
@ -49,9 +50,9 @@ public final class SetStatsCommand implements CommandHandler {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
CommandHandler.sendMessage(sender, "HP set to " + health + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_hp, health));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid HP value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_hp_error);
return;
}
break;
@ -61,9 +62,9 @@ public final class SetStatsCommand implements CommandHandler {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, def);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_DEFENSE));
CommandHandler.sendMessage(sender, "DEF set to " + def + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_def, def));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid DEF value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_def_error);
return;
}
break;
@ -73,9 +74,9 @@ public final class SetStatsCommand implements CommandHandler {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, atk);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_ATTACK));
CommandHandler.sendMessage(sender, "ATK set to " + atk + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_atk, atk));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid ATK value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_atk_error);
return;
}
break;
@ -85,9 +86,9 @@ public final class SetStatsCommand implements CommandHandler {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
entity.setFightProperty(FightProperty.FIGHT_PROP_ELEMENT_MASTERY, em);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ELEMENT_MASTERY));
CommandHandler.sendMessage(sender, "Elemental Mastery set to " + em + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_em, em));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid EM value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_em_error);
return;
}
break;
@ -99,9 +100,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, erecharge);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY));
float iger = erecharge * 100;
CommandHandler.sendMessage(sender, "Energy recharge set to " + iger + "%.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_er, iger));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid ER value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_er_error);
return;
}
break;
@ -113,9 +114,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL, crate);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL));
float igcrate = crate * 100;
CommandHandler.sendMessage(sender, "Crit Rate set to " + igcrate + "%.");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_cr, igcrate));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Crit Rate value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_cr_error);
return;
}
break;
@ -127,9 +128,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_CRITICAL_HURT, cdamage);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CRITICAL_HURT));
float igcdmg = cdamage * 100;
CommandHandler.sendMessage(sender, "Crit DMG set to " + igcdmg + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_cd, igcdmg));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Crit DMG value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_cd_error);
return;
}
break;
@ -141,9 +142,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_FIRE_ADD_HURT, pyro);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_FIRE_ADD_HURT));
float igpyro = pyro * 100;
CommandHandler.sendMessage(sender, "Pyro DMG Bonus set to " + igpyro + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_pdb, igpyro));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Pyro DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_pdb_error);
return;
}
break;
@ -155,9 +156,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_ICE_ADD_HURT, cryo);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ICE_ADD_HURT));
float igcyro = cryo * 100;
CommandHandler.sendMessage(sender, "Cyro DMG Bonus set to " + igcyro + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_cdb, igcyro));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Cryo DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_cdb_error);
return;
}
break;
@ -169,9 +170,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_WATER_ADD_HURT, hydro);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_WATER_ADD_HURT));
float ighydro = hydro * 100;
CommandHandler.sendMessage(sender, "Hydro DMG Bonus set to " + ighydro + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_hdb, ighydro));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Hydro DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_hdb_error);
return;
}
break;
@ -183,9 +184,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_WIND_ADD_HURT, anemo);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_WIND_ADD_HURT));
float iganemo = anemo * 100;
CommandHandler.sendMessage(sender, "Anemo DMG Bonus set to " + iganemo + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_adb, iganemo));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Anemo DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_adb_error);
return;
}
break;
@ -197,9 +198,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_ROCK_ADD_HURT, geo);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ROCK_ADD_HURT));
float iggeo = geo * 100;
CommandHandler.sendMessage(sender, "Geo DMG Bonus set to " + iggeo + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_gdb, iggeo));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Geo DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_gdb_error);
return;
}
break;
@ -212,9 +213,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_ELEC_ADD_HURT, elec);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_ELEC_ADD_HURT));
float igelec = elec * 100;
CommandHandler.sendMessage(sender, "Electro DMG Bonus set to " + igelec + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_edb, igelec));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Electro DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_edb_error);
return;
}
break;
@ -226,9 +227,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_PHYSICAL_ADD_HURT, phys);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_PHYSICAL_ADD_HURT));
float igphys = phys * 100;
CommandHandler.sendMessage(sender, "Physical DMG Bonus set to " + igphys + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_physdb, igphys));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Physical DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_physdb_error);
return;
}
break;
@ -240,9 +241,9 @@ public final class SetStatsCommand implements CommandHandler {
entity.setFightProperty(FightProperty.FIGHT_PROP_GRASS_ADD_HURT, dend);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_GRASS_ADD_HURT));
float igdend = dend * 100;
CommandHandler.sendMessage(sender, "Dendro DMG Bonus set to " + igdend + "%");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().SetStats_set_ddb, igdend));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid Dendro DMG Bonus value.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetStats_set_ddb_error);
return;
}
break;

View File

@ -1,5 +1,6 @@
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;
@ -14,19 +15,19 @@ public final class SetWorldLevelCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return; // TODO: set player's world level from console or other players
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: setworldlevel <level>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetWorldLevel_usage);
return;
}
try {
int level = Integer.parseInt(args.get(0));
if (level > 8 || level < 0) {
sender.dropMessage("World level must be between 0-8");
sender.dropMessage(Grasscutter.getLanguage().SetWorldLevel_world_level_must_between_0_and_8);
return;
}
@ -34,9 +35,9 @@ public final class SetWorldLevelCommand implements CommandHandler {
sender.getWorld().setWorldLevel(level);
sender.setWorldLevel(level);
sender.dropMessage("World level set to " + level + ".");
sender.dropMessage(String.format(Grasscutter.getLanguage().SetWorldLevel_set_world_level, level));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid world level.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SetWorldLevel_invalid_world_level);
}
}
}

View File

@ -1,5 +1,6 @@
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.GameData;
@ -25,12 +26,12 @@ public final class SpawnCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: spawn <entityId> [amount] [level(monster only)]");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Spawn_usage);
return;
}
@ -43,7 +44,7 @@ public final class SpawnCommand implements CommandHandler {
GadgetData gadgetData = GameData.getGadgetDataMap().get(id);
ItemData itemData = GameData.getItemDataMap().get(id);
if (monsterData == null && gadgetData == null && itemData == null) {
CommandHandler.sendMessage(sender, "Invalid entity id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id);
return;
}
@ -78,9 +79,9 @@ public final class SpawnCommand implements CommandHandler {
sender.getScene().addEntity(entity);
}
CommandHandler.sendMessage(sender, String.format("Spawned %s of %s.", amount, id));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Spawn_message, amount, id));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid entity ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id);
}
}

View File

@ -13,9 +13,9 @@ public final class StopCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
CommandHandler.sendMessage(null, "Server shutting down...");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Stop_message);
for (Player p : Grasscutter.getGameServer().getPlayers().values()) {
CommandHandler.sendMessage(p, "Server shutting down...");
CommandHandler.sendMessage(p, Grasscutter.getLanguage().Stop_message);
}
System.exit(1);

View File

@ -1,5 +1,6 @@
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.def.AvatarSkillDepotData;
@ -18,23 +19,23 @@ public final class TalentCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1){
CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
CommandHandler.sendMessage(sender, "Another way to set talent level: /talent <n or e or q> <value>");
CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
return;
}
String cmdSwitch = args.get(0);
switch (cmdSwitch) {
default:
CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
CommandHandler.sendMessage(sender, "Another way to set talent level: /talent <n or e or q> <value>");
CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
return;
case "set":
try {
@ -49,12 +50,12 @@ public final class TalentCommand implements CommandHandler {
int currentLevelE = avatar.getSkillLevelMap().get(skillIdE);
int currentLevelQ = avatar.getSkillLevelMap().get(skillIdQ);
if (args.size() < 2){
CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
return;
}
if (nextLevel >= 16){
CommandHandler.sendMessage(sender, "Invalid talent level. Level should be lower than 16");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_lower_16);
return;
}
if (skillId == skillIdNorAtk){
@ -65,7 +66,7 @@ public final class TalentCommand implements CommandHandler {
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel));
CommandHandler.sendMessage(sender, "Set talent Normal ATK to " + nextLevel + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_atk, nextLevel));
}
if (skillId == skillIdE){
// Upgrade skill
@ -75,7 +76,7 @@ public final class TalentCommand implements CommandHandler {
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdE, currentLevelE, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdE, currentLevelE, nextLevel));
CommandHandler.sendMessage(sender, "Set talent E to " + nextLevel + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_e, nextLevel));
}
if (skillId == skillIdQ){
// Upgrade skill
@ -85,11 +86,11 @@ public final class TalentCommand implements CommandHandler {
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdQ, currentLevelQ, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdQ, currentLevelQ, nextLevel));
CommandHandler.sendMessage(sender, "Set talent Q to " + nextLevel + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_q, nextLevel));
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid skill ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_skill_id);
return;
}
@ -114,11 +115,11 @@ public final class TalentCommand implements CommandHandler {
int nextLevel = Integer.parseInt(args.get(1));
int currentLevel = avatar.getSkillLevelMap().get(skillId);
if (args.size() < 1){
CommandHandler.sendMessage(sender, "To set talent level: /talent <n or e or q> <value>");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
return;
}
if (nextLevel >= 16){
CommandHandler.sendMessage(sender, "Invalid talent level. Level should be lower than 16");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_lower_16);
return;
}
// Upgrade skill
@ -127,9 +128,9 @@ public final class TalentCommand implements CommandHandler {
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillId, currentLevel, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillId, currentLevel, nextLevel));
CommandHandler.sendMessage(sender, "Set this talent to " + nextLevel + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_set_this, nextLevel));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid talent level.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_talent_level);
return;
}
break;
@ -140,9 +141,9 @@ public final class TalentCommand implements CommandHandler {
int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1);
int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill();
CommandHandler.sendMessage(sender, "Normal Attack ID " + skillIdNorAtk + ".");
CommandHandler.sendMessage(sender, "E skill ID " + skillIdE + ".");
CommandHandler.sendMessage(sender, "Q skill ID " + skillIdQ + ".");
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_normal_attack_id, skillIdNorAtk));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_e_skill_id, skillIdE));
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Talent_q_skill_id, skillIdQ));
break;
}
}

View File

@ -1,5 +1,6 @@
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;
@ -13,12 +14,12 @@ public final class TeleportAllCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (!sender.getWorld().isMultiplayer()) {
CommandHandler.sendMessage(sender, "You only can use this command in MP mode.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().TeleportAll_message);
return;
}

View File

@ -16,20 +16,20 @@ public final class TeleportCommand implements CommandHandler {
public void execute(Player sender, List<String> args) {
int target;
if (args.size() < (sender == null ? 4 : 3)) {
CommandHandler.sendMessage(sender, sender == null ? "Usage: /tp @<player id> <x> <y> <z> [scene id]" :
"Usage: /tp [@<player id>] <x> <y> <z> [scene id]");
CommandHandler.sendMessage(sender, sender == null ? Grasscutter.getLanguage().Teleport_usage_server :
Grasscutter.getLanguage().Teleport_usage);
return;
}
if (args.get(0).startsWith("@")) {
try {
target = Integer.parseInt(args.get(0).substring(1));
} catch (NumberFormatException e) {
CommandHandler.sendMessage(sender, "Invalid player id.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
}
} else {
if (sender == null) {
CommandHandler.sendMessage(null, "You must specify a player id.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Teleport_specify_player_id);
return;
}
target = sender.getUid();
@ -37,7 +37,7 @@ public final class TeleportCommand implements CommandHandler {
Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, "Player not found or offline.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline);
return;
}
args = args.subList(args.get(0).startsWith("@") ? 1 : 0, args.size());
@ -80,12 +80,12 @@ public final class TeleportCommand implements CommandHandler {
Position target_pos = new Position(x, y, z);
boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, target_pos);
if (!result) {
CommandHandler.sendMessage(sender, "Invalid position.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
} else {
CommandHandler.sendMessage(sender, "Teleported " + targetPlayer.getNickname() + " to " + x + "," + y + "," + z + " in scene " + sceneId);
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Teleport_message, targetPlayer.getNickname(), x, y, z, sceneId));
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid position.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
}
}
}

View File

@ -1,5 +1,6 @@
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;
@ -15,12 +16,12 @@ public final class WeatherCommand implements CommandHandler {
@Override
public void execute(Player sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game);
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: weather <weatherId> [climateId]");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_usage);
return;
}
@ -33,9 +34,9 @@ public final class WeatherCommand implements CommandHandler {
sender.getScene().setWeather(weatherId);
sender.getScene().setClimate(climate);
sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
CommandHandler.sendMessage(sender, "Changed weather to " + weatherId + " with climate " + climateId);
CommandHandler.sendMessage(sender, String.format(Grasscutter.getLanguage().Weather_message, weatherId, climateId));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid ID.");
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id);
}
}
}

View File

@ -32,7 +32,7 @@ public final class DispatchHttpJsonHandler implements HttpContextHandler {
public void handle(Request req, Response res) throws IOException {
// Checking for ALL here isn't required as when ALL is enabled enableDevLogging() gets enabled
if(Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING && Arrays.stream(missingRoutes).anyMatch(x -> x == req.baseUrl())) {
Grasscutter.getLogger().info(String.format("[Dispatch] Client %s %s request: %s", req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING ? "(MISSING)" : ""));
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_request, req.ip(), req.method(), req.baseUrl()) + (Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING ? "(MISSING)" : ""));
}
res.send(response);
}

View File

@ -211,21 +211,21 @@ public final class DispatchServer {
sslContextFactory.setKeyStorePassword(Grasscutter.getConfig().getDispatchOptions().KeystorePassword);
} catch (Exception e) {
e.printStackTrace();
Grasscutter.getLogger().warn("[Dispatch] Unable to load keystore. Trying default keystore password...");
Grasscutter.getLogger().warn(Grasscutter.getLanguage().Not_load_keystore);
try {
sslContextFactory.setKeyStorePath(keystoreFile.getPath());
sslContextFactory.setKeyStorePassword("123456");
Grasscutter.getLogger().warn("[Dispatch] The default keystore password was loaded successfully. Please consider setting the password to 123456 in config.json.");
Grasscutter.getLogger().warn(Grasscutter.getLanguage().Use_default_keystore);
} catch (Exception e2) {
Grasscutter.getLogger().warn("[Dispatch] Error while loading keystore!");
Grasscutter.getLogger().warn(Grasscutter.getLanguage().Load_keystore_error);
e2.printStackTrace();
}
}
serverConnector = new ServerConnector(server, sslContextFactory);
} else {
Grasscutter.getLogger().warn("[Dispatch] No SSL cert found! Falling back to HTTP server.");
Grasscutter.getLogger().warn(Grasscutter.getLanguage().Not_find_ssl_cert);
Grasscutter.getConfig().getDispatchOptions().UseSSL = false;
serverConnector = new ServerConnector(server);
@ -245,11 +245,11 @@ public final class DispatchServer {
}
});
httpServer.get("/", (req, res) -> res.send("Welcome to Grasscutter"));
httpServer.get("/", (req, res) -> res.send(Grasscutter.getLanguage().Welcome));
httpServer.raw().error(404, ctx -> {
if(Grasscutter.getConfig().DebugMode == ServerDebugMode.MISSING) {
Grasscutter.getLogger().info(String.format("[Dispatch] Potential unhandled %s request: %s", ctx.method(), ctx.url()));
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Potential_unhandled_request, ctx.method(), ctx.url()));
}
ctx.contentType("text/html");
ctx.result("<!doctype html><html lang=\"en\"><body><img src=\"https://http.cat/404\" /></body></html>"); // I'm like 70% sure this won't break anything.
@ -327,7 +327,7 @@ public final class DispatchServer {
return;
}
LoginResultJson responseData = new LoginResultJson();
Grasscutter.getLogger().info(String.format("[Dispatch] Client %s is trying to log in via token", req.ip()));
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_login_token, req.ip()));
// Login
Account account = DatabaseHelper.getAccountById(requestData.uid);
@ -335,17 +335,17 @@ public final class DispatchServer {
// Test
if (account == null || !account.getSessionKey().equals(requestData.token)) {
responseData.retcode = -111;
responseData.message = "Game account cache information error";
responseData.message = Grasscutter.getLanguage().Game_account_cache_error;
Grasscutter.getLogger()
.info(String.format("[Dispatch] Client %s failed to log in via token", req.ip()));
.info(String.format(Grasscutter.getLanguage().Client_token_login_failed, req.ip()));
} else {
responseData.message = "OK";
responseData.data.account.uid = requestData.uid;
responseData.data.account.token = requestData.token;
responseData.data.account.email = account.getEmail();
Grasscutter.getLogger().info(String.format("[Dispatch] Client %s logged in via token as %s",
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_login_in_token,
req.ip(), responseData.data.account.uid));
}
@ -376,10 +376,10 @@ public final class DispatchServer {
// Test
if (account == null || !account.getSessionKey().equals(loginData.token)) {
responseData.retcode = -201;
responseData.message = "Wrong session key.";
responseData.message = Grasscutter.getLanguage().Wrong_session_key;
Grasscutter.getLogger().info(
String.format("[Dispatch] Client %s failed to exchange combo token", req.ip()));
String.format(Grasscutter.getLanguage().Client_failed_exchange_combo_token, req.ip()));
} else {
responseData.message = "OK";
responseData.data.open_id = loginData.uid;
@ -387,7 +387,7 @@ public final class DispatchServer {
responseData.data.combo_token = account.generateLoginToken();
Grasscutter.getLogger().info(
String.format("[Dispatch] Client %s succeed to exchange combo token", req.ip()));
String.format(Grasscutter.getLanguage().Client_exchange_combo_token, req.ip()));
}
res.send(responseData);
@ -453,7 +453,7 @@ public final class DispatchServer {
httpServer.get("/gcstatic/*", new StaticFileHandler());
httpServer.listen(Grasscutter.getConfig().getDispatchOptions().Port);
Grasscutter.getLogger().info("[Dispatch] Dispatch server started on port " + httpServer.raw().port());
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Dispatch_start_server_port, httpServer.raw().port()));
}
private Map<String, String> parseQueryString(String qs) {

View File

@ -52,21 +52,21 @@ public class DefaultAuthenticationHandler implements AuthenticationHandler {
responseData.data.account.email = account.getEmail();
Grasscutter.getLogger()
.info(String.format("[Dispatch] Client %s failed to log in: Account %s created",
.info(String.format(Grasscutter.getLanguage().Client_failed_login_account_create,
req.ip(), responseData.data.account.uid));
} else {
responseData.retcode = -201;
responseData.message = "Username not found, create failed.";
responseData.message = Grasscutter.getLanguage().Username_not_found_create_failed;
Grasscutter.getLogger().info(String.format(
"[Dispatch] Client %s failed to log in: Account create failed", req.ip()));
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_failed_login_account_create_failed
, req.ip()));
}
} else {
responseData.retcode = -201;
responseData.message = "Username not found.";
responseData.message = Grasscutter.getLanguage().Username_not_found;
Grasscutter.getLogger().info(String
.format("[Dispatch] Client %s failed to log in: Account no found", req.ip()));
.format(Grasscutter.getLanguage().Client_failed_login_account_no_found, req.ip()));
}
} else {
// Account was found, log the player in
@ -75,7 +75,7 @@ public class DefaultAuthenticationHandler implements AuthenticationHandler {
responseData.data.account.token = account.generateSessionKey();
responseData.data.account.email = account.getEmail();
Grasscutter.getLogger().info(String.format("[Dispatch] Client %s logged in as %s", req.ip(),
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_login, req.ip(),
responseData.data.account.uid));
}

View File

@ -72,7 +72,7 @@ public final class GameServer extends KcpServer {
try {
onTick();
} catch (Exception e) {
Grasscutter.getLogger().error("An error occurred during game update.", e);
Grasscutter.getLogger().error(Grasscutter.getLanguage().An_error_occurred_during_game_update, e);
}
}
}, new Date(), 1000L);
@ -207,8 +207,8 @@ public final class GameServer extends KcpServer {
@Override
public void onStartFinish() {
Grasscutter.getLogger().info("Grasscutter is FREE software. If you have paid for this, you may have been scammed. Homepage: https://github.com/Grasscutters/Grasscutter");
Grasscutter.getLogger().info("Game Server started on port " + address.getPort());
Grasscutter.getLogger().info(Grasscutter.getLanguage().grasscutter_is_free);
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Game_start_port, address.getPort()));
ServerStartEvent event = new ServerStartEvent(ServerEvent.Type.GAME, OffsetDateTime.now()); event.call();
}

View File

@ -113,12 +113,12 @@ public class GameSession extends KcpChannel {
@Override
protected void onConnect() {
Grasscutter.getLogger().info("Client connected from " + getAddress().getHostString().toLowerCase());
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_connect, getAddress().getHostString().toLowerCase()));
}
@Override
protected synchronized void onDisconnect() { // Synchronize so we dont add character at the same time
Grasscutter.getLogger().info("Client disconnected from " + getAddress().getHostString().toLowerCase());
Grasscutter.getLogger().info(String.format(Grasscutter.getLanguage().Client_disconnect, getAddress().getHostString().toLowerCase()));
// Set state so no more packets can be handled
this.setState(SessionState.INACTIVE);