Commit 65861c3c authored by Akka's avatar Akka Committed by GitHub
Browse files

Merge pull request #7 from Grasscutters/development

Development
parents c2d2a37f 176f3e91
......@@ -31,4 +31,4 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: Grasscutter
path: grasscutter-*-dev.jar
path: grasscutter-*.jar
......@@ -67,4 +67,5 @@ mongod.exe
/*.sh
language/
languages/
gacha_mappings.js
gacha-mapping.js
data/gacha_mappings.js
......@@ -28,7 +28,7 @@ plugins {
// Eclipse Support
id 'eclipse'
// Intelij Support
// IntelliJ Support
id 'idea'
// Maven
......@@ -43,7 +43,7 @@ sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
group = 'xyz.grasscutters'
version = '1.0.3-dev'
version = '1.1.0'
sourceCompatibility = 17
targetCompatibility = 17
......
[
{
"expId": 101,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101001,
"minCount": 4,
"maxCount": 5
}, {
"itemId": 101002,
"minCount": 2,
"maxCount": 3
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101002,
"minCount": 6,
"maxCount": 7
}, {
"itemId": 101003,
"minCount": 1,
"maxCount": 2
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101002,
"minCount": 6,
"maxCount": 7
}, {
"itemId": 101003,
"minCount": 2,
"maxCount": 3
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101002,
"minCount": 3,
"maxCount": 4
}, {
"itemId": 101003,
"minCount": 7,
"maxCount": 8
}
]
}
]
},
{
"expId": 102,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100061,
"minCount": 1,
"maxCount": 1
}, {
"itemId": 100064,
"minCount": 1,
"maxCount": 1
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100061,
"minCount": 2,
"maxCount": 4
}, {
"itemId": 100064,
"minCount": 2,
"maxCount": 4
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100061,
"minCount": 4,
"maxCount": 6
}, {
"itemId": 100064,
"minCount": 4,
"maxCount": 6
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100061,
"minCount": 8,
"maxCount": 12
}, {
"itemId": 100064,
"minCount": 8,
"maxCount": 12
}
]
}
]
},
{
"expId": 103,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101001,
"minCount": 4,
"maxCount": 5
}, {
"itemId": 101002,
"minCount": 2,
"maxCount": 3
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101002,
"minCount": 6,
"maxCount": 7
}, {
"itemId": 101003,
"minCount": 1,
"maxCount": 2
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101002,
"minCount": 6,
"maxCount": 7
}, {
"itemId": 101003,
"minCount": 2,
"maxCount": 3
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101002,
"minCount": 3,
"maxCount": 4
}, {
"itemId": 101003,
"minCount": 7,
"maxCount": 8
}
]
}
]
},
{
"expId": 104,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100012,
"minCount": 1,
"maxCount": 1
}, {
"itemId": 100062,
"minCount": 1,
"maxCount": 1
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100012,
"minCount": 2,
"maxCount": 4
}, {
"itemId": 100062,
"minCount": 2,
"maxCount": 4
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100012,
"minCount": 4,
"maxCount": 6
}, {
"itemId": 100062,
"minCount": 4,
"maxCount": 6
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100012,
"minCount": 8,
"maxCount": 12
}, {
"itemId": 100062,
"minCount": 8,
"maxCount": 12
}
]
}
]
},
{
"expId": 105,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 1,
"maxCount": 1
}, {
"itemId": 100013,
"minCount": 1,
"maxCount": 1
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 2,
"maxCount": 4
}, {
"itemId": 100013,
"minCount": 2,
"maxCount": 4
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 4,
"maxCount": 6
}, {
"itemId": 100013,
"minCount": 4,
"maxCount": 6
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 8,
"maxCount": 12
}, {
"itemId": 100013,
"minCount": 8,
"maxCount": 12
}
]
}
]
},
{
"expId": 106,
"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": 201,
"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": 202,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100026,
"minCount": 1,
"maxCount": 1
}, {
"itemId": 100063,
"minCount": 1,
"maxCount": 1
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100026,
"minCount": 2,
"maxCount": 4
}, {
"itemId": 100063,
"minCount": 2,
"maxCount": 4
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100026,
"minCount": 4,
"maxCount": 6
}, {
"itemId": 100063,
"minCount": 4,
"maxCount": 6
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100026,
"minCount": 8,
"maxCount": 12
}, {
"itemId": 100063,
"minCount": 8,
"maxCount": 12
}
]
}
]
},
{
"expId": 203,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101001,
"minCount": 4,
"maxCount": 5
}, {
"itemId": 101002,
"minCount": 2,
"maxCount": 3
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101002,
"minCount": 6,
"maxCount": 7
}, {
"itemId": 101003,
"minCount": 1,
"maxCount": 2
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101002,
"minCount": 6,
"maxCount": 7
}, {
"itemId": 101003,
"minCount": 2,
"maxCount": 3
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 101002,
"minCount": 3,
"maxCount": 4
}, {
"itemId": 101003,
"minCount": 7,
"maxCount": 8
}
]
}
]
},
{
"expId": 204,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 1,
"maxCount": 1
}, {
"itemId": 100013,
"minCount": 1,
"maxCount": 1
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 2,
"maxCount": 4
}, {
"itemId": 100013,
"minCount": 2,
"maxCount": 4
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 4,
"maxCount": 6
}, {
"itemId": 100013,
"minCount": 4,
"maxCount": 6
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 8,
"maxCount": 12
}, {
"itemId": 100013,
"minCount": 8,
"maxCount": 12
}
]
}
]
},
{
"expId": 205,
"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": 206,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100026,
"minCount": 1,
"maxCount": 1
}, {
"itemId": 100063,
"minCount": 1,
"maxCount": 1
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100026,
"minCount": 2,
"maxCount": 4
}, {
"itemId": 100063,
"minCount": 2,
"maxCount": 4
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100026,
"minCount": 4,
"maxCount": 6
}, {
"itemId": 100063,
"minCount": 4,
"maxCount": 6
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100026,
"minCount": 8,
"maxCount": 12
}, {
"itemId": 100063,
"minCount": 8,
"maxCount": 12
}
]
}
]
},
{
"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": 302,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 1,
"maxCount": 1
}, {
"itemId": 101211,
"minCount": 1,
"maxCount": 1
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 2,
"maxCount": 4
}, {
"itemId": 101211,
"minCount": 2,
"maxCount": 4
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 4,
"maxCount": 6
}, {
"itemId": 101211,
"minCount": 4,
"maxCount": 6
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100014,
"minCount": 8,
"maxCount": 12
}, {
"itemId": 101211,
"minCount": 8,
"maxCount": 12
}
]
}
]
},
{
"expId": 303,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100012,
"minCount": 1,
"maxCount": 1
}, {
"itemId": 100002,
"minCount": 1,
"maxCount": 1
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100012,
"minCount": 2,
"maxCount": 4
}, {
"itemId": 100002,
"minCount": 2,
"maxCount": 4
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100012,
"minCount": 4,
"maxCount": 6
}, {
"itemId": 100002,
"minCount": 4,
"maxCount": 6
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100012,
"minCount": 8,
"maxCount": 12
}, {
"itemId": 100002,
"minCount": 8,
"maxCount": 12
}
]
}
]
},
{
"expId": 304,
"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
}
]
}
]
},
{
"expId": 306,
"expeditionRewardDataList": [
{
"hourTime": 4,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100061,
"minCount": 1,
"maxCount": 1
}, {
"itemId": 100062,
"minCount": 1,
"maxCount": 1
}
]
},
{
"hourTime": 8,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100061,
"minCount": 2,
"maxCount": 4
}, {
"itemId": 100062,
"minCount": 2,
"maxCount": 4
}
]
},
{
"hourTime": 12,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100061,
"minCount": 4,
"maxCount": 6
}, {
"itemId": 100062,
"minCount": 4,
"maxCount": 6
}
]
},
{
"hourTime": 20,
"rewardMora": 0,
"expeditionRewardData": [
{
"itemId": 100061,
"minCount": 8,
"maxCount": 12
}, {
"itemId": 100062,
"minCount": 8,
"maxCount": 12
}
]
}
]
}
]
\ No newline at end of file
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "JSON schema for a Grasscutter Plugin",
"type": "object",
"additionalProperties": true,
"definitions": {
"plugin-name": {
"type": "string",
"pattern": "^[A-Za-z\\d_.-]+$"
}
},
"required": [ "name", "description", "mainClass" ],
"properties": {
"name": {
"description": "The unique name of plugin.",
"$ref": "#/definitions/plugin-name"
},
"mainClass": {
"description": "The plugin's initial class file.",
"type": "string",
"pattern": "^(?!org\\.bukkit\\.)([a-zA-Z_$][a-zA-Z\\d_$]*\\.)*[a-zA-Z_$][a-zA-Z\\d_$]*$"
},
"version": {
"description": "A plugin revision identifier.",
"type": [ "string", "number" ]
},
"description": {
"description": "Human readable plugin summary.",
"type": "string"
},
"author": {
"description": "The plugin author.",
"type": "string"
},
"authors": {
"description": "The plugin contributors.",
"type": "array",
"items": {
"type": "string"
}
},
"website": {
"title": "Website",
"description": "The URL to the plugin's site",
"type": "string",
"format": "uri"
}
}
}
\ No newline at end of file
import os
# This can also be replaced with another IP address.
USE_SSL = True
REMOTE_HOST = "127.0.0.1"
REMOTE_HOST = "localhost"
REMOTE_PORT = 443
if os.getenv('MITM_REMOTE_HOST') != None:
REMOTE_HOST = os.getenv('MITM_REMOTE_HOST')
if os.getenv('MITM_REMOTE_PORT') != None:
REMOTE_PORT = int(os.getenv('MITM_REMOTE_PORT'))
if os.getenv('MITM_USE_SSL') != None:
USE_SSL = bool(os.getenv('MITM_USE_SSL'))
print('MITM Remote Host: ' + REMOTE_HOST)
print('MITM Remote Port: ' + str(REMOTE_PORT))
print('MITM Use SSL ' + str(USE_SSL))
......@@ -6,7 +6,6 @@ import emu.grasscutter.Grasscutter.ServerRunMode;
import emu.grasscutter.game.mail.Mail;
public final class Config {
public String DatabaseUrl = "mongodb://localhost:27017";
public String DatabaseCollection = "grasscutter";
......@@ -24,6 +23,7 @@ public final class Config {
public GameServerOptions GameServer = new GameServerOptions();
public DispatchServerOptions DispatchServer = new DispatchServerOptions();
public Locale LocaleLanguage = Locale.getDefault();
public Locale DefaultLanguage = Locale.ENGLISH;
public Boolean OpenStamina = true;
public GameServerOptions getGameServerOptions() {
......@@ -41,6 +41,8 @@ public final class Config {
public String KeystorePassword = "123456";
public Boolean UseSSL = true;
public Boolean FrontHTTPS = true;
public Boolean CORS = false;
public String[] CORSAllowedOrigins = new String[] { "*" };
public boolean AutomaticallyCreateAccounts = false;
public String[] defaultPermissions = new String[] { "" };
......@@ -80,6 +82,10 @@ public final class Config {
public boolean WatchGacha = false;
public String ServerNickname = "Server";
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 String WelcomeMotd = "Welcome to Grasscutter emu";
public String WelcomeMailTitle = "Welcome to Grasscutter!";
......
......@@ -11,8 +11,6 @@ public final class GameConstants {
public static final int MAX_TEAMS = 4;
public static final int MAIN_CHARACTER_MALE = 10000005;
public static final int MAIN_CHARACTER_FEMALE = 10000007;
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 Position START_POSITION = new Position(2747, 194, -1719);
public static final int MAX_FRIENDS = 45;
......
......@@ -4,9 +4,7 @@ import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOError;
import java.net.InetSocketAddress;
import java.util.Calendar;
import java.util.Locale;
import emu.grasscutter.command.CommandMap;
import emu.grasscutter.plugin.PluginManager;
......@@ -28,24 +26,25 @@ import com.google.gson.GsonBuilder;
import ch.qos.logback.classic.Logger;
import emu.grasscutter.data.ResourceLoader;
import emu.grasscutter.database.DatabaseManager;
import emu.grasscutter.languages.CNLanguage;
import emu.grasscutter.languages.Language;
import emu.grasscutter.utils.Language;
import emu.grasscutter.server.dispatch.DispatchServer;
import emu.grasscutter.server.game.GameServer;
import emu.grasscutter.tools.Tools;
import emu.grasscutter.utils.Crypto;
import static emu.grasscutter.utils.Language.translate;
public final class Grasscutter {
private static final Logger log = (Logger) LoggerFactory.getLogger(Grasscutter.class);
private static Config config;
private static LineReader consoleLineReader = null;
private static Config config;
private static Language language;
private static CNLanguage cn_language;
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
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 GameServer gameServer;
......@@ -60,7 +59,7 @@ public final class Grasscutter {
// Load server configuration.
Grasscutter.loadConfig();
// Load Language
// Load translation files.
Grasscutter.loadLanguage();
// Check server structure.
......@@ -68,38 +67,42 @@ public final class Grasscutter {
}
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) {
switch (arg.toLowerCase()) {
case "-handbook" -> {
Tools.createGmHandbook(); return;
Tools.createGmHandbook(); exitEarly = true;
}
case "-gachamap" -> {
Tools.createGachaMapping("./gacha_mappings.js"); return;
Tools.createGachaMapping(Grasscutter.getConfig().DATA_FOLDER + "/gacha_mappings.js"); exitEarly = true;
}
}
}
// Exit early if argument sets it.
if(exitEarly) System.exit(0);
// Initialize server.
Grasscutter.getLogger().info(language.Starting_Grasscutter);
Grasscutter.getLogger().info(translate("messages.status.starting"));
// Load all resources.
Grasscutter.updateDayOfWeek();
ResourceLoader.loadAll();
ScriptLoader.init();
// Database
// Initialize database.
DatabaseManager.initialize();
// Create plugin manager instance.
pluginManager = new PluginManager();
// Create server instances.
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.
new ServerHook(gameServer, dispatchServer);
// Create plugin manager instance.
pluginManager = new PluginManager();
// Start servers.
if (getConfig().RunMode == ServerRunMode.HYBRID) {
......@@ -110,9 +113,9 @@ public final class Grasscutter {
} else if (getConfig().RunMode == ServerRunMode.GAME_ONLY) {
gameServer.start();
} else {
getLogger().error(language.Invalid_server_run_mode + " " + getConfig().RunMode);
getLogger().error(language.Server_run_mode);
getLogger().error(language.Shutting_down);
getLogger().error(translate("messages.status.run_mode_error", getConfig().RunMode));
getLogger().error(translate("messages.status.run_mode_help"));
getLogger().error(translate("messages.status.shutdown"));
System.exit(1);
}
......@@ -145,40 +148,14 @@ public final class Grasscutter {
}
public static void loadLanguage() {
try (FileReader file = new FileReader(String.format("%s%s.json", getConfig().LANGUAGE_FOLDER, Grasscutter.config.LocaleLanguage))) {
language = gson.fromJson(file, Language.class);
} 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("无法创建简体中文语言文件。");
}
var locale = config.LocaleLanguage;
var languageTag = locale.toLanguageTag();
// 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");
}
if (languageTag.equals("und")) {
Grasscutter.getLogger().error("Illegal locale language, using 'en-US' instead.");
language = Language.getLanguage("en-US");
} else {
language = Language.getLanguage(languageTag);
}
}
......@@ -193,11 +170,11 @@ public final class Grasscutter {
public static void startConsole() {
// Console should not start in dispatch only mode.
if (getConfig().RunMode == ServerRunMode.DISPATCH_ONLY) {
getLogger().info(language.Dispatch_mode_not_support_command);
getLogger().info(translate("messages.dispatch.no_commands_error"));
return;
}
getLogger().info(language.Start_done);
getLogger().info(translate("messages.status.done"));
String input = null;
boolean isLastInterrupted = false;
while (true) {
......@@ -223,7 +200,7 @@ public final class Grasscutter {
try {
CommandMap.getInstance().invoke(null, null, input);
} catch (Exception e) {
Grasscutter.getLogger().error(language.Command_error, e);
Grasscutter.getLogger().error(translate("messages.game.command_error"), e);
}
}
}
......
......@@ -9,7 +9,7 @@ public @interface Command {
String usage() default "No usage specified";
String description() default "No description specified";
String description() default "commands.generic.no_description_specified";
String[] aliases() default {};
......
......@@ -6,6 +6,7 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
public interface CommandHandler {
/**
* Send a message to the target.
*
......
......@@ -8,6 +8,8 @@ import org.reflections.Reflections;
import java.util.*;
import static emu.grasscutter.utils.Language.translate;
@SuppressWarnings({"UnusedReturnValue", "unused"})
public final class CommandMap {
private final Map<String, CommandHandler> commands = new HashMap<>();
......@@ -77,6 +79,12 @@ public final class CommandMap {
return this;
}
public List<Command> getAnnotationsAsList() { return new LinkedList<>(this.annotations.values()); }
public HashMap<String, Command> getAnnotations() {
return new LinkedHashMap<>(this.annotations);
}
/**
* Returns a list of all registered commands.
*
......@@ -109,7 +117,7 @@ public final class CommandMap {
public void invoke(Player player, Player targetPlayer, String rawMessage) {
rawMessage = rawMessage.trim();
if (rawMessage.length() == 0) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().No_command_specified);
CommandHandler.sendMessage(player, translate("commands.generic.not_specified"));
return;
}
......@@ -118,7 +126,8 @@ public final class CommandMap {
List<String> args = new LinkedList<>(Arrays.asList(split));
String label = args.remove(0);
String playerId = (player == null) ? consoleId : player.getAccount().getId();
// Check for special cases - currently only target command
// Check for special cases - currently only target command.
String targetUidStr = null;
if (label.startsWith("@")) { // @[UID]
targetUidStr = label.substring(1);
......@@ -133,70 +142,66 @@ public final class CommandMap {
}
}
if (targetUidStr != null) {
if (targetUidStr.equals("")) { // Clears default targetPlayer
if (targetUidStr.equals("")) { // Clears the default targetPlayer.
targetPlayerIds.remove(playerId);
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Target_cleared);
return;
} else { // Sets default targetPlayer to the UID given
CommandHandler.sendMessage(player, translate("commands.execution.clear_target"));
} else { // Sets default targetPlayer to the UID provided.
try {
int uid = Integer.parseInt(targetUidStr);
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid);
if (targetPlayer == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline);
CommandHandler.sendMessage(player, translate("commands.generic.execution.player_exist_offline_error"));
} else {
targetPlayerIds.put(playerId, uid);
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Target_set.replace("{uid}", targetUidStr));
CommandHandler.sendMessage(player, translate("commands.execution.set_target", targetUidStr));
}
} catch (NumberFormatException e) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Invalid_UID);
CommandHandler.sendMessage(player, translate("commands.execution.uid_error"));
}
return;
}
return;
}
// Get command handler.
CommandHandler handler = this.commands.get(label);
if (handler == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Unknown_command + label);
CommandHandler.sendMessage(player, translate("commands.generic.unknown_command", label));
return;
}
// If any @UID argument is present, override targetPlayer with it
// If any @UID argument is present, override targetPlayer with it.
for (int i = 0; i < args.size(); i++) {
String arg = args.get(i);
if (!arg.startsWith("@")) {
continue;
} else {
if (arg.startsWith("@")) {
arg = args.remove(i).substring(1);
try {
int uid = Integer.parseInt(arg);
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(uid);
if (targetPlayer == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline);
CommandHandler.sendMessage(player, translate("commands.generic.execution.player_exist_offline_error"));
return;
}
break;
} catch (NumberFormatException e) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Invalid_UID);
CommandHandler.sendMessage(player, translate("commands.execution.uid_error"));
return;
}
}
}
// If there's still no targetPlayer at this point, use previously-set target
if (targetPlayer == null) {
if (targetPlayerIds.containsKey(playerId)) {
targetPlayer = Grasscutter.getGameServer().getPlayerByUid(targetPlayerIds.get(playerId)); // We check every time in case the target goes offline after being targeted
if (targetPlayer == null) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().Player_not_found_or_offline);
CommandHandler.sendMessage(player, translate("commands.generic.execution.player_exist_offline_error"));
return;
}
} else {
// If there's still no targetPlayer at this point, use local player
if (targetPlayer == null) {
// If there's still no targetPlayer at this point, use executor.
targetPlayer = player;
}
}
}
// Check for permission.
if (player != null) {
......@@ -205,12 +210,12 @@ public final class CommandMap {
Account account = player.getAccount();
if (player != targetPlayer) { // Additional permission required for targeting another player
if (!permissionNodeTargeted.isEmpty() && !account.hasPermission(permissionNodeTargeted)) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().You_not_permission_run_command);
CommandHandler.sendMessage(player, translate("commands.generic.permission_error"));
return;
}
}
if (!permissionNode.isEmpty() && !account.hasPermission(permissionNode)) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().You_not_permission_run_command);
CommandHandler.sendMessage(player, translate("commands.generic.permission_error"));
return;
}
}
......@@ -220,10 +225,8 @@ public final class CommandMap {
final Player targetPlayerF = targetPlayer; // Is there a better way to do this?
Runnable runnable = () -> handler.execute(player, targetPlayerF, args);
if(threading) {
Thread command = new Thread(runnable);
command.start();
}
else {
new Thread(runnable).start();
} else {
runnable.run();
}
}
......
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.database.DatabaseHelper;
......@@ -8,18 +7,20 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
@Command(label = "account", usage = "account <create|delete> <username> [uid]", description = "Modify user accounts")
import static emu.grasscutter.utils.Language.translate;
@Command(label = "account", usage = "account <create|delete> <username> [uid]", description = "commands.account.description")
public final class AccountCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender != null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().This_command_can_only_run_from_console);
CommandHandler.sendMessage(sender, translate("commands.generic.console_execute_error"));
return;
}
if (args.size() < 2) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_command_usage);
CommandHandler.sendMessage(null, translate("commands.account.command_usage"));
return;
}
......@@ -28,7 +29,7 @@ public final class AccountCommand implements CommandHandler {
switch (action) {
default:
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_command_usage);
CommandHandler.sendMessage(null, translate("commands.account.command_usage"));
return;
case "create":
int uid = 0;
......@@ -36,27 +37,27 @@ public final class AccountCommand implements CommandHandler {
try {
uid = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Invalid_UID);
CommandHandler.sendMessage(null, translate("commands.account.invalid"));
return;
}
}
emu.grasscutter.game.Account account = DatabaseHelper.createAccountWithId(username, uid);
if (account == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_exists);
CommandHandler.sendMessage(null, translate("commands.account.exists"));
return;
} else {
account.addPermission("*");
account.save(); // Save account to database.
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_create_UID.replace("{uid}", Integer.toString(account.getPlayerUid())));
CommandHandler.sendMessage(null, translate("commands.account.create", Integer.toString(account.getPlayerUid())));
}
return;
case "delete":
if (DatabaseHelper.deleteAccount(username)) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_delete);
CommandHandler.sendMessage(null, translate("commands.account.delete"));
} else {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Account_not_find);
CommandHandler.sendMessage(null, translate("commands.account.no_account"));
}
}
}
......
......@@ -7,14 +7,15 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
@Command(label = "broadcast", usage = "broadcast <message>",
description = "Sends a message to all the players", aliases = {"b"}, permission = "server.broadcast")
import static emu.grasscutter.utils.Language.translate;
@Command(label = "broadcast", usage = "broadcast <message>", aliases = {"b"}, permission = "server.broadcast", description = "commands.broadcast.description")
public final class BroadcastCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_command_usage);
CommandHandler.sendMessage(sender, translate("commands.broadcast.command_usage"));
return;
}
......@@ -24,6 +25,6 @@ public final class BroadcastCommand implements CommandHandler {
CommandHandler.sendMessage(p, message);
}
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Broadcast_message_sent);
CommandHandler.sendMessage(sender, translate("commands.broadcast.message_sent"));
}
}
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
import java.util.List;
@Command(label = "changescene", usage = "changescene <scene id>",
description = "Changes your scene", aliases = {"scene"}, permission = "player.changescene")
import static emu.grasscutter.utils.Language.translate;
@Command(label = "changescene", usage = "changescene <scene id>", aliases = {"scene"}, permission = "player.changescene", description = "commands.changescene.description")
public final class ChangeSceneCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() != 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_usage);
CommandHandler.sendMessage(sender, translate("commands.changescene.usage"));
return;
}
try {
int sceneId = Integer.parseInt(args.get(0));
if (sceneId == targetPlayer.getSceneId()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_you_in_that_screen);
CommandHandler.sendMessage(sender, translate("commands.changescene.already_in_scene"));
return;
}
boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, targetPlayer.getPos());
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen + sceneId);
CommandHandler.sendMessage(sender, translate("commands.changescene.result", Integer.toString(sceneId)));
if (!result) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Change_screen_not_exist);
CommandHandler.sendMessage(sender, translate("commands.changescene.exists_error"));
}
} catch (Exception e) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments);
CommandHandler.sendMessage(sender, translate("commands.execution.argument_error"));
}
}
}
......@@ -10,8 +10,10 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "clear", usage = "clear <all|wp|art|mat>", //Merged /clearartifacts and /clearweapons to /clear <args> [uid]
description = "Deletes unequipped unlocked items, including yellow rarity ones from your inventory",
description = "commands.clear.description",
aliases = {"clear"}, permission = "player.clearinv")
public final class ClearCommand implements CommandHandler {
......@@ -19,11 +21,11 @@ public final class ClearCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_usage);
CommandHandler.sendMessage(sender, translate("commands.clear.command_usage"));
return;
}
Inventory playerInventory = targetPlayer.getInventory();
......@@ -35,7 +37,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getItemType() == ItemType.ITEM_WEAPON)
.filter(item -> !item.isLocked() && !item.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_weapons.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.weapons", targetPlayer.getNickname()));
}
case "art" -> {
toDelete = playerInventory.getItems().values().stream()
......@@ -43,7 +45,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.artifacts", targetPlayer.getNickname()));
}
case "mat" -> {
toDelete = playerInventory.getItems().values().stream()
......@@ -51,7 +53,7 @@ public final class ClearCommand implements CommandHandler {
.filter(item -> item.getLevel() == 1 && item.getExp() == 0)
.filter(item -> !item.isLocked() && !item.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.materials", targetPlayer.getNickname()));
}
case "all" -> {
toDelete = playerInventory.getItems().values().stream()
......@@ -59,34 +61,44 @@ public final class ClearCommand implements CommandHandler {
.filter(item1 -> item1.getLevel() == 1 && item1.getExp() == 0)
.filter(item1 -> !item1.isLocked() && !item1.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.artifacts", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
toDelete = playerInventory.getItems().values().stream()
.filter(item2 -> item2.getItemType() == ItemType.ITEM_MATERIAL)
.filter(item2 -> !item2.isLocked() && !item2.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.materials", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream()
.filter(item3 -> item3.getItemType() == ItemType.ITEM_WEAPON)
.filter(item3 -> item3.getLevel() == 1 && item3.getExp() == 0)
.filter(item3 -> !item3.isLocked() && !item3.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_artifacts.replace("{name}", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.weapons", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream()
.filter(item4 -> item4.getItemType() == ItemType.ITEM_FURNITURE)
.filter(item4 -> !item4.isLocked() && !item4.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_furniture.replace("{name}", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.furniture", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream()
.filter(item5 -> item5.getItemType() == ItemType.ITEM_DISPLAY)
.filter(item5 -> !item5.isLocked() && !item5.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_displays.replace("{name}", targetPlayer.getNickname()));
playerInventory.removeItems(toDelete);
CommandHandler.sendMessage(sender, translate("commands.clear.displays", targetPlayer.getNickname()));
toDelete = playerInventory.getItems().values().stream()
.filter(item6 -> item6.getItemType() == ItemType.ITEM_VIRTUAL)
.filter(item6 -> !item6.isLocked() && !item6.isEquipped())
.toList();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_virtuals.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Clear_everything.replace("{name}", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.virtuals", targetPlayer.getNickname()));
CommandHandler.sendMessage(sender, translate("commands.clear.everything", targetPlayer.getNickname()));
}
}
......
......@@ -7,39 +7,40 @@ import emu.grasscutter.game.player.Player;
import java.util.List;
@Command(label = "coop", usage = "coop [host UID]",
description = "Forces someone to join the world of others", permission = "server.coop")
import static emu.grasscutter.utils.Language.translate;
@Command(label = "coop", usage = "coop [host UID]", permission = "server.coop", description = "commands.coop.description")
public final class CoopCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
Player host = sender;
switch (args.size()) {
case 0: // Summon target to self
if (sender == null) { // Console doesn't have a self to summon to
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Coop_usage);
CommandHandler.sendMessage(sender, translate("commands.coop.usage"));
if (sender == null) // Console doesn't have a self to summon to
return;
}
break;
case 1: // Summon target to argument
try {
int hostId = Integer.parseInt(args.get(0));
host = Grasscutter.getGameServer().getPlayerByUid(hostId);
if (host == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_is_offline);
CommandHandler.sendMessage(sender, translate("commands.execution.player_offline_error"));
return;
}
break;
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
CommandHandler.sendMessage(sender, translate("commands.execution.uid_error"));
return;
}
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Coop_usage);
CommandHandler.sendMessage(sender, translate("commands.coop.usage"));
return;
}
......@@ -49,6 +50,6 @@ public final class CoopCommand implements CommandHandler {
}
host.getServer().getMultiplayerManager().applyEnterMp(targetPlayer, host.getUid());
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,14 +11,15 @@ import emu.grasscutter.utils.Position;
import java.util.List;
@Command(label = "drop", usage = "drop <itemId|itemName> [amount]",
description = "Drops an item near you", aliases = {"d", "dropitem"}, permission = "server.drop")
import static emu.grasscutter.utils.Language.translate;
@Command(label = "drop", usage = "drop <itemId|itemName> [amount]", aliases = {"d", "dropitem"}, permission = "server.drop", description = "commands.drop.description")
public final class DropCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(null, translate("commands.execution.need_target"));
return;
}
......@@ -30,25 +31,25 @@ public final class DropCommand implements CommandHandler {
try {
amount = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_amount);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.amount"));
return;
} // Slightly cheeky here: no break so it falls through to initialize the first argument too
} // Slightly cheeky here: no break, so it falls through to initialize the first argument too
case 1:
try {
item = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId"));
return;
}
break;
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Drop_usage);
CommandHandler.sendMessage(sender, translate("commands.drop.command_usage"));
return;
}
ItemData itemData = GameData.getItemDataMap().get(item);
if (itemData == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_item_id);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.itemId"));
return;
}
if (itemData.isEquip()) {
......@@ -62,6 +63,6 @@ public final class DropCommand implements CommandHandler {
EntityItem entity = new EntityItem(targetPlayer.getScene(), targetPlayer, itemData, targetPlayer.getPos().clone().addY(3f), amount);
targetPlayer.getScene().addEntity(entity);
}
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Drop_dropped_of.replace("{amount}", Integer.toString(amount)).replace("{item}", Integer.toString(item)));
CommandHandler.sendMessage(sender, translate("commands.drop.success", Integer.toString(amount), Integer.toString(item)));
}
}
\ No newline at end of file
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
import java.util.List;
@Command(label = "enterdungeon", usage = "enterdungeon <dungeon id>",
description = "Enter a dungeon", aliases = {"dungeon"}, permission = "player.enterdungeon")
import static emu.grasscutter.utils.Language.translate;
@Command(label = "enterdungeon", usage = "enterdungeon <dungeon id>", aliases = {"dungeon"}, permission = "player.enterdungeon", description = "commands.enter_dungeon.description")
public final class EnterDungeonCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(null, translate("commands.execution.need_target"));
return;
}
if (args.size() < 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_usage);
CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.usage"));
return;
}
try {
int dungeonId = Integer.parseInt(args.get(0));
if (dungeonId == targetPlayer.getSceneId()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_you_in_that_dungeon);
CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.in_dungeon_error"));
return;
}
boolean result = targetPlayer.getServer().getDungeonManager().enterDungeon(targetPlayer.getSession().getPlayer(), 0, dungeonId);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_changed_to_dungeon + dungeonId);
CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.changed", dungeonId));
if (!result) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_dungeon_not_found);
CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.not_found_error"));
}
} catch (Exception e) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().EnterDungeon_usage);
CommandHandler.sendMessage(sender, translate("commands.enter_dungeon.usage"));
}
}
}
......@@ -13,14 +13,15 @@ import emu.grasscutter.game.player.Player;
import java.util.*;
@Command(label = "giveall", usage = "giveall [amount]",
description = "Gives all items", aliases = {"givea"}, permission = "player.giveall", threading = true)
import static emu.grasscutter.utils.Language.translate;
@Command(label = "giveall", usage = "giveall [amount]", aliases = {"givea"}, permission = "player.giveall", threading = true, description = "commands.giveAll.description")
public final class GiveAllCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
return;
}
int amount = 99999;
......@@ -32,21 +33,21 @@ public final class GiveAllCommand implements CommandHandler {
try {
amount = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_amount);
CommandHandler.sendMessage(sender, translate("commands.generic.invalid.amount"));
return;
}
break;
default: // invalid
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().GiveAll_usage);
CommandHandler.sendMessage(sender, translate("commands.giveAll.usage"));
return;
}
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) {
CommandHandler.sendMessage(player, Grasscutter.getLanguage().GiveAll_item);
CommandHandler.sendMessage(player, translate("commands.giveAll.started"));
for (AvatarData avatarData: GameData.getAvatarDataMap().values()) {
//Exclude test avatar
......
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