Skip to content

Commit

Permalink
Velocity support
Browse files Browse the repository at this point in the history
  • Loading branch information
HaHaWTH committed Apr 16, 2024
1 parent 2d1bf91 commit 43399c3
Show file tree
Hide file tree
Showing 43 changed files with 395 additions and 209 deletions.
7 changes: 6 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@
<scope>provided</scope>
</dependency>

<!-- Velocity API -->
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- AuthMe -->
<dependency>
<groupId>fr.xephi</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.wdsj.asw;
package io.wdsj.asw.bukkit;

import ch.jalu.configme.SettingsManager;
import ch.jalu.configme.SettingsManagerBuilder;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.wdsj.asw.event;
package io.wdsj.asw.bukkit.event;

/**
* Event types for different detection modules.
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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;
import org.bukkit.event.server.BroadcastMessageEvent;

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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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(()-> {
Expand Down Expand Up @@ -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(()-> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 43399c3

Please sign in to comment.