New config system implemented

This commit is contained in:
obvWolf
2024-01-31 07:29:50 -06:00
parent dba308efd2
commit 3bc8e2f9a7
43 changed files with 360 additions and 355 deletions

View File

@@ -27,9 +27,11 @@ repositories {
} }
dependencies { dependencies {
compileOnly "org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT" compileOnly 'org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT'
implementation 'com.google.code.gson:gson:2.10.1' implementation 'com.google.code.gson:gson:2.10.1'
implementation("club.minnced:discord-webhooks:0.8.4")
implementation files("libs/PDK-1.3.3.jar") implementation files("libs/PDK-1.3.3.jar")
} }
def targetJavaVersion = 16 def targetJavaVersion = 16

View File

@@ -17,7 +17,7 @@ if [ $? -eq 0 ]; then
TEMP_FILE=$(mktemp) TEMP_FILE=$(mktemp)
# Specify the local file to upload # Specify the local file to upload
LOCAL_FILE="/run/media/trouper/'1TB drive'/IJ/IdeaProjects/Sentinel/build/libs/Sentinel-0.2.2.jar" LOCAL_FILE="/run/media/trouper/'1TB drive'/IJ/IdeaProjects/Sentinel/build/libs/Sentinel-0.2.4.jar"
# Write the SFTP commands to the temporary file # Write the SFTP commands to the temporary file
echo "put $LOCAL_FILE $SFTP_REMOTE_DIR" > "$TEMP_FILE" echo "put $LOCAL_FILE $SFTP_REMOTE_DIR" > "$TEMP_FILE"
@@ -39,7 +39,7 @@ EOF
) )
for cmd in "${SSH_COMMANDS[@]}"; do for cmd in "${SSH_COMMANDS[@]}"; do
ssh -oStrictHostKeyChecking=no -oBatchMode=no "$SFTP_USER@$SFTP_HOST" "docker exec docker-mc-1 mc-send-to-console $cmd" ssh -oStrictHostKeyChecking=no -oBatchMode=no "$SFTP_USER@$SFTP_HOST" "docker exec docker_mc_1 mc-send-to-console $cmd"
done done
echo "Plugin reloaded." echo "Plugin reloaded."

View File

@@ -1,7 +1,7 @@
# Plugin # Plugin
group = 'io.github.thetrouper' group = 'io.github.thetrouper'
version = 0.2.2 version = 0.2.4
# Minecraft # Minecraft
mc_version = 1.19.4 mc_version = 1.19.4

View File

@@ -1,46 +1,52 @@
package io.github.thetrouper.sentinel; package io.github.thetrouper.sentinel;
import com.google.gson.JsonObject; import club.minnced.discord.webhook.WebhookClient;
import club.minnced.discord.webhook.WebhookClientBuilder;
import club.minnced.discord.webhook.send.WebhookEmbed;
import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
import club.minnced.discord.webhook.send.WebhookMessageBuilder;
import io.github.itzispyder.pdk.PDK; import io.github.itzispyder.pdk.PDK;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
import io.github.thetrouper.sentinel.auth.Auth; import io.github.thetrouper.sentinel.auth.Auth;
import io.github.thetrouper.sentinel.cmds.*; import io.github.thetrouper.sentinel.cmds.*;
import io.github.thetrouper.sentinel.data.config.*;
import io.github.thetrouper.sentinel.events.*; import io.github.thetrouper.sentinel.events.*;
import io.github.thetrouper.sentinel.server.config.*;
import io.github.thetrouper.sentinel.server.functions.AntiSpam; import io.github.thetrouper.sentinel.server.functions.AntiSpam;
import io.github.thetrouper.sentinel.server.functions.Authenticator; import io.github.thetrouper.sentinel.server.functions.Authenticator;
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter; import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;
import io.github.thetrouper.sentinel.server.functions.Telemetry; import io.github.thetrouper.sentinel.server.functions.Telemetry;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.*; import java.io.File;
import java.net.URL; import java.time.temporal.TemporalAccessor;
import java.util.logging.Logger; import java.util.logging.Logger;
public final class Sentinel extends JavaPlugin { public final class Sentinel extends JavaPlugin {
private static Sentinel instance; private static Sentinel instance;
public static LanguageFile dict;
private static final File cfgfile = new File("plugins/Sentinel/main-config.json"); private static final File cfgfile = new File("plugins/Sentinel/main-config.json");
private static final File nbtcfg = new File("plugins/Sentinel/nbt-config.json"); private static final File nbtcfg = new File("plugins/Sentinel/nbt-config.json");
private static final File strctcfg = new File("plugins/Sentinel/strict.json"); private static final File strctcfg = new File("plugins/Sentinel/strict.json");
private static final File swrcfg = new File("plugins/Sentinel/swears.json"); private static final File swrcfg = new File("plugins/Sentinel/swears.json");
private static final File fpcfg = new File("plugins/Sentinel/false-positives.json"); private static final File fpcfg = new File("plugins/Sentinel/false-positives.json");
private static final File advcfg = new File("plugins/Sentinel/advanced-config.json"); private static final File advcfg = new File("plugins/Sentinel/advanced-config.json");
public static MainConfig mainConfig = JsonSerializable.load(cfgfile, MainConfig.class, new MainConfig()); public static MainConfig mainConfig = JsonSerializable.load(cfgfile, MainConfig.class, new MainConfig());
public static FPConfig fpConfig = JsonSerializable.load(fpcfg, FPConfig.class, new FPConfig()); public static FPConfig fpConfig = JsonSerializable.load(fpcfg, FPConfig.class, new FPConfig());
public static SwearsConfig swearConfig = JsonSerializable.load(swrcfg, SwearsConfig.class, new SwearsConfig()); public static SwearsConfig swearConfig = JsonSerializable.load(swrcfg, SwearsConfig.class, new SwearsConfig());
public static StrictConfig strictConfig = JsonSerializable.load(strctcfg, StrictConfig.class, new StrictConfig()); public static StrictConfig strictConfig = JsonSerializable.load(strctcfg, StrictConfig.class, new StrictConfig());
public static NBTConfig nbtConfig = JsonSerializable.load(nbtcfg, NBTConfig.class, new NBTConfig()); public static NBTConfig nbtConfig = JsonSerializable.load(nbtcfg, NBTConfig.class, new NBTConfig());
public static AdvancedConfig advConfig = JsonSerializable.load(advcfg, AdvancedConfig.class, new AdvancedConfig()); public static AdvancedConfig advConfig = JsonSerializable.load(advcfg, AdvancedConfig.class, new AdvancedConfig());
public static LanguageFile language;
public static final PluginManager manager = Bukkit.getPluginManager(); public static final PluginManager manager = Bukkit.getPluginManager();
public static String prefix = "";
public static String key = "";
public static final Logger log = Bukkit.getLogger(); public static final Logger log = Bukkit.getLogger();
public static String identifier = "";
public static boolean usesDynamicIP; public static boolean usesDynamicIP;
public static WebhookClient webclient;
/** /**
* Plugin startup logic * Plugin startup logic
@@ -53,22 +59,23 @@ public final class Sentinel extends JavaPlugin {
instance = this; instance = this;
log.info("Loading Config..."); log.info("Loading Config...");
loadConfig(); loadConfig();
log.info("Language Status: (" + dict.get("if-you-see-this-lang-is-broken") + ")");
log.info("Language Status: (" + language.get("if-you-see-this-lang-is-broken") + ")");
log.info("Initializing Server ID..."); log.info("Initializing Server ID...");
String serverID = Authenticator.getServerID(); String serverID = Authenticator.getServerID();
key = mainConfig.plugin.license; String license = mainConfig.plugin.license;
identifier = serverID;
log.info("Pre-load finished!\n]====---- Requesting Authentication ----====[ \n- License Key: " + key + " \n- Server ID: " + serverID); log.info("Pre-load finished!\n]====---- Requesting Authentication ----====[ \n- License Key: " + license + " \n- Server ID: " + serverID);
log.info("Auth Requested..."); log.info("Auth Requested...");
String authStatus = "ERROR"; String authStatus = "ERROR";
String authstatus = "ERROR"; String authstatus = "ERROR";
try { try {
authStatus = Authenticator.authorize(key, serverID); authStatus = Authenticator.authorize(license, serverID);
authstatus = Auth.authorize(key, serverID); authstatus = Auth.authorize(license, serverID);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@@ -79,13 +86,13 @@ public final class Sentinel extends JavaPlugin {
case "AUTHORIZED" -> { case "AUTHORIZED" -> {
log.info("\n]======----- Auth Success! -----======["); log.info("\n]======----- Auth Success! -----======[");
startup(); startup();
authstatus = authstatus.replaceAll("ur a skid lmao","get out of here kiddo");
} }
case "MINEHUT" -> { case "MINEHUT" -> {
usesDynamicIP = true; usesDynamicIP = true;
String minehutStatus = Telemetry.loadTelemetryHook(serverID, key); String minehutStatus = Telemetry.loadTelemetryHook(serverID, license);
switch (minehutStatus) { switch (minehutStatus) {
case "SUCCESS" -> { case "SUCCESS" -> {
authstatus = authstatus.replaceAll("ur a skid lmao","get out of here kiddo");
log.info("Dynamic IP auth Success! " + authstatus); log.info("Dynamic IP auth Success! " + authstatus);
startup(); startup();
} }
@@ -100,15 +107,15 @@ public final class Sentinel extends JavaPlugin {
manager.disablePlugin(this); manager.disablePlugin(this);
} }
case "UNREGISTERED" -> { case "UNREGISTERED" -> {
log.warning("Authentication Failure, YOU SHALL NOT PASS! License: " + key + " Server ID: " + serverID); log.warning("Authentication Failure, YOU SHALL NOT PASS! License: " + license + " Server ID: " + serverID);
manager.disablePlugin(this); manager.disablePlugin(this);
} }
case "ERROR" -> { case "ERROR" -> {
log.warning("Hmmmmmm thats not right... License: " + key + " Server ID: " + serverID + "\nPlease report the above stacktrace."); log.warning("Hmmmmmm thats not right... License: " + license + " Server ID: " + serverID + "\nPlease report the above stacktrace.");
manager.disablePlugin(this); manager.disablePlugin(this);
} }
default -> { default -> {
log.warning("Achievment unlocked:\n How did we get here? \nLicense: " + key + " Server ID: " + serverID + "\nPlease report the above stacktrace."); log.warning("Achievement unlocked:\n How did we get here? \nLicense: " + license + " Server ID: " + serverID + "\nPlease report the above stacktrace.");
manager.disablePlugin(this); manager.disablePlugin(this);
} }
} }
@@ -116,17 +123,17 @@ public final class Sentinel extends JavaPlugin {
public void startup() { public void startup() {
log.info("\n]======----- Loading Sentinel! -----======["); log.info("\n]======----- Loading Sentinel! -----======[");
loadConfig();
// Plugin startup logic // Plugin startup logic
log.info("Starting Up! (" + getDescription().getVersion() + ")..."); log.info("Starting Up! (" + getDescription().getVersion() + ")...");
loadWebhook();
// Enable Functions // Enable Functions
AntiSpam.enableAntiSpam(); AntiSpam.enableAntiSpam();
ProfanityFilter.enableAntiSwear(); ProfanityFilter.enableAntiSwear();
prefix = mainConfig.plugin.prefix; // Commands
// Commands -> BE SURE TO REGISTER ANY NEW COMMANDS IN PLUGIN.YML (src/main/java/resources/plugin.yml)!
new SentinelCommand().register(); new SentinelCommand().register();
new MessageCommand().register(); new MessageCommand().register();
new ReplyCommand().register(); new ReplyCommand().register();
@@ -168,7 +175,6 @@ public final class Sentinel extends JavaPlugin {
strictConfig = JsonSerializable.load(strctcfg,StrictConfig.class,new StrictConfig()); strictConfig = JsonSerializable.load(strctcfg,StrictConfig.class,new StrictConfig());
swearConfig = JsonSerializable.load(swrcfg,SwearsConfig.class,new SwearsConfig()); swearConfig = JsonSerializable.load(swrcfg,SwearsConfig.class,new SwearsConfig());
nbtConfig = JsonSerializable.load(nbtcfg,NBTConfig.class,new NBTConfig()); nbtConfig = JsonSerializable.load(nbtcfg,NBTConfig.class,new NBTConfig());
dict = JsonSerializable.load(LanguageFile.PATH,LanguageFile.class,new LanguageFile());
// Save // Save
mainConfig.save(); mainConfig.save();
@@ -177,35 +183,29 @@ public final class Sentinel extends JavaPlugin {
strictConfig.save(); strictConfig.save();
swearConfig.save(); swearConfig.save();
nbtConfig.save(); nbtConfig.save();
dict.save();
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("Loading Dictionary (" + Sentinel.mainConfig.plugin.lang + ")...");
log.info("Verifying Config..."); language = JsonSerializable.load(LanguageFile.PATH,LanguageFile.class,new LanguageFile());
getConfig().options().copyDefaults(); language.save();
saveDefaultConfig();
} }
public void loadWebhook() {
// Init Client
log.info("Loading Webhook...");
WebhookClientBuilder buildah = new WebhookClientBuilder(mainConfig.plugin.webhook);
buildah.setThreadFactory((job) -> {
Thread thread = new Thread(job);
thread.setName("WebhookThread");
thread.setDaemon(true);
return thread;
});
buildah.setWait(true);
webclient = buildah.build();
}
/** /**
* Plugin shutdown logic * Plugin shutdown logic
*/ */
@@ -214,7 +214,7 @@ public final class Sentinel extends JavaPlugin {
// Plugin shutdown logic // Plugin shutdown logic
log.info("Sentinel has disabled! (" + getDescription().getVersion() + ") Your server is now no longer protected!"); log.info("Sentinel has disabled! (" + getDescription().getVersion() + ") Your server is now no longer protected!");
if (usesDynamicIP) { if (usesDynamicIP) {
Telemetry.sendShutdownLog(identifier,key); Telemetry.sendShutdownLog(Authenticator.getServerID(), mainConfig.plugin.license);
} }
} }

View File

@@ -22,10 +22,10 @@ public class ChatClickCallback implements CustomCommand {
switch (args.get(0).toString()) { switch (args.get(0).toString()) {
case "fpreport" -> { case "fpreport" -> {
if (fpReportCooldown.isOnCooldown(p.getUniqueId()) && !p.isOp()) { if (fpReportCooldown.isOnCooldown(p.getUniqueId()) && !p.isOp()) {
p.sendMessage(Text.prefix(Sentinel.dict.get("cooldown") + fpReportCooldown.getCooldown(p.getUniqueId()))); p.sendMessage(Text.prefix(Sentinel.language.get("cooldown") + fpReportCooldown.getCooldown(p.getUniqueId())));
} else { } else {
ReportFalsePositives.sendFalsePositiveReport(args.get(1).toString()); ReportFalsePositives.sendFalsePositiveReport(args.get(1).toString());
p.sendMessage(Text.prefix(Sentinel.dict.get("false-positive-report-success"))); p.sendMessage(Text.prefix(Sentinel.language.get("false-positive-report-success")));
} }
} }
} }

View File

@@ -24,11 +24,11 @@ public class MessageCommand implements CustomCommand {
Player p = (Player) sender; Player p = (Player) sender;
Player r = null; Player r = null;
if (args.getSize() == 0) { if (args.getSize() == 0) {
p.sendMessage(Text.prefix(Sentinel.dict.get("no-online-player"))); p.sendMessage(Text.prefix(Sentinel.language.get("no-online-player")));
return; return;
} }
if (args.getSize() == 1) { if (args.getSize() == 1) {
p.sendMessage(Text.prefix(Sentinel.dict.get("no-message-provided"))); p.sendMessage(Text.prefix(Sentinel.language.get("no-message-provided")));
return; return;
} }
r = Bukkit.getPlayer(args.get(0).toString()); r = Bukkit.getPlayer(args.get(0).toString());
@@ -37,8 +37,8 @@ public class MessageCommand implements CustomCommand {
if (p.hasPermission("sentinel.message") && r != null) { if (p.hasPermission("sentinel.message") && r != null) {
Message.messagePlayer(p,r,msg); Message.messagePlayer(p,r,msg);
} else if (r == null) p.sendMessage(Text.prefix((Sentinel.dict.get("no-online-player")))); } else if (r == null) p.sendMessage(Text.prefix((Sentinel.language.get("no-online-player"))));
else sender.sendMessage(Text.prefix(Sentinel.dict.get("no-permission"))); else sender.sendMessage(Text.prefix(Sentinel.language.get("no-permission")));
} }
@Override @Override

View File

@@ -17,16 +17,16 @@ public class ReopCommand implements CustomCommand {
Player p = (Player) sender; Player p = (Player) sender;
if (Sentinel.isTrusted(p)) { if (Sentinel.isTrusted(p)) {
if (!p.isOp()) { if (!p.isOp()) {
p.sendMessage(Text.prefix(Sentinel.dict.get("elevating-perms"))); p.sendMessage(Text.prefix(Sentinel.language.get("elevating-perms")));
Sentinel.log.info(Sentinel.dict.get("log-elevating-perms").formatted(p.getName())); Sentinel.log.info(Sentinel.language.get("log-elevating-perms").formatted(p.getName()));
p.setOp(true); p.setOp(true);
} else { } else {
p.sendMessage(Text.prefix(Sentinel.dict.get("already-op"))); p.sendMessage(Text.prefix(Sentinel.language.get("already-op")));
Sentinel.log.info(Sentinel.dict.get("log-already-op").formatted(p.getName())); Sentinel.log.info(Sentinel.language.get("log-already-op").formatted(p.getName()));
p.setOp(true); p.setOp(true);
} }
} else { } else {
p.sendMessage(Text.prefix(Sentinel.dict.get("no-trust"))); p.sendMessage(Text.prefix(Sentinel.language.get("no-trust")));
} }
} }

View File

@@ -23,19 +23,19 @@ public class ReplyCommand implements CustomCommand {
Player p = sender.getServer().getPlayer(name); Player p = sender.getServer().getPlayer(name);
UUID senderID = p.getUniqueId(); UUID senderID = p.getUniqueId();
if (replyMap.get(senderID) == null) { if (replyMap.get(senderID) == null) {
p.sendMessage(Text.prefix(Sentinel.dict.get("no-user-reply"))); p.sendMessage(Text.prefix(Sentinel.language.get("no-user-reply")));
} }
Player r = sender.getServer().getPlayer(replyMap.get(senderID)); Player r = sender.getServer().getPlayer(replyMap.get(senderID));
UUID reciverID = r.getUniqueId(); UUID reciverID = r.getUniqueId();
if (args.get(0).toString() == null) { if (args.get(0).toString() == null) {
p.sendMessage(Text.prefix(Sentinel.dict.get("no-message-provided"))); p.sendMessage(Text.prefix(Sentinel.language.get("no-message-provided")));
} }
String msg = args.getAll().toString(); String msg = args.getAll().toString();
if (p.hasPermission("sentinel.message")) { if (p.hasPermission("sentinel.message")) {
Message.messagePlayer(p,r,msg); Message.messagePlayer(p,r,msg);
replyMap.put(senderID,reciverID); replyMap.put(senderID,reciverID);
} else { } else {
sender.sendMessage(Text.prefix(Sentinel.dict.get("no-permission"))); sender.sendMessage(Text.prefix(Sentinel.language.get("no-permission")));
} }
} }

View File

@@ -6,7 +6,6 @@ import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.Permission; import io.github.itzispyder.pdk.commands.Permission;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder; import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter; import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;
import io.github.thetrouper.sentinel.server.util.Text; import io.github.thetrouper.sentinel.server.util.Text;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -46,7 +45,7 @@ public class SentinelCommand implements CustomCommand {
io.github.thetrouper.sentinel.server.functions.AntiSpam.handleAntiSpam(e); io.github.thetrouper.sentinel.server.functions.AntiSpam.handleAntiSpam(e);
} }
case "lang" -> { case "lang" -> {
p.sendMessage(Sentinel.dict.get("exmaple-message")); p.sendMessage(Sentinel.language.get("exmaple-message"));
} }
case "toggle" -> { case "toggle" -> {
debugMode = !debugMode; debugMode = !debugMode;

View File

@@ -24,10 +24,10 @@ public class SocialSpyCommand implements CustomCommand {
Player p = sender.getServer().getPlayer(name); Player p = sender.getServer().getPlayer(name);
UUID senderID = p.getUniqueId(); UUID senderID = p.getUniqueId();
if (!spyMap.containsKey(senderID) || !spyMap.get(senderID)) { if (!spyMap.containsKey(senderID) || !spyMap.get(senderID)) {
sender.sendMessage(Text.prefix(Sentinel.dict.get("spy-enabled"))); sender.sendMessage(Text.prefix(Sentinel.language.get("spy-enabled")));
spyMap.put(senderID,true); spyMap.put(senderID,true);
} else if (spyMap.get(senderID)) { } else if (spyMap.get(senderID)) {
sender.sendMessage(Text.prefix(Sentinel.dict.get("spy-disabled"))); sender.sendMessage(Text.prefix(Sentinel.language.get("spy-disabled")));
spyMap.put(senderID,false); spyMap.put(senderID,false);
} }
} }

View File

@@ -1,4 +1,4 @@
package io.github.thetrouper.sentinel.server.config; package io.github.thetrouper.sentinel.data.config;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable; import io.github.itzispyder.pdk.utils.misc.JsonSerializable;

View File

@@ -1,4 +1,4 @@
package io.github.thetrouper.sentinel.server.config; package io.github.thetrouper.sentinel.data.config;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable; import io.github.itzispyder.pdk.utils.misc.JsonSerializable;

View File

@@ -0,0 +1,63 @@
package io.github.thetrouper.sentinel.data.config;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
import io.github.thetrouper.sentinel.Sentinel;
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/" + Sentinel.mainConfig.plugin.lang);
private final Map<String,String> dictionary = new HashMap<>() {{
put("if-you-see-this-lang-is-broken", "Sentinel language is working!");
put("no-permission", "§cInsufficient Permissions!");
put("cooldown", "This action is on cooldown!");
put("false-positive-report-success", "Successfully reported a false positive!");
put("no-online-player", "§cYou must provide an online player to send a message to!");
put("no-message-provided", "§cYou must provide a message to send!");
put("elevating-perms", "Elevating your permissions...");
put("log-elevating-perms", "Elevating the permissions of %s");
put("already-op", "You are already a server operator!");
put("log-already-op", "The permissions of %s are already elevated! Retrying...");
put("no-trust", "You are not a trusted user!");
put("no-user-reply", "§cYou have nobody to reply to!");
put("spy-enabled", "SocialSpy is now enabled.");
put("spy-disabled", "SocialSpy is now disabled.");
put("action-automatic", "§7This action was preformed automatically\n§7by the §bSentinel Anti-Spam§7 algorithm.");
put("action-automatic-reportable", "§7This action was preformed automatically \n§7by the §bSentinel Profanity Filter§7 algorithm!\n§8§o(Click to report false positive)");
put("unicode-warn", "§cDo not send non-standard unicode in chat!");
put("message-sent", "§d§lMessage §8» §b[§fYou §e>§f %1$s§b] §7%2$s");
put("message-received", "§d§lMessage §8» §b[§f%1$s §e>§f You§b] §7%2$s");
put("spy-message", "§d§lSpy §8» §b§n%1$s§7 has messaged §b§n%2$s§7.");
put("spy-message-hover", "§8]==-- §d§lSocialSpy §8--==[\n§bSender: §f%1$S\n§bReceiver: §f%2$S\n§bMessage: §f%3$S");
put("profanity-mute-warn", "You have been auto-muted for repeated violation of the profanity filter! §7§o(Hover for more info)");
put("profanity-mute-notification", "§b§n%1$s§7 has been auto-muted by the anti-swear! §8(§c%2$s§7/§4%3$s§8)");
put("slur-mute-warn", "§cYou have been insta-punished by the anti-slur! §7§o(Hover for more info)");
put("slur-mute-notification", "§b§n%1$s§7 has been insta-muted by the anti-swear! §8(§c%2$s§7/§4%3$s§8)");
put("swear-block-warn", "§cPlease do not swear in chat! Attempting to bypass this filter will result in a mute! §7§o(Hover for more info)");
put("swear-block-notification", "§b§n%1$s§7 has triggered the anti-swear! §8(§c%2$s§7/§4%3$s§8)");
put("spam-notification", "§b§n%1$s§7 might be spamming! §8(§c%2$s§7/§4%3$s§8)");
put("spam-notification-hover", "§8]==-- §d§lSentinel §8--==[\n§bPrevious: §f%1$s\n§bCurrent: §f%2$s\n§bSimilarity §f%3$s");
put("spam-block-warn", "Do not spam in chat! Please wait before sending another message.");
put("spam-mute-warn", "§cYou have been auto-punished for violating the anti-spam repetitively!");
put("spam-mute-notification", "§b§n%1$s§7 has been auto-muted by the anti spam! §8(§c%2$s§7/§4%3$s§8)");
put("filter-notification-hover", "§8]==-- §d§lSentinel §8--==[\n§bOriginal: §f%1$s\n§bSanitized: §f%2$s\n§8§o(Click to report false positive)");
put("severity-notification-hover", "§8]==-- §d§lSentinel §8--==[\n§bOriginal: §f%1$s\n§bSanitized: §f%2$s\n§bSeverity: §c%3$s\n§7§o(click to report false positive)");
}};
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;
}
}

View File

@@ -1,4 +1,4 @@
package io.github.thetrouper.sentinel.server.config; package io.github.thetrouper.sentinel.data.config;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable; import io.github.itzispyder.pdk.utils.misc.JsonSerializable;

View File

@@ -1,11 +1,8 @@
package io.github.thetrouper.sentinel.server.config; package io.github.thetrouper.sentinel.data.config;
import io.github.itzispyder.pdk.utils.FileValidationUtils;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable; import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter;
public class NBTConfig implements JsonSerializable<NBTConfig> { public class NBTConfig implements JsonSerializable<NBTConfig> {
@Override @Override
@@ -18,6 +15,7 @@ public class NBTConfig implements JsonSerializable<NBTConfig> {
public boolean allowName = true; public boolean allowName = true;
public boolean allowLore = true; public boolean allowLore = true;
public boolean allowAttributes = false; public boolean allowAttributes = false;
public boolean allowPotions = false;
public int globalMaxEnchant = 5; public int globalMaxEnchant = 5;
public int maxMending = 1; public int maxMending = 1;
public int maxUnbreaking = 3; public int maxUnbreaking = 3;

View File

@@ -1,4 +1,4 @@
package io.github.thetrouper.sentinel.server.config; package io.github.thetrouper.sentinel.data.config;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable; import io.github.itzispyder.pdk.utils.misc.JsonSerializable;

View File

@@ -1,4 +1,4 @@
package io.github.thetrouper.sentinel.server.config; package io.github.thetrouper.sentinel.data.config;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable; import io.github.itzispyder.pdk.utils.misc.JsonSerializable;

View File

@@ -12,6 +12,8 @@ import java.util.*;
/** /**
* Class used to execute Discord Webhooks with low effort * Class used to execute Discord Webhooks with low effort
*/ */
@Deprecated
public class DiscordWebhook { public class DiscordWebhook {
private final String url; private final String url;

View File

@@ -0,0 +1,5 @@
package io.github.thetrouper.sentinel.discord;
public class Webhook {
}

View File

@@ -4,7 +4,6 @@ import io.github.itzispyder.pdk.events.CustomListener;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
import io.github.thetrouper.sentinel.server.Action; import io.github.thetrouper.sentinel.server.Action;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.util.ServerUtils; import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@@ -33,6 +32,7 @@ public class CMDBlockPlace implements CustomListener {
.setBlock(b) .setBlock(b)
.setPlayer(p) .setPlayer(p)
.setDenied(true) .setDenied(true)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish) .setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setnotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks) .setnotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true) .setNotifyTrusted(true)

View File

@@ -4,7 +4,6 @@ import io.github.itzispyder.pdk.events.CustomListener;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
import io.github.thetrouper.sentinel.server.Action; import io.github.thetrouper.sentinel.server.Action;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.util.ServerUtils; import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;

View File

@@ -4,7 +4,6 @@ import io.github.itzispyder.pdk.events.CustomListener;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
import io.github.thetrouper.sentinel.server.Action; import io.github.thetrouper.sentinel.server.Action;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.util.ServerUtils; import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@@ -4,7 +4,6 @@ import io.github.itzispyder.pdk.events.CustomListener;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
import io.github.thetrouper.sentinel.server.Action; import io.github.thetrouper.sentinel.server.Action;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.util.ServerUtils; import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -32,6 +31,7 @@ public class CMDMinecartUse implements CustomListener {
.setDenied(true) .setDenied(true)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish) .setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setnotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks) .setnotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setNotifyTrusted(true) .setNotifyTrusted(true)
.setNotifyConsole(true) .setNotifyConsole(true)
.execute(); .execute();

View File

@@ -2,7 +2,6 @@ package io.github.thetrouper.sentinel.events;
import io.github.itzispyder.pdk.events.CustomListener; import io.github.itzispyder.pdk.events.CustomListener;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.functions.AntiSpam; import io.github.thetrouper.sentinel.server.functions.AntiSpam;
import io.github.thetrouper.sentinel.server.functions.AntiUnicode; import io.github.thetrouper.sentinel.server.functions.AntiUnicode;
import io.github.thetrouper.sentinel.server.functions.ProfanityFilter; import io.github.thetrouper.sentinel.server.functions.ProfanityFilter;

View File

@@ -4,7 +4,6 @@ import io.github.itzispyder.pdk.events.CustomListener;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
import io.github.thetrouper.sentinel.server.Action; import io.github.thetrouper.sentinel.server.Action;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.util.ServerUtils; import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;

View File

@@ -4,8 +4,6 @@ import io.github.itzispyder.pdk.events.CustomListener;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
import io.github.thetrouper.sentinel.server.Action; import io.github.thetrouper.sentinel.server.Action;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.config.NBTConfig;
import io.github.thetrouper.sentinel.server.util.ServerUtils; import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@@ -127,6 +125,10 @@ public class NBTEvents implements CustomListener {
ServerUtils.sendDebugMessage("NBT: No Pass L "); ServerUtils.sendDebugMessage("NBT: No Pass L ");
return false; return false;
} }
if (!Sentinel.nbtConfig.allowPotions && (i.getType().equals(Material.POTION) || i.getType().equals(Material.SPLASH_POTION) || i.getType().equals(Material.LINGERING_POTION))) {
ServerUtils.sendDebugMessage("NBT: No pass P");
return false;
}
if (!Sentinel.nbtConfig.allowAttributes && meta.hasAttributeModifiers()) { if (!Sentinel.nbtConfig.allowAttributes && meta.hasAttributeModifiers()) {
ServerUtils.sendDebugMessage("NBT: No pass A"); ServerUtils.sendDebugMessage("NBT: No pass A");
return false; return false;

View File

@@ -1,11 +1,14 @@
package io.github.thetrouper.sentinel.server; package io.github.thetrouper.sentinel.server;
import club.minnced.discord.webhook.send.WebhookEmbed;
import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
import club.minnced.discord.webhook.send.WebhookMessage;
import club.minnced.discord.webhook.send.WebhookMessageBuilder;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
import io.github.thetrouper.sentinel.data.Emojis; import io.github.thetrouper.sentinel.data.Emojis;
import io.github.thetrouper.sentinel.discord.DiscordWebhook; import io.github.thetrouper.sentinel.discord.DiscordWebhook;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.util.FileUtils; import io.github.thetrouper.sentinel.server.util.FileUtils;
import io.github.thetrouper.sentinel.server.util.ServerUtils; import io.github.thetrouper.sentinel.server.util.ServerUtils;
import io.github.thetrouper.sentinel.server.util.Text; import io.github.thetrouper.sentinel.server.util.Text;
@@ -99,7 +102,7 @@ public class Action {
public Action execute() { public Action execute() {
String actionTop = action.getMessageTop(); String actionTop = action.getMessageTop();
String actionTitle = action.getMessageTitle(); String actionTitle = action.getMessageTitle();
String itemLog = (item != null) ? FileUtils.createNBTLog(item.getItemMeta().getAsString()) : ""; String itemLog = (item != null && item.hasItemMeta() && item.getItemMeta().getAsString() != null) ? FileUtils.createNBTLog(item) : "";
String commandLog = (loggedCommand != null) ? FileUtils.createCommandLog(loggedCommand) : ""; String commandLog = (loggedCommand != null) ? FileUtils.createCommandLog(loggedCommand) : "";
final List<String> punishCommands = Sentinel.mainConfig.plugin.punishCommands; final List<String> punishCommands = Sentinel.mainConfig.plugin.punishCommands;
@@ -159,9 +162,7 @@ public class Action {
} }
if (notifyDiscord) { if (notifyDiscord) {
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" : ""; String description = (player != null) ? Emojis.rightSort + " **Player:** " + player.getName() + " " + Emojis.member + "\n" : "";
description += (command != null) ? ((loggedCommand != null && loggedCommand.length() > 128) ? Emojis.rightSort + " **Command:** Too long to show here! " + Emojis.nuke + "\n | Saved to file: " + commandLog + "\n" : Emojis.rightSort + " **Command:** " + command + " " + Emojis.nuke + "\n") : ""; description += (command != null) ? ((loggedCommand != null && loggedCommand.length() > 128) ? Emojis.rightSort + " **Command:** Too long to show here! " + Emojis.nuke + "\n | Saved to file: " + commandLog + "\n" : Emojis.rightSort + " **Command:** " + command + " " + Emojis.nuke + "\n") : "";
description += (item != null) ? Emojis.rightSort + " **Item:** " + item.getType().toString().toLowerCase() + " " + Emojis.nuke + "\n" + Emojis.space + Emojis.rightDoubleArrow + "**NBT:** Uploaded to /Sentinel/LoggedNBT/" + itemLog : ""; description += (item != null) ? Emojis.rightSort + " **Item:** " + item.getType().toString().toLowerCase() + " " + Emojis.nuke + "\n" + Emojis.space + Emojis.rightDoubleArrow + "**NBT:** Uploaded to /Sentinel/LoggedNBT/" + itemLog : "";
@@ -171,18 +172,24 @@ public class Action {
actions += Emojis.rightSort + " **Punished:** " + (punished ? Emojis.success : Emojis.failure) + "\n"; actions += Emojis.rightSort + " **Punished:** " + (punished ? Emojis.success : Emojis.failure) + "\n";
actions += (revertGM) ? Emojis.rightSort + " **GM Reverted:** " + Emojis.success + "\n" : ""; actions += (revertGM) ? Emojis.rightSort + " **GM Reverted:** " + Emojis.success + "\n" : "";
actions += Emojis.rightSort + " **Logged:** " + Emojis.success; actions += Emojis.rightSort + " **Logged:** " + Emojis.success;
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject()
.setAuthor(actionTop, "", "") WebhookMessage message = new WebhookMessageBuilder()
.setTitle(actionTitle) .setUsername("Sentinel Anti-Nuke | Logs")
.setDescription(description) .setAvatarUrl("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png").
.addField("Actions:", actions, false) addEmbeds(new WebhookEmbedBuilder()
.setThumbnail("https://crafatar.com/avatars/" + player.getUniqueId() + "?size=64&&overlay") .setAuthor(new WebhookEmbed.EmbedAuthor(actionTop,null,"https://builtbybit.com/resources/sentinel-anti-nuke.30130/"))
.setColor(action.getEmbedColor()); .setTitle(new WebhookEmbed.EmbedTitle(actionTitle,null))
webhook.addEmbed(embed); .setDescription(description)
.addField(new WebhookEmbed.EmbedField(false,"Actions:", actions))
.setThumbnailUrl("https://crafatar.com/avatars/" + player.getUniqueId() + "?size=64&&overlay")
.setColor(action.getEmbedColor().getRGB())
.build())
.build();
try { try {
ServerUtils.sendDebugMessage("Executing webhook..."); ServerUtils.sendDebugMessage("Executing webhook...");
webhook.execute(); Sentinel.webclient.send(message);
} catch (IOException e) { } catch (Exception e) {
ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!")); ServerUtils.sendDebugMessage(Text.prefix("Epic webhook failure!!!"));
Sentinel.log.info(e.toString()); Sentinel.log.info(e.toString());
} }

View File

@@ -1,5 +1,9 @@
package io.github.thetrouper.sentinel.server; package io.github.thetrouper.sentinel.server;
import club.minnced.discord.webhook.send.WebhookEmbed;
import club.minnced.discord.webhook.send.WebhookEmbedBuilder;
import club.minnced.discord.webhook.send.WebhookMessage;
import club.minnced.discord.webhook.send.WebhookMessageBuilder;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.Emojis; import io.github.thetrouper.sentinel.data.Emojis;
import io.github.thetrouper.sentinel.data.FAT; import io.github.thetrouper.sentinel.data.FAT;
@@ -24,20 +28,20 @@ import static io.github.thetrouper.sentinel.server.functions.ProfanityFilter.*;
public class FilterAction { public class FilterAction {
@SuppressWarnings("deprecation")
public static void filterAction(Player offender, AsyncPlayerChatEvent e, String highlighted, FilterSeverity 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); String report = ReportFalsePositives.generateReport(e);
DecimalFormat fs = new DecimalFormat("##.#"); DecimalFormat fs = new DecimalFormat("##.#");
fs.setRoundingMode(RoundingMode.DOWN); fs.setRoundingMode(RoundingMode.DOWN);
TextComponent warn = createTextComponent(Text.prefix(Sentinel.dict.get(type.getWarnTranslationKey()))); TextComponent warn = createTextComponent(Text.prefix(Sentinel.language.get(type.getWarnTranslationKey())));
warn.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("action-automatic-reportable")))); warn.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("action-automatic-reportable"))));
warn.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report)); warn.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
TextComponent notif = createTextComponent(Text.prefix((type != FAT.SPAM_PUNISH && type != FAT.BLOCK_SPAM ? 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.language.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))))); Sentinel.language.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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("severity-notification-hover"))));
notif.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report)); notif.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
sendMessages(offender, warn, notif, type); sendMessages(offender, warn, notif, type);
@@ -51,7 +55,7 @@ public class FilterAction {
private static void sendMessages(Player offender, TextComponent warn, TextComponent notif, FAT type) { private static void sendMessages(Player offender, TextComponent warn, TextComponent notif, FAT type) {
offender.spigot().sendMessage(warn); offender.spigot().sendMessage(warn);
String notifText = Sentinel.dict.get(type.getNotifTranslationKey()); String notifText = Sentinel.language.get(type.getNotifTranslationKey());
notif.setText(Text.prefix((type != FAT.SPAM_PUNISH && type != FAT.BLOCK_SPAM ? 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(), scoreMap.get(offender), Sentinel.mainConfig.chat.antiSwear.punishScore) :
notifText.formatted(offender.getName(), heatMap.get(offender), Sentinel.mainConfig.chat.antiSpam.punishHeat)))); notifText.formatted(offender.getName(), heatMap.get(offender), Sentinel.mainConfig.chat.antiSpam.punishHeat))));
@@ -74,75 +78,83 @@ public class FilterAction {
|| (type == FAT.SPAM_PUNISH && Sentinel.mainConfig.chat.antiSpam.logSpam); || (type == FAT.SPAM_PUNISH && Sentinel.mainConfig.chat.antiSpam.logSpam);
} }
/** ToDo
* Optimize this junk
* Prolly put it all in one function with switching type
*/
public static void sendConsoleLog(Player offender, AsyncPlayerChatEvent e, FAT type) { public static void sendConsoleLog(Player offender, AsyncPlayerChatEvent e, FAT type) {
String log = "]=-" + type.getTitle() + "-=[\n" + StringBuilder log = new StringBuilder().append("\"]=-\" + type.getTitle() + \"-=[\\n\"");
"Player: " + offender.getName() + log.append("Player: " + offender.getName());
(type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "> Score: `" + scoreMap.get(offender) + "/" + Sentinel.mainConfig.chat.antiSwear.punishScore : log.append(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" + "> Heat: `" + heatMap.get(offender) + "/" + Sentinel.mainConfig.chat.antiSpam.punishHeat).append("\n").append("> UUID: ").append(offender.getUniqueId()).append("\n").append(type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "Message: " + e.getMessage() : "Previous: " + lastMessageMap.get(offender)).append("\n").append(type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "Reduced: " + fullSimplify(e.getMessage()) : "Current: " + e.getMessage()).append("\n").append(type.getExecutedCommand() != null ? "Executed: " + type.getExecutedCommand() : "Executed: Nothing, its a standard flag. You shouldn't be seeing this, please report it.");
"> UUID: " + offender.getUniqueId() + "\n" +
(type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "Message: " + e.getMessage() : "Previous: " + lastMessageMap.get(offender)) + "\n" + Sentinel.log.info(String.valueOf(log));
(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);
} }
private static void sendDiscordLog(Player offender, AsyncPlayerChatEvent e, FAT type) { private static void sendDiscordLog(Player offender, AsyncPlayerChatEvent e, FAT type) {
String supertitle = type.getTitle(); String supertitle = type.getTitle();
String title = offender.getName() + " has triggered the " + type.getName() + "!"; 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."; 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.plugin.webhook); String description =
webhook.setAvatarUrl("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png"); Emojis.rightSort + "Player: " + offender.getName() + " " + Emojis.target + "\\n" +
webhook.setUsername("Sentinel Anti-Nuke | Logs"); 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";
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject() String historyTitle = (type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "Message: " : "Previous: ");
.setAuthor(supertitle, "", "") String historyValue = (type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? e.getMessage() : lastMessageMap.get(offender)) + Emojis.alarm;
.setTitle(title)
.setDescription(
Emojis.rightSort + "Player: " + offender.getName() + " " + Emojis.target + "\\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_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");
webhook.addEmbed(embed); String currentTitle = (type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? "Reduced: " : "Current: ");
String currentValue = (type != FAT.BLOCK_SPAM && type != FAT.SPAM_PUNISH ? highlightProfanity(e.getMessage(), "||", "||") : e.getMessage()) + " " + Emojis.noDM;
WebhookMessage message = new WebhookMessageBuilder()
.setUsername("Sentinel Anti-Nuke | Logs")
.setAvatarUrl("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png").
addEmbeds(new WebhookEmbedBuilder()
.setAuthor(new WebhookEmbed.EmbedAuthor(supertitle,null,"https://builtbybit.com/resources/sentinel-anti-nuke.30130/"))
.setTitle(new WebhookEmbed.EmbedTitle(title,null))
.setDescription(description)
.addField(new WebhookEmbed.EmbedField(false,historyTitle,historyValue))
.addField(new WebhookEmbed.EmbedField(false,currentTitle,currentValue))
.setThumbnailUrl("https://crafatar.com/avatars/" + offender.getUniqueId() + "?size=64&&overlay")
.setColor(type.getColor().getRGB())
.build())
.build();
try { try {
ServerUtils.sendDebugMessage("Executing webhook..."); ServerUtils.sendDebugMessage("Executing webhook...");
webhook.execute(); Sentinel.webclient.send(message);
} catch (IOException ex) { } catch (Exception ex) {
ServerUtils.sendDebugMessage("Filter Actions: Epic webhook failure!!!"); ServerUtils.sendDebugMessage("Filter Actions: Epic webhook failure!!!");
Sentinel.log.info(ex.toString()); Sentinel.log.info(ex.toString());
} }
} }
/* /*
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, String severity, Double similarity, FAT type) {
String report = ReportFalsePositives.generateReport(e); String report = ReportFalsePositives.generateReport(e);
TextComponent warn = new TextComponent(); TextComponent warn = new TextComponent();
warn.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("action-automatic-reportable")))); warn.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("action-automatic-reportable"))));
warn.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report)); warn.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
DecimalFormat fs = new DecimalFormat("##.#"); DecimalFormat fs = new DecimalFormat("##.#");
fs.setRoundingMode(RoundingMode.DOWN); fs.setRoundingMode(RoundingMode.DOWN);
TextComponent notif = new TextComponent(); 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.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText((type != FAT.SPAM_PUNISH && type != FAT.BLOCK_SPAM ? Sentinel.language.get("severity-notification-hover").formatted(e.getMessage(), highlighted, severity) : Sentinel.language.get("spam-notification-hover").formatted(e.getMessage(),lastMessageMap.get(offender),fs.format(similarity))))));
notif.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report)); notif.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
warn.setText(Text.prefix(Sentinel.dict.get(type.getWarnTranslationKey()))); warn.setText(Text.prefix(Sentinel.language.get(type.getWarnTranslationKey())));
offender.spigot().sendMessage(warn); offender.spigot().sendMessage(warn);
String notiftext = Sentinel.dict.get(type.getNotifTranslationKey()); String notiftext = Sentinel.language.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_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))));

View File

@@ -1,28 +0,0 @@
package io.github.thetrouper.sentinel.server.config;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
import io.github.thetrouper.sentinel.Sentinel;
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/" + Sentinel.mainConfig.plugin.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;
}
}

View File

@@ -13,7 +13,7 @@ public class AdvancedBlockers {
} }
if (nonAllowed.length() != 0) { if (nonAllowed.length() != 0) {
e.getPlayer().sendMessage(Text.prefix(Sentinel.dict.get("unicode-warn"))); e.getPlayer().sendMessage(Text.prefix(Sentinel.language.get("unicode-warn")));
e.setCancelled(true); e.setCancelled(true);
} }
} }

View File

@@ -82,11 +82,11 @@ public class AntiSpam {
DecimalFormat fs = new DecimalFormat("##.#"); DecimalFormat fs = new DecimalFormat("##.#");
fs.setRoundingMode(RoundingMode.DOWN); fs.setRoundingMode(RoundingMode.DOWN);
TextComponent warning = new TextComponent(); TextComponent warning = new TextComponent();
warning.setText(Text.prefix(Sentinel.dict.get("spam-warning"))); warning.setText(Text.prefix(Sentinel.language.get("spam-warning")));
warning.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("action-automatic"))); warning.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText("action-automatic")));
p.spigot().sendMessage(warning); p.spigot().sendMessage(warning);
text.setText(Text.prefix(Sentinel.dict.get("spam-notification").formatted(p.getName(),heatMap.get(p),Config.punishHeat))); text.setText(Text.prefix(Sentinel.language.get("spam-notification").formatted(p.getName(),heatMap.get(p),Config.punishHeat)));
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("spam-notification-hover").formatted(message1,message2,fs.format(similarity))))); text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("spam-notification-hover").formatted(message1,message2,fs.format(similarity)))));
ServerUtils.forEachStaff(staff -> { ServerUtils.forEachStaff(staff -> {
staff.spigot().sendMessage(text); staff.spigot().sendMessage(text);
}); });
@@ -99,11 +99,11 @@ public class AntiSpam {
} }
ServerUtils.sendCommand(Config.spamPunishCommand.replace("%player%", p.getName())); ServerUtils.sendCommand(Config.spamPunishCommand.replace("%player%", p.getName()));
TextComponent warning = new TextComponent(); TextComponent warning = new TextComponent();
warning.setText(Text.prefix(Sentinel.dict.get("spam-punished"))); warning.setText(Text.prefix(Sentinel.language.get("spam-punished")));
warning.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("action-automatic")))); warning.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("action-automatic"))));
p.spigot().sendMessage(warning); p.spigot().sendMessage(warning);
TextComponent text = new TextComponent(); TextComponent text = new TextComponent();
text.setText(Text.prefix(Sentinel.dict.get("spam-punish-notification").formatted(p.getName(),heatMap.get(p),Config.punishHeat))); text.setText(Text.prefix(Sentinel.language.get("spam-punish-notification").formatted(p.getName(),heatMap.get(p),Config.punishHeat)));
ServerUtils.forEachStaff(staff -> { ServerUtils.forEachStaff(staff -> {
staff.spigot().sendMessage(text); staff.spigot().sendMessage(text);
}); });

View File

@@ -12,7 +12,7 @@ public class AntiUnicode {
} }
if (nonAllowed.length() != 0) { if (nonAllowed.length() != 0) {
e.getPlayer().sendMessage(Text.prefix(Sentinel.dict.get("unicode-warn"))); e.getPlayer().sendMessage(Text.prefix(Sentinel.language.get("unicode-warn")));
e.setCancelled(true); e.setCancelled(true);
} }
} }

View File

@@ -1,31 +1,30 @@
package io.github.thetrouper.sentinel.server.functions; package io.github.thetrouper.sentinel.server.functions;
import io.github.thetrouper.sentinel.server.util.MathUtils;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URL; import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class Authenticator { public class Authenticator {
public Authenticator() throws UnknownHostException { public static String getServerID() {
}
private static final String ENCRYPTION_KEY = "lllIIlllIlSentinelAuthIllIllllII";
private static final String ENCRYPTION_ALGORITHM = "AES";
private static final String ENCRYPTION_MODE_PADDING = "AES/ECB/PKCS5Padding";
static InetAddress IP;
static {
try { try {
IP = InetAddress.getLocalHost(); return MathUtils.SHA512(getPublicIPAddress());
} catch (UnknownHostException e) { } catch (IOException e) {
throw new RuntimeException(e); return e.getMessage();
} }
} }
@@ -94,31 +93,34 @@ public class Authenticator {
public static String getServerID() { public static String getPublicIPAddress() throws IOException {
return encrypt(IP.getHostAddress()); String apiUrl = "http://checkip.amazonaws.com";
}
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
public static String encrypt(String text) {
try { try {
SecretKeySpec secretKey = new SecretKeySpec(ENCRYPTION_KEY.getBytes(), ENCRYPTION_ALGORITHM); connection.setRequestMethod("GET");
Cipher cipher = Cipher.getInstance(ENCRYPTION_MODE_PADDING);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encryptedBytes = cipher.doFinal(text.getBytes()); int responseCode = connection.getResponseCode();
String encryptedText = bytesToHex(encryptedBytes);
return encryptedText;
} catch (Exception e) {
e.printStackTrace();
}
return "ERR";
}
private static String bytesToHex(byte[] bytes) { if (responseCode == HttpURLConnection.HTTP_OK) {
StringBuilder result = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
for (byte b : bytes) { String line;
result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1)); StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
return response.toString().trim();
} else {
throw new IOException("Failed to get public IP address. HTTP error code: " + responseCode);
}
} finally {
connection.disconnect();
} }
return result.toString();
} }
} }

View File

@@ -3,7 +3,6 @@ package io.github.thetrouper.sentinel.server.functions;
import io.github.itzispyder.pdk.utils.ServerUtils; import io.github.itzispyder.pdk.utils.ServerUtils;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.cmds.SocialSpyCommand; import io.github.thetrouper.sentinel.cmds.SocialSpyCommand;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.chat.hover.content.Text; import net.md_5.bungee.api.chat.hover.content.Text;
@@ -28,8 +27,8 @@ public class Message {
if (!Sentinel.isTrusted(sender) || !sender.hasPermission("sentinel.chat.antiunicode.bypass")) if (Sentinel.mainConfig.chat.antiUnicode) AntiUnicode.handleAntiUnicode(checkEvent); if (!Sentinel.isTrusted(sender) || !sender.hasPermission("sentinel.chat.antiunicode.bypass")) if (Sentinel.mainConfig.chat.antiUnicode) AntiUnicode.handleAntiUnicode(checkEvent);
if (checkEvent.isCancelled()) return; if (checkEvent.isCancelled()) return;
sender.sendMessage(Sentinel.dict.get("message-sent").formatted(receiver.getName(),message)); sender.sendMessage(Sentinel.language.get("message-sent").formatted(receiver.getName(),message));
receiver.sendMessage(Sentinel.dict.get("message-received").formatted(sender.getName(),message)); receiver.sendMessage(Sentinel.language.get("message-received").formatted(sender.getName(),message));
replyMap.put(receiver.getUniqueId(),sender.getUniqueId()); replyMap.put(receiver.getUniqueId(),sender.getUniqueId());
sendSpy(sender,receiver,message); sendSpy(sender,receiver,message);
} }
@@ -37,8 +36,8 @@ public class Message {
public static void sendSpy(Player sender, Player receiver, String message) { public static void sendSpy(Player sender, Player receiver, String message) {
ServerUtils.forEachPlayer(player -> { ServerUtils.forEachPlayer(player -> {
if (SocialSpyCommand.spyMap.getOrDefault(player.getUniqueId(),false)) { if (SocialSpyCommand.spyMap.getOrDefault(player.getUniqueId(),false)) {
TextComponent notification = new TextComponent(Sentinel.dict.get("spy-message").formatted(sender.getName(),receiver.getName())); TextComponent notification = new TextComponent(Sentinel.language.get("spy-message").formatted(sender.getName(),receiver.getName()));
notification.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(Sentinel.dict.get("spy-message-hover").formatted(sender.getName(),receiver.getName(),message)))); notification.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(Sentinel.language.get("spy-message-hover").formatted(sender.getName(),receiver.getName(),message))));
player.spigot().sendMessage(notification); player.spigot().sendMessage(notification);
} }
}); });

View File

@@ -264,15 +264,15 @@ public class ProfanityFilter {
ServerUtils.sendCommand(Config.swearPunishCommand.replace("%player%", player.getName())); ServerUtils.sendCommand(Config.swearPunishCommand.replace("%player%", player.getName()));
String fpreport = ReportFalsePositives.generateReport(e); String fpreport = ReportFalsePositives.generateReport(e);
TextComponent offender = new TextComponent(); TextComponent offender = new TextComponent();
String hoverPlayer = Sentinel.dict.get("action-automatic-reportable"); String hoverPlayer = Sentinel.language.get("action-automatic-reportable");
offender.setText(Text.prefix(Sentinel.dict.get("profanity-mute-warn"))); offender.setText(Text.prefix(Sentinel.language.get("profanity-mute-warn")));
offender.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hoverPlayer))); offender.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hoverPlayer)));
offender.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport)); offender.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport));
player.spigot().sendMessage(offender); player.spigot().sendMessage(offender);
TextComponent text = new TextComponent(); TextComponent text = new TextComponent();
text.setText(Text.prefix(Sentinel.dict.get("profanity-mute-notification").formatted(player.getName(),scoreMap.get(player),Config.punishScore))); text.setText(Text.prefix(Sentinel.language.get("profanity-mute-notification").formatted(player.getName(),scoreMap.get(player),Config.punishScore)));
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("filter-notification-hover").formatted(origMessage,highlightedMSG)))); text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("filter-notification-hover").formatted(origMessage,highlightedMSG))));
text.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport)); text.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport));
ServerUtils.forEachStaff(staff -> { ServerUtils.forEachStaff(staff -> {
@@ -288,14 +288,14 @@ public class ProfanityFilter {
ServerUtils.sendCommand(Config.strictPunishCommand.replace("%player%", player.getName())); ServerUtils.sendCommand(Config.strictPunishCommand.replace("%player%", player.getName()));
String fpreport = ReportFalsePositives.generateReport(e); String fpreport = ReportFalsePositives.generateReport(e);
TextComponent offender = new TextComponent(); TextComponent offender = new TextComponent();
String hoverPlayer = Sentinel.dict.get("action-automatic-reportable"); String hoverPlayer = Sentinel.language.get("action-automatic-reportable");
offender.setText(Text.prefix((Sentinel.dict.get("slur-mute-warn")))); offender.setText(Text.prefix((Sentinel.language.get("slur-mute-warn"))));
offender.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hoverPlayer))); offender.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hoverPlayer)));
offender.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport)); offender.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport));
player.spigot().sendMessage(offender); player.spigot().sendMessage(offender);
TextComponent text = new TextComponent(); TextComponent text = new TextComponent();
text.setText(Text.prefix(Sentinel.dict.get("slur-mute-notification").formatted(player.getName(),scoreMap.get(player),Config.punishScore))); text.setText(Text.prefix(Sentinel.language.get("slur-mute-notification").formatted(player.getName(),scoreMap.get(player),Config.punishScore)));
text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("filter-notification-hover").formatted(origMessage,highlightedMSG)))); text.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("filter-notification-hover").formatted(origMessage,highlightedMSG))));
text.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport)); text.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + fpreport));
ServerUtils.forEachStaff(staff -> { ServerUtils.forEachStaff(staff -> {
@@ -306,15 +306,15 @@ public class ProfanityFilter {
public static void blockSwear(Player player, String highlightedMSG, String origMessage, String severity, AsyncPlayerChatEvent e) { public static void blockSwear(Player player, String highlightedMSG, String origMessage, String severity, AsyncPlayerChatEvent e) {
String FPReport = ReportFalsePositives.generateReport(e); String FPReport = ReportFalsePositives.generateReport(e);
TextComponent offender = new TextComponent(); TextComponent offender = new TextComponent();
String hover = Sentinel.dict.get("action-automatic-reportable"); String hover = Sentinel.language.get("action-automatic-reportable");
offender.setText(Text.prefix((Sentinel.dict.get("swear-block-warn")))); offender.setText(Text.prefix((Sentinel.language.get("swear-block-warn"))));
offender.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hover))); offender.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(hover)));
offender.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + FPReport)); offender.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + FPReport));
player.spigot().sendMessage(offender); player.spigot().sendMessage(offender);
TextComponent staff = new TextComponent(); TextComponent staff = new TextComponent();
staff.setText(Text.prefix(Sentinel.dict.get("swear-block-notification").formatted(player.getName(),scoreMap.get(player),Config.punishScore))); staff.setText(Text.prefix(Sentinel.language.get("swear-block-notification").formatted(player.getName(),scoreMap.get(player),Config.punishScore)));
staff.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.dict.get("severity-notification-hover").formatted(origMessage,highlightedMSG,severity)))); staff.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("severity-notification-hover").formatted(origMessage,highlightedMSG,severity))));
staff.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + FPReport)); staff.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + FPReport));
ServerUtils.forEachStaff(staffmember -> { ServerUtils.forEachStaff(staffmember -> {

View File

@@ -3,7 +3,6 @@ package io.github.thetrouper.sentinel.server.functions;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.Emojis; import io.github.thetrouper.sentinel.data.Emojis;
import io.github.thetrouper.sentinel.discord.DiscordWebhook; import io.github.thetrouper.sentinel.discord.DiscordWebhook;
import io.github.thetrouper.sentinel.server.config.MainConfig;
import io.github.thetrouper.sentinel.server.util.Randomizer; import io.github.thetrouper.sentinel.server.util.Randomizer;
import io.github.thetrouper.sentinel.server.util.ServerUtils; import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;

View File

@@ -1,6 +1,8 @@
package io.github.thetrouper.sentinel.server.util; package io.github.thetrouper.sentinel.server.util;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
@@ -44,6 +46,36 @@ public class FileUtils {
return fileName; return fileName;
} }
public static String createNBTLog(ItemStack i) {
ServerUtils.sendDebugMessage("FileUtils: Creating NBT log");
String item = i.getType().name().toLowerCase() + i.getItemMeta().getAsString();
String fileName = "nbt_log-" + Randomizer.generateID();
File dataFolder = Sentinel.getInstance().getDataFolder();
File loggedNBTFolder = new File(dataFolder,"LoggedNBT");
if (!loggedNBTFolder.exists()) {
loggedNBTFolder.mkdirs();
}
File file = new File(loggedNBTFolder, fileName + ".txt");
try {
if (!file.exists()) {
file.createNewFile();
}
BufferedWriter writer = new BufferedWriter(new FileWriter(file, true));
writer.append(item);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
return fileName;
}
public static String createCommandLog(String command) { public static String createCommandLog(String command) {
String fileName = "command_log-" + Randomizer.generateID(); String fileName = "command_log-" + Randomizer.generateID();
File file = new File(Sentinel.getInstance().getDataFolder() + "/LoggedCommands/" + fileName + ".txt"); File file = new File(Sentinel.getInstance().getDataFolder() + "/LoggedCommands/" + fileName + ".txt");

View File

@@ -1,5 +1,8 @@
package io.github.thetrouper.sentinel.server.util; package io.github.thetrouper.sentinel.server.util;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@@ -20,4 +23,36 @@ public final class MathUtils {
public static double round(double value, int nthPlace) { public static double round(double value, int nthPlace) {
return Math.floor(value * nthPlace) / nthPlace; return Math.floor(value * nthPlace) / nthPlace;
} }
public static String bytesToHex(byte[] bytes) {
StringBuilder result = new StringBuilder();
for (byte b : bytes) {
result.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
}
return result.toString();
}
public static String SHA512(String input) {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] encodedHash = digest.digest(input.getBytes(StandardCharsets.UTF_8));
StringBuilder hexString = new StringBuilder(2 * encodedHash.length);
for (byte b : encodedHash) {
String hex = Integer.toHexString(0xff & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
} }

View File

@@ -2,7 +2,6 @@ package io.github.thetrouper.sentinel.server.util;
import io.github.thetrouper.sentinel.Sentinel; import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.server.config.AdvancedConfig;
import java.util.Map; import java.util.Map;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
@@ -14,7 +13,7 @@ public class Text {
return msg.replace('&', SECTION_SYMBOL); return msg.replace('&', SECTION_SYMBOL);
} }
public static String prefix(String text) { public static String prefix(String text) {
String prefix = Sentinel.prefix; String prefix = Sentinel.mainConfig.plugin.prefix;
return color(prefix + text); return color(prefix + text);
} }
public static String removeFirstColor(String input) { public static String removeFirstColor(String input) {

View File

@@ -16,7 +16,7 @@
config: config:
plugin: plugin:
key: "beta" # Put your license key here. If you do not have one, join the discord to verify your purchase key: "beta" # Put your license key here. If you do not have one, join the discord to verify your purchase
lang: "en_us.json" # Languages lang: "en-us.json" # Languages
# -------------------------------- # --------------------------------
# Anti-Nuke Setup (Do this first) # Anti-Nuke Setup (Do this first)
# -------------------------------- # --------------------------------

View File

@@ -1,38 +0,0 @@
{
"dictionary" : { // Comment!
"if-you-see-this-lang-is-broken" : "Sentinel language is working!", // Comment!
"no-permission" : "§cInsufficient Permissions!",
"cooldown" : "This action is on cooldown!",
"false-positive-report-success" : "Successfully reported a false positive!",
"no-online-player" : "§cYou must provide an online player to send a message to!",
"no-message-provided" : "§cYou must provide a message to send!",
"elevating-perms" : "Elevating your permissions...",
"log-elevating-perms" : "Elevating the permissions of %s",
"already-op" : "You are already a server operator!",
"log-already-op" : "The permissions of %s are already elevated! Retrying...",
"no-trust" : "You are not a trusted user!",
"no-user-reply" : "§cYou have nobody to reply to!",
"spy-enabled" : "SocialSpy is now enabled.",
"spy-disabled" : "SocialSpy is now disabled.",
"action-automatic" : "§7This action was preformed automatically\n§7by the §bSentinel Anti-Spam§7 algorithm.",
"action-automatic-reportable" : "§7This action was preformed automatically \n§7by the §bSentinel Profanity Filter§7 algorithm!\n§8§o(Click to report false positive)",
"unicode-warn" : "§cDo not send non standard unicode in chat!",
"message-sent" : "§d§lMessage §8» §b[§fYou §e>§f %1$s§b] §7%2$s",
"message-received" : "§d§lMessage §8» §b[§f%1$s §e>§f You§b] §7%2$s",
"spy-message" : "§d§lSpy §8» §b§n%1$s§7 has messaged §b§n%2$s§7.",
"spy-message-hover" : "§8]==-- §d§lSocialSpy §8--==[\n§bSender: §f%1$S\n§bReceiver: §f%2$S\n§bMessage: §f%3$S",
"profanity-mute-warn" : "You have been auto muted for repeated violation of the profanity filter! §7§o(Hover for more info)",
"profanity-mute-notification" : "§b§n%1$s§7 has been auto-muted by the anti-swear! §8(§c%2$s§7/§4%3$s§8)",
"slur-mute-warn" : "§cYou have been insta-punished by the anti-slur! §7§o(Hover for more info)",
"slur-mute-notification" : "§b§n%1$s§7 has been insta-muted by the anti-swear! §8(§c%2$s§7/§4%3$s§8)",
"swear-block-warn" : "§cPlease do not swear in chat! Attempting to bypass this filter will result in a mute! §7§o(Hover for more info)",
"swear-block-notification" : "§b§n%1$s§7 has triggered the anti-swear! §8(§c%2$s§7/§4%3$s§8)",
"spam-notification" : "§b§n%1$s§7 might be spamming! §8(§c%2$s§7/§4%3$s§8)",
"spam-notification-hover" : "§8]==-- §d§lSentinel §8--==[\n§bPrevious: §f%1$s\n§bCurrent: §f%2$s\n§bSimilarity §f%3$s",
"spam-block-warn" : "Do not spam in chat! Please wait before sending another message.",
"spam-mute-warn" : "§cYou have been auto-punished for violating the anti-spam repetitively!",
"spam-mute-notification" : "§b§n%1$s§7 has been auto-muted by the anti spam! §8(§c%2$s§7/§4%3$s§8)",
"filter-notification-hover" : "§8]==-- §d§lSentinel §8--==[\n§bOriginal: §f%1$s\n§bSanitized: §f%2$s\n§8§o(Click to report false positive)",
"severity-notification-hover" : "§8]==-- §d§lSentinel §8--==[\n§bOriginal: §f%1$s\n§bSanitized: §f%2$s\n§bSeverity: §c%3$s\n§7§o(click to report false positive)"
}
}

View File

@@ -1,81 +0,0 @@
{ // Comment!
"plugin": {
"license": "beta", // Here is a comment!
"prefix": "§d§lSentinel §8» §7", // Here is another one!
"webhook": "https://discord.com/api/webhooks/id/token",
"lang": "en-us.json",
"trustedPlayers": [
"049460f7-21cb-42f5-8059-d42752bf406f"
],
"blockSpecific": true,
"preventNBT": true,
"preventCmdBlockPlace": true,
"preventCmdBlockUse": true,
"preventCmdBlockChange": true,
"preventCmdCartPlace": true,
"preventCmdCartUse": true,
"cmdBlockOpCheck": true,
"dangerous": [
"op",
"deop",
"stop",
"restart",
"execute",
"sudo",
"esudo",
"fill",
"setblock",
"data",
"whitelist"
],
"logDangerous": true,
"logCmdBlocks": true,
"logNBT": true,
"logSpecific": false,
"logged": [
"give",
"item"
],
"deop": true,
"nbtPunish": false,
"cmdBlockPunish": false,
"commandPunish": false,
"specificPunish": false,
"punishCommands": [
"smite %player%",
"ban %player% ]\u003d- Sentinel -\u003d[ You have been banned for attempting a dangerous action. If you believe this to be a mistake, please contact the server owner."
],
"reopCommand": false
},
"chat": {
"antiSwear": {
"antiSwearEnabled": true,
"lowScore": 0,
"mediumLowScore": 1,
"mediumScore": 3,
"mediumHighScore": 5,
"highScore": 7,
"scoreDecay": 3,
"punishScore": 20,
"strictInstaPunish": true,
"swearPunishCommand": "mute %player% 15m Do not attempt to bypass the Profanity Filter",
"strictPunishCommand": "mute %player% 1h Discriminatory speech is not tolerated on this server!",
"logSwears": true
},
"antiSpam": {
"antiSpamEnabled": true,
"defaultGain": 1,
"lowGain": 2,
"mediumGain": 4,
"highGain": 6,
"heatDecay": 1,
"blockHeat": 10,
"punishHeat": 25,
"clearChat": true,
"chatClearCommand": "cc",
"spamPunishCommand": "mute %player% 1m Please refrain from spamming!",
"logSpam": true
},
"antiUnicode": true
}
}