Impl join message

This commit is contained in:
2023-01-13 19:45:22 +08:00
parent d9474e73bd
commit 9b08c1cc48
5 changed files with 118 additions and 26 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
package com.github.jie65535.openchat; 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 { //public final class EventListeners {
private static final OpenChatPlugin plugin = OpenChatPlugin.getInstance(); // 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 (!(plugin.getServer().getChatSystem() instanceof OpenChatSystem)) { //// if (!(plugin.getServer().getChatSystem() instanceof OpenChatSystem)) {
// plugin.getLogger().warn("聊天系统已被其它插件更改,现已重置为 OpenChat !"); //// plugin.getLogger().warn("聊天系统已被其它插件更改,现已重置为 OpenChat !");
// plugin.getServer().setChatSystem(new OpenChatSystem(plugin)); //// 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);
// }
//} //}
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);
}
}

View File

@ -20,9 +20,6 @@ package com.github.jie65535.openchat;
import com.github.jie65535.openchat.commands.ChatPlayerCommands; import com.github.jie65535.openchat.commands.ChatPlayerCommands;
import com.github.jie65535.openchat.commands.ChatServerCommands; import com.github.jie65535.openchat.commands.ChatServerCommands;
import emu.grasscutter.plugin.Plugin; 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 emu.grasscutter.utils.JsonUtils;
import java.io.File; import java.io.File;
@ -104,10 +101,10 @@ public final class OpenChatPlugin extends Plugin {
@Override @Override
public void onEnable() { public void onEnable() {
// Register event listeners. // Register event listeners.
new EventHandler<>(PlayerJoinEvent.class) // new EventHandler<>(PlayerJoinEvent.class)
.priority(HandlerPriority.NORMAL) // .priority(HandlerPriority.NORMAL)
.listener(EventListeners::onJoin) // .listener(EventListeners::onJoin)
.register(this); // .register(this);
// Register commands. // Register commands.
getHandle().registerCommand(new ChatServerCommands()); getHandle().registerCommand(new ChatServerCommands());

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
package com.github.jie65535.openchat; package com.github.jie65535.openchat;
import emu.grasscutter.GameConstants; import emu.grasscutter.GameConstants;
@ -5,6 +22,8 @@ import emu.grasscutter.game.chat.ChatSystem;
import emu.grasscutter.game.player.Player; import emu.grasscutter.game.player.Player;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; 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; import it.unimi.dsi.fastutil.longs.LongArrayFIFOQueue;
public class OpenChatSystem extends ChatSystem { public class OpenChatSystem extends ChatSystem {
@ -15,6 +34,27 @@ public class OpenChatSystem extends ChatSystem {
plugin.getLogger().debug("OpenChatSystem created."); 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 @Override
public void sendPrivateMessage(Player player, int targetUid, String message) { public void sendPrivateMessage(Player player, int targetUid, String message) {
plugin.getLogger().debug(String.format("onSendPrivateMessage: player=%s(%d) targetUid=%d message=%s", plugin.getLogger().debug(String.format("onSendPrivateMessage: player=%s(%d) targetUid=%d message=%s",

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
package com.github.jie65535.openchat.commands; package com.github.jie65535.openchat.commands;
import com.github.jie65535.openchat.OpenChatPlugin; import com.github.jie65535.openchat.OpenChatPlugin;

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
package com.github.jie65535.openchat.commands; package com.github.jie65535.openchat.commands;
import com.github.jie65535.openchat.OpenChatPlugin; import com.github.jie65535.openchat.OpenChatPlugin;