From 43399c3cb1c2441e7de3e5fd97a60458f5d10580 Mon Sep 17 00:00:00 2001 From: HaHaWTH Date: Tue, 16 Apr 2024 17:52:24 +0800 Subject: [PATCH] Velocity support --- .idea/misc.xml | 7 ++- pom.xml | 8 +++ .../{ => bukkit}/AdvancedSensitiveWords.java | 37 +++++++------ .../command/ConstructCommandExecutor.java | 16 +++--- .../command/ConstructTabCompleter.java | 4 +- .../{ => bukkit}/event/ASWFilterEvent.java | 2 +- .../asw/{ => bukkit}/event/EventType.java | 2 +- .../{ => bukkit}/impl/list/AdvancedList.java | 2 +- .../{ => bukkit}/listener/AnvilListener.java | 31 ++++++----- .../{ => bukkit}/listener/BookListener.java | 32 ++++++----- .../listener/BroadCastListener.java | 12 ++-- .../{ => bukkit}/listener/ChatListener.java | 37 ++++++++----- .../listener/CommandListener.java | 26 +++++---- .../listener/PlayerItemListener.java | 26 +++++---- .../listener/PlayerLoginListener.java | 30 +++++----- .../{ => bukkit}/listener/SignListener.java | 32 ++++++----- .../listener/packet/ASWPacketListener.java | 39 ++++++++----- .../listener/packet/ProtocolLibListener.java | 33 ++++++----- .../{ => bukkit}/manage/notice/Notifier.java | 8 +-- .../manage/punish/Punishment.java | 8 +-- .../manage/punish/PunishmentType.java | 2 +- .../asw/{ => bukkit}/method/CharIgnore.java | 6 +- .../method/ExternalWordAllow.java | 6 +- .../{ => bukkit}/method/ExternalWordDeny.java | 6 +- .../{ => bukkit}/method/OnlineWordDeny.java | 10 ++-- .../asw/{ => bukkit}/method/WordAllow.java | 6 +- .../asw/{ => bukkit}/method/WordDeny.java | 6 +- .../asw/{ => bukkit}/method/WordReplace.java | 6 +- .../proxy/velocity/VelocityChannel.java | 5 ++ .../proxy/velocity/VelocityReceiver.java | 37 +++++++++++++ .../bukkit/proxy/velocity/VelocitySender.java | 18 ++++++ .../{ => bukkit}/setting/PluginMessages.java | 2 +- .../{ => bukkit}/setting/PluginSettings.java | 6 +- .../wdsj/asw/{ => bukkit}/update/Updater.java | 2 +- .../asw/{ => bukkit}/util/EntropyUtils.java | 2 +- .../asw/{ => bukkit}/util/PlayerUtils.java | 2 +- .../{ => bukkit}/util/SchedulingUtils.java | 4 +- .../asw/{ => bukkit}/util/TimingUtils.java | 6 +- .../io/wdsj/asw/{ => bukkit}/util/Utils.java | 8 +-- .../{ => bukkit}/util/cache/BookCache.java | 6 +- .../util/context/ChatContext.java | 6 +- .../AdvancedSensitiveWordsVelocity.java | 55 +++++++++++++++++++ src/main/resources/plugin.yml | 5 +- 43 files changed, 395 insertions(+), 209 deletions(-) rename src/main/java/io/wdsj/asw/{ => bukkit}/AdvancedSensitiveWords.java (89%) rename src/main/java/io/wdsj/asw/{ => bukkit}/command/ConstructCommandExecutor.java (93%) rename src/main/java/io/wdsj/asw/{ => bukkit}/command/ConstructTabCompleter.java (95%) rename src/main/java/io/wdsj/asw/{ => bukkit}/event/ASWFilterEvent.java (98%) rename src/main/java/io/wdsj/asw/{ => bukkit}/event/EventType.java (80%) rename src/main/java/io/wdsj/asw/{ => bukkit}/impl/list/AdvancedList.java (99%) rename src/main/java/io/wdsj/asw/{ => bukkit}/listener/AnvilListener.java (79%) rename src/main/java/io/wdsj/asw/{ => bukkit}/listener/BookListener.java (86%) rename src/main/java/io/wdsj/asw/{ => bukkit}/listener/BroadCastListener.java (82%) rename src/main/java/io/wdsj/asw/{ => bukkit}/listener/ChatListener.java (83%) rename src/main/java/io/wdsj/asw/{ => bukkit}/listener/CommandListener.java (82%) rename src/main/java/io/wdsj/asw/{ => bukkit}/listener/PlayerItemListener.java (88%) rename src/main/java/io/wdsj/asw/{ => bukkit}/listener/PlayerLoginListener.java (77%) rename src/main/java/io/wdsj/asw/{ => bukkit}/listener/SignListener.java (83%) rename src/main/java/io/wdsj/asw/{ => bukkit}/listener/packet/ASWPacketListener.java (89%) rename src/main/java/io/wdsj/asw/{ => bukkit}/listener/packet/ProtocolLibListener.java (88%) rename src/main/java/io/wdsj/asw/{ => bukkit}/manage/notice/Notifier.java (78%) rename src/main/java/io/wdsj/asw/{ => bukkit}/manage/punish/Punishment.java (95%) rename src/main/java/io/wdsj/asw/{ => bukkit}/manage/punish/PunishmentType.java (66%) rename src/main/java/io/wdsj/asw/{ => bukkit}/method/CharIgnore.java (78%) rename src/main/java/io/wdsj/asw/{ => bukkit}/method/ExternalWordAllow.java (91%) rename src/main/java/io/wdsj/asw/{ => bukkit}/method/ExternalWordDeny.java (91%) rename src/main/java/io/wdsj/asw/{ => bukkit}/method/OnlineWordDeny.java (84%) rename src/main/java/io/wdsj/asw/{ => bukkit}/method/WordAllow.java (61%) rename src/main/java/io/wdsj/asw/{ => bukkit}/method/WordDeny.java (61%) rename src/main/java/io/wdsj/asw/{ => bukkit}/method/WordReplace.java (89%) create mode 100644 src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocityChannel.java create mode 100644 src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocityReceiver.java create mode 100644 src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocitySender.java rename src/main/java/io/wdsj/asw/{ => bukkit}/setting/PluginMessages.java (99%) rename src/main/java/io/wdsj/asw/{ => bukkit}/setting/PluginSettings.java (98%) rename src/main/java/io/wdsj/asw/{ => bukkit}/update/Updater.java (97%) rename src/main/java/io/wdsj/asw/{ => bukkit}/util/EntropyUtils.java (99%) rename src/main/java/io/wdsj/asw/{ => bukkit}/util/PlayerUtils.java (94%) rename src/main/java/io/wdsj/asw/{ => bukkit}/util/SchedulingUtils.java (91%) rename src/main/java/io/wdsj/asw/{ => bukkit}/util/TimingUtils.java (88%) rename src/main/java/io/wdsj/asw/{ => bukkit}/util/Utils.java (95%) rename src/main/java/io/wdsj/asw/{ => bukkit}/util/cache/BookCache.java (92%) rename src/main/java/io/wdsj/asw/{ => bukkit}/util/context/ChatContext.java (88%) create mode 100644 src/main/java/io/wdsj/asw/velocity/AdvancedSensitiveWordsVelocity.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 06d2cab..dcddf79 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,9 +5,14 @@ - + + + + + + diff --git a/pom.xml b/pom.xml index 45b6ff8..4cbd2d0 100644 --- a/pom.xml +++ b/pom.xml @@ -279,6 +279,14 @@ provided + + + com.velocitypowered + velocity-api + 3.3.0-SNAPSHOT + provided + + fr.xephi diff --git a/src/main/java/io/wdsj/asw/AdvancedSensitiveWords.java b/src/main/java/io/wdsj/asw/bukkit/AdvancedSensitiveWords.java similarity index 89% rename from src/main/java/io/wdsj/asw/AdvancedSensitiveWords.java rename to src/main/java/io/wdsj/asw/bukkit/AdvancedSensitiveWords.java index 19069b0..5918bcc 100644 --- a/src/main/java/io/wdsj/asw/AdvancedSensitiveWords.java +++ b/src/main/java/io/wdsj/asw/bukkit/AdvancedSensitiveWords.java @@ -1,4 +1,4 @@ -package io.wdsj.asw; +package io.wdsj.asw.bukkit; import ch.jalu.configme.SettingsManager; import ch.jalu.configme.SettingsManagerBuilder; @@ -13,18 +13,20 @@ import com.github.houbb.sensitive.word.support.tag.WordTags; import com.github.retrooper.packetevents.PacketEvents; import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder; -import io.wdsj.asw.command.ConstructCommandExecutor; -import io.wdsj.asw.command.ConstructTabCompleter; -import io.wdsj.asw.listener.*; -import io.wdsj.asw.listener.packet.ASWPacketListener; -import io.wdsj.asw.listener.packet.ProtocolLibListener; -import io.wdsj.asw.method.*; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.update.Updater; -import io.wdsj.asw.util.TimingUtils; -import io.wdsj.asw.util.cache.BookCache; -import io.wdsj.asw.util.context.ChatContext; +import io.wdsj.asw.bukkit.command.ConstructCommandExecutor; +import io.wdsj.asw.bukkit.command.ConstructTabCompleter; +import io.wdsj.asw.bukkit.listener.*; +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.velocity.VelocityChannel; +import io.wdsj.asw.bukkit.proxy.velocity.VelocityReceiver; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.update.Updater; +import io.wdsj.asw.bukkit.util.TimingUtils; +import io.wdsj.asw.bukkit.util.cache.BookCache; +import io.wdsj.asw.bukkit.util.context.ChatContext; import org.bstats.bukkit.Metrics; import org.bstats.charts.SimplePie; import org.bukkit.Bukkit; @@ -36,8 +38,8 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Logger; -import static io.wdsj.asw.util.TimingUtils.cleanStatisticCache; -import static io.wdsj.asw.util.Utils.*; +import static io.wdsj.asw.bukkit.util.TimingUtils.cleanStatisticCache; +import static io.wdsj.asw.bukkit.util.Utils.*; public final class AdvancedSensitiveWords extends JavaPlugin { @@ -128,6 +130,10 @@ public void onEnable() { logger.info("BroadcastMessage is not available, please disable chat broadcast check in config.yml"); } } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + getServer().getMessenger().registerOutgoingPluginChannel(this, VelocityChannel.CHANNEL); + getServer().getMessenger().registerIncomingPluginChannel(this, VelocityChannel.CHANNEL, new VelocityReceiver()); + } long endTime = System.currentTimeMillis(); logger.info("AdvancedSensitiveWords is enabled!(took " + (endTime - startTime) + "ms)"); if (settingsManager.getProperty(PluginSettings.CHECK_FOR_UPDATE)) { @@ -159,7 +165,6 @@ public void doInitTasks() { } else { wD.set(WordDenys.chains(new WordDeny(), new ExternalWordDeny())); } - // Full async reload sensitiveWordBs = SensitiveWordBs.newInstance().ignoreCase(settingsManager.getProperty(PluginSettings.IGNORE_CASE)).ignoreWidth(settingsManager.getProperty(PluginSettings.IGNORE_WIDTH)).ignoreNumStyle(settingsManager.getProperty(PluginSettings.IGNORE_NUM_STYLE)).ignoreChineseStyle(settingsManager.getProperty(PluginSettings.IGNORE_CHINESE_STYLE)).ignoreEnglishStyle(settingsManager.getProperty(PluginSettings.IGNORE_ENGLISH_STYLE)).ignoreRepeat(settingsManager.getProperty(PluginSettings.IGNORE_REPEAT)).enableNumCheck(settingsManager.getProperty(PluginSettings.ENABLE_NUM_CHECK)).enableEmailCheck(settingsManager.getProperty(PluginSettings.ENABLE_EMAIL_CHECK)).enableUrlCheck(settingsManager.getProperty(PluginSettings.ENABLE_URL_CHECK)).enableWordCheck(settingsManager.getProperty(PluginSettings.ENABLE_WORD_CHECK)).wordResultCondition(settingsManager.getProperty(PluginSettings.FORCE_ENGLISH_FULL_MATCH) ? WordResultConditions.englishWordMatch() : WordResultConditions.alwaysTrue()).wordDeny(wD.get()).wordAllow(wA).numCheckLen(settingsManager.getProperty(PluginSettings.NUM_CHECK_LEN)).wordReplace(new WordReplace()).wordTag(WordTags.none()).charIgnore(new CharIgnore()).init(); isInitialized = true; }); diff --git a/src/main/java/io/wdsj/asw/command/ConstructCommandExecutor.java b/src/main/java/io/wdsj/asw/bukkit/command/ConstructCommandExecutor.java similarity index 93% rename from src/main/java/io/wdsj/asw/command/ConstructCommandExecutor.java rename to src/main/java/io/wdsj/asw/bukkit/command/ConstructCommandExecutor.java index b67b023..3bdd5bd 100644 --- a/src/main/java/io/wdsj/asw/command/ConstructCommandExecutor.java +++ b/src/main/java/io/wdsj/asw/bukkit/command/ConstructCommandExecutor.java @@ -1,10 +1,10 @@ -package io.wdsj.asw.command; +package io.wdsj.asw.bukkit.command; import com.github.houbb.heaven.util.util.OsUtil; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.cache.BookCache; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.cache.BookCache; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -16,9 +16,9 @@ import static com.github.houbb.heaven.util.util.OsUtil.is64; import static com.github.houbb.heaven.util.util.OsUtil.isUnix; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.TimingUtils.*; -import static io.wdsj.asw.util.Utils.*; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.TimingUtils.*; +import static io.wdsj.asw.bukkit.util.Utils.*; public class ConstructCommandExecutor implements CommandExecutor { @Override diff --git a/src/main/java/io/wdsj/asw/command/ConstructTabCompleter.java b/src/main/java/io/wdsj/asw/bukkit/command/ConstructTabCompleter.java similarity index 95% rename from src/main/java/io/wdsj/asw/command/ConstructTabCompleter.java rename to src/main/java/io/wdsj/asw/bukkit/command/ConstructTabCompleter.java index 3981b7f..994ec2e 100644 --- a/src/main/java/io/wdsj/asw/command/ConstructTabCompleter.java +++ b/src/main/java/io/wdsj/asw/bukkit/command/ConstructTabCompleter.java @@ -1,6 +1,6 @@ -package io.wdsj.asw.command; +package io.wdsj.asw.bukkit.command; -import io.wdsj.asw.impl.list.AdvancedList; +import io.wdsj.asw.bukkit.impl.list.AdvancedList; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; diff --git a/src/main/java/io/wdsj/asw/event/ASWFilterEvent.java b/src/main/java/io/wdsj/asw/bukkit/event/ASWFilterEvent.java similarity index 98% rename from src/main/java/io/wdsj/asw/event/ASWFilterEvent.java rename to src/main/java/io/wdsj/asw/bukkit/event/ASWFilterEvent.java index 832ac06..54f3247 100644 --- a/src/main/java/io/wdsj/asw/event/ASWFilterEvent.java +++ b/src/main/java/io/wdsj/asw/bukkit/event/ASWFilterEvent.java @@ -1,4 +1,4 @@ -package io.wdsj.asw.event; +package io.wdsj.asw.bukkit.event; import org.apiguardian.api.API; import org.bukkit.entity.Player; diff --git a/src/main/java/io/wdsj/asw/event/EventType.java b/src/main/java/io/wdsj/asw/bukkit/event/EventType.java similarity index 80% rename from src/main/java/io/wdsj/asw/event/EventType.java rename to src/main/java/io/wdsj/asw/bukkit/event/EventType.java index 17cea06..8bdbc67 100644 --- a/src/main/java/io/wdsj/asw/event/EventType.java +++ b/src/main/java/io/wdsj/asw/bukkit/event/EventType.java @@ -1,4 +1,4 @@ -package io.wdsj.asw.event; +package io.wdsj.asw.bukkit.event; /** * Event types for different detection modules. diff --git a/src/main/java/io/wdsj/asw/impl/list/AdvancedList.java b/src/main/java/io/wdsj/asw/bukkit/impl/list/AdvancedList.java similarity index 99% rename from src/main/java/io/wdsj/asw/impl/list/AdvancedList.java rename to src/main/java/io/wdsj/asw/bukkit/impl/list/AdvancedList.java index cc4e96a..569e045 100644 --- a/src/main/java/io/wdsj/asw/impl/list/AdvancedList.java +++ b/src/main/java/io/wdsj/asw/bukkit/impl/list/AdvancedList.java @@ -1,4 +1,4 @@ -package io.wdsj.asw.impl.list; +package io.wdsj.asw.bukkit.impl.list; import java.io.IOException; import java.io.ObjectInputStream; diff --git a/src/main/java/io/wdsj/asw/listener/AnvilListener.java b/src/main/java/io/wdsj/asw/bukkit/listener/AnvilListener.java similarity index 79% rename from src/main/java/io/wdsj/asw/listener/AnvilListener.java rename to src/main/java/io/wdsj/asw/bukkit/listener/AnvilListener.java index f406a97..fbfbe30 100644 --- a/src/main/java/io/wdsj/asw/listener/AnvilListener.java +++ b/src/main/java/io/wdsj/asw/bukkit/listener/AnvilListener.java @@ -1,13 +1,14 @@ -package io.wdsj.asw.listener; +package io.wdsj.asw.bukkit.listener; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.event.ASWFilterEvent; -import io.wdsj.asw.event.EventType; -import io.wdsj.asw.manage.notice.Notifier; -import io.wdsj.asw.manage.punish.Punishment; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.Utils; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.event.ASWFilterEvent; +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.velocity.VelocitySender; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.Utils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -21,10 +22,10 @@ import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.TimingUtils.addProcessStatistic; -import static io.wdsj.asw.util.Utils.getIgnoreFormatCodeRegex; -import static io.wdsj.asw.util.Utils.messagesFilteredNum; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.TimingUtils.addProcessStatistic; +import static io.wdsj.asw.bukkit.util.Utils.getIgnoreFormatCodeRegex; +import static io.wdsj.asw.bukkit.util.Utils.messagesFilteredNum; public class AnvilListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW) @@ -66,6 +67,10 @@ public void onAnvil(InventoryClickEvent event) { if (settingsManager.getProperty(PluginSettings.ENABLE_API)) { Bukkit.getPluginManager().callEvent(new ASWFilterEvent(player, originalItemName, processedItemName, censoredWords, EventType.ANVIL, false)); } + + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.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/src/main/java/io/wdsj/asw/listener/BookListener.java b/src/main/java/io/wdsj/asw/bukkit/listener/BookListener.java similarity index 86% rename from src/main/java/io/wdsj/asw/listener/BookListener.java rename to src/main/java/io/wdsj/asw/bukkit/listener/BookListener.java index 9b91e79..f815b62 100644 --- a/src/main/java/io/wdsj/asw/listener/BookListener.java +++ b/src/main/java/io/wdsj/asw/bukkit/listener/BookListener.java @@ -1,15 +1,16 @@ -package io.wdsj.asw.listener; +package io.wdsj.asw.bukkit.listener; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.event.ASWFilterEvent; -import io.wdsj.asw.event.EventType; -import io.wdsj.asw.impl.list.AdvancedList; -import io.wdsj.asw.manage.notice.Notifier; -import io.wdsj.asw.manage.punish.Punishment; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.Utils; -import io.wdsj.asw.util.cache.BookCache; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.event.ASWFilterEvent; +import io.wdsj.asw.bukkit.event.EventType; +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.velocity.VelocitySender; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.Utils; +import io.wdsj.asw.bukkit.util.cache.BookCache; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -21,9 +22,9 @@ import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.TimingUtils.addProcessStatistic; -import static io.wdsj.asw.util.Utils.messagesFilteredNum; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.TimingUtils.addProcessStatistic; +import static io.wdsj.asw.bukkit.util.Utils.messagesFilteredNum; public class BookListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW) @@ -111,6 +112,9 @@ public void onBook(PlayerEditBookEvent event) { if (settingsManager.getProperty(PluginSettings.ENABLE_API)) { Bukkit.getPluginManager().callEvent(new ASWFilterEvent(player, outMessage, processedOutMessage, outList, EventType.BOOK, false)); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.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/src/main/java/io/wdsj/asw/listener/BroadCastListener.java b/src/main/java/io/wdsj/asw/bukkit/listener/BroadCastListener.java similarity index 82% rename from src/main/java/io/wdsj/asw/listener/BroadCastListener.java rename to src/main/java/io/wdsj/asw/bukkit/listener/BroadCastListener.java index d3b968e..b74a8d9 100644 --- a/src/main/java/io/wdsj/asw/listener/BroadCastListener.java +++ b/src/main/java/io/wdsj/asw/bukkit/listener/BroadCastListener.java @@ -1,7 +1,7 @@ -package io.wdsj.asw.listener; +package io.wdsj.asw.bukkit.listener; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.Utils; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.Utils; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -9,9 +9,9 @@ import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.TimingUtils.addProcessStatistic; -import static io.wdsj.asw.util.Utils.messagesFilteredNum; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.TimingUtils.addProcessStatistic; +import static io.wdsj.asw.bukkit.util.Utils.messagesFilteredNum; public class BroadCastListener implements Listener { diff --git a/src/main/java/io/wdsj/asw/listener/ChatListener.java b/src/main/java/io/wdsj/asw/bukkit/listener/ChatListener.java similarity index 83% rename from src/main/java/io/wdsj/asw/listener/ChatListener.java rename to src/main/java/io/wdsj/asw/bukkit/listener/ChatListener.java index d9228d9..51d7b25 100644 --- a/src/main/java/io/wdsj/asw/listener/ChatListener.java +++ b/src/main/java/io/wdsj/asw/bukkit/listener/ChatListener.java @@ -1,15 +1,16 @@ -package io.wdsj.asw.listener; +package io.wdsj.asw.bukkit.listener; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.event.ASWFilterEvent; -import io.wdsj.asw.event.EventType; -import io.wdsj.asw.manage.notice.Notifier; -import io.wdsj.asw.manage.punish.Punishment; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.TimingUtils; -import io.wdsj.asw.util.Utils; -import io.wdsj.asw.util.context.ChatContext; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.event.ASWFilterEvent; +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.velocity.VelocitySender; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.TimingUtils; +import io.wdsj.asw.bukkit.util.Utils; +import io.wdsj.asw.bukkit.util.context.ChatContext; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -22,10 +23,10 @@ import java.util.Deque; import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.TimingUtils.addProcessStatistic; -import static io.wdsj.asw.util.Utils.getPlayerIp; -import static io.wdsj.asw.util.Utils.messagesFilteredNum; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.TimingUtils.addProcessStatistic; +import static io.wdsj.asw.bukkit.util.Utils.getPlayerIp; +import static io.wdsj.asw.bukkit.util.Utils.messagesFilteredNum; @SuppressWarnings("unused") public class ChatListener implements Listener { @@ -59,6 +60,9 @@ public void onChat(AsyncPlayerChatEvent event) { if (settingsManager.getProperty(PluginSettings.LOG_VIOLATION)) { Utils.logViolation(player.getName() + "(IP: " + getPlayerIp(player) + ")(Chat)", originalMessage + censoredWordList); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.send(player, EventType.CHAT, originalMessage); + } long endTime = System.currentTimeMillis(); TimingUtils.addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { @@ -92,6 +96,9 @@ public void onChat(AsyncPlayerChatEvent event) { if (settingsManager.getProperty(PluginSettings.LOG_VIOLATION)) { Utils.logViolation(player.getName() + "(IP: " + getPlayerIp(player) + ")(Chat)(Context)", originalContext + censoredContextList); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.send(player, EventType.CHAT, originalContext); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { diff --git a/src/main/java/io/wdsj/asw/listener/CommandListener.java b/src/main/java/io/wdsj/asw/bukkit/listener/CommandListener.java similarity index 82% rename from src/main/java/io/wdsj/asw/listener/CommandListener.java rename to src/main/java/io/wdsj/asw/bukkit/listener/CommandListener.java index 917a23b..794c4d7 100644 --- a/src/main/java/io/wdsj/asw/listener/CommandListener.java +++ b/src/main/java/io/wdsj/asw/bukkit/listener/CommandListener.java @@ -1,13 +1,14 @@ -package io.wdsj.asw.listener; +package io.wdsj.asw.bukkit.listener; -import io.wdsj.asw.event.ASWFilterEvent; -import io.wdsj.asw.event.EventType; -import io.wdsj.asw.manage.notice.Notifier; -import io.wdsj.asw.manage.punish.Punishment; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.TimingUtils; -import io.wdsj.asw.util.Utils; +import io.wdsj.asw.bukkit.event.ASWFilterEvent; +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.velocity.VelocitySender; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.TimingUtils; +import io.wdsj.asw.bukkit.util.Utils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -18,8 +19,8 @@ import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.Utils.*; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.Utils.*; @SuppressWarnings("unused") public class CommandListener implements Listener { @@ -51,6 +52,9 @@ public void onCommand(PlayerCommandPreprocessEvent event) { if (settingsManager.getProperty(PluginSettings.LOG_VIOLATION)) { Utils.logViolation(player.getName() + "(IP: " + getPlayerIp(player) + ")(Chat)", originalCommand + censoredWordList); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.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/src/main/java/io/wdsj/asw/listener/PlayerItemListener.java b/src/main/java/io/wdsj/asw/bukkit/listener/PlayerItemListener.java similarity index 88% rename from src/main/java/io/wdsj/asw/listener/PlayerItemListener.java rename to src/main/java/io/wdsj/asw/bukkit/listener/PlayerItemListener.java index 8f7e5bd..f185359 100644 --- a/src/main/java/io/wdsj/asw/listener/PlayerItemListener.java +++ b/src/main/java/io/wdsj/asw/bukkit/listener/PlayerItemListener.java @@ -1,13 +1,14 @@ -package io.wdsj.asw.listener; +package io.wdsj.asw.bukkit.listener; -import io.wdsj.asw.event.ASWFilterEvent; -import io.wdsj.asw.event.EventType; -import io.wdsj.asw.manage.notice.Notifier; -import io.wdsj.asw.manage.punish.Punishment; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.TimingUtils; -import io.wdsj.asw.util.Utils; +import io.wdsj.asw.bukkit.event.ASWFilterEvent; +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.velocity.VelocitySender; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.TimingUtils; +import io.wdsj.asw.bukkit.util.Utils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -21,8 +22,8 @@ import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.Utils.messagesFilteredNum; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.Utils.messagesFilteredNum; public class PlayerItemListener implements Listener { @@ -97,6 +98,9 @@ public void onDrop(PlayerDropItemEvent event) { if (settingsManager.getProperty(PluginSettings.ENABLE_API)) { Bukkit.getPluginManager().callEvent(new ASWFilterEvent(player, originalName, processedName, censoredWordList, EventType.ITEM, false)); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.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/src/main/java/io/wdsj/asw/listener/PlayerLoginListener.java b/src/main/java/io/wdsj/asw/bukkit/listener/PlayerLoginListener.java similarity index 77% rename from src/main/java/io/wdsj/asw/listener/PlayerLoginListener.java rename to src/main/java/io/wdsj/asw/bukkit/listener/PlayerLoginListener.java index 09a1390..dd424f0 100644 --- a/src/main/java/io/wdsj/asw/listener/PlayerLoginListener.java +++ b/src/main/java/io/wdsj/asw/bukkit/listener/PlayerLoginListener.java @@ -1,14 +1,15 @@ -package io.wdsj.asw.listener; +package io.wdsj.asw.bukkit.listener; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.event.ASWFilterEvent; -import io.wdsj.asw.event.EventType; -import io.wdsj.asw.manage.notice.Notifier; -import io.wdsj.asw.manage.punish.Punishment; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.PlayerUtils; -import io.wdsj.asw.util.Utils; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.event.ASWFilterEvent; +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.velocity.VelocitySender; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.PlayerUtils; +import io.wdsj.asw.bukkit.util.Utils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -19,9 +20,9 @@ import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.TimingUtils.addProcessStatistic; -import static io.wdsj.asw.util.Utils.messagesFilteredNum; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.TimingUtils.addProcessStatistic; +import static io.wdsj.asw.bukkit.util.Utils.messagesFilteredNum; public class PlayerLoginListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) @@ -55,6 +56,9 @@ public void onLogin(PlayerLoginEvent event) { if (settingsManager.getProperty(PluginSettings.ENABLE_API)) { Bukkit.getPluginManager().callEvent(new ASWFilterEvent(player, playerName, processedPlayerName, censoredWordList, EventType.NAME, false)); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.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/src/main/java/io/wdsj/asw/listener/SignListener.java b/src/main/java/io/wdsj/asw/bukkit/listener/SignListener.java similarity index 83% rename from src/main/java/io/wdsj/asw/listener/SignListener.java rename to src/main/java/io/wdsj/asw/bukkit/listener/SignListener.java index 644f3c2..da5b1f9 100644 --- a/src/main/java/io/wdsj/asw/listener/SignListener.java +++ b/src/main/java/io/wdsj/asw/bukkit/listener/SignListener.java @@ -1,15 +1,16 @@ -package io.wdsj.asw.listener; +package io.wdsj.asw.bukkit.listener; import com.github.houbb.heaven.util.lang.StringUtil; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.event.ASWFilterEvent; -import io.wdsj.asw.event.EventType; -import io.wdsj.asw.impl.list.AdvancedList; -import io.wdsj.asw.manage.notice.Notifier; -import io.wdsj.asw.manage.punish.Punishment; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.Utils; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.event.ASWFilterEvent; +import io.wdsj.asw.bukkit.event.EventType; +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.velocity.VelocitySender; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.Utils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -20,9 +21,9 @@ import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.TimingUtils.addProcessStatistic; -import static io.wdsj.asw.util.Utils.messagesFilteredNum; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.TimingUtils.addProcessStatistic; +import static io.wdsj.asw.bukkit.util.Utils.messagesFilteredNum; public class SignListener implements Listener { private String outMessage = ""; @@ -93,6 +94,11 @@ public void onSign(SignChangeEvent event) { if (settingsManager.getProperty(PluginSettings.LOG_VIOLATION) && shouldSendMessage) { Utils.logViolation(player.getName() + "(IP: " + Utils.getPlayerIp(player) + ")(Sign)", outMessage + outList); } + + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY) && shouldSendMessage) { + VelocitySender.send(player, EventType.CHAT, outMessage); + } + if (shouldSendMessage) { messagesFilteredNum.getAndIncrement(); long endTime = System.currentTimeMillis(); diff --git a/src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java b/src/main/java/io/wdsj/asw/bukkit/listener/packet/ASWPacketListener.java similarity index 89% rename from src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java rename to src/main/java/io/wdsj/asw/bukkit/listener/packet/ASWPacketListener.java index e8039f6..b6f167c 100644 --- a/src/main/java/io/wdsj/asw/listener/packet/ASWPacketListener.java +++ b/src/main/java/io/wdsj/asw/bukkit/listener/packet/ASWPacketListener.java @@ -1,4 +1,4 @@ -package io.wdsj.asw.listener.packet; +package io.wdsj.asw.bukkit.listener.packet; import com.github.retrooper.packetevents.event.PacketListenerAbstract; import com.github.retrooper.packetevents.event.PacketListenerPriority; @@ -8,15 +8,16 @@ import com.github.retrooper.packetevents.protocol.player.User; import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientChatCommand; import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientChatMessage; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.event.ASWFilterEvent; -import io.wdsj.asw.event.EventType; -import io.wdsj.asw.manage.notice.Notifier; -import io.wdsj.asw.manage.punish.Punishment; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.Utils; -import io.wdsj.asw.util.context.ChatContext; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.event.ASWFilterEvent; +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.velocity.VelocitySender; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.Utils; +import io.wdsj.asw.bukkit.util.context.ChatContext; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -24,9 +25,9 @@ import java.util.Deque; import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.TimingUtils.addProcessStatistic; -import static io.wdsj.asw.util.Utils.*; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.TimingUtils.addProcessStatistic; +import static io.wdsj.asw.bukkit.util.Utils.*; /** * @author HaHaWTH & HeyWTF_IS_That and 0D00_0721 @@ -72,10 +73,12 @@ public void onPacketReceive(PacketReceiveEvent event) { if (settingsManager.getProperty(PluginSettings.ENABLE_API)) { getScheduler().runTask(() -> Bukkit.getPluginManager().callEvent(new ASWFilterEvent(player, originalMessage, processedMessage, censoredWords, EventType.CHAT, false))); } - if (settingsManager.getProperty(PluginSettings.LOG_VIOLATION)) { Utils.logViolation(userName + "(IP: " + user.getAddress().getAddress().getHostAddress() + ")(Chat)", originalMessage + censoredWords); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.send(player, EventType.CHAT, originalMessage); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { @@ -109,9 +112,12 @@ public void onPacketReceive(PacketReceiveEvent event) { if (settingsManager.getProperty(PluginSettings.LOG_VIOLATION)) { Utils.logViolation(userName + "(IP: " + user.getAddress().getAddress().getHostAddress() + ")(Chat)(Context)", originalContext + censoredContextList); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.send(player, EventType.CHAT, originalContext); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); - getScheduler().runTask(()-> { + getScheduler().runTask(() -> { if (settingsManager.getProperty(PluginSettings.NOTICE_OPERATOR)) Notifier.notice(player, EventType.CHAT, originalContext); if (settingsManager.getProperty(PluginSettings.CHAT_PUNISH)) Punishment.punish(player); }); @@ -145,6 +151,9 @@ public void onPacketReceive(PacketReceiveEvent event) { if (settingsManager.getProperty(PluginSettings.LOG_VIOLATION)) { Utils.logViolation(userName + "(IP: " + user.getAddress().getAddress().getHostAddress() + ")(Chat)", "/" + originalCommand + censoredWords); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.send(player, EventType.CHAT, originalCommand); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { diff --git a/src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java b/src/main/java/io/wdsj/asw/bukkit/listener/packet/ProtocolLibListener.java similarity index 88% rename from src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java rename to src/main/java/io/wdsj/asw/bukkit/listener/packet/ProtocolLibListener.java index 739ea4a..cf90be3 100644 --- a/src/main/java/io/wdsj/asw/listener/packet/ProtocolLibListener.java +++ b/src/main/java/io/wdsj/asw/bukkit/listener/packet/ProtocolLibListener.java @@ -1,14 +1,15 @@ -package io.wdsj.asw.listener.packet; +package io.wdsj.asw.bukkit.listener.packet; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.event.ASWFilterEvent; -import io.wdsj.asw.event.EventType; -import io.wdsj.asw.manage.notice.Notifier; -import io.wdsj.asw.manage.punish.Punishment; -import io.wdsj.asw.setting.PluginMessages; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.Utils; -import io.wdsj.asw.util.context.ChatContext; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.event.ASWFilterEvent; +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.velocity.VelocitySender; +import io.wdsj.asw.bukkit.setting.PluginMessages; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.Utils; +import io.wdsj.asw.bukkit.util.context.ChatContext; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -17,9 +18,9 @@ import java.util.Deque; import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.*; -import static io.wdsj.asw.util.TimingUtils.addProcessStatistic; -import static io.wdsj.asw.util.Utils.*; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.*; +import static io.wdsj.asw.bukkit.util.TimingUtils.addProcessStatistic; +import static io.wdsj.asw.bukkit.util.Utils.*; /** * This class keeps compatibility with ProtocolLib 4.x and lower. @@ -73,6 +74,9 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent if (settingsManager.getProperty(PluginSettings.LOG_VIOLATION)) { Utils.logViolation(player.getName() + "(IP: " + getPlayerIp(player) + ")(Chat)", message + censoredWords); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.send(player, EventType.CHAT, message); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { @@ -103,6 +107,9 @@ public void onPacketReceiving(@NotNull com.comphenix.protocol.events.PacketEvent if (settingsManager.getProperty(PluginSettings.LOG_VIOLATION)) { Utils.logViolation(player.getName() + "(IP: " + getPlayerIp(player) + ")(Chat)(Context)", originalContext + censoredContextList); } + if (settingsManager.getProperty(PluginSettings.HOOK_VELOCITY)) { + VelocitySender.send(player, EventType.CHAT, originalContext); + } long endTime = System.currentTimeMillis(); addProcessStatistic(endTime, startTime); getScheduler().runTask(()-> { diff --git a/src/main/java/io/wdsj/asw/manage/notice/Notifier.java b/src/main/java/io/wdsj/asw/bukkit/manage/notice/Notifier.java similarity index 78% rename from src/main/java/io/wdsj/asw/manage/notice/Notifier.java rename to src/main/java/io/wdsj/asw/bukkit/manage/notice/Notifier.java index bbcae5b..5cae927 100644 --- a/src/main/java/io/wdsj/asw/manage/notice/Notifier.java +++ b/src/main/java/io/wdsj/asw/bukkit/manage/notice/Notifier.java @@ -1,14 +1,14 @@ -package io.wdsj.asw.manage.notice; +package io.wdsj.asw.bukkit.manage.notice; -import io.wdsj.asw.event.EventType; -import io.wdsj.asw.setting.PluginMessages; +import io.wdsj.asw.bukkit.event.EventType; +import io.wdsj.asw.bukkit.setting.PluginMessages; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import java.util.Collection; -import static io.wdsj.asw.AdvancedSensitiveWords.messagesManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.messagesManager; public class Notifier { public static void notice(Player violatedPlayer, EventType eventType, String originalMessage) { diff --git a/src/main/java/io/wdsj/asw/manage/punish/Punishment.java b/src/main/java/io/wdsj/asw/bukkit/manage/punish/Punishment.java similarity index 95% rename from src/main/java/io/wdsj/asw/manage/punish/Punishment.java rename to src/main/java/io/wdsj/asw/bukkit/manage/punish/Punishment.java index 3f36e0a..2a40c8d 100644 --- a/src/main/java/io/wdsj/asw/manage/punish/Punishment.java +++ b/src/main/java/io/wdsj/asw/bukkit/manage/punish/Punishment.java @@ -1,7 +1,7 @@ -package io.wdsj.asw.manage.punish; +package io.wdsj.asw.bukkit.manage.punish; -import io.wdsj.asw.setting.PluginSettings; -import io.wdsj.asw.util.SchedulingUtils; +import io.wdsj.asw.bukkit.setting.PluginSettings; +import io.wdsj.asw.bukkit.util.SchedulingUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; import org.bukkit.entity.Mob; @@ -12,7 +12,7 @@ import java.util.List; import java.util.Locale; -import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager; @SuppressWarnings("deprecation") public class Punishment { diff --git a/src/main/java/io/wdsj/asw/manage/punish/PunishmentType.java b/src/main/java/io/wdsj/asw/bukkit/manage/punish/PunishmentType.java similarity index 66% rename from src/main/java/io/wdsj/asw/manage/punish/PunishmentType.java rename to src/main/java/io/wdsj/asw/bukkit/manage/punish/PunishmentType.java index 4773d63..77cc0e9 100644 --- a/src/main/java/io/wdsj/asw/manage/punish/PunishmentType.java +++ b/src/main/java/io/wdsj/asw/bukkit/manage/punish/PunishmentType.java @@ -1,4 +1,4 @@ -package io.wdsj.asw.manage.punish; +package io.wdsj.asw.bukkit.manage.punish; public enum PunishmentType { COMMAND, diff --git a/src/main/java/io/wdsj/asw/method/CharIgnore.java b/src/main/java/io/wdsj/asw/bukkit/method/CharIgnore.java similarity index 78% rename from src/main/java/io/wdsj/asw/method/CharIgnore.java rename to src/main/java/io/wdsj/asw/bukkit/method/CharIgnore.java index b8999f0..064b868 100644 --- a/src/main/java/io/wdsj/asw/method/CharIgnore.java +++ b/src/main/java/io/wdsj/asw/bukkit/method/CharIgnore.java @@ -1,13 +1,13 @@ -package io.wdsj.asw.method; +package io.wdsj.asw.bukkit.method; import com.github.houbb.heaven.util.lang.StringUtil; import com.github.houbb.sensitive.word.api.ISensitiveWordCharIgnore; import com.github.houbb.sensitive.word.api.context.InnerSensitiveWordContext; -import io.wdsj.asw.setting.PluginSettings; +import io.wdsj.asw.bukkit.setting.PluginSettings; import java.util.Set; -import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager; public class CharIgnore implements ISensitiveWordCharIgnore { @Override diff --git a/src/main/java/io/wdsj/asw/method/ExternalWordAllow.java b/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordAllow.java similarity index 91% rename from src/main/java/io/wdsj/asw/method/ExternalWordAllow.java rename to src/main/java/io/wdsj/asw/bukkit/method/ExternalWordAllow.java index f4ed5dc..086c113 100644 --- a/src/main/java/io/wdsj/asw/method/ExternalWordAllow.java +++ b/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordAllow.java @@ -1,8 +1,8 @@ -package io.wdsj.asw.method; +package io.wdsj.asw.bukkit.method; import com.github.houbb.sensitive.word.api.IWordAllow; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.impl.list.AdvancedList; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.impl.list.AdvancedList; import java.io.File; import java.io.IOException; diff --git a/src/main/java/io/wdsj/asw/method/ExternalWordDeny.java b/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordDeny.java similarity index 91% rename from src/main/java/io/wdsj/asw/method/ExternalWordDeny.java rename to src/main/java/io/wdsj/asw/bukkit/method/ExternalWordDeny.java index 6a14575..18bf89e 100644 --- a/src/main/java/io/wdsj/asw/method/ExternalWordDeny.java +++ b/src/main/java/io/wdsj/asw/bukkit/method/ExternalWordDeny.java @@ -1,8 +1,8 @@ -package io.wdsj.asw.method; +package io.wdsj.asw.bukkit.method; import com.github.houbb.sensitive.word.api.IWordDeny; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.impl.list.AdvancedList; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.impl.list.AdvancedList; import java.io.File; import java.io.IOException; diff --git a/src/main/java/io/wdsj/asw/method/OnlineWordDeny.java b/src/main/java/io/wdsj/asw/bukkit/method/OnlineWordDeny.java similarity index 84% rename from src/main/java/io/wdsj/asw/method/OnlineWordDeny.java rename to src/main/java/io/wdsj/asw/bukkit/method/OnlineWordDeny.java index 8357bf7..0201c4b 100644 --- a/src/main/java/io/wdsj/asw/method/OnlineWordDeny.java +++ b/src/main/java/io/wdsj/asw/bukkit/method/OnlineWordDeny.java @@ -1,9 +1,9 @@ -package io.wdsj.asw.method; +package io.wdsj.asw.bukkit.method; import com.github.houbb.sensitive.word.api.IWordDeny; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.impl.list.AdvancedList; -import io.wdsj.asw.setting.PluginSettings; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.impl.list.AdvancedList; +import io.wdsj.asw.bukkit.setting.PluginSettings; import java.net.HttpURLConnection; import java.net.URL; @@ -11,7 +11,7 @@ import java.util.List; import java.util.Scanner; -import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager; /** * OnlineWordDeny for ASW. diff --git a/src/main/java/io/wdsj/asw/method/WordAllow.java b/src/main/java/io/wdsj/asw/bukkit/method/WordAllow.java similarity index 61% rename from src/main/java/io/wdsj/asw/method/WordAllow.java rename to src/main/java/io/wdsj/asw/bukkit/method/WordAllow.java index 3d1da03..c42573c 100644 --- a/src/main/java/io/wdsj/asw/method/WordAllow.java +++ b/src/main/java/io/wdsj/asw/bukkit/method/WordAllow.java @@ -1,11 +1,11 @@ -package io.wdsj.asw.method; +package io.wdsj.asw.bukkit.method; import com.github.houbb.sensitive.word.api.IWordAllow; -import io.wdsj.asw.setting.PluginSettings; +import io.wdsj.asw.bukkit.setting.PluginSettings; import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager; public class WordAllow implements IWordAllow { @Override diff --git a/src/main/java/io/wdsj/asw/method/WordDeny.java b/src/main/java/io/wdsj/asw/bukkit/method/WordDeny.java similarity index 61% rename from src/main/java/io/wdsj/asw/method/WordDeny.java rename to src/main/java/io/wdsj/asw/bukkit/method/WordDeny.java index a3de308..23d94d4 100644 --- a/src/main/java/io/wdsj/asw/method/WordDeny.java +++ b/src/main/java/io/wdsj/asw/bukkit/method/WordDeny.java @@ -1,11 +1,11 @@ -package io.wdsj.asw.method; +package io.wdsj.asw.bukkit.method; import com.github.houbb.sensitive.word.api.IWordDeny; -import io.wdsj.asw.setting.PluginSettings; +import io.wdsj.asw.bukkit.setting.PluginSettings; import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager; public class WordDeny implements IWordDeny { @Override diff --git a/src/main/java/io/wdsj/asw/method/WordReplace.java b/src/main/java/io/wdsj/asw/bukkit/method/WordReplace.java similarity index 89% rename from src/main/java/io/wdsj/asw/method/WordReplace.java rename to src/main/java/io/wdsj/asw/bukkit/method/WordReplace.java index 52f63a1..7d2f5d1 100644 --- a/src/main/java/io/wdsj/asw/method/WordReplace.java +++ b/src/main/java/io/wdsj/asw/bukkit/method/WordReplace.java @@ -1,12 +1,12 @@ -package io.wdsj.asw.method; +package io.wdsj.asw.bukkit.method; import com.github.houbb.sensitive.word.api.IWordContext; import com.github.houbb.sensitive.word.api.IWordReplace; import com.github.houbb.sensitive.word.api.IWordResult; import com.github.houbb.sensitive.word.utils.InnerWordCharUtils; -import io.wdsj.asw.setting.PluginSettings; +import io.wdsj.asw.bukkit.setting.PluginSettings; -import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager; public class WordReplace implements IWordReplace { @Override diff --git a/src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocityChannel.java b/src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocityChannel.java new file mode 100644 index 0000000..6faab6e --- /dev/null +++ b/src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocityChannel.java @@ -0,0 +1,5 @@ +package io.wdsj.asw.bukkit.proxy.velocity; + +public class VelocityChannel { + public static final String CHANNEL = "asw:main"; +} diff --git a/src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocityReceiver.java b/src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocityReceiver.java new file mode 100644 index 0000000..e8b6dab --- /dev/null +++ b/src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocityReceiver.java @@ -0,0 +1,37 @@ +package io.wdsj.asw.bukkit.proxy.velocity; + +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 VelocityReceiver implements PluginMessageListener { + @Override + public void onPluginMessageReceived(String channel, Player player, byte[] message) { + if (channel.equals("asw:main")) { + ByteArrayDataInput input = ByteStreams.newDataInput(message); + String playerName = input.readUTF(); + String eventType = input.readUTF(); + String originalMsg = 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%", originalMsg)); + for (Player iPlayer : players) { + if (iPlayer.hasPermission("advancedsensitivewords.notice")) { + iPlayer.sendMessage(msg); + } + } + } + } + } +} diff --git a/src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocitySender.java b/src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocitySender.java new file mode 100644 index 0000000..343e2ec --- /dev/null +++ b/src/main/java/io/wdsj/asw/bukkit/proxy/velocity/VelocitySender.java @@ -0,0 +1,18 @@ +package io.wdsj.asw.bukkit.proxy.velocity; + +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 VelocitySender { + public static void send(Player violatedPlayer, EventType eventType, String originalMessage) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF(violatedPlayer.getName()); + out.writeUTF(eventType.toString()); + out.writeUTF(originalMessage); + byte[] data = out.toByteArray(); + violatedPlayer.sendPluginMessage(AdvancedSensitiveWords.getInstance(), VelocityChannel.CHANNEL, data); + } +} diff --git a/src/main/java/io/wdsj/asw/setting/PluginMessages.java b/src/main/java/io/wdsj/asw/bukkit/setting/PluginMessages.java similarity index 99% rename from src/main/java/io/wdsj/asw/setting/PluginMessages.java rename to src/main/java/io/wdsj/asw/bukkit/setting/PluginMessages.java index c3f1a21..4e53d40 100644 --- a/src/main/java/io/wdsj/asw/setting/PluginMessages.java +++ b/src/main/java/io/wdsj/asw/bukkit/setting/PluginMessages.java @@ -1,4 +1,4 @@ -package io.wdsj.asw.setting; +package io.wdsj.asw.bukkit.setting; import ch.jalu.configme.Comment; import ch.jalu.configme.SettingsHolder; diff --git a/src/main/java/io/wdsj/asw/setting/PluginSettings.java b/src/main/java/io/wdsj/asw/bukkit/setting/PluginSettings.java similarity index 98% rename from src/main/java/io/wdsj/asw/setting/PluginSettings.java rename to src/main/java/io/wdsj/asw/bukkit/setting/PluginSettings.java index b63a354..ea8994f 100644 --- a/src/main/java/io/wdsj/asw/setting/PluginSettings.java +++ b/src/main/java/io/wdsj/asw/bukkit/setting/PluginSettings.java @@ -1,4 +1,4 @@ -package io.wdsj.asw.setting; +package io.wdsj.asw.bukkit.setting; import ch.jalu.configme.Comment; import ch.jalu.configme.SettingsHolder; @@ -79,6 +79,10 @@ public class PluginSettings implements SettingsHolder { "Whether to enable API (do not disable unless necessary)"}) public static final Property ENABLE_API = newProperty("Plugin.enableApi", true); + @Comment({"*是否启用Velocity支持", + "*Whether to enable Velocity support"}) + public static final Property HOOK_VELOCITY = newProperty("Plugin.hookVelocity", false); + @Comment({"是否启用AuthMe兼容(在玩家未登录时不进行检测, 避免误判)", "Whether to enable AuthMe compatibility (no checks on players not logged in to avoid false positives)"}) public static final Property ENABLE_AUTHME_COMPATIBILITY = newProperty("Plugin.compatibility.authMe", false); diff --git a/src/main/java/io/wdsj/asw/update/Updater.java b/src/main/java/io/wdsj/asw/bukkit/update/Updater.java similarity index 97% rename from src/main/java/io/wdsj/asw/update/Updater.java rename to src/main/java/io/wdsj/asw/bukkit/update/Updater.java index 68b7fe4..9e92d77 100644 --- a/src/main/java/io/wdsj/asw/update/Updater.java +++ b/src/main/java/io/wdsj/asw/bukkit/update/Updater.java @@ -1,4 +1,4 @@ -package io.wdsj.asw.update; +package io.wdsj.asw.bukkit.update; import java.io.IOException; import java.net.HttpURLConnection; diff --git a/src/main/java/io/wdsj/asw/util/EntropyUtils.java b/src/main/java/io/wdsj/asw/bukkit/util/EntropyUtils.java similarity index 99% rename from src/main/java/io/wdsj/asw/util/EntropyUtils.java rename to src/main/java/io/wdsj/asw/bukkit/util/EntropyUtils.java index 7c55573..bb2635c 100644 --- a/src/main/java/io/wdsj/asw/util/EntropyUtils.java +++ b/src/main/java/io/wdsj/asw/bukkit/util/EntropyUtils.java @@ -1,4 +1,4 @@ -package io.wdsj.asw.util; +package io.wdsj.asw.bukkit.util; import java.util.HashMap; //TODO: Add AntiSpam feature(maybe) diff --git a/src/main/java/io/wdsj/asw/util/PlayerUtils.java b/src/main/java/io/wdsj/asw/bukkit/util/PlayerUtils.java similarity index 94% rename from src/main/java/io/wdsj/asw/util/PlayerUtils.java rename to src/main/java/io/wdsj/asw/bukkit/util/PlayerUtils.java index b4852a7..946f5c8 100644 --- a/src/main/java/io/wdsj/asw/util/PlayerUtils.java +++ b/src/main/java/io/wdsj/asw/bukkit/util/PlayerUtils.java @@ -1,4 +1,4 @@ -package io.wdsj.asw.util; +package io.wdsj.asw.bukkit.util; import org.bukkit.entity.Player; diff --git a/src/main/java/io/wdsj/asw/util/SchedulingUtils.java b/src/main/java/io/wdsj/asw/bukkit/util/SchedulingUtils.java similarity index 91% rename from src/main/java/io/wdsj/asw/util/SchedulingUtils.java rename to src/main/java/io/wdsj/asw/bukkit/util/SchedulingUtils.java index ff8e506..3caae3e 100644 --- a/src/main/java/io/wdsj/asw/util/SchedulingUtils.java +++ b/src/main/java/io/wdsj/asw/bukkit/util/SchedulingUtils.java @@ -1,7 +1,7 @@ -package io.wdsj.asw.util; +package io.wdsj.asw.bukkit.util; -import io.wdsj.asw.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; import org.bukkit.Location; import org.bukkit.entity.Entity; diff --git a/src/main/java/io/wdsj/asw/util/TimingUtils.java b/src/main/java/io/wdsj/asw/bukkit/util/TimingUtils.java similarity index 88% rename from src/main/java/io/wdsj/asw/util/TimingUtils.java rename to src/main/java/io/wdsj/asw/bukkit/util/TimingUtils.java index c7ae669..b6c6662 100644 --- a/src/main/java/io/wdsj/asw/util/TimingUtils.java +++ b/src/main/java/io/wdsj/asw/bukkit/util/TimingUtils.java @@ -1,10 +1,10 @@ -package io.wdsj.asw.util; +package io.wdsj.asw.bukkit.util; -import io.wdsj.asw.impl.list.AdvancedList; +import io.wdsj.asw.bukkit.impl.list.AdvancedList; import java.util.List; -import static io.wdsj.asw.util.Utils.messagesFilteredNum; +import static io.wdsj.asw.bukkit.util.Utils.messagesFilteredNum; public class TimingUtils { private static final List processStatistic = new AdvancedList<>(); diff --git a/src/main/java/io/wdsj/asw/util/Utils.java b/src/main/java/io/wdsj/asw/bukkit/util/Utils.java similarity index 95% rename from src/main/java/io/wdsj/asw/util/Utils.java rename to src/main/java/io/wdsj/asw/bukkit/util/Utils.java index 000589e..be54335 100644 --- a/src/main/java/io/wdsj/asw/util/Utils.java +++ b/src/main/java/io/wdsj/asw/bukkit/util/Utils.java @@ -1,9 +1,9 @@ -package io.wdsj.asw.util; +package io.wdsj.asw.bukkit.util; import com.github.houbb.heaven.util.io.FileUtil; import com.github.houbb.heaven.util.lang.StringUtil; -import io.wdsj.asw.AdvancedSensitiveWords; -import io.wdsj.asw.setting.PluginSettings; +import io.wdsj.asw.bukkit.AdvancedSensitiveWords; +import io.wdsj.asw.bukkit.setting.PluginSettings; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -17,7 +17,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicLong; -import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager; public class Utils { public static AtomicLong messagesFilteredNum = new AtomicLong(0); diff --git a/src/main/java/io/wdsj/asw/util/cache/BookCache.java b/src/main/java/io/wdsj/asw/bukkit/util/cache/BookCache.java similarity index 92% rename from src/main/java/io/wdsj/asw/util/cache/BookCache.java rename to src/main/java/io/wdsj/asw/bukkit/util/cache/BookCache.java index 952e086..6d85abd 100644 --- a/src/main/java/io/wdsj/asw/util/cache/BookCache.java +++ b/src/main/java/io/wdsj/asw/bukkit/util/cache/BookCache.java @@ -1,11 +1,11 @@ -package io.wdsj.asw.util.cache; +package io.wdsj.asw.bukkit.util.cache; -import io.wdsj.asw.setting.PluginSettings; +import io.wdsj.asw.bukkit.setting.PluginSettings; import java.util.HashMap; import java.util.List; -import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager; /** * Cache utilities class for Book detections. diff --git a/src/main/java/io/wdsj/asw/util/context/ChatContext.java b/src/main/java/io/wdsj/asw/bukkit/util/context/ChatContext.java similarity index 88% rename from src/main/java/io/wdsj/asw/util/context/ChatContext.java rename to src/main/java/io/wdsj/asw/bukkit/util/context/ChatContext.java index fbb0c07..9381963 100644 --- a/src/main/java/io/wdsj/asw/util/context/ChatContext.java +++ b/src/main/java/io/wdsj/asw/bukkit/util/context/ChatContext.java @@ -1,13 +1,13 @@ -package io.wdsj.asw.util.context; +package io.wdsj.asw.bukkit.util.context; -import io.wdsj.asw.setting.PluginSettings; +import io.wdsj.asw.bukkit.setting.PluginSettings; import org.bukkit.entity.Player; import java.util.Deque; import java.util.LinkedList; import java.util.concurrent.ConcurrentHashMap; -import static io.wdsj.asw.AdvancedSensitiveWords.settingsManager; +import static io.wdsj.asw.bukkit.AdvancedSensitiveWords.settingsManager; public class ChatContext { private static final ConcurrentHashMap> chatHistory = new ConcurrentHashMap<>(); diff --git a/src/main/java/io/wdsj/asw/velocity/AdvancedSensitiveWordsVelocity.java b/src/main/java/io/wdsj/asw/velocity/AdvancedSensitiveWordsVelocity.java new file mode 100644 index 0000000..91b6e28 --- /dev/null +++ b/src/main/java/io/wdsj/asw/velocity/AdvancedSensitiveWordsVelocity.java @@ -0,0 +1,55 @@ +package io.wdsj.asw.velocity; + +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import com.google.inject.Inject; +import com.velocitypowered.api.event.connection.PluginMessageEvent; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.ServerConnection; +import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; +import org.slf4j.Logger; + +import java.util.Optional; + +@Plugin( + id = "advancedsensitivewords", + name = "AdvancedSensitiveWordsVelocity", + version = "Crystal", + authors = {"HaHaWTH"} +) +public class AdvancedSensitiveWordsVelocity { + + @Inject + private Logger logger; + @Inject + private ProxyServer server; + private static final MinecraftChannelIdentifier CHANNEL = MinecraftChannelIdentifier.create("asw", "main"); + + @Subscribe + public void onProxyInitialization(ProxyInitializeEvent event) { + } + + @Subscribe + public void onPluginMessage(PluginMessageEvent event) { + if (event.getIdentifier().equals(CHANNEL)) { + if (!(event.getSource() instanceof Player)) return; + Optional sourceConnection = ((Player) event.getSource()).getCurrentServer(); + byte[] message = event.getData(); + server.getAllServers().forEach(server -> { + sourceConnection.ifPresent(source -> { + if (!server.getServerInfo().equals(source.getServerInfo()) && server.getPlayersConnected().size() > 0) { + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.write(message); + out.writeUTF(sourceConnection.get().getServerInfo().getName()); + server.sendPluginMessage(CHANNEL, out.toByteArray()); + logger.debug("Send message to " + server.getServerInfo().getName()); + } + }); + }); + } + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 38e1104..985672b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: AdvancedSensitiveWords version: ${project.version} -main: io.wdsj.asw.AdvancedSensitiveWords +main: io.wdsj.asw.bukkit.AdvancedSensitiveWords api-version: '1.13' website: https://github.com/HaHaWTH/AdvancedSensitiveWords authors: @@ -53,5 +53,4 @@ permissions: advancedsensitivewords.notice: description: Retrive the notice message when player violated. default: op -# Love you -# Support me on Afdian https://afdian.net/a/114514woxiuyuan/ \ No newline at end of file +# Love you \ No newline at end of file