worked on command block whitelist

This commit is contained in:
TheTrouper
2024-02-19 16:30:21 -06:00
parent 449740cd91
commit f6dc9e3629
205 changed files with 2776 additions and 287 deletions

View File

@@ -46,6 +46,7 @@ public final class Sentinel extends JavaPlugin {
public static String serverID;
public static String license;
public static String IP;
public static boolean doNoPlugins = false;
/**
* Plugin startup logic
@@ -55,33 +56,44 @@ public final class Sentinel extends JavaPlugin {
log.info("\n]======------ Pre-load started! ------======[");
PDK.init(this);
protocolManager = ProtocolLibrary.getProtocolManager();
instance = this;
log.info("Loading Config...");
loadConfig();
log.info("Language Status: (" + language.get("if-you-see-this-lang-is-broken") + ")");
log.info("Loading ProtocolLib");
if (Bukkit.getServer().getPluginManager().isPluginEnabled("ProtocolLib") && mainConfig.plugin.pluginHider) {
doNoPlugins = true;
protocolManager = ProtocolLibrary.getProtocolManager();
} else {
doNoPlugins = false;
log.warning("Sentinel: ProtocolLib not found. Sentinel will not attempt to hide your plugins.");
}
log.info("Language Status: (%s)".formatted(language.get("if-you-see-this-lang-is-broken")));
log.info("Initializing Server ID...");
serverID = Authenticator.getServerID();
license = mainConfig.plugin.license;
log.info("Pre-load finished!\n]====---- Requesting Authentication ----====[ \n- License Key: " + license + " \n- Server ID: " + serverID);
log.info("Auth Requested...");
log.info("Pre-load finished!\n]====---- Requesting Authentication ----====[ \n- License Key: %s\n- Server ID: %s".formatted(license,serverID));
String authStatus = "ERROR";
String authstatus = "ERROR";
try {
/*try {
authStatus = Authenticator.authorize(license, serverID);
authstatus = Auth.authorize(license, serverID);
IP = Authenticator.getPublicIPAddress();
log.info("Auth Requested...");
} catch (Exception e) {
e.printStackTrace();
log.info("WTFFFF ARE YOU DOING MAN??????");
manager.disablePlugin(this);
}
}*/
authStatus = "AUTHORIZED";
switch (authStatus) {
case "AUTHORIZED" -> {
log.info("\n]======----- Auth Success! -----======[");
@@ -106,15 +118,15 @@ public final class Sentinel extends JavaPlugin {
manager.disablePlugin(this);
}
case "UNREGISTERED" -> {
log.warning("Authentication Failure, YOU SHALL NOT PASS! License: " + license + " Server ID: " + serverID);
log.warning("Authentication Failure, YOU SHALL NOT PASS! License: %s Server ID: %s".formatted(license,serverID));
manager.disablePlugin(this);
}
case "ERROR" -> {
log.warning("Hmmmmmm thats not right... License: " + license + " Server ID: " + serverID + "\nPlease report the above stacktrace.");
log.warning("Hmmmmmm thats not right... License: %s Server ID: %s\nPlease report the above stacktrace.".formatted(license,serverID));
manager.disablePlugin(this);
}
default -> {
log.warning("Achievement unlocked:\n How did we get here? \nLicense: " + license + " Server ID: " + serverID + "\nPlease report the above stacktrace.");
log.warning("Achievement unlocked: How did we get here? License: %s Server ID: %s\nPlease report the above stacktrace.".formatted(license,serverID));
manager.disablePlugin(this);
}
}
@@ -124,7 +136,7 @@ public final class Sentinel extends JavaPlugin {
log.info("\n]======----- Loading Sentinel! -----======[");
// Plugin startup logic
log.info("Starting Up! (" + getDescription().getVersion() + ")...");
log.info("Starting Up! (%s)...".formatted(getDescription().getVersion()));
// Enable Functions
AntiSpam.enableAntiSpam();
@@ -137,7 +149,6 @@ public final class Sentinel extends JavaPlugin {
new ReopCommand().register();
new SocialSpyCommand().register();
new ChatClickCallback().register();
new TrapCommand().register();
// Events
new ChatEvent().register();
@@ -148,10 +159,12 @@ public final class Sentinel extends JavaPlugin {
new CMDMinecartPlace().register();
new CMDMinecartUse().register();
new NBTEvents().register();
new PluginHiderEvents().register();
new MiscEvents().register();
TabCompleteEvent.registerEvent(this);
if (doNoPlugins) {
new TrapCommand().register();
new PluginHiderEvents().register();
TabCompleteEvent.registerEvent(this);
}
// Scheduled timers
Bukkit.getScheduler().runTaskTimer(this, AntiSpam::decayHeat,0, 20);
@@ -190,7 +203,7 @@ public final class Sentinel extends JavaPlugin {
whitelist = JsonSerializable.load(cmdWhitelist, WhitelistStorage.class, new WhitelistStorage());
whitelist.save();
log.info("Loading Dictionary (" + Sentinel.mainConfig.plugin.lang + ")...");
log.info("Loading Dictionary (%s)...".formatted(Sentinel.mainConfig.plugin.lang));
language = JsonSerializable.load(LanguageFile.PATH,LanguageFile.class,new LanguageFile());
language.save();
@@ -203,7 +216,7 @@ public final class Sentinel extends JavaPlugin {
@Override
public void onDisable() {
// Plugin shutdown logic
log.info("Sentinel has disabled! (" + getDescription().getVersion() + ") Your server is now no longer protected!");
log.info("Sentinel has disabled! (%s) Your server is now no longer protected!".formatted(getDescription().getVersion()));
if (usesDynamicIP) {
Telemetry.sendShutdownLog();
}

View File

@@ -14,7 +14,7 @@ public class ReopCommand implements CustomCommand {
@Override
public void dispatchCommand(CommandSender sender, Args args) {
Player p = (Player) sender;
if (Sentinel.isTrusted(p)) {
if (Sentinel.isTrusted(p) && Sentinel.mainConfig.plugin.reopCommand) {
if (!p.isOp()) {
p.sendMessage(Text.prefix(Sentinel.language.get("elevating-perms")));
Sentinel.log.info(Sentinel.language.get("log-elevating-perms").formatted(p.getName()));

View File

@@ -5,6 +5,8 @@ import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import io.github.itzispyder.pdk.utils.ArrayUtils;
import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.config.AdvancedConfig;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
@@ -13,7 +15,7 @@ import java.util.List;
@CommandRegistry(value = "sentineltab")
public class TrapCommand implements CustomCommand {
private ArrayList<String> fakePlugins = new ArrayList<>();
private final List<String> fakePlugins = Sentinel.advConfig.fakePlugins;
@Override
public void dispatchCommand(CommandSender commandSender, Args args) {
@@ -21,26 +23,6 @@ public class TrapCommand implements CustomCommand {
@Override
public void dispatchCompletions(CompletionBuilder b) {
fakePlugins.clear();
fakePlugins.add("This server wishes to keep their plugins confidential. Anyways, Enjoy your meteor client! If the owner is incompetent, then .server plugins MassScan should still work ;)");
fakePlugins.add("NoCheatPlus");
fakePlugins.add("Negativity");
fakePlugins.add("Warden");
fakePlugins.add("Horizon");
fakePlugins.add("Illegalstack");
fakePlugins.add("CoreProtect");
fakePlugins.add("ExploitsX");
fakePlugins.add("Vulcan (Outdated version frfr)");
fakePlugins.add("ABC");
fakePlugins.add("Spartan");
fakePlugins.add("Kauri");
fakePlugins.add("AnticheatReloaded");
fakePlugins.add("WitherAC");
fakePlugins.add("GodsEye");
fakePlugins.add("Matrix");
fakePlugins.add("Wraith");
fakePlugins.add("AntiXrayHeuristics");
fakePlugins.add("GrimAC");
b.then(b.arg(fakePlugins));
}
}

View File

@@ -10,8 +10,8 @@ public enum ActionType {
UPDATE_COMMAND_BLOCK("HoneyPot log","Caught a command block command!", 0xF8FF00),
PLACE_MINECART_COMMAND("Anti-Nuke has been triggered","The placing of a minecart command has been detected!", 0xFF0000),
USE_MINECART_COMMAND("Anti-Nuke has been triggered", "The use of a command block has been detected!", 0xFF0000),
UPDATE_MINECART_COMMAND("HoneyPot log","Caught a command minecart command!", 0xFFB000),
COMMAND_BLOCK_EXECUTE("Command Block log","Caught an invalid command block!", 0xFFB000);
UPDATE_MINECART_COMMAND("HoneyPot has been triggered","Caught a command minecart command!", 0xFFB000),
COMMAND_BLOCK_EXECUTE("Command block whitelist has been triggered","Caught an invalid command block.", 0xFFB000);
private final String messageTop;
private final String messageTitle;
private final int embedColor;

View File

@@ -3,8 +3,7 @@ package io.github.thetrouper.sentinel.data.config;
import io.github.itzispyder.pdk.utils.misc.JsonSerializable;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
public class AdvancedConfig implements JsonSerializable<AdvancedConfig> {
@@ -14,6 +13,29 @@ public class AdvancedConfig implements JsonSerializable<AdvancedConfig> {
file.getParentFile().mkdirs();
return file;
}
public List<String> fakePlugins = Arrays.asList(
"This server wishes to keep their plugins confidential. Anyways, Enjoy your meteor client! If the owner is incompetent, then .server plugins MassScan should still work ;)",
"NoCheatPlus",
"Negativity",
"Warden",
"Horizon",
"Illegalstack",
"CoreProtect",
"ExploitsX",
"Vulcan (Outdated version frfr)",
"ABC",
"Spartan",
"Kauri",
"AnticheatReloaded",
"WitherAC",
"GodsEye",
"Matrix",
"Wraith",
"AntiXrayHeuristics",
"GrimAC"
);
public String[] versionAliases = {"version", "ver", "about", "bukkit:version", "bukkit:ver", "bukkit:about", "?", "bukkit:?","pl","bukkit:pl","plugins","bukkit:plugins","bukkit:help"};
public Map<String, String> leetPatterns = new HashMap<>() {{
put("0", "o");

View File

@@ -31,6 +31,7 @@ public class MainConfig implements JsonSerializable<MainConfig> {
public boolean preventCmdBlockUse = true;
public boolean preventCmdBlockChange = true;
public boolean cmdBlockWhitelist = false;
public boolean deleteUnauthorizedCmdBlocks = false;
public boolean logUnauthorizedCmdBlocks = false;
public boolean preventCmdCartPlace = true;
public boolean preventCmdCartUse = true;
@@ -66,11 +67,15 @@ public class MainConfig implements JsonSerializable<MainConfig> {
add("ban %player% ]=- Sentinel -=[ You have been banned for attempting a dangerous action. If you believe this to be a mistake, please contact the server owner.");
}};
public boolean reopCommand = false;
public boolean pluginHider = true;
}
public class Chat {
public AntiSwear antiSwear = new AntiSwear();
public AntiSpam antiSpam = new AntiSpam();
public boolean blockURLs = false;
public boolean useSwearRegex = false;
public boolean useStrictRegex = false;
public boolean antiUnicode = true;
public class AntiSpam {
@@ -96,7 +101,6 @@ public class MainConfig implements JsonSerializable<MainConfig> {
public int highScore = 7;
public int scoreDecay = 3;
public int punishScore = 20;
public boolean strictInstaPunish = true;
public String swearPunishCommand = "mute %player% 15m Do not attempt to bypass the Profanity Filter";
public String strictPunishCommand = "mute %player% 1h Discriminatory speech is not tolerated on this server!";
public boolean logSwears = true;

View File

@@ -5,6 +5,8 @@ import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.ActionType;
import io.github.thetrouper.sentinel.server.Action;
import io.github.thetrouper.sentinel.server.functions.CMDBlockWhitelist;
import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.event.EventHandler;
@@ -14,10 +16,14 @@ public class CMDBlockExecute implements CustomListener {
@EventHandler
private void onCommandBlock(ServerCommandEvent e) {
ServerUtils.sendDebugMessage("Handling command block event: " + e.getCommand());
if (!Sentinel.mainConfig.plugin.cmdBlockWhitelist) return;
ServerUtils.sendDebugMessage("Whitelist not disabled ");
if (!(e.getSender() instanceof BlockCommandSender s)) return;
ServerUtils.sendDebugMessage("Sender is command block");
Block cmdBlock = s.getBlock();
if (CMDBlockWhitelist.canRun(cmdBlock)) return;
ServerUtils.sendDebugMessage("Command block cant run.");
Action a = new Action.Builder()
.setEvent(e)
.setAction(ActionType.COMMAND_BLOCK_EXECUTE)
@@ -26,8 +32,8 @@ public class CMDBlockExecute implements CustomListener {
.setNotifyDiscord(Sentinel.mainConfig.plugin.logUnauthorizedCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.setDenied(true)
.setLoggedCommand(e.getCommand())
.execute();
if (Sentinel.mainConfig.plugin.deleteUnauthorizedCmdBlocks) cmdBlock.setType(Material.AIR);
}
}

View File

@@ -20,25 +20,23 @@ public class CMDBlockPlace implements CustomListener {
if (Sentinel.mainConfig.plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("CommandBlockPlace: Player is operator");
Block b = e.getBlockPlaced();
if (b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK ) {
ServerUtils.sendDebugMessage("CommandBlockPlace: Block is a command block");
Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("CommandBlockPlace: Not trusted, preforming action");
e.setCancelled(true);
Action a = new Action.Builder()
.setAction(ActionType.PLACE_COMMAND_BLOCK)
.setEvent(e)
.setBlock(b)
.setPlayer(p)
.setDenied(true)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();
}
}
if ((b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK)) return;
ServerUtils.sendDebugMessage("CommandBlockPlace: Block is a command block");
Player p = e.getPlayer();
if (Sentinel.isTrusted(p)) return;
ServerUtils.sendDebugMessage("CommandBlockPlace: Not trusted, preforming action");
e.setCancelled(true);
Action a = new Action.Builder()
.setAction(ActionType.PLACE_COMMAND_BLOCK)
.setEvent(e)
.setBlock(b)
.setPlayer(p)
.setDenied(true)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();
}
}

View File

@@ -25,58 +25,53 @@ public class CMDBlockUse implements CustomListener {
if (e.getClickedBlock() == null) return;
ServerUtils.sendDebugMessage("CommandBlockUse: Block isn't null");
Block b = e.getClickedBlock();
if (b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK) {
ServerUtils.sendDebugMessage("CommandBlockUse: Block is a command block");
Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("CommandBlockUse: Not trusted, preforming action");
e.setCancelled(true);
Action a = new Action.Builder()
.setAction(ActionType.USE_COMMAND_BLOCK)
.setEvent(e)
.setBlock(b)
.setPlayer(p)
.setDenied(true)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();
}
}
if (!(b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK)) return;
ServerUtils.sendDebugMessage("CommandBlockUse: Block is a command block");
Player p = e.getPlayer();
if (Sentinel.isTrusted(p)) return;
ServerUtils.sendDebugMessage("CommandBlockUse: Not trusted, preforming action");
e.setCancelled(true);
Action a = new Action.Builder()
.setAction(ActionType.USE_COMMAND_BLOCK)
.setEvent(e)
.setBlock(b)
.setPlayer(p)
.setDenied(true)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();
}
@EventHandler
private void onCMDBlockChange(EntityChangeBlockEvent e) {
ServerUtils.sendDebugMessage("CommandBlockChange: Detected change block");
if (!(e.getEntity() instanceof Player p)) return;
ServerUtils.sendDebugMessage("CommandBlockChange: Changer is a player");
if (!Sentinel.mainConfig.plugin.preventCmdBlockUse) return;
if (!Sentinel.mainConfig.plugin.preventCmdBlockChange) return;
ServerUtils.sendDebugMessage("CommandBlockChange: Enabled");
if (Sentinel.mainConfig.plugin.cmdBlockOpCheck && !p.isOp()) return;
ServerUtils.sendDebugMessage("CommandBlockChange: Player is op");
Block b = e.getBlock();
if (b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK) {
ServerUtils.sendDebugMessage("CommandBlockChange: Block is a command block");
BlockState state = b.getState();
CommandBlock cb = (CommandBlock) state;
if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("CommandBlockChange: Not trusted, preforming action");
e.setCancelled(true);
Action a = new Action.Builder()
.setAction(ActionType.UPDATE_COMMAND_BLOCK)
.setEvent(e)
.setBlock(b)
.setCommand(cb.getCommand())
.setPlayer(p)
.setDenied(true)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();
}
}
if (!(b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK)) return; ServerUtils.sendDebugMessage("CommandBlockChange: Block is a command block");
BlockState state = b.getState();
CommandBlock cb = (CommandBlock) state;
if (Sentinel.isTrusted(p)) return;
ServerUtils.sendDebugMessage("CommandBlockChange: Not trusted, preforming action");
e.setCancelled(true);
Action a = new Action.Builder()
.setAction(ActionType.UPDATE_COMMAND_BLOCK)
.setEvent(e)
.setBlock(b)
.setCommand(cb.getCommand())
.setPlayer(p)
.setDenied(true)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();
}
}

View File

@@ -15,37 +15,34 @@ public class CMDMinecartPlace implements CustomListener {
@EventHandler
private void onCMDMinecartPlace(PlayerInteractEvent e) {
ServerUtils.sendDebugMessage("MinecartCommandPlace: Detected interaction");
if (Sentinel.mainConfig.plugin.preventCmdCartPlace) {
ServerUtils.sendDebugMessage("MinecartCommandPlace: Enabled");
if (Sentinel.mainConfig.plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Player is op");
if (e.getItem() == null) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Item isn't null");
if (e.getClickedBlock() == null) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Clicked block isn't null");
if (!e.getItem().getType().equals(Material.COMMAND_BLOCK_MINECART)) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Item is a minecart command");
if (e.getClickedBlock().getType() == Material.RAIL || e.getClickedBlock().getType() == Material.POWERED_RAIL || e.getClickedBlock().getType() == Material.ACTIVATOR_RAIL || e.getClickedBlock().getType() == Material.DETECTOR_RAIL) {
ServerUtils.sendDebugMessage("MinecartCommandPlace: Clicked block is a rail");
Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("MinecartCommandPlace: Not trusted, preforming action");
e.setCancelled(true);
p.getInventory().remove(Material.COMMAND_BLOCK_MINECART);
Action a = new Action.Builder()
.setAction(ActionType.PLACE_MINECART_COMMAND)
.setEvent(e)
.setPlayer(p)
.setBlock(e.getClickedBlock())
.setDenied(Sentinel.mainConfig.plugin.preventCmdCartPlace)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setNotifyConsole(true)
.setNotifyTrusted(true)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.execute();
}
}
}
if (!Sentinel.mainConfig.plugin.preventCmdCartPlace) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Enabled");
if (Sentinel.mainConfig.plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Player is op");
if (e.getItem() == null) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Item isn't null");
if (e.getClickedBlock() == null) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Clicked block isn't null");
if (!e.getItem().getType().equals(Material.COMMAND_BLOCK_MINECART)) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Item is a minecart command");
if (!(e.getClickedBlock().getType() == Material.RAIL || e.getClickedBlock().getType() == Material.POWERED_RAIL || e.getClickedBlock().getType() == Material.ACTIVATOR_RAIL || e.getClickedBlock().getType() == Material.DETECTOR_RAIL)) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Clicked block is a rail");
Player p = e.getPlayer();
if (Sentinel.isTrusted(p)) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Not trusted, preforming action");
e.setCancelled(true);
p.getInventory().remove(Material.COMMAND_BLOCK_MINECART);
Action a = new Action.Builder()
.setAction(ActionType.PLACE_MINECART_COMMAND)
.setEvent(e)
.setPlayer(p)
.setBlock(e.getClickedBlock())
.setDenied(Sentinel.mainConfig.plugin.preventCmdCartPlace)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setNotifyConsole(true)
.setNotifyTrusted(true)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.execute();
}
}

View File

@@ -18,24 +18,22 @@ public class CMDMinecartUse implements CustomListener {
ServerUtils.sendDebugMessage("MinecartCommandUse: Enabled");
if (Sentinel.mainConfig.plugin.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("MinecartCommandUse: Player op");
if (e.getRightClicked().getType() == EntityType.MINECART_COMMAND) {
ServerUtils.sendDebugMessage("MinecartCommandUse: Entity is minecart command");
Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("MinecartCommandUse: Not trusted, preforming action");
e.setCancelled(true);
Action a = new Action.Builder()
.setAction(ActionType.USE_MINECART_COMMAND)
.setEvent(e)
.setPlayer(p)
.setDenied(true)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();
}
}
if (e.getRightClicked().getType() != EntityType.MINECART_COMMAND) return;
ServerUtils.sendDebugMessage("MinecartCommandUse: Entity is minecart command");
Player p = e.getPlayer();
if (Sentinel.isTrusted(p)) return;
ServerUtils.sendDebugMessage("MinecartCommandUse: Not trusted, preforming action");
e.setCancelled(true);
Action a = new Action.Builder()
.setAction(ActionType.USE_MINECART_COMMAND)
.setEvent(e)
.setPlayer(p)
.setDenied(true)
.setPunished(Sentinel.mainConfig.plugin.cmdBlockPunish)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logCmdBlocks)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setNotifyTrusted(true)
.setNotifyConsole(true)
.execute();
}
}

View File

@@ -8,8 +8,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
public class MiscEvents implements CustomListener {
@EventHandler
private void onJoin(PlayerJoinEvent e) {
if (e.getPlayer().getUniqueId().toString().equals("049460f7-21cb-42f5-8059-d42752bf406f")) {
e.getPlayer().sendMessage(Text.prefix("Welcome, obvWolf. This server uses Sentinel."));
}
if (!e.getPlayer().getUniqueId().toString().equals("049460f7-21cb-42f5-8059-d42752bf406f")) return;
e.getPlayer().sendMessage(Text.prefix("Welcome, obvWolf. This server uses Sentinel."));
}
}

View File

@@ -35,25 +35,23 @@ public class NBTEvents implements CustomListener {
ServerUtils.sendDebugMessage("NBT: Not trusted");
if (e.getCursor().getItemMeta() == null) return;
ServerUtils.sendDebugMessage("NBT: Cursor has meta");
if (i.hasItemMeta() && i.getItemMeta() != null) {
ServerUtils.sendDebugMessage("NBT: Item has meta");
if (!itemPasses(i)) {
ServerUtils.sendDebugMessage("NBT: Item doesn't pass, preforming action");
Action a = new Action.Builder()
.setEvent(e)
.setAction(ActionType.NBT)
.setPlayer(Bukkit.getPlayer(e.getWhoClicked().getName()))
.setItem(e.getCursor())
.setDenied(Sentinel.mainConfig.plugin.preventNBT)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setPunished(Sentinel.mainConfig.plugin.nbtPunish)
.setRevertGM(Sentinel.mainConfig.plugin.preventNBT)
.setNotifyConsole(true)
.setNotifyTrusted(true)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logNBT)
.execute();
}
}
if (!(i.hasItemMeta() && i.getItemMeta() != null)) return;
ServerUtils.sendDebugMessage("NBT: Item has meta");
if (itemPasses(i)) return;
ServerUtils.sendDebugMessage("NBT: Item doesn't pass, preforming action");
Action a = new Action.Builder()
.setEvent(e)
.setAction(ActionType.NBT)
.setPlayer(Bukkit.getPlayer(e.getWhoClicked().getName()))
.setItem(e.getCursor())
.setDenied(Sentinel.mainConfig.plugin.preventNBT)
.setDeoped(Sentinel.mainConfig.plugin.deop)
.setPunished(Sentinel.mainConfig.plugin.nbtPunish)
.setRevertGM(Sentinel.mainConfig.plugin.preventNBT)
.setNotifyConsole(true)
.setNotifyTrusted(true)
.setNotifyDiscord(Sentinel.mainConfig.plugin.logNBT)
.execute();
}
private boolean isContainer(ItemStack itemStack) {

View File

@@ -9,7 +9,7 @@ import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.plugin.Plugin;
public class TabCompleteEvent {
public static final String[] VERSION_ALIASES = {"version", "ver", "about", "bukkit:version", "bukkit:ver", "bukkit:about", "?", "bukkit:?","pl","bukkit:pl","plugins","bukkit:plugins","bukkit:help"};
public static final String[] VERSION_ALIASES = Sentinel.advConfig.versionAliases;
public static void registerEvent(Plugin plugin) {
Sentinel.protocolManager.addPacketListener(new PacketAdapter(
plugin,

View File

@@ -32,6 +32,8 @@ public class FilterAction {
Player offender = e.getPlayer();
switch (type) {
case BLOCK_SPAM -> {
if (Sentinel.mainConfig.chat.antiSpam.clearChat) ServerUtils.sendCommand(Sentinel.mainConfig.chat.antiSpam.chatClearCommand);
staffNotif = Component
.text(Text.prefix(String.format(Sentinel.language.get("spam-notification"),
offender.getName(),
@@ -47,6 +49,7 @@ public class FilterAction {
playerWarning = Component.text(Text.prefix(Sentinel.language.get("spam-block-warn")));
}
case SPAM_PUNISH -> {
if (Sentinel.mainConfig.chat.antiSpam.clearChat) ServerUtils.sendCommand(Sentinel.mainConfig.chat.antiSpam.chatClearCommand);
staffNotif = Component.text(Text.prefix(String.format(Sentinel.language.get("spam-mute-notification"),
offender.getName(),
heatMap.get(offender),
@@ -60,7 +63,7 @@ public class FilterAction {
playerWarning = Component.text(Sentinel.language.get("spam-mute-warn"));
sendConsoleLog(offender,e,type);
sendDiscordLog(offender,e,type);
if (Sentinel.mainConfig.chat.antiSpam.logSpam) sendDiscordLog(offender,e,type);
}
case BLOCK_SWEAR -> {
staffNotif = Component.text(Text.prefix(String.format(Sentinel.language.get("profanity-block-notification"),
@@ -93,7 +96,7 @@ public class FilterAction {
playerWarning = Component.text(Text.prefix(Sentinel.language.get("profanity-mute-warn")))
.hoverEvent(Component.text(Sentinel.language.get("action-automatic-reportable")));
sendConsoleLog(offender,e,type);
sendDiscordLog(offender,e,type);
if (Sentinel.mainConfig.chat.antiSwear.logSwears) sendDiscordLog(offender,e,type);
}
case SLUR_PUNISH -> {
staffNotif = Component.text(Text.prefix(String.format(Sentinel.language.get("slur-mute-notification"),
@@ -110,7 +113,7 @@ public class FilterAction {
playerWarning = Component.text(Text.prefix(Sentinel.language.get("slur-mute-warn")))
.hoverEvent(Component.text(Sentinel.language.get("action-automatic-reportable")));
sendConsoleLog(offender,e,type);
sendDiscordLog(offender,e,type);
if (Sentinel.mainConfig.chat.antiSwear.logSwears) sendDiscordLog(offender,e,type);
}
}
if (type.getExecutedCommand() != null) {
@@ -124,55 +127,6 @@ public class FilterAction {
e.getPlayer().sendMessage(playerWarning);
}
/*public static void filterAction(Player offender, AsyncPlayerChatEvent e, String highlighted, FilterSeverity severity, Double similarity, FAT type) {
String report = ReportFalsePositives.generateReport(e);
DecimalFormat fs = new DecimalFormat("##.#");
fs.setRoundingMode(RoundingMode.DOWN);
TextComponent warn = createTextComponent(Text.prefix(Sentinel.language.get(type.getWarnTranslationKey())));
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));
TextComponent notif = createTextComponent(Text.prefix((type != FAT.SPAM_PUNISH && type != FAT.BLOCK_SPAM ?
Sentinel.language.get("severity-notification-hover").formatted(e.getMessage(), highlighted, severity.name().toLowerCase().replace("_"," ")) :
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.language.get("severity-notification-hover"))));
notif.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
sendMessages(offender, warn, notif, type);
if (shouldLogSwears(type)) {
sendDiscordLog(offender, e, type);
sendConsoleLog(offender, e, type);
}
}
private static void sendMessages(Player offender, TextComponent warn, TextComponent notif, FAT type) {
offender.spigot().sendMessage(warn);
String notifText = Sentinel.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))));
ServerUtils.forEachStaff(staffmember -> staffmember.spigot().sendMessage(notif));
if (type.getExecutedCommand() != null) {
ServerUtils.sendCommand(type.getExecutedCommand().replace("%player%", offender.getName()));
}
}
private static TextComponent createTextComponent(String text) {
TextComponent component = new TextComponent();
component.setText(text);
return component;
}*/
private static boolean shouldLogSwears(FAT type) {
return (type == FAT.SWEAR_PUNISH || type == FAT.SLUR_PUNISH) && Sentinel.mainConfig.chat.antiSwear.logSwears
|| (type == FAT.SPAM_PUNISH && Sentinel.mainConfig.chat.antiSpam.logSpam);
}
public static void sendConsoleLog(Player offender, AsyncPlayerChatEvent e, FAT type) {
StringBuilder log = new StringBuilder().append(String.format("]=- %s -=[",type.getTitle()));
log.append(String.format("\nPlayer: %s",offender.getName()));
@@ -269,51 +223,4 @@ public class FilterAction {
}
/*
public static void filterAction(Player offender, AsyncPlayerChatEvent e, String highlighted, String severity, Double similarity, FAT type) {
String report = ReportFalsePositives.generateReport(e);
TextComponent warn = new TextComponent();
warn.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(Sentinel.language.get("action-automatic-reportable"))));
warn.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/sentinelcallback fpreport " + report));
DecimalFormat fs = new DecimalFormat("##.#");
fs.setRoundingMode(RoundingMode.DOWN);
TextComponent notif = new TextComponent();
notif.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText((type != FAT.SPAM_PUNISH && type != FAT.BLOCK_SPAM ? Sentinel.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));
warn.setText(Text.prefix(Sentinel.language.get(type.getWarnTranslationKey())));
offender.spigot().sendMessage(warn);
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))));
ServerUtils.forEachStaff(staffmember -> {
staffmember.spigot().sendMessage(notif);
});
if (type.getExecutedCommand() != null) {
ServerUtils.sendCommand(type.getExecutedCommand().replace("%player%", offender.getName()));
}
if (type == FAT.SWEAR_PUNISH && Sentinel.mainConfig.chat.antiSwear.logSwears) {
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
}
if (type == FAT.SLUR_PUNISH && Sentinel.mainConfig.chat.antiSwear.logSwears) {
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
}
if (type == FAT.SPAM_PUNISH && Sentinel.mainConfig.chat.antiSpam.logSpam) {
sendDiscordLog(offender,e,type);
sendConsoleLog(offender,e,type);
}
}*/
}

View File

@@ -14,10 +14,11 @@ import java.util.regex.Pattern;
public class AdvancedBlockers {
public static void handleAdvanced(AsyncPlayerChatEvent e) {
if (!Sentinel.advConfig.allowedCharRegex.isBlank()) handleAntiUnicode(e);
if (!Sentinel.advConfig.urlRegex.isBlank()) handleAntiURL(e);
if (!Sentinel.advConfig.strictRegex.isBlank()) handleStrictRegex(e);
if (!Sentinel.advConfig.swearRegex.isBlank()) handleSwearRegex(e);
if (Sentinel.isTrusted(e.getPlayer())) return;
if (Sentinel.mainConfig.chat.antiUnicode) handleAntiUnicode(e);
if (Sentinel.mainConfig.chat.blockURLs) handleAntiURL(e);
if (Sentinel.mainConfig.chat.useStrictRegex) handleStrictRegex(e);
if (Sentinel.mainConfig.chat.useSwearRegex) handleSwearRegex(e);
}
public static void handleAntiUnicode(AsyncPlayerChatEvent e) {
String message = Text.removeFirstColor(e.getMessage());

View File

@@ -51,6 +51,8 @@ public class AntiSpam {
}
}
lastMessageMap.put(p, message);
if (heatMap.get(p) > Sentinel.mainConfig.chat.antiSpam.punishHeat) {
e.setCancelled(true);
FilterAction.filterPunish(e,FAT.SPAM_PUNISH,GPTUtils.calcSim(e.getMessage(),lastMessageMap.get(p)), null);
@@ -63,7 +65,8 @@ public class AntiSpam {
heatMap.put(p, heatMap.get(p) + Sentinel.mainConfig.chat.antiSpam.highGain);
return;
}
lastMessageMap.put(p, message);
heatMap.put(p,heatMap.get(p) + Sentinel.mainConfig.chat.antiSpam.defaultGain);
}
public static void decayHeat() {
for (Player p : heatMap.keySet()) {

View File

@@ -1,5 +1,6 @@
package io.github.thetrouper.sentinel.server.util;
import io.github.itzispyder.pdk.utils.FileValidationUtils;
import io.github.thetrouper.sentinel.Sentinel;
import org.bukkit.inventory.ItemStack;
@@ -75,9 +76,12 @@ public class FileUtils {
return fileName;
}
public static String createCommandLog(String command) {
String fileName = "command_log-" + Randomizer.generateID();
File file = new File(Sentinel.getInstance().getDataFolder() + "/LoggedCommands/" + fileName + ".txt");
FileValidationUtils.validate(file);
try {
if (!file.exists()) {
file.createNewFile();
@@ -90,6 +94,7 @@ public class FileUtils {
} catch (IOException e) {
e.printStackTrace();
}
return fileName;
}
}

View File

@@ -5,8 +5,7 @@ api-version: 1.19
authors: [ TheTrouper ]
description: Detect Block and Ban players who attempt to grief your server.
website: https://thetrouper.github.io/
depend:
- ProtocolLib
softdepend: [ ProtocolLib ]
permissions:
sentinel.message:
description: Access to the direct messages