Trying to fix dictionary saving

This commit is contained in:
obvWolf
2024-01-17 17:09:42 -06:00
parent 6a53dfd467
commit c92cf71b07
30 changed files with 519 additions and 379 deletions

View File

@@ -1,5 +1,6 @@
package io.github.thetrouper.sentinel;
import com.google.gson.JsonObject;
import io.github.itzispyder.pdk.PDK;
import io.github.thetrouper.sentinel.auth.Auth;
import io.github.thetrouper.sentinel.cmds.*;
@@ -15,7 +16,8 @@ import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.*;
import java.net.URL;
import java.util.logging.Logger;
public final class Sentinel extends JavaPlugin {
@@ -45,16 +47,23 @@ public final class Sentinel extends JavaPlugin {
*/
@Override
public void onEnable() {
log.info("\n]======------ Pre-load started! ------======[");
PDK.init(this);
instance = this;
log.info("Loading Config...");
loadConfig();
log.info("Language Status: (" + dict.get("if-you-see-this-lang-is-broken") + ")");
log.info("Initializing Server ID...");
String serverID = Authenticator.getServerID();
key = mainConfig.plugin.license;
identifier = serverID;
log.info("Pre-load finished!\n]====---- Requesting Authentication ----====[ \n- License Key: " + key + " \n- Server ID: " + serverID);
log.info("Auth Requested...");
String authStatus = "ERROR";
String authstatus = "ERROR";
try {
@@ -98,6 +107,10 @@ public final class Sentinel extends JavaPlugin {
log.warning("Hmmmmmm thats not right... License: " + key + " Server ID: " + serverID + "\nPlease report the above stacktrace.");
manager.disablePlugin(this);
}
default -> {
log.warning("Achievment unlocked:\n How did we get here? \nLicense: " + key + " Server ID: " + serverID + "\nPlease report the above stacktrace.");
manager.disablePlugin(this);
}
}
}
@@ -111,7 +124,7 @@ public final class Sentinel extends JavaPlugin {
AntiSpam.enableAntiSpam();
ProfanityFilter.enableAntiSwear();
prefix = MainConfig.Plugin.prefix;
prefix = mainConfig.plugin.prefix;
// Commands -> BE SURE TO REGISTER ANY NEW COMMANDS IN PLUGIN.YML (src/main/java/resources/plugin.yml)!
new SentinelCommand().register();
@@ -166,11 +179,31 @@ public final class Sentinel extends JavaPlugin {
nbtConfig.save();
dict.save();
log.info("Loading Dictionary (" + MainConfig.Plugin.lang + ")...");
try {
InputStream langIn = Sentinel.class.getClassLoader().getResourceAsStream("lang/en_us.json");
InputStreamReader langReader = new InputStreamReader(langIn);
BufferedReader langBR = new BufferedReader(langReader);
File langFile = LanguageFile.PATH;
FileWriter langFW = new FileWriter(langFile,true);
String line;
while ((line = langBR.readLine()) != null) {
langFW.write(line);
}
langFW.close();
langIn.close();
langReader.close();
langBR.close();
} catch (Exception ex) {
log.warning("Error during config initialization: " + ex.getMessage());
}
log.info("Loading Dictionary (" + Sentinel.mainConfig.plugin.lang + ")...");
log.info("Verifying Config...");
//getConfig().options().copyDefaults();
//saveDefaultConfig();
getConfig().options().copyDefaults();
saveDefaultConfig();
}
/**
@@ -191,7 +224,7 @@ public final class Sentinel extends JavaPlugin {
* @return true if the player is trusted, false otherwise
*/
public static boolean isTrusted(Player player) {
return MainConfig.Plugin.trustedPlayers.contains(player.getUniqueId().toString());
return Sentinel.mainConfig.plugin.trustedPlayers.contains(player.getUniqueId().toString());
}
/**
@@ -200,7 +233,7 @@ public final class Sentinel extends JavaPlugin {
* @return true if the command is logged, false otherwise
*/
public static boolean isLoggedCommand(String command) {
return MainConfig.Plugin.logged.contains(command);
return Sentinel.mainConfig.plugin.logged.contains(command);
}
/**
@@ -209,7 +242,7 @@ public final class Sentinel extends JavaPlugin {
* @return true if the command is dangerous, false otherwise
*/
public static boolean isDangerousCommand(String command) {
return MainConfig.Plugin.dangerous.contains(command);
return Sentinel.mainConfig.plugin.dangerous.contains(command);
}
/**
* Returns an instance of this plugin

View File

@@ -1,7 +1,9 @@
package io.github.thetrouper.sentinel.cmds;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.Permission;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import io.github.itzispyder.pdk.utils.misc.Cooldown;
import io.github.thetrouper.sentinel.Sentinel;
@@ -11,7 +13,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.UUID;
@CommandRegistry(value = "sentinelcallback", permission = @Permission("sentinel.callbacks"))
public class ChatClickCallback implements CustomCommand {
Cooldown<UUID> fpReportCooldown = new Cooldown<>();
@Override

View File

@@ -5,14 +5,18 @@ import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.Permission;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import io.github.itzispyder.pdk.utils.ArrayUtils;
import io.github.itzispyder.pdk.utils.ServerUtils;
import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.server.functions.Message;
import io.github.thetrouper.sentinel.server.util.ServerUtils;
import io.github.thetrouper.sentinel.server.util.Text;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.List;
@CommandRegistry(value = "sentinelmessage",permission = @Permission("sentinel.message"))
public class MessageCommand implements CustomCommand {
@Override
@@ -39,7 +43,7 @@ public class MessageCommand implements CustomCommand {
@Override
public void dispatchCompletions(CompletionBuilder b) {
b.then(b.arg(ServerUtils.unVanishedPlayers())
b.then(b.arg(ArrayUtils.toNewList(Bukkit.getOnlinePlayers(), Player::getName))
.then(b.arg("[<Message>]")));
}
}

View File

@@ -1,13 +1,16 @@
package io.github.thetrouper.sentinel.cmds;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
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.server.util.Text;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandRegistry(value = "reop")
public class ReopCommand implements CustomCommand {
@Override
public void dispatchCommand(CommandSender sender, Args args) {

View File

@@ -1,7 +1,9 @@
package io.github.thetrouper.sentinel.cmds;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
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.server.functions.Message;
@@ -12,6 +14,7 @@ import org.bukkit.entity.Player;
import java.util.Map;
import java.util.UUID;
@CommandRegistry(value = "reply", permission = @Permission("sentinel.reply"))
public class ReplyCommand implements CustomCommand {
public static Map<UUID, UUID> replyMap = Message.replyMap;
@Override

View File

@@ -60,7 +60,7 @@ public class SentinelCommand implements CustomCommand {
p.sendMessage(Text.prefix("Invalid Player!"));
return;
}
p.sendMessage(Text.prefix("Heat of " + target.getName() + ": &8(&c" + io.github.thetrouper.sentinel.server.functions.AntiSpam.heatMap.get(target) + "&7/&4" + MainConfig.Chat.AntiSpam.punishHeat + "&8)"));
p.sendMessage(Text.prefix("Heat of " + target.getName() + ": &8(&c" + io.github.thetrouper.sentinel.server.functions.AntiSpam.heatMap.get(target) + "&7/&4" + Sentinel.mainConfig.chat.antiSpam.punishHeat + "&8)"));
}
}
}

View File

@@ -1,7 +1,9 @@
package io.github.thetrouper.sentinel.cmds;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
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.server.util.Text;
@@ -12,6 +14,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@CommandRegistry(value = "socialspy", permission = @Permission("sentinel.spy"))
public class SocialSpyCommand implements CustomCommand {
public static Map<UUID, Boolean> spyMap = new HashMap<>();

View File

@@ -1,15 +1,15 @@
package io.github.thetrouper.sentinel.data;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.Sentinel;
import java.awt.*;
public enum FAT {
BLOCK_SWEAR("Sentinel Profanity Filter",null,"swear-block-warn", "swear-block-notification", null,null),
BLOCK_SPAM("Sentinel Anti-Spam", null, "spam-block-warn", "spam-notification",null,null),
SWEAR("Sentinel Anti-Swear Log","Anti-Swear", "profanity-mute-warn", "profanity-mute-notification", MainConfig.Chat.AntiSwear.swearPunishCommand, Color.orange),
SLUR("Sentinel Anti-Slur Log", "Anti-Slur", "slur-mute-warn", "slur-mute-notification", MainConfig.Chat.AntiSwear.strictPunishCommand, Color.red),
SPAM("Sentinel Anti-Spam Log", "Anti-Spam", "spam-mute-warn", "spam-mute-notification", MainConfig.Chat.AntiSpam.spamPunishCommand, Color.pink);
SWEAR_PUNISH("Sentinel Anti-Swear Log","Anti-Swear", "profanity-mute-warn", "profanity-mute-notification", Sentinel.mainConfig.chat.antiSwear.swearPunishCommand, Color.orange),
SLUR_PUNISH("Sentinel Anti-Slur Log", "Anti-Slur", "slur-mute-warn", "slur-mute-notification", Sentinel.mainConfig.chat.antiSwear.strictPunishCommand, Color.red),
SPAM_PUNISH("Sentinel Anti-Spam Log", "Anti-Spam", "spam-mute-warn", "spam-mute-notification", Sentinel.mainConfig.chat.antiSpam.spamPunishCommand, Color.pink);
private final String title;
private final String name;

View File

@@ -16,9 +16,9 @@ public class CMDBlockPlace implements CustomListener {
@EventHandler
private void onCMDBlockPlace(BlockPlaceEvent e) {
ServerUtils.sendDebugMessage("CommandBlockPlace: Detected block place");
if (!MainConfig.Plugin.preventCmdBlockPlace) return;
if (!Sentinel.mainConfig.plugin.preventCmdBlockPlace) return;
ServerUtils.sendDebugMessage("CommandBlockPlace: Enabled");
if (MainConfig.Plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
if (Sentinel.mainConfig.plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("CommandBlockPlace: Player is operator");
Block b = e.getBlockPlaced();
if (b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK ) {
@@ -33,8 +33,8 @@ public class CMDBlockPlace implements CustomListener {
.setBlock(b)
.setPlayer(p)
.setDenied(true)
.setPunished(MainConfig.Plugin.cmdBlockPunish)
.setnotifyDiscord(MainConfig.Plugin.logCmdBlocks)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setnotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();

View File

@@ -19,9 +19,9 @@ public class CMDBlockUse implements CustomListener {
@EventHandler
private void onCMDBlockUse(PlayerInteractEvent e) {
ServerUtils.sendDebugMessage("CommandBlockUse: Detected Interaction");
if (!MainConfig.Plugin.preventCmdBlockUse) return;
if (!Sentinel.mainConfig.plugin.preventCmdBlockUse) return;
ServerUtils.sendDebugMessage("CommandBlockUse: Enabled");
if (MainConfig.Plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
if (Sentinel.mainConfig.plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("CommandBlockUse: Player is op");
if (e.getClickedBlock() == null) return;
ServerUtils.sendDebugMessage("CommandBlockUse: Block isn't null");
@@ -38,9 +38,9 @@ public class CMDBlockUse implements CustomListener {
.setBlock(b)
.setPlayer(p)
.setDenied(true)
.setPunished(MainConfig.Plugin.cmdBlockPunish)
.setDeoped(MainConfig.Plugin.deop)
.setnotifyDiscord(MainConfig.Plugin.logCmdBlocks)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setnotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();
@@ -52,9 +52,9 @@ public class CMDBlockUse implements CustomListener {
ServerUtils.sendDebugMessage("CommandBlockChange: Detected change block");
if (!(e.getEntity() instanceof Player p)) return;
ServerUtils.sendDebugMessage("CommandBlockChange: Changer is a player");
if (!MainConfig.Plugin.preventCmdBlockUse) return;
if (!Sentinel.mainConfig.plugin.preventCmdBlockUse) return;
ServerUtils.sendDebugMessage("CommandBlockChange: Enabled");
if (MainConfig.Plugin.cmdBlockOpCheck && !p.isOp()) return;
if (Sentinel.mainConfig.plugin.cmdBlockOpCheck && !p.isOp()) return;
ServerUtils.sendDebugMessage("CommandBlockChange: Player is op");
Block b = e.getBlock();
if (b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK) {
@@ -71,9 +71,9 @@ public class CMDBlockUse implements CustomListener {
.setCommand(cb.getCommand())
.setPlayer(p)
.setDenied(true)
.setPunished(MainConfig.Plugin.cmdBlockPunish)
.setDeoped(MainConfig.Plugin.deop)
.setnotifyDiscord(MainConfig.Plugin.logCmdBlocks)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setnotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();

View File

@@ -16,9 +16,9 @@ public class CMDMinecartPlace implements CustomListener {
@EventHandler
private void onCMDMinecartPlace(PlayerInteractEvent e) {
ServerUtils.sendDebugMessage("MinecartCommandPlace: Detected interaction");
if (MainConfig.Plugin.preventCmdCartPlace) {
if (Sentinel.mainConfig.plugin.preventCmdCartPlace) {
ServerUtils.sendDebugMessage("MinecartCommandPlace: Enabled");
if (MainConfig.Plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
if (Sentinel.mainConfig.plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Player is op");
if (e.getItem() == null) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Item isn't null");
@@ -38,12 +38,12 @@ public class CMDMinecartPlace implements CustomListener {
.setEvent(e)
.setPlayer(p)
.setBlock(e.getClickedBlock())
.setDenied(MainConfig.Plugin.preventCmdCartPlace)
.setPunished(MainConfig.Plugin.cmdBlockPunish)
.setDeoped(MainConfig.Plugin.deop)
.setDenied(Sentinel.mainConfig.plugin.preventCmdCartPlace)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setNotifyConsole(true)
.setNotifyTrusted(true)
.setnotifyDiscord(MainConfig.Plugin.logCmdBlocks)
.setnotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.execute();
}
}

View File

@@ -15,9 +15,9 @@ public class CMDMinecartUse implements CustomListener {
@EventHandler
private void onCMDBlockMinecartUse(PlayerInteractEntityEvent e) {
ServerUtils.sendDebugMessage("MinecartCommandUse: Detected Interaction with entity");
if (!MainConfig.Plugin.preventCmdCartUse) return;
if (!Sentinel.mainConfig.plugin.preventCmdCartUse) return;
ServerUtils.sendDebugMessage("MinecartCommandUse: Enabled");
if (MainConfig.Plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
if (Sentinel.mainConfig.plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("MinecartCommandUse: Player op");
if (e.getRightClicked().getType() == EntityType.MINECART_COMMAND) {
ServerUtils.sendDebugMessage("MinecartCommandUse: Entity is minecart command");
@@ -30,8 +30,8 @@ public class CMDMinecartUse implements CustomListener {
.setEvent(e)
.setPlayer(p)
.setDenied(true)
.setPunished(MainConfig.Plugin.cmdBlockPunish)
.setnotifyDiscord(MainConfig.Plugin.logCmdBlocks)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setnotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();

View File

@@ -18,21 +18,21 @@ public class ChatEvent implements CustomListener {
ServerUtils.sendDebugMessage("ChatEvent: Chat event detected!");
if (!Sentinel.isTrusted(e.getPlayer()) || !e.getPlayer().hasPermission("sentinel.chat.antiunicode.bypass")) {
ServerUtils.sendDebugMessage("ChatEvent: Permission bypass failed, checking for unicode");
if (MainConfig.Chat.antiUnicode) {
if (Sentinel.mainConfig.chat.antiUnicode) {
ServerUtils.sendDebugMessage(("ChatEvent: Enabled, Continuing unicode check!"));
AntiUnicode.handleAntiUnicode(e);
}
}
if (!Sentinel.isTrusted(e.getPlayer()) || !e.getPlayer().hasPermission("sentinel.chat.antiswear.bypass")) {
ServerUtils.sendDebugMessage("ChatEvent: Permission bypass failed, checking for swears");
if (MainConfig.Chat.AntiSwear.antiSwearEnabled) {
if (Sentinel.mainConfig.chat.antiSwear.antiSwearEnabled) {
ServerUtils.sendDebugMessage(("ChatEvent: Enabled, Continuing swear check!"));
ProfanityFilter.handleProfanityFilter(e);
}
}
if (!Sentinel.isTrusted(e.getPlayer()) || !e.getPlayer().hasPermission("sentinel.chat.antispam.bypass")) {
ServerUtils.sendDebugMessage(("ChatEvent: Permission bypass failed, checking for spam"));
if (MainConfig.Chat.AntiSpam.antiSpamEnabled) {
if (Sentinel.mainConfig.chat.antiSpam.antiSpamEnabled) {
ServerUtils.sendDebugMessage(("ChatEvent: Enabled, Continuing spam check!"));
AntiSpam.handleAntiSpam(e);
}

View File

@@ -29,15 +29,15 @@ public class CommandEvent implements CustomListener {
.setPlayer(p)
.setCommand(fullcommand)
.setDenied(true)
.setDeoped(MainConfig.Plugin.deop)
.setPunished(MainConfig.Plugin.commandPunish)
.setnotifyDiscord(MainConfig.Plugin.logDangerous)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setPunished(Sentinel.mainConfig.plugin.commandPunish)
.setnotifyDiscord(Sentinel.mainConfig.plugin.logDangerous)
.setNotifyConsole(true)
.setNotifyTrusted(true)
.execute();
}
}
if (MainConfig.Plugin.blockSpecific) {
if (Sentinel.mainConfig.plugin.blockSpecific) {
ServerUtils.sendDebugMessage("CommandEvent: Checking command for specific");
if (command.contains(":")) {
ServerUtils.sendDebugMessage("CommandEvent: Failed check");
@@ -50,9 +50,9 @@ public class CommandEvent implements CustomListener {
.setPlayer(p)
.setCommand(command)
.setDenied(true)
.setDeoped(MainConfig.Plugin.deop)
.setPunished(MainConfig.Plugin.specificPunish)
.setnotifyDiscord(MainConfig.Plugin.logSpecific)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setPunished(Sentinel.mainConfig.plugin.specificPunish)
.setnotifyDiscord(Sentinel.mainConfig.plugin.logSpecific)
.setNotifyConsole(true)
.setNotifyTrusted(true)
.execute();

View File

@@ -26,7 +26,7 @@ public class NBTEvents implements CustomListener {
@EventHandler
private void onNBTPull(InventoryCreativeEvent e) {
ServerUtils.sendDebugMessage("NBT: Detected creative mode action");
if (!MainConfig.Plugin.preventNBT) return;
if (!Sentinel.mainConfig.plugin.preventNBT) return;
ServerUtils.sendDebugMessage("NBT: Enabled");
if (!(e.getWhoClicked() instanceof Player p)) return;
ServerUtils.sendDebugMessage("NBT: Clicker is a player");
@@ -46,13 +46,13 @@ public class NBTEvents implements CustomListener {
.setAction(ActionType.NBT)
.setPlayer(Bukkit.getPlayer(e.getWhoClicked().getName()))
.setItem(e.getCursor())
.setDenied(MainConfig.Plugin.preventNBT)
.setDeoped(MainConfig.Plugin.deop)
.setPunished(MainConfig.Plugin.nbtPunish)
.setRevertGM(MainConfig.Plugin.preventNBT)
.setDenied(Sentinel.mainConfig.plugin.preventNBT)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setPunished(Sentinel.mainConfig.plugin.nbtPunish)
.setRevertGM(Sentinel.mainConfig.plugin.preventNBT)
.setNotifyConsole(true)
.setNotifyTrusted(true)
.setnotifyDiscord(MainConfig.Plugin.logNBT)
.setnotifyDiscord(Sentinel.mainConfig.plugin.logNBT)
.execute();
}
}
@@ -119,19 +119,19 @@ public class NBTEvents implements CustomListener {
return false;
}
}
if (!NBTConfig.allowName && meta.hasDisplayName()) {
if (!Sentinel.nbtConfig.allowName && meta.hasDisplayName()) {
ServerUtils.sendDebugMessage("NBT: No pass N");
return false;
}
if (!NBTConfig.allowLore && meta.hasLore()) {
if (!Sentinel.nbtConfig.allowLore && meta.hasLore()) {
ServerUtils.sendDebugMessage("NBT: No Pass L ");
return false;
}
if (!NBTConfig.allowAttributes && meta.hasAttributeModifiers()) {
if (!Sentinel.nbtConfig.allowAttributes && meta.hasAttributeModifiers()) {
ServerUtils.sendDebugMessage("NBT: No pass A");
return false;
}
if (NBTConfig.globalMaxEnchant != 0 && hasIllegalEnchants(i)) {
if (Sentinel.nbtConfig.globalMaxEnchant != 0 && hasIllegalEnchants(i)) {
ServerUtils.sendDebugMessage("NBT: No pass E");
return false;
}
@@ -156,174 +156,174 @@ public class NBTEvents implements CustomListener {
final ItemMeta meta = i.getItemMeta();
final Map<Enchantment, Integer> enchantments = meta.getEnchants();
for (Integer value : enchantments.values()) {
if (value > NBTConfig.globalMaxEnchant) {
if (value > Sentinel.nbtConfig.globalMaxEnchant) {
return true;
}
}
// ALL
if (meta.hasEnchant(Enchantment.MENDING)) {
final int level = meta.getEnchantLevel(Enchantment.MENDING);
return level > NBTConfig.maxMending || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxMending || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.DURABILITY)) {
final int level = meta.getEnchantLevel(Enchantment.DURABILITY);
return level > NBTConfig.maxUnbreaking || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxUnbreaking || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.VANISHING_CURSE)) {
final int level = meta.getEnchantLevel(Enchantment.VANISHING_CURSE);
return level > NBTConfig.maxVanishing || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxVanishing || level > Sentinel.nbtConfig.globalMaxEnchant;
}
// ARMOR
if (meta.hasEnchant(Enchantment.BINDING_CURSE)) {
final int level = meta.getEnchantLevel(Enchantment.BINDING_CURSE);
return level > NBTConfig.maxCurseOfBinding || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxCurseOfBinding || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.WATER_WORKER)) {
final int level = meta.getEnchantLevel(Enchantment.WATER_WORKER);
return level > NBTConfig.maxAquaAffinity || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxAquaAffinity || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.PROTECTION_ENVIRONMENTAL)) {
final int level = meta.getEnchantLevel(Enchantment.PROTECTION_ENVIRONMENTAL);
return level > NBTConfig.maxProtection || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxProtection || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.PROTECTION_EXPLOSIONS)) {
final int level = meta.getEnchantLevel(Enchantment.PROTECTION_EXPLOSIONS);
return level > NBTConfig.maxBlastProtection || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxBlastProtection || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.DEPTH_STRIDER)) {
final int level = meta.getEnchantLevel(Enchantment.DEPTH_STRIDER);
return level > NBTConfig.maxDepthStrider || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxDepthStrider || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.PROTECTION_FALL)) {
final int level = meta.getEnchantLevel(Enchantment.PROTECTION_FALL);
return level > NBTConfig.maxFeatherFalling || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxFeatherFalling || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.PROTECTION_FIRE)) {
final int level = meta.getEnchantLevel(Enchantment.PROTECTION_FIRE);
return level > NBTConfig.maxFireProtection || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxFireProtection || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.FROST_WALKER)) {
final int level = meta.getEnchantLevel(Enchantment.FROST_WALKER);
return level > NBTConfig.maxFrostWalker || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxFrostWalker || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.PROTECTION_PROJECTILE)) {
final int level = meta.getEnchantLevel(Enchantment.PROTECTION_PROJECTILE);
return level > NBTConfig.maxProjectileProtection || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxProjectileProtection || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.OXYGEN)) {
final int level = meta.getEnchantLevel(Enchantment.OXYGEN);
return level > NBTConfig.maxRespiration || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxRespiration || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.SOUL_SPEED)) {
final int level = meta.getEnchantLevel(Enchantment.SOUL_SPEED);
return level > NBTConfig.maxSoulSpeed || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxSoulSpeed || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.THORNS)) {
final int level = meta.getEnchantLevel(Enchantment.THORNS);
return level > NBTConfig.maxThorns || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxThorns || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.SWEEPING_EDGE)) {
final int level = meta.getEnchantLevel(Enchantment.SWEEPING_EDGE);
return level > NBTConfig.maxSweepingEdge || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxSweepingEdge || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.FROST_WALKER)) {
final int level = meta.getEnchantLevel(Enchantment.FROST_WALKER);
return level > NBTConfig.maxFrostWalker || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxFrostWalker || level > Sentinel.nbtConfig.globalMaxEnchant;
}
// MELEE WEAPONS
if (meta.hasEnchant(Enchantment.DAMAGE_ARTHROPODS)) {
final int level = meta.getEnchantLevel(Enchantment.DAMAGE_ARTHROPODS);
return level > NBTConfig.maxBaneOfArthropods || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxBaneOfArthropods || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.FIRE_ASPECT)) {
final int level = meta.getEnchantLevel(Enchantment.FIRE_ASPECT);
return level > NBTConfig.maxFireAspect || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxFireAspect || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.LOOT_BONUS_MOBS)) {
final int level = meta.getEnchantLevel(Enchantment.LOOT_BONUS_MOBS);
return level > NBTConfig.maxLooting || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxLooting || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.IMPALING)) {
final int level = meta.getEnchantLevel(Enchantment.IMPALING);
return level > NBTConfig.maxImpaling || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxImpaling || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.KNOCKBACK)) {
final int level = meta.getEnchantLevel(Enchantment.KNOCKBACK);
return level > NBTConfig.maxKnockback || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxKnockback || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.DAMAGE_ALL)) {
final int level = meta.getEnchantLevel(Enchantment.DAMAGE_ALL);
return level > NBTConfig.maxSharpness || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxSharpness || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.DAMAGE_UNDEAD)) {
final int level = meta.getEnchantLevel(Enchantment.DAMAGE_UNDEAD);
return level > NBTConfig.maxSmite || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxSmite || level > Sentinel.nbtConfig.globalMaxEnchant;
}
// RANGED WEAPONS
if (meta.hasEnchant(Enchantment.CHANNELING)) {
final int level = meta.getEnchantLevel(Enchantment.CHANNELING);
return level > NBTConfig.maxChanneling || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxChanneling || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.ARROW_FIRE)) {
final int level = meta.getEnchantLevel(Enchantment.ARROW_FIRE);
return level > NBTConfig.maxFlame || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxFlame || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.ARROW_INFINITE)) {
final int level = meta.getEnchantLevel(Enchantment.ARROW_INFINITE);
return level > NBTConfig.maxInfinity || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxInfinity || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.LOYALTY)) {
final int level = meta.getEnchantLevel(Enchantment.LOYALTY);
return level > NBTConfig.maxLoyalty || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxLoyalty || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.RIPTIDE)) {
final int level = meta.getEnchantLevel(Enchantment.RIPTIDE);
return level > NBTConfig.maxRiptide || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxRiptide || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.MULTISHOT)) {
final int level = meta.getEnchantLevel(Enchantment.MULTISHOT);
return level > NBTConfig.maxMultishot || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxMultishot || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.PIERCING)) {
final int level = meta.getEnchantLevel(Enchantment.PIERCING);
return level > NBTConfig.maxPiercing || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxPiercing || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.ARROW_DAMAGE)) {
final int level = meta.getEnchantLevel(Enchantment.ARROW_DAMAGE);
return level > NBTConfig.maxPower || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxPower || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.ARROW_KNOCKBACK)) {
final int level = meta.getEnchantLevel(Enchantment.ARROW_KNOCKBACK);
return level > NBTConfig.maxPunch || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxPunch || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.QUICK_CHARGE)) {
final int level = meta.getEnchantLevel(Enchantment.QUICK_CHARGE);
return level > NBTConfig.maxQuickCharge || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxQuickCharge || level > Sentinel.nbtConfig.globalMaxEnchant;
}
// TOOLS
if (meta.hasEnchant(Enchantment.DIG_SPEED)) {
final int level = meta.getEnchantLevel(Enchantment.DIG_SPEED);
return level > NBTConfig.maxEfficiency || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxEfficiency || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.LOOT_BONUS_BLOCKS)) {
final int level = meta.getEnchantLevel(Enchantment.LOOT_BONUS_BLOCKS);
return level > NBTConfig.maxFortune || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxFortune || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.LUCK)) {
final int level = meta.getEnchantLevel(Enchantment.LUCK);
return level > NBTConfig.maxLuckOfTheSea || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxLuckOfTheSea || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.LURE)) {
final int level = meta.getEnchantLevel(Enchantment.LURE);
return level > NBTConfig.maxLure || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxLure || level > Sentinel.nbtConfig.globalMaxEnchant;
}
if (meta.hasEnchant(Enchantment.SILK_TOUCH)) {
final int level = meta.getEnchantLevel(Enchantment.SILK_TOUCH);
return level > NBTConfig.maxSilkTouch || level > NBTConfig.globalMaxEnchant;
return level > Sentinel.nbtConfig.maxSilkTouch || level > Sentinel.nbtConfig.globalMaxEnchant;
}
}
return false;

View File

@@ -102,7 +102,7 @@ public class Action {
String itemLog = (item != null) ? FileUtils.createNBTLog(item.getItemMeta().getAsString()) : "";
String commandLog = (loggedCommand != null) ? FileUtils.createCommandLog(loggedCommand) : "";
final List<String> punishCommands = MainConfig.Plugin.punishCommands;
final List<String> punishCommands = Sentinel.mainConfig.plugin.punishCommands;
if (denied) {
event.setCancelled(true);
@@ -159,7 +159,7 @@ public class Action {
}
if (notifyDiscord) {
DiscordWebhook webhook = new DiscordWebhook(MainConfig.Plugin.webhook);
DiscordWebhook webhook = new DiscordWebhook(Sentinel.mainConfig.plugin.webhook);
webhook.setAvatarUrl("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png");
webhook.setUsername("Sentinel Anti-Nuke | Logs");
String description = (player != null) ? Emojis.rightSort + " **Player:** " + player.getName() + " " + Emojis.member + "\n" : "";

View File

@@ -3,8 +3,8 @@ package io.github.thetrouper.sentinel.server;
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.discord.DiscordWebhook;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.functions.ReportFalsePositives;
import io.github.thetrouper.sentinel.server.util.ServerUtils;
import io.github.thetrouper.sentinel.server.util.Text;
@@ -24,56 +24,65 @@ import static io.github.thetrouper.sentinel.server.functions.ProfanityFilter.*;
public class FilterAction {
public static void filterAction(Player offender, AsyncPlayerChatEvent e, String highlighted, String severity, Double similarity, FAT type) {
public static void filterAction(Player offender, AsyncPlayerChatEvent e, String highlighted, FilterSeverity severity, Double similarity, FAT type) {
String report = ReportFalsePositives.generateReport(e);
TextComponent warn = new TextComponent();
warn.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("action-automatic-reportable"))));
warn.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
DecimalFormat fs = new DecimalFormat("##.#");
fs.setRoundingMode(RoundingMode.DOWN);
TextComponent notif = new TextComponent();
notif.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText((type != FAT.SPAM && type != FAT.BLOCK_SPAM ? Sentinel.dict.get("severity-notification-hover").formatted(e.getMessage(), highlighted, severity) : Sentinel.dict.get("spam-notification-hover").formatted(e.getMessage(),lastMessageMap.get(offender),fs.format(similarity))))));
TextComponent warn = createTextComponent(Text.prefix(Sentinel.dict.get(type.getWarnTranslationKey())));
warn.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("action-automatic-reportable"))));
warn.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
TextComponent notif = createTextComponent(Text.prefix((type != FAT.SPAM_PUNISH && type != FAT.BLOCK_SPAM ?
Sentinel.dict.get("severity-notification-hover").formatted(e.getMessage(), highlighted, severity.name().toLowerCase().replace("_"," ")) :
Sentinel.dict.get("spam-notification-hover").formatted(e.getMessage(), lastMessageMap.get(offender), fs.format(similarity)))));
notif.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("severity-notification-hover"))));
notif.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
warn.setText(Text.prefix(Sentinel.dict.get(type.getWarnTranslationKey())));
sendMessages(offender, warn, notif, type);
if (shouldLogSwears(type)) {
sendDiscordLog(offender, e, type);
sendConsoleLog(offender, e, type);
}
}
private static void sendMessages(Player offender, TextComponent warn, TextComponent notif, FAT type) {
offender.spigot().sendMessage(warn);
String notiftext = Sentinel.dict.get(type.getNotifTranslationKey());
String notifText = Sentinel.dict.get(type.getNotifTranslationKey());
notif.setText(Text.prefix((type != FAT.SPAM_PUNISH && type != FAT.BLOCK_SPAM ?
notifText.formatted(offender.getName(), scoreMap.get(offender), Sentinel.mainConfig.chat.antiSwear.punishScore) :
notifText.formatted(offender.getName(), heatMap.get(offender), Sentinel.mainConfig.chat.antiSpam.punishHeat))));
notif.setText(Text.prefix((type != FAT.SPAM && type != FAT.BLOCK_SPAM ? notiftext.formatted(offender.getName(), scoreMap.get(offender), MainConfig.Chat.AntiSwear.punishScore) : notiftext.formatted(offender.getName(),heatMap.get(offender),MainConfig.Chat.AntiSpam.punishHeat))));
ServerUtils.forEachStaff(staffmember -> {
staffmember.spigot().sendMessage(notif);
});
ServerUtils.forEachStaff(staffmember -> staffmember.spigot().sendMessage(notif));
if (type.getExecutedCommand() != null) {
ServerUtils.sendCommand(type.getExecutedCommand().replace("%player%", offender.getName()));
}
if (type == FAT.SWEAR && MainConfig.Chat.AntiSwear.logSwears) {
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
}
if (type == FAT.SLUR && MainConfig.Chat.AntiSwear.logSwears) {
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
}
if (type == FAT.SPAM && Sentinel.mainConfig) {
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
private static TextComponent createTextComponent(String text) {
TextComponent component = new TextComponent();
component.setText(text);
return component;
}
private static boolean shouldLogSwears(FAT type) {
return (type == FAT.SWEAR_PUNISH || type == FAT.SLUR_PUNISH) && Sentinel.mainConfig.chat.antiSwear.logSwears
|| (type == FAT.SPAM_PUNISH && Sentinel.mainConfig.chat.antiSpam.logSpam);
}
public static void sendConsoleLog(Player offender, AsyncPlayerChatEvent e, FAT type) {
String log = "]=-" + type.getTitle() + "-=[\n" +
"Player: " + offender.getName() +
(type != FAT.BLOCK_SPAM && type != FAT.SPAM ? "> Score: `" + scoreMap.get(offender) + "/" + MainConfig.Chat.AntiSwear.punishScore : "> Heat: `" + heatMap.get(offender) + "/" + MainConfig.Chat.AntiSpam.punishHeat) + "\n" +
(type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "> Score: `" + scoreMap.get(offender) + "/" + Sentinel.mainConfig.chat.antiSwear.punishScore :
"> Heat: `" + heatMap.get(offender) + "/" + Sentinel.mainConfig.chat.antiSpam.punishHeat) + "\n" +
"> UUID: " + offender.getUniqueId() + "\n" +
(type != FAT.BLOCK_SPAM && type != FAT.SPAM ? "Message: " + e.getMessage() : "Previous: " + lastMessageMap.get(offender)) + "\n" +
(type != FAT.BLOCK_SPAM && type != FAT.SPAM ? "Reduced: " + fullSimplify(e.getMessage()) : "Current: " + e.getMessage()) + "\n" +
(type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "Message: " + e.getMessage() : "Previous: " + lastMessageMap.get(offender)) + "\n" +
(type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "Reduced: " + fullSimplify(e.getMessage()) : "Current: " + e.getMessage()) + "\n" +
(type.getExecutedCommand() != null ? "Executed: " + type.getExecutedCommand() : "Executed: Nothing, its a standard flag. You shouldn't be seeing this, please report it.");
Sentinel.log.info(log);
}
@@ -83,7 +92,7 @@ public class FilterAction {
String title = offender.getName() + " has triggered the " + type.getName() + "!";
String executed = type.getExecutedCommand() != null ? type.getExecutedCommand() : "Nothing, its a standard flag. You shouldn't be seeing this, please report it.";
DiscordWebhook webhook = new DiscordWebhook(Sentinel.mainConfig.);
DiscordWebhook webhook = new DiscordWebhook(Sentinel.mainConfig.plugin.webhook);
webhook.setAvatarUrl("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png");
webhook.setUsername("Sentinel Anti-Nuke | Logs");
@@ -92,12 +101,16 @@ public class FilterAction {
.setTitle(title)
.setDescription(
Emojis.rightSort + "Player: " + offender.getName() + " " + Emojis.target + "\\n" +
Emojis.space + Emojis.arrowRight + (type != FAT.BLOCK_SPAM ? "Score: `" + scoreMap.get(offender) + "/" + MainConfig.Chat.AntiSwear.punishScore : "Heat: `" + heatMap.get(offender) + "/" + MainConfig.Chat.AntiSpam.punishHeat) + "`\\n" +
Emojis.space + Emojis.arrowRight + (type != FAT.BLOCK_SPAM ?
"Score: `" + scoreMap.get(offender) + "/" + Sentinel.mainConfig.chat.antiSwear.punishScore :
"Heat: `" + heatMap.get(offender) + "/" + Sentinel.mainConfig.chat.antiSpam.punishHeat) + "`\\n" +
Emojis.space + Emojis.arrowRight + "UUID: `" + offender.getUniqueId() + "`\\n" +
Emojis.rightSort + "Executed: " + executed + " " + Emojis.mute + "\\n"
)
.addField((type != FAT.BLOCK_SPAM && type != FAT.SPAM ? "Message: " : "Previous: "), (type != FAT.BLOCK_SPAM && type != FAT.SPAM ? e.getMessage() : lastMessageMap.get(offender)) + Emojis.alarm, false)
.addField((type != FAT.BLOCK_SPAM && type != FAT.SPAM ? "Reduced: " : "Current: "), (type != FAT.BLOCK_SPAM && type != FAT.SPAM ? highlightProfanity(e.getMessage(), "||", "||") : e.getMessage()) + " " + Emojis.noDM, false)
.addField((type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "Message: " : "Previous: "),
(type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? e.getMessage() : lastMessageMap.get(offender)) + Emojis.alarm, false)
.addField((type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "Reduced: " : "Current: "),
(type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? highlightProfanity(e.getMessage(), "||", "||") : e.getMessage()) + " " + Emojis.noDM, false)
.setColor(type.getColor())
.setThumbnail("https://crafatar.com/avatars/" + offender.getUniqueId() + "?size=64&&overlay");
@@ -111,4 +124,51 @@ public class FilterAction {
Sentinel.log.info(ex.toString());
}
}
/*
public static void filterAction(Player offender, AsyncPlayerChatEvent e, String highlighted, String severity, Double similarity, FAT type) {
String report = ReportFalsePositives.generateReport(e);
TextComponent warn = new TextComponent();
warn.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("action-automatic-reportable"))));
warn.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
DecimalFormat fs = new DecimalFormat("##.#");
fs.setRoundingMode(RoundingMode.DOWN);
TextComponent notif = new TextComponent();
notif.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText((type != FAT.SPAM_PUNISH && type != FAT.BLOCK_SPAM ? Sentinel.dict.get("severity-notification-hover").formatted(e.getMessage(), highlighted, severity) : Sentinel.dict.get("spam-notification-hover").formatted(e.getMessage(),lastMessageMap.get(offender),fs.format(similarity))))));
notif.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
warn.setText(Text.prefix(Sentinel.dict.get(type.getWarnTranslationKey())));
offender.spigot().sendMessage(warn);
String notiftext = Sentinel.dict.get(type.getNotifTranslationKey());
notif.setText(Text.prefix((type != FAT.SPAM_PUNISH && type != FAT.BLOCK_SPAM ? notiftext.formatted(offender.getName(), scoreMap.get(offender), Sentinel.mainConfig.chat.antiSwear.punishScore) : notiftext.formatted(offender.getName(),heatMap.get(offender),Sentinel.mainConfig.chat.antiSpam.punishHeat))));
ServerUtils.forEachStaff(staffmember -> {
staffmember.spigot().sendMessage(notif);
});
if (type.getExecutedCommand() != null) {
ServerUtils.sendCommand(type.getExecutedCommand().replace("%player%", offender.getName()));
}
if (type == FAT.SWEAR_PUNISH && Sentinel.mainConfig.chat.antiSwear.logSwears) {
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
}
if (type == FAT.SLUR_PUNISH && Sentinel.mainConfig.chat.antiSwear.logSwears) {
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
}
if (type == FAT.SPAM_PUNISH && Sentinel.mainConfig.chat.antiSpam.logSpam) {
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
}
}*/
}

View File

@@ -15,7 +15,7 @@ public class AdvancedConfig implements JsonSerializable<AdvancedConfig> {
return file;
}
public static Map<String, String> leetPatterns = new HashMap<>() {{
public Map<String, String> leetPatterns = new HashMap<>() {{
put("0", "o");
put("1", "i");
put("3", "e");
@@ -33,8 +33,8 @@ public class AdvancedConfig implements JsonSerializable<AdvancedConfig> {
put("V", "u");
put("v", "u");
}};
public static String falsePosRegex = "";
public static String swearRegex = "";
public static String strictRegex = "";
public static String urlRegex = "^(https?://)?([a-zA-Z0-9-]+\\.)*[a-zA-Z0-9-]+\\.[a-zA-Z]{2,}(/\\S*)?$\n";
public String falsePosRegex = "";
public String swearRegex = "";
public String strictRegex = "";
public String urlRegex = "(http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)";
}

View File

@@ -16,7 +16,7 @@ public class FPConfig implements JsonSerializable<FPConfig> {
return file;
}
public static List<String> swearWhitelist = new ArrayList<>(Arrays.asList(
public List<String> swearWhitelist = new ArrayList<>(Arrays.asList(
"but then",
"was scamming",
"an alt",

View File

@@ -8,7 +8,7 @@ import java.util.HashMap;
import java.util.Map;
public class LanguageFile implements JsonSerializable<LanguageFile> {
public static final File PATH = new File(Sentinel.getInstance().getDataFolder(), "/lang/" + MainConfig.Plugin.lang);
public static final File PATH = new File(Sentinel.getInstance().getDataFolder(), "/lang/" + Sentinel.mainConfig.plugin.lang);
private final Map<String,String> dictionary = new HashMap<>();
public LanguageFile() {}

View File

@@ -18,6 +18,7 @@ public class MainConfig implements JsonSerializable<MainConfig> {
public Chat chat = new Chat();
public class Plugin {
public String license = "null";
public String prefix = "§d§lSentinel §8» §7";
public String webhook = "https://discord.com/api/webhooks/id/token";
public String lang = "en-us.json";

View File

@@ -15,47 +15,47 @@ public class NBTConfig implements JsonSerializable<NBTConfig> {
return file;
}
public static boolean allowName = true;
public static boolean allowLore = true;
public static boolean allowAttributes = false;
public static int globalMaxEnchant = 5;
public static int maxMending = 1;
public static int maxUnbreaking = 3;
public static int maxVanishing = 1;
public static int maxAquaAffinity = 1;
public static int maxBlastProtection = 4;
public static int maxCurseOfBinding = 1;
public static int maxDepthStrider = 3;
public static int maxFeatherFalling = 4;
public static int maxFireProtection = 4;
public static int maxFrostWalker = 2;
public static int maxProjectileProtection = 4;
public static int maxProtection = 4;
public static int maxRespiration = 3;
public static int maxSoulSpeed = 3;
public static int maxThorns = 3;
public static int maxSwiftSneak = 3;
public static int maxBaneOfArthropods = 5;
public static int maxEfficiency = 5;
public static int maxFireAspect = 2;
public static int maxLooting = 3;
public static int maxImpaling = 5;
public static int maxKnockback = 2;
public static int maxSharpness = 5;
public static int maxSmite = 5;
public static int maxSweepingEdge = 3;
public static int maxChanneling = 1;
public static int maxFlame = 1;
public static int maxInfinity = 1;
public static int maxLoyalty = 3;
public static int maxRiptide = 3;
public static int maxMultishot = 1;
public static int maxPiercing = 4;
public static int maxPower = 5;
public static int maxPunch = 2;
public static int maxQuickCharge = 3;
public static int maxFortune = 3;
public static int maxLuckOfTheSea = 3;
public static int maxLure = 3;
public static int maxSilkTouch = 1;
public boolean allowName = true;
public boolean allowLore = true;
public boolean allowAttributes = false;
public int globalMaxEnchant = 5;
public int maxMending = 1;
public int maxUnbreaking = 3;
public int maxVanishing = 1;
public int maxAquaAffinity = 1;
public int maxBlastProtection = 4;
public int maxCurseOfBinding = 1;
public int maxDepthStrider = 3;
public int maxFeatherFalling = 4;
public int maxFireProtection = 4;
public int maxFrostWalker = 2;
public int maxProjectileProtection = 4;
public int maxProtection = 4;
public int maxRespiration = 3;
public int maxSoulSpeed = 3;
public int maxThorns = 3;
public int maxSwiftSneak = 3;
public int maxBaneOfArthropods = 5;
public int maxEfficiency = 5;
public int maxFireAspect = 2;
public int maxLooting = 3;
public int maxImpaling = 5;
public int maxKnockback = 2;
public int maxSharpness = 5;
public int maxSmite = 5;
public int maxSweepingEdge = 3;
public int maxChanneling = 1;
public int maxFlame = 1;
public int maxInfinity = 1;
public int maxLoyalty = 3;
public int maxRiptide = 3;
public int maxMultishot = 1;
public int maxPiercing = 4;
public int maxPower = 5;
public int maxPunch = 2;
public int maxQuickCharge = 3;
public int maxFortune = 3;
public int maxLuckOfTheSea = 3;
public int maxLure = 3;
public int maxSilkTouch = 1;
}

View File

@@ -14,7 +14,7 @@ public class StrictConfig implements JsonSerializable<StrictConfig> {
return file;
}
public static List<String> strict = new ArrayList<>() {{
public List<String> strict = new ArrayList<>() {{
add("nigg");
add("niger");
add("nlgg");

View File

@@ -14,7 +14,7 @@ public class SwearsConfig implements JsonSerializable<SwearsConfig> {
return file;
}
public static List<String> swears = new ArrayList<>() {{
public List<String> swears = new ArrayList<>() {{
add("anal");
add("anus");
add("arse");

View File

@@ -1,8 +1,8 @@
package io.github.thetrouper.sentinel.server.functions;
import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.FAT;
import io.github.thetrouper.sentinel.server.FilterAction;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.util.GPTUtils;
import io.github.thetrouper.sentinel.server.util.ServerUtils;
import io.github.thetrouper.sentinel.server.util.Text;
@@ -38,29 +38,29 @@ public class AntiSpam {
if (lastMessageMap.containsKey(p)) {
String lastMessage = lastMessageMap.get(p);
double similarity = GPTUtils.calcSim(message, lastMessage);
ServerUtils.sendDebugMessage("AntiSpam: " + p.getName() + " has a heat of " + heatMap.get(p) + "/" + MainConfig.Chat.AntiSpam.punishHeat + ". Current Message: \"" + message + "\" Last message: \"" + lastMessage + "\"");
ServerUtils.sendDebugMessage("AntiSpam: " + p.getName() + " has a heat of " + heatMap.get(p) + "/" + Sentinel.mainConfig.chat.antiSpam.punishHeat + ". Current Message: \"" + message + "\" Last message: \"" + lastMessage + "\"");
if (similarity > 90) {
heatMap.put(p, heatMap.get(p) + MainConfig.Chat.AntiSpam.highGain);
ServerUtils.sendDebugMessage("AntiSpam: Similarity: " + similarity + ", is greater than 90% for " + p.getName() + ". Adding " + MainConfig.Chat.AntiSpam.highGain);
heatMap.put(p, heatMap.get(p) + Sentinel.mainConfig.chat.antiSpam.highGain);
ServerUtils.sendDebugMessage("AntiSpam: Similarity: " + similarity + ", is greater than 90% for " + p.getName() + ". Adding " + Sentinel.mainConfig.chat.antiSpam.highGain);
} else if (similarity > 50) {
heatMap.put(p, heatMap.get(p) + MainConfig.Chat.AntiSpam.mediumGain);
ServerUtils.sendDebugMessage("AntiSpam: Similarity: " + similarity + ", is greater than 50% for " + p.getName() + ". Adding " + MainConfig.Chat.AntiSpam.mediumGain);
heatMap.put(p, heatMap.get(p) + Sentinel.mainConfig.chat.antiSpam.mediumGain);
ServerUtils.sendDebugMessage("AntiSpam: Similarity: " + similarity + ", is greater than 50% for " + p.getName() + ". Adding " + Sentinel.mainConfig.chat.antiSpam.mediumGain);
} else if (similarity > 25) {
heatMap.put(p, heatMap.get(p) + MainConfig.Chat.AntiSpam.lowGain);
ServerUtils.sendDebugMessage("AntiSpam: Similarity: " + similarity + ", is greater than 25% for " + p.getName() + ". Adding " + MainConfig.Chat.AntiSpam.lowGain);
heatMap.put(p, heatMap.get(p) + Sentinel.mainConfig.chat.antiSpam.lowGain);
ServerUtils.sendDebugMessage("AntiSpam: Similarity: " + similarity + ", is greater than 25% for " + p.getName() + ". Adding " + Sentinel.mainConfig.chat.antiSpam.lowGain);
}
}
if (heatMap.get(p) > MainConfig.Chat.AntiSpam.punishHeat) {
if (heatMap.get(p) > Sentinel.mainConfig.chat.antiSpam.punishHeat) {
e.setCancelled(true);
FilterAction.filterAction(p,e,null,null, GPTUtils.calcSim(e.getMessage(),lastMessageMap.get(p)), FAT.SPAM);
FilterAction.filterAction(p,e,null,null, GPTUtils.calcSim(e.getMessage(),lastMessageMap.get(p)), FAT.SPAM_PUNISH);
return;
}
if (heatMap.get(p) > MainConfig.Chat.AntiSpam.blockHeat) {
if (heatMap.get(p) > Sentinel.mainConfig.chat.antiSpam.blockHeat) {
e.setCancelled(true);
FilterAction.filterAction(p,e,null,null, GPTUtils.calcSim(e.getMessage(),lastMessageMap.get(p)), FAT.BLOCK_SPAM);
heatMap.put(p, heatMap.get(p) + MainConfig.Chat.AntiSpam.highGain);
heatMap.put(p, heatMap.get(p) + Sentinel.mainConfig.chat.antiSpam.highGain);
return;
}
lastMessageMap.put(p, message);
@@ -69,7 +69,7 @@ public class AntiSpam {
for (Player p : heatMap.keySet()) {
int heat = heatMap.get(p);
if (heat > 0) {
heat = heat - MainConfig.Chat.AntiSpam.heatDecay;
heat = heat - Sentinel.mainConfig.chat.antiSpam.heatDecay;
heatMap.put(p, Math.max(0, heat));
}
//ServerUtils.sendDebugMessage("AntiSpam: Decaying heat for " + p.getName() + ": " + heatMap.get(p));

View File

@@ -45,7 +45,7 @@ public class Authenticator {
if (key.equals(licenseKey)) {
if (Arrays.asList(allowedArr).contains(serverID)) {
authStatus = "AUTHOReIZED";
authStatus = "AUTHORIZED";
return authStatus;
} else {
if (Arrays.asList(allowedArr).contains("minehut")) {

View File

@@ -23,9 +23,9 @@ public class Message {
receivers.add(sender);
AsyncPlayerChatEvent checkEvent = new AsyncPlayerChatEvent(true,sender,message,receivers);
if (checkEvent.isCancelled()) return;
if (!Sentinel.isTrusted(sender) || !sender.hasPermission("sentinel.chat.antiswear.bypass")) if (MainConfig.Chat.AntiSwear.antiSwearEnabled) ProfanityFilter.handleProfanityFilter(checkEvent);
if (!Sentinel.isTrusted(sender) || !sender.hasPermission("sentinel.chat.antispam.bypass")) if (MainConfig.Chat.AntiSpam.antiSpamEnabled) AntiSpam.handleAntiSpam(checkEvent);
if (!Sentinel.isTrusted(sender) || !sender.hasPermission("sentinel.chat.antiunicode.bypass")) if (MainConfig.Chat.antiUnicode) AntiUnicode.handleAntiUnicode(checkEvent);
if (!Sentinel.isTrusted(sender) || !sender.hasPermission("sentinel.chat.antiswear.bypass")) if (Sentinel.mainConfig.chat.antiSwear.antiSwearEnabled) ProfanityFilter.handleProfanityFilter(checkEvent);
if (!Sentinel.isTrusted(sender) || !sender.hasPermission("sentinel.chat.antispam.bypass")) if (Sentinel.mainConfig.chat.antiSpam.antiSpamEnabled) AntiSpam.handleAntiSpam(checkEvent);
if (!Sentinel.isTrusted(sender) || !sender.hasPermission("sentinel.chat.antiunicode.bypass")) if (Sentinel.mainConfig.chat.antiUnicode) AntiUnicode.handleAntiUnicode(checkEvent);
if (checkEvent.isCancelled()) return;
sender.sendMessage(Sentinel.dict.get("message-sent").formatted(receiver.getName(),message));

View File

@@ -1,81 +1,263 @@
package io.github.thetrouper.sentinel.server.functions;
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.config.*;
import io.github.thetrouper.sentinel.server.util.ServerUtils;
import io.github.thetrouper.sentinel.server.util.Text;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import javax.print.attribute.standard.Severity;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ProfanityFilter {
public static Map<Player, Integer> scoreMap;
private static final List<String> swearBlacklist = SwearsConfig.swears;
private static final List<String> swearWhitelist = FPConfig.swearWhitelist;
private static final List<String> slurs = StrictConfig.strict;
private static final List<String> swearBlacklist = Sentinel.swearConfig.swears;
private static final List<String> swearWhitelist = Sentinel.fpConfig.swearWhitelist;
private static final List<String> slurs = Sentinel.strictConfig.strict;
public static void enableAntiSwear() {
scoreMap = new HashMap<>();
}
public static void handleProfanityFilter(AsyncPlayerChatEvent e) {
Player p = e.getPlayer();
String message = Text.removeFirstColor(e.getMessage());
String highlighted = highlightProfanity(message);
FilterSeverity severity = ProfanityFilter.checkSeverity(message);
if (severity.equals(FilterSeverity.SAFE)) return;
if (!scoreMap.containsKey(p)) scoreMap.put(p, 0);
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + severity.getScore());
e.setCancelled(true);
FilterAction.filterAction(p,e,highlighted,severity,null,getFAT(severity));
}
private static FAT getFAT(FilterSeverity severity) {
switch (severity) {
case LOW, MEDIUM_LOW, MEDIUM, MEDIUM_HIGH, HIGH -> {
return FAT.BLOCK_SWEAR;
}
case SLUR -> {
return FAT.SLUR_PUNISH;
}
default -> throw new IllegalArgumentException("Warning! This severity doesn't exist! " + severity);
}
}
public static String highlightProfanity(String text) {
String highlightedSwears = highlightSwears(fullSimplify(text), "&e", "&f");
String highlightedText = highlightSlurs(highlightedSwears, "&c", "&f");
return Text.color(highlightedText);
}
public static String highlightProfanity(String text, String start, String end) {
String highlightedSwears = highlightSwears(fullSimplify(text), start, end);
String highlightedText = highlightSlurs(highlightedSwears, start, end);
return Text.color(highlightedText);
}
private static String highlightSwears(String text, String start, String end) {
for (String swear : swearBlacklist) {
if (text.contains(swear)) {text = text.replace(swear, start + swear + end);}
}
return text;
}
private static String highlightSlurs(String text, String start, String end) {
for (String slur : slurs) {
if (text.contains(slur)) {
text = text.replace(slur, start + slur + end);
}
}
return text;
}
/**
* 1: lowercase the text
* 1.4: Separate the string into words
* 1.5: Remove all verified clean english words
* 1.6: Put it back into one string
* 2: remove the known false positives
* 3: Check for swears and return "low" if true
* 4: Convert LeetSpeak Characters
* 5: Check for swears and return "medium-low" if true
* 6: Strip all special characters
* 7: Check for swears and return "medium" if true
* 8: simplify repeating letters
* 9: Check for swears and return "medium-high" if true
* 10: remove periods and spaces
* 11: Check for swears and return "high" if true
*/
public static String fullSimplify(String text) {
String lowercasedText = text.toLowerCase();
String cleanedText = removeFalsePositives(lowercasedText);
String convertedText = convertLeetSpeakCharacters(cleanedText);
String strippedText = stripSpecialCharacters(convertedText);
String simplifiedText = simplifyRepeatingLetters(strippedText);
return removePeriodsAndSpaces(simplifiedText);
}
public static FilterSeverity checkSeverity(String text) {
// 1:
String lowercasedText = text.toLowerCase();
ServerUtils.sendDebugMessage("ProfanityFilter: Lowercased: " + lowercasedText);
// 2:
String cleanedText = removeFalsePositives(lowercasedText);
ServerUtils.sendDebugMessage(("ProfanityFilter: Removed False positives: " + cleanedText));
// 3:
if (containsSwears(cleanedText)) return FilterSeverity.LOW;
if (containsSlurs(cleanedText)) return FilterSeverity.SLUR;
// 4:
String convertedText = convertLeetSpeakCharacters(cleanedText);
ServerUtils.sendDebugMessage(("ProfanityFilter: Leet Converted: " + convertedText));
// 5:
if (containsSwears(convertedText)) return FilterSeverity.MEDIUM_LOW;
if (containsSlurs(cleanedText)) return FilterSeverity.SLUR;
// 6:
String strippedText = stripSpecialCharacters(convertedText);
ServerUtils.sendDebugMessage(("ProfanityFilter: Specials Removed: " + strippedText));
// 7:
if (containsSwears(strippedText)) return FilterSeverity.MEDIUM;
if (containsSlurs(strippedText)) return FilterSeverity.SLUR;
// 8:
String simplifiedText = simplifyRepeatingLetters(strippedText);
ServerUtils.sendDebugMessage(("ProfanityFilter: Removed Repeating: " + simplifiedText));
// 9:
if (containsSwears(simplifiedText)) return FilterSeverity.MEDIUM_HIGH;
if (containsSlurs(simplifiedText)) return FilterSeverity.SLUR;
// 10:
String finalText = removePeriodsAndSpaces(simplifiedText);
ServerUtils.sendDebugMessage(("ProfanityFilter: Remove Punctuation: " + finalText));
// 11:
if (containsSwears(finalText)) return FilterSeverity.HIGH;
if (containsSlurs(finalText)) return FilterSeverity.SLUR;
return FilterSeverity.SAFE;
}
public static boolean ContainsProfanity(String text) {
return containsSwears(text) || containsSlurs(text);
}
private static boolean containsSwears(String text) {
ServerUtils.sendDebugMessage("ProfanityFilter: Checking for swears");
for (String swear : swearBlacklist) {
if (text.contains(swear)) return true;
}
return false;
}
private static boolean containsSlurs(String text) {
ServerUtils.sendDebugMessage("ProfanityFilter: Checking for slurs");
for (String slur : slurs) {
if (text.contains(slur)) return true;
}
return false;
}
public static String removeFalsePositives(String text) {
for (String falsePositive : swearWhitelist) {
text = text.replace(falsePositive, "");
}
return text;
}
public static String convertLeetSpeakCharacters(String text) {
text = Text.fromLeetString(text);
return text;
}
public static String stripSpecialCharacters(String text) {
text = text.replaceAll("[^A-Za-z0-9.,!?;:'\"()\\[\\]{}]", "").trim();
return text;
}
public static String simplifyRepeatingLetters(String text) {
text = Text.replaceRepeatingLetters(text);
return text;
}
public static String removePeriodsAndSpaces(String text) {
return text.replaceAll("[^A-Za-z0-9]", "").replace(" ", "");
}
public static void decayScore() {
for (Player p : scoreMap.keySet()) {
int score = scoreMap.get(p);
if (score > 0) {
score = score - Sentinel.mainConfig.chat.antiSwear.scoreDecay;
scoreMap.put(p, Math.max(0, score));
}
}
}
/*public static void handleProfanityFilter(AsyncPlayerChatEvent e) {
Player p = e.getPlayer();
String message = Text.removeFirstColor(e.getMessage());
String highlighted = highlightProfanity(message);
String severity = ProfanityFilter.checkSeverity(message);
if (!scoreMap.containsKey(p)) scoreMap.put(p, 0);
// Old: if (scoreMap.get(p) > Config.punishScore) punishSwear(p,highlighted,message,e);
if (scoreMap.get(p) > MainConfig.Chat.AntiSwear.punishScore) FilterAction.filterAction(p,e,highlighted,severity, null, FAT.SWEAR);
if (scoreMap.get(p) > Sentinel.mainConfig.chat.antiSwear.punishScore) FilterAction.filterAction(p,e,highlighted,severity, null, FAT.SWEAR);
switch (severity) {
case "low" -> {
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + MainConfig.Chat.AntiSwear.lowScore);
scoreMap.put(p, scoreMap.get(p) + MainConfig.Chat.AntiSwear.lowScore);
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Sentinel.mainConfig.chat.antiSwear.lowScore);
scoreMap.put(p, scoreMap.get(p) + Sentinel.mainConfig.chat.antiSwear.lowScore);
e.setCancelled(true);
// Old: blockSwear(p,highlighted,message,severity,e);
FilterAction.filterAction(p,e,highlighted,severity, null, FAT.BLOCK_SWEAR);
}
case "medium-low" -> {
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + MainConfig.Chat.AntiSwear.mediumLowScore);
scoreMap.put(p, scoreMap.get(p) + MainConfig.Chat.AntiSwear.mediumLowScore);
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Sentinel.mainConfig.chat.antiSwear.mediumLowScore);
scoreMap.put(p, scoreMap.get(p) + Sentinel.mainConfig.chat.antiSwear.mediumLowScore);
e.setCancelled(true);
// Old: blockSwear(p,highlighted,message,severity,e);
FilterAction.filterAction(p,e,highlighted,severity, null, FAT.BLOCK_SWEAR);
}
case "medium" -> {
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + MainConfig.Chat.AntiSwear.mediumScore);
scoreMap.put(p, scoreMap.get(p) + MainConfig.Chat.AntiSwear.mediumScore);
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Sentinel.mainConfig.chat.antiSwear.mediumScore);
scoreMap.put(p, scoreMap.get(p) + Sentinel.mainConfig.chat.antiSwear.mediumScore);
e.setCancelled(true);
// Old: blockSwear(p,highlighted,message,severity,e);
FilterAction.filterAction(p,e,highlighted,severity, null, FAT.BLOCK_SWEAR);
}
case "medium-high" -> {
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + MainConfig.Chat.AntiSwear.mediumHighScore);
scoreMap.put(p, scoreMap.get(p) + MainConfig.Chat.AntiSwear.mediumHighScore);
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Sentinel.mainConfig.chat.antiSwear.mediumHighScore);
scoreMap.put(p, scoreMap.get(p) + Sentinel.mainConfig.chat.antiSwear.mediumHighScore);
e.setCancelled(true);
// Old: blockSwear(p,highlighted,message,severity,e);
FilterAction.filterAction(p,e,highlighted,severity, null, FAT.BLOCK_SWEAR);
}
case "high" -> {
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + MainConfig.Chat.AntiSwear.highScore);
scoreMap.put(p, scoreMap.get(p) + MainConfig.Chat.AntiSwear.highScore);
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Sentinel.mainConfig.chat.antiSwear.highScore);
scoreMap.put(p, scoreMap.get(p) + Sentinel.mainConfig.chat.antiSwear.highScore);
e.setCancelled(true);
// Old: blockSwear(p,highlighted,message,severity,e);
FilterAction.filterAction(p,e,highlighted,severity, null, FAT.BLOCK_SWEAR);
}
case "slur" -> {
// Insta-Punish
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + MainConfig.Chat.AntiSwear.highScore);
scoreMap.put(p, scoreMap.get(p) + MainConfig.Chat.AntiSwear.highScore);
ServerUtils.sendDebugMessage("AntiSwear Flag, Message: " + message + " Concentrated: " + fullSimplify(message) + " Severity: " + severity + " Previous Score: " + scoreMap.get(p) +" Adding Score: " + Sentinel.mainConfig.chat.antiSwear.highScore);
scoreMap.put(p, scoreMap.get(p) + Sentinel.mainConfig.chat.antiSwear.highScore);
e.setCancelled(true);
// Old: punishSlur(p,highlighted,message,e);
FilterAction.filterAction(p,e,highlighted,severity, null,FAT.SLUR);
}
}
}
}*/
/*
public static void punishSwear(Player player, String highlightedMSG, String origMessage, AsyncPlayerChatEvent e) {
@@ -140,155 +322,4 @@ public class ProfanityFilter {
});
}
*/
public static String highlightProfanity(String text) {
String highlightedSwears = highlightSwears(fullSimplify(text), "&e", "&f");
String highlightedText = highlightSlurs(highlightedSwears, "&c", "&f");
return Text.color(highlightedText);
}
public static String highlightProfanity(String text, String start, String end) {
String highlightedSwears = highlightSwears(fullSimplify(text), start, end);
String highlightedText = highlightSlurs(highlightedSwears, start, end);
return Text.color(highlightedText);
}
private static String highlightSwears(String text, String start, String end) {
for (String swear : swearBlacklist) {
if (text.contains(swear)) {text = text.replace(swear, start + swear + end);}
}
return text;
}
private static String highlightSlurs(String text, String start, String end) {
for (String slur : slurs) {
if (text.contains(slur)) {
text = text.replace(slur, start + slur + end);
}
}
return text;
}
/**
* 1: lowercase the text
* 1.4: Separate the string into words
* 1.5: Remove all verified clean english words
* 1.6: Put it back into one string
* 2: remove the known false positives
* 3: Check for swears and return "low" if true
* 4: Convert LeetSpeak Characters
* 5: Check for swears and return "medium-low" if true
* 6: Strip all special characters
* 7: Check for swears and return "medium" if true
* 8: simplify repeating letters
* 9: Check for swears and return "medium-high" if true
* 10: remove periods and spaces
* 11: Check for swears and return "high" if true
*/
public static String fullSimplify(String text) {
String lowercasedText = text.toLowerCase();
String cleanedText = removeFalsePositives(lowercasedText);
String convertedText = convertLeetSpeakCharacters(cleanedText);
String strippedText = stripSpecialCharacters(convertedText);
String simplifiedText = simplifyRepeatingLetters(strippedText);
String finalText = removePeriodsAndSpaces(simplifiedText);
return finalText;
}
public static String checkSeverity(String text) {
// 1:
String lowercasedText = text.toLowerCase();
ServerUtils.sendDebugMessage("ProfanityFilter: Lowercased: " + lowercasedText);
// 2:
String cleanedText = removeFalsePositives(lowercasedText);
ServerUtils.sendDebugMessage(("ProfanityFilter: Removed False positives: " + cleanedText));
// 3:
if (containsSwears(cleanedText)) return "low";
if (containsSlurs(cleanedText)) return "slur";
// 4:
String convertedText = convertLeetSpeakCharacters(cleanedText);
ServerUtils.sendDebugMessage(("ProfanityFilter: Leet Converted: " + convertedText));
// 5:
if (containsSwears(convertedText)) return "medium-low";
if (containsSlurs(cleanedText)) return "slur";
// 6:
String strippedText = stripSpecialCharacters(convertedText);
ServerUtils.sendDebugMessage(("ProfanityFilter: Specials Removed: " + strippedText));
// 7:
if (containsSwears(strippedText)) return "medium";
if (containsSlurs(strippedText)) return "slur";
// 8:
String simplifiedText = simplifyRepeatingLetters(strippedText);
ServerUtils.sendDebugMessage(("ProfanityFilter: Removed Repeating: " + simplifiedText));
// 9:
if (containsSwears(simplifiedText)) return "medium-high";
if (containsSlurs(simplifiedText)) return "slur";
// 10:
String finalText = removePeriodsAndSpaces(simplifiedText);
ServerUtils.sendDebugMessage(("ProfanityFilter: Remove Punctuation: " + finalText));
// 11:
if (containsSwears(finalText)) return "high";
if (containsSlurs(finalText)) return "slur";
return "safe";
}
public static boolean ContainsProfanity(String text) {
return containsSwears(text) || containsSlurs(text);
}
private static boolean containsSwears(String text) {
ServerUtils.sendDebugMessage("ProfanityFilter: Checking for swears");
for (String swear : swearBlacklist) {
if (text.contains(swear)) return true;
}
return false;
}
private static boolean containsSlurs(String text) {
ServerUtils.sendDebugMessage("ProfanityFilter: Checking for slurs");
for (String slur : slurs) {
if (text.contains(slur)) return true;
}
return false;
}
public static String removeFalsePositives(String text) {
for (String falsePositive : swearWhitelist) {
text = text.replace(falsePositive, "");
}
return text;
}
public static String convertLeetSpeakCharacters(String text) {
text = Text.fromLeetString(text);
return text;
}
public static String stripSpecialCharacters(String text) {
text = text.replaceAll("[^A-Za-z0-9.,!?;:'\"()\\[\\]{}]", "").trim();
return text;
}
public static String simplifyRepeatingLetters(String text) {
text = Text.replaceRepeatingLetters(text);
return text;
}
public static String removePeriodsAndSpaces(String text) {
return text.replaceAll("[^A-Za-z0-9]", "").replace(" ", "");
}
public static void decayScore() {
for (Player p : scoreMap.keySet()) {
int score = scoreMap.get(p);
if (score > 0) {
score = score - MainConfig.Chat.AntiSwear.scoreDecay;
scoreMap.put(p, Math.max(0, score));
}
}
}
}

View File

@@ -53,7 +53,7 @@ public class ReportFalsePositives {
String simplifyRep,
String sanitized) {
ServerUtils.sendDebugMessage("Creating FalsePositive Webhook...");
DiscordWebhook webhook = new DiscordWebhook(MainConfig.Plugin.webhook);
DiscordWebhook webhook = new DiscordWebhook(Sentinel.mainConfig.plugin.webhook);
webhook.setAvatarUrl("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png");
webhook.setUsername("Sentinel Anti-Nuke | Logs");
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject()

View File

@@ -48,7 +48,7 @@ public class Text {
return result.toString();
}
public static String fromLeetString(String s) {
Map<String, String> dictionary = AdvancedConfig.leetPatterns;
Map<String, String> dictionary = Sentinel.advConfig.leetPatterns;
String msg = s;
for (String key : dictionary.keySet()) {