mirror of
https://github.com/jie65535/gc-openchat-plugin.git
synced 2025-06-01 17:29:11 +08:00
Add logs
This commit is contained in:
parent
560a5e25f0
commit
ec347e2eab
@ -46,7 +46,7 @@ public final class OpenChatPlugin extends Plugin {
|
|||||||
var configFile = new File(getDataFolder(), "config.json");
|
var configFile = new File(getDataFolder(), "config.json");
|
||||||
if (!configFile.exists()) {
|
if (!configFile.exists()) {
|
||||||
config = new OpenChatConfig();
|
config = new OpenChatConfig();
|
||||||
try (var file = new FileWriter(configFile)) {
|
try (var file = new FileWriter(configFile, StandardCharsets.UTF_8)) {
|
||||||
file.write(JsonUtils.encode(config));
|
file.write(JsonUtils.encode(config));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
getLogger().error("[OpenChat] Unable to write to config file.");
|
getLogger().error("[OpenChat] Unable to write to config file.");
|
||||||
@ -58,7 +58,7 @@ public final class OpenChatPlugin extends Plugin {
|
|||||||
config = JsonUtils.decode(Files.readString(configFile.toPath(), StandardCharsets.UTF_8), OpenChatConfig.class);
|
config = JsonUtils.decode(Files.readString(configFile.toPath(), StandardCharsets.UTF_8), 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.");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,7 +68,6 @@ public final class OpenChatPlugin extends Plugin {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
private void loadData() {
|
private void loadData() {
|
||||||
data = new OpenChatData();
|
|
||||||
var dataFile = new File(getDataFolder(), "data.json");
|
var dataFile = new File(getDataFolder(), "data.json");
|
||||||
if (!dataFile.exists()) {
|
if (!dataFile.exists()) {
|
||||||
data = new OpenChatData();
|
data = new OpenChatData();
|
||||||
@ -78,12 +77,12 @@ public final class OpenChatPlugin extends Plugin {
|
|||||||
data = JsonUtils.decode(Files.readString(dataFile.toPath(), StandardCharsets.UTF_8), OpenChatData.class);
|
data = JsonUtils.decode(Files.readString(dataFile.toPath(), StandardCharsets.UTF_8), 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.");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void saveData() {
|
public void saveData() {
|
||||||
try (var file = new FileWriter(new File(getDataFolder(), "data.json"))) {
|
try (var file = new FileWriter(new File(getDataFolder(), "data.json"), StandardCharsets.UTF_8)) {
|
||||||
file.write(JsonUtils.encode(data));
|
file.write(JsonUtils.encode(data));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
getLogger().error("[OpenChat] Unable to write to data file.");
|
getLogger().error("[OpenChat] Unable to write to data file.");
|
||||||
@ -112,6 +111,7 @@ public final class OpenChatPlugin extends Plugin {
|
|||||||
getHandle().registerCommand(new ChatServerCommands());
|
getHandle().registerCommand(new ChatServerCommands());
|
||||||
getHandle().registerCommand(new ChatPlayerCommands());
|
getHandle().registerCommand(new ChatPlayerCommands());
|
||||||
|
|
||||||
|
// Set my chat system.
|
||||||
getServer().setChatSystem(new OpenChatSystem(getServer(), this));
|
getServer().setChatSystem(new OpenChatSystem(getServer(), this));
|
||||||
|
|
||||||
// Log a plugin status message.
|
// Log a plugin status message.
|
||||||
|
@ -14,6 +14,8 @@ public class OpenChatSystem extends ChatSystem {
|
|||||||
|
|
||||||
@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",
|
||||||
|
player.getNickname(), player.getUid(), targetUid, message));
|
||||||
// Sanity checks.
|
// Sanity checks.
|
||||||
if (message == null || message.length() == 0) {
|
if (message == null || message.length() == 0) {
|
||||||
return;
|
return;
|
||||||
@ -33,6 +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");
|
||||||
if (!plugin.getConfig().serverChatEnabled) {
|
if (!plugin.getConfig().serverChatEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -45,6 +48,8 @@ public class OpenChatSystem extends ChatSystem {
|
|||||||
// 处理发言频率限制与发言内容审查
|
// 处理发言频率限制与发言内容审查
|
||||||
if (!checkMessageFre(player) || !checkMessageModeration(message)) {
|
if (!checkMessageFre(player) || !checkMessageModeration(message)) {
|
||||||
// 可提示也可忽略,忽略可让玩家以为自己发送成功,其实别人看不到
|
// 可提示也可忽略,忽略可让玩家以为自己发送成功,其实别人看不到
|
||||||
|
plugin.getLogger().warn(String.format("Message blocked: player=%s(%d): \"%s\"",
|
||||||
|
player.getNickname(), player.getUid(), message));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 格式化消息
|
// 格式化消息
|
||||||
@ -55,7 +60,7 @@ public class OpenChatSystem extends ChatSystem {
|
|||||||
// 转发给其它玩家
|
// 转发给其它玩家
|
||||||
for (Player p : getServer().getPlayers().values()) {
|
for (Player p : getServer().getPlayers().values()) {
|
||||||
// 将消息发送给除了自己以外所有未关闭聊天的玩家
|
// 将消息发送给除了自己以外所有未关闭聊天的玩家
|
||||||
if (p != player && plugin.getData().offChatPlayers.contains(p.getUid())) {
|
if (p != player && !plugin.getData().offChatPlayers.contains(p.getUid())) {
|
||||||
p.dropMessage(message);
|
p.dropMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user