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

Merge branch 'development' into development

parents 79babcc5 38fd7bb7
...@@ -67,4 +67,4 @@ mongod.exe ...@@ -67,4 +67,4 @@ mongod.exe
/*.sh /*.sh
language/ language/
languages/ languages/
gacha_mappings.js gacha-mapping.js
\ No newline at end of file
...@@ -28,7 +28,7 @@ plugins { ...@@ -28,7 +28,7 @@ plugins {
// Eclipse Support // Eclipse Support
id 'eclipse' id 'eclipse'
// Intelij Support // IntelliJ Support
id 'idea' id 'idea'
// Maven // Maven
......
[
{
"expId": 301,
"expeditionRewardDataList": [
{
"hourTime": 4,
"expeditionRewardData": [
{
"itemId": 202,
"minCount": 625,
"maxCount": 625
}
]
},
{
"hourTime": 8,
"expeditionRewardData": [
{
"itemId": 202,
"minCount": 1575,
"maxCount": 1575
}
]
},
{
"hourTime": 12,
"expeditionRewardData": [
{
"itemId": 202,
"minCount": 2500,
"maxCount": 2500
}
]
},
{
"hourTime": 20,
"expeditionRewardData": [
{
"itemId": 202,
"minCount": 5000,
"maxCount": 5000
}
]
}
]
},
{
"expId": 305,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100064,
"minCount": 1,
"maxCount": 1
}, {
"itemId": 101210,
"minCount": 1,
"maxCount": 1
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100064,
"minCount": 2,
"maxCount": 4
}, {
"itemId": 101210,
"minCount": 2,
"maxCount": 4
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100064,
"minCount": 4,
"maxCount": 6
}, {
"itemId": 101210,
"minCount": 4,
"maxCount": 6
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100064,
"minCount": 8,
"maxCount": 12
}, {
"itemId": 101210,
"minCount": 8,
"maxCount": 12
}
]
}
]
}
]
\ No newline at end of file
...@@ -6,7 +6,6 @@ import emu.grasscutter.Grasscutter.ServerRunMode; ...@@ -6,7 +6,6 @@ import emu.grasscutter.Grasscutter.ServerRunMode;
import emu.grasscutter.game.mail.Mail; import emu.grasscutter.game.mail.Mail;
public final class Config { public final class Config {
public String DatabaseUrl = "mongodb://localhost:27017"; public String DatabaseUrl = "mongodb://localhost:27017";
public String DatabaseCollection = "grasscutter"; public String DatabaseCollection = "grasscutter";
...@@ -41,6 +40,8 @@ public final class Config { ...@@ -41,6 +40,8 @@ public final class Config {
public String KeystorePassword = "123456"; public String KeystorePassword = "123456";
public Boolean UseSSL = true; public Boolean UseSSL = true;
public Boolean FrontHTTPS = true; public Boolean FrontHTTPS = true;
public Boolean CORS = false;
public String[] CORSAllowedOrigins = new String[] { "*" };
public boolean AutomaticallyCreateAccounts = false; public boolean AutomaticallyCreateAccounts = false;
public String[] defaultPermissions = new String[] { "" }; public String[] defaultPermissions = new String[] { "" };
...@@ -80,6 +81,10 @@ public final class Config { ...@@ -80,6 +81,10 @@ public final class Config {
public boolean WatchGacha = false; public boolean WatchGacha = false;
public String ServerNickname = "Server"; public String ServerNickname = "Server";
public int ServerAvatarId = 10000007; public int ServerAvatarId = 10000007;
public int ServerNameCardId = 210001;
public int ServerLevel = 1;
public int ServerWorldLevel = 1;
public String ServerSignature = "Server Signature";
public int[] WelcomeEmotes = {2007, 1002, 4010}; public int[] WelcomeEmotes = {2007, 1002, 4010};
public String WelcomeMotd = "Welcome to Grasscutter emu"; public String WelcomeMotd = "Welcome to Grasscutter emu";
public String WelcomeMailTitle = "Welcome to Grasscutter!"; public String WelcomeMailTitle = "Welcome to Grasscutter!";
......
...@@ -13,7 +13,11 @@ public final class GameConstants { ...@@ -13,7 +13,11 @@ public final class GameConstants {
public static final int MAIN_CHARACTER_FEMALE = 10000007; public static final int MAIN_CHARACTER_FEMALE = 10000007;
public static final String SERVER_AVATAR_NAME = Grasscutter.getConfig().getGameServerOptions().ServerNickname; public static final String SERVER_AVATAR_NAME = Grasscutter.getConfig().getGameServerOptions().ServerNickname;
public static final int SERVER_AVATAR_ID = Grasscutter.getConfig().getGameServerOptions().ServerAvatarId; public static final int SERVER_AVATAR_ID = Grasscutter.getConfig().getGameServerOptions().ServerAvatarId;
public static final String SERVER_SIGNATURE = Grasscutter.getConfig().getGameServerOptions().ServerSignature;
public static final Position START_POSITION = new Position(2747, 194, -1719); public static final Position START_POSITION = new Position(2747, 194, -1719);
public static final int SERVER_NAMECARD_ID = Grasscutter.getConfig().getGameServerOptions().ServerNameCardId;
public static final int SERVER_LEVEL = Grasscutter.getConfig().getGameServerOptions().ServerLevel;
public static final int SERVER_WORLD_LEVEL = Grasscutter.getConfig().getGameServerOptions().ServerWorldLevel;
public static final int MAX_FRIENDS = 45; public static final int MAX_FRIENDS = 45;
public static final int MAX_FRIEND_REQUESTS = 50; public static final int MAX_FRIEND_REQUESTS = 50;
......
...@@ -4,9 +4,7 @@ import java.io.File; ...@@ -4,9 +4,7 @@ import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOError; import java.io.IOError;
import java.net.InetSocketAddress;
import java.util.Calendar; import java.util.Calendar;
import java.util.Locale;
import emu.grasscutter.command.CommandMap; import emu.grasscutter.command.CommandMap;
import emu.grasscutter.plugin.PluginManager; import emu.grasscutter.plugin.PluginManager;
...@@ -28,24 +26,25 @@ import com.google.gson.GsonBuilder; ...@@ -28,24 +26,25 @@ import com.google.gson.GsonBuilder;
import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.Logger;
import emu.grasscutter.data.ResourceLoader; import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.database.DatabaseManager; import emu.grasscutter.database.DatabaseManager;
import emu.grasscutter.languages.CNLanguage; import emu.grasscutter.utils.Language;
import emu.grasscutter.languages.Language;
import emu.grasscutter.server.dispatch.DispatchServer; import emu.grasscutter.server.dispatch.DispatchServer;
import emu.grasscutter.server.game.GameServer; import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.tools.Tools; import emu.grasscutter.tools.Tools;
import emu.grasscutter.utils.Crypto; import emu.grasscutter.utils.Crypto;
import static emu.grasscutter.utils.Language.translate;
public final class Grasscutter { public final class Grasscutter {
private static final Logger log = (Logger) LoggerFactory.getLogger(Grasscutter.class); private static final Logger log = (Logger) LoggerFactory.getLogger(Grasscutter.class);
private static Config config;
private static LineReader consoleLineReader = null; private static LineReader consoleLineReader = null;
private static Config config;
private static Language language; private static Language language;
private static CNLanguage cn_language;
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static final File configFile = new File("./config.json"); private static final File configFile = new File("./config.json");
private static int day; // Current day of week private static int day; // Current day of week.
private static DispatchServer dispatchServer; private static DispatchServer dispatchServer;
private static GameServer gameServer; private static GameServer gameServer;
...@@ -60,7 +59,7 @@ public final class Grasscutter { ...@@ -60,7 +59,7 @@ public final class Grasscutter {
// Load server configuration. // Load server configuration.
Grasscutter.loadConfig(); Grasscutter.loadConfig();
// Load Language // Load translation files.
Grasscutter.loadLanguage(); Grasscutter.loadLanguage();
// Check server structure. // Check server structure.
...@@ -68,21 +67,26 @@ public final class Grasscutter { ...@@ -68,21 +67,26 @@ public final class Grasscutter {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
Crypto.loadKeys(); Crypto.loadKeys(); // Load keys from buffers.
// Parse arguments.
boolean exitEarly = false;
for (String arg : args) { for (String arg : args) {
switch (arg.toLowerCase()) { switch (arg.toLowerCase()) {
case "-handbook" -> { case "-handbook" -> {
Tools.createGmHandbook(); return; Tools.createGmHandbook(); exitEarly = true;
} }
case "-gachamap" -> { case "-gachamap" -> {
Tools.createGachaMapping("./gacha_mappings.js"); return; Tools.createGachaMapping("./gacha-mapping.js"); exitEarly = true;
} }
} }
} }
// Exit early if argument sets it.
if(exitEarly) System.exit(0);
// Initialize server. // Initialize server.
Grasscutter.getLogger().info(language.Starting_Grasscutter); Grasscutter.getLogger().info(translate("messages.status.starting"));
// Load all resources. // Load all resources.
Grasscutter.updateDayOfWeek(); Grasscutter.updateDayOfWeek();
...@@ -94,7 +98,7 @@ public final class Grasscutter { ...@@ -94,7 +98,7 @@ public final class Grasscutter {
// Create server instances. // Create server instances.
dispatchServer = new DispatchServer(); dispatchServer = new DispatchServer();
gameServer = new GameServer(new InetSocketAddress(getConfig().getGameServerOptions().Ip, getConfig().getGameServerOptions().Port)); gameServer = new GameServer();
// Create a server hook instance with both servers. // Create a server hook instance with both servers.
new ServerHook(gameServer, dispatchServer); new ServerHook(gameServer, dispatchServer);
// Create plugin manager instance. // Create plugin manager instance.
...@@ -109,9 +113,9 @@ public final class Grasscutter { ...@@ -109,9 +113,9 @@ public final class Grasscutter {
} else if (getConfig().RunMode == ServerRunMode.GAME_ONLY) { } else if (getConfig().RunMode == ServerRunMode.GAME_ONLY) {
gameServer.start(); gameServer.start();
} else { } else {
getLogger().error(language.Invalid_server_run_mode + " " + getConfig().RunMode); getLogger().error(translate("messages.status.run_mode_error", getConfig().RunMode));
getLogger().error(language.Server_run_mode); getLogger().error(translate("messages.status.run_mode_help"));
getLogger().error(language.Shutting_down); getLogger().error(translate("messages.status.shutdown"));
System.exit(1); System.exit(1);
} }
...@@ -144,41 +148,8 @@ public final class Grasscutter { ...@@ -144,41 +148,8 @@ public final class Grasscutter {
} }
public static void loadLanguage() { public static void loadLanguage() {
try (FileReader file = new FileReader(String.format("%s%s.json", getConfig().LANGUAGE_FOLDER, Grasscutter.config.LocaleLanguage))) { var locale = config.LocaleLanguage;
language = gson.fromJson(file, Language.class); language = Language.getLanguage(locale.toLanguageTag());
} catch (Exception e) {
Grasscutter.language = new Language();
Grasscutter.cn_language = new CNLanguage();
Grasscutter.config.LocaleLanguage = Locale.getDefault();
saveConfig();
try {
File folder = new File("./languages");
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("./languages/" + Locale.US + ".json")) {
file.write(gson.toJson(language));
} catch (Exception ee) {
Grasscutter.getLogger().error("Unable to create language file.");
}
try (FileWriter file = new FileWriter("./languages/" + Locale.SIMPLIFIED_CHINESE + ".json")) {
file.write(gson.toJson(cn_language));
} catch (Exception ee) {
Grasscutter.getLogger().error("无法创建简体中文语言文件。");
}
// try again
try (FileReader file = new FileReader(String.format("%s%s.json", getConfig().LANGUAGE_FOLDER, Grasscutter.config.LocaleLanguage))) {
language = gson.fromJson(file, Language.class);
} catch (Exception ee) {
Grasscutter.getLogger().error("Unable to load " + Grasscutter.config.LocaleLanguage + ".json");
}
}
} }
public static void saveConfig() { public static void saveConfig() {
...@@ -192,11 +163,11 @@ public final class Grasscutter { ...@@ -192,11 +163,11 @@ public final class Grasscutter {
public static void startConsole() { public static void startConsole() {
// Console should not start in dispatch only mode. // Console should not start in dispatch only mode.
if (getConfig().RunMode == ServerRunMode.DISPATCH_ONLY) { if (getConfig().RunMode == ServerRunMode.DISPATCH_ONLY) {
getLogger().info(language.Dispatch_mode_not_support_command); getLogger().info(translate("messages.dispatch.no_commands_error"));
return; return;
} }
getLogger().info(language.Start_done); getLogger().info(translate("messages.status.done"));
String input = null; String input = null;
boolean isLastInterrupted = false; boolean isLastInterrupted = false;
while (true) { while (true) {
...@@ -222,7 +193,7 @@ public final class Grasscutter { ...@@ -222,7 +193,7 @@ public final class Grasscutter {
try { try {
CommandMap.getInstance().invoke(null, null, input); CommandMap.getInstance().invoke(null, null, input);
} catch (Exception e) { } catch (Exception e) {
Grasscutter.getLogger().error(language.Command_error, e); Grasscutter.getLogger().error(translate("messages.game.command_error"), e);
} }
} }
} }
......
...@@ -8,6 +8,8 @@ import org.reflections.Reflections; ...@@ -8,6 +8,8 @@ import org.reflections.Reflections;
import java.util.*; import java.util.*;
import static emu.grasscutter.utils.Language.translate;
@SuppressWarnings({"UnusedReturnValue", "unused"}) @SuppressWarnings({"UnusedReturnValue", "unused"})
public final class CommandMap { public final class CommandMap {
private final Map<String, CommandHandler> commands = new HashMap<>(); private final Map<String, CommandHandler> commands = new HashMap<>();
...@@ -109,7 +111,7 @@ public final class CommandMap { ...@@ -109,7 +111,7 @@ public final class CommandMap {
public void invoke(Player player, Player targetPlayer, String rawMessage) { public void invoke(Player player, Player targetPlayer, String rawMessage) {
rawMessage = rawMessage.trim(); rawMessage = rawMessage.trim();
if (rawMessage.length() == 0) { if (rawMessage.length() == 0) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().No_command_specified); CommandHandler.sendMessage(player, translate("commands.generic.not_specified"));
return; return;
} }
...@@ -118,11 +120,12 @@ public final class CommandMap { ...@@ -118,11 +120,12 @@ public final class CommandMap {
List<String> args = new LinkedList<>(Arrays.asList(split)); List<String> args = new LinkedList<>(Arrays.asList(split));
String label = args.remove(0); String label = args.remove(0);
String playerId = (player == null) ? consoleId : player.getAccount().getId(); String playerId = (player == null) ? consoleId : player.getAccount().getId();
// Check for special cases - currently only target command
// Check for special cases - currently only target command.
String targetUidStr = null; String targetUidStr = null;
if (label.startsWith("@")) { // @[UID] if (label.startsWith("@")) { // @[UID]
targetUidStr = label.substring(1); targetUidStr = label.substring(1);
} else if (label.equalsIgnoreCase("target")) { // target [[@]UID] } else if (label.equalsIgnoreCase("target")) { // target [[@]UID]
if (args.size() > 0) { if (args.size() > 0) {
targetUidStr = args.get(0); targetUidStr = args.get(0);
if (targetUidStr.startsWith("@")) { if (targetUidStr.startsWith("@")) {
...@@ -133,68 +136,64 @@ public final class CommandMap { ...@@ -133,68 +136,64 @@ public final class CommandMap {
} }
} }
if (targetUidStr != null) { if (targetUidStr != null) {
if (targetUidStr.equals("")) { // Clears default targetPlayer if (targetUidStr.equals("")) { // Clears the default targetPlayer.
targetPlayerIds.remove(playerId); targetPlayerIds.remove(playerId);
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Target_cleared); CommandHandler.sendMessage(player, translate("commands.execution.clear_target"));
return; } else { // Sets default targetPlayer to the UID provided.
} else { // Sets default targetPlayer to the UID given
try { try {
int uid = Integer.parseInt(targetUidStr); int uid = Integer.parseInt(targetUidStr);
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid); targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline); CommandHandler.sendMessage(player, translate("commands.generic.execution.player_exist_offline_error"));
} else { } else {
targetPlayerIds.put(playerId, uid); targetPlayerIds.put(playerId, uid);
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Target_set.replace("{uid}", targetUidStr)); CommandHandler.sendMessage(player, translate("commands.execution.set_target", targetUidStr));
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Invalid_UID); CommandHandler.sendMessage(player, translate("commands.execution.uid_error"));
} }
return;
} }
return;
} }
// Get command handler. // Get command handler.
CommandHandler handler = this.commands.get(label); CommandHandler handler = this.commands.get(label);
if (handler == null) { if (handler == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Unknown_command + label); CommandHandler.sendMessage(player, translate("commands.generic.unknown_command", label));
return; return;
} }
// If any @UID argument is present, override targetPlayer with it // If any @UID argument is present, override targetPlayer with it.
for (int i = 0; i < args.size(); i++) { for (int i = 0; i < args.size(); i++) {
String arg = args.get(i); String arg = args.get(i);
if (!arg.startsWith("@")) { if (arg.startsWith("@")) {
continue;
} else {
arg = args.remove(i).substring(1); arg = args.remove(i).substring(1);
try { try {
int uid = Integer.parseInt(arg); int uid = Integer.parseInt(arg);
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid); targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline); CommandHandler.sendMessage(player, translate("commands.generic.execution.player_exist_offline_error"));
return; return;
} }
break; break;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Invalid_UID); CommandHandler.sendMessage(player, translate("commands.execution.uid_error"));
return; return;
} }
} }
} }
// If there's still no targetPlayer at this point, use previously-set target // If there's still no targetPlayer at this point, use previously-set target
if (targetPlayer == null) { if (targetPlayer == null) {
if (targetPlayerIds.containsKey(playerId)) { if (targetPlayerIds.containsKey(playerId)) {
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(targetPlayerIds.get(playerId)); // We check every time in case the target goes offline after being targeted targetPlayer = Grasscutter.getGameServer().getPlayerByUid(targetPlayerIds.get(playerId)); // We check every time in case the target goes offline after being targeted
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline); CommandHandler.sendMessage(player, translate("commands.generic.execution.player_exist_offline_error"));
return; return;
} }
} else { } else {
// If there's still no targetPlayer at this point, use local player // If there's still no targetPlayer at this point, use executor.
if (targetPlayer == null) { targetPlayer = player;
targetPlayer = player;
}
} }
} }
...@@ -205,12 +204,12 @@ public final class CommandMap { ...@@ -205,12 +204,12 @@ public final class CommandMap {
Account account = player.getAccount(); Account account = player.getAccount();
if (player != targetPlayer) { // Additional permission required for targeting another player if (player != targetPlayer) { // Additional permission required for targeting another player
if (!permissionNodeTargeted.isEmpty() && !account.hasPermission(permissionNodeTargeted)) { if (!permissionNodeTargeted.isEmpty() && !account.hasPermission(permissionNodeTargeted)) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().You_not_permission_run_command); CommandHandler.sendMessage(player, translate("commands.generic.permission_error"));
return; return;
} }
} }
if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) { if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().You_not_permission_run_command); CommandHandler.sendMessage(player, translate("commands.generic.permission_error"));
return; return;
} }
} }
...@@ -220,10 +219,8 @@ public final class CommandMap { ...@@ -220,10 +219,8 @@ public final class CommandMap {
final Player targetPlayerF = targetPlayer; // Is there a better way to do this? final Player targetPlayerF = targetPlayer; // Is there a better way to do this?
Runnable runnable = () -> handler.execute(player, targetPlayerF, args); Runnable runnable = () -> handler.execute(player, targetPlayerF, args);
if(threading) { if(threading) {
Thread command = new Thread(runnable); new Thread(runnable).start();
command.start(); } else {
}
else {
runnable.run(); runnable.run();
} }
} }
......
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.database.DatabaseHelper;
...@@ -8,18 +7,20 @@ import emu.grasscutter.game.player.Player; ...@@ -8,18 +7,20 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "account", usage = "account <create|delete> <username> [uid]", description = "Modify user accounts") @Command(label = "account", usage = "account <create|delete> <username> [uid]", description = "Modify user accounts")
public final class AccountCommand implements CommandHandler { public final class AccountCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender != null) { if (sender != null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().This_command_can_only_run_from_console); CommandHandler.sendMessage(sender, translate("commands.generic.console_execute_error"));
return; return;
} }
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_command_usage); CommandHandler.sendMessage(null, translate("commands.account.command_usage"));
return; return;
} }
...@@ -28,7 +29,7 @@ public final class AccountCommand implements CommandHandler { ...@@ -28,7 +29,7 @@ public final class AccountCommand implements CommandHandler {
switch (action) { switch (action) {
default: default:
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_command_usage); CommandHandler.sendMessage(null, translate("commands.account.command_usage"));
return; return;
case "create": case "create":
int uid = 0; int uid = 0;
...@@ -36,27 +37,27 @@ public final class AccountCommand implements CommandHandler { ...@@ -36,27 +37,27 @@ public final class AccountCommand implements CommandHandler {
try { try {
uid = Integer.parseInt(args.get(2)); uid = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Invalid_UID); CommandHandler.sendMessage(null, translate("commands.account.invalid"));
return; return;
} }
} }
emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid); emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid);
if (account == null) { if (account == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_exists); CommandHandler.sendMessage(null, translate("commands.account.exists"));
return; return;
} else { } else {
account.addPermission("*"); account.addPermission("*");
account.save(); // Save account to database. account.save(); // Save account to database.
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_create_UID.replace("{uid}", Integer.toString(account.getPlayerUid()))); CommandHandler.sendMessage(null, translate("commands.account.create", Integer.toString(account.getPlayerUid())));
} }
return; return;
case "delete": case "delete":
if (DatabaseHelper.deleteAccount(username)) { if (DatabaseHelper.deleteAccount(username)) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_delete); CommandHandler.sendMessage(null, translate("commands.account.delete"));
} else { } else {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_not_find); CommandHandler.sendMessage(null, translate("commands.account.no_account"));
} }
} }
} }
......
...@@ -7,6 +7,8 @@ import emu.grasscutter.game.player.Player; ...@@ -7,6 +7,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "broadcast", usage = "broadcast <message>", @Command(label = "broadcast", usage = "broadcast <message>",
description = "Sends a message to all the players", aliases = {"b"}, permission = "server.broadcast") description = "Sends a message to all the players", aliases = {"b"}, permission = "server.broadcast")
public final class BroadcastCommand implements CommandHandler { public final class BroadcastCommand implements CommandHandler {
...@@ -14,7 +16,7 @@ public final class BroadcastCommand implements CommandHandler { ...@@ -14,7 +16,7 @@ public final class BroadcastCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_command_usage); CommandHandler.sendMessage(sender, translate("commands.broadcast.command_usage"));
return; return;
} }
...@@ -24,6 +26,6 @@ public final class BroadcastCommand implements CommandHandler { ...@@ -24,6 +26,6 @@ public final class BroadcastCommand implements CommandHandler {
CommandHandler.sendMessage(p, message); CommandHandler.sendMessage(p, message);
} }
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_message_sent); CommandHandler.sendMessage(sender, translate("commands.broadcast.message_sent"));
} }
} }
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "changescene", usage = "changescene <scene id>", @Command(label = "changescene", usage = "changescene <scene id>",
description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene") description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene")
public final class ChangeSceneCommand implements CommandHandler { public final class ChangeSceneCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
if (args.size() != 1) { if (args.size() != 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_usage); CommandHandler.sendMessage(sender, translate("commands.changescene.usage"));
return; return;
} }
try { try {
int sceneId = Integer.parseInt(args.get(0)); int sceneId = Integer.parseInt(args.get(0));
if (sceneId == targetPlayer.getSceneId()) { if (sceneId == targetPlayer.getSceneId()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_you_in_that_screen); CommandHandler.sendMessage(sender, translate("commands.changescene.already_in_scene"));
return; return;
} }
boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, targetPlayer.getPos()); boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, targetPlayer.getPos());
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen + sceneId); CommandHandler.sendMessage(sender, translate("commands.changescene.result", Integer.toString(sceneId)));
if (!result) { if (!result) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_not_exist); CommandHandler.sendMessage(sender, translate("commands.changescene.exists_error"));
} }
} catch (Exception e) { } catch (Exception e) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments); CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
} }
} }
} }
...@@ -10,6 +10,8 @@ import emu.grasscutter.game.player.Player; ...@@ -10,6 +10,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "clear", usage = "clear <all|wp|art|mat>", //Merged /clearartifacts and /clearweapons to /clear <args> [uid] @Command(label = "clear", usage = "clear <all|wp|art|mat>", //Merged /clearartifacts and /clearweapons to /clear <args> [uid]
description = "Deletes unequipped unlocked items, including yellow rarity ones from your inventory", description = "Deletes unequipped unlocked items, including yellow rarity ones from your inventory",
aliases = {"clear"}, permission = "player.clearinv") aliases = {"clear"}, permission = "player.clearinv")
...@@ -19,11 +21,11 @@ public final class ClearCommand implements CommandHandler { ...@@ -19,11 +21,11 @@ public final class ClearCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_usage); CommandHandler.sendMessage(sender, translate("commands.clear.command_usage"));
return; return;
} }
Inventory playerInventory = targetPlayer.getInventory(); Inventory playerInventory = targetPlayer.getInventory();
...@@ -35,7 +37,7 @@ public final class ClearCommand implements CommandHandler { ...@@ -35,7 +37,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getItemType() == ItemType.ITEM_WEAPON) .filter(item -> item.getItemType() == ItemType.ITEM_WEAPON)
.filter(item -> !item.isLocked() && !item.isEquipped()) .filter(item -> !item.isLocked() && !item.isEquipped())
.toList(); .toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_weapons.replace("{name}", targetPlayer.getNickname())); CommandHandler.sendMessage(sender, translate("commands.clear.weapons", targetPlayer.getNickname()));
} }
case "art" -> { case "art" -> {
toDelete = playerInventory.getItems().values().stream() toDelete = playerInventory.getItems().values().stream()
...@@ -43,7 +45,7 @@ public final class ClearCommand implements CommandHandler { ...@@ -43,7 +45,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getLevel() == 1 && item.getExp() == 0) .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped()) .filter(item -> !item.isLocked() && !item.isEquipped())
.toList(); .toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname())); CommandHandler.sendMessage(sender, translate("commands.clear.artifacts", targetPlayer.getNickname()));
} }
case "mat" -> { case "mat" -> {
toDelete = playerInventory.getItems().values().stream() toDelete = playerInventory.getItems().values().stream()
...@@ -51,7 +53,7 @@ public final class ClearCommand implements CommandHandler { ...@@ -51,7 +53,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getLevel() == 1 && item.getExp() == 0) .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped()) .filter(item -> !item.isLocked() && !item.isEquipped())
.toList(); .toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname())); CommandHandler.sendMessage(sender, translate("commands.clear.materials", targetPlayer.getNickname()));
} }
case "all" -> { case "all" -> {
toDelete = playerInventory.getItems().values().stream() toDelete = playerInventory.getItems().values().stream()
...@@ -59,34 +61,44 @@ public final class ClearCommand implements CommandHandler { ...@@ -59,34 +61,44 @@ public final class ClearCommand implements CommandHandler {
.filter(item1 -> item1.getLevel() == 1 && item1.getExp() == 0) .filter(item1 -> item1.getLevel() == 1 && item1.getExp() == 0)
.filter(item1 -> !item1.isLocked() && !item1.isEquipped()) .filter(item1 -> !item1.isLocked() && !item1.isEquipped())
.toList(); .toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname())); CommandHandler.sendMessage(sender, translate("commands.clear.artifacts", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
toDelete = playerInventory.getItems().values().stream() toDelete = playerInventory.getItems().values().stream()
.filter(item2 -> item2.getItemType() == ItemType.ITEM_MATERIAL) .filter(item2 -> item2.getItemType() == ItemType.ITEM_MATERIAL)
.filter(item2 -> !item2.isLocked() && !item2.isEquipped()) .filter(item2 -> !item2.isLocked() && !item2.isEquipped())
.toList(); .toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname())); playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.materials", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream() toDelete = playerInventory.getItems().values().stream()
.filter(item3 -> item3.getItemType() == ItemType.ITEM_WEAPON) .filter(item3 -> item3.getItemType() == ItemType.ITEM_WEAPON)
.filter(item3 -> item3.getLevel() == 1 && item3.getExp() == 0) .filter(item3 -> item3.getLevel() == 1 && item3.getExp() == 0)
.filter(item3 -> !item3.isLocked() && !item3.isEquipped()) .filter(item3 -> !item3.isLocked() && !item3.isEquipped())
.toList(); .toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname())); playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.weapons", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream() toDelete = playerInventory.getItems().values().stream()
.filter(item4 -> item4.getItemType() == ItemType.ITEM_FURNITURE) .filter(item4 -> item4.getItemType() == ItemType.ITEM_FURNITURE)
.filter(item4 -> !item4.isLocked() && !item4.isEquipped()) .filter(item4 -> !item4.isLocked() && !item4.isEquipped())
.toList(); .toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_furniture.replace("{name}", targetPlayer.getNickname())); playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.furniture", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream() toDelete = playerInventory.getItems().values().stream()
.filter(item5 -> item5.getItemType() == ItemType.ITEM_DISPLAY) .filter(item5 -> item5.getItemType() == ItemType.ITEM_DISPLAY)
.filter(item5 -> !item5.isLocked() && !item5.isEquipped()) .filter(item5 -> !item5.isLocked() && !item5.isEquipped())
.toList(); .toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_displays.replace("{name}", targetPlayer.getNickname())); playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.displays", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream() toDelete = playerInventory.getItems().values().stream()
.filter(item6 -> item6.getItemType() == ItemType.ITEM_VIRTUAL) .filter(item6 -> item6.getItemType() == ItemType.ITEM_VIRTUAL)
.filter(item6 -> !item6.isLocked() && !item6.isEquipped()) .filter(item6 -> !item6.isLocked() && !item6.isEquipped())
.toList(); .toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_virtuals.replace("{name}", targetPlayer.getNickname())); CommandHandler.sendMessage(sender, translate("commands.clear.virtuals", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_everything.replace("{name}", targetPlayer.getNickname())); CommandHandler.sendMessage(sender, translate("commands.clear.everything", targetPlayer.getNickname()));
} }
} }
......
...@@ -7,39 +7,40 @@ import emu.grasscutter.game.player.Player; ...@@ -7,39 +7,40 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "coop", usage = "coop [host UID]", @Command(label = "coop", usage = "coop [host UID]",
description = "Forces someone to join the world of others", permission = "server.coop") description = "Forces someone to join the world of others", permission = "server.coop")
public final class CoopCommand implements CommandHandler { public final class CoopCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
Player host = sender; Player host = sender;
switch (args.size()) { switch (args.size()) {
case 0: // Summon target to self case 0: // Summon target to self
if (sender == null) { // Console doesn't have a self to summon to CommandHandler.sendMessage(sender, translate("commands.coop.usage"));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Coop_usage); if (sender == null) // Console doesn't have a self to summon to
return; return;
}
break; break;
case 1: // Summon target to argument case 1: // Summon target to argument
try { try {
int hostId = Integer.parseInt(args.get(0)); int hostId = Integer.parseInt(args.get(0));
host = Grasscutter.getGameServer().getPlayerByUid(hostId); host = Grasscutter.getGameServer().getPlayerByUid(hostId);
if (host == null) { if (host == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_is_offline); CommandHandler.sendMessage(sender, translate("commands.execution.player_offline_error"));
return; return;
} }
break; break;
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId); CommandHandler.sendMessage(sender, translate("commands.execution.uid_error"));
return; return;
} }
default: default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Coop_usage); CommandHandler.sendMessage(sender, translate("commands.coop.usage"));
return; return;
} }
...@@ -49,6 +50,6 @@ public final class CoopCommand implements CommandHandler { ...@@ -49,6 +50,6 @@ public final class CoopCommand implements CommandHandler {
} }
host.getServer().getMultiplayerManager().applyEnterMp(targetPlayer, host.getUid()); host.getServer().getMultiplayerManager().applyEnterMp(targetPlayer, host.getUid());
targetPlayer.getServer().getMultiplayerManager().applyEnterMpReply(host, targetPlayer.getUid(), true); targetPlayer.getServer().getMultiplayerManager().applyEnterMpReply(host, targetPlayer.getUid(), true);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Coop_success.replace("{host}", host.getNickname()).replace("{target}", targetPlayer.getNickname())); CommandHandler.sendMessage(sender, translate("commands.coop.success", targetPlayer.getNickname(), host.getNickname()));
} }
} }
...@@ -11,6 +11,8 @@ import emu.grasscutter.utils.Position; ...@@ -11,6 +11,8 @@ import emu.grasscutter.utils.Position;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "drop", usage = "drop <itemId|itemName> [amount]", @Command(label = "drop", usage = "drop <itemId|itemName> [amount]",
description = "Drops an item near you", aliases = {"d", "dropitem"}, permission = "server.drop") description = "Drops an item near you", aliases = {"d", "dropitem"}, permission = "server.drop")
public final class DropCommand implements CommandHandler { public final class DropCommand implements CommandHandler {
...@@ -18,7 +20,7 @@ public final class DropCommand implements CommandHandler { ...@@ -18,7 +20,7 @@ public final class DropCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(null, translate("commands.execution.need_target"));
return; return;
} }
...@@ -30,25 +32,25 @@ public final class DropCommand implements CommandHandler { ...@@ -30,25 +32,25 @@ public final class DropCommand implements CommandHandler {
try { try {
amount = Integer.parseInt(args.get(1)); amount = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_amount); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.amount"));
return; return;
} // Slightly cheeky here: no break so it falls through to initialize the first argument too } // Slightly cheeky here: no break, so it falls through to initialize the first argument too
case 1: case 1:
try { try {
item = Integer.parseInt(args.get(0)); item = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId"));
return; return;
} }
break; break;
default: default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Drop_usage); CommandHandler.sendMessage(sender, translate("commands.drop.command_usage"));
return; return;
} }
ItemData itemData = GameData.getItemDataMap().get(item); ItemData itemData = GameData.getItemDataMap().get(item);
if (itemData == null) { if (itemData == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId"));
return; return;
} }
if (itemData.isEquip()) { if (itemData.isEquip()) {
...@@ -62,6 +64,6 @@ public final class DropCommand implements CommandHandler { ...@@ -62,6 +64,6 @@ public final class DropCommand implements CommandHandler {
EntityItem entity = new EntityItem(targetPlayer.getScene(), targetPlayer, itemData, targetPlayer.getPos().clone().addY(3f), amount); EntityItem entity = new EntityItem(targetPlayer.getScene(), targetPlayer, itemData, targetPlayer.getPos().clone().addY(3f), amount);
targetPlayer.getScene().addEntity(entity); targetPlayer.getScene().addEntity(entity);
} }
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Drop_dropped_of.replace("{amount}", Integer.toString(amount)).replace("{item}", Integer.toString(item))); CommandHandler.sendMessage(sender, translate("commands.drop.success", Integer.toString(amount), Integer.toString(item)));
} }
} }
\ No newline at end of file
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "enterdungeon", usage = "enterdungeon <dungeon id>", @Command(label = "enterdungeon", usage = "enterdungeon <dungeon id>",
description = "Enter a dungeon", aliases = {"dungeon"}, permission = "player.enterdungeon") description = "Enter a dungeon", aliases = {"dungeon"}, permission = "player.enterdungeon")
public final class EnterDungeonCommand implements CommandHandler { public final class EnterDungeonCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(null, translate("commands.execution.need_target"));
return; return;
} }
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_usage); CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.usage"));
return; return;
} }
try { try {
int dungeonId = Integer.parseInt(args.get(0)); int dungeonId = Integer.parseInt(args.get(0));
if (dungeonId == targetPlayer.getSceneId()) { if (dungeonId == targetPlayer.getSceneId()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_you_in_that_dungeon); CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.in_dungeon_error"));
return; return;
} }
boolean result = targetPlayer.getServer().getDungeonManager().enterDungeon(targetPlayer.getSession().getPlayer(), 0, dungeonId); boolean result = targetPlayer.getServer().getDungeonManager().enterDungeon(targetPlayer.getSession().getPlayer(), 0, dungeonId);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_changed_to_dungeon + dungeonId); CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.changed", dungeonId));
if (!result) { if (!result) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_dungeon_not_found); CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.not_found_error"));
} }
} catch (Exception e) { } catch (Exception e) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_usage); CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.usage"));
} }
} }
} }
...@@ -13,6 +13,8 @@ import emu.grasscutter.game.player.Player; ...@@ -13,6 +13,8 @@ import emu.grasscutter.game.player.Player;
import java.util.*; import java.util.*;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "giveall", usage = "giveall [amount]", @Command(label = "giveall", usage = "giveall [amount]",
description = "Gives all items", aliases = {"givea"}, permission = "player.giveall", threading = true) description = "Gives all items", aliases = {"givea"}, permission = "player.giveall", threading = true)
public final class GiveAllCommand implements CommandHandler { public final class GiveAllCommand implements CommandHandler {
...@@ -20,7 +22,7 @@ public final class GiveAllCommand implements CommandHandler { ...@@ -20,7 +22,7 @@ public final class GiveAllCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
int amount = 99999; int amount = 99999;
...@@ -32,21 +34,21 @@ public final class GiveAllCommand implements CommandHandler { ...@@ -32,21 +34,21 @@ public final class GiveAllCommand implements CommandHandler {
try { try {
amount = Integer.parseInt(args.get(0)); amount = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_amount); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.amount"));
return; return;
} }
break; break;
default: // invalid default: // invalid
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveAll_usage); CommandHandler.sendMessage(sender, translate("commands.giveAll.usage"));
return; return;
} }
this.giveAllItems(targetPlayer, amount); this.giveAllItems(targetPlayer, amount);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveAll_done); CommandHandler.sendMessage(sender, translate("commands.giveAll.success", targetPlayer.getNickname()));
} }
public void giveAllItems(Player player, int amount) { public void giveAllItems(Player player, int amount) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().GiveAll_item); CommandHandler.sendMessage(player, translate("commands.giveAll.started"));
for (AvatarData avatarData: GameData.getAvatarDataMap().values()) { for (AvatarData avatarData: GameData.getAvatarDataMap().values()) {
//Exclude test avatar //Exclude test avatar
......
...@@ -14,17 +14,19 @@ import java.util.ArrayList; ...@@ -14,17 +14,19 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "giveart", usage = "giveart <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]", description = "Gives the player a specified artifact", aliases = {"gart"}, permission = "player.giveart") @Command(label = "giveart", usage = "giveart <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]", description = "Gives the player a specified artifact", aliases = {"gart"}, permission = "player.giveart")
public final class GiveArtifactCommand implements CommandHandler { public final class GiveArtifactCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveArtifact_usage); CommandHandler.sendMessage(sender, translate("commands.giveArtifact.usage"));
return; return;
} }
...@@ -32,12 +34,12 @@ public final class GiveArtifactCommand implements CommandHandler { ...@@ -32,12 +34,12 @@ public final class GiveArtifactCommand implements CommandHandler {
try { try {
itemId = Integer.parseInt(args.remove(0)); itemId = Integer.parseInt(args.remove(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_artifact_id); CommandHandler.sendMessage(sender, translate("commands.giveArtifact.id_error"));
return; return;
} }
ItemData itemData = GameData.getItemDataMap().get(itemId); ItemData itemData = GameData.getItemDataMap().get(itemId);
if (itemData.getItemType() != ItemType.ITEM_RELIQUARY) { if (itemData.getItemType() != ItemType.ITEM_RELIQUARY) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_artifact_id); CommandHandler.sendMessage(sender, translate("commands.giveArtifact.id_error"));
return; return;
} }
...@@ -45,7 +47,7 @@ public final class GiveArtifactCommand implements CommandHandler { ...@@ -45,7 +47,7 @@ public final class GiveArtifactCommand implements CommandHandler {
try { try {
mainPropId = Integer.parseInt(args.remove(0)); mainPropId = Integer.parseInt(args.remove(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments); CommandHandler.sendMessage(sender, translate("commands.generic.execution.argument_error"));
return; return;
} }
...@@ -59,7 +61,7 @@ public final class GiveArtifactCommand implements CommandHandler { ...@@ -59,7 +61,7 @@ public final class GiveArtifactCommand implements CommandHandler {
} catch (NumberFormatException ignored) { // Could be a stat,times string so no need to panic } catch (NumberFormatException ignored) { // Could be a stat,times string so no need to panic
} }
ArrayList<Integer> appendPropIdList = new ArrayList<>(); List<Integer> appendPropIdList = new ArrayList<>();
try { try {
args.forEach(it -> { args.forEach(it -> {
String[] arr; String[] arr;
...@@ -74,7 +76,7 @@ public final class GiveArtifactCommand implements CommandHandler { ...@@ -74,7 +76,7 @@ public final class GiveArtifactCommand implements CommandHandler {
appendPropIdList.addAll(Collections.nCopies(n, Integer.parseInt(it))); appendPropIdList.addAll(Collections.nCopies(n, Integer.parseInt(it)));
}); });
} catch (Exception ignored) { } catch (Exception ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments); CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
return; return;
} }
...@@ -85,7 +87,7 @@ public final class GiveArtifactCommand implements CommandHandler { ...@@ -85,7 +87,7 @@ public final class GiveArtifactCommand implements CommandHandler {
item.getAppendPropIdList().addAll(appendPropIdList); item.getAppendPropIdList().addAll(appendPropIdList);
targetPlayer.getInventory().addItem(item, ActionReason.SubfieldDrop); targetPlayer.getInventory().addItem(item, ActionReason.SubfieldDrop);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveArtifact_given.replace("{itemId}", Integer.toString(itemId)).replace("target", Integer.toString(targetPlayer.getUid()))); CommandHandler.sendMessage(sender, translate("commands.giveArtifact.success", Integer.toString(itemId), Integer.toString(targetPlayer.getUid())));
} }
} }
...@@ -10,6 +10,8 @@ import emu.grasscutter.game.player.Player; ...@@ -10,6 +10,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "givechar", usage = "givechar <avatarId> [level]", @Command(label = "givechar", usage = "givechar <avatarId> [level]",
description = "Gives the player a specified character", aliases = {"givec"}, permission = "player.givechar") description = "Gives the player a specified character", aliases = {"givec"}, permission = "player.givechar")
public final class GiveCharCommand implements CommandHandler { public final class GiveCharCommand implements CommandHandler {
...@@ -17,7 +19,7 @@ public final class GiveCharCommand implements CommandHandler { ...@@ -17,7 +19,7 @@ public final class GiveCharCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
...@@ -30,7 +32,7 @@ public final class GiveCharCommand implements CommandHandler { ...@@ -30,7 +32,7 @@ public final class GiveCharCommand implements CommandHandler {
level = Integer.parseInt(args.get(1)); level = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook. // TODO: Parse from avatar name using GM Handbook.
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_avatar_level); CommandHandler.sendMessage(sender, translate("commands.execution.invalid.avatarLevel"));
return; return;
} // Cheeky fall-through to parse first argument too } // Cheeky fall-through to parse first argument too
case 1: case 1:
...@@ -38,24 +40,24 @@ public final class GiveCharCommand implements CommandHandler { ...@@ -38,24 +40,24 @@ public final class GiveCharCommand implements CommandHandler {
avatarId = Integer.parseInt(args.get(0)); avatarId = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from avatar name using GM Handbook. // TODO: Parse from avatar name using GM Handbook.
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_avatar_id); CommandHandler.sendMessage(sender, translate("commands.execution.invalid.avatarId"));
return; return;
} }
break; break;
default: default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_usage); CommandHandler.sendMessage(sender, translate("commands.giveChar.usage"));
return; return;
} }
AvatarData avatarData = GameData.getAvatarDataMap().get(avatarId); AvatarData avatarData = GameData.getAvatarDataMap().get(avatarId);
if (avatarData == null) { if (avatarData == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_avatar_id); CommandHandler.sendMessage(sender, translate("commands.execution.invalid.avatarId"));
return; return;
} }
// Check level. // Check level.
if (level > 90) { if (level > 90) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_avatar_level); CommandHandler.sendMessage(sender, translate("commands.execution.invalid.avatarLevel"));
return; return;
} }
...@@ -75,6 +77,6 @@ public final class GiveCharCommand implements CommandHandler { ...@@ -75,6 +77,6 @@ public final class GiveCharCommand implements CommandHandler {
avatar.recalcStats(); avatar.recalcStats();
targetPlayer.addAvatar(avatar); targetPlayer.addAvatar(avatar);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveChar_given.replace("{avatarId}", Integer.toString(avatarId)).replace("{level}", Integer.toString(level)).replace("{target}", Integer.toString(targetPlayer.getUid()))); CommandHandler.sendMessage(sender, translate("commands.execution.giveChar.given", Integer.toString(avatarId), Integer.toString(level), Integer.toString(targetPlayer.getUid())));
} }
} }
...@@ -15,6 +15,8 @@ import java.util.List; ...@@ -15,6 +15,8 @@ import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "give", usage = "give <itemId|itemName> [amount] [level]", description = "Gives an item to you or the specified player", aliases = { @Command(label = "give", usage = "give <itemId|itemName> [amount] [level]", description = "Gives an item to you or the specified player", aliases = {
"g", "item", "giveitem"}, permission = "player.give") "g", "item", "giveitem"}, permission = "player.give")
public final class GiveCommand implements CommandHandler { public final class GiveCommand implements CommandHandler {
...@@ -33,7 +35,7 @@ public final class GiveCommand implements CommandHandler { ...@@ -33,7 +35,7 @@ public final class GiveCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
int item; int item;
...@@ -67,21 +69,21 @@ public final class GiveCommand implements CommandHandler { ...@@ -67,21 +69,21 @@ public final class GiveCommand implements CommandHandler {
try { try {
refinement = Integer.parseInt(args.get(3)); refinement = Integer.parseInt(args.get(3));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_refinement); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemRefinement"));
return; return;
} // Fallthrough } // Fallthrough
case 3: // <itemId|itemName> [amount] [level] case 3: // <itemId|itemName> [amount] [level]
try { try {
lvl = Integer.parseInt(args.get(2)); lvl = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_level); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemLevel"));
return; return;
} // Fallthrough } // Fallthrough
case 2: // <itemId|itemName> [amount] case 2: // <itemId|itemName> [amount]
try { try {
amount = Integer.parseInt(args.get(1)); amount = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_amount); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.amount"));
return; return;
} // Fallthrough } // Fallthrough
case 1: // <itemId|itemName> case 1: // <itemId|itemName>
...@@ -89,30 +91,28 @@ public final class GiveCommand implements CommandHandler { ...@@ -89,30 +91,28 @@ public final class GiveCommand implements CommandHandler {
item = Integer.parseInt(args.get(0)); item = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
// TODO: Parse from item name using GM Handbook. // TODO: Parse from item name using GM Handbook.
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId"));
return; return;
} }
break; break;
default: // *No args* default: // *No args*
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_usage); CommandHandler.sendMessage(sender, translate("commands.give.usage"));
return; return;
} }
ItemData itemData = GameData.getItemDataMap().get(item); ItemData itemData = GameData.getItemDataMap().get(item);
if (itemData == null) { if (itemData == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id); CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId"));
return; return;
} }
if (refinement != 0) { if (refinement != 0) {
if (itemData.getItemType() == ItemType.ITEM_WEAPON) { if (itemData.getItemType() == ItemType.ITEM_WEAPON) {
if (refinement < 1 || refinement > 5) { if (refinement < 1 || refinement > 5) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_refinement_must_between_1_and_5); CommandHandler.sendMessage(sender, translate("commands.give.refinement_must_between_1_and_5"));
return; return;
} }
} else { } else {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_refinement_only_applicable_weapons); CommandHandler.sendMessage(sender, translate("commands.give.refinement_only_applicable_weapons"));
return; return;
} }
} }
...@@ -120,11 +120,11 @@ public final class GiveCommand implements CommandHandler { ...@@ -120,11 +120,11 @@ public final class GiveCommand implements CommandHandler {
this.item(targetPlayer, itemData, amount, lvl, refinement); this.item(targetPlayer, itemData, amount, lvl, refinement);
if (!itemData.isEquip()) { if (!itemData.isEquip()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_given.replace("{amount}", Integer.toString(amount)).replace("{item}", Integer.toString(item)).replace("{target}", Integer.toString(targetPlayer.getUid()))); CommandHandler.sendMessage(sender, translate("commands.give.given", Integer.toString(amount), Integer.toString(item), Integer.toString(targetPlayer.getUid())));
} else if (itemData.getItemType() == ItemType.ITEM_WEAPON) { } else if (itemData.getItemType() == ItemType.ITEM_WEAPON) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Give_given_with_level_and_refinement.replace("{item}", Integer.toString(item)).replace("{lvl}", Integer.toString(lvl)).replace("{refinement}", Integer.toString(refinement)).replace("{amount}", Integer.toString(amount)).replace("{target}", Integer.toString(targetPlayer.getUid()))); CommandHandler.sendMessage(sender, translate("commands.give.given_with_level_and_refinement", Integer.toString(item), Integer.toString(lvl), Integer.toString(refinement), Integer.toString(amount), Integer.toString(targetPlayer.getUid())));
} else { } else {
CommandHandler.sendMessage(sender,Grasscutter.getLanguage().Give_given_level.replace("{item}", Integer.toString(item)).replace("{lvl}", Integer.toString(lvl)).replace("{amount}", Integer.toString(amount))); CommandHandler.sendMessage(sender, translate("commands.give.given_level", Integer.toString(item), Integer.toString(lvl), Integer.toString(amount)));
} }
} }
......
...@@ -7,6 +7,8 @@ import emu.grasscutter.game.player.Player; ...@@ -7,6 +7,8 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "godmode", usage = "godmode [on|off|toggle]", @Command(label = "godmode", usage = "godmode [on|off|toggle]",
description = "Prevents you from taking damage. Defaults to toggle.", permission = "player.godmode") description = "Prevents you from taking damage. Defaults to toggle.", permission = "player.godmode")
public final class GodModeCommand implements CommandHandler { public final class GodModeCommand implements CommandHandler {
...@@ -14,7 +16,7 @@ public final class GodModeCommand implements CommandHandler { ...@@ -14,7 +16,7 @@ public final class GodModeCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
...@@ -30,11 +32,11 @@ public final class GodModeCommand implements CommandHandler { ...@@ -30,11 +32,11 @@ public final class GodModeCommand implements CommandHandler {
case "toggle": case "toggle":
break; // Already toggled break; // Already toggled
default: default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Godmode_status); break;
} }
} }
targetPlayer.setGodmode(enabled); targetPlayer.setGodmode(enabled);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Godmode_status.replace("{status}", (enabled ? Grasscutter.getLanguage().Enabled : Grasscutter.getLanguage().Disabled)).replace("{name}", targetPlayer.getNickname())); CommandHandler.sendMessage(sender, translate("commands.godmode.success", (enabled ? translate("commands.status.enabled") : translate("commands.status.disabled")), targetPlayer.getNickname()));
} }
} }
package emu.grasscutter.command.commands; package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command; import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler; import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
...@@ -10,13 +9,15 @@ import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify; ...@@ -10,13 +9,15 @@ import emu.grasscutter.server.packet.send.PacketAvatarLifeStateChangeNotify;
import java.util.List; import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "heal", usage = "heal|h", aliases = {"h"}, @Command(label = "heal", usage = "heal|h", aliases = {"h"},
description = "Heal all characters in your current team.", permission = "player.heal") description = "Heal all characters in your current team.", permission = "player.heal")
public final class HealCommand implements CommandHandler { public final class HealCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed); CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return; return;
} }
...@@ -31,6 +32,6 @@ public final class HealCommand implements CommandHandler { ...@@ -31,6 +32,6 @@ public final class HealCommand implements CommandHandler {
entity.getWorld().broadcastPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar())); entity.getWorld().broadcastPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar()));
} }
}); });
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Heal_message); CommandHandler.sendMessage(sender, translate("commands.heal.success"));
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment