mirror of
https://github.com/jie65535/gc-openchat-plugin.git
synced 2025-06-01 17:29:11 +08:00
Impl join message
This commit is contained in:
parent
d9474e73bd
commit
9b08c1cc48
@ -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;
|
||||
|
||||
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);
|
||||
// }
|
||||
//}
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
||||
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",
|
||||
|
@ -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;
|
||||
|
||||
import com.github.jie65535.openchat.OpenChatPlugin;
|
||||
|
@ -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;
|
||||
|
||||
import com.github.jie65535.openchat.OpenChatPlugin;
|
||||
|
Loading…
Reference in New Issue
Block a user