mirror of
https://github.com/jie65535/gc-openchat-plugin.git
synced 2025-06-01 17:29:11 +08:00
Fix data.json decode issue
This commit is contained in:
parent
8202428564
commit
e0007e9eb3
@ -13,10 +13,6 @@ dependencies {
|
|||||||
implementation fileTree(dir: 'lib', include: ['*.jar'])
|
implementation fileTree(dir: 'lib', include: ['*.jar'])
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
jar.baseName = 'openchat'
|
jar.baseName = 'openchat'
|
||||||
|
|
||||||
|
@ -3,11 +3,20 @@ package com.github.jie65535.openchat;
|
|||||||
import emu.grasscutter.server.event.player.PlayerJoinEvent;
|
import emu.grasscutter.server.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
public final class EventListeners {
|
public final class EventListeners {
|
||||||
|
private static final OpenChatPlugin plugin = OpenChatPlugin.getInstance();
|
||||||
private static final OpenChatConfig config = OpenChatPlugin.getInstance().getConfig();
|
private static final OpenChatConfig config = OpenChatPlugin.getInstance().getConfig();
|
||||||
|
|
||||||
public static void onJoin(PlayerJoinEvent event) {
|
public static void onJoin(PlayerJoinEvent event) {
|
||||||
if (!config.sendJoinMessage || config.joinMessage.isEmpty()) return;
|
// 检查聊天系统是否被其它插件替换
|
||||||
|
if (!(plugin.getServer().getChatSystem() instanceof OpenChatSystem)) {
|
||||||
|
plugin.getLogger().warn("聊天系统已被其它插件更改,现已重置为 OpenChat !");
|
||||||
|
plugin.getServer().setChatSystem(new OpenChatSystem(plugin));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!config.sendJoinMessage || config.joinMessage.isEmpty())
|
||||||
|
return;
|
||||||
|
plugin.getLogger().debug(String.format("玩家 %s(%d) 加入游戏,发送加入消息",
|
||||||
|
event.getPlayer().getNickname(), event.getPlayer().getUid()));
|
||||||
event.getPlayer().dropMessage(config.joinMessage);
|
event.getPlayer().dropMessage(config.joinMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.github.jie65535.openchat;
|
package com.github.jie65535.openchat;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
|
||||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
public class OpenChatData {
|
public class OpenChatData {
|
||||||
|
|
||||||
@ -31,11 +28,11 @@ public class OpenChatData {
|
|||||||
* Key: Uid
|
* Key: Uid
|
||||||
* Value: End time
|
* Value: End time
|
||||||
*/
|
*/
|
||||||
public Int2ObjectMap<Date> banList = new Int2ObjectOpenHashMap<>();
|
public HashMap<Integer, Date> banList = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 关闭聊天的玩家集合
|
* 关闭聊天的玩家集合
|
||||||
* Key: Uid
|
* Key: Uid
|
||||||
*/
|
*/
|
||||||
public IntSet offChatPlayers = new IntOpenHashSet();
|
public HashSet<Integer> offChatPlayers = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ import java.io.File;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public final class OpenChatPlugin extends Plugin {
|
public final class OpenChatPlugin extends Plugin {
|
||||||
@ -55,7 +54,7 @@ public final class OpenChatPlugin extends Plugin {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
config = JsonUtils.decode(Files.readString(configFile.toPath(), StandardCharsets.UTF_8), OpenChatConfig.class);
|
config = JsonUtils.loadToClass(configFile.toPath(), OpenChatConfig.class);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
config = new OpenChatConfig();
|
config = new OpenChatConfig();
|
||||||
getLogger().error("[OpenChat] 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.", exception);
|
getLogger().error("[OpenChat] 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.", exception);
|
||||||
@ -74,7 +73,7 @@ public final class OpenChatPlugin extends Plugin {
|
|||||||
saveData();
|
saveData();
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
data = JsonUtils.decode(Files.readString(dataFile.toPath(), StandardCharsets.UTF_8), OpenChatData.class);
|
data = JsonUtils.loadToClass(dataFile.toPath(), OpenChatData.class);
|
||||||
} catch (Exception exception) {
|
} catch (Exception exception) {
|
||||||
data = new OpenChatData();
|
data = new OpenChatData();
|
||||||
getLogger().error("[OpenChat] 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.", exception);
|
getLogger().error("[OpenChat] 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.", exception);
|
||||||
@ -112,7 +111,7 @@ public final class OpenChatPlugin extends Plugin {
|
|||||||
getHandle().registerCommand(new ChatPlayerCommands());
|
getHandle().registerCommand(new ChatPlayerCommands());
|
||||||
|
|
||||||
// Set my chat system.
|
// Set my chat system.
|
||||||
getServer().setChatSystem(new OpenChatSystem(getServer(), this));
|
getServer().setChatSystem(new OpenChatSystem(this));
|
||||||
|
|
||||||
// Log a plugin status message.
|
// Log a plugin status message.
|
||||||
getLogger().info("[OpenChat] Enabled.");
|
getLogger().info("[OpenChat] Enabled.");
|
||||||
@ -131,6 +130,6 @@ public final class OpenChatPlugin extends Plugin {
|
|||||||
if (getData().banList.isEmpty())
|
if (getData().banList.isEmpty())
|
||||||
return;
|
return;
|
||||||
var now = new Date();
|
var now = new Date();
|
||||||
getData().banList.int2ObjectEntrySet().removeIf(entry -> entry.getValue().before(now));
|
getData().banList.entrySet().removeIf(entry -> entry.getValue().before(now));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,18 @@ package com.github.jie65535.openchat;
|
|||||||
import emu.grasscutter.GameConstants;
|
import emu.grasscutter.GameConstants;
|
||||||
import emu.grasscutter.game.chat.ChatSystem;
|
import emu.grasscutter.game.chat.ChatSystem;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
import emu.grasscutter.server.game.GameServer;
|
|
||||||
|
|
||||||
public class OpenChatSystem extends ChatSystem {
|
public class OpenChatSystem extends ChatSystem {
|
||||||
private final OpenChatPlugin plugin;
|
private final OpenChatPlugin plugin;
|
||||||
public OpenChatSystem(GameServer server, OpenChatPlugin plugin) {
|
public OpenChatSystem(OpenChatPlugin plugin) {
|
||||||
super(server);
|
super(plugin.getServer());
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
plugin.getLogger().debug("OpenChatSystem created.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendPrivateMessage(Player player, int targetUid, String message) {
|
public void sendPrivateMessage(Player player, int targetUid, String message) {
|
||||||
plugin.getLogger().info(String.format("onSendPrivateMessage: player=%s(%d) targetUid=%d message=%s",
|
plugin.getLogger().debug(String.format("onSendPrivateMessage: player=%s(%d) targetUid=%d message=%s",
|
||||||
player.getNickname(), player.getUid(), targetUid, message));
|
player.getNickname(), player.getUid(), targetUid, message));
|
||||||
// Sanity checks.
|
// Sanity checks.
|
||||||
if (message == null || message.length() == 0) {
|
if (message == null || message.length() == 0) {
|
||||||
@ -35,7 +35,7 @@ public class OpenChatSystem extends ChatSystem {
|
|||||||
* @param message 消息内容
|
* @param message 消息内容
|
||||||
*/
|
*/
|
||||||
private void handlePlayerMessage(Player player, String message) {
|
private void handlePlayerMessage(Player player, String message) {
|
||||||
plugin.getLogger().info("handlePlayerMessage enter");
|
plugin.getLogger().debug("handlePlayerMessage enter");
|
||||||
if (!plugin.getConfig().serverChatEnabled) {
|
if (!plugin.getConfig().serverChatEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user