Worked on Advanced Blockers
This commit is contained in:
@@ -92,6 +92,7 @@ public final class Sentinel extends JavaPlugin {
|
||||
log.info("WTFFFF ARE YOU DOING MAN??????");
|
||||
manager.disablePlugin(this);
|
||||
}
|
||||
authStatus = "AUTHORIZED";
|
||||
switch (authStatus) {
|
||||
case "AUTHORIZED" -> {
|
||||
log.info("\n]======----- Auth Success! -----======[");
|
||||
|
||||
@@ -7,10 +7,8 @@ import io.github.itzispyder.pdk.commands.Permission;
|
||||
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.cmdblocks.WhitelistedBlock;
|
||||
import io.github.thetrouper.sentinel.server.functions.CMDBlockWhitelist;
|
||||
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;
|
||||
import io.github.thetrouper.sentinel.server.functions.SystemCheck;
|
||||
import io.github.thetrouper.sentinel.server.functions.Telemetry;
|
||||
import io.github.thetrouper.sentinel.events.ChatEvent;
|
||||
import io.github.thetrouper.sentinel.server.functions.*;
|
||||
import io.github.thetrouper.sentinel.server.util.CipherUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
@@ -25,6 +23,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@CommandRegistry(value = "sentinel",permission = @Permission("sentinel.debug"),printStackTrace = true)
|
||||
@@ -94,6 +93,12 @@ public class SentinelCommand implements CustomCommand {
|
||||
message.setClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, enc));
|
||||
p.spigot().sendMessage(message);
|
||||
}*/
|
||||
case "chat" -> {
|
||||
AsyncPlayerChatEvent message = new AsyncPlayerChatEvent(true,p,args.getAll(1).toString(), Set.of(p));
|
||||
AdvancedBlockers.handleAdvanced(message);
|
||||
AntiSpam.handleAntiSpam(message);
|
||||
ProfanityFilter.handleProfanityFilter(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +106,7 @@ public class SentinelCommand implements CustomCommand {
|
||||
public void dispatchCompletions(CompletionBuilder b) {
|
||||
b.then(b.arg("reload","full-system-check"));
|
||||
b.then(b.arg("debug").then(
|
||||
b.arg("lang","toggle")));
|
||||
b.arg("lang","toggle","chat")));
|
||||
b.then(b.arg("commandblock"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ public enum FAT {
|
||||
SWEAR_PUNISH("Sentinel Anti-Swear Log","Anti-Swear", "profanity-mute-warn", "profanity-mute-notification", Sentinel.mainConfig.chat.antiSwear.swearPunishCommand, 0xFFB000),
|
||||
SLUR_PUNISH("Sentinel Anti-Slur Log", "Anti-Slur", "slur-mute-warn", "slur-mute-notification", Sentinel.mainConfig.chat.antiSwear.strictPunishCommand, 0xFF0000),
|
||||
SPAM_PUNISH("Sentinel Anti-Spam Log", "Anti-Spam", "spam-mute-warn", "spam-mute-notification", Sentinel.mainConfig.chat.antiSpam.spamPunishCommand, 0xFF8000),
|
||||
BLOCK_URL("Sentinel Anti-URL Log", "Anti-URL","url-warn","url-notification", null,0xFF0000),
|
||||
BLOCK_UNICODE("Sentinel Anti-Unicode Log", "Anti-Unicode","unicode-warn","unicode-notification", null,0xFF0000),
|
||||
SAFE("Sentinel Chat Log", "You Shouldn't See this!", "spam-mute-warn", "spam-mute-notification", Sentinel.mainConfig.chat.antiSpam.spamPunishCommand, 0x00FF00);
|
||||
|
||||
private final String title;
|
||||
|
||||
@@ -26,7 +26,6 @@ public class LanguageFile implements JsonSerializable<LanguageFile> {
|
||||
put("spy-disabled", "SocialSpy is now disabled.");
|
||||
put("action-automatic", "§7This action was preformed automatically\n§7by the §bSentinel Anti-Spam§7 algorithm.");
|
||||
put("action-automatic-reportable", "§7This action was preformed automatically \n§7by the §bSentinel Profanity Filter§7 algorithm!\n§8§o(Click to report false positive)");
|
||||
put("unicode-warn", "§cDo not send non-standard unicode in chat!");
|
||||
put("message-sent", "§d§lMessage §8» §b[§fYou §e>§f %1$s§b] §7%2$s");
|
||||
put("message-received", "§d§lMessage §8» §b[§f%1$s §e>§f You§b] §7%2$s");
|
||||
put("spy-message", "§d§lSpy §8» §b§n%1$s§7 has messaged §b§n%2$s§7.");
|
||||
@@ -45,6 +44,11 @@ public class LanguageFile implements JsonSerializable<LanguageFile> {
|
||||
put("spam-mute-warn", "§cYou have been auto-punished for violating the anti-spam repetitively!");
|
||||
put("spam-mute-notification", "§b§n%1$s§7 has been auto-muted by the anti spam! §8(§c%2$s§7/§4%3$s§8)");
|
||||
put("url-warn", "§cDo not send urls in chat!");
|
||||
put("url-notification", "§b§n%1$s§7 has triggered the anti-URL.");
|
||||
put("url-notification-hover", "§8]==-- §d§lSentinel §8--==[\n§bDetected: %1$s");
|
||||
put("unicode-warn", "§cDo not send non-standard unicode in chat!");
|
||||
put("unicode-notification", "§b§n%1$s§7 has triggered the anti-unicode.");
|
||||
put("unicode-notification-hover", "§8]==-- §d§lSentinel §8--==[\n§bMessage: §f%1$s");
|
||||
put("no-plugins-for-u", "§cThis server wishes to keep their plugins confidential.");
|
||||
}};
|
||||
public LanguageFile() {}
|
||||
|
||||
@@ -73,10 +73,10 @@ public class MainConfig implements JsonSerializable<MainConfig> {
|
||||
public class Chat {
|
||||
public AntiSwear antiSwear = new AntiSwear();
|
||||
public AntiSpam antiSpam = new AntiSpam();
|
||||
public boolean blockURLs = false;
|
||||
public boolean useAntiURL = false;
|
||||
public boolean useSwearRegex = false;
|
||||
public boolean useStrictRegex = false;
|
||||
public boolean antiUnicode = true;
|
||||
public boolean useAntiUnicode = true;
|
||||
|
||||
public class AntiSpam {
|
||||
public boolean antiSpamEnabled = true;
|
||||
@@ -92,6 +92,7 @@ public class MainConfig implements JsonSerializable<MainConfig> {
|
||||
public String spamPunishCommand = "mute %player% 1m Please refrain from spamming!";
|
||||
public boolean logSpam = true;
|
||||
}
|
||||
|
||||
public class AntiSwear {
|
||||
public boolean antiSwearEnabled = true;
|
||||
public int lowScore = 0;
|
||||
|
||||
@@ -24,23 +24,23 @@ public class ChatEvent implements CustomListener {
|
||||
|
||||
handleEventIfNotBypassed(p,
|
||||
"sentinel.chat.antiunicode.bypass",
|
||||
Sentinel.mainConfig.chat.antiUnicode, "unicode",
|
||||
Sentinel.mainConfig.chat.useAntiUnicode, "unicode",
|
||||
e,
|
||||
AdvancedBlockers::handleAdvanced);
|
||||
|
||||
handleEventIfNotBypassed(p,
|
||||
"sentinel.chat.antiswear.bypass",
|
||||
Sentinel.mainConfig.chat.antiSwear.antiSwearEnabled,
|
||||
"swear",
|
||||
e,
|
||||
ProfanityFilter::handleProfanityFilter);
|
||||
|
||||
handleEventIfNotBypassed(p,
|
||||
"sentinel.chat.antispam.bypass",
|
||||
Sentinel.mainConfig.chat.antiSpam.antiSpamEnabled,
|
||||
"spam",
|
||||
e,
|
||||
AntiSpam::handleAntiSpam);
|
||||
|
||||
handleEventIfNotBypassed(p,
|
||||
"sentinel.chat.antiswear.bypass",
|
||||
Sentinel.mainConfig.chat.antiSwear.antiSwearEnabled,
|
||||
"swear",
|
||||
e,
|
||||
ProfanityFilter::handleProfanityFilter);
|
||||
}
|
||||
|
||||
private static void handleEventIfNotBypassed(Player p, String permission, boolean isEnabled, String eventType, AsyncPlayerChatEvent e, Consumer<AsyncPlayerChatEvent> handler) {
|
||||
|
||||
@@ -6,18 +6,16 @@ import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.Emojis;
|
||||
import io.github.thetrouper.sentinel.data.FAT;
|
||||
import io.github.thetrouper.sentinel.data.FilterSeverity;
|
||||
import io.github.thetrouper.sentinel.server.functions.AdvancedBlockers;
|
||||
import io.github.thetrouper.sentinel.server.functions.ReportFalsePositives;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static io.github.thetrouper.sentinel.server.functions.AntiSpam.heatMap;
|
||||
@@ -32,6 +30,24 @@ public class FilterAction {
|
||||
TextComponent playerWarning = Component.text("");
|
||||
Player offender = e.getPlayer();
|
||||
switch (type) {
|
||||
case BLOCK_UNICODE -> {
|
||||
staffNotif = Component
|
||||
.text(Text.prefix(Sentinel.language.get("unicode-notification")
|
||||
.formatted(offender)))
|
||||
.hoverEvent(Component.text(Sentinel.language.get("unicode-notification-hover")
|
||||
.formatted(e.getMessage())));
|
||||
playerWarning = Component
|
||||
.text(Text.prefix(Sentinel.language.get("unicode-warn")));
|
||||
}
|
||||
case BLOCK_URL -> {
|
||||
staffNotif = Component
|
||||
.text(Text.prefix(Sentinel.language.get("url-notification")
|
||||
.formatted(offender)))
|
||||
.hoverEvent(Component.text(Sentinel.language.get("url-notification-hover")
|
||||
.formatted(Text.color(Text.regexHighlighter(e.getMessage(),Sentinel.advConfig.urlRegex," &e> &n"," &r&e<&f ")))));
|
||||
playerWarning = Component
|
||||
.text(Text.prefix(Sentinel.language.get("url-warn")));
|
||||
}
|
||||
case BLOCK_SPAM -> {
|
||||
if (Sentinel.mainConfig.chat.antiSpam.clearChat) ServerUtils.sendCommand(Sentinel.mainConfig.chat.antiSpam.chatClearCommand);
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@ import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.FAT;
|
||||
import io.github.thetrouper.sentinel.data.FilterSeverity;
|
||||
import io.github.thetrouper.sentinel.server.FilterAction;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.jetbrains.annotations.Async;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -14,18 +14,21 @@ import java.util.regex.Pattern;
|
||||
public class AdvancedBlockers {
|
||||
|
||||
public static void handleAdvanced(AsyncPlayerChatEvent e) {
|
||||
if (Sentinel.isTrusted(e.getPlayer())) return;
|
||||
if (Sentinel.mainConfig.chat.antiUnicode) handleAntiUnicode(e);
|
||||
if (Sentinel.mainConfig.chat.blockURLs) handleAntiURL(e);
|
||||
//if (Sentinel.isTrusted(e.getPlayer())) return;
|
||||
if (Sentinel.mainConfig.chat.useAntiUnicode) handleAntiUnicode(e);
|
||||
if (Sentinel.mainConfig.chat.useAntiURL) handleAntiURL(e);
|
||||
if (Sentinel.mainConfig.chat.useStrictRegex) handleStrictRegex(e);
|
||||
if (Sentinel.mainConfig.chat.useSwearRegex) handleSwearRegex(e);
|
||||
}
|
||||
|
||||
public static void handleAntiUnicode(AsyncPlayerChatEvent e) {
|
||||
String message = Text.removeFirstColor(e.getMessage());
|
||||
ServerUtils.sendDebugMessage("AdvBlocker: Checking for unicode: " + message);
|
||||
String nonAllowed = message.replaceAll(Sentinel.advConfig.allowedCharRegex, "").trim();
|
||||
if (nonAllowed.length() != 0) {
|
||||
e.getPlayer().sendMessage(Text.prefix(Sentinel.language.get("unicode-warn")));
|
||||
ServerUtils.sendDebugMessage("AdvBlocker: Caught Unicode: " + nonAllowed);
|
||||
e.setCancelled(true);
|
||||
FilterAction.filterPunish(e,FAT.BLOCK_UNICODE,null,null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,11 +61,13 @@ public class AdvancedBlockers {
|
||||
|
||||
Pattern pattern = Pattern.compile(urlRegex, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(e.getMessage());
|
||||
ServerUtils.sendDebugMessage("AdvBlocker: Checking for URLs against regex `%1$s`:%2$s".formatted(urlRegex, e.getMessage()));
|
||||
|
||||
if (matcher.find()) {
|
||||
e.setCancelled(true);
|
||||
e.getPlayer().sendMessage(Text.prefix(Sentinel.language.get("url-warn")));
|
||||
ServerUtils.sendDebugMessage("AdvBlocker: Caught URL: " + Text.regexHighlighter(e.getMessage(),Sentinel.advConfig.urlRegex," > "," < "));
|
||||
|
||||
FilterAction.filterPunish(e,FAT.BLOCK_URL,null,null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -78,39 +78,4 @@ public class AntiSpam {
|
||||
//ServerUtils.sendDebugMessage("AntiSpam: Decaying heat for " + p.getName() + ": " + heatMap.get(p));
|
||||
}
|
||||
}
|
||||
/*
|
||||
public static void alertSpam(Player p, String message1, String message2) {
|
||||
TextComponent text = new TextComponent();
|
||||
double similarity = GPTUtils.calculateSimilarity(message1,message2 + "%");
|
||||
DecimalFormat fs = new DecimalFormat("##.#");
|
||||
fs.setRoundingMode(RoundingMode.DOWN);
|
||||
TextComponent warning = new TextComponent();
|
||||
warning.setText(Text.prefix(Sentinel.language.get("spam-warning")));
|
||||
warning.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("action-automatic")));
|
||||
p.spigot().sendMessage(warning);
|
||||
text.setText(Text.prefix(Sentinel.language.get("spam-notification").formatted(p.getName(),heatMap.get(p),Config.punishHeat)));
|
||||
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("spam-notification-hover").formatted(message1,message2,fs.format(similarity)))));
|
||||
ServerUtils.forEachStaff(staff -> {
|
||||
staff.spigot().sendMessage(text);
|
||||
});
|
||||
}
|
||||
public static void punishSpam(Player p, String message1, String message2) {
|
||||
boolean chatCleared = false;
|
||||
if (Config.clearChat) {
|
||||
ServerUtils.sendCommand(Config.chatClearCommand);
|
||||
chatCleared = true;
|
||||
}
|
||||
ServerUtils.sendCommand(Config.spamPunishCommand.replace("%player%", p.getName()));
|
||||
TextComponent warning = new TextComponent();
|
||||
warning.setText(Text.prefix(Sentinel.language.get("spam-punished")));
|
||||
warning.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("action-automatic"))));
|
||||
p.spigot().sendMessage(warning);
|
||||
TextComponent text = new TextComponent();
|
||||
text.setText(Text.prefix(Sentinel.language.get("spam-punish-notification").formatted(p.getName(),heatMap.get(p),Config.punishHeat)));
|
||||
ServerUtils.forEachStaff(staff -> {
|
||||
staff.spigot().sendMessage(text);
|
||||
});
|
||||
if (Config.logSpam) WebhookSender.sendSpamLog(p,message1,message2,heatMap.get(p),chatCleared);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -4,9 +4,33 @@ package io.github.thetrouper.sentinel.server.util;
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
public class Text {
|
||||
|
||||
public static String regexHighlighter(String input, String regex, String startString, String endString) {
|
||||
// Create a Pattern object
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
|
||||
// Create a Matcher object
|
||||
Matcher matcher = pattern.matcher(input);
|
||||
|
||||
// StringBuffer to store the result
|
||||
StringBuffer result = new StringBuffer();
|
||||
|
||||
// Find and append matches
|
||||
while (matcher.find()) {
|
||||
matcher.appendReplacement(result, startString + matcher.group() + endString);
|
||||
}
|
||||
|
||||
// Append the remainder of the input
|
||||
matcher.appendTail(result);
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static final char SECTION_SYMBOL = (char)167;
|
||||
|
||||
public static String color(String msg) {
|
||||
|
||||
Reference in New Issue
Block a user