diff --git a/src/main/java/com/github/jie65535/openchat/EventListeners.java b/src/main/java/com/github/jie65535/openchat/EventListeners.java
index 3ea9cb5..06a3da6 100644
--- a/src/main/java/com/github/jie65535/openchat/EventListeners.java
+++ b/src/main/java/com/github/jie65535/openchat/EventListeners.java
@@ -1,23 +1,44 @@
+/*
+ * gc-openchat
+ * Copyright (C) 2022 jie65535
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
package com.github.jie65535.openchat;
-import emu.grasscutter.server.event.player.PlayerJoinEvent;
+//import emu.grasscutter.server.event.player.PlayerJoinEvent;
+//import emu.grasscutter.server.scheduler.ServerTaskScheduler;
-public final class EventListeners {
- private static final OpenChatPlugin plugin = OpenChatPlugin.getInstance();
- private static final OpenChatConfig config = OpenChatPlugin.getInstance().getConfig();
+//public final class EventListeners {
+// private static final OpenChatPlugin plugin = OpenChatPlugin.getInstance();
+// private static final OpenChatConfig config = OpenChatPlugin.getInstance().getConfig();
- public static void onJoin(PlayerJoinEvent event) {
- // 检查聊天系统是否被其它插件替换
- // 不再检查
-// 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("Player %s(%d) joined the game, send join message.",
- event.getPlayer().getNickname(), event.getPlayer().getUid()));
- event.getPlayer().dropMessage(config.joinMessage);
- }
-}
+// public static void onJoin(PlayerJoinEvent event) {
+// // 检查聊天系统是否被其它插件替换
+// // 不再检查
+//// if (!(plugin.getServer().getChatSystem() instanceof OpenChatSystem)) {
+//// plugin.getLogger().warn("聊天系统已被其它插件更改,现已重置为 OpenChat !");
+//// plugin.getServer().setChatSystem(new OpenChatSystem(plugin));
+//// }
+//
+// if (!config.sendJoinMessage || config.joinMessage.isEmpty())
+// return;
+// var player = event.getPlayer();
+// plugin.getLogger().debug(String.format("Player %s(%d) joined the game, send join message.",
+// player.getNickname(), player.getUid()));
+// plugin.getServer().getScheduler().scheduleDelayedTask(() -> {
+// if (player.isOnline()) player.dropMessage(config.joinMessage);
+// }, 60);
+// }
+//}
diff --git a/src/main/java/com/github/jie65535/openchat/OpenChatPlugin.java b/src/main/java/com/github/jie65535/openchat/OpenChatPlugin.java
index 1b4012a..d5ffd67 100644
--- a/src/main/java/com/github/jie65535/openchat/OpenChatPlugin.java
+++ b/src/main/java/com/github/jie65535/openchat/OpenChatPlugin.java
@@ -20,9 +20,6 @@ package com.github.jie65535.openchat;
import com.github.jie65535.openchat.commands.ChatPlayerCommands;
import com.github.jie65535.openchat.commands.ChatServerCommands;
import emu.grasscutter.plugin.Plugin;
-import emu.grasscutter.server.event.EventHandler;
-import emu.grasscutter.server.event.HandlerPriority;
-import emu.grasscutter.server.event.player.PlayerJoinEvent;
import emu.grasscutter.utils.JsonUtils;
import java.io.File;
@@ -104,10 +101,10 @@ public final class OpenChatPlugin extends Plugin {
@Override
public void onEnable() {
// Register event listeners.
- new EventHandler<>(PlayerJoinEvent.class)
- .priority(HandlerPriority.NORMAL)
- .listener(EventListeners::onJoin)
- .register(this);
+// new EventHandler<>(PlayerJoinEvent.class)
+// .priority(HandlerPriority.NORMAL)
+// .listener(EventListeners::onJoin)
+// .register(this);
// Register commands.
getHandle().registerCommand(new ChatServerCommands());
diff --git a/src/main/java/com/github/jie65535/openchat/OpenChatSystem.java b/src/main/java/com/github/jie65535/openchat/OpenChatSystem.java
index 4d11a18..c19a77c 100644
--- a/src/main/java/com/github/jie65535/openchat/OpenChatSystem.java
+++ b/src/main/java/com/github/jie65535/openchat/OpenChatSystem.java
@@ -1,3 +1,20 @@
+/*
+ * gc-openchat
+ * Copyright (C) 2022 jie65535
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
package com.github.jie65535.openchat;
import emu.grasscutter.GameConstants;
@@ -5,6 +22,8 @@ import emu.grasscutter.game.chat.ChatSystem;
import emu.grasscutter.game.player.Player;
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 it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue;
public class OpenChatSystem extends ChatSystem {
@@ -15,6 +34,27 @@ public class OpenChatSystem extends ChatSystem {
plugin.getLogger().debug("OpenChatSystem created.");
}
+ IntSet hasHistory = new IntOpenHashSet();
+
+ @Override
+ public void clearHistoryOnLogout(Player player) {
+ super.clearHistoryOnLogout(player);
+ hasHistory.remove(player.getUid());
+ }
+
+ @Override
+ public void handlePullRecentChatReq(Player player) {
+ super.handlePullRecentChatReq(player);
+ if (!hasHistory.contains(player.getUid())) {
+ hasHistory.add(player.getUid());
+ if (plugin.getConfig().sendJoinMessage && !plugin.getConfig().joinMessage.isEmpty()) {
+ plugin.getLogger().debug(String.format("send join message to %s(%d)",
+ player.getNickname(), player.getUid()));
+ player.dropMessage(plugin.getConfig().joinMessage);
+ }
+ }
+ }
+
@Override
public void sendPrivateMessage(Player player, int targetUid, String message) {
plugin.getLogger().debug(String.format("onSendPrivateMessage: player=%s(%d) targetUid=%d message=%s",
diff --git a/src/main/java/com/github/jie65535/openchat/commands/ChatPlayerCommands.java b/src/main/java/com/github/jie65535/openchat/commands/ChatPlayerCommands.java
index 2a5fa81..ca09524 100644
--- a/src/main/java/com/github/jie65535/openchat/commands/ChatPlayerCommands.java
+++ b/src/main/java/com/github/jie65535/openchat/commands/ChatPlayerCommands.java
@@ -1,3 +1,20 @@
+/*
+ * gc-openchat
+ * Copyright (C) 2022 jie65535
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
package com.github.jie65535.openchat.commands;
import com.github.jie65535.openchat.OpenChatPlugin;
diff --git a/src/main/java/com/github/jie65535/openchat/commands/ChatServerCommands.java b/src/main/java/com/github/jie65535/openchat/commands/ChatServerCommands.java
index e522731..2789dd9 100644
--- a/src/main/java/com/github/jie65535/openchat/commands/ChatServerCommands.java
+++ b/src/main/java/com/github/jie65535/openchat/commands/ChatServerCommands.java
@@ -1,3 +1,20 @@
+/*
+ * gc-openchat
+ * Copyright (C) 2022 jie65535
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
package com.github.jie65535.openchat.commands;
import com.github.jie65535.openchat.OpenChatPlugin;