mirror of
https://github.com/jie65535/gc-opencommand-plugin.git
synced 2025-12-15 19:31:35 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ded44804d4 | |||
| 4b8eb490f5 | |||
| 70261df520 | |||
| 5c2be0e776 | |||
| 72948121d6 | |||
| 42c748ad2e |
@@ -4,6 +4,11 @@
|
|||||||
|
|
||||||
一个为第三方客户端开放GC命令执行接口的插件
|
一个为第三方客户端开放GC命令执行接口的插件
|
||||||
|
|
||||||
|
## 使用本插件的应用
|
||||||
|
- [GrasscutterTools](https://github.com/jie65535/GrasscutterCommandGenerator) —— Windows 客户端工具
|
||||||
|
- [JGrasscutterCommand](https://github.com/jie65535/JGrasscutterCommand) —— [Mirai](https://github.com/mamoe/mirai) 插件,在QQ里执行命令
|
||||||
|
- 待补充
|
||||||
|
|
||||||
## 服务端安装
|
## 服务端安装
|
||||||
|
|
||||||
1. 在 [Release](https://github.com/jie65535/gc-opencommand-plugin/releases) 下载 `jar`
|
1. 在 [Release](https://github.com/jie65535/gc-opencommand-plugin/releases) 下载 `jar`
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
|
|
||||||
A plugin that opens the GC command execution interface for third-party clients
|
A plugin that opens the GC command execution interface for third-party clients
|
||||||
|
|
||||||
|
## Applications using this plug-in
|
||||||
|
- [GrasscutterTools](https://github.com/jie65535/GrasscutterCommandGenerator) —— Windows Client Tools
|
||||||
|
- [JGrasscutterCommand](https://github.com/jie65535/JGrasscutterCommand) —— [Mirai](https://github.com/mamoe/mirai) Plugin, run commands in QQ
|
||||||
|
- TODO
|
||||||
|
|
||||||
## Server installation
|
## Server installation
|
||||||
|
|
||||||
1. Download the `jar` in [Release](https://github.com/jie65535/gc-opencommand-plugin/releases)
|
1. Download the `jar` in [Release](https://github.com/jie65535/gc-opencommand-plugin/releases)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'com.github.jie65535.opencommand'
|
group 'com.github.jie65535.opencommand'
|
||||||
version 'dev-1.5.0'
|
version '1.5.1'
|
||||||
|
|
||||||
sourceCompatibility = 17
|
sourceCompatibility = 17
|
||||||
targetCompatibility = 17
|
targetCompatibility = 17
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ public final class OpenCommandHandler implements Router {
|
|||||||
private static final Map<String, Integer> codes = new HashMap<>();
|
private static final Map<String, Integer> codes = new HashMap<>();
|
||||||
private static final Int2ObjectMap<Date> codeExpireTime = new Int2ObjectOpenHashMap<>();
|
private static final Int2ObjectMap<Date> codeExpireTime = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
private static final Int2ObjectMap<MessageHandler> playerMessageHandlers = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
public static void handle(Context context) {
|
public static void handle(Context context) {
|
||||||
var plugin = OpenCommandPlugin.getInstance();
|
var plugin = OpenCommandPlugin.getInstance();
|
||||||
var config = plugin.getConfig();
|
var config = plugin.getConfig();
|
||||||
@@ -152,13 +154,18 @@ public final class OpenCommandHandler implements Router {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Player MessageHandler do not support concurrency
|
// Player MessageHandler do not support concurrency
|
||||||
|
var handler = playerMessageHandlers.get(player.getUid());
|
||||||
|
if (handler == null) {
|
||||||
|
handler = new MessageHandler();
|
||||||
|
playerMessageHandlers.put(player.getUid(), handler);
|
||||||
|
}
|
||||||
//noinspection SynchronizationOnLocalVariableOrMethodParameter
|
//noinspection SynchronizationOnLocalVariableOrMethodParameter
|
||||||
synchronized (player) {
|
synchronized (handler) {
|
||||||
try {
|
try {
|
||||||
var resultCollector = new MessageHandler();
|
handler.setMessage("");
|
||||||
player.setMessageHandler(resultCollector);
|
player.setMessageHandler(handler);
|
||||||
CommandMap.getInstance().invoke(player, player, command);
|
CommandMap.getInstance().invoke(player, player, command);
|
||||||
context.json(new JsonResponse(resultCollector.getMessage()));
|
context.json(new JsonResponse(handler.getMessage()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.getLogger().warn("Run command failed.", e);
|
plugin.getLogger().warn("Run command failed.", e);
|
||||||
context.json(new JsonResponse(500, "error", e.getLocalizedMessage()));
|
context.json(new JsonResponse(500, "error", e.getLocalizedMessage()));
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import emu.grasscutter.server.event.player.PlayerQuitEvent;
|
|||||||
import emu.grasscutter.utils.JsonUtils;
|
import emu.grasscutter.utils.JsonUtils;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public final class OpenCommandPlugin extends Plugin {
|
public final class OpenCommandPlugin extends Plugin {
|
||||||
|
|
||||||
@@ -106,7 +108,8 @@ public final class OpenCommandPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
config = JsonUtils.loadToClass(configFile.getAbsolutePath(), OpenCommandConfig.class);
|
config = JsonUtils.decode(Files.readString(configFile.toPath(), StandardCharsets.UTF_8),
|
||||||
|
OpenCommandConfig.class);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
config = new OpenCommandConfig();
|
config = new OpenCommandConfig();
|
||||||
getLogger().error("[OpenCommand] There was an error while trying to load the configuration from config.json. Please make sure that there are no syntax errors. If you want to start with a default configuration, delete your existing config.json.");
|
getLogger().error("[OpenCommand] There was an error while trying to load the configuration from config.json. Please make sure that there are no syntax errors. If you want to start with a default configuration, delete your existing config.json.");
|
||||||
@@ -126,7 +129,8 @@ public final class OpenCommandPlugin extends Plugin {
|
|||||||
saveData();
|
saveData();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
data = JsonUtils.loadToClass(dataFile.getAbsolutePath(), OpenCommandData.class);
|
data = JsonUtils.decode(Files.readString(dataFile.toPath(), StandardCharsets.UTF_8),
|
||||||
|
OpenCommandData.class);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
data = new OpenCommandData();
|
data = new OpenCommandData();
|
||||||
getLogger().error("[OpenCommand] There was an error while trying to load the data from data.json. Please make sure that there are no syntax errors. If you want to start with a default data, delete your existing data.json.");
|
getLogger().error("[OpenCommand] There was an error while trying to load the data from data.json. Please make sure that there are no syntax errors. If you want to start with a default data, delete your existing data.json.");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "opencommand-plugin",
|
"name": "opencommand-plugin",
|
||||||
"description": "Open command interface for third-party clients",
|
"description": "Open command interface for third-party clients",
|
||||||
"version": "dev-1.5.0",
|
"version": "dev-1.5.1",
|
||||||
"mainClass": "com.github.jie65535.opencommand.OpenCommandPlugin",
|
"mainClass": "com.github.jie65535.opencommand.OpenCommandPlugin",
|
||||||
"authors": ["jie65535", "方块君"]
|
"authors": ["jie65535", "方块君"]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user