Language config works, some messages need to be colored
This commit is contained in:
@@ -6,20 +6,18 @@ package io.github.thetrouper.sentinel;
|
||||
|
||||
import io.github.thetrouper.sentinel.commands.*;
|
||||
import io.github.thetrouper.sentinel.data.Config;
|
||||
import io.github.thetrouper.sentinel.data.LanguageFile;
|
||||
import io.github.thetrouper.sentinel.events.*;
|
||||
import io.github.thetrouper.sentinel.server.functions.AntiSpam;
|
||||
import io.github.thetrouper.sentinel.server.functions.Authenticator;
|
||||
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;
|
||||
import io.github.thetrouper.sentinel.server.functions.Telemetry;
|
||||
import io.github.thetrouper.sentinel.server.util.FileUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Randomizer;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import io.github.thetrouper.sentinel.server.util.JsonSerializable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
@@ -29,7 +27,7 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public final class Sentinel extends JavaPlugin {
|
||||
private static Sentinel instance;
|
||||
|
||||
public static LanguageFile dict;
|
||||
public static final PluginManager manager = Bukkit.getPluginManager();
|
||||
public static String prefix = "";
|
||||
public static String key = "";
|
||||
@@ -42,12 +40,14 @@ public final class Sentinel extends JavaPlugin {
|
||||
*/
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
log.info("\n]======------ Pre-load started! ------======[");
|
||||
instance = this;
|
||||
Config.loadConfiguration();
|
||||
dict = JsonSerializable.load(LanguageFile.PATH,LanguageFile.class,new LanguageFile());
|
||||
String serverID = Authenticator.getServerID();
|
||||
identifier = serverID;
|
||||
log.info("\n]====---- Requesting Authentication ----====[ \n- license Key: " + key + " \n- Server ID: " + serverID);
|
||||
log.info("\n]====---- Requesting Authentication (" + dict.get("example-message") + ") ----====[ \n- license Key: " + key + " \n- Server ID: " + serverID);
|
||||
String authStatus = "ERROR";
|
||||
try {
|
||||
authStatus = Authenticator.authorize(key, serverID);
|
||||
|
||||
@@ -4,17 +4,14 @@
|
||||
|
||||
package io.github.thetrouper.sentinel.commands;
|
||||
|
||||
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.server.functions.ReportFalsePositives;
|
||||
import io.github.thetrouper.sentinel.server.util.Cooldown;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -33,10 +30,10 @@ public class ChatClickCallback extends CustomCommand {
|
||||
switch (args[0]) {
|
||||
case "fpreport" -> {
|
||||
if (fpReportCooldown.isOnCooldown(p.getUniqueId()) && !p.isOp()) {
|
||||
p.sendMessage(TextUtils.prefix("This action is on cooldown! " + fpReportCooldown.getCooldown(p.getUniqueId())));
|
||||
p.sendMessage(Text.prefix(Sentinel.dict.get("cooldown") + fpReportCooldown.getCooldown(p.getUniqueId())));
|
||||
} else {
|
||||
ReportFalsePositives.sendFalsePositiveReport(args[1]);
|
||||
p.sendMessage(TextUtils.prefix("Successfully reported a false positive!"));
|
||||
p.sendMessage(Text.prefix(Sentinel.dict.get("false positive report success")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.github.thetrouper.sentinel.commands;
|
||||
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@@ -48,9 +48,9 @@ public abstract class CustomCommand implements TabExecutor {
|
||||
else if (ex instanceof NullPointerException)
|
||||
msg = "command contains a null value";
|
||||
|
||||
sender.sendMessage(TextUtils.prefix("§4Command Error: §cUnknown or incomplete command!"));
|
||||
sender.sendMessage(TextUtils.prefix("§cCaused by: §8§o(" + ex.getClass().getSimpleName() + ") §7" + msg));
|
||||
sender.sendMessage(TextUtils.prefix("§cCorrect Usage: §7" + command.getUsage()));
|
||||
sender.sendMessage(Text.prefix("§4Command Error: §cUnknown or incomplete command!"));
|
||||
sender.sendMessage(Text.prefix("§cCaused by: §8§o(" + ex.getClass().getSimpleName() + ") §7" + msg));
|
||||
sender.sendMessage(Text.prefix("§cCorrect Usage: §7" + command.getUsage()));
|
||||
|
||||
if (printStacktrace) {
|
||||
ex.printStackTrace();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package io.github.thetrouper.sentinel.commands;
|
||||
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.server.functions.Message;
|
||||
import io.github.thetrouper.sentinel.server.util.ArrayUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -26,10 +26,10 @@ public class MessageCommand extends CustomCommand {
|
||||
Player p = (Player) sender;
|
||||
Player r = null;
|
||||
if (args.length == 0) {
|
||||
p.sendMessage(TextUtils.prefix("§cYou must provide an online player to send a message to!"));
|
||||
p.sendMessage(Text.prefix(Sentinel.dict.get("no-online-player")));
|
||||
}
|
||||
if (args.length == 1) {
|
||||
p.sendMessage(TextUtils.prefix("§cYou must provide a message to send!"));
|
||||
p.sendMessage(Text.prefix(Sentinel.dict.get("no-message-provided")));
|
||||
}
|
||||
r = Bukkit.getPlayer(args[0]);
|
||||
String msg = "";
|
||||
@@ -40,10 +40,10 @@ public class MessageCommand extends CustomCommand {
|
||||
if (p.hasPermission("sentinel.message") && r != null) {
|
||||
Message.messagePlayer(p,r,msg);
|
||||
} else if (r == null) {
|
||||
p.sendMessage(TextUtils.prefix("§cYou must provide an §c§l§nonline §cplayer to send a message to!"));
|
||||
p.sendMessage(Text.prefix((Sentinel.dict.get("no-online-player"))));
|
||||
}
|
||||
else {
|
||||
sender.sendMessage(TextUtils.prefix("Invalid Permissions!"));
|
||||
sender.sendMessage(Text.prefix(Sentinel.dict.get("no-permission")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package io.github.thetrouper.sentinel.commands;
|
||||
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
public class ReopCommand extends CustomCommand {
|
||||
public ReopCommand() {
|
||||
@@ -18,16 +17,16 @@ public class ReopCommand extends CustomCommand {
|
||||
Player p = (Player) sender;
|
||||
if (Sentinel.isTrusted(p)) {
|
||||
if (!p.isOp()) {
|
||||
p.sendMessage(TextUtils.prefix("Elevating your permissions..."));
|
||||
Sentinel.log.info("Elevating the permissions of " + p.getName());
|
||||
p.sendMessage(Text.prefix(Sentinel.dict.get("elevating-perms")));
|
||||
Sentinel.log.info(Sentinel.dict.get("log-elevating-perms").formatted(p.getName()));
|
||||
p.setOp(true);
|
||||
} else {
|
||||
p.sendMessage(TextUtils.prefix("You are already are an operator!"));
|
||||
Sentinel.log.info("The permissions of " + p.getName() + " are already elevated! Retrying...");
|
||||
p.sendMessage(Text.prefix(Sentinel.dict.get("already-op")));
|
||||
Sentinel.log.info(Sentinel.dict.get("log-already-op").formatted(p.getName()));
|
||||
p.setOp(true);
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(TextUtils.prefix("§cYou are not trusted!"));
|
||||
p.sendMessage(Text.prefix(Sentinel.dict.get("no-trust")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package io.github.thetrouper.sentinel.commands;
|
||||
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.server.functions.Message;
|
||||
import io.github.thetrouper.sentinel.server.util.ArrayUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -27,19 +25,19 @@ public class ReplyCommand extends CustomCommand {
|
||||
Player p = sender.getServer().getPlayer(name);
|
||||
UUID senderID = p.getUniqueId();
|
||||
if (replyMap.get(senderID) == null) {
|
||||
p.sendMessage(TextUtils.prefix("§cYou have nobody to reply to!"));
|
||||
p.sendMessage(Text.prefix(Sentinel.dict.get("no-user-reply")));
|
||||
}
|
||||
Player r = sender.getServer().getPlayer(replyMap.get(senderID));
|
||||
UUID reciverID = r.getUniqueId();
|
||||
if (args[0] == null) {
|
||||
p.sendMessage(TextUtils.prefix("§cYou must provide a message to send!"));
|
||||
p.sendMessage(Text.prefix(Sentinel.dict.get("no-message-provided")));
|
||||
}
|
||||
String msg = String.join(" ", Arrays.asList(args));
|
||||
if (p.hasPermission("sentinel.message")) {
|
||||
Message.messagePlayer(p,r,msg);
|
||||
replyMap.put(senderID,reciverID);
|
||||
} else {
|
||||
sender.sendMessage(TextUtils.prefix("Invalid Permissions!"));
|
||||
sender.sendMessage(Text.prefix(Sentinel.dict.get("no-permission")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,16 +5,13 @@
|
||||
package io.github.thetrouper.sentinel.commands;
|
||||
|
||||
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;
|
||||
import io.github.thetrouper.sentinel.server.functions.ReportFalsePositives;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Example command
|
||||
@@ -33,7 +30,7 @@ public class SentinelCommand extends CustomCommand {
|
||||
switch (args[0]) {
|
||||
case "debugmode" -> {
|
||||
debugmode = !debugmode;
|
||||
p.sendMessage(TextUtils.prefix(TextUtils.boolString(debugmode,"§aEnabled","§cDisabled") + "§7 debug mode."));
|
||||
p.sendMessage(Text.prefix(Text.boolString(debugmode,"§aEnabled","§cDisabled") + "§7 debug mode."));
|
||||
}
|
||||
case "testantiswear" -> {
|
||||
HashSet<Player> players = new HashSet<>();
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package io.github.thetrouper.sentinel.commands;
|
||||
|
||||
import io.github.thetrouper.sentinel.server.functions.Message;
|
||||
import io.github.thetrouper.sentinel.server.util.ArrayUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -26,10 +24,10 @@ public class SocialSpyCommand extends CustomCommand {
|
||||
Player p = sender.getServer().getPlayer(name);
|
||||
UUID senderID = p.getUniqueId();
|
||||
if (!spyMap.containsKey(senderID) || !spyMap.get(senderID)) {
|
||||
sender.sendMessage(TextUtils.prefix("SocialSpy is now enabled."));
|
||||
sender.sendMessage(Text.prefix(Sentinel.dict.get("spy-enabled")));
|
||||
spyMap.put(senderID,true);
|
||||
} else if (spyMap.get(senderID)) {
|
||||
sender.sendMessage(TextUtils.prefix("SocialSpy is now disabled."));
|
||||
sender.sendMessage(Text.prefix(Sentinel.dict.get("spy-disabled")));
|
||||
spyMap.put(senderID,false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public abstract class Config {
|
||||
}
|
||||
}
|
||||
public static String webhook;
|
||||
public static String lang;
|
||||
public static List<String> trustedPlayers;
|
||||
public static boolean blockSpecific;
|
||||
public static boolean preventNBT;
|
||||
@@ -154,6 +155,7 @@ public abstract class Config {
|
||||
|
||||
Sentinel.prefix = mainConfig.getString("config.plugin.prefix");
|
||||
Sentinel.key = mainConfig.getString("config.plugin.key");
|
||||
lang = mainConfig.getString("config.plugin.lang");
|
||||
webhook = mainConfig.getString("config.plugin.webhook");
|
||||
trustedPlayers = mainConfig.getStringList("config.plugin.trusted");
|
||||
blockSpecific = mainConfig.getBoolean("config.plugin.block-specific");
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.github.thetrouper.sentinel.data;
|
||||
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.server.util.JsonSerializable;
|
||||
|
||||
import java.io.File;
|
||||
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/" + Config.lang);
|
||||
private final Map<String,String> dictionary = new HashMap<>();
|
||||
public LanguageFile() {};
|
||||
|
||||
@Override
|
||||
public File getFile() {
|
||||
return PATH;
|
||||
}
|
||||
public String get(String key) {
|
||||
return dictionary.getOrDefault(key,key);
|
||||
}
|
||||
public Map<String, String> getDictionary() {
|
||||
return dictionary;
|
||||
}
|
||||
public String format(String input) {
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
||||
@@ -4,20 +4,12 @@ import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.Config;
|
||||
import io.github.thetrouper.sentinel.data.Emojis;
|
||||
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;
|
||||
import io.github.thetrouper.sentinel.server.util.FileUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class WebhookSender {
|
||||
|
||||
@@ -64,7 +56,7 @@ public class WebhookSender {
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
webhook.execute();
|
||||
} catch (IOException e) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Epic webhook failure!!!"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
|
||||
Sentinel.log.info(e.toString());
|
||||
}
|
||||
}
|
||||
@@ -91,7 +83,7 @@ public class WebhookSender {
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
webhook.execute();
|
||||
} catch (IOException e) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Epic webhook failure!!!"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
|
||||
Sentinel.log.info(e.toString());
|
||||
}
|
||||
}
|
||||
@@ -118,7 +110,7 @@ public class WebhookSender {
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
webhook.execute();
|
||||
} catch (IOException e) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Epic webhook failure!!!"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
|
||||
Sentinel.log.info(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package io.github.thetrouper.sentinel.events;
|
||||
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.commands.SentinelCommand;
|
||||
import io.github.thetrouper.sentinel.data.Config;
|
||||
import io.github.thetrouper.sentinel.server.Action;
|
||||
import io.github.thetrouper.sentinel.server.ActionType;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
@@ -17,8 +14,6 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class CMDBlockUse implements Listener {
|
||||
@EventHandler
|
||||
private void onCMDBlockUse(PlayerInteractEvent e) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import io.github.thetrouper.sentinel.server.functions.AntiSpam;
|
||||
import io.github.thetrouper.sentinel.server.functions.AntiUnicode;
|
||||
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
@@ -16,25 +16,25 @@ public class ChatEvent implements Listener {
|
||||
@EventHandler
|
||||
public static void onChat(AsyncPlayerChatEvent e) {
|
||||
if (e.isCancelled()) return;
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Chat event detected!"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Chat event detected!"));
|
||||
if (!Sentinel.isTrusted(e.getPlayer()) || !e.getPlayer().hasPermission("sentinel.chat.antiunicode.bypass")) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Permission bypass failed, checking for unicode"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Permission bypass failed, checking for unicode"));
|
||||
if (Config.antiUnicode) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Enabled, Continuing unicode check!"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Enabled, Continuing unicode check!"));
|
||||
AntiUnicode.handleAntiUnicode(e);
|
||||
}
|
||||
}
|
||||
if (!Sentinel.isTrusted(e.getPlayer()) || !e.getPlayer().hasPermission("sentinel.chat.antiswear.bypass")) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Permission bypass failed, checking for swears"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Permission bypass failed, checking for swears"));
|
||||
if (Config.antiSwearEnabled) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Enabled, Continuing swear check!"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Enabled, Continuing swear check!"));
|
||||
ProfanityFilter.handleProfanityFilter(e);
|
||||
}
|
||||
}
|
||||
if (!Sentinel.isTrusted(e.getPlayer()) || !e.getPlayer().hasPermission("sentinel.chat.antispam.bypass")) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Permission bypass failed, checking for spam"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Permission bypass failed, checking for spam"));
|
||||
if (Config.antiSpamEnabled) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Enabled, Continuing spam check!"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Enabled, Continuing spam check!"));
|
||||
AntiSpam.handleAntiSpam(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import io.github.thetrouper.sentinel.data.Config;
|
||||
import io.github.thetrouper.sentinel.server.Action;
|
||||
import io.github.thetrouper.sentinel.server.ActionType;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -17,12 +17,12 @@ public class CommandEvent implements Listener {
|
||||
private void onCommand(PlayerCommandPreprocessEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
String command = e.getMessage().substring(1).split(" ")[0];
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Checking command"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Checking command"));
|
||||
if (Sentinel.isDangerousCommand(command)) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix( "Command is dangerous"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix( "Command is dangerous"));
|
||||
if (!Sentinel.isTrusted(p)) {
|
||||
e.setCancelled(true);
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Command is canceled"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Command is canceled"));
|
||||
Action a = new Action.Builder()
|
||||
.setAction(ActionType.DANGEROUS_COMMAND)
|
||||
.setEvent(e)
|
||||
@@ -38,12 +38,12 @@ public class CommandEvent implements Listener {
|
||||
}
|
||||
}
|
||||
if (Config.blockSpecific) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Checking command for specific"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Checking command for specific"));
|
||||
if (command.contains(":")) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Checking is specific"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Checking is specific"));
|
||||
if (!Sentinel.isTrusted(p)) {
|
||||
e.setCancelled(true);
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Command is canceled"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Command is canceled"));
|
||||
Action a = new Action.Builder()
|
||||
.setAction(ActionType.SPECIFIC_COMMAND)
|
||||
.setEvent(e)
|
||||
|
||||
@@ -7,10 +7,9 @@ import io.github.thetrouper.sentinel.data.Emojis;
|
||||
import io.github.thetrouper.sentinel.discord.DiscordWebhook;
|
||||
import io.github.thetrouper.sentinel.server.util.FileUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.chat.hover.content.Text;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -182,7 +181,7 @@ public class Action {
|
||||
}
|
||||
if (notifyTrusted) {
|
||||
TextComponent notification = new TextComponent();
|
||||
notification.setText(TextUtils.prefix(" " + actionTop));
|
||||
notification.setText(Text.prefix(" " + actionTop));
|
||||
String body = "]=- Sentinel -=[ ";
|
||||
body += "\n" + actionTitle + "\n";
|
||||
if (player != null) {
|
||||
@@ -217,7 +216,7 @@ public class Action {
|
||||
body += "Punished: " + (punished ? "§a\u2714" : "§c\u2718") + "\n";
|
||||
if (revertGM) body += "RevertGM: " + "§a\u2714" + "\n";
|
||||
body += "Logged: " + (notifyDiscord ? "§a\u2714" : "§c\u2718");
|
||||
notification.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(body)));
|
||||
notification.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new net.md_5.bungee.api.chat.hover.content.Text(body)));
|
||||
ServerUtils.forEachPlayer(trusted -> {
|
||||
if (Sentinel.isTrusted(trusted)) {
|
||||
trusted.spigot().sendMessage(notification);
|
||||
@@ -250,9 +249,9 @@ public class Action {
|
||||
Emojis.space + Emojis.rightDoubleArrow + " **Location:** X: " + block.getX() + " Y: " + block.getY() + " Z: " + block.getZ() + "\\n";
|
||||
}
|
||||
String actions = "";
|
||||
actions += Emojis.rightSort + " **Denied:** " + TextUtils.boolString(denied,Emojis.success, Emojis.failure) + "\\n";
|
||||
actions += Emojis.rightSort + " **De-oped:** " + TextUtils.boolString(deoped,Emojis.success, Emojis.failure) + "\\n";
|
||||
actions += Emojis.rightSort + " **Punished:** " + TextUtils.boolString(punished,Emojis.success, Emojis.failure) + "\\n";
|
||||
actions += Emojis.rightSort + " **Denied:** " + Text.boolString(denied,Emojis.success, Emojis.failure) + "\\n";
|
||||
actions += Emojis.rightSort + " **De-oped:** " + Text.boolString(deoped,Emojis.success, Emojis.failure) + "\\n";
|
||||
actions += Emojis.rightSort + " **Punished:** " + Text.boolString(punished,Emojis.success, Emojis.failure) + "\\n";
|
||||
if (revertGM) actions += Emojis.rightSort + " **GM Reverted:** " + Emojis.success + "\\n";
|
||||
actions += Emojis.rightSort + " **Logged:** " + Emojis.success;
|
||||
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject()
|
||||
@@ -267,7 +266,7 @@ public class Action {
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
webhook.execute();
|
||||
} catch (IOException e) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Epic webhook failure!!!"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
|
||||
Sentinel.log.info(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package io.github.thetrouper.sentinel.server.functions;
|
||||
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.Config;
|
||||
import io.github.thetrouper.sentinel.discord.WebhookSender;
|
||||
import io.github.thetrouper.sentinel.server.util.GPTUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -29,7 +28,7 @@ public class AntiSpam {
|
||||
}
|
||||
public static void handleAntiSpam(AsyncPlayerChatEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
String message = TextUtils.removeFirstColor(e.getMessage());
|
||||
String message = Text.removeFirstColor(e.getMessage());
|
||||
if (!heatMap.containsKey(p)) heatMap.put(p, 0);
|
||||
if (heatMap.get(p) > Config.punishHeat) {
|
||||
e.setCancelled(true);
|
||||
@@ -65,33 +64,38 @@ public class AntiSpam {
|
||||
public static void alertSpam(Player p, String message1, String message2) {
|
||||
TextComponent text = new TextComponent();
|
||||
double similarity = GPTUtils.calculateSimilarity(message1,message2 + "%");
|
||||
DecimalFormat fs = new DecimalFormat("###.#");
|
||||
p.sendMessage(TextUtils.prefix("Do not spam in chat! Please wait before sending another message."));
|
||||
DecimalFormat fs = new DecimalFormat("##.#");
|
||||
fs.setRoundingMode(RoundingMode.DOWN);
|
||||
TextComponent warning = new TextComponent();
|
||||
warning.setText(Text.prefix(Sentinel.dict.get("spam-warning")));
|
||||
warning.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("action-automatic")));
|
||||
p.spigot().sendMessage(warning);
|
||||
String hover ="§8]==-- §d§lSentinel §8--==[" +
|
||||
"\n§bPrevious: §f" + message2 +
|
||||
"\n§bCurrent: §f" + message1 +
|
||||
"\n§bSimilarity §f" + fs.format(similarity);
|
||||
text.setText(TextUtils.prefix(
|
||||
"§b§n" + p.getName() + "§7 might be spamming! §8(§c" + heatMap.get(p) + "§7/§4" + Config.punishHeat + "§8)"));
|
||||
text.setText(Text.prefix(Sentinel.dict.get("spam-notification").formatted(p.getName(),heatMap.get(p),Config.punishHeat)));
|
||||
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hover)));
|
||||
ServerUtils.forEachStaff(staff -> {
|
||||
staff.spigot().sendMessage(text);
|
||||
});
|
||||
}
|
||||
public static void punishSpam(Player player, String message1, String message2) {
|
||||
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%", player.getName()));
|
||||
player.sendMessage(TextUtils.prefix("§cYou have been auto-punished for violating the anti-spam repetitively!"));
|
||||
ServerUtils.sendCommand(Config.spamPunishCommand.replace("%player%", p.getName()));
|
||||
TextComponent warning = new TextComponent();
|
||||
warning.setText(Text.prefix(Sentinel.dict.get("spam-punished")));
|
||||
warning.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("action-automatic"))));
|
||||
p.spigot().sendMessage(warning);
|
||||
TextComponent text = new TextComponent();
|
||||
text.setText(TextUtils.prefix(
|
||||
"§b§n" + player.getName() + "§7 has been auto-muted by the anti-spam! §8(§c" + heatMap.get(player) + "§7/§4" + Config.punishHeat + "§8)"));
|
||||
text.setText(Text.prefix(Sentinel.dict.get("spam-punish-notification").formatted(p,heatMap.get(p),Config.punishHeat)));
|
||||
ServerUtils.forEachStaff(staff -> {
|
||||
staff.spigot().sendMessage(text);
|
||||
});
|
||||
if (Config.logSpam) WebhookSender.sendSpamLog(player,message1,message2,heatMap.get(player),chatCleared);
|
||||
if (Config.logSpam) WebhookSender.sendSpamLog(p,message1,message2,heatMap.get(p),chatCleared);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package io.github.thetrouper.sentinel.server.functions;
|
||||
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class AntiUnicode {
|
||||
public static void handleAntiUnicode(AsyncPlayerChatEvent e) {
|
||||
String message = TextUtils.removeFirstColor(e.getMessage());
|
||||
String message = Text.removeFirstColor(e.getMessage());
|
||||
String nonAllowed = message.replaceAll("[A-Za-z0-9\\[,./?><|\\]()*&^%$#@!~`{}:;'\"-_]", "").trim();
|
||||
if (nonAllowed.length() != 0) {
|
||||
e.getPlayer().sendMessage(TextUtils.prefix("§cDo not send non standard unicode in chat!"));
|
||||
e.getPlayer().sendMessage(Text.prefix(Sentinel.dict.get("unicode-warn")));
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ public class Message {
|
||||
return;
|
||||
}
|
||||
|
||||
sender.sendMessage("§d§lMessage §8» §b[§fYou §e>§f " + receiver.getName() + "§b] §7" + message);
|
||||
receiver.sendMessage("§d§lMessage §8» §b[§f" + sender.getName() + " §e>§f You§b] §7" + message);
|
||||
sender.sendMessage(Sentinel.dict.get("message-sent").replace("{1}",receiver.getName()).replace("{m}", message));
|
||||
receiver.sendMessage(Sentinel.dict.get("message-sent").replace("{1}",sender.getName()).replace("{m}", message));
|
||||
replyMap.put(receiver.getUniqueId(),sender.getUniqueId());
|
||||
sendSpy(sender,receiver,message);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class Message {
|
||||
public static void sendSpy(Player sender, Player receiver, String message) {
|
||||
ServerUtils.forEachPlayer(player -> {
|
||||
if (SocialSpyCommand.spyMap.getOrDefault(player.getUniqueId(),false)) {
|
||||
TextComponent notification = new TextComponent("§d§lSpy §8» §b§n" + sender.getName() + "§7 has messaged §b§n " + receiver.getName() + "§7.");
|
||||
TextComponent notification = new TextComponent(Sentinel.dict.get("spy-message").replace("{1}",sender.getName()).replace("{2}", receiver.getName()));
|
||||
notification.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(
|
||||
"§8]==-- §d§lSocialSpy §8--==[" +
|
||||
"\n§bSender: §f" + sender.getName() +
|
||||
|
||||
@@ -3,22 +3,15 @@ import io.github.thetrouper.sentinel.Sentinel;
|
||||
import io.github.thetrouper.sentinel.data.Config;
|
||||
import io.github.thetrouper.sentinel.discord.WebhookSender;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.io.BufferedReader;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProfanityFilter {
|
||||
@@ -32,7 +25,7 @@ public class ProfanityFilter {
|
||||
}
|
||||
public static void handleProfanityFilter(AsyncPlayerChatEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
String message = TextUtils.removeFirstColor(e.getMessage());
|
||||
String message = Text.removeFirstColor(e.getMessage());
|
||||
if (!scoreMap.containsKey(p)) scoreMap.put(p, 0);
|
||||
if (scoreMap.get(p) > Config.punishScore) punishSwear(p,highlightProfanity(message),message,e);
|
||||
String severity = ProfanityFilter.checkSeverity(message);
|
||||
@@ -81,16 +74,15 @@ public class ProfanityFilter {
|
||||
ServerUtils.sendCommand(Config.strictPunishCommand.replace("%player%", player.getName()));
|
||||
String fpreport = ReportFalsePositives.generateReport(e);
|
||||
TextComponent offender = new TextComponent();
|
||||
String hoverPlayer = ("§7This action was preformed automatically \n§7by the §bSentinel Profanity Filter§7 algorithm!\n§8§o(Click to report false positive)");
|
||||
offender.setText(TextUtils.prefix(("§cYou have been auto muted for repeated violation of the profanity filter! §7§o(Hover for more info)")));
|
||||
String hoverPlayer = Sentinel.dict.get("action-automatic-reportable");
|
||||
offender.setText(Text.prefix(Sentinel.dict.get("profanity-mute-warn")));
|
||||
offender.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hoverPlayer)));
|
||||
offender.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport));
|
||||
player.spigot().sendMessage(offender);
|
||||
|
||||
String hover = ("§bOriginal: §f" + origMessage + "\n§bSanitized: §f" + highlightedMSG + "\n\n§8§o(Click to report false positive)");
|
||||
TextComponent text = new TextComponent();
|
||||
text.setText(TextUtils.prefix(
|
||||
("§b§n" + player.getName() + "§7 has been auto-muted by the anti-swear! §8(§c" + scoreMap.get(player) + "§7/§4" + Config.punishScore + "§8)")));
|
||||
text.setText(Text.prefix(Sentinel.dict.get("profanity-mute-notification").formatted(player,scoreMap.get(player),Config.punishScore)));
|
||||
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hover)));
|
||||
text.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport));
|
||||
|
||||
@@ -105,16 +97,15 @@ public class ProfanityFilter {
|
||||
ServerUtils.sendCommand(Config.strictPunishCommand.replace("%player%", player.getName()));
|
||||
String fpreport = ReportFalsePositives.generateReport(e);
|
||||
TextComponent offender = new TextComponent();
|
||||
String hoverPlayer = ("§7This action was preformed automatically \n§7by the §bSentinel Profanity Filter§7 algorithm!\n§8§o(Click to report false positive)");
|
||||
offender.setText(TextUtils.prefix(("§cYou have been insta-punished by the anti-slur! §7§o(Hover for more info)")));
|
||||
String hoverPlayer = Sentinel.dict.get("action-automatic-reportable");
|
||||
offender.setText(Text.prefix((Sentinel.dict.get("slur-mute-warn"))));
|
||||
offender.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hoverPlayer)));
|
||||
offender.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport));
|
||||
player.spigot().sendMessage(offender);
|
||||
|
||||
String hover = ("§bOriginal: §f" + origMessage + "\n§bSanitized: §f" + highlightedMSG + "\n§8§o(Click to report false positive)");
|
||||
TextComponent text = new TextComponent();
|
||||
text.setText(TextUtils.prefix(
|
||||
("§b§n" + player.getName() + "§7 has been insta-muted by the anti-swear! §8(§e" + scoreMap.get(player) + "§7/§4" + Config.punishScore + "§8)")));
|
||||
text.setText(Text.prefix(Sentinel.dict.get("slur-mute-notification").formatted(player,scoreMap.get(player),Config.punishScore)));
|
||||
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hover)));
|
||||
text.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport));
|
||||
|
||||
@@ -126,16 +117,15 @@ public class ProfanityFilter {
|
||||
public static void blockSwear(Player player, String highlightedMSG, String origMessage, String severity, AsyncPlayerChatEvent e) {
|
||||
String FPReport = ReportFalsePositives.generateReport(e);
|
||||
TextComponent offender = new TextComponent();
|
||||
String hover = ("§7This action was preformed automatically \n§7by the §bSentinel Profanity Filter§7 algorithm!\n§8§o(Click to report false positive)");
|
||||
offender.setText(TextUtils.prefix(("§cPlease do not swear in chat! Attempting to bypass this filter will result in a mute! §7§o(Hover for more info)")));
|
||||
String hover = Sentinel.dict.get("action-automatic-reportable");
|
||||
offender.setText(Text.prefix((Sentinel.dict.get("swear-block-warn"))));
|
||||
offender.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hover)));
|
||||
offender.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + FPReport));
|
||||
player.spigot().sendMessage(offender);
|
||||
|
||||
String hoverStaff = ("§bOriginal: §f" + origMessage + "\n§bSanitized: §f" + highlightedMSG + "\n§bSeverity: §c" + severity + "\n§7§o(click to report false positive)");
|
||||
TextComponent staff = new TextComponent();
|
||||
staff.setText(TextUtils.prefix(
|
||||
("§b§n" + player.getName() + "§7 has triggered the anti-swear! §8(§c" + scoreMap.get(player) + "§7/§4" + Config.punishScore + "§8)")));
|
||||
staff.setText(Text.prefix(Sentinel.dict.get("swear-block-notification").formatted(player,scoreMap.get(player),Config.punishScore)));
|
||||
staff.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hoverStaff)));
|
||||
staff.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + FPReport));
|
||||
|
||||
@@ -199,11 +189,11 @@ public class ProfanityFilter {
|
||||
public static String checkSeverity(String text) {
|
||||
// 1:
|
||||
String lowercasedText = text.toLowerCase();
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Debug: [AntiSwear] Lowercased: " + lowercasedText));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Lowercased: " + lowercasedText));
|
||||
|
||||
// 2:
|
||||
String cleanedText = removeFalsePositives(lowercasedText);
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Debug: [AntiSwear] Removed False positives: " + cleanedText));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Removed False positives: " + cleanedText));
|
||||
|
||||
// 3:
|
||||
if (containsSwears(cleanedText)) return "low";
|
||||
@@ -211,7 +201,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 4:
|
||||
String convertedText = convertLeetSpeakCharacters(cleanedText);
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Debug: [AntiSwear] Leet Converted: " + convertedText));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Leet Converted: " + convertedText));
|
||||
|
||||
// 5:
|
||||
if (containsSwears(convertedText)) return "medium-low";
|
||||
@@ -219,7 +209,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 6:
|
||||
String strippedText = stripSpecialCharacters(convertedText);
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Debug: [AntiSwear] Specials Removed: " + strippedText));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Specials Removed: " + strippedText));
|
||||
|
||||
// 7:
|
||||
if (containsSwears(strippedText)) return "medium";
|
||||
@@ -227,7 +217,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 8:
|
||||
String simplifiedText = simplifyRepeatingLetters(strippedText);
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Debug: [AntiSwear] Removed Repeating: " + simplifiedText));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Removed Repeating: " + simplifiedText));
|
||||
|
||||
// 9:
|
||||
if (containsSwears(simplifiedText)) return "medium-high";
|
||||
@@ -235,7 +225,7 @@ public class ProfanityFilter {
|
||||
|
||||
// 10:
|
||||
String finalText = removePeriodsAndSpaces(simplifiedText);
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Debug: [AntiSwear] Remove Punctuation: " + finalText));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Debug: [AntiSwear] Remove Punctuation: " + finalText));
|
||||
|
||||
// 11:
|
||||
if (containsSwears(finalText)) return "high";
|
||||
@@ -269,7 +259,7 @@ public class ProfanityFilter {
|
||||
return text;
|
||||
}
|
||||
public static String convertLeetSpeakCharacters(String text) {
|
||||
text = TextUtils.fromLeetString(text);
|
||||
text = Text.fromLeetString(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -279,7 +269,7 @@ public class ProfanityFilter {
|
||||
}
|
||||
|
||||
public static String simplifyRepeatingLetters(String text) {
|
||||
text = TextUtils.replaceRepeatingLetters(text);
|
||||
text = Text.replaceRepeatingLetters(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import io.github.thetrouper.sentinel.data.Emojis;
|
||||
import io.github.thetrouper.sentinel.discord.DiscordWebhook;
|
||||
import io.github.thetrouper.sentinel.server.util.Randomizer;
|
||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.TextUtils;
|
||||
import io.github.thetrouper.sentinel.server.util.Text;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
@@ -21,12 +21,12 @@ public class ReportFalsePositives {
|
||||
public static String generateReport(AsyncPlayerChatEvent e) {
|
||||
final long reportLong = Randomizer.generateID();
|
||||
final String reportID = Long.toString(reportLong);
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("DEBUG: Generating chat filter report"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("DEBUG: Generating chat filter report"));
|
||||
reportMap.put(reportID,e);
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("DEBUG: Generated chat filter report. ID:" + reportID + " Message: \"" + reportMap.get(reportID).getMessage() + "\" Expires in 60 seconds"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("DEBUG: Generated chat filter report. ID:" + reportID + " Message: \"" + reportMap.get(reportID).getMessage() + "\" Expires in 60 seconds"));
|
||||
Bukkit.getScheduler().runTaskLater(Sentinel.getInstance(),()->{
|
||||
reportMap.remove(reportID);
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("DEBUG: Chat filter Report expired. ID: " + reportID));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("DEBUG: Chat filter Report expired. ID: " + reportID));
|
||||
},60000);
|
||||
return reportID;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class ReportFalsePositives {
|
||||
ServerUtils.sendDebugMessage("Executing webhook...");
|
||||
webhook.execute();
|
||||
} catch (IOException e) {
|
||||
ServerUtils.sendDebugMessage(TextUtils.prefix("Epic webhook failure!!!"));
|
||||
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
|
||||
Sentinel.log.info(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.github.thetrouper.sentinel.server.util;
|
||||
|
||||
public class Color {
|
||||
public static String color(String tocolor) {
|
||||
return tocolor.replace("&","\u00A7");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package io.github.thetrouper.sentinel.server.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public final class FileValidationUtils {
|
||||
|
||||
public static boolean validate(File file) {
|
||||
try {
|
||||
if (!file.getParentFile().exists())
|
||||
if (!file.getParentFile().mkdirs())
|
||||
return false;
|
||||
if (!file.exists())
|
||||
if (!file.createNewFile())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package io.github.thetrouper.sentinel.server.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public interface JsonSerializable<T> {
|
||||
|
||||
Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
|
||||
File getFile();
|
||||
|
||||
default String serialize(boolean pretty) {
|
||||
Gson gson;
|
||||
if (pretty) {
|
||||
gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
}
|
||||
else {
|
||||
gson = new Gson();
|
||||
}
|
||||
|
||||
try {
|
||||
String json = gson.toJson(this);
|
||||
if (json == null) {
|
||||
throw new IllegalStateException("json parse failed for " + this.getClass().getSimpleName());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return "{}";
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
default T deserialize(String json) {
|
||||
try {
|
||||
JsonSerializable<?> v = gson.fromJson(json, this.getClass());
|
||||
if (v == null) {
|
||||
throw new IllegalStateException("json parse failed");
|
||||
}
|
||||
return (T)v;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
default void save() {
|
||||
String json = serialize(true);
|
||||
File f = getFile();
|
||||
|
||||
if (FileValidationUtils.validate(f)) {
|
||||
try {
|
||||
FileWriter fw = new FileWriter(f);
|
||||
BufferedWriter bw = new BufferedWriter(fw);
|
||||
bw.write(json);
|
||||
bw.close();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default <O> O getOrDef(O val, O def) {
|
||||
return val != null ? val : def;
|
||||
}
|
||||
|
||||
static <T extends JsonSerializable<?>> T load(File file, Class<T> jsonSerializable, T fallback) {
|
||||
if (FileValidationUtils.validate(file)) {
|
||||
try {
|
||||
FileReader fr = new FileReader(file);
|
||||
BufferedReader br = new BufferedReader(fr);
|
||||
T t = gson.fromJson(br, jsonSerializable);
|
||||
|
||||
if (t == null) {
|
||||
throw new IllegalStateException("json parse failed!");
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
static <T extends JsonSerializable<?>> T load(String path, Class<T> jsonSerializable, T fallback) {
|
||||
return load(new File(path), jsonSerializable, fallback);
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,13 @@ import io.github.thetrouper.sentinel.data.Config;
|
||||
import java.util.Map;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
public class TextUtils {
|
||||
public class Text {
|
||||
public static String color(String s) {
|
||||
return s.replaceAll("&","§");
|
||||
return s.replaceAll("&","\u00A7");
|
||||
}
|
||||
public static String prefix(String text) {
|
||||
String prefix = Sentinel.prefix;
|
||||
return prefix + text;
|
||||
return color(prefix + text);
|
||||
}
|
||||
public static String removeFirstColor(String input) {
|
||||
if (input.startsWith("§")) {
|
||||
Reference in New Issue
Block a user