diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ad93547..6319b2d 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -21,7 +21,7 @@ jobs: cache: 'maven' - name: Build run: mvn -V -B clean package --file pom.xml - - name: Upload Artifacts + - name: Upload Bukkit Artifacts uses: actions/upload-artifact@v3.1.2 with: name: Download-Bukkit @@ -31,6 +31,11 @@ jobs: with: name: Download-Velocity path: ./velocity/target/AdvancedSensitiveWords-velocity.jar + - name: Upload BungeeCord Artifacts + uses: actions/upload-artifact@v3.1.2 + with: + name: Download-BungeeCord + path: ./bungee/target/AdvancedSensitiveWords-bungee.jar runtime-test: name: Plugin Runtime Test needs: [Build] diff --git a/README.md b/README.md index 3390fc0..0ec8f6d 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Logo designed by GPT-4 ## Supported Platforms - Spigot(stable) - Velocity(experimental) -- BungeeCord(WIP) +- BungeeCord(experimental) - Sponge(WIP) - Fabric(Planned) - Forge/NeoForge(Coming s∞n) diff --git a/README_zh.md b/README_zh.md index 50042a0..1c077bd 100644 --- a/README_zh.md +++ b/README_zh.md @@ -80,7 +80,7 @@ Logo 由 GPT-4 生成 ## 支持平台 - Spigot(稳定) - Velocity(测试) -- BungeeCord(在做了在做了) +- BungeeCord(测试) - Sponge(在做了在做了) - Fabric(计划中) - Forge/NeoForge(Coming s∞n) diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/AdvancedSensitiveWords.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/AdvancedSensitiveWords.java index 5918bcc..8e33b71 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/AdvancedSensitiveWords.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/AdvancedSensitiveWords.java @@ -19,6 +19,8 @@ import io.wdsj.asw.bukkit.listener.packet.ASWPacketListener; import io.wdsj.asw.bukkit.listener.packet.ProtocolLibListener; import io.wdsj.asw.bukkit.method.*; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeCordChannel; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeReceiver; import io.wdsj.asw.bukkit.proxy.velocity.VelocityChannel; import io.wdsj.asw.bukkit.proxy.velocity.VelocityReceiver; import io.wdsj.asw.bukkit.setting.PluginMessages; @@ -134,6 +136,10 @@ public void onEnable() { getServer().getMessenger().registerOutgoingPluginChannel(this, VelocityChannel.CHANNEL); getServer().getMessenger().registerIncomingPluginChannel(this, VelocityChannel.CHANNEL, new VelocityReceiver()); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + getServer().getMessenger().registerOutgoingPluginChannel(this, BungeeCordChannel.BUNGEE_CHANNEL); + getServer().getMessenger().registerIncomingPluginChannel(this, BungeeCordChannel.BUNGEE_CHANNEL, new BungeeReceiver()); + } long endTime = System.currentTimeMillis(); logger.info("AdvancedSensitiveWords is enabled!(took " + (endTime - startTime) + "ms)"); if (settingsManager.getProperty(PluginSettings.CHECK_FOR_UPDATE)) { @@ -177,6 +183,11 @@ public void onDisable() { } else { com.comphenix.protocol.ProtocolLibrary.getProtocolManager().removePacketListeners(this); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD) || + settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + getServer().getMessenger().unregisterOutgoingPluginChannel(this); + getServer().getMessenger().unregisterIncomingPluginChannel(this); + } TimingUtils.cleanStatisticCache(); ChatContext.forceClearContext(); BookCache.forceClearCache(); diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/AnvilListener.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/AnvilListener.java index fbfbe30..1d2e809 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/AnvilListener.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/AnvilListener.java @@ -5,6 +5,7 @@ import io.wdsj.asw.bukkit.event.EventType; import io.wdsj.asw.bukkit.manage.notice.Notifier; import io.wdsj.asw.bukkit.manage.punish.Punishment; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender; import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender; import io.wdsj.asw.bukkit.setting.PluginMessages; import io.wdsj.asw.bukkit.setting.PluginSettings; @@ -71,6 +72,11 @@ public void onAnvil(InventoryClickEvent event) { if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.ANVIL, originalItemName); } + + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.ANVIL, originalItemName); + } + long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.ANVIL, originalItemName); diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/BookListener.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/BookListener.java index f815b62..9b76d24 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/BookListener.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/BookListener.java @@ -6,6 +6,7 @@ import io.wdsj.asw.bukkit.impl.list.AdvancedList; import io.wdsj.asw.bukkit.manage.notice.Notifier; import io.wdsj.asw.bukkit.manage.punish.Punishment; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender; import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender; import io.wdsj.asw.bukkit.setting.PluginMessages; import io.wdsj.asw.bukkit.setting.PluginSettings; @@ -115,6 +116,9 @@ public void onBook(PlayerEditBookEvent event) { if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.BOOK, outMessage); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.BOOK, outMessage); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.BOOK, outMessage); diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/ChatListener.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/ChatListener.java index 51d7b25..261a03d 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/ChatListener.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/ChatListener.java @@ -5,6 +5,7 @@ import io.wdsj.asw.bukkit.event.EventType; import io.wdsj.asw.bukkit.manage.notice.Notifier; import io.wdsj.asw.bukkit.manage.punish.Punishment; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender; import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender; import io.wdsj.asw.bukkit.setting.PluginMessages; import io.wdsj.asw.bukkit.setting.PluginSettings; @@ -63,6 +64,9 @@ public void onChat(AsyncPlayerChatEvent event) { if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.CHAT, originalMessage); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.CHAT, originalMessage); + } long endTime = System.currentTimeMillis(); TimingUtils.addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { @@ -99,6 +103,9 @@ public void onChat(AsyncPlayerChatEvent event) { if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.CHAT, originalContext); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.CHAT, originalContext); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/CommandListener.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/CommandListener.java index 794c4d7..f0ce496 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/CommandListener.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/CommandListener.java @@ -4,6 +4,7 @@ import io.wdsj.asw.bukkit.event.EventType; import io.wdsj.asw.bukkit.manage.notice.Notifier; import io.wdsj.asw.bukkit.manage.punish.Punishment; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender; import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender; import io.wdsj.asw.bukkit.setting.PluginMessages; import io.wdsj.asw.bukkit.setting.PluginSettings; @@ -55,6 +56,9 @@ public void onCommand(PlayerCommandPreprocessEvent event) { if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.CHAT, originalCommand); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.CHAT, originalCommand); + } long endTime = System.currentTimeMillis(); TimingUtils.addProcessStatistic(endTime, startTime); if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.CHAT, originalCommand); diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/PlayerItemListener.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/PlayerItemListener.java index f185359..6e1913a 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/PlayerItemListener.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/PlayerItemListener.java @@ -4,6 +4,7 @@ import io.wdsj.asw.bukkit.event.EventType; import io.wdsj.asw.bukkit.manage.notice.Notifier; import io.wdsj.asw.bukkit.manage.punish.Punishment; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender; import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender; import io.wdsj.asw.bukkit.setting.PluginMessages; import io.wdsj.asw.bukkit.setting.PluginSettings; @@ -101,6 +102,9 @@ public void onDrop(PlayerDropItemEvent event) { if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.ITEM, originalName); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.ITEM, originalName); + } long endTime = System.currentTimeMillis(); TimingUtils.addProcessStatistic(endTime, startTime); if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.ITEM, originalName); diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/PlayerLoginListener.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/PlayerLoginListener.java index dd424f0..db05906 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/PlayerLoginListener.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/PlayerLoginListener.java @@ -5,6 +5,7 @@ import io.wdsj.asw.bukkit.event.EventType; import io.wdsj.asw.bukkit.manage.notice.Notifier; import io.wdsj.asw.bukkit.manage.punish.Punishment; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender; import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender; import io.wdsj.asw.bukkit.setting.PluginMessages; import io.wdsj.asw.bukkit.setting.PluginSettings; @@ -59,6 +60,9 @@ public void onLogin(PlayerLoginEvent event) { if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.NAME, playerName); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.NAME, playerName); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.NAME, playerName); diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/SignListener.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/SignListener.java index da5b1f9..ab63dc2 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/SignListener.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/SignListener.java @@ -7,6 +7,7 @@ import io.wdsj.asw.bukkit.impl.list.AdvancedList; import io.wdsj.asw.bukkit.manage.notice.Notifier; import io.wdsj.asw.bukkit.manage.punish.Punishment; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender; import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender; import io.wdsj.asw.bukkit.setting.PluginMessages; import io.wdsj.asw.bukkit.setting.PluginSettings; @@ -96,7 +97,11 @@ public void onSign(SignChangeEvent event) { } if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY) && shouldSendMessage) { - VelocitySender.send(player, EventType.CHAT, outMessage); + VelocitySender.send(player, EventType.SIGN, outMessage); + } + + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.SIGN, outMessage); } if (shouldSendMessage) { diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/packet/ASWPacketListener.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/packet/ASWPacketListener.java index b6f167c..c74df35 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/packet/ASWPacketListener.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/packet/ASWPacketListener.java @@ -13,6 +13,7 @@ import io.wdsj.asw.bukkit.event.EventType; import io.wdsj.asw.bukkit.manage.notice.Notifier; import io.wdsj.asw.bukkit.manage.punish.Punishment; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender; import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender; import io.wdsj.asw.bukkit.setting.PluginMessages; import io.wdsj.asw.bukkit.setting.PluginSettings; @@ -79,6 +80,9 @@ public void onPacketReceive(PacketReceiveEvent event) { if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.CHAT, originalMessage); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.CHAT, originalMessage); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { @@ -115,6 +119,9 @@ public void onPacketReceive(PacketReceiveEvent event) { if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.CHAT, originalContext); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.CHAT, originalContext); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(() -> { @@ -154,6 +161,9 @@ public void onPacketReceive(PacketReceiveEvent event) { if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.CHAT, originalCommand); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.CHAT, originalCommand); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/packet/ProtocolLibListener.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/packet/ProtocolLibListener.java index cf90be3..cab4517 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/packet/ProtocolLibListener.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/listener/packet/ProtocolLibListener.java @@ -5,6 +5,7 @@ import io.wdsj.asw.bukkit.event.EventType; import io.wdsj.asw.bukkit.manage.notice.Notifier; import io.wdsj.asw.bukkit.manage.punish.Punishment; +import io.wdsj.asw.bukkit.proxy.bungee.BungeeSender; import io.wdsj.asw.bukkit.proxy.velocity.VelocitySender; import io.wdsj.asw.bukkit.setting.PluginMessages; import io.wdsj.asw.bukkit.setting.PluginSettings; @@ -77,6 +78,9 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.CHAT, message); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.CHAT, message); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { @@ -110,6 +114,9 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { VelocitySender.send(player, EventType.CHAT, originalContext); } + if (settingsManager.getProperty(PluginSettings.HOOK_BUNGEECORD)) { + BungeeSender.send(player, EventType.CHAT, originalContext); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/proxy/bungee/BungeeCordChannel.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/proxy/bungee/BungeeCordChannel.java new file mode 100644 index 0000000..c539fee --- /dev/null +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/proxy/bungee/BungeeCordChannel.java @@ -0,0 +1,6 @@ +package io.wdsj.asw.bukkit.proxy.bungee; + +public class BungeeCordChannel { + public static final String BUNGEE_CHANNEL = "BungeeCord"; + public static final String SUB_CHANNEL = "asw"; +} diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/proxy/bungee/BungeeReceiver.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/proxy/bungee/BungeeReceiver.java new file mode 100644 index 0000000..9368ce5 --- /dev/null +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/proxy/bungee/BungeeReceiver.java @@ -0,0 +1,40 @@ +package io.wdsj.asw.bukkit.proxy.bungee; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteStreams; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.plugin.messaging.PluginMessageListener; + +import java.util.Collection; + +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.messagesManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager; + +public class BungeeReceiver implements PluginMessageListener { + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] message) { + if (channel.equals(BungeeCordChannel.BUNGEE_CHANNEL)) { + ByteArrayDataInput input = ByteStreams.newDataInput(message); + String subChannel = input.readUTF(); + if (subChannel.equals(BungeeCordChannel.SUB_CHANNEL)) { + String playerName = input.readUTF(); + String eventType = input.readUTF(); + String originalMessage = input.readUTF(); + String serverName = input.readUTF(); + if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) { + Collection players = Bukkit.getOnlinePlayers(); + String msg = ChatColor.translateAlternateColorCodes('&', messagesManager.getProperty(PluginMessages.ADMIN_REMINDER).replace("%player%", playerName + "(" + serverName + ")").replace("%type%", eventType).replace("%message%", originalMessage)); + for (Player iPlayer : players) { + if (iPlayer.hasPermission("advancedsensitivewords.notice")) { + iPlayer.sendMessage(msg); + } + } + } + } + } + } +} diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/proxy/bungee/BungeeSender.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/proxy/bungee/BungeeSender.java new file mode 100644 index 0000000..4307f22 --- /dev/null +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/proxy/bungee/BungeeSender.java @@ -0,0 +1,19 @@ +package io.wdsj.asw.bukkit.proxy.bungee; + +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.event.EventType; +import org.bukkit.entity.Player; + +public class BungeeSender { + public static void send(Player violatedPlayer, EventType eventType, String originalMessage) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF(BungeeCordChannel.SUB_CHANNEL); + out.writeUTF(violatedPlayer.getName()); + out.writeUTF(eventType.toString()); + out.writeUTF(originalMessage); + byte[] data = out.toByteArray(); + violatedPlayer.sendPluginMessage(AdvancedSensitiveWords.getInstance(), BungeeCordChannel.BUNGEE_CHANNEL, data); + } +} diff --git a/bukkit/src/main/java/io/wdsj/asw/bukkit/setting/PluginSettings.java b/bukkit/src/main/java/io/wdsj/asw/bukkit/setting/PluginSettings.java index ea8994f..5436b02 100644 --- a/bukkit/src/main/java/io/wdsj/asw/bukkit/setting/PluginSettings.java +++ b/bukkit/src/main/java/io/wdsj/asw/bukkit/setting/PluginSettings.java @@ -82,6 +82,9 @@ public class PluginSettings implements SettingsHolder { @Comment({"*是否启用Velocity支持", "*Whether to enable Velocity support"}) public static final Property HOOK_VELOCITY = newProperty("Plugin.hookVelocity", false); + @Comment({"*是否启用BungeeCord支持", + "*Whether to enable BungeeCord support"}) + public static final Property HOOK_BUNGEECORD = newProperty("Plugin.hookBungeeCord", false); @Comment({"是否启用AuthMe兼容(在玩家未登录时不进行检测, 避免误判)", "Whether to enable AuthMe compatibility (no checks on players not logged in to avoid false positives)"}) diff --git a/bungee/pom.xml b/bungee/pom.xml index 7cbd586..852da2b 100644 --- a/bungee/pom.xml +++ b/bungee/pom.xml @@ -45,6 +45,9 @@ + + ${project.artifactId} + diff --git a/bungee/src/main/java/io/wdsj/asw/bungee/AdvancedSensitiveWords.java b/bungee/src/main/java/io/wdsj/asw/bungee/AdvancedSensitiveWords.java index 6dee08d..c350e87 100644 --- a/bungee/src/main/java/io/wdsj/asw/bungee/AdvancedSensitiveWords.java +++ b/bungee/src/main/java/io/wdsj/asw/bungee/AdvancedSensitiveWords.java @@ -1,16 +1,25 @@ package io.wdsj.asw.bungee; +import io.wdsj.asw.bungee.listener.PluginMessageListener; import net.md_5.bungee.api.plugin.Plugin; public final class AdvancedSensitiveWords extends Plugin { + public static final String BUNGEE_CHANNEL = "BungeeCord"; + public static final String SUB_CHANNEL = "asw"; + + private static AdvancedSensitiveWords instance; + public static AdvancedSensitiveWords getInstance() { + return instance; + } @Override public void onEnable() { - // Plugin startup logic + instance = this; + getProxy().getPluginManager().registerListener(this, new PluginMessageListener()); } @Override public void onDisable() { - // Plugin shutdown logic + getProxy().getPluginManager().unregisterListener(new PluginMessageListener()); } } diff --git a/bungee/src/main/java/io/wdsj/asw/bungee/listener/PluginMessageListener.java b/bungee/src/main/java/io/wdsj/asw/bungee/listener/PluginMessageListener.java new file mode 100644 index 0000000..73492cd --- /dev/null +++ b/bungee/src/main/java/io/wdsj/asw/bungee/listener/PluginMessageListener.java @@ -0,0 +1,46 @@ +package io.wdsj.asw.bungee.listener; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import io.wdsj.asw.bungee.AdvancedSensitiveWords; +import net.md_5.bungee.api.connection.Server; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; + +import static io.wdsj.asw.bungee.AdvancedSensitiveWords.BUNGEE_CHANNEL; +import static io.wdsj.asw.bungee.AdvancedSensitiveWords.SUB_CHANNEL; + +public class PluginMessageListener implements Listener { + + @EventHandler + public void onPluginMessage(final PluginMessageEvent event) { + if (!event.getTag().equals(BUNGEE_CHANNEL)) return; + if (!(event.getSender() instanceof Server)) { + return; + } + ByteArrayDataInput in = ByteStreams.newDataInput(event.getData()); + if (in.readUTF().equals(SUB_CHANNEL)) { + try { + String playerName = in.readUTF(); + String eventType = in.readUTF(); + String originalMessage = in.readUTF(); + String serverName = ((Server) event.getSender()).getInfo().getName(); + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF(SUB_CHANNEL); + out.writeUTF(playerName); + out.writeUTF(eventType); + out.writeUTF(originalMessage); + out.writeUTF(serverName); + AdvancedSensitiveWords.getInstance().getProxy().getServers().forEach((name, server) -> { + if (!server.equals(((Server) event.getSender()).getInfo()) && !server.getPlayers().isEmpty()) { + server.sendData(BUNGEE_CHANNEL, out.toByteArray()); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} diff --git a/pom.xml b/pom.xml index 9912963..651c186 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,7 @@ bukkit velocity + bungee