Fixed all (I hope) the bugs, and pushed update to BBB

(False Positive Report + Lang File)
This commit is contained in:
obvWolf
2023-10-22 21:30:36 -05:00
parent 3851fbf97a
commit 9e156d1147
15 changed files with 125 additions and 55 deletions

View File

@@ -180,40 +180,40 @@ public class Action {
if (notifyTrusted) { if (notifyTrusted) {
TextComponent notification = new TextComponent(); TextComponent notification = new TextComponent();
notification.setText(Text.prefix(" " + actionTop)); notification.setText(Text.prefix(" " + actionTop));
String body = "]=- Sentinel -=[ "; String body = "\u00a78]==-- \u00a7d\u00a7lSentinel\u00a78--==[ ";
body += "\n" + actionTitle + "\n"; body += "\n" + actionTitle + "\n";
if (player != null) { if (player != null) {
body += "Player: " + player.getName() + "\n"; body += "\u00a7bPlayer: \u00a77" + player.getName() + "\n";
} }
if (command != null) { if (command != null) {
if (loggedCommand != null) { if (loggedCommand != null) {
if (loggedCommand.length() > 64) { if (loggedCommand.length() > 64) {
body += "Command: Too long to show here!" + "\n"; body += "\u00a7bCommand: \u00a7cToo long to show here!" + "\n";
body += " | Saved to file: " + commandLog + "\n"; body += " \u00a78| \u00a7bSaved to file: \u00a7f" + commandLog + "\n";
} else { } else {
body += "Command: " + command + "\n"; body += "\u00a7bCommand: \u00a7f" + command + "\n";
} }
} else { } else {
body += "Command: " + command + "\n"; body += "\u00a7bCommand: \u00a7f" + command + "\n";
} }
} }
if (item != null) { if (item != null) {
body += "Item: /Sentinel/LoggedNBT/" + itemLog + "\n"; body += "\u00a7bItem: \u00a7f/Sentinel/LoggedNBT/" + itemLog + "\n";
} }
if (block != null) { if (block != null) {
Location loc = block.getLocation(); Location loc = block.getLocation();
body += "Block: " + block.getType().toString().toLowerCase().replace("_", " ") + "\n"; body += "\u00a7bBlock: \u00a7f" + block.getType().toString().toLowerCase().replace("_", " ") + "\n";
body += "Location: " + loc.getX() + " " + loc.getY() + " " + loc.getZ() + "\n"; body += "\u00a7bLocation: \u00a7f" + loc.getX() + " " + loc.getY() + " " + loc.getZ() + "\n";
} }
body += "Denied: " + (denied ? "\u00a7a\u2714" : "\u00a7c\u2718") + "\n"; body += "\u00a7bDenied: \u00a7f" + (denied ? "\u00a7a\u2714" : "\u00a7c\u2718") + "\n";
if (deoped) { if (deoped) {
player.setOp(false); player.setOp(false);
} }
body += "Deoped: " + (deoped ? "\u00a7a\u2714" : "\u00a7c\u2718") + "\n"; body += "\u00a7bDeoped: \u00a7f" + (deoped ? "\u00a7a\u2714" : "\u00a7c\u2718") + "\n";
body += "Punished: " + (punished ? "\u00a7a\u2714" : "\u00a7c\u2718") + "\n"; body += "\u00a7bPunished: \u00a7f" + (punished ? "\u00a7a\u2714" : "\u00a7c\u2718") + "\n";
if (revertGM) body += "RevertGM: " + "\u00a7a\u2714" + "\n"; if (revertGM) body += "\u00a7bRevertGM: \u00a7f" + "\u00a7a\u2714" + "\n";
body += "Logged: " + (notifyDiscord ? "\u00a7a\u2714" : "\u00a7c\u2718"); body += "\u00a7bLogged: \u00a7f" + (notifyDiscord ? "\u00a7a\u2714" : "\u00a7c\u2718");
notification.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new net.md_5.bungee.api.chat.hover.content.Text(body))); notification.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new net.md_5.bungee.api.chat.hover.content.Text(body)));
ServerUtils.forEachPlayer(trusted -> { ServerUtils.forEachPlayer(trusted -> {
if (Sentinel.isTrusted(trusted)) { if (Sentinel.isTrusted(trusted)) {

View File

@@ -3,8 +3,6 @@ package io.github.thetrouper.sentinel.data;
import java.awt.*; import java.awt.*;
public enum FAT { public enum FAT {
// I couldn't miss the opportunity to call the "Filter Action Type" FAT
// Its rly just to make the tab completion of FilterAction easier
BLOCK_SWEAR("Sentinel Profanity Filter",null,"swear-block-warn", "swear-block-notification", null,null), BLOCK_SWEAR("Sentinel Profanity Filter",null,"swear-block-warn", "swear-block-notification", null,null),
BLOCK_SPAM("Sentinel Anti-Spam", null, "spam-block-warn", "spam-notification",null,null), BLOCK_SPAM("Sentinel Anti-Spam", null, "spam-block-warn", "spam-notification",null,null),
SWEAR("Sentinel Anti-Swear Log","Anti-Swear", "profanity-mute-warn", "profanity-mute-notification", Config.swearPunishCommand, Color.orange), SWEAR("Sentinel Anti-Swear Log","Anti-Swear", "profanity-mute-warn", "profanity-mute-notification", Config.swearPunishCommand, Color.orange),

View File

@@ -44,6 +44,7 @@ public class FilterAction {
String notiftext = Sentinel.dict.get(type.getNotifTranslationKey()); String notiftext = Sentinel.dict.get(type.getNotifTranslationKey());
notif.setText(Text.prefix((type != FAT.SPAM && type != FAT.BLOCK_SPAM ? notiftext.formatted(offender.getName(), scoreMap.get(offender), Config.punishScore) : notiftext.formatted(offender.getName(),heatMap.get(offender),Config.punishHeat)))); notif.setText(Text.prefix((type != FAT.SPAM && type != FAT.BLOCK_SPAM ? notiftext.formatted(offender.getName(), scoreMap.get(offender), Config.punishScore) : notiftext.formatted(offender.getName(),heatMap.get(offender),Config.punishHeat))));
ServerUtils.forEachStaff(staffmember -> { ServerUtils.forEachStaff(staffmember -> {
staffmember.spigot().sendMessage(notif); staffmember.spigot().sendMessage(notif);
}); });
@@ -80,7 +81,6 @@ public class FilterAction {
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() + "!";
Color color = Color.white;
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(Config.webhook); DiscordWebhook webhook = new DiscordWebhook(Config.webhook);
@@ -91,14 +91,14 @@ public class FilterAction {
.setAuthor(supertitle, "", "") .setAuthor(supertitle, "", "")
.setTitle(title) .setTitle(title)
.setDescription( .setDescription(
Emojis.rightSort + "Player: " + offender.getName() + " " + Emojis.target + "\n" + Emojis.rightSort + "Player: " + offender.getName() + " " + Emojis.target + "\\n" +
Emojis.space + Emojis.arrowRight + (type != FAT.BLOCK_SPAM ? "Score: `" + scoreMap.get(offender) + "/" + Config.punishScore : "Heat: `" + heatMap.get(offender) + "/" + Config.punishHeat) + "`\n" + Emojis.space + Emojis.arrowRight + (type != FAT.BLOCK_SPAM ? "Score: `" + scoreMap.get(offender) + "/" + Config.punishScore : "Heat: `" + heatMap.get(offender) + "/" + Config.punishHeat) + "`\\n" +
Emojis.space + Emojis.arrowRight + "UUID: `" + offender.getUniqueId() + "`\n" + Emojis.space + Emojis.arrowRight + "UUID: `" + offender.getUniqueId() + "`\\n" +
Emojis.rightSort + "Executed: " + executed + " " + Emojis.mute + "\n" Emojis.rightSort + "Executed: " + executed + " " + Emojis.mute + "\\n"
) )
.addField((type != FAT.BLOCK_SPAM ? "Message: " : "Previous: "), (type != FAT.BLOCK_SPAM ? e.getMessage() : lastMessageMap.get(offender)) + Emojis.alarm, false) .addField((type != FAT.BLOCK_SPAM && type != FAT.SPAM ? "Message: " : "Previous: "), (type != FAT.BLOCK_SPAM && type != FAT.SPAM ? e.getMessage() : lastMessageMap.get(offender)) + Emojis.alarm, false)
.addField((type != FAT.BLOCK_SPAM ? "Reduced: " : "Current: "), (type != FAT.BLOCK_SPAM ? highlightProfanity(e.getMessage(), "||", "||") : e.getMessage()) + " " + Emojis.noDM, false) .addField((type != FAT.BLOCK_SPAM && type != FAT.SPAM ? "Reduced: " : "Current: "), (type != FAT.BLOCK_SPAM && type != FAT.SPAM ? highlightProfanity(e.getMessage(), "||", "||") : e.getMessage()) + " " + Emojis.noDM, false)
.setColor(color) .setColor(type.getColor())
.setThumbnail("https://crafatar.com/avatars/" + offender.getUniqueId() + "?size=64&&overlay"); .setThumbnail("https://crafatar.com/avatars/" + offender.getUniqueId() + "?size=64&&overlay");
webhook.addEmbed(embed); webhook.addEmbed(embed);

View File

@@ -4,6 +4,7 @@ import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.Config; import io.github.thetrouper.sentinel.data.Config;
import io.github.thetrouper.sentinel.data.Action; import io.github.thetrouper.sentinel.data.Action;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
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;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -14,12 +15,17 @@ import org.bukkit.event.block.BlockPlaceEvent;
public class CMDBlockPlace implements Listener { public class CMDBlockPlace implements Listener {
@EventHandler @EventHandler
private void onCMDBlockPlace(BlockPlaceEvent e) { private void onCMDBlockPlace(BlockPlaceEvent e) {
ServerUtils.sendDebugMessage("CommandBlockPlace: Detected block place");
if (!Config.preventCmdBlockPlace) return; if (!Config.preventCmdBlockPlace) return;
ServerUtils.sendDebugMessage("CommandBlockPlace: Enabled");
if (Config.cmdBlockOpCheck && !e.getPlayer().isOp()) return; if (Config.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("CommandBlockPlace: Player is operator");
Block b = e.getBlockPlaced(); Block b = e.getBlockPlaced();
if (b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK ) { 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(); Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) { if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("CommandBlockPlace: Not trusted, preforming action");
e.setCancelled(true); e.setCancelled(true);
Action a = new Action.Builder() Action a = new Action.Builder()
.setAction(ActionType.PLACE_COMMAND_BLOCK) .setAction(ActionType.PLACE_COMMAND_BLOCK)

View File

@@ -4,6 +4,7 @@ import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.Config; import io.github.thetrouper.sentinel.data.Config;
import io.github.thetrouper.sentinel.data.Action; import io.github.thetrouper.sentinel.data.Action;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
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;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
@@ -17,13 +18,19 @@ import org.bukkit.event.player.PlayerInteractEvent;
public class CMDBlockUse implements Listener { public class CMDBlockUse implements Listener {
@EventHandler @EventHandler
private void onCMDBlockUse(PlayerInteractEvent e) { private void onCMDBlockUse(PlayerInteractEvent e) {
ServerUtils.sendDebugMessage("CommandBlockUse: Detected Interaction");
if (!Config.preventCmdBlockUse) return; if (!Config.preventCmdBlockUse) return;
ServerUtils.sendDebugMessage("CommandBlockUse: Enabled");
if (Config.cmdBlockOpCheck && !e.getPlayer().isOp()) return; if (Config.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("CommandBlockUse: Player is op");
if (e.getClickedBlock() == null) return; if (e.getClickedBlock() == null) return;
ServerUtils.sendDebugMessage("CommandBlockUse: Block isn't null");
Block b = e.getClickedBlock(); Block b = e.getClickedBlock();
if (b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK) { 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(); Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) { if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("CommandBlockUse: Not trusted, preforming action");
e.setCancelled(true); e.setCancelled(true);
Action a = new Action.Builder() Action a = new Action.Builder()
.setAction(ActionType.USE_COMMAND_BLOCK) .setAction(ActionType.USE_COMMAND_BLOCK)
@@ -32,6 +39,7 @@ public class CMDBlockUse implements Listener {
.setPlayer(p) .setPlayer(p)
.setDenied(true) .setDenied(true)
.setPunished(Config.cmdBlockPunish) .setPunished(Config.cmdBlockPunish)
.setDeoped(Config.deop)
.setnotifyDiscord(Config.logCmdBlocks) .setnotifyDiscord(Config.logCmdBlocks)
.setNotifyTrusted(true) .setNotifyTrusted(true)
.setNotifyConsole(true) .setNotifyConsole(true)
@@ -41,14 +49,20 @@ public class CMDBlockUse implements Listener {
} }
@EventHandler @EventHandler
private void onCMDBlockChange(EntityChangeBlockEvent e) { private void onCMDBlockChange(EntityChangeBlockEvent e) {
ServerUtils.sendDebugMessage("CommandBlockChange: Detected change block");
if (!(e.getEntity() instanceof Player p)) return; if (!(e.getEntity() instanceof Player p)) return;
ServerUtils.sendDebugMessage("CommandBlockChange: Changer is a player");
if (!Config.preventCmdBlockUse) return; if (!Config.preventCmdBlockUse) return;
ServerUtils.sendDebugMessage("CommandBlockChange: Enabled");
if (Config.cmdBlockOpCheck && !p.isOp()) return; if (Config.cmdBlockOpCheck && !p.isOp()) return;
ServerUtils.sendDebugMessage("CommandBlockChange: Player is op");
Block b = e.getBlock(); Block b = e.getBlock();
if (b.getType() == Material.COMMAND_BLOCK || b.getType() == Material.REPEATING_COMMAND_BLOCK || b.getType() == Material.CHAIN_COMMAND_BLOCK) { 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(); BlockState state = b.getState();
CommandBlock cb = (CommandBlock) state; CommandBlock cb = (CommandBlock) state;
if (!Sentinel.isTrusted(p)) { if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("CommandBlockChange: Not trusted, preforming action");
e.setCancelled(true); e.setCancelled(true);
Action a = new Action.Builder() Action a = new Action.Builder()
.setAction(ActionType.UPDATE_COMMAND_BLOCK) .setAction(ActionType.UPDATE_COMMAND_BLOCK)
@@ -58,6 +72,7 @@ public class CMDBlockUse implements Listener {
.setPlayer(p) .setPlayer(p)
.setDenied(true) .setDenied(true)
.setPunished(Config.cmdBlockPunish) .setPunished(Config.cmdBlockPunish)
.setDeoped(Config.deop)
.setnotifyDiscord(Config.logCmdBlocks) .setnotifyDiscord(Config.logCmdBlocks)
.setNotifyTrusted(true) .setNotifyTrusted(true)
.setNotifyConsole(true) .setNotifyConsole(true)

View File

@@ -4,6 +4,7 @@ import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.Config; import io.github.thetrouper.sentinel.data.Config;
import io.github.thetrouper.sentinel.data.Action; import io.github.thetrouper.sentinel.data.Action;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
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;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -14,14 +15,22 @@ public class CMDMinecartPlace implements Listener {
@EventHandler @EventHandler
private void onCMDMinecartPlace(PlayerInteractEvent e) { private void onCMDMinecartPlace(PlayerInteractEvent e) {
if (!Config.preventCmdCartPlace) { ServerUtils.sendDebugMessage("MinecartCommandPlace: Detected interaction");
if (Config.preventCmdCartPlace) {
ServerUtils.sendDebugMessage("MinecartCommandPlace: Enabled");
if (Config.cmdBlockOpCheck && !e.getPlayer().isOp()) return; if (Config.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Player is op");
if (e.getItem() == null) return; if (e.getItem() == null) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Item isn't null");
if (e.getClickedBlock() == null) return; if (e.getClickedBlock() == null) return;
ServerUtils.sendDebugMessage("MinecartCommandPlace: Clicked block isn't null");
if (!e.getItem().getType().equals(Material.COMMAND_BLOCK_MINECART)) return; 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) { 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(); Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) { if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("MinecartCommandPlace: Not trusted, preforming action");
e.setCancelled(true); e.setCancelled(true);
p.getInventory().remove(Material.COMMAND_BLOCK_MINECART); p.getInventory().remove(Material.COMMAND_BLOCK_MINECART);
Action a = new Action.Builder() Action a = new Action.Builder()

View File

@@ -4,6 +4,7 @@ import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.Config; import io.github.thetrouper.sentinel.data.Config;
import io.github.thetrouper.sentinel.data.Action; import io.github.thetrouper.sentinel.data.Action;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
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;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -13,11 +14,16 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
public class CMDMinecartUse implements Listener { public class CMDMinecartUse implements Listener {
@EventHandler @EventHandler
private void onCMDBlockMinecartUse(PlayerInteractEntityEvent e) { private void onCMDBlockMinecartUse(PlayerInteractEntityEvent e) {
ServerUtils.sendDebugMessage("MinecartCommandUse: Detected Interaction with entity");
if (!Config.preventCmdCartUse) return; if (!Config.preventCmdCartUse) return;
ServerUtils.sendDebugMessage("MinecartCommandUse: Enabled");
if (Config.cmdBlockOpCheck && !e.getPlayer().isOp()) return; if (Config.cmdBlockOpCheck && !e.getPlayer().isOp()) return;
ServerUtils.sendDebugMessage("MinecartCommandUse: Player op");
if (e.getRightClicked().getType() == EntityType.MINECART_COMMAND) { if (e.getRightClicked().getType() == EntityType.MINECART_COMMAND) {
ServerUtils.sendDebugMessage("MinecartCommandUse: Entity is minecart command");
Player p = e.getPlayer(); Player p = e.getPlayer();
if (!Sentinel.isTrusted(p)) { if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("MinecartCommandUse: Not trusted, preforming action");
e.setCancelled(true); e.setCancelled(true);
Action a = new Action.Builder() Action a = new Action.Builder()
.setAction(ActionType.USE_MINECART_COMMAND) .setAction(ActionType.USE_MINECART_COMMAND)

View File

@@ -17,6 +17,7 @@ public class CommandEvent implements Listener {
private void onCommand(PlayerCommandPreprocessEvent e) { private void onCommand(PlayerCommandPreprocessEvent e) {
Player p = e.getPlayer(); Player p = e.getPlayer();
String command = e.getMessage().substring(1).split(" ")[0]; String command = e.getMessage().substring(1).split(" ")[0];
String fullcommand = e.getMessage();
ServerUtils.sendDebugMessage("CommandEvent: Checking command"); ServerUtils.sendDebugMessage("CommandEvent: Checking command");
if (Sentinel.isDangerousCommand(command)) { if (Sentinel.isDangerousCommand(command)) {
ServerUtils.sendDebugMessage("CommandEvent: Command is dangerous"); ServerUtils.sendDebugMessage("CommandEvent: Command is dangerous");
@@ -27,7 +28,7 @@ public class CommandEvent implements Listener {
.setAction(ActionType.DANGEROUS_COMMAND) .setAction(ActionType.DANGEROUS_COMMAND)
.setEvent(e) .setEvent(e)
.setPlayer(p) .setPlayer(p)
.setCommand(command) .setCommand(fullcommand)
.setDenied(true) .setDenied(true)
.setDeoped(Config.deop) .setDeoped(Config.deop)
.setPunished(Config.commandPunish) .setPunished(Config.commandPunish)
@@ -40,10 +41,10 @@ public class CommandEvent implements Listener {
if (Config.blockSpecific) { if (Config.blockSpecific) {
ServerUtils.sendDebugMessage("CommandEvent: Checking command for specific"); ServerUtils.sendDebugMessage("CommandEvent: Checking command for specific");
if (command.contains(":")) { if (command.contains(":")) {
ServerUtils.sendDebugMessage("CommandEvent: Checking is specific"); ServerUtils.sendDebugMessage("CommandEvent: Failed check");
if (!Sentinel.isTrusted(p)) { if (!Sentinel.isTrusted(p)) {
e.setCancelled(true); e.setCancelled(true);
ServerUtils.sendDebugMessage(("CommandEvent: Command is canceled")); ServerUtils.sendDebugMessage(("CommandEvent: Not trusted, preforming action"));
Action a = new Action.Builder() Action a = new Action.Builder()
.setAction(ActionType.SPECIFIC_COMMAND) .setAction(ActionType.SPECIFIC_COMMAND)
.setEvent(e) .setEvent(e)
@@ -60,6 +61,7 @@ public class CommandEvent implements Listener {
} }
} }
if (Sentinel.isLoggedCommand(command)) { if (Sentinel.isLoggedCommand(command)) {
ServerUtils.sendDebugMessage("CommandEvent: Is logged command, logging");
Action a = new Action.Builder() Action a = new Action.Builder()
.setAction(ActionType.LOGGED_COMMAND) .setAction(ActionType.LOGGED_COMMAND)
.setEvent(e) .setEvent(e)

View File

@@ -4,6 +4,7 @@ import io.github.thetrouper.sentinel.Sentinel;
import io.github.thetrouper.sentinel.data.Config; import io.github.thetrouper.sentinel.data.Config;
import io.github.thetrouper.sentinel.data.Action; import io.github.thetrouper.sentinel.data.Action;
import io.github.thetrouper.sentinel.data.ActionType; import io.github.thetrouper.sentinel.data.ActionType;
import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -18,16 +19,22 @@ import java.util.Map;
public class NBTEvents implements Listener { public class NBTEvents implements Listener {
@EventHandler @EventHandler
private void onNBTPull(InventoryCreativeEvent e) { private void onNBTPull(InventoryCreativeEvent e) {
ServerUtils.sendDebugMessage("NBT: Detected creative mode action");
if (Config.preventNBT) { if (Config.preventNBT) {
if (!(e.getWhoClicked() instanceof Player p)) { ServerUtils.sendDebugMessage("NBT: Enabled");
return; if (!(e.getWhoClicked() instanceof Player p)) return;
} ServerUtils.sendDebugMessage("NBT: Clicker is a player");
if (e.getCursor() == null) return; if (e.getCursor() == null) return;
ServerUtils.sendDebugMessage("NBT: Cursor isn't null");
ItemStack i = e.getCursor(); ItemStack i = e.getCursor();
if (!Sentinel.isTrusted(p)) { if (!Sentinel.isTrusted(p)) {
ServerUtils.sendDebugMessage("NBT: Not trusted");
if (e.getCursor().getItemMeta() == null) return; if (e.getCursor().getItemMeta() == null) return;
ServerUtils.sendDebugMessage("NBT: Cursor has meta");
if (i.hasItemMeta() && i.getItemMeta() != null) { if (i.hasItemMeta() && i.getItemMeta() != null) {
ServerUtils.sendDebugMessage("NBT: Item has meta");
if (!itemPasses(i)) { if (!itemPasses(i)) {
ServerUtils.sendDebugMessage("NBT: Item doesn't pass, preforming action");
Action a = new Action.Builder() Action a = new Action.Builder()
.setEvent(e) .setEvent(e)
.setAction(ActionType.NBT) .setAction(ActionType.NBT)
@@ -48,28 +55,52 @@ public class NBTEvents implements Listener {
} }
private boolean itemPasses(ItemStack i) { private boolean itemPasses(ItemStack i) {
if (i.hasItemMeta()) { ServerUtils.sendDebugMessage("NBT: Checking if item passes: " + i.getItemMeta());
if (i.getItemMeta() != null) {
ServerUtils.sendDebugMessage("NBT: Item meta isn't null");
ItemMeta meta = i.getItemMeta(); ItemMeta meta = i.getItemMeta();
if (!Config.allowName && meta.hasDisplayName()) return false; if (!Config.allowName && meta.hasDisplayName()) {
if (!Config.allowLore && meta.hasLore()) return false; ServerUtils.sendDebugMessage("NBT: No pass N");
if (!Config.allowAttributes && meta.hasAttributeModifiers()) return false; return false;
if (Config.globalMaxEnchant == 0 && hasIllegalEnchants(i)) return false; } else if (!Config.allowLore && meta.hasLore()) {
ServerUtils.sendDebugMessage("NBT: No Pass L ");
return false;
} else if (!Config.allowAttributes && meta.hasAttributeModifiers()) {
ServerUtils.sendDebugMessage("NBT: No pass A");
return false;
} else if (Config.globalMaxEnchant != 0 && hasIllegalEnchants(i)) {
ServerUtils.sendDebugMessage("NBT: No pass E");
return false;
}
ServerUtils.sendDebugMessage("NBT: All checks passed");
return true;
} else {
ServerUtils.sendDebugMessage("NBT: Item passes because of no meta");
return true;
} }
return true;
} }
/*
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Detected creative mode action
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Enabled
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Clicker is a player
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Cursor isn't null
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Not trusted
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Cursor has meta
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Item has meta
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Checking if item passes: UNSPECIFIC_META:{meta-type=UNSPECIFIC, display-name={"italic":false,"color":"red","text":"Penguin's Flaming Fish!"}, lore=[{"extra":[{"bold":false,"italic":false,"underlined":false,"strikethrough":false,"obfuscated":false,"color":"gray","text":"Penguin Almighty XXXMMDCCLXVII"}],"text":""}], enchants={FIRE_ASPECT=32767, KNOCKBACK=32767}, ItemFlags=[HIDE_ENCHANTS]}
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Item meta isn't null
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: All checks passed
*/
private boolean hasIllegalEnchants(ItemStack i) { private boolean hasIllegalEnchants(ItemStack i) {
ServerUtils.sendDebugMessage("NBT: Checking for illegal enchants");
if (i.hasItemMeta() && i.getItemMeta().hasEnchants()) { if (i.hasItemMeta() && i.getItemMeta().hasEnchants()) {
final ItemMeta meta = i.getItemMeta(); final ItemMeta meta = i.getItemMeta();
final Map<Enchantment, Integer> enchantments = meta.getEnchants(); final Map<Enchantment, Integer> enchantments = meta.getEnchants();
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) { for (Integer value : enchantments.values()) {
Enchantment enchantment = entry.getKey(); if (value > Config.globalMaxEnchant) {
int level = entry.getValue();
if (level > Config.globalMaxEnchant) {
return true; return true;
} }
} }
// ALL // ALL
if (meta.hasEnchant(Enchantment.MENDING)) { if (meta.hasEnchant(Enchantment.MENDING)) {
final int level = meta.getEnchantLevel(Enchantment.MENDING); final int level = meta.getEnchantLevel(Enchantment.MENDING);

View File

@@ -7,7 +7,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
public class AntiUnicode { public class AntiUnicode {
public static void handleAntiUnicode(AsyncPlayerChatEvent e) { public static void handleAntiUnicode(AsyncPlayerChatEvent e) {
String message = Text.removeFirstColor(e.getMessage()); String message = Text.removeFirstColor(e.getMessage());
String nonAllowed = message.replaceAll("[A-Za-z0-9\\[,./?><|\\]()*&^%$#@!~`{}:;'\"-_]", "").trim(); String nonAllowed = message.replaceAll("[A-Za-z0-9\\[,./?><|\\]\u00A7()*&^%$#@!~`{}:;'\"-_]", "").trim();
if (nonAllowed.length() != 0) { if (nonAllowed.length() != 0) {
e.getPlayer().sendMessage(Text.prefix(Sentinel.dict.get("unicode-warn"))); e.getPlayer().sendMessage(Text.prefix(Sentinel.dict.get("unicode-warn")));
e.setCancelled(true); e.setCancelled(true);

View File

@@ -11,6 +11,8 @@ import java.util.List;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static io.github.thetrouper.sentinel.server.util.Text.SECTION_SYMBOL;
public class ProfanityFilter { public class ProfanityFilter {
public static Map<Player, Integer> scoreMap; public static Map<Player, Integer> scoreMap;
private static final List<String> swearBlacklist = Config.swearBlacklist; private static final List<String> swearBlacklist = Config.swearBlacklist;
@@ -140,14 +142,14 @@ public class ProfanityFilter {
} }
*/ */
public static String highlightProfanity(String text) { public static String highlightProfanity(String text) {
String highlightedSwears = highlightSwears(fullSimplify(text), "\u00a7e", "\u00a7f"); String highlightedSwears = highlightSwears(fullSimplify(text), "&e", "&f");
String highlightedText = highlightSlurs(highlightedSwears, "\u00a7c", "\u00a7f"); String highlightedText = highlightSlurs(highlightedSwears, "&c", "&f");
return highlightedText; return Text.color(highlightedText);
} }
public static String highlightProfanity(String text, String start, String end) { public static String highlightProfanity(String text, String start, String end) {
String highlightedSwears = highlightSwears(fullSimplify(text), start, end); String highlightedSwears = highlightSwears(fullSimplify(text), start, end);
String highlightedText = highlightSlurs(highlightedSwears, start, end); String highlightedText = highlightSlurs(highlightedSwears, start, end);
return highlightedText; return Text.color(highlightedText);
} }
private static String highlightSwears(String text, String start, String end) { private static String highlightSwears(String text, String start, String end) {

View File

@@ -40,6 +40,7 @@ public class FileUtils {
} }
} }
public static String createNBTLog(String contents) { public static String createNBTLog(String contents) {
ServerUtils.sendDebugMessage("FileUtils: Creating NBT log");
String fileName = "nbt_log-" + Randomizer.generateID(); String fileName = "nbt_log-" + Randomizer.generateID();
File file = new File(Sentinel.getInstance().getDataFolder() + "/LoggedNBT/" + fileName + ".txt"); File file = new File(Sentinel.getInstance().getDataFolder() + "/LoggedNBT/" + fileName + ".txt");
try { try {

View File

@@ -8,8 +8,10 @@ import java.util.Map;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
public class Text { public class Text {
public static String color(String s) { public static final char SECTION_SYMBOL = (char)167;
return s.replaceAll("&","\u00A7");
public static String color(String msg) {
return msg.replace('&', SECTION_SYMBOL);
} }
public static String prefix(String text) { public static String prefix(String text) {
String prefix = Sentinel.prefix; String prefix = Sentinel.prefix;

View File

@@ -109,5 +109,3 @@ config:
<: c <: c
V: u V: u
v: u v: u

View File

@@ -32,7 +32,7 @@
"spam-block-warn" : "Do not spam in chat! Please wait before sending another message.", "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-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)", "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" : "§bOriginal: §f%1$s\n§bSanitized: §f%2$s\n§8§o(Click to report false positive)", "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" : "§bOriginal: §f%1$s\n§bSanitized: §f%2$s\n§bSeverity: §c%3$s\n§7§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)"
} }
} }