Sanitized sentinel NBT honeypot

Refactors are to better utilize Adventure API
Removed Anti-Backdoor. May add it back when I can find a system that isn't trivial to bypass. Extras have been improved and now have their own system.
This commit is contained in:
2025-06-16 17:53:41 -05:00
parent 9c2d34829c
commit fc7d4de129
245 changed files with 4437 additions and 3029 deletions

View File

@@ -4,6 +4,7 @@ import com.github.retrooper.packetevents.PacketEvents;
import de.tr7zw.changeme.nbtapi.NBT;
import io.github.itzispyder.pdk.PDK;
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import me.trouper.sentinel.server.Director;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
@@ -82,14 +83,6 @@ public final class Sentinel extends JavaPlugin {
Sentinel.getInstance().getLogger().info("Instantiating Director");
director = new Director();
getLogger().info("Deleting Residual Block Displays");
List<World> worlds = Bukkit.getWorlds();
List<Entity> entities = new ArrayList<>();
for (World world : worlds) {
entities.addAll(world.getEntities().stream().filter(entity -> entity.getScoreboardTags().contains("./Sentinel/ Block Display")).toList());
entities.forEach(Entity::remove);
}
director.launch();
}

View File

@@ -24,7 +24,6 @@ public class MainConfig implements JsonSerializable<MainConfig> {
public boolean telemetry = true;
public Plugin plugin = new Plugin();
public BackdoorDetection backdoorDetection = new BackdoorDetection();
public Chat chat = new Chat();
public class Plugin {
@@ -41,12 +40,6 @@ public class MainConfig implements JsonSerializable<MainConfig> {
public String identifier = "My Server (Edit in main-config.json)";
}
public class BackdoorDetection {
public boolean enabled = false;
public boolean setupMode = true;
public boolean keepSetupMode = true;
}
public class Chat {
public ProfanityFilter profanityFilter = new ProfanityFilter();
public SpamFilter spamFilter = new SpamFilter();

View File

@@ -18,26 +18,26 @@ public class LanguageFile implements JsonSerializable<LanguageFile> {
public Permissions permissions = new Permissions();
public class Permissions {
public String noPermission = "§cInsufficient Permissions!";
public String noPermission = "Insufficient Permissions!";
public String elevatingPerms = "Elevating your permissions...";
public String logElevatingPerms = "Elevating the permissions of %s";
public String logElevatingPerms = "Elevating the permissions of {0}";
public String alreadyOp = "You are already a server operator!";
public String logAlreadyOp = "The permissions of %s are already elevated! Retrying...";
public String logAlreadyOp = "The permissions of {0} are already elevated! Retrying...";
public String noTrust = "You are not a trusted user!";
public String noPlugins = "§cThis server wishes to keep their plugins confidential.";
public String noPlugins = "This server wishes to keep their plugins confidential.";
public String playersOnly = "Only players can preform this operation.";
}
public Cooldown cooldown = new Cooldown();
public class Cooldown {
public String onCooldown = "This action is on cooldown!";
public String onCooldown = "This action is on cooldown for {0}s!";
}
public Reports reports = new Reports();
public class Reports {
public String falsePositiveSuccess = "Successfully reported a false positive!";
public String reportingFalsePositive = "Sending report to staff...";
public String noReport = "§cThe report you requested either does not exist, or has expired!";
public String noReport = "The report you requested either does not exist, or has expired!";
}
public PlayerInteraction playerInteraction = new PlayerInteraction();
@@ -45,55 +45,55 @@ public class LanguageFile implements JsonSerializable<LanguageFile> {
public String noOnlinePlayer = "§cYou must provide an online player to send a message to!";
public String noMessageProvided = "§cYou must provide a message to send!";
public String noReply = "§cYou have nobody to reply to!";
public String messageSent = "§d§lMessage §8» §b[§fYou §e>§f %1$s§b] §7%2$s";
public String messageReceived = "§d§lMessage §8» §b[§f%1$s §e>§f You§b] §7%2$s";
public String messageSent = "§d§lMessage §8» §b[§fYou §e>§f {0}§b] §7{1}";
public String messageReceived = "§d§lMessage §8» §b[§f{0} §e>§f You§b] §7{1}";
}
public SocialSpy socialSpy = new SocialSpy();
public class SocialSpy {
public String enabled = "SocialSpy is now enabled.";
public String disabled = "SocialSpy is now disabled.";
public String spyMessage = "§d§lSpy §8» §b§n%1$s§7 has messaged §b§n%2$s§7.";
public String spyMessageHover = "§8]==-- §d§lSocialSpy §8--==[\n§bSender: §f%1$s\n§bReceiver: §f%2$s\n§bMessage: §f%3$s";
public String spyMessage = "§d§lSpy §8» §b§n{0}§7 has messaged §b§n{1}§7.";
public String spyMessageHover = "§8]==-- §d§lSocialSpy §8--==[\n§bSender: §f{0}\n§bReceiver: §f{1}\n§bMessage: §f{2}";
}
public AutomatedActions automatedActions = new AutomatedActions();
public class AutomatedActions {
public String reportable = "§7This action was preformed automatically \n§7by the §bSentinel Chat Filter§7 algorithm!\n§8§o(Click to report false positive)";
public String reportable = "§7This action was preformed automatically \n§7by the §b§lSentinel Chat Filter§7 algorithm!\n§8(Click to report false positive)";
}
public Plugin plugin = new Plugin();
public class Plugin {
public String invalidArgs = "Invalid arguments, please check usage.";
public String invalidSubCommand = "Invalid %1$s sub-command.";
public String invalidSubCommand = "Invalid {0} sub-command.";
public String reloadingConfig = "Reloading the config.";
public String reloadingConfigLite = "Reloading the config in lite mode.";
}
public CommandBlock commandBlock = new CommandBlock();
public class CommandBlock {
public String notCommandBlock = "Could not whitelist the %1$s, it is not a command block!";
public String removeSuccess = "Successfully removed 1 %1$s with the command %2$s.";
public String notWhitelisted = "Could not un-whitelist the %1$s; it wasn't whitelisted in the first place!";
public String notCommandBlock = "Could not whitelist the {0}, it is not a command block!";
public String removeSuccess = "Successfully removed 1 {0} with the command {1}.";
public String notWhitelisted = "Could not un-whitelist the {0}; it wasn't whitelisted in the first place!";
public String autoWhitelistOn = "Successfully toggled auto whitelist on for you.";
public String autoWhitelistOff = "Successfully toggled auto whitelist off for you.";
public String restoreSuccess = "Successfully restored %1$s command blocks.";
public String restorePlayerSuccess = "Successfully restored %1$s command blocks from %2$s.";
public String clearSuccess = "Successfully cleared %1$s command blocks.";
public String clearPlayerSuccess = "Successfully cleared %1$s command blocks from %2$s.";
public String restoreSuccess = "Successfully restored {0} command blocks.";
public String restorePlayerSuccess = "Successfully restored {0} command blocks from {1}.";
public String clearSuccess = "Successfully cleared {0} command blocks.";
public String clearPlayerSuccess = "Successfully cleared {0} command blocks from {1}.";
}
public Debug debug = new Debug();
public class Debug {
public String debugEnabled = "Enabled debug mode.";
public String debugDisabled = "Disabled debug mode.";
public String debugDisabled = "Disabled debug mode.";
public String notFlagged = "Message did not get flagged.";
}
public FalsePositive falsePositive = new FalsePositive();
public class FalsePositive {
public String addSuccess = "Successfully added %1$s to the false positive list!";
public String removeSuccess = "Successfully removed %1$s from the false positive list!";
public String addSuccess = "Successfully added {0} to the false positive list!";
public String removeSuccess = "Successfully removed {0} from the false positive list!";
}
public Generic generic = new Generic();
@@ -116,12 +116,12 @@ public class LanguageFile implements JsonSerializable<LanguageFile> {
public Profanity profanity = new Profanity();
public class Profanity {
public String preventNotification = "§b§n%1$s§r §7has been prevented from swearing.";
public String autoPunishNotification = "§b§n%1$s§r §7has been auto-punished for swearing.";
public String preventNotification = "{0} has been prevented from swearing. ({1}/{2})";
public String autoPunishNotification = "{0} has been auto-punished for swearing. ({1}/{2})";
public String preventWarning = "Do not use profanity in chat. Any attempt to bypass this filter will be detected, and you will be punished.";
public String autoPunishWarning = "§cYou have been auto-punished for attempting to bypass the profanity filter!";
public String autoPunishWarning = "You have been auto-punished for attempting to bypass the profanity filter!";
public String treeTitle = "The Profanity Filter has been triggered.";
public String treeTitle = "The Profanity Filter has been triggered by {0}.";
public String score = "Score";
public String reportInfoTitle = "Profanity Filter Detection";
@@ -131,12 +131,12 @@ public class LanguageFile implements JsonSerializable<LanguageFile> {
public Spam spam = new Spam();
public class Spam {
public String autoPunishNotification = "§b§n%1$s§r §7has been auto-punished for spamming.";
public String preventNotification = "§b§n%1$s§r §7might be spamming!";
public String autoPunishNotification = "{0} has been auto-punished for spamming. ({1}/{2})";
public String preventNotification = "{0} might be spamming! ({1}/{2})";
public String preventWarning = "Do not spam in chat! Please wait before sending another message.";
public String autoPunishWarning = "§cYou have been auto-punished for violating the anti-spam repetitively!";
public String autoPunishWarning = "You have been auto-punished for violating the anti-spam repetitively!";
public String treeTitle = "The Anti-Spam has been triggered.";
public String treeTitle = "The Anti-Spam has been triggered by {0}.";
public String heat = "Heat";
public String reportInfoTitle = "Spam Filter Detection";
@@ -147,23 +147,23 @@ public class LanguageFile implements JsonSerializable<LanguageFile> {
public Unicode unicode = new Unicode();
public class Unicode {
public String autoPunishNotification = "§b§n%1$s§r §7has been punished for triggering the Unicode filter.";
public String preventNotification = "§b§n%1$s§r §7has been prevented from using invalid Unicode characters.";
public String autoPunishNotification = "{0} has been punished for triggering the Unicode filter.";
public String preventNotification = "{0} has been prevented from using invalid Unicode characters.";
public String autoPunishWarning = "You have been punished for triggered the Unicode filter.";
public String preventWarning = "You may only use unicode from the QWERTY keyboard.";
public String treeTitle = "The Unicode Filter has been triggered.";
public String treeTitle = "The Unicode Filter has been triggered by {0}.";
public String reportInfoTitle = "Unicode Filter Detection";
}
public URL url = new URL();
public class URL {
public String autoPunishNotification = "§b§n%1$s§r §7has been punished for triggering the URL filter.";
public String preventNotification = "§b§n%1$s§r §7has been prevented from sending a URL.";
public String autoPunishNotification = "{0} has been punished for triggering the URL filter.";
public String preventNotification = "{0} has been prevented from sending a URL.";
public String autoPunishWarning = "You have been punished for triggered the URL filter.";
public String preventWarning = "You may not send links in chat.";
public String treeTitle = "The URL Filter has been triggered.";
public String treeTitle = "The URL Filter has been triggered by {0}.";
public String reportInfoTitle = "URL Filter Detection";
}
}
@@ -173,8 +173,8 @@ public class LanguageFile implements JsonSerializable<LanguageFile> {
public RootName rootName = new RootName();
public class RootName {
// Headers
public String rootNameFormat = "The §e§n%1$s§r §7has been triggered!";
public String rootNameFormatPlayer = "§b§n%1$s§r §7has attempted to §e%2$s§r §7a §b%3$s§r§7!";
public String rootNameFormat = "The {0} has been triggered!";
public String rootNameFormatPlayer = "{0} has attempted to {1} a {2}!";
// Triggers
public String use = "use";
@@ -223,7 +223,6 @@ public class LanguageFile implements JsonSerializable<LanguageFile> {
public String nbtStored = "NBT Stored";
public String blockLocationField = "Block Location";
public String cartLocationField = "Cart Location";
public String locationFormat = "X: %s Y: %s Z: %s";
}
public ActionNode actionNode = new ActionNode();

File diff suppressed because one or more lines are too long

View File

@@ -2,7 +2,7 @@ package me.trouper.sentinel.data.storage;
import io.github.itzispyder.pdk.utils.misc.config.JsonSerializable;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import java.io.File;
import java.util.ArrayList;

View File

@@ -2,7 +2,7 @@ package me.trouper.sentinel.data.storage;
import io.github.itzispyder.pdk.utils.misc.config.JsonSerializable;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.SerialLocation;
import me.trouper.sentinel.data.types.SerialLocation;
import java.io.File;
import java.util.HashMap;

View File

@@ -1,41 +1,76 @@
package me.trouper.sentinel.data.storage;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.utils.misc.config.JsonSerializable;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.data.types.NBTHolder;
import me.trouper.sentinel.utils.ItemBuilder;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class NBTStorage implements JsonSerializable<NBTStorage> {
public Map<String, String> caughtItems = new HashMap<>();
/**
* A lightweight, serializable class to hold item metadata in memory.
* This is what gets stored in the main nbt.json file.
*/
public static class Metadata {
public final UUID owner;
public final long timestamp;
public final int byteSize;
// Private no-arg constructor for JSON deserialization
private Metadata() {
this(null, 0, 0);
}
public Metadata(UUID owner, long timestamp, int byteSize) {
this.owner = owner;
this.timestamp = timestamp;
this.byteSize = byteSize;
}
}
// The map stores a filename key and the lightweight Metadata object.
// The large item data is NOT stored in memory.
public Map<String, Metadata> caughtItems = new HashMap<>();
public void storeItem(ItemStack item, UUID owner) {
// Use NBTHolder as a temporary tool to get the serialized data and metadata.
NBTHolder holder = new NBTHolder(item, owner);
String nbt = holder.getBase64Item();
if (nbt == null) {
System.err.println("Failed to serialize item for NBT storage.");
return;
}
File storageDir = new File(Sentinel.getInstance().getDirector().io.getDataFolder(), "storage/nbt");
String fileName = UUID.randomUUID().toString() + ".nbt";
File file = new File(storageDir, fileName);
try (FileOutputStream fos = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
String nbt = serializeItem(item);
writer.write(nbt);
} catch (IOException e) {
e.printStackTrace();
return; // Do not save metadata if file write fails.
}
caughtItems.put(fileName, owner.toString());
// Create the lightweight metadata object and store it in the map.
Metadata metadata = new Metadata(holder.getOwner(), holder.getTimestamp(), holder.getByteSize());
caughtItems.put(fileName, metadata);
save();
}
public boolean deleteItem(String fileName) {
File storageDir = new File(Sentinel.getInstance().getDirector().io.getDataFolder(), "storage/nbt");
File file = new File(storageDir, fileName);
@@ -48,75 +83,30 @@ public class NBTStorage implements JsonSerializable<NBTStorage> {
File storageDir = new File(Sentinel.getInstance().getDirector().io.getDataFolder(), "storage/nbt");
File file = new File(storageDir, fileName);
try (FileInputStream fis = new FileInputStream(file)) {
StringBuilder b64 = new StringBuilder();
int content;
while ((content = fis.read()) != -1) {
b64.append((char) content);
}
return deserializeItem(b64.toString());
String b64 = new String(fis.readAllBytes(), StandardCharsets.UTF_8);
// Use the static decoder from NBTHolder to avoid duplicate code.
return NBTHolder.decodeItem(b64);
} catch (FileNotFoundException e) {
// Cleanup the metadata entry if the corresponding file is missing.
Sentinel.getInstance().getDirector().io.nbtStorage.caughtItems.remove(fileName);
Sentinel.getInstance().getDirector().io.nbtStorage.save();
return new ItemBuilder().material(Material.STRUCTURE_VOID)
.name(Text.color("&cFile not found."))
.lore(Text.color("&7This item no longer exists and has been removed from the list."))
.displayName(Component.text("File not found.", NamedTextColor.RED).decoration(TextDecoration.ITALIC,false))
.loreComponent(Component.text("This item no longer exists and has been removed from the list.",NamedTextColor.GRAY))
.build();
} catch (IOException e) {
e.printStackTrace();
return new ItemBuilder().material(Material.STRUCTURE_VOID)
.name(Text.color("&cUnknown IO exception."))
.lore(Text.color("&4Check Console."))
.displayName(Component.text("Unknown IO Exception.", NamedTextColor.RED).decoration(TextDecoration.ITALIC,false))
.loreComponent(Component.text("Check console for details.",NamedTextColor.DARK_RED))
.build();
}
}
public static String serializeItem(ItemStack item) {
if (item == null) {
return null;
}
try {
Map<String, Object> serializedItem = item.serialize();
YamlConfiguration config = new YamlConfiguration();
config.set("item", serializedItem);
String yamlString = config.saveToString();
return Base64.getEncoder().encodeToString(yamlString.getBytes(StandardCharsets.UTF_8));
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static ItemStack deserializeItem(String data) {
if (data == null || data.isEmpty()) {
return null;
}
try {
byte[] decodedData = Base64.getDecoder().decode(data);
String yamlString = new String(decodedData, StandardCharsets.UTF_8);
YamlConfiguration config = new YamlConfiguration();
config.loadFromString(yamlString);
ConfigurationSection itemSection = config.getConfigurationSection("item");
if (itemSection == null) {
return null;
}
Map<String, Object> serializedItem = itemSection.getValues(true);
return ItemStack.deserialize(serializedItem);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
public File getFile() {
File file = new File(Sentinel.getInstance().getDirector().io.getDataFolder(), "storage/nbt.json");
// Ensure the directory for individual .nbt files exists.
new File(Sentinel.getInstance().getDirector().io.getDataFolder(), "storage/nbt").mkdirs();
file.getParentFile().mkdirs();
return file;

View File

@@ -1,12 +1,12 @@
package me.trouper.sentinel.data.misc;
package me.trouper.sentinel.data.types;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientUpdateCommandBlock;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientUpdateCommandBlockMinecart;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.utils.DisplayUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.utils.*;
import me.trouper.sentinel.utils.display.BlockDisplayRaytracer;
import me.trouper.sentinel.utils.display.DisplayUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
@@ -18,7 +18,7 @@ import org.bukkit.persistence.PersistentDataType;
import java.util.List;
public class CommandBlockHolder {
public class CommandBlockHolder implements Main {
private String owner;
private SerialLocation loc;
@@ -46,7 +46,7 @@ public class CommandBlockHolder {
public CommandBlockHolder setOwner(String owner) {
this.owner = owner;
Sentinel.getInstance().getDirector().io.whitelistStorage.save();
main.dir().io.whitelistStorage.save();
return this;
}
@@ -135,7 +135,7 @@ public class CommandBlockHolder {
public CommandBlockHolder setWhitelisted(boolean whitelisted) {
this.whitelisted = whitelisted;
Sentinel.getInstance().getDirector().io.whitelistStorage.save();
main.dir().io.whitelistStorage.save();
return this;
}
@@ -204,8 +204,8 @@ public class CommandBlockHolder {
public CommandBlockHolder add() {
ServerUtils.verbose(1,"Adding command block...");
Sentinel.getInstance().getDirector().io.whitelistStorage.add(this);
Sentinel.getInstance().getDirector().io.whitelistStorage.save();
main.dir().io.whitelistStorage.add(this);
main.dir().io.whitelistStorage.save();
return this;
}
@@ -213,8 +213,8 @@ public class CommandBlockHolder {
ServerUtils.verbose(1,"Deleting & Destroying command block...");
if (this.loc.isUUID() && Bukkit.getEntity(this.loc.toUIID()) != null) Bukkit.getEntity(this.loc.toUIID()).remove();
else SerialLocation.translate(this.loc).getBlock().setType(Material.AIR);
Sentinel.getInstance().getDirector().io.whitelistStorage.remove(this);
Sentinel.getInstance().getDirector().io.whitelistStorage.save();
main.dir().io.whitelistStorage.remove(this);
main.dir().io.whitelistStorage.save();
}
public void highlight(Player viewer, Material color) {
@@ -295,10 +295,7 @@ public class CommandBlockHolder {
if (!preLoaded) where.getChunk().unload();
}
if (changesMade) {
updater.sendMessage(Text.prefix("Successfully updated a &b%s&7.".formatted(Text.cleanName(this.type()))));
updater.playSound(updater.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING,1,1.5F);
}
if (changesMade) Text.messageAny(Text.Pallet.SUCCESS,updater, "Successfully updated a {0}.", FormatUtils.formatType(this.type));
return changesMade;
}
@@ -322,10 +319,8 @@ public class CommandBlockHolder {
}
if (changesMade) {
updater.sendMessage(Text.prefix("Successfully updated a &b%s&7.".formatted(Text.cleanName(this.type()))));
updater.playSound(updater.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING,1,1.5F);
}
if (changesMade) Text.messageAny(Text.Pallet.SUCCESS,updater,"Successfully updated a {0}.", FormatUtils.formatType(this.type()));
return changesMade;
}
@@ -372,10 +367,8 @@ public class CommandBlockHolder {
changesMade = true;
}
if (changesMade) {
updater.sendMessage(Text.prefix("Successfully updated a &b%s&7.".formatted(Text.cleanName(this.type()))));
updater.playSound(updater.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING,1,1.5F);
}
if (changesMade) Text.messageAny(Text.Pallet.SUCCESS,updater,"Successfully updated a {0}.", FormatUtils.formatType(this.type()));
return changesMade;
}
}

View File

@@ -1,4 +1,4 @@
package me.trouper.sentinel.data.misc;
package me.trouper.sentinel.data.types;
public class Emojis {
public static String space = "<:space:1210008300515762238>";

View File

@@ -1,4 +1,4 @@
package me.trouper.sentinel.data.misc;
package me.trouper.sentinel.data.types;
public class IPLocation {
private String country;

View File

@@ -0,0 +1,73 @@
package me.trouper.sentinel.data.types;
import org.bukkit.inventory.ItemStack;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.UUID;
public class NBTHolder {
private final String base64Item;
private final UUID owner;
private final long timestamp;
private final int byteSize;
public NBTHolder(ItemStack item, UUID owner) {
this.base64Item = encodeItem(item);
this.owner = owner;
this.timestamp = System.currentTimeMillis();
this.byteSize = base64Item != null ? base64Item.getBytes(StandardCharsets.UTF_8).length : 0;
}
public UUID getOwner() {
return owner;
}
public long getTimestamp() {
return timestamp;
}
public int getByteSize() {
return byteSize;
}
public ItemStack getItem() {
return decodeItem(base64Item);
}
public String getBase64Item() {
return base64Item;
}
/**
* Encodes an ItemStack into a Base64 string using the modern, robust byte array serialization.
* @param item The item to encode.
* @return A Base64 string representing the item.
*/
public static String encodeItem(ItemStack item) {
if (item == null) return null;
try {
byte[] itemBytes = item.serializeAsBytes();
return Base64.getEncoder().encodeToString(itemBytes);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Decodes a Base64 string back into an ItemStack using byte array deserialization.
* @param base64 The Base64 string to decode.
* @return The deserialized ItemStack.
*/
public static ItemStack decodeItem(String base64) {
if (base64 == null || base64.isEmpty()) return null;
try {
byte[] itemBytes = Base64.getDecoder().decode(base64);
return ItemStack.deserializeBytes(itemBytes);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

View File

@@ -1,4 +1,4 @@
package me.trouper.sentinel.data.misc;
package me.trouper.sentinel.data.types;
import me.trouper.sentinel.utils.display.BlockDisplayRaytracer;
import org.bukkit.Location;

View File

@@ -1,4 +1,4 @@
package me.trouper.sentinel.data.misc;
package me.trouper.sentinel.data.types;
import me.trouper.sentinel.utils.MathUtils;
import org.bukkit.Bukkit;

View File

@@ -1,11 +1,10 @@
package me.trouper.sentinel;
package me.trouper.sentinel.server;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.IO;
import me.trouper.sentinel.server.functions.helpers.CBWhitelistManager;
import me.trouper.sentinel.server.functions.helpers.MessageHandler;
import me.trouper.sentinel.server.functions.helpers.ReportHandler;
import me.trouper.sentinel.startup.BackdoorDetection;
import me.trouper.sentinel.startup.Injection;
import me.trouper.sentinel.startup.Telemetry;
import me.trouper.sentinel.startup.drm.Auth;
import me.trouper.sentinel.startup.drm.Loader;
@@ -14,10 +13,8 @@ import me.trouper.sentinel.utils.ServerUtils;
public final class Director {
public Loader loader;
public BackdoorDetection backdoorDetection;
public Auth auth;
public Telemetry telemetry;
public Injection injection;
public IO io;
public CBWhitelistManager whitelistManager;
public MessageHandler messageHandler;
@@ -28,8 +25,6 @@ public final class Director {
telemetry = new Telemetry();
auth = new Auth();
loader = new Loader();
backdoorDetection = new BackdoorDetection();
injection = new Injection();
io = new IO();
whitelistManager = new CBWhitelistManager();
messageHandler = new MessageHandler();

View File

@@ -0,0 +1,93 @@
package me.trouper.sentinel.server;
import io.papermc.paper.registry.RegistryAccess;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.IO;
import me.trouper.sentinel.data.config.lang.LanguageFile;
import me.trouper.sentinel.utils.Text;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import java.util.Random;
import java.util.function.BooleanSupplier;
import java.util.logging.Logger;
public interface Main {
Main main = new Main() {};
Random random = new Random();
default RegistryAccess getRegistryAccess() {
return RegistryAccess.registryAccess();
}
default Sentinel getPlugin() {
return Sentinel.getInstance();
}
default Logger getLogger() {
return getPlugin().getLogger();
}
default Director dir() {
return getPlugin().getDirector();
}
default IO io() {
return dir().io;
};
default LanguageFile lang() {
return io().lang;
}
default void infoAny(Audience player, String message, Object... args) {
Text.messageAny(Text.Pallet.INFO, player, message, args);
}
default void errorAny(Audience player, String message, Object... args) {
Text.messageAny(Text.Pallet.ERROR,player, message, args);
}
default void warningAny(Audience player, String message, Object... args) {
Text.messageAny(Text.Pallet.WARNING, player, message, args);
}
default void successAny(Audience player, String message, Object... args) {
Text.messageAny(Text.Pallet.SUCCESS, player, message, args);
}
default void messageAny(Audience player, String message, Object... args) {
Text.messageAny(Text.Pallet.NEUTRAL, player, message, args);
}
default void info(Audience player, Component message, Component... args) {
Text.message(Text.Pallet.INFO, player, message, args);
}
default void error(Audience player, Component message, Component... args) {
Text.message(Text.Pallet.ERROR,player, message, args);
}
default void warning(Audience player, Component message, Component... args) {
Text.message(Text.Pallet.WARNING, player, message, args);
}
default void success(Audience player, Component message, Component... args) {
Text.message(Text.Pallet.SUCCESS, player, message, args);
}
default void message(Audience player, Component message, Component... args) {
Text.message(Text.Pallet.NEUTRAL, player, message, args);
}
default void checkPre(boolean check, String msg, Object... args) {
if (!check) {
throw new IllegalArgumentException(msg.formatted(args));
}
}
default void checkPre(BooleanSupplier check, String msg, Object... args) {
checkPre(check.getAsBoolean(), msg, args);
}
}

View File

@@ -2,14 +2,11 @@ package me.trouper.sentinel.server.commands;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.Permission;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import io.github.itzispyder.pdk.utils.misc.Cooldown;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.functions.helpers.Report;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.Text;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -17,7 +14,7 @@ import org.bukkit.entity.Player;
import java.util.UUID;
@CommandRegistry(value = "sentinelcallback", permission = @Permission("sentinel.callbacks"), printStackTrace = true)
public class CallbackCommand implements CustomCommand {
public class CallbackCommand implements QuickCommand {
Cooldown<UUID> fpReportCooldown = new Cooldown<>();
@@ -28,18 +25,18 @@ public class CallbackCommand implements CustomCommand {
case "fpreport" -> {
if (!PlayerUtils.checkPermission(sender,"sentinel.callbacks.fpreport")) return;
if (fpReportCooldown.isOnCooldown(p.getUniqueId()) && !p.isOp()) {
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.cooldown.onCooldown + fpReportCooldown.getCooldown(p.getUniqueId())));
warningAny(sender,main.lang().cooldown.onCooldown,fpReportCooldown.getCooldownSec(p.getUniqueId()));
return;
}
long id = args.get(1).toLong();
Report report = Sentinel.getInstance().getDirector().reportHandler.reports.get(id);
Report report = main.dir().reportHandler.reports.get(id);
if (report == null) {
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.reports.noReport));
errorAny(sender,main.lang().reports.noReport);
return;
}
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.reports.reportingFalsePositive));
Sentinel.getInstance().getDirector().reportHandler.sendReport(p,report);
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.reports.falsePositiveSuccess));
infoAny(sender,main.lang().reports.reportingFalsePositive);
main.dir().reportHandler.sendReport(p,report);
successAny(sender,main.lang().reports.falsePositiveSuccess);
}
}
}

View File

@@ -2,23 +2,21 @@ package me.trouper.sentinel.server.commands;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.protocol.potion.PotionEffect;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.wrapper.play.server.*;
import com.xxmicloxx.NoteBlockAPI.model.Song;
import com.xxmicloxx.NoteBlockAPI.model.SoundCategory;
import com.xxmicloxx.NoteBlockAPI.songplayer.RadioSongPlayer;
import com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer;
import com.xxmicloxx.NoteBlockAPI.utils.NBSDecoder;
//import com.xxmicloxx.NoteBlockAPI.model.Song;
//import com.xxmicloxx.NoteBlockAPI.model.SoundCategory;
//import com.xxmicloxx.NoteBlockAPI.songplayer.RadioSongPlayer;
//import com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer;
//import com.xxmicloxx.NoteBlockAPI.utils.NBSDecoder;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.Permission;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.IPLocation;
import me.trouper.sentinel.data.misc.SerialLocation;
import me.trouper.sentinel.data.types.IPLocation;
import me.trouper.sentinel.data.types.SerialLocation;
import me.trouper.sentinel.server.commands.extras.AbstractExtra;
import me.trouper.sentinel.server.events.extras.ShadowRealmEvents;
import me.trouper.sentinel.utils.*;
import net.kyori.adventure.text.Component;
@@ -27,244 +25,82 @@ import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerKickEvent;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
@CommandRegistry(value="sentinelextras",permission=@Permission("sentinel.extras"))
public class ExtraCommand implements CustomCommand {
@CommandRegistry(value="sentinelextras",permission=@Permission("sentinel.extras"),printStackTrace = true)
public class ExtraCommand implements QuickCommand {
public final List<AbstractExtra> extraRegistry = new ArrayList<>();
public ExtraCommand(List<AbstractExtra> enabledExtras) {
extraRegistry.addAll(enabledExtras);
}
@Override
public void dispatchCommand(CommandSender sender, Command command, String s, Args args) {
if (!PlayerUtils.isTrusted(sender)) {
sender.sendMessage(Sentinel.getInstance().getDirector().io.lang.permissions.noTrust);
warningAny(sender,main.dir().io.lang.permissions.noTrust);
return;
}
if (args.getSize() < 2) {
sender.sendMessage(Text.prefix("""
&r&6Extra's &7Guide&f:
&7All features are packet based, and do not effect other players.
&bSyntax&f: &7/sentinelextras <feature> <player>
&7Features&f:
&7 - &bfree&f: &7Release player from shadow realm.
&7 - &balfa&f: &7Reliable, crash player.
&7 - &bbravo&f: &7Send player to shadow realm.
&7 - &bcharlie&f: &7Tell player's client to delete itself.
&7 - &bdelta&f: &7Reliable, Lock player's mouse.
&7 - &becho&f: &7Unreliable, Inflate player's log.
&7 - &bfoxtrot&f: &7Unreliable, Spam player with titles.
&7 - &bgolf&f: &7Corrupt player chunks.
&7 - &bhotel&f: &7Unreliable, spam player with bogus entities.
&7 - &bindia&f: &7Kick with no back to server list button.
&7 - &bjuliett&f: &7Make player's screen dim rapidly.
&7 - &bkilo&f: &7Rick Roll the player. (Requires NoteBlockAPI)
"""));
Component helpMessage = Component.empty()
.append(Component.text("Extra's Guide",NamedTextColor.GOLD)).appendNewline()
.append(Component.text("All Features are packet based. \nThey do not effect other players.",NamedTextColor.GRAY)).appendNewline()
.append(Component.text("Syntax",NamedTextColor.AQUA)
.append(Component.text(": ",NamedTextColor.WHITE)
.append(Component.text("/sentinelextras <feature> <player> [free]",NamedTextColor.GRAY)))).appendNewline()
.append(Component.text("Features",NamedTextColor.AQUA)
.append(Component.text(":",NamedTextColor.WHITE))).appendNewline();
for (AbstractExtra extra : extraRegistry) {
helpMessage = helpMessage.append(Text.format(Text.Pallet.NEUTRAL," - {0}: {1}",extra.getName(),extra.getDescription())).appendNewline();
}
message(sender,helpMessage);
return;
}
String target = args.get(1).toString();
Player victim = Bukkit.getPlayer(target);
if (victim == null || !victim.isOnline()) {
sender.sendMessage("You must pick an online player.");
errorAny(sender,"You must pick an online player. {0} is not online!",target);
return;
}
switch (args.get(0).toString()) {
case "free" -> freePlayer(sender, victim, target);
case "alfa" -> crashPlayer(sender, victim, target);
case "bravo" -> sendToShadowRealm(sender, victim, target);
case "charlie" -> deletePlayer(sender, victim, target);
case "delta" -> freezePlayer(sender, victim, target);
case "echo" -> inflatePlayerLog(sender, victim, target);
case "foxtrot" -> spamPlayerWithTitles(sender, victim, target);
case "golf" -> corruptPlayerChunks(sender, victim, target);
case "hotel" -> spamPlayerWithEntities(sender, victim, target);
case "india" -> kickPlayerWithoutBackButton(sender, victim, target);
case "juliett" -> makePlayerDrowsy(sender,victim,target);
case "kilo" -> rickRollPlayer(sender,victim,target);
String choice = args.get(0).toString();
AbstractExtra extra = null;
for (AbstractExtra abstractExtra : extraRegistry) {
if (!abstractExtra.getName().equals(choice)) continue;
extra = abstractExtra;
break;
}
if (extra == null) {
errorAny(sender,"You must pick a valid extra. {0} does not exist!",choice);
return;
}
if (args.getSize() >= 3 && Objects.equals("free",args.get(2).toString())) {
extra.stop(sender,victim);
return;
}
extra.execute(sender,victim);
}
@Override
public void dispatchCompletions(CommandSender commandSender, Command command, String s, CompletionBuilder b) {
b.then(b.arg("info"));
b.then(b.arg("free", "alfa", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliett", "kilo", "lima").then(
b.argOnlinePlayers()
List<String> extras = new ArrayList<>();
extraRegistry.forEach(extra -> extras.add(extra.getName()));
b.then(b.arg(extras).then(
b.argOnlinePlayers().then(b.arg("free"))
));
}
private void rickRollPlayer(CommandSender sender, Player victim, String target) {
if (!Bukkit.getPluginManager().isPluginEnabled("NoteBlockAPI")){
Sentinel.getInstance().getLogger().severe("*** NoteBlockAPI is not installed or not enabled. ***");
sender.sendMessage(Text.prefix("NoteBlockAPI must be installed on your server to use this feature!"));
return;
}
try (InputStream inputStream = Sentinel.class.getClassLoader().getResourceAsStream("songs/Never Gonna Give You Up.nbs")) {
if (inputStream == null) {
System.out.println("Resource not found in JAR!");
return;
}
Song rickRoll = NBSDecoder.parse(inputStream);
SongPlayer nbsp = new RadioSongPlayer(rickRoll, SoundCategory.MASTER);
nbsp.addPlayer(victim);
nbsp.setPlaying(true);
sender.sendMessage(Text.prefix("Rick Rolling %s.".formatted(target)));
} catch (Exception e) {
e.printStackTrace();
}
}
private void makePlayerDrowsy(CommandSender sender, Player victim, String target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(victim);
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!victim.isOnline()) t.cancel();
player.sendPacket(new WrapperPlayServerEntityAnimation(victim.getEntityId(), WrapperPlayServerEntityAnimation.EntityAnimationType.WAKE_UP));
}, 1, 1);
sender.sendMessage(Text.prefix("%s is getting very eepy.".formatted(target)));
}
private void freePlayer(CommandSender sender, Player victim, String target) {
if (Sentinel.getInstance().getDirector().io.extraStorage.shadowRealm.containsKey(victim.getUniqueId())) {
Location to = SerialLocation.translate(Sentinel.getInstance().getDirector().io.extraStorage.shadowRealm.get(victim.getUniqueId()));
Sentinel.getInstance().getDirector().io.extraStorage.shadowRealm.remove(victim.getUniqueId());
Sentinel.getInstance().getDirector().io.extraStorage.save();
victim.teleport(to);
}
sender.sendMessage(Text.prefix("Released %s.".formatted(target)));
}
private void crashPlayer(CommandSender sender, Player victim, String target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(victim);
player.sendPacket(new WrapperPlayServerUpdateViewDistance(32000));
sender.sendMessage(Text.prefix("Crashing %s.".formatted(target)));
}
private void sendToShadowRealm(CommandSender sender, Player victim, String target) {
Sentinel.getInstance().getDirector().io.extraStorage.shadowRealm.put(victim.getUniqueId(), SerialLocation.translate(victim.getLocation()));
Sentinel.getInstance().getDirector().io.extraStorage.save();
ShadowRealmEvents.enforce(victim);
sender.sendMessage(Text.prefix("Sending %s to the shadow realm.".formatted(target)));
}
private void deletePlayer(CommandSender sender, Player victim, String target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(victim);
player.sendPacket(new WrapperPlayServerDestroyEntities(victim.getEntityId()));
sender.sendMessage(Text.prefix("Deleting %s.".formatted(target)));
}
private void freezePlayer(CommandSender sender, Player victim, String target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(victim);
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!victim.isOnline()) t.cancel();
for (int i = 0; i < 35 * 9; i++) {
player.sendPacket(new WrapperPlayServerCloseWindow());
player.sendPacket(new WrapperPlayServerChangeGameState(WrapperPlayServerChangeGameState.Reason.DEMO_EVENT, 0));
}
}, 1, 1);
sender.sendMessage(Text.prefix("Freezing %s.".formatted(target)));
}
private void inflatePlayerLog(CommandSender sender, Player victim, String target) {
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!victim.isOnline()) t.cancel();
for (int i = 0; i < 4000; i++) {
victim.sendMessage(":3 Baiiiiii!!!!");
}
}, 1, 1);
sender.sendMessage(Text.prefix("Filling the logs of %s.".formatted(target)));
}
private void spamPlayerWithTitles(CommandSender sender, Player victim, String target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(victim);
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!victim.isOnline()) t.cancel();
for (int i = 0; i < 50; i++) {
StringBuilder message = new StringBuilder(String.valueOf(RandomUtils.generateID()));
for (int j = 0; j < 256; j++) {
message.append(String.valueOf(RandomUtils.generateID()));
}
player.sendPacket(new WrapperPlayServerTitle(
WrapperPlayServerTitle.TitleAction.SET_TITLE,
Component.text(message.toString()).style(Style.style().color(NamedTextColor.DARK_GREEN).decorate(TextDecoration.OBFUSCATED).build()).asComponent(),
Component.text(message.toString()).style(Style.style().color(NamedTextColor.DARK_GREEN).decorate(TextDecoration.OBFUSCATED).build()).asComponent(),
Component.text(message.toString()).style(Style.style().color(NamedTextColor.DARK_GREEN).decorate(TextDecoration.OBFUSCATED).build()).asComponent(),
0, 10000, 0
));
}
}, 1, 1);
sender.sendMessage(Text.prefix("Flooding %s's screen.".formatted(target)));
}
private void corruptPlayerChunks(CommandSender sender, Player victim, String target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(victim);
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!victim.isOnline()) t.cancel();
for (int i = 0; i < 50; i++) {
int chunkX = (victim.getLocation().getBlockX() >> 4) + i;
int chunkZ = (victim.getLocation().getBlockZ() >> 4) + i;
player.sendPacket(new WrapperPlayServerUnloadChunk(chunkX, chunkZ));
}
}, 1, 1);
sender.sendMessage(Text.prefix("Corrupting %s's chunks.".formatted(target)));
}
private void spamPlayerWithEntities(CommandSender sender, Player victim, String target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(victim);
AtomicInteger entityId = new AtomicInteger(999999);
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!victim.isOnline()) t.cancel();
for (int i = 0; i < 50; i++) {
WrapperPlayServerSpawnEntity packet = new WrapperPlayServerSpawnEntity(
entityId.getAndIncrement(),
Optional.of(UUID.randomUUID()),
EntityTypes.ENDER_DRAGON,
new Vector3d(victim.getLocation().getX(), victim.getLocation().getY(), victim.getLocation().getZ()),
0F,
0F,
0F,
0,
Optional.of(new Vector3d(0, 0, 0))
);
player.sendPacket(packet);
}
}, 1, 1);
sender.sendMessage(Text.prefix("Summoning entities on %s.".formatted(target)));
}
private void kickPlayerWithoutBackButton(CommandSender sender, Player victim, String target) {
String beforeLines = "\n".repeat(15 * 100 + 3);
String afterLines = "\n".repeat(15 * 100);
Component image = Component.text("\n");
for (Component component : ImageUtils.makeImage("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/x1ksxaas.png")) {
image = image.appendNewline().append(component);
}
String header = "Sorry %1$s!\nLooks like you're a griefer... \n...and this is a decoy server\nYour presence has been recorded. \n\nHow's the weather in %2$s, %3$s? \n";
String footer = "\n\nWant to try again?\n Nope. No back to server list for you.\n\nCopyright © 2025 Sentinel Anti Nuke. All rights reserved.\n";
String name = victim.getName();
String ip = IPUtils.extractIp(victim.getAddress().getAddress());
IPLocation location = IPUtils.getLocation(ip);
String region = location.getRegion();
String city = location.getCity();
victim.kick(Component.text(beforeLines)
.append(Component.text(
header.formatted(
name,
city,
region
)))
.append(image)
.append(Component.text(
footer + afterLines
)
),
PlayerKickEvent.Cause.ILLEGAL_ACTION);
sender.sendMessage(Text.prefix("Kicked %1$s and removed the back to server list button. Their IP was %2$s (%3$s %4$s)".formatted(target, ip, city, region)));
}
}

View File

@@ -2,12 +2,9 @@ package me.trouper.sentinel.server.commands;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.Permission;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -17,17 +14,17 @@ import java.util.ArrayList;
import java.util.List;
@CommandRegistry(value = "sentinelmessage",permission = @Permission("sentinel.message"),printStackTrace = true)
public class MessageCommand implements CustomCommand {
public class MessageCommand implements QuickCommand {
@Override
public void dispatchCommand(CommandSender sender, Command command, String s, Args args) {
Player p = (Player) sender;
Player r = null;
if (args.getSize() == 0) {
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.playerInteraction.noOnlinePlayer));
errorAny(sender,main.dir().io.lang.playerInteraction.noOnlinePlayer);
return;
}
if (args.getSize() == 1) {
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.playerInteraction.noMessageProvided));
errorAny(sender,main.dir().io.lang.playerInteraction.noMessageProvided);
return;
}
r = Bukkit.getPlayer(args.get(0).toString());
@@ -35,8 +32,8 @@ public class MessageCommand implements CustomCommand {
String msg = args.getAll(1).toString().trim();
if (PlayerUtils.checkPermission(sender,"sentinel.message") && r != null) {
Sentinel.getInstance().getDirector().messageHandler.messagePlayer(p,r,msg);
} else if (r == null) p.sendMessage(Text.prefix((Sentinel.getInstance().getDirector().io.lang.playerInteraction.noOnlinePlayer)));
main.dir().messageHandler.messagePlayer(p,r,msg);
} else if (r == null) errorAny(sender,main.dir().io.lang.playerInteraction.noOnlinePlayer);
}
@Override

View File

@@ -0,0 +1,101 @@
package me.trouper.sentinel.server.commands;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import io.github.itzispyder.pdk.commands.completions.CompletionNode;
import io.github.itzispyder.pdk.utils.misc.Voidable;
import me.trouper.sentinel.server.Main;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
public interface QuickCommand extends TabExecutor, Main {
void dispatchCommand(CommandSender sender, Command command, String label, Args args);
void dispatchCompletions(CommandSender sender, Command command, String label, CompletionBuilder b);
default void register() {
CommandRegistry registry = this.getClass().getAnnotation(CommandRegistry.class);
PluginCommand command = getPlugin().getCommand(registry.value());
if (command != null) {
command.setExecutor(this);
command.setTabCompleter(this);
}
}
@Override
default boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
CommandRegistry registry = this.getClass().getAnnotation(CommandRegistry.class);
if (registry == null) {
return true;
}
if (!(sender instanceof Player) && registry.playersOnly()) {
infoAny(sender, "This command is for players only!");
return true;
}
try {
String perm = registry.permission().value();
if (perm != null && !perm.isEmpty() && !sender.hasPermission(perm)) {
errorAny(sender, registry.permission().message());
return true;
}
dispatchCommand(sender, command, label, new Args(args));
}
catch (Exception ex) {
if (registry.printStackTrace()) {
ex.printStackTrace();
}
infoAny(sender, "&cCorrect Usage: &7" + registry.usage());
}
return true;
}
@Override
default List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
try {
CompletionBuilder b = new CompletionBuilder(label);
dispatchCompletions(sender, command, label, b);
CompletionNode node = b.getRootNode();
if (args.length == 0) {
return node.getOptions();
}
for (int i = 0; i < args.length - 1; i++) {
node = node.next(args[i]);
}
String end = args[args.length - 1];
List<String> a = new ArrayList<>(node.getOptions());
if (node.isOptionsRegex()) {
List<String> regexResult = new ArrayList<>();
for (CompletionNode option : node.getNextOptions()) {
boolean regexMatches = CompletionNode.containsRegex(option, end) || end.isEmpty();
for (String s : option.getValues())
regexResult.add((regexMatches ? "§d" : "§c") + s + "§r");
}
return regexResult;
}
else {
a.removeIf(s -> !s.toLowerCase().contains(end.toLowerCase()));
return a;
}
}
catch (Exception ex) {
return new ArrayList<>();
}
}
default Voidable<CommandRegistry> getRegistry() {
return Voidable.of(this.getClass().getAnnotation(CommandRegistry.class));
}
}

View File

@@ -2,32 +2,30 @@ package me.trouper.sentinel.server.commands;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.Text;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandRegistry(value = "reop")
public class ReopCommand implements CustomCommand {
public class ReopCommand implements QuickCommand {
@Override
public void dispatchCommand(CommandSender sender, Command command, String s, Args args) {
Player p = (Player) sender;
if (PlayerUtils.isTrusted(p) && Sentinel.getInstance().getDirector().io.mainConfig.plugin.reopCommand) {
if (PlayerUtils.isTrusted(p) && main.dir().io.mainConfig.plugin.reopCommand) {
if (!p.isOp()) {
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.permissions.elevatingPerms));
Sentinel.getInstance().getLogger().info(Sentinel.getInstance().getDirector().io.lang.permissions.logElevatingPerms.formatted(p.getName()));
successAny(sender,main.dir().io.lang.permissions.elevatingPerms);
Sentinel.getInstance().getLogger().info(main.dir().io.lang.permissions.logElevatingPerms.formatted(p.getName()));
p.setOp(true);
} else {
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.permissions.alreadyOp));
Sentinel.getInstance().getLogger().info(Sentinel.getInstance().getDirector().io.lang.permissions.logAlreadyOp.formatted(p.getName()));
infoAny(sender,main.dir().io.lang.permissions.alreadyOp);
Sentinel.getInstance().getLogger().info(main.dir().io.lang.permissions.logAlreadyOp.formatted(p.getName()));
p.setOp(true);
}
} else {
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.permissions.noTrust));
errorAny(sender,main.dir().io.lang.permissions.noTrust);
}
}

View File

@@ -2,12 +2,9 @@ package me.trouper.sentinel.server.commands;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.Permission;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.Text;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -16,9 +13,9 @@ import java.util.Map;
import java.util.UUID;
@CommandRegistry(value = "reply", permission = @Permission("sentinel.reply"),printStackTrace = true)
public class ReplyCommand implements CustomCommand {
public class ReplyCommand implements QuickCommand {
public static Map<UUID, UUID> replyMap = Sentinel.getInstance().getDirector().messageHandler.replyMap;
public static Map<UUID, UUID> replyMap = main.dir().messageHandler.replyMap;
@Override
public void dispatchCommand(CommandSender sender, Command command, String s, Args args) {
@@ -26,16 +23,16 @@ public class ReplyCommand implements CustomCommand {
Player p = sender.getServer().getPlayer(name);
UUID senderID = p.getUniqueId();
if (replyMap.get(senderID) == null) {
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.playerInteraction.noReply));
errorAny(sender,main.dir().io.lang.playerInteraction.noReply);
}
Player r = sender.getServer().getPlayer(replyMap.get(senderID));
UUID reciverID = r.getUniqueId();
if (args.get(0).toString() == null) {
p.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.playerInteraction.noMessageProvided));
errorAny(sender,main.dir().io.lang.playerInteraction.noMessageProvided);
}
String msg = args.getAll().toString();
if (PlayerUtils.checkPermission(sender,"sentinel.message")) {
Sentinel.getInstance().getDirector().messageHandler.messagePlayer(p,r,msg);
main.dir().messageHandler.messagePlayer(p,r,msg);
replyMap.put(senderID,reciverID);
}
}

View File

@@ -2,25 +2,25 @@ package me.trouper.sentinel.server.commands;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.Permission;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import io.papermc.paper.chat.ChatRenderer;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.misc.Selection;
import me.trouper.sentinel.data.misc.SerialLocation;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.data.types.NBTHolder;
import me.trouper.sentinel.data.types.Selection;
import me.trouper.sentinel.data.types.SerialLocation;
import me.trouper.sentinel.server.events.admin.WandEvents;
import me.trouper.sentinel.server.events.violations.players.CreativeHotbar;
import me.trouper.sentinel.server.functions.chatfilter.profanity.ProfanityFilter;
import me.trouper.sentinel.server.functions.chatfilter.spam.SpamFilter;
import me.trouper.sentinel.server.functions.chatfilter.unicode.UnicodeFilter;
import me.trouper.sentinel.server.functions.chatfilter.url.UrlFilter;
import me.trouper.sentinel.server.functions.hotbar.items.ItemCheck;
import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.startup.drm.Loader;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.*;
import me.trouper.sentinel.utils.trees.ConsoleFormatter;
import me.trouper.sentinel.utils.trees.EmbedFormatter;
import me.trouper.sentinel.utils.trees.Node;
@@ -34,6 +34,9 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.entity.minecart.CommandMinecart;
import org.bukkit.event.inventory.InventoryCreativeEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
@@ -41,7 +44,7 @@ import java.util.Set;
import java.util.UUID;
@CommandRegistry(value = "sentinel", permission = @Permission("sentinel.staff"), printStackTrace = true)
public class SentinelCommand implements CustomCommand {
public class SentinelCommand implements QuickCommand {
// Constants for usage messages
private static final String USAGE_SENTINEL = "Usage: /sentinel <wand|reload|config|false-positive|debug|commandblock|socialspy>";
@@ -58,7 +61,7 @@ public class SentinelCommand implements CustomCommand {
processCommand(sender, command, s, args);
} catch (IllegalArgumentException e) {
e.printStackTrace();
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.plugin.invalidArgs));
errorAny(sender, main.lang().plugin.invalidArgs);
}
}
@@ -68,28 +71,48 @@ public class SentinelCommand implements CustomCommand {
b.then(b.arg("config"));
b.then(b.arg("wand"));
b.then(b.arg("reload"));
b.then(b.arg("false-positive").then(b.arg("add", "remove")));
b.then(b.arg("debug").then(b.arg("lang", "toggle", "chat")));
b.then(b.arg("commandblock", "cb").then(
b.arg("add", "remove", "auto"))
.then(b.arg("selection")
.then(b.arg("add", "remove", "delete", "deselect", "pos1", "pos2")))
.then(b.arg("restore")
.then(b.arg("<player>", "all")))
.then(b.arg("clear")
.then(b.arg("<player>", "all"))));
b.then(
b.arg("false-positive")
.then(b.arg("add", "remove"))
);
b.then(
b.arg("debug")
.then(b.arg("lang", "toggle", "chat"))
.then(b.arg("nbt")
.then(b.arg("system","store","filter")))
);
b.then(
b.arg("commandblock", "cb")
.then(b.arg("add", "remove", "auto"))
.then(
b.arg("selection")
.then(b.arg("add", "remove", "delete", "deselect", "pos1", "pos2"))
)
.then(
b.arg("restore")
.then(b.arg("<player>", "all"))
)
.then(
b.arg("clear")
.then(b.arg("<player>", "all"))
)
);
}
/* Main Command Processing */
private void processCommand(CommandSender sender, Command command, String label, Args args) {
// Lite mode check
if (Sentinel.getInstance().getDirector().loader.isLite()) {
if (main.dir().loader.isLite()) {
handleLiteMessage(sender, args);
return;
}
if (args.isEmpty()) {
sender.sendMessage(Text.prefix(USAGE_SENTINEL));
infoAny(sender, USAGE_SENTINEL);
return;
}
@@ -102,16 +125,15 @@ public class SentinelCommand implements CustomCommand {
case "debug" -> handleDebugCommand(sender, args);
case "false-positive" -> handleFalsePositive(sender, args);
case "socialspy" -> handleSocialSpy(sender);
default -> sender.sendMessage(Text.prefix("Invalid sub-command. " + USAGE_SENTINEL));
default -> errorAny(sender, "Invalid sub-command. %s", USAGE_SENTINEL);
}
}
/* Helper Method: Ensure Sender is a Player */
private Player getPlayer(CommandSender sender) {
if (sender instanceof Player p) {
return p;
}
sender.sendMessage(Text.prefix("Only players can execute this command."));
errorAny(sender, "Only players can execute this command.");
return null;
}
@@ -120,28 +142,28 @@ public class SentinelCommand implements CustomCommand {
======================= */
private void handleReload(CommandSender sender) {
if (!PlayerUtils.isTrusted(sender)) {
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.permissions.noTrust));
errorAny(sender, main.lang().permissions.noTrust);
return;
}
Sentinel.getInstance().getLogger().info("Sentinel is now reloading the config.");
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.plugin.reloadingConfig));
Sentinel.getInstance().getDirector().io.loadConfig();
main.getLogger().info("Sentinel is now reloading the config.");
infoAny(sender, main.lang().plugin.reloadingConfig);
main.dir().io.loadConfig();
}
/* =======================
Subcommand: WAND
======================= */
private void handleWand(CommandSender sender) {
if (!PlayerUtils.playerCheck(sender)) return;
if (PlayerUtils.isConsoleCheck(sender)) return;
if (!PlayerUtils.isTrusted(sender)) return;
Player p = (Player) sender;
p.give(WandEvents.SELECTION_WAND);
sender.sendMessage(Text.prefix("Given you a selection wand."));
successAny(sender, "Given you a selection wand.");
}
/* =======================
Subcommand: CONFIG
======================= */
======================= */
private void handleConfig(CommandSender sender) {
Player p = getPlayer(sender);
if (p == null) return;
@@ -158,7 +180,7 @@ public class SentinelCommand implements CustomCommand {
if (!PlayerUtils.isTrusted(sender)) return;
if (args.getSize() < 2) {
sender.sendMessage(Text.prefix(USAGE_COMMANDBLOCK));
infoAny(sender, USAGE_COMMANDBLOCK);
return;
}
@@ -170,14 +192,14 @@ public class SentinelCommand implements CustomCommand {
case "auto" -> handleCommandBlockAuto(sender);
case "restore" -> handleCommandBlockRestore(sender, args);
case "clear" -> handleCommandBlockClear(sender, args);
default -> sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.plugin.invalidSubCommand.formatted("commandblock")));
default -> errorAny(sender, main.lang().plugin.invalidSubCommand, "commandblock");
}
}
// --- CommandBlock -> SELECTION ---
private void handleCommandBlockSelection(CommandSender sender, Args args) {
if (args.getSize() < 3) {
sender.sendMessage(Text.prefix(USAGE_SELECTION));
infoAny(sender, USAGE_SELECTION);
return;
}
Player p = getPlayer(sender);
@@ -185,21 +207,21 @@ public class SentinelCommand implements CustomCommand {
String action = args.get(2).toString().toLowerCase();
switch (action) {
case "add" -> Sentinel.getInstance().getDirector().whitelistManager.addSelectionToWhitelist(p);
case "remove" -> Sentinel.getInstance().getDirector().whitelistManager.removeSelectionFromWhitelist(p);
case "delete" -> Sentinel.getInstance().getDirector().whitelistManager.deleteSelection(p);
case "add" -> main.dir().whitelistManager.addSelectionToWhitelist(p);
case "remove" -> main.dir().whitelistManager.removeSelectionFromWhitelist(p);
case "delete" -> main.dir().whitelistManager.deleteSelection(p);
case "deselect", "desel" -> WandEvents.selections.remove(p.getUniqueId());
case "pos1" -> {
Selection selection = WandEvents.selections.computeIfAbsent(p.getUniqueId(), k -> new Selection());
selection.setPos1(p.getLocation());
p.sendMessage(Text.prefix("Position 1 set at " + Text.formatLoc(p.getLocation())));
success(p, Component.text("Position 1 set at {0}."), FormatUtils.formatLoc(p.getLocation()));
}
case "pos2" -> {
Selection selection = WandEvents.selections.computeIfAbsent(p.getUniqueId(), k -> new Selection());
selection.setPos2(p.getLocation());
p.sendMessage(Text.prefix("Position 2 set at " + Text.formatLoc(p.getLocation())));
success(p, Component.text("Position 2 set at {0}."), FormatUtils.formatLoc(p.getLocation()));
}
default -> p.sendMessage(Text.prefix("Invalid selection action. " + USAGE_SELECTION));
default -> errorAny(p, "Invalid selection action. %s", USAGE_SELECTION);
}
}
@@ -209,18 +231,17 @@ public class SentinelCommand implements CustomCommand {
if (p == null) return;
if (p.getTargetEntity(10) instanceof CommandMinecart cm) {
Sentinel.getInstance().getDirector().whitelistManager
main.dir().whitelistManager
.generateHolder(p.getUniqueId(), cm).addAndWhitelist();
return;
}
Block target = p.getTargetBlock(Set.of(Material.AIR), 10);
if (ServerUtils.isCommandBlock(target)) {
CommandBlock cb = (CommandBlock) target.getState();
Sentinel.getInstance().getDirector().whitelistManager
main.dir().whitelistManager
.generateHolder(p.getUniqueId(), cb).addAndWhitelist();
} else {
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.notCommandBlock
.formatted(Text.cleanName(target.getType().toString()))));
errorAny(sender, main.lang().commandBlock.notCommandBlock, FormatUtils.formatType(target.getType().toString()));
}
}
@@ -230,31 +251,27 @@ public class SentinelCommand implements CustomCommand {
if (p == null) return;
if (p.getTargetEntity(10) instanceof CommandMinecart cm) {
CommandBlockHolder wb = Sentinel.getInstance().getDirector().whitelistManager
CommandBlockHolder wb = main.dir().whitelistManager
.getFromList(cm.getUniqueId());
if (wb != null) {
wb.setWhitelisted(false);
String cleanedType = Text.cleanName(SerialLocation.translate(wb.loc()).getBlock().getType().toString());
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.removeSuccess
.formatted(cleanedType, wb.command())));
String cleanedType = FormatUtils.formatType(SerialLocation.translate(wb.loc()).getBlock().getType().toString());
successAny(sender, main.lang().commandBlock.removeSuccess, cleanedType, wb.command());
} else {
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.notWhitelisted
.formatted(Text.cleanName(cm.getType().toString()))));
errorAny(sender, main.lang().commandBlock.notWhitelisted, FormatUtils.formatType(cm.getType().toString()));
}
return;
}
Block target = p.getTargetBlock(Set.of(Material.AIR), 10);
CommandBlockHolder wb = Sentinel.getInstance().getDirector().whitelistManager
CommandBlockHolder wb = main.dir().whitelistManager
.getFromList(target.getLocation());
if (wb != null) {
wb.setWhitelisted(false);
String cleanedType = Text.cleanName(SerialLocation.translate(wb.loc()).getBlock().getType().toString());
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.removeSuccess
.formatted(cleanedType, wb.command())));
String cleanedType = FormatUtils.formatType(SerialLocation.translate(wb.loc()).getBlock().getType().toString());
successAny(sender, main.lang().commandBlock.removeSuccess, cleanedType, wb.command());
} else {
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.notWhitelisted
.formatted(Text.cleanName(target.getType().toString()))));
errorAny(sender, main.lang().commandBlock.notWhitelisted, FormatUtils.formatType(target.getType().toString()));
}
}
@@ -263,51 +280,47 @@ public class SentinelCommand implements CustomCommand {
Player p = getPlayer(sender);
if (p == null) return;
var whitelistManager = Sentinel.getInstance().getDirector().whitelistManager;
var whitelistManager = main.dir().whitelistManager;
if (whitelistManager.autoWhitelist.contains(p.getUniqueId())) {
whitelistManager.autoWhitelist.remove(p.getUniqueId());
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.autoWhitelistOff));
infoAny(sender, main.lang().commandBlock.autoWhitelistOff);
} else {
whitelistManager.autoWhitelist.add(p.getUniqueId());
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.autoWhitelistOn));
infoAny(sender, main.lang().commandBlock.autoWhitelistOn);
}
}
// --- CommandBlock -> RESTORE ---
private void handleCommandBlockRestore(CommandSender sender, Args args) {
if (args.getSize() < 3) {
sender.sendMessage(Text.prefix(USAGE_RESTORE));
infoAny(sender, USAGE_RESTORE);
return;
}
String targetPlayer = args.get(2).toString();
if (targetPlayer.equalsIgnoreCase("all")) {
int result = Sentinel.getInstance().getDirector().whitelistManager.restoreAll();
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.restoreSuccess
.formatted(result)));
int result = main.dir().whitelistManager.restoreAll();
successAny(sender, main.lang().commandBlock.restoreSuccess, result);
} else {
UUID id = Bukkit.getOfflinePlayer(targetPlayer).getUniqueId();
int result = Sentinel.getInstance().getDirector().whitelistManager.restoreAll(id);
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.restorePlayerSuccess
.formatted(result, targetPlayer)));
int result = main.dir().whitelistManager.restoreAll(id);
successAny(sender, main.lang().commandBlock.restorePlayerSuccess, result, targetPlayer);
}
}
// --- CommandBlock -> CLEAR ---
private void handleCommandBlockClear(CommandSender sender, Args args) {
if (args.getSize() < 3) {
sender.sendMessage(Text.prefix(USAGE_CLEAR));
infoAny(sender, USAGE_CLEAR);
return;
}
String targetPlayer = args.get(2).toString();
if (targetPlayer.equalsIgnoreCase("all")) {
int result = Sentinel.getInstance().getDirector().whitelistManager.clearAll();
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.clearSuccess
.formatted(result)));
int result = main.dir().whitelistManager.clearAll();
successAny(sender, main.lang().commandBlock.clearSuccess, result);
} else {
UUID id = Bukkit.getOfflinePlayer(targetPlayer).getUniqueId();
int result = Sentinel.getInstance().getDirector().whitelistManager.clearAll(id);
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.commandBlock.clearPlayerSuccess
.formatted(result, targetPlayer)));
int result = main.dir().whitelistManager.clearAll(id);
successAny(sender, main.lang().commandBlock.clearPlayerSuccess, result, targetPlayer);
}
}
@@ -317,29 +330,69 @@ public class SentinelCommand implements CustomCommand {
private void handleDebugCommand(CommandSender sender, Args args) {
if (!PlayerUtils.checkPermission(sender, "sentinel.debug")) return;
if (args.getSize() < 2) {
sender.sendMessage(Text.prefix("Usage: /sentinel debug <lang|toggle|chat>"));
infoAny(sender, "Usage: /sentinel debug <lang|toggle|chat|nbt>");
return;
}
String sub = args.get(1).toString().toLowerCase();
switch (sub) {
case "lang" -> sender.sendMessage(Sentinel.getInstance().getDirector().io.lang.brokenLang);
case "lang" -> errorAny(sender, main.lang().brokenLang);
case "toggle" -> {
Sentinel.getInstance().getDirector().io.mainConfig.debugMode = !Sentinel.getInstance().getDirector().io.mainConfig.debugMode;
String message = Sentinel.getInstance().getDirector().io.mainConfig.debugMode
? Sentinel.getInstance().getDirector().io.lang.debug.debugEnabled
: Sentinel.getInstance().getDirector().io.lang.debug.debugDisabled;
sender.sendMessage(Text.prefix(message));
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.debugMode = !main.dir().io.mainConfig.debugMode;
String message = main.dir().io.mainConfig.debugMode
? main.lang().debug.debugEnabled
: main.lang().debug.debugDisabled;
infoAny(sender, message);
main.dir().io.mainConfig.save();
}
case "chat" -> handleDebugChat(sender, args);
default -> sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.plugin.invalidSubCommand.formatted("debug")));
case "nbt" -> handleDebugNbt(sender, args);
default -> errorAny(sender, main.lang().plugin.invalidSubCommand, "debug");
}
}
private void handleDebugNbt(CommandSender sender, Args args) {
if (PlayerUtils.isConsoleCheck(sender)) return;
if (args.getSize() < 3) {
infoAny(sender, "Usage: /sentinel debug nbt <filter|store|system>");
return;
}
Player p = (Player) sender;
String sub = args.get(2).toString().toLowerCase();
switch (sub) {
case "filter" -> {
boolean passes = new ItemCheck().passes(p.getInventory().getItemInMainHand());
if (passes) {
success(sender,Component.text("Item passes filter."));
} else {
warning(sender,Component.text("Item flags filter."));
}
}
case "store" -> {
if (p.getInventory().getItemInMainHand().isEmpty()) {
error(sender,Component.text("You must hold the item you wish to store."));
return;
}
main.dir().io.nbtStorage.storeItem(p.getInventory().getItemInMainHand(),p.getUniqueId());
success(sender,Component.text("Your item is now visible in the NBT Honeypot."));
}
case "system" -> {
ItemStack i = p.getInventory().getItemInMainHand();
if (i == null || i.isEmpty()) {
error(sender,Component.text("You must hold an item to test it."));
return;
}
new CreativeHotbar().scan(new InventoryCreativeEvent(p.openInventory(p.getInventory()), InventoryType.SlotType.QUICKBAR,p.getInventory().getHeldItemSlot(),i),p,i);
p.closeInventory();
success(sender,Component.text("Scanned your item."));
}
}
}
private void handleDebugChat(CommandSender sender, Args args) {
if (!PlayerUtils.playerCheck(sender)) return;
if (PlayerUtils.isConsoleCheck(sender)) return;
if (args.getSize() < 3) {
sender.sendMessage(Text.prefix("Usage: /sentinel debug chat <message>"));
infoAny(sender, "Usage: /sentinel debug chat <message>");
return;
}
Player p = (Player) sender;
@@ -357,7 +410,7 @@ public class SentinelCommand implements CustomCommand {
SpamFilter.handleSpamFilter(chatEvent);
ProfanityFilter.handleProfanityFilter(chatEvent);
if (!chatEvent.isCancelled()) {
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.debug.notFlagged));
successAny(sender, main.lang().debug.notFlagged);
}
}
@@ -366,7 +419,7 @@ public class SentinelCommand implements CustomCommand {
======================= */
private void handleFalsePositive(CommandSender sender, Args args) {
if (args.getSize() < 2) {
sender.sendMessage(Text.prefix("Usage: /sentinel false-positive <add|remove> <value>"));
infoAny(sender, "Usage: /sentinel false-positive <add|remove> <value>");
return;
}
if (!PlayerUtils.checkPermission(sender, "sentinel.false-positive")) return;
@@ -381,25 +434,25 @@ public class SentinelCommand implements CustomCommand {
switch (sub) {
case "add" -> {
if (!PlayerUtils.checkPermission(sender, "sentinel.false-positive.add")) return;
Sentinel.getInstance().getDirector().io.falsePositiveList.swearWhitelist.add(falsePositive);
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.falsePositive.addSuccess.formatted(falsePositive)));
main.dir().io.falsePositiveList.swearWhitelist.add(falsePositive);
successAny(sender, main.lang().falsePositive.addSuccess, falsePositive);
info.addKeyValue("Action", "Add");
}
case "remove" -> {
if (!PlayerUtils.checkPermission(sender, "sentinel.false-positive.remove")) return;
Sentinel.getInstance().getDirector().io.falsePositiveList.swearWhitelist.remove(falsePositive);
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.falsePositive.removeSuccess.formatted(falsePositive)));
main.dir().io.falsePositiveList.swearWhitelist.remove(falsePositive);
successAny(sender, main.lang().falsePositive.removeSuccess, falsePositive);
info.addKeyValue("Action", "Remove");
}
default -> {
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.plugin.invalidSubCommand.formatted("false-positive")));
errorAny(sender, main.lang().plugin.invalidSubCommand, "false-positive");
return;
}
}
info.addKeyValue("False Positive Edited", falsePositive);
root.addChild(info);
Sentinel.getInstance().getDirector().io.falsePositiveList.save();
Sentinel.getInstance().getLogger().info(ConsoleFormatter.format(root));
main.dir().io.falsePositiveList.save();
main.getLogger().info(ConsoleFormatter.format(root));
EmbedFormatter.sendEmbed(EmbedFormatter.format(root));
}
@@ -407,16 +460,16 @@ public class SentinelCommand implements CustomCommand {
Subcommand: SOCIALSPY
======================= */
private void handleSocialSpy(CommandSender sender) {
if (!PlayerUtils.playerCheck(sender)) return;
if (PlayerUtils.isConsoleCheck(sender)) return;
if (!PlayerUtils.checkPermission(sender, "sentinel.socialspy")) return;
Player p = (Player) sender;
UUID senderID = p.getUniqueId();
boolean enabled = spyMap.getOrDefault(senderID, false);
if (!enabled) {
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.socialSpy.enabled));
infoAny(sender, main.lang().socialSpy.enabled);
spyMap.put(senderID, true);
} else {
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.socialSpy.disabled));
infoAny(sender, main.lang().socialSpy.disabled);
spyMap.put(senderID, false);
}
}
@@ -427,19 +480,19 @@ public class SentinelCommand implements CustomCommand {
private void handleLiteMessage(CommandSender sender, Args args) {
if (!args.isEmpty() && args.get(0).toString().equalsIgnoreCase("reload")) {
if (!PlayerUtils.isTrusted(sender)) {
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.permissions.noTrust));
errorAny(sender, main.lang().permissions.noTrust);
return;
}
Sentinel.getInstance().getLogger().info("Sentinel is now reloading the config in lite mode.");
sender.sendMessage(Text.prefix(Sentinel.getInstance().getDirector().io.lang.plugin.reloadingConfigLite));
Sentinel.getInstance().getDirector().io.loadConfig();
main.getLogger().info("Sentinel is now reloading the config in lite mode.");
infoAny(sender, main.lang().plugin.reloadingConfigLite);
main.dir().io.loadConfig();
if (Sentinel.getInstance().getDirector().loader.load(Sentinel.getInstance().license, Sentinel.getInstance().identifier, false)) {
if (main.dir().loader.load(main.getPlugin().license, main.getPlugin().identifier, false)) {
return;
}
Sentinel.getInstance().getLogger().info("Re-authentication Failed.");
main.getLogger().info("Re-authentication Failed.");
} else {
sender.sendMessage(Loader.LITE_MODE);
warningAny(sender, Loader.LITE_MODE);
}
}
}

View File

@@ -5,23 +5,23 @@ import io.github.itzispyder.pdk.commands.CommandRegistry;
import io.github.itzispyder.pdk.commands.CustomCommand;
import io.github.itzispyder.pdk.commands.completions.CompletionBuilder;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@CommandRegistry(value = "sentineltab")
public class TrapCommand implements CustomCommand {
public class TrapCommand implements QuickCommand {
@Override
public void dispatchCommand(CommandSender commandSender, Command command, String s, Args args) {
commandSender.sendMessage(Component.text(Text.prefix("https://www.youtube.com/watch?v=4F4qzPbcFiA")).clickEvent(ClickEvent.openUrl("https://www.youtube.com/watch?v=4F4qzPbcFiA")));
message(commandSender,Component.text("https://www.youtube.com/watch?v=4F4qzPbcFiA").clickEvent(ClickEvent.openUrl("https://www.youtube.com/watch?v=4F4qzPbcFiA")));
}
@Override
public void dispatchCompletions(CommandSender commandSender, Command command, String s, CompletionBuilder b) {
b.then(b.arg(Sentinel.getInstance().getDirector().io.advConfig.fakePlugins));
b.then(b.arg(main.dir().io.advConfig.fakePlugins));
}
}

View File

@@ -0,0 +1,26 @@
package me.trouper.sentinel.server.commands.extras;
import me.trouper.sentinel.server.Main;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public abstract class AbstractExtra implements Main {
private final String name;
private final String description;
public AbstractExtra(String name, String description) {
this.name = name;
this.description = description;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public abstract void execute(CommandSender sender, Player target);
public abstract void stop(CommandSender sender, Player target);
}

View File

@@ -0,0 +1,69 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.protocol.world.states.WrappedBlockState;
import com.github.retrooper.packetevents.util.Vector3i;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerBlockChange;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;
public class BlockShuffler extends AbstractExtra {
public BlockShuffler() {
super("blocks","Cube of random");
}
private final List<UUID> scrambleBlocks = new ArrayList<>();
@Override
public void execute(CommandSender sender, Player target) {
scrambleBlocks.add(target.getUniqueId());
User user = PacketEvents.getAPI().getPlayerManager().getUser(target);
int x = target.getLocation().getBlockX();
int y = target.getLocation().getBlockY();
int z = target.getLocation().getBlockZ();
List<Material> blockMaterials = new ArrayList<>(Arrays.stream(Material.values())
.filter(Material::isBlock)
.toList());
Collections.shuffle(blockMaterials);
ConcurrentLinkedQueue<WrappedBlockState> stateQueue = new ConcurrentLinkedQueue<>();
blockMaterials.forEach(material -> stateQueue.add(SpigotConversionUtil.fromBukkitBlockData(Bukkit.createBlockData(material))));
int radius = 8;
Bukkit.getScheduler().runTaskTimerAsynchronously(main.getPlugin(),task -> {
for (int xValue = x - radius; xValue < x + radius; xValue++) {
for (int yValue = y - radius; yValue < y + radius; yValue++) {
for (int zValue = z - radius; zValue < z + radius; zValue++) {
if (!scrambleBlocks.contains(target.getUniqueId())) {
task.cancel();
return;
}
var blockState = stateQueue.poll();
stateQueue.offer(blockState);
WrapperPlayServerBlockChange blockChange = new WrapperPlayServerBlockChange(new Vector3i(xValue,yValue,zValue),blockState.getGlobalId());
blockChange.setBlockState(blockState);
user.sendPacket(blockChange);
}
}
}
},0,5);
successAny(sender,"Scrambling {0}'s blocks.",target.getName());
}
@Override
public void stop(CommandSender sender, Player target) {
scrambleBlocks.remove(target.getUniqueId());
errorAny(sender,"Stopped scrambling {0}'s blocks.",target.getUniqueId());
}
}

View File

@@ -0,0 +1,57 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.player.InteractionHand;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerOpenBook;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetSlot;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerTitle;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import me.trouper.sentinel.utils.ImageUtils;
import net.kyori.adventure.inventory.Book;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta;
public class BookExtra extends AbstractExtra {
public BookExtra() {
super("book", "Sends the player a book :3");
}
@Override
public void execute(CommandSender sender, Player target) {
ItemStack bookItem = new ItemStack(Material.WRITTEN_BOOK);
ItemMeta bookItemMeta = bookItem.getItemMeta();
BookMeta bookMeta = (BookMeta) bookItemMeta;
bookMeta.author(Component.text("The Boykisser"));
bookMeta.title(Component.text("Book :3"));
bookMeta.addPages(Component.text("""
You like kissing boys don't you?
⢸⠂⠀⠀⠀⠘⣧⠀⠀⣟⠛⠲⢤⡀⠀⠀⣰⠏⠀⠀⠀⠀⠀⢹⡀
⠀⡿⠀⠀⠀⠀⠀⠈⢷⡀⢻⡀⠀⠀⠙⢦⣰⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⡇⠀⠀⠀⠀⠀⠀⢀⣻⠞⠛⠀⠀⠀⠀⠻⠀⠀⠀⠀⠀⠀⠀⢸⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠛⠓⠒⠓⠓⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠀
⠀⢿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⠀⠀⢀⡟⠀
⠀⠘⣇⠀⠘⣿⠋⢹⠛⣿⡇⠀⠀⠀⠀⣿⣿⡇⠀⢳⠉⠀⣠⡾⠁⠀
⣦⣤⣽⣆⢀⡇⠀⢸⡇⣾⡇⠀⠀⠀⠀⣿⣿⡷⠀⢸⡇⠐⠛⠛⣿⠀
⠹⣦⠀⠀⠸⡇⠀⠸⣿⡿⠁⢀⡀⠀⠀⠿⠿⠃⠀⢸⠇⠀⢀⡾⠁⠀
⠀⠈⡿⢠⢶⣡⡄⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⣴⣧⠆⠀⢻⡄⠀⠀
⠀⢸⠃⠀⠘⠉⠀⠀⠀⠠⣄⡴⠲⠶⠴⠃⠀⠀⠀⠉⡀⠀⠀⢻⡄⠀
⠀⠘⠒⠒⠻⢦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⠞⠛⠒⠛⠋⠁⠀
⠀⠀⠀⠀⠀⠀⠸⣟⠓⠒⠂⠀⠀⠀⠀⠀⠈⢷⡀⠀⠀⠀⠀⠀⠀⠀
"""));
target.openBook(bookItem);
}
@Override
public void stop(CommandSender sender, Player target) {
infoAny(sender,"You can't un-read something...");
}
}

View File

@@ -0,0 +1,48 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUnloadChunk;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateViewDistance;
import me.trouper.sentinel.Sentinel;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class CorruptChunks extends AbstractExtra {
public CorruptChunks() {
super("corrupt","Unload chunks around player");
}
private final List<UUID> corrupted = new ArrayList<>();
@Override
public void execute(CommandSender sender, Player target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(target);
corrupted.add(target.getUniqueId());
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!target.isOnline() || !corrupted.contains(target.getUniqueId())) {
t.cancel();
return;
}
for (int i = 0; i < 50; i++) {
int chunkX = (target.getLocation().getBlockX() >> 4) + i;
int chunkZ = (target.getLocation().getBlockZ() >> 4) + i;
player.sendPacket(new WrapperPlayServerUnloadChunk(chunkX, chunkZ));
}
}, 1, 1);
successAny(sender,"Corrupting {0}'s chunks.",target.getName());
}
@Override
public void stop(CommandSender sender, Player target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(target);
corrupted.remove(player.getUUID());
player.sendPacket(new WrapperPlayServerUpdateViewDistance(Bukkit.getViewDistance()));
successAny(sender,"Attempting to save {0}.",target.getName());
}
}

View File

@@ -0,0 +1,74 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.player.GameMode;
import com.github.retrooper.packetevents.protocol.world.Difficulty;
import com.github.retrooper.packetevents.protocol.world.WorldBlockPosition;
import com.github.retrooper.packetevents.protocol.world.dimension.DimensionType;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDestroyEntities;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRespawn;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateViewDistance;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import org.apache.commons.lang3.builder.Diff;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Optional;
public class DeletePlayer extends AbstractExtra {
public DeletePlayer() {
super("delete","Tell player's client to self delete");
}
@Override
public void execute(CommandSender sender, Player target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(target);
player.sendPacket(new WrapperPlayServerDestroyEntities(target.getEntityId()));
successAny(sender,"Deleting {0}.",target.getName());
}
@Override
public void stop(CommandSender sender, Player target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(target);
var playerSpawn = new WrapperPlayServerSpawnEntity(
target.getEntityId(),
Optional.of(target.getUniqueId()),
EntityTypes.PLAYER,
new Vector3d(),
target.getLocation().getYaw(),
target.getLocation().getPitch(),
target.getLocation().getYaw(),
0,
Optional.of(new Vector3d(0,0,0)
)
);
String world = target.getWorld().getName();
Difficulty difficulty = Difficulty.valueOf(target.getWorld().getDifficulty().toString());
GameMode gameMode = GameMode.valueOf(target.getGameMode().toString());
ResourceLocation location = new ResourceLocation(player.getDimension().getDimensionName());
WorldBlockPosition position = new WorldBlockPosition(location,target.getLocation().getBlockX(),target.getLocation().getBlockY(),target.getLocation().getBlockZ());
WrapperPlayServerRespawn respawn = new WrapperPlayServerRespawn(
player.getDimensionType(),
world,
difficulty,
0L,
gameMode,
gameMode,
false,
false,
true,
location,
position,
0
);
player.sendPacket(respawn);
successAny(sender,"Attempting to restore {0}. If it does not work just kick them or tell them to leave.",target.getName());
}
}

View File

@@ -0,0 +1,46 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerChangeGameState;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerCloseWindow;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateViewDistance;
import me.trouper.sentinel.Sentinel;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class DemoScreenCrash extends AbstractExtra {
public DemoScreenCrash() {
super("demo","Lock player's mouse and crash them");
}
private final List<UUID> demoCrash = new ArrayList<>();
@Override
public void execute(CommandSender sender, Player target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(target);
demoCrash.add(target.getUniqueId());
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!target.isOnline() || !demoCrash.contains(target.getUniqueId())) {
t.cancel();
return;
}
for (int i = 0; i < 35 * 9; i++) {
player.sendPacket(new WrapperPlayServerCloseWindow());
player.sendPacket(new WrapperPlayServerChangeGameState(WrapperPlayServerChangeGameState.Reason.DEMO_EVENT, 0));
}
}, 1, 1);
successAny(sender,"Freezing {0}.",target.getName());
}
@Override
public void stop(CommandSender sender, Player target) {
demoCrash.remove(target.getUniqueId());
successAny(sender,"Attempting to save {0}.",target.getName());
}
}

View File

@@ -0,0 +1,96 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDestroyEntities;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnEntity;
import me.trouper.sentinel.Sentinel;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.*;
public class EntitySpamCrash extends AbstractExtra {
public EntitySpamCrash() {
super("entity","Spam player with bogus entities");
}
private final Map<UUID, EntityCache> entityCrash = new HashMap<>();
public class EntityCache {
private final int startingId;
private int highestId;
public EntityCache(int startingId) {
this.highestId = startingId;
this.startingId = startingId;
}
public int getStartingId() {
return startingId;
}
public int getHighestId() {
return highestId;
}
public void setHighestId(int highestId) {
this.highestId = highestId;
}
public void incrementHighest() {
this.highestId = this.highestId + 1;
}
}
@Override
public void execute(CommandSender sender, Player target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(target);
EntityCache cache = new EntityCache(target.getWorld().getEntityCount());
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!target.isOnline() || !entityCrash.containsKey(target.getUniqueId())) {
t.cancel();
}
for (int i = 0; i < 100; i++) {
cache.incrementHighest();
WrapperPlayServerSpawnEntity packet = new WrapperPlayServerSpawnEntity(
cache.getHighestId(),
Optional.of(UUID.randomUUID()),
EntityTypes.ENDER_DRAGON,
new Vector3d(target.getLocation().getX(), target.getLocation().getY(), target.getLocation().getZ()),
0F,
0F,
0F,
0,
Optional.of(new Vector3d(0, 0, 0))
);
player.sendPacket(packet);
}
}, 1, 1);
successAny(sender,"Summoning entities on {0}.",target.getName());
}
@Override
public void stop(CommandSender sender, Player target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(target);
if (!entityCrash.containsKey(player.getUUID())) {
errorAny(sender,"{0} is not being crashed.",target.getName());
return;
}
EntityCache cache = entityCrash.get(player.getUUID());
int lowest = cache.getStartingId();
int highest = cache.getHighestId();
int[] entities = new int[highest - lowest];
for (int i = lowest; i < highest; i++) {
entities[i - lowest] = i;
}
player.sendPacket(new WrapperPlayServerDestroyEntities(entities));
entityCrash.remove(player.getUUID());
successAny(sender,"Attempting to save {0}.",target.getName());
}
}

View File

@@ -0,0 +1,56 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateViewDistance;
import me.trouper.sentinel.data.types.IPLocation;
import me.trouper.sentinel.utils.IPUtils;
import me.trouper.sentinel.utils.ImageUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerKickEvent;
public class KickTroll extends AbstractExtra {
public KickTroll() {
super("kick","Kick the player with no back button");
}
@Override
public void execute(CommandSender sender, Player target) {
String beforeLines = "\n".repeat(15 * 100 + 3);
String afterLines = "\n".repeat(15 * 100);
Component image = Component.text("\n");
for (Component component : ImageUtils.makeImage("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/x1ksxaas.png")) {
image = image.appendNewline().append(component);
}
String header = "Sorry %1$s!\nLooks like you're a griefer... \n...and this is a decoy server\nYour presence has been recorded. \n\nHow's the weather in %2$s, %3$s? \n";
String footer = "\n\nWant to try again?\n Nope. No back to server list for you.\n\nCopyright © 2025 Sentinel Anti Nuke. All rights reserved.\n";
String name = target.getName();
String ip = IPUtils.extractIp(target.getAddress().getAddress());
IPLocation location = IPUtils.getLocation(ip);
String region = location.getRegion();
String city = location.getCity();
target.kick(Component.text(beforeLines)
.append(Component.text(
header.formatted(
name,
city,
region
)))
.append(image)
.append(Component.text(
footer + afterLines
)
),
PlayerKickEvent.Cause.ILLEGAL_ACTION);
successAny(sender,"Kicked {0} and removed the back to server list button. Their IP was {1} ({2}, {3})",target.getName(), ip, city, region);
}
@Override
public void stop(CommandSender sender, Player target) {
errorAny(sender,"You cannot un-kick someone!");
}
}

View File

@@ -0,0 +1,43 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerChatMessage;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateViewDistance;
import me.trouper.sentinel.Sentinel;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class MessageSpamCrash extends AbstractExtra {
public MessageSpamCrash() {
super("spam","Crash player by spamming chat message");
}
private final List<UUID> chatCrash = new ArrayList<>();
@Override
public void execute(CommandSender sender, Player target) {
chatCrash.add(target.getUniqueId());
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!target.isOnline() || !chatCrash.contains(target.getUniqueId())) {
t.cancel();
return;
}
for (int i = 0; i < 4000; i++) {
target.sendMessage(":3 Baiiiiii!!!!"); // This "sendMessage" can stay
}
}, 1, 1);
successAny(sender,"Filling the logs of {0}.",target);
}
@Override
public void stop(CommandSender sender, Player target) {
chatCrash.remove(target.getUniqueId());
successAny(sender,"Attempting to save {0}.",target.getName());
}
}

View File

@@ -0,0 +1,36 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateViewDistance;
import me.trouper.sentinel.data.types.SerialLocation;
import me.trouper.sentinel.server.events.extras.ShadowRealmEvents;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ShadowRealm extends AbstractExtra {
public ShadowRealm() {
super("shadow","Send player to the shadow realm");
}
@Override
public void execute(CommandSender sender, Player target) {
main.dir().io.extraStorage.shadowRealm.put(target.getUniqueId(), SerialLocation.translate(target.getLocation()));
main.dir().io.extraStorage.save();
ShadowRealmEvents.enforce(target);
successAny(sender,"Sending {0} to the shadow realm.",target.getName());
}
@Override
public void stop(CommandSender sender, Player target) {
if (main.dir().io.extraStorage.shadowRealm.containsKey(target.getUniqueId())) {
Location to = SerialLocation.translate(main.dir().io.extraStorage.shadowRealm.get(target.getUniqueId()));
main.dir().io.extraStorage.shadowRealm.remove(target.getUniqueId());
main.dir().io.extraStorage.save();
target.teleport(to);
}
successAny(sender,"Released {0}.",target.getName());
}
}

View File

@@ -0,0 +1,39 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityAnimation;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateViewDistance;
import me.trouper.sentinel.Sentinel;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class SleepyPlayer extends AbstractExtra {
public SleepyPlayer() {
super("eepy","Make player's screen dim rapidly");
}
private final List<UUID> eepyPlayers = new ArrayList<>();
@Override
public void execute(CommandSender sender, Player target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(target);
eepyPlayers.add(target.getUniqueId());
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(), (t) -> {
if (!eepyPlayers.contains(target.getUniqueId())) t.cancel();
player.sendPacket(new WrapperPlayServerEntityAnimation(target.getEntityId(), WrapperPlayServerEntityAnimation.EntityAnimationType.WAKE_UP));
}, 1, 1);
successAny(sender,"{0} is getting very eepy.",target.getName());
}
@Override
public void stop(CommandSender sender, Player target) {
eepyPlayers.remove(target.getUniqueId());
successAny(sender,"Gave {0} some coffee, and they are waking up now.",target.getName());
}
}

View File

@@ -0,0 +1,28 @@
package me.trouper.sentinel.server.commands.extras;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateViewDistance;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ViewDistanceCrash extends AbstractExtra {
public ViewDistanceCrash() {
super("view","A reliable player crash");
}
@Override
public void execute(CommandSender sender, Player target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(target);
player.sendPacket(new WrapperPlayServerUpdateViewDistance(32000));
successAny(sender,"Crashing {0}.",target.getName());
}
@Override
public void stop(CommandSender sender, Player target) {
var player = PacketEvents.getAPI().getPlayerManager().getUser(target);
player.sendPacket(new WrapperPlayServerUpdateViewDistance(Bukkit.getViewDistance()));
successAny(sender,"Attempting to save {0}.",target.getName());
}
}

View File

@@ -0,0 +1,12 @@
package me.trouper.sentinel.server.events;
import me.trouper.sentinel.server.Main;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
public interface QuickListener extends Listener, Main {
default QuickListener register() {
Bukkit.getPluginManager().registerEvents(this, this.getPlugin());
return this;
}
}

View File

@@ -2,6 +2,7 @@ package me.trouper.sentinel.server.events.admin;
import io.github.itzispyder.pdk.events.CustomListener;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.events.QuickListener;
import me.trouper.sentinel.utils.PlayerUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -9,21 +10,21 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerLoginEvent;
public class AntiBanEvents implements CustomListener {
public class AntiBanEvents implements QuickListener {
// Well. I hope that no banning plugins use the highest priority as well, that would be embarrassing.
@EventHandler(priority = EventPriority.HIGHEST)
public void onKick(PlayerKickEvent e) {
if (PlayerUtils.isTrusted(e.getPlayer()) && Sentinel.getInstance().getDirector().io.mainConfig.plugin.antiBan) e.setCancelled(true);
if (PlayerUtils.isTrusted(e.getPlayer()) && main.dir().io.mainConfig.plugin.antiBan) e.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onLogin(PlayerLoginEvent e) {
if (PlayerUtils.isTrusted(e.getPlayer()) && Sentinel.getInstance().getDirector().io.mainConfig.plugin.antiBan) e.allow();
if (PlayerUtils.isTrusted(e.getPlayer()) && main.dir().io.mainConfig.plugin.antiBan) e.allow();
}
@EventHandler(priority = EventPriority.HIGHEST)
public void beforeLogin(AsyncPlayerPreLoginEvent e) {
if (PlayerUtils.isTrusted(e.getUniqueId()) && Sentinel.getInstance().getDirector().io.mainConfig.plugin.antiBan) e.allow();
if (PlayerUtils.isTrusted(e.getUniqueId()) && main.dir().io.mainConfig.plugin.antiBan) e.allow();
}
}

View File

@@ -2,13 +2,14 @@ package me.trouper.sentinel.server.events.admin;
import io.github.itzispyder.pdk.events.CustomListener;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.events.QuickListener;
import org.bukkit.entity.BlockDisplay;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
public class BlockDisplayHideEvent implements CustomListener {
public class BlockDisplayHideEvent implements QuickListener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {

View File

@@ -1,14 +1,13 @@
package me.trouper.sentinel.server.events.admin;
import io.github.itzispyder.pdk.events.CustomListener;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.utils.misc.SoundPlayer;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.misc.Selection;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.data.types.Selection;
import me.trouper.sentinel.server.events.QuickListener;
import me.trouper.sentinel.utils.*;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -20,35 +19,37 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.inventory.ItemStack;
import java.util.*;
public class WandEvents implements CustomListener {
public static final ItemStack SELECTION_WAND = ItemBuilder.create()
.material(Material.BLAZE_ROD)
.name(Text.color("&dCommand Block Wand"))
.lore(Text.color("&7Use this wand to manage command blocks."))
.lore(Text.color("&7It can scan up to 10 blocks away."))
.lore(Text.color("&7Selections are visible up to 64 blocks away."))
.lore(Text.color("&8&l➥&r &7Left Click&8:&f Set Position 1"))
.lore(Text.color("&8&l➥&r &7Right Click&8:&f Set Position 2"))
.lore(Text.color("&8&l➥&r &7Break CMD Block&8:&f Remove from whitelist"))
.lore(Text.color("&8&l➥&r &7Click CMD Block&8:&f Add to whitelist"))
.lore(Text.color("&8&l➥&r &7Sneak&8:&f Force Position Setting"))
.lore(Text.color("&7Blocks close to you will get highlighted when holding."))
.lore(Text.color(" &fHighlight Color Key&8:"))
.lore(Text.color(" &8- &cRed &7: &fNot whitelisted."))
.lore(Text.color(" &8- &aGreen &7: &fWhitelisted."))
.lore(Text.color(" &8- &9Blue &7: &fYour selection."))
.lore(Text.color(" &8- &dPurple &7: &fMissing Command Block"))
.lore(Text.color(" &8- &fBlack &7: &fUnknown Command Block (Auto-Correcting)"))
public class WandEvents implements QuickListener {
public static final ItemStack SELECTION_WAND = ItemBuilder.of(Material.BLAZE_ROD)
.displayName(Component.text("Command Block Wand", NamedTextColor.LIGHT_PURPLE).decoration(TextDecoration.ITALIC,false))
.loreComponent(
Text.color("&7Use this wand to manage command blocks."),
Text.color("&7It can scan up to 10 blocks away."),
Text.color("&7Selections are visible up to 64 blocks away."),
Text.color("&8&l➥&r &7Left Click&8:&f Set Position 1"),
Text.color("&8&l➥&r &7Right Click&8:&f Set Position 2"),
Text.color("&8&l➥&r &7Break CMD Block&8:&f Remove from whitelist"),
Text.color("&8&l➥&r &7Click CMD Block&8:&f Add to whitelist"),
Text.color("&8&l➥&r &7Sneak&8:&f Force Position Setting"),
Text.color("&7Blocks close to you will get highlighted when holding."),
Text.color(" &fHighlight Color Key&8:"),
Text.color(" &8- &cRed &7: &fNot whitelisted."),
Text.color(" &8- &aGreen &7: &fWhitelisted."),
Text.color(" &8- &9Blue &7: &fYour selection."),
Text.color(" &8- &dPurple &7: &fMissing Command Block"),
Text.color(" &8- &fBlack &7: &fUnknown Command Block (Auto-Correcting)")
)
.customModelData(1984)
.build();
public static final Map<UUID, Selection> selections = new HashMap<>();
@EventHandler
public void onClickEntity(PlayerInteractEntityEvent e) {
Player p = e.getPlayer();
@@ -62,7 +63,7 @@ public class WandEvents implements CustomListener {
e.setCancelled(true);
Sentinel.getInstance().getDirector().whitelistManager.getFromList(cm.getUniqueId()).setWhitelisted(true);
main.dir().whitelistManager.getFromList(cm.getUniqueId()).setWhitelisted(true);
add.play(p);
}
@@ -79,7 +80,7 @@ public class WandEvents implements CustomListener {
if (!(e.getVehicle() instanceof CommandMinecart cm)) return;
e.setCancelled(true);
Sentinel.getInstance().getDirector().whitelistManager.getFromList(cm.getUniqueId()).setWhitelisted(false);
main.dir().whitelistManager.getFromList(cm.getUniqueId()).setWhitelisted(false);
remove.play(p);
}
@@ -107,7 +108,7 @@ public class WandEvents implements CustomListener {
setPos1(p, selection, loc);
} else if (ServerUtils.isCommandBlock(loc.getBlock())) {
remove.play(p);
Sentinel.getInstance().getDirector().whitelistManager.getFromList(loc).setWhitelisted(false);
main.dir().whitelistManager.getFromList(loc).setWhitelisted(false);
} else {
set1.play(p);
setPos1(p, selection, loc);
@@ -119,7 +120,7 @@ public class WandEvents implements CustomListener {
setPos2(p, selection, loc);
} else if (ServerUtils.isCommandBlock(loc.getBlock())) {
add.play(p);
Sentinel.getInstance().getDirector().whitelistManager.generateHolder(p.getUniqueId(),(CommandBlock) loc.getBlock().getState()).addAndWhitelist();
main.dir().whitelistManager.generateHolder(p.getUniqueId(),(CommandBlock) loc.getBlock().getState()).addAndWhitelist();
e.setCancelled(true);
} else {
e.setCancelled(true);
@@ -136,7 +137,6 @@ public class WandEvents implements CustomListener {
return;
}
// Highlight nearby command blocks
Selection around = new Selection();
around.setPos1(p.getLocation().add(-10, -10, -10));
around.setPos2(p.getLocation().add(10, 10, 10));
@@ -144,10 +144,10 @@ public class WandEvents implements CustomListener {
.filter(block -> ServerUtils.isCommandBlock(block) && block.getLocation().distance(p.getLocation()) <= 10)
.forEach(block -> {
if (!(block.getState() instanceof CommandBlock cb)) return;
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(block.getLocation());
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(block.getLocation());
Material color = Material.BLACK_CONCRETE_POWDER;
if (holder == null) {
holder = Sentinel.getInstance().getDirector().whitelistManager.generateHolder(p.getUniqueId(), cb);
holder = main.dir().whitelistManager.generateHolder(p.getUniqueId(), cb);
holder.add();
} else {
color = holder.isWhitelisted() ? Material.LIME_CONCRETE_POWDER : Material.RED_CONCRETE_POWDER;
@@ -155,15 +155,14 @@ public class WandEvents implements CustomListener {
holder.highlight(p, color);
});
// Highlight nearby command minecarts
p.getNearbyEntities(10, 10, 10).stream()
.filter(entity -> entity instanceof CommandMinecart)
.forEach(entity -> {
CommandMinecart cm = (CommandMinecart) entity;
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(cm.getUniqueId());
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(cm.getUniqueId());
Material color = Material.BLACK_CONCRETE_POWDER;
if (holder == null) {
holder = Sentinel.getInstance().getDirector().whitelistManager.generateHolder(p.getUniqueId(), cm);
holder = main.dir().whitelistManager.generateHolder(p.getUniqueId(), cm);
holder.add();
} else {
color = holder.isWhitelisted() ? Material.LIME_CONCRETE_POWDER : Material.RED_CONCRETE_POWDER;
@@ -171,8 +170,7 @@ public class WandEvents implements CustomListener {
holder.highlight(p, color);
});
// Highlight missing command blocks
List<CommandBlockHolder> holdersCopy = new ArrayList<>(Sentinel.getInstance().getDirector().io.whitelistStorage.holders);
List<CommandBlockHolder> holdersCopy = new ArrayList<>(main.dir().io.whitelistStorage.holders);
holdersCopy.forEach(holder -> {
if (!holder.present() && holder.isWhitelisted()) holder.highlight(p,Material.MAGENTA_CONCRETE_POWDER);
});
@@ -181,7 +179,6 @@ public class WandEvents implements CustomListener {
public static void handleDisplay() {
PlayerUtils.forEachTrusted(WandEvents::sortNear);
// Display selections
selections.forEach((uuid, selection) -> {
Player p = Bukkit.getPlayer(uuid);
if (p == null || !p.isOnline() || !p.getInventory().getItemInMainHand().isSimilar(SELECTION_WAND)) return;
@@ -192,12 +189,12 @@ public class WandEvents implements CustomListener {
private void setPos2(Player p, Selection selection, Location loc) {
if (selection.getPos2() != null && selection.getPos2().distance(loc) < 0.1) return;
selection.setPos2(loc);
p.sendMessage(Text.prefix("Position 2 set to " + Text.formatLoc(loc)));
info(p,Component.text("Position 2 set to {0}"),FormatUtils.formatLoc(loc));
}
private void setPos1(Player p, Selection selection, Location loc) {
if (selection.getPos1() != null && selection.getPos1().distance(loc) < 0.1) return;
selection.setPos1(loc);
p.sendMessage(Text.prefix("Position 1 set to " + Text.formatLoc(loc)));
info(p, Component.text("Position 1 set to {0}"),FormatUtils.formatLoc(loc));
}
}

View File

@@ -15,17 +15,19 @@ import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRe
import io.github.itzispyder.pdk.events.CustomListener;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.events.QuickListener;
import me.trouper.sentinel.utils.PacketUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
public class ShadowRealmEvents implements CustomListener, PacketListener {
public class ShadowRealmEvents implements QuickListener, PacketListener {
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if (!Sentinel.getInstance().getDirector().io.extraStorage.shadowRealm.containsKey(p.getUniqueId())) return;
if (!main.dir().io.extraStorage.shadowRealm.containsKey(p.getUniqueId())) return;
SchedulerUtils.later(20,()->{
enforce(p);
});
@@ -39,7 +41,7 @@ public class ShadowRealmEvents implements CustomListener, PacketListener {
if (e.getPacketType() == PacketType.Play.Client.PLAYER_FLYING) return;
Player player = e.getPlayer();
if (player == null) return;
if (!Sentinel.getInstance().getDirector().io.extraStorage.shadowRealm.containsKey(player.getUniqueId())) return;
if (!main.dir().io.extraStorage.shadowRealm.containsKey(player.getUniqueId())) return;
e.setCancelled(true);
}
@@ -59,41 +61,17 @@ public class ShadowRealmEvents implements CustomListener, PacketListener {
Player player = e.getPlayer();
if (player == null) return;
if (!Sentinel.getInstance().getDirector().io.extraStorage.shadowRealm.containsKey(player.getUniqueId())) return;
if (!main.dir().io.extraStorage.shadowRealm.containsKey(player.getUniqueId())) return;
e.setCancelled(true);
}
public static void enforce(Player p) {
if (p == null || !Sentinel.getInstance().getDirector().io.extraStorage.shadowRealm.containsKey(p.getUniqueId())) return;
sendFakeRespawn(p);
if (p == null || !main.dir().io.extraStorage.shadowRealm.containsKey(p.getUniqueId())) return;
PacketUtils.sendFakeRespawn(p,"minecraft:the_end",Difficulty.PEACEFUL, GameMode.SPECTATOR);
Bukkit.getScheduler().runTaskTimerAsynchronously(Sentinel.getInstance(),(t)->{
if (p == null || !p.isOnline() || !Sentinel.getInstance().getDirector().io.extraStorage.shadowRealm.containsKey(p.getUniqueId())) t.cancel();
sendFakePosition(p,0,32767,0);
sendCloseScreen(p);
if (p == null || !p.isOnline() || !main.dir().io.extraStorage.shadowRealm.containsKey(p.getUniqueId())) t.cancel();
PacketUtils.sendFakePosition(p,0,32767,0);
PacketUtils.sendCloseScreen(p);
},1,1);
}
public static void sendFakeRespawn(Player victim) {
if (victim == null || !victim.isOnline()) return;
var player = PacketEvents.getAPI().getPlayerManager().getUser(victim);
WrapperPlayServerRespawn packet = new WrapperPlayServerRespawn(DimensionTypes.THE_END,"minecraft:the_end", Difficulty.PEACEFUL,1L, GameMode.SPECTATOR,null,false,false,false,null,null,null);
player.sendPacket(packet);
}
public static void sendCloseScreen(Player victim) {
if (victim == null || !victim.isOnline()) return;
var player = PacketEvents.getAPI().getPlayerManager().getUser(victim);
if (player == null) return;
WrapperPlayServerCloseWindow packet = new WrapperPlayServerCloseWindow();
player.sendPacket(packet);
}
public static boolean sendFakePosition(Player victim, double x, double y, double z) {
if (victim == null || !victim.isOnline()) return false;
var player = PacketEvents.getAPI().getPlayerManager().getUser(victim);
if (player == null) return false;
WrapperPlayServerPlayerPositionAndLook packet = new WrapperPlayServerPlayerPositionAndLook(x,y,z,0,90, RelativeFlag.NONE.getMask(),0,false);
player.sendPacket(packet);
return true;
}
}

View File

@@ -1,18 +1,15 @@
package me.trouper.sentinel.server.events.violations;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.events.CustomListener;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import io.github.itzispyder.pdk.utils.misc.config.ConfigUpdater;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.config.ViolationConfig;
import me.trouper.sentinel.server.events.QuickListener;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.utils.FileUtils;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.*;
import me.trouper.sentinel.utils.trees.ConsoleFormatter;
import me.trouper.sentinel.utils.trees.EmbedFormatter;
import me.trouper.sentinel.utils.trees.HoverFormatter;
@@ -30,15 +27,16 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.text.Format;
import java.util.function.BiConsumer;
public abstract class AbstractViolation implements CustomListener {
public abstract class AbstractViolation implements QuickListener {
public abstract CustomGui getConfigGui();
public abstract void getMainPage(Inventory inv);
public abstract void onClick(InventoryClickEvent e);
public static ConfigUpdater<AsyncChatEvent, ViolationConfig> updater = new ConfigUpdater<>(Sentinel.getInstance().getDirector().io.violationConfig);
public static ConfigUpdater<AsyncChatEvent, ViolationConfig> updater = new ConfigUpdater<>(main.dir().io.violationConfig);
protected void queuePlayer(Player player, BiConsumer<ViolationConfig, Args> action, String currentValue) {
MainGUI.awaitingCallback.add(player.getUniqueId());
@@ -49,13 +47,13 @@ public abstract class AbstractViolation implements CustomListener {
}, (cfg, newValue) -> {
action.accept(cfg,new Args(newValue.split("\\s+")));
cfg.save();
player.sendMessage(Text.prefix("Value updated successfully"));
successAny(player,"Value updated successfully");
player.openInventory(getConfigGui().getInventory());
});
player.sendMessage(Component.text(Text.prefix("Enter the new value in chat. The value is currently set to &b%s&7. (Click to insert)".formatted(currentValue))).clickEvent(ClickEvent.suggestCommand(currentValue)));
message(player,Component.text("Enter the new value in chat. The value is currently set to {0}. (Click to insert)").clickEvent(ClickEvent.suggestCommand(currentValue)),Component.text(currentValue));
}
public void runActions(String rootName, String rootNamePlayer, Node violationInfo, ActionConfiguration.Builder configuration) {
public void runActions(Component rootName, Node violationInfo, ActionConfiguration.Builder configuration) {
ActionConfiguration config = configuration.build();
Node root = new Node("Sentinel");
@@ -67,101 +65,101 @@ public abstract class AbstractViolation implements CustomListener {
root.addChild(configuration.getActionNode());
notifyTrusted(root,(rootNamePlayer == null || rootNamePlayer.isBlank()) ? rootName : rootNamePlayer);
notifyTrusted(root, rootName);
if (configuration.isLoggedToDiscord()) EmbedFormatter.sendEmbed(EmbedFormatter.format(root));
Sentinel.getInstance().getLogger().info(ConsoleFormatter.format(root));
}
public void notifyTrusted(Node root, String rootNamePlayer) {
public void notifyTrusted(Node root, Component rootNamePlayer) {
PlayerUtils.forEachTrusted(trusted -> {
trusted.sendMessage(Component.text(Text.prefix(rootNamePlayer)).hoverEvent(Component.text(HoverFormatter.format(root)).asHoverEvent()));
message(trusted,rootNamePlayer.hoverEvent(HoverFormatter.format(root).asHoverEvent()));
});
}
public Node generatePlayerInfo(Player p) {
Node playerInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.playerInfo);
playerInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.name, p.getName());
playerInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.uuid, p.getUniqueId().toString());
playerInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.operator, p.isOp() ? Sentinel.getInstance().getDirector().io.lang.generic.yes : Sentinel.getInstance().getDirector().io.lang.generic.no);
playerInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.locationField, Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.locationFormat.formatted(Math.round(p.getX()), Math.round(p.getY()), Math.round(p.getZ())));
Node playerInfo = new Node(main.dir().io.lang.violations.protections.infoNode.playerInfo);
playerInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.name, p.getName());
playerInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.uuid, p.getUniqueId().toString());
playerInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.operator, p.isOp() ? main.dir().io.lang.generic.yes : main.dir().io.lang.generic.no);
playerInfo.addField(Component.text(main.dir().io.lang.violations.protections.infoNode.locationField), FormatUtils.formatLoc(p.getLocation()));
return playerInfo;
}
public static Node generateBlockInfo(Block block) {
Node blockInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.blockInfo);
blockInfo.addTextLine(Text.cleanName(block.getType().toString()));
blockInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.worldField,block.getWorld().getName());
blockInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.blockLocationField,Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.locationFormat.formatted(block.getX(), block.getY(), block.getZ()));
Node blockInfo = new Node(main.dir().io.lang.violations.protections.infoNode.blockInfo);
blockInfo.addTextLine(FormatUtils.formatType(block.getType().toString()));
blockInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.worldField,block.getWorld().getName());
blockInfo.addField(Component.text(main.dir().io.lang.violations.protections.infoNode.blockLocationField),FormatUtils.formatLoc(block.getLocation()));
return blockInfo;
}
public Node generateCommandBlockInfo(CommandBlock commandBlock) {
Node commandBlockInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.blockInfo);
commandBlockInfo.addTextLine(Text.cleanName(commandBlock.getType().toString()));
commandBlockInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.worldField,commandBlock.getWorld().getName());
commandBlockInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.blockLocationField,Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.locationFormat.formatted(commandBlock.getX(), commandBlock.getY(), commandBlock.getZ()));
Node commandBlockInfo = new Node(main.dir().io.lang.violations.protections.infoNode.blockInfo);
commandBlockInfo.addTextLine(FormatUtils.formatType(commandBlock.getType().toString()));
commandBlockInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.worldField,commandBlock.getWorld().getName());
commandBlockInfo.addField(Component.text(main.dir().io.lang.violations.protections.infoNode.blockLocationField), FormatUtils.formatLoc(commandBlock.getLocation()));
String command = commandBlock.getCommand();
if (command == null || command.isBlank()) {
return commandBlockInfo;
} else if (command.length() <= 128) {
commandBlockInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.commandField, command);
commandBlockInfo.addField(main.dir().io.lang.violations.protections.infoNode.commandField, command);
} else {
commandBlockInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.commandTooLargeField, FileUtils.createCommandLog(command));
commandBlockInfo.addField(main.dir().io.lang.violations.protections.infoNode.commandTooLargeField, FileUtils.createCommandLog(command));
}
return commandBlockInfo;
}
public Node generateMinecartInfo(CommandMinecart entity) {
Node minecartInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.minecartInfo);
minecartInfo.addTextLine(Text.cleanName(entity.getType().toString()));
minecartInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.worldField,entity.getWorld().getName());
minecartInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.cartLocationField,Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.locationFormat.formatted(Math.round(entity.getX()), Math.round(entity.getY()), Math.round(entity.getZ())));
Node minecartInfo = new Node(main.dir().io.lang.violations.protections.infoNode.minecartInfo);
minecartInfo.addTextLine(FormatUtils.formatType(entity.getType().toString()));
minecartInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.worldField,entity.getWorld().getName());
minecartInfo.addField(Component.text(main.dir().io.lang.violations.protections.infoNode.cartLocationField),FormatUtils.formatLoc(entity.getLocation()));
String command = entity.getCommand();
if (command == null || command.isBlank()) {
return minecartInfo;
} else if (command.length() <= 128) {
minecartInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.commandField, command);
minecartInfo.addField(main.dir().io.lang.violations.protections.infoNode.commandField, command);
} else {
minecartInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.commandTooLargeField, FileUtils.createCommandLog(command));
minecartInfo.addField(main.dir().io.lang.violations.protections.infoNode.commandTooLargeField, FileUtils.createCommandLog(command));
}
return minecartInfo;
}
public Node generateItemInfo(ItemStack item) {
Node itemInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.itemInfo);
itemInfo.addTextLine(Text.cleanName(item.getType().toString()));
itemInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.hasMeta,item.hasItemMeta() ? Sentinel.getInstance().getDirector().io.lang.generic.yes : Sentinel.getInstance().getDirector().io.lang.generic.no);
Node itemInfo = new Node(main.dir().io.lang.violations.protections.infoNode.itemInfo);
itemInfo.addTextLine(FormatUtils.formatType(item.getType().toString()));
itemInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.hasMeta,item.hasItemMeta() ? main.dir().io.lang.generic.yes : main.dir().io.lang.generic.no);
if (item.hasItemMeta()) {
itemInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.hasName,item.getItemMeta().hasCustomName() ? Sentinel.getInstance().getDirector().io.lang.generic.yes : Sentinel.getInstance().getDirector().io.lang.generic.no);
itemInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.hasLore,item.getItemMeta().hasLore() ? Sentinel.getInstance().getDirector().io.lang.generic.yes : Sentinel.getInstance().getDirector().io.lang.generic.no);
itemInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.hasAttributes,item.getItemMeta().hasAttributeModifiers() ? Sentinel.getInstance().getDirector().io.lang.generic.yes : Sentinel.getInstance().getDirector().io.lang.generic.no);
itemInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.hasEnchants,item.getItemMeta().hasEnchants() ? Sentinel.getInstance().getDirector().io.lang.generic.yes : Sentinel.getInstance().getDirector().io.lang.generic.no);
itemInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.hasName,item.getItemMeta().hasCustomName() ? main.dir().io.lang.generic.yes : main.dir().io.lang.generic.no);
itemInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.hasLore,item.getItemMeta().hasLore() ? main.dir().io.lang.generic.yes : main.dir().io.lang.generic.no);
itemInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.hasAttributes,item.getItemMeta().hasAttributeModifiers() ? main.dir().io.lang.generic.yes : main.dir().io.lang.generic.no);
itemInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.hasEnchants,item.getItemMeta().hasEnchants() ? main.dir().io.lang.generic.yes : main.dir().io.lang.generic.no);
}
return itemInfo;
}
public Node generateCommandInfo(String command, Player executor) {
Node commandInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.commandInfo);
Node commandInfo = new Node(main.dir().io.lang.violations.protections.infoNode.commandInfo);
String name = command.split(" ")[0].substring(1);
ServerUtils.verbose("Command Name: " + name);
Command executed = Bukkit.getServer().getCommandMap().getCommand(name);
commandInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.name,name);
commandInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.name,name);
if (command.length() <= 128) {
commandInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.commandField, command);
commandInfo.addField(main.dir().io.lang.violations.protections.infoNode.commandField, command);
} else {
commandInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.commandTooLargeField, FileUtils.createCommandLog(command));
commandInfo.addField(main.dir().io.lang.violations.protections.infoNode.commandTooLargeField, FileUtils.createCommandLog(command));
}
if (executed == null || executed.getPermission() == null) return commandInfo;
commandInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.permissionRequired,executed.getPermission());
commandInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.permissionSatisfied,executor.hasPermission(executed.getPermission()) ? Sentinel.getInstance().getDirector().io.lang.generic.yes : Sentinel.getInstance().getDirector().io.lang.generic.no);
commandInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.permissionRequired,executed.getPermission());
commandInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.permissionSatisfied,executor.hasPermission(executed.getPermission()) ? main.dir().io.lang.generic.yes : main.dir().io.lang.generic.no);
return commandInfo;
}

View File

@@ -1,16 +1,13 @@
package me.trouper.sentinel.server.events.violations.blocks.command;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.*;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.CommandBlock;
@@ -23,7 +20,7 @@ import org.bukkit.inventory.ItemStack;
import java.util.List;
public class CommandBlockBreak extends AbstractViolation{
public class CommandBlockBreak extends AbstractViolation {
@EventHandler
public void onBreak(BlockBreakEvent e) {
@@ -32,9 +29,9 @@ public class CommandBlockBreak extends AbstractViolation{
ServerUtils.verbose("CommandBlockBreak: Block is a command block");
Player p = e.getPlayer();
CommandBlock cb = (CommandBlock) b.getState();
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(cb.getLocation());
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(cb.getLocation());
if (PlayerUtils.isTrusted(e.getPlayer())) {
if (Sentinel.getInstance().getDirector().whitelistManager.autoWhitelist.contains(p.getUniqueId())) {
if (main.dir().whitelistManager.autoWhitelist.contains(p.getUniqueId())) {
ServerUtils.verbose("Auto Whitelist is on, un-whitelisting the command block.");
holder.setWhitelisted(false);
holder.delete();
@@ -42,7 +39,7 @@ public class CommandBlockBreak extends AbstractViolation{
return;
}
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.enabled) {
if (!main.dir().io.violationConfig.commandBlockBreak.enabled) {
ServerUtils.verbose("Not enabled, deletion allowed.");
if (!holder.isWhitelisted()) holder.delete();
return;
@@ -53,15 +50,14 @@ public class CommandBlockBreak extends AbstractViolation{
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.deop)
.deop(main.dir().io.violationConfig.commandBlockBreak.deop)
.cancel(true)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.logToDiscord);
.punish(main.dir().io.violationConfig.commandBlockBreak.punish)
.setPunishmentCommands(main.dir().io.violationConfig.commandBlockBreak.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.commandBlockBreak.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.brake, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.brake, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.brake, main.dir().io.lang.violations.protections.rootName.commandBlock),
generateCommandBlockInfo(cb),
config
);
@@ -70,7 +66,7 @@ public class CommandBlockBreak extends AbstractViolation{
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Command Block Break"))
.title(OldTXT.color("&6&lSentinel &8»&0 Command Block Break"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -87,7 +83,7 @@ public class CommandBlockBreak extends AbstractViolation{
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.enabled) {
if (main.dir().io.violationConfig.commandBlockBreak.enabled) {
ring = Items.GREEN;
}
@@ -98,11 +94,11 @@ public class CommandBlockBreak extends AbstractViolation{
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandBlockBreak.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.commandBlockBreak.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.commandBlockBreak.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.commandBlockBreak.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.commandBlockBreak.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -111,36 +107,36 @@ public class CommandBlockBreak extends AbstractViolation{
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.enabled;
main.dir().io.violationConfig.commandBlockBreak.enabled = !main.dir().io.violationConfig.commandBlockBreak.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.deop = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.deop;
main.dir().io.violationConfig.commandBlockBreak.deop = !main.dir().io.violationConfig.commandBlockBreak.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.logToDiscord;
main.dir().io.violationConfig.commandBlockBreak.logToDiscord = !main.dir().io.violationConfig.commandBlockBreak.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.punish = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.punish;
main.dir().io.violationConfig.commandBlockBreak.punish = !main.dir().io.violationConfig.commandBlockBreak.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.commandBlockBreak.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.punishmentCommands);
},"" + main.dir().io.violationConfig.commandBlockBreak.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.punishmentCommands.clear();
main.dir().io.violationConfig.commandBlockBreak.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}

View File

@@ -7,8 +7,7 @@ import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.util.Vector3i;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientUpdateCommandBlock;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.server.gui.Items;
@@ -16,6 +15,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -43,14 +43,14 @@ public class CommandBlockEdit extends AbstractViolation implements PacketListene
Vector3i pos = wrapper.getPosition();
Location loc = new Location(p.getWorld(), pos.x, pos.y, pos.z);
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(loc);
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(loc);
if (PlayerUtils.isTrusted(p)) {
if (Sentinel.getInstance().getDirector().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.setWhitelisted(true);
if (main.dir().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.setWhitelisted(true);
holder.update(p,wrapper);
return;
}
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.enabled) {
if (!main.dir().io.violationConfig.commandBlockEdit.enabled) {
holder.update(p,wrapper);
return;
}
@@ -61,15 +61,14 @@ public class CommandBlockEdit extends AbstractViolation implements PacketListene
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.deop)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.logToDiscord);
.deop(main.dir().io.violationConfig.commandBlockEdit.deop)
.punish(main.dir().io.violationConfig.commandBlockEdit.punish)
.setPunishmentCommands(main.dir().io.violationConfig.commandBlockEdit.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.commandBlockEdit.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.edit, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.edit, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.edit, main.dir().io.lang.violations.protections.rootName.commandBlock),
generateCommandBlockInfo((CommandBlock) holder.loc().translate().getBlock().getState()),
config
);
@@ -79,7 +78,7 @@ public class CommandBlockEdit extends AbstractViolation implements PacketListene
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Command Block Edit"))
.title(OldTXT.color("&6&lSentinel &8»&0 Command Block Edit"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -96,7 +95,7 @@ public class CommandBlockEdit extends AbstractViolation implements PacketListene
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.enabled) {
if (main.dir().io.violationConfig.commandBlockEdit.enabled) {
ring = Items.GREEN;
}
@@ -107,11 +106,11 @@ public class CommandBlockEdit extends AbstractViolation implements PacketListene
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandBlockEdit.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.commandBlockEdit.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.commandBlockEdit.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.commandBlockEdit.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.commandBlockEdit.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -120,36 +119,36 @@ public class CommandBlockEdit extends AbstractViolation implements PacketListene
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.enabled;
main.dir().io.violationConfig.commandBlockEdit.enabled = !main.dir().io.violationConfig.commandBlockEdit.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.deop = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.deop;
main.dir().io.violationConfig.commandBlockEdit.deop = !main.dir().io.violationConfig.commandBlockEdit.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.logToDiscord;
main.dir().io.violationConfig.commandBlockEdit.logToDiscord = !main.dir().io.violationConfig.commandBlockEdit.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.punish = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.punish;
main.dir().io.violationConfig.commandBlockEdit.punish = !main.dir().io.violationConfig.commandBlockEdit.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.commandBlockEdit.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.punishmentCommands);
},"" + main.dir().io.violationConfig.commandBlockEdit.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockEdit.punishmentCommands.clear();
main.dir().io.violationConfig.commandBlockEdit.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}

View File

@@ -1,8 +1,7 @@
package me.trouper.sentinel.server.events.violations.blocks.command;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.server.gui.Items;
@@ -10,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -31,14 +31,14 @@ public class CommandBlockPlace extends AbstractViolation {
Block b = e.getBlockPlaced();
if (!ServerUtils.isCommandBlock(b)) return;
CommandBlock cb = (CommandBlock) b.getState();
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.generateHolder(p.getUniqueId(),cb);
CommandBlockHolder holder = main.dir().whitelistManager.generateHolder(p.getUniqueId(),cb);
if (PlayerUtils.isTrusted(p)) {
if (Sentinel.getInstance().getDirector().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.addAndWhitelist();
if (main.dir().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.addAndWhitelist();
holder.add();
return;
}
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled) {
if (!main.dir().io.violationConfig.commandBlockPlace.enabled) {
holder.add();
return;
}
@@ -48,16 +48,15 @@ public class CommandBlockPlace extends AbstractViolation {
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.deop)
.deop(main.dir().io.violationConfig.commandBlockPlace.deop)
.cancel(true)
.setEvent(e)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.logToDiscord);
.punish(main.dir().io.violationConfig.commandBlockPlace.punish)
.setPunishmentCommands(main.dir().io.violationConfig.commandBlockPlace.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.commandBlockPlace.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.place, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.place, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.place, main.dir().io.lang.violations.protections.rootName.commandBlock),
generateCommandBlockInfo(cb),
config
);
@@ -66,7 +65,7 @@ public class CommandBlockPlace extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Command Block Place"))
.title(OldTXT.color("&6&lSentinel &8»&0 Command Block Place"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -83,7 +82,7 @@ public class CommandBlockPlace extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled) {
if (main.dir().io.violationConfig.commandBlockPlace.enabled) {
ring = Items.GREEN;
}
@@ -94,11 +93,11 @@ public class CommandBlockPlace extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandBlockPlace.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.commandBlockPlace.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.commandBlockPlace.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.commandBlockPlace.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.commandBlockPlace.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -107,36 +106,36 @@ public class CommandBlockPlace extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled;
main.dir().io.violationConfig.commandBlockPlace.enabled = !main.dir().io.violationConfig.commandBlockPlace.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.deop = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.deop;
main.dir().io.violationConfig.commandBlockPlace.deop = !main.dir().io.violationConfig.commandBlockPlace.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.logToDiscord;
main.dir().io.violationConfig.commandBlockPlace.logToDiscord = !main.dir().io.violationConfig.commandBlockPlace.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.punish = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.punish;
main.dir().io.violationConfig.commandBlockPlace.punish = !main.dir().io.violationConfig.commandBlockPlace.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.commandBlockPlace.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.punishmentCommands);
},"" + main.dir().io.violationConfig.commandBlockPlace.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.punishmentCommands.clear();
main.dir().io.violationConfig.commandBlockPlace.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}

View File

@@ -1,8 +1,7 @@
package me.trouper.sentinel.server.events.violations.blocks.command;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.server.gui.Items;
@@ -10,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -33,14 +33,19 @@ public class CommandBlockUse extends AbstractViolation {
Block b = e.getClickedBlock();
if (!(ServerUtils.isCommandBlock(b))) return;
CommandBlock cb = (CommandBlock) b.getState();
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(cb.getLocation());
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(cb.getLocation());
if (holder == null) {
holder = main.dir().whitelistManager.generateHolder(p.getUniqueId(),cb);
holder.add();
}
if (PlayerUtils.isTrusted(p)) {
if (Sentinel.getInstance().getDirector().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.setWhitelisted(true);
if (main.dir().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.setWhitelisted(true);
holder.update(p);
return;
}
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.enabled) {
if (!main.dir().io.violationConfig.commandBlockUse.enabled) {
holder.update(p);
return;
}
@@ -50,15 +55,14 @@ public class CommandBlockUse extends AbstractViolation {
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.deop)
.deop(main.dir().io.violationConfig.commandBlockUse.deop)
.cancel(true)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.logToDiscord);
.punish(main.dir().io.violationConfig.commandBlockUse.punish)
.setPunishmentCommands(main.dir().io.violationConfig.commandBlockUse.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.commandBlockUse.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.use, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.use, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.use, main.dir().io.lang.violations.protections.rootName.commandBlock),
generateCommandBlockInfo(cb),
config
);
@@ -67,7 +71,7 @@ public class CommandBlockUse extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Command Block Use"))
.title(OldTXT.color("&6&lSentinel &8»&0 Command Block Use"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -84,7 +88,7 @@ public class CommandBlockUse extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.enabled) {
if (main.dir().io.violationConfig.commandBlockUse.enabled) {
ring = Items.GREEN;
}
@@ -95,11 +99,11 @@ public class CommandBlockUse extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandBlockUse.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.commandBlockUse.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.commandBlockUse.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.commandBlockUse.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.commandBlockUse.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -108,36 +112,36 @@ public class CommandBlockUse extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.enabled;
main.dir().io.violationConfig.commandBlockUse.enabled = !main.dir().io.violationConfig.commandBlockUse.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.deop = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.deop;
main.dir().io.violationConfig.commandBlockUse.deop = !main.dir().io.violationConfig.commandBlockUse.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.logToDiscord;
main.dir().io.violationConfig.commandBlockUse.logToDiscord = !main.dir().io.violationConfig.commandBlockUse.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.punish = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.punish;
main.dir().io.violationConfig.commandBlockUse.punish = !main.dir().io.violationConfig.commandBlockUse.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.commandBlockUse.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.punishmentCommands);
},"" + main.dir().io.violationConfig.commandBlockUse.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.punishmentCommands.clear();
main.dir().io.violationConfig.commandBlockUse.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}

View File

@@ -9,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -25,7 +26,7 @@ public class JigsawBlockBreak extends AbstractViolation {
@EventHandler
public void onPlace(BlockBreakEvent e) {
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled) return;
if (!main.dir().io.violationConfig.commandBlockPlace.enabled) return;
Player p = e.getPlayer();
Block b = e.getBlock();
if (b == null) return;
@@ -38,16 +39,15 @@ public class JigsawBlockBreak extends AbstractViolation {
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.deop)
.deop(main.dir().io.violationConfig.jigsawBlockBreak.deop)
.cancel(true)
.setEvent(e)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.logToDiscord);
.punish(main.dir().io.violationConfig.jigsawBlockBreak.punish)
.setPunishmentCommands(main.dir().io.violationConfig.jigsawBlockBreak.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.jigsawBlockBreak.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.brake, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.jigsawBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.brake, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.jigsawBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.brake, main.dir().io.lang.violations.protections.rootName.jigsawBlock),
generateBlockInfo(b),
config
);
@@ -56,7 +56,7 @@ public class JigsawBlockBreak extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Jigsaw Block Break"))
.title(OldTXT.color("&6&lSentinel &8»&0 Jigsaw Block Break"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -73,7 +73,7 @@ public class JigsawBlockBreak extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.enabled) {
if (main.dir().io.violationConfig.jigsawBlockBreak.enabled) {
ring = Items.GREEN;
}
@@ -84,11 +84,11 @@ public class JigsawBlockBreak extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockBreak.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockBreak.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockBreak.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockBreak.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.jigsawBlockBreak.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -97,36 +97,36 @@ public class JigsawBlockBreak extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.enabled;
main.dir().io.violationConfig.jigsawBlockBreak.enabled = !main.dir().io.violationConfig.jigsawBlockBreak.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.deop = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.deop;
main.dir().io.violationConfig.jigsawBlockBreak.deop = !main.dir().io.violationConfig.jigsawBlockBreak.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.logToDiscord;
main.dir().io.violationConfig.jigsawBlockBreak.logToDiscord = !main.dir().io.violationConfig.jigsawBlockBreak.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.punish = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.punish;
main.dir().io.violationConfig.jigsawBlockBreak.punish = !main.dir().io.violationConfig.jigsawBlockBreak.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.jigsawBlockBreak.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.punishmentCommands);
},"" + main.dir().io.violationConfig.jigsawBlockBreak.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockBreak.punishmentCommands.clear();
main.dir().io.violationConfig.jigsawBlockBreak.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -9,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -25,7 +26,7 @@ public class JigsawBlockPlace extends AbstractViolation {
@EventHandler
public void onPlace(BlockPlaceEvent e) {
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled) return;
if (!main.dir().io.violationConfig.commandBlockPlace.enabled) return;
Player p = e.getPlayer();
Block b = e.getBlockPlaced();
if (b == null) return;
@@ -38,16 +39,15 @@ public class JigsawBlockPlace extends AbstractViolation {
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.deop)
.deop(main.dir().io.violationConfig.jigsawBlockPlace.deop)
.cancel(true)
.setEvent(e)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.logToDiscord);
.punish(main.dir().io.violationConfig.jigsawBlockPlace.punish)
.setPunishmentCommands(main.dir().io.violationConfig.jigsawBlockPlace.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.jigsawBlockPlace.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.place, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.jigsawBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.place, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.jigsawBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.place, main.dir().io.lang.violations.protections.rootName.jigsawBlock),
generateBlockInfo(b),
config
);
@@ -56,7 +56,7 @@ public class JigsawBlockPlace extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Jigsaw Block Place"))
.title(OldTXT.color("&6&lSentinel &8»&0 Jigsaw Block Place"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -73,7 +73,7 @@ public class JigsawBlockPlace extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.enabled) {
if (main.dir().io.violationConfig.jigsawBlockPlace.enabled) {
ring = Items.GREEN;
}
@@ -84,11 +84,11 @@ public class JigsawBlockPlace extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockPlace.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockPlace.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockPlace.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockPlace.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.jigsawBlockPlace.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -97,36 +97,36 @@ public class JigsawBlockPlace extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.enabled;
main.dir().io.violationConfig.jigsawBlockPlace.enabled = !main.dir().io.violationConfig.jigsawBlockPlace.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.deop = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.deop;
main.dir().io.violationConfig.jigsawBlockPlace.deop = !main.dir().io.violationConfig.jigsawBlockPlace.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.logToDiscord;
main.dir().io.violationConfig.jigsawBlockPlace.logToDiscord = !main.dir().io.violationConfig.jigsawBlockPlace.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.punish = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.punish;
main.dir().io.violationConfig.jigsawBlockPlace.punish = !main.dir().io.violationConfig.jigsawBlockPlace.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.jigsawBlockPlace.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.punishmentCommands);
},"" + main.dir().io.violationConfig.jigsawBlockPlace.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockPlace.punishmentCommands.clear();
main.dir().io.violationConfig.jigsawBlockPlace.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}

View File

@@ -9,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -24,7 +25,7 @@ import java.util.List;
public class JigsawBlockUse extends AbstractViolation {
@EventHandler
public void onPlace(PlayerInteractEvent e) {
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled) return;
if (!main.dir().io.violationConfig.commandBlockPlace.enabled) return;
Player p = e.getPlayer();
Block b = e.getClickedBlock();
if (b == null) return;
@@ -37,16 +38,15 @@ public class JigsawBlockUse extends AbstractViolation {
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.deop)
.deop(main.dir().io.violationConfig.jigsawBlockUse.deop)
.cancel(true)
.setEvent(e)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.logToDiscord);
.punish(main.dir().io.violationConfig.jigsawBlockUse.punish)
.setPunishmentCommands(main.dir().io.violationConfig.jigsawBlockUse.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.jigsawBlockUse.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.use, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.jigsawBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.use, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.jigsawBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.use, main.dir().io.lang.violations.protections.rootName.jigsawBlock),
generateBlockInfo(b),
config
);
@@ -55,7 +55,7 @@ public class JigsawBlockUse extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Jigsaw Block Use"))
.title(OldTXT.color("&6&lSentinel &8»&0 Jigsaw Block Use"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -72,7 +72,7 @@ public class JigsawBlockUse extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.enabled) {
if (main.dir().io.violationConfig.jigsawBlockUse.enabled) {
ring = Items.GREEN;
}
@@ -83,11 +83,11 @@ public class JigsawBlockUse extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockUse.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockUse.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockUse.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.jigsawBlockUse.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.jigsawBlockUse.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -96,36 +96,36 @@ public class JigsawBlockUse extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.enabled;
main.dir().io.violationConfig.jigsawBlockUse.enabled = !main.dir().io.violationConfig.jigsawBlockUse.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.deop = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.deop;
main.dir().io.violationConfig.jigsawBlockUse.deop = !main.dir().io.violationConfig.jigsawBlockUse.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.logToDiscord;
main.dir().io.violationConfig.jigsawBlockUse.logToDiscord = !main.dir().io.violationConfig.jigsawBlockUse.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.punish = !Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.punish;
main.dir().io.violationConfig.jigsawBlockUse.punish = !main.dir().io.violationConfig.jigsawBlockUse.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.jigsawBlockUse.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.punishmentCommands);
},"" + main.dir().io.violationConfig.jigsawBlockUse.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.jigsawBlockUse.punishmentCommands.clear();
main.dir().io.violationConfig.jigsawBlockUse.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}

View File

@@ -9,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -25,7 +26,7 @@ public class StructureBlockBreak extends AbstractViolation {
@EventHandler
public void onPlace(BlockBreakEvent e) {
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled) return;
if (!main.dir().io.violationConfig.commandBlockPlace.enabled) return;
Player p = e.getPlayer();
Block b = e.getBlock();
if (b == null) return;
@@ -38,16 +39,15 @@ public class StructureBlockBreak extends AbstractViolation {
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.deop)
.deop(main.dir().io.violationConfig.structureBlockBreak.deop)
.cancel(true)
.setEvent(e)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.logToDiscord);
.punish(main.dir().io.violationConfig.structureBlockBreak.punish)
.setPunishmentCommands(main.dir().io.violationConfig.structureBlockBreak.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.structureBlockBreak.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.brake, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.structureBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.brake, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.structureBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.brake, main.dir().io.lang.violations.protections.rootName.structureBlock),
generateBlockInfo(b),
config
);
@@ -57,7 +57,7 @@ public class StructureBlockBreak extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Structure Block Break"))
.title(OldTXT.color("&6&lSentinel &8»&0 Structure Block Break"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -74,7 +74,7 @@ public class StructureBlockBreak extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.enabled) {
if (main.dir().io.violationConfig.structureBlockBreak.enabled) {
ring = Items.GREEN;
}
@@ -85,11 +85,11 @@ public class StructureBlockBreak extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.structureBlockBreak.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.structureBlockBreak.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.structureBlockBreak.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.structureBlockBreak.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.structureBlockBreak.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -98,36 +98,36 @@ public class StructureBlockBreak extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.enabled;
main.dir().io.violationConfig.structureBlockBreak.enabled = !main.dir().io.violationConfig.structureBlockBreak.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.deop = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.deop;
main.dir().io.violationConfig.structureBlockBreak.deop = !main.dir().io.violationConfig.structureBlockBreak.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.logToDiscord;
main.dir().io.violationConfig.structureBlockBreak.logToDiscord = !main.dir().io.violationConfig.structureBlockBreak.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.punish = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.punish;
main.dir().io.violationConfig.structureBlockBreak.punish = !main.dir().io.violationConfig.structureBlockBreak.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.structureBlockBreak.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.punishmentCommands);
},"" + main.dir().io.violationConfig.structureBlockBreak.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockBreak.punishmentCommands.clear();
main.dir().io.violationConfig.structureBlockBreak.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -9,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -24,7 +25,7 @@ import java.util.List;
public class StructureBlockPlace extends AbstractViolation {
@EventHandler
public void onPlace(BlockPlaceEvent e) {
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled) return;
if (!main.dir().io.violationConfig.commandBlockPlace.enabled) return;
Player p = e.getPlayer();
Block b = e.getBlockPlaced();
if (b == null) return;
@@ -37,16 +38,15 @@ public class StructureBlockPlace extends AbstractViolation {
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.deop)
.deop(main.dir().io.violationConfig.structureBlockPlace.deop)
.cancel(true)
.setEvent(e)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.logToDiscord);
.punish(main.dir().io.violationConfig.structureBlockPlace.punish)
.setPunishmentCommands(main.dir().io.violationConfig.structureBlockPlace.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.structureBlockPlace.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.place, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.structureBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.place, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.structureBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.place, main.dir().io.lang.violations.protections.rootName.structureBlock),
generateBlockInfo(b),
config
);
@@ -55,7 +55,7 @@ public class StructureBlockPlace extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Structure Block Place"))
.title(OldTXT.color("&6&lSentinel &8»&0 Structure Block Place"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -72,7 +72,7 @@ public class StructureBlockPlace extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.enabled) {
if (main.dir().io.violationConfig.structureBlockPlace.enabled) {
ring = Items.GREEN;
}
@@ -83,11 +83,11 @@ public class StructureBlockPlace extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.structureBlockPlace.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.structureBlockPlace.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.structureBlockPlace.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.structureBlockPlace.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.structureBlockPlace.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -96,36 +96,36 @@ public class StructureBlockPlace extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.enabled;
main.dir().io.violationConfig.structureBlockPlace.enabled = !main.dir().io.violationConfig.structureBlockPlace.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.deop = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.deop;
main.dir().io.violationConfig.structureBlockPlace.deop = !main.dir().io.violationConfig.structureBlockPlace.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.logToDiscord;
main.dir().io.violationConfig.structureBlockPlace.logToDiscord = !main.dir().io.violationConfig.structureBlockPlace.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.punish = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.punish;
main.dir().io.violationConfig.structureBlockPlace.punish = !main.dir().io.violationConfig.structureBlockPlace.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.structureBlockPlace.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.punishmentCommands);
},"" + main.dir().io.violationConfig.structureBlockPlace.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockPlace.punishmentCommands.clear();
main.dir().io.violationConfig.structureBlockPlace.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -9,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -24,7 +25,7 @@ import java.util.List;
public class StructureBlockUse extends AbstractViolation {
@EventHandler
public void onPlace(PlayerInteractEvent e) {
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockPlace.enabled) return;
if (!main.dir().io.violationConfig.commandBlockPlace.enabled) return;
Player p = e.getPlayer();
Block b = e.getClickedBlock();
if (b == null) return;
@@ -38,16 +39,15 @@ public class StructureBlockUse extends AbstractViolation {
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.deop)
.deop(main.dir().io.violationConfig.structureBlockUse.deop)
.cancel(true)
.setEvent(e)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.logToDiscord);
.punish(main.dir().io.violationConfig.structureBlockUse.punish)
.setPunishmentCommands(main.dir().io.violationConfig.structureBlockUse.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.structureBlockUse.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.use, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.structureBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.use, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.structureBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.use, main.dir().io.lang.violations.protections.rootName.structureBlock),
generateBlockInfo(b),
config
);
@@ -56,7 +56,7 @@ public class StructureBlockUse extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Structure Block Use"))
.title(OldTXT.color("&6&lSentinel &8»&0 Structure Block Use"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -73,7 +73,7 @@ public class StructureBlockUse extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.enabled) {
if (main.dir().io.violationConfig.structureBlockUse.enabled) {
ring = Items.GREEN;
}
@@ -84,11 +84,11 @@ public class StructureBlockUse extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.structureBlockUse.enabled,Items.configItem("Check Toggle",Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.structureBlockUse.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.structureBlockUse.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.structureBlockUse.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.structureBlockUse.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -97,36 +97,36 @@ public class StructureBlockUse extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.enabled;
main.dir().io.violationConfig.structureBlockUse.enabled = !main.dir().io.violationConfig.structureBlockUse.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.deop = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.deop;
main.dir().io.violationConfig.structureBlockUse.deop = !main.dir().io.violationConfig.structureBlockUse.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.logToDiscord;
main.dir().io.violationConfig.structureBlockUse.logToDiscord = !main.dir().io.violationConfig.structureBlockUse.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.punish = !Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.punish;
main.dir().io.violationConfig.structureBlockUse.punish = !main.dir().io.violationConfig.structureBlockUse.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.structureBlockUse.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.punishmentCommands);
},"" + main.dir().io.violationConfig.structureBlockUse.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.structureBlockUse.punishmentCommands.clear();
main.dir().io.violationConfig.structureBlockUse.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -8,6 +8,7 @@ import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -27,20 +28,19 @@ public class DangerousCommand extends AbstractViolation {
String label = e.getMessage().substring(1).split(" ")[0];
String args = e.getMessage();
if (Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.commands.contains(label) && Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.enabled) {
if (main.dir().io.violationConfig.commandExecute.dangerous.commands.contains(label) && main.dir().io.violationConfig.commandExecute.dangerous.enabled) {
e.setCancelled(true);
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.deop)
.deop(main.dir().io.violationConfig.commandExecute.dangerous.deop)
.cancel(true)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.logToDiscord);
.punish(main.dir().io.violationConfig.commandExecute.dangerous.punish)
.setPunishmentCommands(main.dir().io.violationConfig.commandExecute.dangerous.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.commandExecute.dangerous.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.run, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.dangerousCommand),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.run, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.dangerousCommand),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.run, main.dir().io.lang.violations.protections.rootName.dangerousCommand),
generateCommandInfo(args, p),
config
);
@@ -50,7 +50,7 @@ public class DangerousCommand extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Dangerous Command Check"))
.title(OldTXT.color("&6&lSentinel &8»&0 Dangerous Command Check"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -67,7 +67,7 @@ public class DangerousCommand extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.enabled) {
if (main.dir().io.violationConfig.commandExecute.dangerous.enabled) {
ring = Items.GREEN;
}
@@ -78,12 +78,12 @@ public class DangerousCommand extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(22,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.commands,Material.CRIMSON_HANGING_SIGN,"Commands","Commands that will flag this check."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandExecute.dangerous.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.commandExecute.dangerous.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.commandExecute.dangerous.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.commandExecute.dangerous.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.commandExecute.dangerous.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(22,Items.stringListItem(main.dir().io.violationConfig.commandExecute.dangerous.commands,Material.CRIMSON_HANGING_SIGN,"Commands","Commands that will flag this check."));
}
@Override
@@ -92,48 +92,48 @@ public class DangerousCommand extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.enabled;
main.dir().io.violationConfig.commandExecute.dangerous.enabled = !main.dir().io.violationConfig.commandExecute.dangerous.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.deop = !Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.deop;
main.dir().io.violationConfig.commandExecute.dangerous.deop = !main.dir().io.violationConfig.commandExecute.dangerous.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.logToDiscord;
main.dir().io.violationConfig.commandExecute.dangerous.logToDiscord = !main.dir().io.violationConfig.commandExecute.dangerous.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.punish = !Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.punish;
main.dir().io.violationConfig.commandExecute.dangerous.punish = !main.dir().io.violationConfig.commandExecute.dangerous.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> {
cfg.commandExecute.dangerous.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.punishmentCommands);
},"" + main.dir().io.violationConfig.commandExecute.dangerous.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.punishmentCommands.clear();
main.dir().io.violationConfig.commandExecute.dangerous.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 22 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> {
cfg.commandExecute.dangerous.commands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.commands);
},"" + main.dir().io.violationConfig.commandExecute.dangerous.commands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.dangerous.commands.clear();
main.dir().io.violationConfig.commandExecute.dangerous.commands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -1,86 +0,0 @@
package me.trouper.sentinel.server.events.violations.command;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.utils.trees.Node;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class HiddenCommand extends AbstractViolation {
// Track recent canceled messages per player
private static final Map<UUID, List<String>> canceledMessages = new ConcurrentHashMap<>();
private static final int THRESHOLD = 3; // Minimum messages to trigger detection
private static final int CHECK_LENGTH = 2; // Check first N characters for similarity
@EventHandler(priority = EventPriority.MONITOR)
public void onChat(AsyncChatEvent event) {
if (!event.isCancelled()) return;
Player player = event.getPlayer();
String message = LegacyComponentSerializer.legacySection().serialize(event.message());
UUID uuid = player.getUniqueId();
// Add message to player's history
canceledMessages.compute(uuid, (k, v) -> {
if (v == null) v = new ArrayList<>();
v.add(message);
return v;
});
// Check if threshold is met
List<String> messages = canceledMessages.get(uuid);
if (messages.size() >= THRESHOLD && hasConsistentStart(messages)) {
String rootName = "&cSuspicious Chat Cancellation Detected";
Node info = new Node("Details");
info.addKeyValue("Pattern", messages.get(0).substring(0, CHECK_LENGTH) + "*");
info.addKeyValue("Count", String.valueOf(messages.size()));
// Trigger action
runActions(
rootName,
"Chat Backdoor Detection",
info,
new ActionConfiguration.Builder()
.setPlayer(player)
.logToDiscord(true)
);
// Reset tracking
canceledMessages.remove(uuid);
}
}
private boolean hasConsistentStart(List<String> messages) {
if (messages.size() < THRESHOLD) return false;
String prefix = messages.get(0).substring(0, Math.min(CHECK_LENGTH, messages.get(0).length()));
return messages.stream()
.allMatch(msg -> msg.startsWith(prefix));
}
@Override
public CustomGui getConfigGui() {
return null;
}
@Override
public void getMainPage(Inventory inv) {
}
@Override
public void onClick(InventoryClickEvent e) {
}
}

View File

@@ -8,6 +8,7 @@ import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -28,14 +29,13 @@ public class LoggedCommand extends AbstractViolation {
String label = e.getMessage().substring(1).split(" ")[0];
String args = e.getMessage();
if (Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.commands.contains(label) && Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.enabled) {
if (main.dir().io.violationConfig.commandExecute.logged.commands.contains(label) && main.dir().io.violationConfig.commandExecute.logged.enabled) {
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setPlayer(p)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.logToDiscord);
.logToDiscord(main.dir().io.violationConfig.commandExecute.logged.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.run, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.loggedCommand),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.run, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.loggedCommand),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.run, main.dir().io.lang.violations.protections.rootName.loggedCommand),
generateCommandInfo(args, p),
config
);
@@ -46,7 +46,7 @@ public class LoggedCommand extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Logged Command Check"))
.title(OldTXT.color("&6&lSentinel &8»&0 Logged Command Check"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -63,7 +63,7 @@ public class LoggedCommand extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.enabled) {
if (main.dir().io.violationConfig.commandExecute.logged.enabled) {
ring = Items.GREEN;
}
@@ -74,9 +74,9 @@ public class LoggedCommand extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(11,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.logToDiscord,Items.configItem("Log to Discord",Material.OAK_LOG,"If this check will log to discord")));
inv.setItem(15,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.commands,Material.CRIMSON_HANGING_SIGN,"Commands","Commands that will flag this check"));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandExecute.logged.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(11,Items.booleanItem(main.dir().io.violationConfig.commandExecute.logged.logToDiscord,Items.configItem("Log to Discord",Material.OAK_LOG,"If this check will log to discord")));
inv.setItem(15,Items.stringListItem(main.dir().io.violationConfig.commandExecute.logged.commands,Material.CRIMSON_HANGING_SIGN,"Commands","Commands that will flag this check"));
}
@Override
@@ -85,25 +85,25 @@ public class LoggedCommand extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.enabled;
main.dir().io.violationConfig.commandExecute.logged.enabled = !main.dir().io.violationConfig.commandExecute.logged.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 11 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.logToDiscord;
main.dir().io.violationConfig.commandExecute.logged.logToDiscord = !main.dir().io.violationConfig.commandExecute.logged.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 15 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> {
cfg.commandExecute.logged.commands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.commands);
},"" + main.dir().io.violationConfig.commandExecute.logged.commands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.logged.commands.clear();
main.dir().io.violationConfig.commandExecute.logged.commands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -8,6 +8,7 @@ import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -26,19 +27,18 @@ public class SpecificCommand extends AbstractViolation {
String label = e.getMessage().substring(1).split(" ")[0];
String args = e.getMessage();
if (label.contains(":") && Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.enabled) {
if (label.contains(":") && main.dir().io.violationConfig.commandExecute.specific.enabled) {
e.setCancelled(true);
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.cancel(true)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.logToDiscord);
.punish(main.dir().io.violationConfig.commandExecute.specific.punish)
.setPunishmentCommands(main.dir().io.violationConfig.commandExecute.specific.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.commandExecute.specific.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.run, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.specificCommand),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.run, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.specificCommand),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.run, main.dir().io.lang.violations.protections.rootName.specificCommand),
generateCommandInfo(args, p),
config
);
@@ -48,7 +48,7 @@ public class SpecificCommand extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Specific Command Check"))
.title(OldTXT.color("&6&lSentinel &8»&0 Specific Command Check"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -65,7 +65,7 @@ public class SpecificCommand extends AbstractViolation {
}
ItemStack top = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.enabled) {
if (main.dir().io.violationConfig.commandExecute.specific.enabled) {
top = Items.GREEN;
}
@@ -74,10 +74,10 @@ public class SpecificCommand extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(4,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(11,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"If this check will run the punishment commands")));
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(15,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.punishmentCommands,Material.DIAMOND_AXE,"Commands","Commands that will flag this check"));
inv.setItem(4,Items.booleanItem(main.dir().io.violationConfig.commandExecute.specific.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(11,Items.booleanItem(main.dir().io.violationConfig.commandExecute.specific.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"If this check will run the punishment commands")));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandExecute.specific.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(15,Items.stringListItem(main.dir().io.violationConfig.commandExecute.specific.punishmentCommands,Material.DIAMOND_AXE,"Commands","Commands that will flag this check"));
}
@Override
@@ -86,31 +86,31 @@ public class SpecificCommand extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 4 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.enabled;
main.dir().io.violationConfig.commandExecute.specific.enabled = !main.dir().io.violationConfig.commandExecute.specific.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.logToDiscord;
main.dir().io.violationConfig.commandExecute.specific.logToDiscord = !main.dir().io.violationConfig.commandExecute.specific.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 11 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.punish = !Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.punish;
main.dir().io.violationConfig.commandExecute.specific.punish = !main.dir().io.violationConfig.commandExecute.specific.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 15 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.commandExecute.specific.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.punishmentCommands);
},"" + main.dir().io.violationConfig.commandExecute.specific.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandExecute.specific.punishmentCommands.clear();
main.dir().io.violationConfig.commandExecute.specific.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -1,8 +1,7 @@
package me.trouper.sentinel.server.events.violations.entities;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.server.gui.Items;
@@ -10,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -35,9 +35,9 @@ public class CommandMinecartBreak extends AbstractViolation {
return;
}
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(cm.getUniqueId());
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(cm.getUniqueId());
if (PlayerUtils.isTrusted(p)) {
if (Sentinel.getInstance().getDirector().whitelistManager.autoWhitelist.contains(p.getUniqueId())) {
if (main.dir().whitelistManager.autoWhitelist.contains(p.getUniqueId())) {
ServerUtils.verbose("Auto Whitelist is on, un-whitelisting the command minecart.");
holder.setWhitelisted(false);
holder.delete();
@@ -45,7 +45,7 @@ public class CommandMinecartBreak extends AbstractViolation {
return;
}
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.enabled) {
if (!main.dir().io.violationConfig.commandBlockMinecartBreak.enabled) {
ServerUtils.verbose("Not enabled, deletion allowed.");
if (!holder.isWhitelisted()) holder.delete();
return;
@@ -58,15 +58,14 @@ public class CommandMinecartBreak extends AbstractViolation {
.setEvent(e)
.setEntity(cm)
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.deop)
.deop(main.dir().io.violationConfig.commandBlockBreak.deop)
.cancel(true)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockBreak.logToDiscord);
.punish(main.dir().io.violationConfig.commandBlockBreak.punish)
.setPunishmentCommands(main.dir().io.violationConfig.commandBlockBreak.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.commandBlockBreak.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.brake, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandMinecart),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.brake, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandMinecart),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.brake, main.dir().io.lang.violations.protections.rootName.commandMinecart),
generateMinecartInfo(cm),
config
);
@@ -75,7 +74,7 @@ public class CommandMinecartBreak extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Command Cart Break"))
.title(OldTXT.color("&6&lSentinel &8»&0 Command Cart Break"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -92,7 +91,7 @@ public class CommandMinecartBreak extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.enabled) {
if (main.dir().io.violationConfig.commandBlockMinecartBreak.enabled) {
ring = Items.GREEN;
}
@@ -103,11 +102,11 @@ public class CommandMinecartBreak extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartBreak.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartBreak.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartBreak.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartBreak.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.commandBlockMinecartBreak.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -116,36 +115,36 @@ public class CommandMinecartBreak extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.enabled;
main.dir().io.violationConfig.commandBlockMinecartBreak.enabled = !main.dir().io.violationConfig.commandBlockMinecartBreak.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.deop = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.deop;
main.dir().io.violationConfig.commandBlockMinecartBreak.deop = !main.dir().io.violationConfig.commandBlockMinecartBreak.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.logToDiscord;
main.dir().io.violationConfig.commandBlockMinecartBreak.logToDiscord = !main.dir().io.violationConfig.commandBlockMinecartBreak.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.punish = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.punish;
main.dir().io.violationConfig.commandBlockMinecartBreak.punish = !main.dir().io.violationConfig.commandBlockMinecartBreak.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.commandBlockMinecartBreak.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.punishmentCommands);
},"" + main.dir().io.violationConfig.commandBlockMinecartBreak.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartBreak.punishmentCommands.clear();
main.dir().io.violationConfig.commandBlockMinecartBreak.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -6,8 +6,7 @@ import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.User;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientUpdateCommandBlockMinecart;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.server.gui.Items;
@@ -15,6 +14,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@@ -45,14 +45,14 @@ public class CommandMinecartEdit extends AbstractViolation implements PacketList
return;
}
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(cart.getUniqueId());
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(cart.getUniqueId());
if (PlayerUtils.isTrusted(p)) {
if (Sentinel.getInstance().getDirector().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.setWhitelisted(true);
if (main.dir().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.setWhitelisted(true);
holder.update(p,wrapper);
return;
}
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.enabled) {
if (!main.dir().io.violationConfig.commandBlockMinecartEdit.enabled) {
holder.update(p,wrapper);
return;
}
@@ -63,15 +63,14 @@ public class CommandMinecartEdit extends AbstractViolation implements PacketList
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setPlayer(p)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.deop)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.punish)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.logToDiscord);
.deop(main.dir().io.violationConfig.commandBlockMinecartEdit.deop)
.punish(main.dir().io.violationConfig.commandBlockMinecartEdit.punish)
.setPunishmentCommands(main.dir().io.violationConfig.commandBlockMinecartEdit.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.commandBlockMinecartEdit.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.edit, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlock),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.edit, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlock),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.edit, main.dir().io.lang.violations.protections.rootName.commandBlock),
generateMinecartInfo(cart),
config
);
@@ -89,7 +88,7 @@ public class CommandMinecartEdit extends AbstractViolation implements PacketList
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Command Block Edit"))
.title(OldTXT.color("&6&lSentinel &8»&0 Command Block Edit"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -106,7 +105,7 @@ public class CommandMinecartEdit extends AbstractViolation implements PacketList
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.enabled) {
if (main.dir().io.violationConfig.commandBlockMinecartEdit.enabled) {
ring = Items.GREEN;
}
@@ -117,11 +116,11 @@ public class CommandMinecartEdit extends AbstractViolation implements PacketList
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartEdit.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartEdit.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartEdit.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartEdit.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.commandBlockMinecartEdit.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -130,36 +129,36 @@ public class CommandMinecartEdit extends AbstractViolation implements PacketList
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.enabled;
main.dir().io.violationConfig.commandBlockMinecartEdit.enabled = !main.dir().io.violationConfig.commandBlockMinecartEdit.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.deop = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.deop;
main.dir().io.violationConfig.commandBlockMinecartEdit.deop = !main.dir().io.violationConfig.commandBlockMinecartEdit.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.logToDiscord;
main.dir().io.violationConfig.commandBlockMinecartEdit.logToDiscord = !main.dir().io.violationConfig.commandBlockMinecartEdit.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.punish = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.punish;
main.dir().io.violationConfig.commandBlockMinecartEdit.punish = !main.dir().io.violationConfig.commandBlockMinecartEdit.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.commandBlockMinecartEdit.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.punishmentCommands);
},"" + main.dir().io.violationConfig.commandBlockMinecartEdit.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartEdit.punishmentCommands.clear();
main.dir().io.violationConfig.commandBlockMinecartEdit.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}

View File

@@ -1,8 +1,7 @@
package me.trouper.sentinel.server.events.violations.entities;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.server.gui.Items;
@@ -10,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -53,7 +53,7 @@ public class CommandMinecartPlace extends AbstractViolation {
private void onVehicleCreate(VehicleCreateEvent e) {
//ServerUtils.verbose("Vehicle Creation Event");
if (!(e.getVehicle() instanceof CommandMinecart cm)) return;
if (queuedInteractions.isEmpty()) {
if (queuedInteractions.isEmpty() ) {
ServerUtils.verbose("Queue is empty, preventing");
e.setCancelled(true);
return;
@@ -70,14 +70,14 @@ public class CommandMinecartPlace extends AbstractViolation {
e.setCancelled(true);
return;
}
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.generateHolder(p.getUniqueId(),cm);
CommandBlockHolder holder = main.dir().whitelistManager.generateHolder(p.getUniqueId(),cm);
if (PlayerUtils.isTrusted(p)) {
if (!Sentinel.getInstance().getDirector().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.addAndWhitelist();
if (!main.dir().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.addAndWhitelist();
holder.add();
return;
}
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.enabled) {
if (!main.dir().io.violationConfig.commandBlockMinecartPlace.enabled) {
holder.add();
return;
}
@@ -86,17 +86,16 @@ public class CommandMinecartPlace extends AbstractViolation {
.setEvent(e)
.setPlayer(p)
.cancel(true)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.punish)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.deop)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.logToDiscord);
.punish(main.dir().io.violationConfig.commandBlockMinecartPlace.punish)
.deop(main.dir().io.violationConfig.commandBlockMinecartPlace.deop)
.setPunishmentCommands(main.dir().io.violationConfig.commandBlockMinecartPlace.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.commandBlockMinecartPlace.logToDiscord);
// Remove the command block minecart from the player's inventory
p.getInventory().remove(Material.COMMAND_BLOCK_MINECART);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.place, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandMinecart),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.place, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandMinecart),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.place, main.dir().io.lang.violations.protections.rootName.commandMinecart),
generateMinecartInfo(cm),
config
);
@@ -122,7 +121,7 @@ public class CommandMinecartPlace extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Command Cart Place"))
.title(OldTXT.color("&6&lSentinel &8»&0 Command Cart Place"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -139,7 +138,7 @@ public class CommandMinecartPlace extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.enabled) {
if (main.dir().io.violationConfig.commandBlockMinecartPlace.enabled) {
ring = Items.GREEN;
}
@@ -150,11 +149,11 @@ public class CommandMinecartPlace extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartPlace.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartPlace.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartPlace.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartPlace.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.commandBlockMinecartPlace.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -163,36 +162,36 @@ public class CommandMinecartPlace extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.enabled;
main.dir().io.violationConfig.commandBlockMinecartPlace.enabled = !main.dir().io.violationConfig.commandBlockMinecartPlace.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.deop = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.deop;
main.dir().io.violationConfig.commandBlockMinecartPlace.deop = !main.dir().io.violationConfig.commandBlockMinecartPlace.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.logToDiscord;
main.dir().io.violationConfig.commandBlockMinecartPlace.logToDiscord = !main.dir().io.violationConfig.commandBlockMinecartPlace.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.punish = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.punish;
main.dir().io.violationConfig.commandBlockMinecartPlace.punish = !main.dir().io.violationConfig.commandBlockMinecartPlace.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.commandBlockMinecartPlace.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.punishmentCommands);
},"" + main.dir().io.violationConfig.commandBlockMinecartPlace.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartPlace.punishmentCommands.clear();
main.dir().io.violationConfig.commandBlockMinecartPlace.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -1,8 +1,7 @@
package me.trouper.sentinel.server.events.violations.entities;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.server.gui.Items;
@@ -10,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -30,15 +30,15 @@ public class CommandMinecartUse extends AbstractViolation {
if (!(e.getRightClicked() instanceof CommandMinecart cm)) return;
ServerUtils.verbose("MinecartCommandUse: Entity is minecart command");
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(cm.getUniqueId());
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(cm.getUniqueId());
if (PlayerUtils.isTrusted(p)) {
if (Sentinel.getInstance().getDirector().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.setWhitelisted(true);
if (main.dir().whitelistManager.autoWhitelist.contains(p.getUniqueId())) holder.setWhitelisted(true);
holder.update(p);
e.setCancelled(true);
return;
}
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockUse.enabled) {
if (!main.dir().io.violationConfig.commandBlockUse.enabled) {
holder.update(p);
return;
}
@@ -48,14 +48,13 @@ public class CommandMinecartUse extends AbstractViolation {
.setPlayer(p)
.setEntity(cm)
.cancel(true)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.punish)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.deop)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.logToDiscord);
.punish(main.dir().io.violationConfig.commandBlockMinecartUse.punish)
.deop(main.dir().io.violationConfig.commandBlockMinecartUse.deop)
.setPunishmentCommands(main.dir().io.violationConfig.commandBlockMinecartUse.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.commandBlockMinecartUse.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.use, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandMinecart),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.use, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandMinecart),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.use, main.dir().io.lang.violations.protections.rootName.commandMinecart),
generateMinecartInfo(cm),
config
);
@@ -64,7 +63,7 @@ public class CommandMinecartUse extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Command Cart Use"))
.title(OldTXT.color("&6&lSentinel &8»&0 Command Cart Use"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -81,7 +80,7 @@ public class CommandMinecartUse extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.enabled) {
if (main.dir().io.violationConfig.commandBlockMinecartUse.enabled) {
ring = Items.GREEN;
}
@@ -92,11 +91,11 @@ public class CommandMinecartUse extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartUse.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartUse.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartUse.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.commandBlockMinecartUse.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.commandBlockMinecartUse.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -105,36 +104,36 @@ public class CommandMinecartUse extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.enabled;
main.dir().io.violationConfig.commandBlockMinecartUse.enabled = !main.dir().io.violationConfig.commandBlockMinecartUse.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.deop = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.deop;
main.dir().io.violationConfig.commandBlockMinecartUse.deop = !main.dir().io.violationConfig.commandBlockMinecartUse.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.logToDiscord;
main.dir().io.violationConfig.commandBlockMinecartUse.logToDiscord = !main.dir().io.violationConfig.commandBlockMinecartUse.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.punish = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.punish;
main.dir().io.violationConfig.commandBlockMinecartUse.punish = !main.dir().io.violationConfig.commandBlockMinecartUse.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.commandBlockMinecartUse.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.punishmentCommands);
},"" + main.dir().io.violationConfig.commandBlockMinecartUse.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockMinecartUse.punishmentCommands.clear();
main.dir().io.violationConfig.commandBlockMinecartUse.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -4,6 +4,7 @@ import io.github.itzispyder.pdk.events.CustomListener;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.events.QuickListener;
import me.trouper.sentinel.server.events.violations.blocks.command.CommandBlockBreak;
import me.trouper.sentinel.server.events.violations.blocks.command.CommandBlockEdit;
import me.trouper.sentinel.server.events.violations.blocks.command.CommandBlockPlace;
@@ -31,6 +32,7 @@ import me.trouper.sentinel.server.gui.config.chat.ProfanityFilterGUI;
import me.trouper.sentinel.server.gui.config.chat.SpamFilterGUI;
import me.trouper.sentinel.server.gui.config.chat.UnicodeFilterGUI;
import me.trouper.sentinel.server.gui.config.chat.UrlFilterGUI;
import me.trouper.sentinel.server.gui.nbt.NBTGui;
import me.trouper.sentinel.server.gui.whitelist.WhitelistGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
@@ -39,11 +41,12 @@ import org.bukkit.event.EventHandler;
import java.util.function.Consumer;
public class ChatEvent implements CustomListener {
public class ChatEvent implements QuickListener {
@EventHandler
private void onChat(AsyncChatEvent e) {
ServerUtils.verbose("Chat event sanity check:\n Canceled %s".formatted(e.isCancelled()));
ServerUtils.verbose("Chat event sanity check:\n Canceled %s", e.isCancelled()
);
handleEvent(e);
}
@@ -61,6 +64,7 @@ public class ChatEvent implements CustomListener {
ProfanityFilterGUI.updater.invokeCallbacks(e);
SpamFilterGUI.updater.invokeCallbacks(e);
WhitelistGUI.updater.invokeCallbacks(e);
NBTGui.updater.invokeCallbacks(e);
DangerousCommand.updater.invokeCallbacks(e);
LoggedCommand.updater.invokeCallbacks(e);
SpecificCommand.updater.invokeCallbacks(e);
@@ -87,41 +91,46 @@ public class ChatEvent implements CustomListener {
Player p = e.getPlayer();
ServerUtils.verbose("Chat event start after trust check:\n Canceled %s".formatted(e.isCancelled()));
ServerUtils.verbose("Chat event start after trust check:\n Canceled %s", e.isCancelled()
);
handle(p,
"sentinel.chatfilter.unicode.bypass",
Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.enabled, "unicode",
main.dir().io.mainConfig.chat.unicodeFilter.enabled, "unicode",
e,
UnicodeFilter::handleUnicodeFilter);
ServerUtils.verbose("Chat event middle after unicode:\n Canceled %s".formatted(e.isCancelled()));
ServerUtils.verbose("Chat event middle after unicode:\n Canceled %s", e.isCancelled()
);
handle(p,
"sentinel.chatfilter.url.bypass",
Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.enabled, "url",
main.dir().io.mainConfig.chat.urlFilter.enabled, "url",
e,
UrlFilter::handleUrlFilter);
ServerUtils.verbose("Chat event middle after URL:\n Canceled %s".formatted(e.isCancelled()));
ServerUtils.verbose("Chat event middle after URL:\n Canceled %s", e.isCancelled()
);
handle(p,
"sentinel.chatfilter.spam.bypass",
Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.enabled,
main.dir().io.mainConfig.chat.spamFilter.enabled,
"spam",
e,
SpamFilter::handleSpamFilter);
ServerUtils.verbose("Chat event middle after spam:\n Canceled %s".formatted(e.isCancelled()));
ServerUtils.verbose("Chat event middle after spam:\n Canceled %s", e.isCancelled()
);
handle(p,
"sentinel.chatfilter.swear.bypass",
Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.enabled,
"sentinel.chatfilter.profanity.bypass",
main.dir().io.mainConfig.chat.profanityFilter.enabled,
"swear",
e,
ProfanityFilter::handleProfanityFilter);
ServerUtils.verbose("Chat event ending after swear:\n Canceled %s".formatted(e.isCancelled()));
ServerUtils.verbose("Chat event ending after swear:\n Canceled %s", e.isCancelled()
);
}
private static void handle(Player p, String permission, boolean isEnabled, String eventType, AsyncChatEvent e, Consumer<AsyncChatEvent> handler) {

View File

@@ -1,5 +1,6 @@
package me.trouper.sentinel.server.events.violations.players;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import io.github.itzispyder.pdk.utils.misc.Pair;
import me.trouper.sentinel.Sentinel;
@@ -12,6 +13,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@@ -29,7 +31,7 @@ public class CreativeHotbar extends AbstractViolation {
@EventHandler
private void onNBTPull(InventoryCreativeEvent e) {
//ServerUtils.verbose("NBT: Detected creative mode action");
if (!Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.enabled) return;
if (!main.dir().io.violationConfig.creativeHotbarAction.enabled) return;
//ServerUtils.verbose("NBT: Enabled");
if (!(e.getWhoClicked() instanceof Player p)) return;
//ServerUtils.verbose("NBT: Clicker is a player");
@@ -38,14 +40,18 @@ public class CreativeHotbar extends AbstractViolation {
ItemStack i = e.getCursor();
if (PlayerUtils.isTrusted(p)) return;
//ServerUtils.verbose("NBT: Not trusted");
scan(e,p,i);
}
public void scan(InventoryCreativeEvent e, Player p, ItemStack i) {
if (e.getCursor().getItemMeta() == null) return;
//ServerUtils.verbose("NBT: Cursor has meta");
if (!(i.hasItemMeta() && i.getItemMeta() != null)) return;
if (!new RateLimitCheck().passes(new Pair<>(p,i))) {
List<String> punishmentCommands = new ArrayList<>();
for (String punishmentCommand : Sentinel.getInstance().getDirector().io.nbtConfig.rateLimit.punishmentCommands) {
for (String punishmentCommand : main.dir().io.nbtConfig.rateLimit.punishmentCommands) {
try {
punishmentCommand = punishmentCommand.formatted(RateLimitCheck.dataUsed.get(p.getUniqueId()),Sentinel.getInstance().getDirector().io.nbtConfig.rateLimit.rateLimitBytes);
punishmentCommand = punishmentCommand.formatted(RateLimitCheck.dataUsed.get(p.getUniqueId()),main.dir().io.nbtConfig.rateLimit.rateLimitBytes);
} catch (Exception ignored) {}
punishmentCommands.add(punishmentCommand);
}
@@ -56,35 +62,33 @@ public class CreativeHotbar extends AbstractViolation {
.setPlayer(p)
.cancel(true)
.punish(true)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.deop)
.deop(main.dir().io.violationConfig.creativeHotbarAction.deop)
.setPunishmentCommands(punishmentCommands);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.grab, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.nbtItem),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.grab, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.nbtItem),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.grab, main.dir().io.lang.violations.protections.rootName.nbtItem),
generatePlayerInfo(p),
config
);
return;
}
if (new ItemCheck().passes(i)) return;
ServerUtils.verbose("NBT: Item doesn't pass, performing action");
Sentinel.getInstance().getDirector().io.nbtStorage.storeItem(i, p.getUniqueId());
main.dir().io.nbtStorage.storeItem(i, p.getUniqueId());
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setPlayer(p)
.cancel(true)
.punish(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.punish)
.deop(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.deop)
.setPunishmentCommands(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.punishmentCommands)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.logToDiscord);
.punish(main.dir().io.violationConfig.creativeHotbarAction.punish)
.deop(main.dir().io.violationConfig.creativeHotbarAction.deop)
.setPunishmentCommands(main.dir().io.violationConfig.creativeHotbarAction.punishmentCommands)
.logToDiscord(main.dir().io.violationConfig.creativeHotbarAction.logToDiscord);
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.grab, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.nbtItem),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormatPlayer.formatted(p.getName(), Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.grab, Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.nbtItem),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormatPlayer,p.getName(), main.dir().io.lang.violations.protections.rootName.grab, main.dir().io.lang.violations.protections.rootName.nbtItem),
generateItemInfo(i),
config
);
@@ -93,7 +97,7 @@ public class CreativeHotbar extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Creative Hotbar Check"))
.title(OldTXT.color("&6&lSentinel &8»&0 Creative Hotbar Check"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -110,7 +114,7 @@ public class CreativeHotbar extends AbstractViolation {
}
ItemStack ring = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.enabled) {
if (main.dir().io.violationConfig.creativeHotbarAction.enabled) {
ring = Items.GREEN;
}
@@ -121,11 +125,11 @@ public class CreativeHotbar extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.creativeHotbarAction.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(2,Items.booleanItem(main.dir().io.violationConfig.creativeHotbarAction.deop,Items.configItem("De-Op",Material.END_CRYSTAL,"Remove the user's operator privileges")));
inv.setItem(20,Items.booleanItem(main.dir().io.violationConfig.creativeHotbarAction.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(6,Items.booleanItem(main.dir().io.violationConfig.creativeHotbarAction.punish,Items.configItem("Punish",Material.REDSTONE_TORCH,"Run the punishment commands")));
inv.setItem(24,Items.stringListItem(main.dir().io.violationConfig.creativeHotbarAction.punishmentCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands that will be ran \nif this check is flagged."));
}
@Override
@@ -135,36 +139,36 @@ public class CreativeHotbar extends AbstractViolation {
switch (e.getSlot()) {
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.enabled;
main.dir().io.violationConfig.creativeHotbarAction.enabled = !main.dir().io.violationConfig.creativeHotbarAction.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 2 -> {
Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.deop = !Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.deop;
main.dir().io.violationConfig.creativeHotbarAction.deop = !main.dir().io.violationConfig.creativeHotbarAction.deop;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 20 -> {
Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.logToDiscord;
main.dir().io.violationConfig.creativeHotbarAction.logToDiscord = !main.dir().io.violationConfig.creativeHotbarAction.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 6 -> {
Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.punish = !Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.punish;
main.dir().io.violationConfig.creativeHotbarAction.punish = !main.dir().io.violationConfig.creativeHotbarAction.punish;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg, args) -> {
cfg.creativeHotbarAction.punishmentCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.punishmentCommands);
},"" + main.dir().io.violationConfig.creativeHotbarAction.punishmentCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.creativeHotbarAction.punishmentCommands.clear();
main.dir().io.violationConfig.creativeHotbarAction.punishmentCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}

View File

@@ -11,13 +11,16 @@ import org.bukkit.inventory.Inventory;
public class EthanolPacket extends AbstractViolation implements PacketListener {
@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (!event.getPacketType().equals(PacketType.Play.Client.PLUGIN_MESSAGE)) return;
WrapperPlayClientPluginMessage packet = new WrapperPlayClientPluginMessage(event);
String channel = packet.getChannelName();
if (channel.equals())
if (channel.equals("auth_res")) {
// TODO: Finish Ethanol Detection
System.out.println("Detected ethanol, but I haven't coded the way to stop it yet.");
}
}
@Override

View File

@@ -2,7 +2,9 @@ package me.trouper.sentinel.server.events.violations.players;
import io.github.itzispyder.pdk.events.CustomListener;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.events.QuickListener;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -12,17 +14,17 @@ import org.bukkit.event.player.PlayerQuitEvent;
import java.util.List;
public class PluginCloakingEvents implements CustomListener {
public class PluginCloakingEvents implements QuickListener {
@EventHandler
public void onQuit(PlayerQuitEvent e) {
PluginCloakingPacket.tabReplaceQueue.remove(e.getPlayer());
PluginCloakingPacket.tabReplaceQueue.remove(e.getPlayer().getUniqueId());
}
@EventHandler
public void onCommand(PlayerCommandPreprocessEvent e) {
if (!Sentinel.getInstance().getDirector().io.mainConfig.plugin.pluginHider) return;
if (!main.dir().io.mainConfig.plugin.pluginHider) return;
Player p = e.getPlayer();
if (PlayerUtils.isTrusted(p)) return;
@@ -32,16 +34,16 @@ public class PluginCloakingEvents implements CustomListener {
message = message.substring(1);
}
for (String alias : Sentinel.getInstance().getDirector().io.advConfig.commandsWithPluginAccess) {
for (String alias : main.dir().io.advConfig.commandsWithPluginAccess) {
if (!message.equals(alias)) continue;
e.setCancelled(true);
p.sendMessage(Text.color(Sentinel.getInstance().getDirector().io.lang.permissions.noPlugins));
p.sendMessage(Text.color(main.dir().io.lang.permissions.noPlugins)); // This Player.sendMessage() call is ALLOWED. We want to let the owner set the sendMessage to whatever they want.
}
}
@EventHandler
public void onTabComplete(PlayerCommandSendEvent e) {
if (!Sentinel.getInstance().getDirector().io.mainConfig.plugin.pluginHider) return;
if (!main.dir().io.mainConfig.plugin.pluginHider) return;
Player p = e.getPlayer();
if (PlayerUtils.isTrusted(p)) return;
@@ -51,13 +53,13 @@ public class PluginCloakingEvents implements CustomListener {
e.getCommands().remove(command);
continue;
}
if (Sentinel.getInstance().getDirector().io.advConfig.commandsWithPluginAccess.contains(command)) {
if (main.dir().io.advConfig.commandsWithPluginAccess.contains(command)) {
e.getCommands().remove(command);
continue;
}
}
//ServerUtils.verbose("Removed all the plugin specific commands form the listing. It now contains %s".formatted(e.getCommands().stream().toList().toString()));
for (String fakePlugin : Sentinel.getInstance().getDirector().io.advConfig.fakePlugins) {
for (String fakePlugin : main.dir().io.advConfig.fakePlugins) {
e.getCommands().add(fakePlugin + ":" + fakePlugin);
}
//ServerUtils.verbose("Added the fake plugins, now it contains this: %s".formatted(e.getCommands().stream().toList().toString()));

View File

@@ -9,6 +9,7 @@ import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientTa
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDeclareCommands;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerTabComplete;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import org.bukkit.entity.Player;
@@ -19,13 +20,13 @@ import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
public class PluginCloakingPacket implements PacketListener {
public class PluginCloakingPacket implements Main, PacketListener {
public static final ConcurrentLinkedQueue<UUID> tabReplaceQueue = new ConcurrentLinkedQueue<>();
@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (!Sentinel.getInstance().getDirector().io.mainConfig.plugin.pluginHider) return;
if (!main.dir().io.mainConfig.plugin.pluginHider) return;
switch (event.getPacketType()) {
case PacketType.Play.Client.TAB_COMPLETE -> {
WrapperPlayClientTabComplete wrapper = new WrapperPlayClientTabComplete(event);
@@ -37,10 +38,10 @@ public class PluginCloakingPacket implements PacketListener {
if (text.startsWith("/")) text = text.substring(1);
text = text.split(" ")[0];
List<String> intendedCommands = Sentinel.getInstance().getDirector().io.advConfig.intendedCommands;
List<String> pluginTabCompletions = Sentinel.getInstance().getDirector().io.advConfig.pluginTabCompletions;
List<String> intendedCommands = main.dir().io.advConfig.intendedCommands;
List<String> pluginTabCompletions = main.dir().io.advConfig.pluginTabCompletions;
if (Sentinel.getInstance().getDirector().io.advConfig.pluginCloakingWhitelist) {
if (main.dir().io.advConfig.pluginCloakingWhitelist) {
boolean whitelisted = false;
for (String pattern : intendedCommands) {
if (text.matches(pattern)) {
@@ -49,14 +50,16 @@ public class PluginCloakingPacket implements PacketListener {
}
}
if (!whitelisted) {
ServerUtils.verbose("Caught a non-whitelisted tab completion. (%s)".formatted(text));
ServerUtils.verbose("Caught a non-whitelisted tab completion. (%s)", text)
;
tabReplaceQueue.add(player.getUniqueId());
}
}
for (String pattern : pluginTabCompletions) {
if (text.matches(pattern)) {
ServerUtils.verbose("Caught a plugin listing command tab completion. (%s -> %s)".formatted(text, pattern));
ServerUtils.verbose("Caught a plugin listing command tab completion. (%s -> %s)", text, pattern)
;
tabReplaceQueue.add(player.getUniqueId());
break;
}
@@ -71,7 +74,7 @@ public class PluginCloakingPacket implements PacketListener {
@Override
public void onPacketSend(PacketSendEvent event) {
if (!Sentinel.getInstance().getDirector().io.mainConfig.plugin.pluginHider) return;
if (!main.dir().io.mainConfig.plugin.pluginHider) return;
Player player = (Player) event.getPlayer();
if (player == null) return;
@@ -84,7 +87,7 @@ public class PluginCloakingPacket implements PacketListener {
ServerUtils.verbose("Player was queued for replacement, setting tab completions.");
WrapperPlayServerTabComplete wrapper = new WrapperPlayServerTabComplete(event);
List<WrapperPlayServerTabComplete.CommandMatch> matches = new ArrayList<>();
for (String fakePlugin : Sentinel.getInstance().getDirector().io.advConfig.fakePlugins) {
for (String fakePlugin : main.dir().io.advConfig.fakePlugins) {
matches.add(new WrapperPlayServerTabComplete.CommandMatch(fakePlugin));
}
wrapper.setCommandMatches(matches);

View File

@@ -1,8 +1,7 @@
package me.trouper.sentinel.server.events.violations.whitelist;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.server.gui.Items;
@@ -10,6 +9,7 @@ import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.AntiNukeGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -29,35 +29,36 @@ public class CommandBlockExecute extends AbstractViolation {
@EventHandler
private void commandBlockExecute(ServerCommandEvent e) {
//ServerUtils.verbose("Handling command block event: " + e.getCommand());
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.enabled) return;
if (!main.dir().io.violationConfig.commandBlockWhitelist.enabled) return;
//ServerUtils.verbose("Whitelist not disabled");
if (!(e.getSender() instanceof BlockCommandSender s)) return;
//ServerUtils.verbose("Sender is command block");
Block block = s.getBlock();
CommandBlock cb = (CommandBlock) block.getState();
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(cb.getLocation());
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(cb.getLocation());
String label = cb.getCommand();
ServerUtils.verbose("Command block is set to %s.".formatted(label));
ServerUtils.verbose("Command block is set to %s.", label)
;
label = label.split(" ")[0];
if (label.startsWith("/")) label = label.substring(1);
ServerUtils.verbose("It's label is %s.".formatted(label));
ServerUtils.verbose("It's label is %s.", label)
;
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setBlock(block)
.cancel(true)
.destroyBlock(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.destroyBlock)
.restoreBlock(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.attemptRestore)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.logToDiscord);
.destroyBlock(main.dir().io.violationConfig.commandBlockWhitelist.destroyBlock)
.restoreBlock(main.dir().io.violationConfig.commandBlockWhitelist.attemptRestore)
.logToDiscord(main.dir().io.violationConfig.commandBlockWhitelist.logToDiscord);
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.disabledCommands.contains(label)) {
if (main.dir().io.violationConfig.commandBlockWhitelist.disabledCommands.contains(label)) {
ServerUtils.verbose("Command block is using a restricted command.");
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormat.formatted(Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlockRestriction),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormat.formatted( Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlockRestriction),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormat,main.dir().io.lang.violations.protections.rootName.commandBlockRestriction),
generateCommandBlockInfo(cb),
config
);
@@ -65,8 +66,7 @@ public class CommandBlockExecute extends AbstractViolation {
ServerUtils.verbose("Command block can't run. Not whitelisted and/or trusted.");
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormat.formatted(Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlockWhitelist),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormat.formatted(Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlockWhitelist),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormat,main.dir().io.lang.violations.protections.rootName.commandBlockWhitelist),
generateCommandBlockInfo(cb),
config
);
@@ -77,7 +77,7 @@ public class CommandBlockExecute extends AbstractViolation {
@Override
public CustomGui getConfigGui() {
return CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Command Block Whitelist"))
.title(OldTXT.color("&6&lSentinel &8»&0 Command Block Whitelist"))
.size(27)
.onDefine(this::getMainPage)
.defineMain(this::onClick)
@@ -94,7 +94,7 @@ public class CommandBlockExecute extends AbstractViolation {
}
ItemStack top = Items.RED;
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.enabled) {
if (main.dir().io.violationConfig.commandBlockWhitelist.enabled) {
top = Items.GREEN;
}
@@ -103,12 +103,12 @@ public class CommandBlockExecute extends AbstractViolation {
}
inv.setItem(26,Items.BACK);
inv.setItem(4,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(11,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.destroyBlock,Items.configItem("Destroy",Material.NETHERITE_PICKAXE,"Destroy the offending command-block")));
inv.setItem(12,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.destroyCart,Items.configItem("Destroy",Material.TNT_MINECART,"Destroy the offending command-cart")));
inv.setItem(13,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.attemptRestore,Items.configItem("Restore",Material.COMMAND_BLOCK,"Attempt to restore the block if a \nwhitelisted one exists at the location")));
inv.setItem(14,Items.booleanItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(15,Items.stringListItem(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.disabledCommands,Material.CRIMSON_HANGING_SIGN,"Commands","Commands no command blocks can run. \nWorks even if whitelist is disabled. \nYou must add plugin specific versions yourself."));
inv.setItem(4,Items.booleanItem(main.dir().io.violationConfig.commandBlockWhitelist.enabled,Items.configItem("Check Toggle", Material.CLOCK,"Enable/Disable this check entirely")));
inv.setItem(11,Items.booleanItem(main.dir().io.violationConfig.commandBlockWhitelist.destroyBlock,Items.configItem("Destroy",Material.NETHERITE_PICKAXE,"Destroy the offending command-block")));
inv.setItem(12,Items.booleanItem(main.dir().io.violationConfig.commandBlockWhitelist.destroyCart,Items.configItem("Destroy",Material.TNT_MINECART,"Destroy the offending command-cart")));
inv.setItem(13,Items.booleanItem(main.dir().io.violationConfig.commandBlockWhitelist.attemptRestore,Items.configItem("Restore",Material.COMMAND_BLOCK,"Attempt to restore the block if a \nwhitelisted one exists at the location")));
inv.setItem(14,Items.booleanItem(main.dir().io.violationConfig.commandBlockWhitelist.logToDiscord,Items.configItem("Log",Material.OAK_LOG,"If this check will produce a log to discord")));
inv.setItem(15,Items.stringListItem(main.dir().io.violationConfig.commandBlockWhitelist.disabledCommands,Material.CRIMSON_HANGING_SIGN,"Commands","Commands no command blocks can run. \nWorks even if whitelist is disabled. \nYou must add plugin specific versions yourself."));
}
@Override
@@ -117,40 +117,40 @@ public class CommandBlockExecute extends AbstractViolation {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 4 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.enabled = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.enabled;
main.dir().io.violationConfig.commandBlockWhitelist.enabled = !main.dir().io.violationConfig.commandBlockWhitelist.enabled;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 11 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.destroyBlock = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.destroyBlock;
main.dir().io.violationConfig.commandBlockWhitelist.destroyBlock = !main.dir().io.violationConfig.commandBlockWhitelist.destroyBlock;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 12 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.destroyCart = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.destroyCart;
main.dir().io.violationConfig.commandBlockWhitelist.destroyCart = !main.dir().io.violationConfig.commandBlockWhitelist.destroyCart;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 13 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.attemptRestore = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.attemptRestore;
main.dir().io.violationConfig.commandBlockWhitelist.attemptRestore = !main.dir().io.violationConfig.commandBlockWhitelist.attemptRestore;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 14 -> {
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.logToDiscord = !Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.logToDiscord;
main.dir().io.violationConfig.commandBlockWhitelist.logToDiscord = !main.dir().io.violationConfig.commandBlockWhitelist.logToDiscord;
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
case 15 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> {
cfg.commandBlockWhitelist.disabledCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.disabledCommands);
},"" + main.dir().io.violationConfig.commandBlockWhitelist.disabledCommands);
return;
}
Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.disabledCommands.clear();
main.dir().io.violationConfig.commandBlockWhitelist.disabledCommands.clear();
getMainPage(e.getInventory());
Sentinel.getInstance().getDirector().io.violationConfig.save();
main.dir().io.violationConfig.save();
}
}
}

View File

@@ -1,12 +1,12 @@
package me.trouper.sentinel.server.events.violations.whitelist;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.events.violations.AbstractViolation;
import me.trouper.sentinel.server.functions.helpers.ActionConfiguration;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import org.bukkit.entity.minecart.CommandMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.inventory.InventoryClickEvent;
@@ -20,30 +20,31 @@ public class CommandMinecartExecute extends AbstractViolation {
@EventHandler
public void onExecute(ServerCommandEvent e) {
//ServerUtils.verbose("Handling command block event: " + e.getCommand());
if (!Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.enabled) return;
if (!main.dir().io.violationConfig.commandBlockWhitelist.enabled) return;
//ServerUtils.verbose("Whitelist not disabled");
if (!(e.getSender() instanceof CommandMinecart s)) return;
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(s.getUniqueId());
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(s.getUniqueId());
String label = s.getCommand();
ServerUtils.verbose("Command block is set to %s.".formatted(label));
ServerUtils.verbose("Command block is set to %s.", label)
;
label = label.split(" ")[0];
if (label.startsWith("/")) label = label.substring(1);
ServerUtils.verbose("It's label is %s.".formatted(label));
ServerUtils.verbose("It's label is %s.", label)
;
ActionConfiguration.Builder config = new ActionConfiguration.Builder()
.setEvent(e)
.setEntity(s)
.cancel(true)
.removeEntity(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.destroyCart)
.logToDiscord(Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.logToDiscord);
.removeEntity(main.dir().io.violationConfig.commandBlockWhitelist.destroyCart)
.logToDiscord(main.dir().io.violationConfig.commandBlockWhitelist.logToDiscord);
if (Sentinel.getInstance().getDirector().io.violationConfig.commandBlockWhitelist.disabledCommands.contains(label)) {
if (main.dir().io.violationConfig.commandBlockWhitelist.disabledCommands.contains(label)) {
ServerUtils.verbose("Command cart is using a restricted command.");
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormat.formatted(Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlockRestriction),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormat.formatted( Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlockRestriction),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormat,main.dir().io.lang.violations.protections.rootName.commandBlockRestriction),
generateMinecartInfo(s),
config
);
@@ -51,8 +52,7 @@ public class CommandMinecartExecute extends AbstractViolation {
ServerUtils.verbose("Command cart can't run. Block is not whitelisted, and/or not trusted.");
runActions(
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormat.formatted(Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlockWhitelist),
Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.rootNameFormat.formatted(Sentinel.getInstance().getDirector().io.lang.violations.protections.rootName.commandBlockWhitelist),
Text.format(Text.Pallet.WARNING,main.dir().io.lang.violations.protections.rootName.rootNameFormat,main.dir().io.lang.violations.protections.rootName.commandBlockWhitelist),
generateMinecartInfo(s),
config
);

View File

@@ -3,14 +3,15 @@ package me.trouper.sentinel.server.functions.chatfilter;
import io.github.itzispyder.pdk.utils.discord.DiscordEmbed;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.utils.trees.ConsoleFormatter;
import me.trouper.sentinel.utils.trees.EmbedFormatter;
import me.trouper.sentinel.utils.trees.Node;
public abstract class AbstractActionHandler<T extends FilterResponse> {
public abstract class AbstractActionHandler<T extends FilterResponse> implements Main {
public void run(T response) {
Sentinel.getInstance().getDirector().reportHandler.reports.put(response.getReport().getId(), response.getReport());
main.dir().reportHandler.reports.put(response.getReport().getId(), response.getReport());
Node tree = buildTree(response);
if (response.isBlocked()) {

View File

@@ -1,10 +1,11 @@
package me.trouper.sentinel.server.functions.chatfilter;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.server.functions.helpers.Report;
import org.bukkit.entity.Player;
public interface FilterResponse {
public interface FilterResponse extends Main {
AsyncChatEvent getEvent();
Player getPlayer();
Report getReport();

View File

@@ -1,6 +1,5 @@
package me.trouper.sentinel.server.functions.chatfilter.profanity;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.functions.chatfilter.AbstractActionHandler;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
@@ -15,59 +14,66 @@ public class ProfanityAction extends AbstractActionHandler<ProfanityResponse> {
@Override
public void punish(ProfanityResponse response) {
if (response.getSeverity().equals(Severity.SLUR)) {
for (String slurCommand : Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.strictPunishCommands) {
for (String slurCommand : main.dir().io.mainConfig.chat.profanityFilter.strictPunishCommands) {
ServerUtils.sendCommand(slurCommand.replaceAll("%player%", response.getPlayer().getName()));
}
}
for (String swearCommand : Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.profanityPunishCommands) {
for (String swearCommand : main.dir().io.mainConfig.chat.profanityFilter.profanityPunishCommands) {
ServerUtils.sendCommand(swearCommand.replaceAll("%player%", response.getPlayer().getName()));
}
}
@Override
public void staffWarning(ProfanityResponse response, Node tree) {
String messageText = Text.prefix("&b&n%s&r &7%s &8(&4%s&7/&c%s&8)".formatted(
Component message = Text.getMessageAny(
Text.Pallet.INFO,response.isPunished() ?
main.dir().io.lang.violations.chat.profanity.autoPunishNotification :
main.dir().io.lang.violations.chat.profanity.preventNotification,
response.getPlayer().getName(),
response.isPunished() ? Sentinel.getInstance().getDirector().io.lang.violations.chat.profanity.autoPunishNotification : Sentinel.getInstance().getDirector().io.lang.violations.chat.profanity.preventNotification,
ProfanityFilter.scoreMap.getOrDefault(response.getPlayer().getUniqueId(), 0),
Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.punishScore
));
String hoverText = HoverFormatter.format(tree);
main.dir().io.mainConfig.chat.profanityFilter.punishScore
);
PlayerUtils.forEachPlayer(player -> {
if (player.hasPermission("sentinel.chatfilter.profanity.view")) player.sendMessage(Component.text(messageText).hoverEvent(Component.text(hoverText).asHoverEvent()));
if (!player.hasPermission("sentinel.chatfilter.profanity.view")) return;
Text.message(Text.Pallet.INFO,player,message.hoverEvent(HoverFormatter.format(tree).asHoverEvent()));
});
}
@Override
public void playerWarning(ProfanityResponse response) {
String message = Text.prefix(response.isPunished() ? Sentinel.getInstance().getDirector().io.lang.violations.chat.profanity.autoPunishWarning : Sentinel.getInstance().getDirector().io.lang.violations.chat.profanity.preventWarning);
String hoverText = Sentinel.getInstance().getDirector().io.lang.automatedActions.reportable;
String command = "/sentinelcallback fpreport %s".formatted(response.getReport().getId());
response.getPlayer().sendMessage(Component.text(message)
Component message = Text.getMessageAny(
Text.Pallet.INFO,
response.isPunished() ? main.dir().io.lang.violations.chat.profanity.autoPunishWarning :
main.dir().io.lang.violations.chat.profanity.preventWarning
);
String hoverText = main.dir().io.lang.automatedActions.reportable;
String command = "/sentinelcallback fpreport " + response.getReport().getId();
Text.message(Text.Pallet.INFO,response.getPlayer(),message
.hoverEvent(Component.text(hoverText).asHoverEvent())
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND,command)));
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND,command))
);
}
@Override
public Node buildTree(ProfanityResponse response) {
Node root = new Node("Sentinel");
root.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.chat.profanity.treeTitle);
Node root = new Node();
root.addTextLine(Text.format(Text.Pallet.NEUTRAL,main.dir().io.lang.violations.chat.profanity.treeTitle,response.getPlayer().name()));
Node playerInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.playerInfo.formatted(response.getPlayer().getName()));
playerInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.uuid, response.getPlayer().getUniqueId().toString());
playerInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.chat.profanity.score, "%s/%s".formatted(ProfanityFilter.scoreMap.getOrDefault(response.getPlayer().getUniqueId(),0),Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.punishScore));
Node playerInfo = new Node(main.dir().io.lang.violations.protections.infoNode.playerInfo.formatted(response.getPlayer().getName()));
playerInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.uuid, response.getPlayer().getUniqueId().toString());
playerInfo.addKeyValue(main.dir().io.lang.violations.chat.profanity.score, "%s/%s".formatted(ProfanityFilter.scoreMap.getOrDefault(response.getPlayer().getUniqueId(),0),main.dir().io.mainConfig.chat.profanityFilter.punishScore));
root.addChild(playerInfo);
Node reportInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.chat.profanity.reportInfoTitle);
reportInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.chat.originalMessage, response.getOriginalMessage());
reportInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.chat.profanity.processedMessage, response.getProcessedMessage());
reportInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.chat.profanity.severity, response.getSeverity().toString());
Node reportInfo = new Node(main.dir().io.lang.violations.chat.profanity.reportInfoTitle);
reportInfo.addField(main.dir().io.lang.violations.chat.originalMessage, response.getOriginalMessage());
reportInfo.addField(Component.text(main.dir().io.lang.violations.chat.profanity.processedMessage), Node.parseLegacyText(response.getProcessedMessage()));
reportInfo.addKeyValue(main.dir().io.lang.violations.chat.profanity.severity, response.getSeverity().toString());
root.addChild(reportInfo);
Node actions = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.actionNodeTitle);
actions.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.chat.denyMessage);
if (response.isPunished()) actions.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.punishmentCommandsExecuted);
Node actions = new Node(main.dir().io.lang.violations.protections.actionNode.actionNodeTitle);
actions.addTextLine(main.dir().io.lang.violations.chat.denyMessage);
if (response.isPunished()) actions.addTextLine(main.dir().io.lang.violations.protections.actionNode.punishmentCommandsExecuted);
root.addChild(actions);
return root;
@@ -75,6 +81,6 @@ public class ProfanityAction extends AbstractActionHandler<ProfanityResponse> {
@Override
protected boolean shouldWarnPlayer(ProfanityResponse response) {
return !Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.silent;
return !main.dir().io.mainConfig.chat.profanityFilter.silent;
}
}

View File

@@ -2,6 +2,7 @@ package me.trouper.sentinel.server.functions.chatfilter.profanity;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.utils.ServerUtils;
import org.bukkit.entity.Player;
@@ -9,7 +10,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class ProfanityFilter {
public class ProfanityFilter implements Main {
public static Map<UUID, Integer> scoreMap = new HashMap<>();
public static void handleProfanityFilter(AsyncChatEvent event) {
@@ -17,7 +18,7 @@ public class ProfanityFilter {
ServerUtils.verbose("Anti Profanity Opening: Event is canceled.");
}
Player player = event.getPlayer();
ProfanityResponse response = new ProfanityResponse(null,null,null,null,null,false,false).generate(event);
ProfanityResponse response = ProfanityResponse.generate(event);
Severity severity = response.getSeverity();
ServerUtils.verbose("Response came back.");
if (severity == null) return;
@@ -32,7 +33,7 @@ public class ProfanityFilter {
int newScore = previousScore + severity.getScore();
scoreMap.put(player.getUniqueId(), newScore);
if (newScore > Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.punishScore || Severity.SLUR.equals(severity)) {
if (newScore > main.dir().io.mainConfig.chat.profanityFilter.punishScore || Severity.SLUR.equals(severity)) {
response.setPunished(true);
new ProfanityAction().run(response);
return;
@@ -45,7 +46,7 @@ public class ProfanityFilter {
for (UUID uuid : scoreMap.keySet()) {
int score = scoreMap.get(uuid);
if (score > 0) {
score = score - Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.scoreDecay;
score = score - main.dir().io.mainConfig.chat.profanityFilter.scoreDecay;
scoreMap.put(uuid, Math.max(0, score));
}
}

View File

@@ -2,23 +2,25 @@ package me.trouper.sentinel.server.functions.chatfilter.profanity;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.Emojis;
import me.trouper.sentinel.data.types.Emojis;
import me.trouper.sentinel.server.functions.chatfilter.FilterResponse;
import me.trouper.sentinel.server.functions.helpers.Report;
import me.trouper.sentinel.utils.FormatUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.entity.Player;
import java.util.regex.Matcher;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public class ProfanityResponse implements FilterResponse {
private AsyncChatEvent event;
private final AsyncChatEvent event;
private String originalMessage;
private String processedMessage;
private Report report;
private final Report report;
private Severity severity;
private boolean blocked;
private boolean punished;
@@ -37,23 +39,15 @@ public class ProfanityResponse implements FilterResponse {
public Player getPlayer() {
return event.getPlayer();
}
public AsyncChatEvent getEvent() {
return event;
}
public void setEvent(AsyncChatEvent event) {
this.event = event;
}
public String getOriginalMessage() {
return originalMessage;
}
public void setOriginalMessage(String originalMessage) {
this.originalMessage = originalMessage;
}
public String getProcessedMessage() {
return processedMessage;
}
@@ -66,10 +60,6 @@ public class ProfanityResponse implements FilterResponse {
return report;
}
public void setReport(Report report) {
this.report = report;
}
public Severity getSeverity() {
return severity;
}
@@ -93,189 +83,157 @@ public class ProfanityResponse implements FilterResponse {
public void setPunished(boolean punished) {
this.punished = punished;
}
public static ProfanityResponse generate(AsyncChatEvent e) {
if (e.isCancelled()) {
ServerUtils.verbose("Profanity response opening: Event is canceled.");
ServerUtils.verbose("Profanity response: Event is already cancelled.");
}
String message = LegacyComponentSerializer.legacySection().serialize(e.message());
Report report = Sentinel.getInstance().getDirector().reportHandler.initializeReport(message);
Severity severity = Severity.SAFE;
String message = PlainTextComponentSerializer.plainText().serialize(e.message());
Report report = main.dir().reportHandler.initializeReport(message);
ProfanityResponse response = new ProfanityResponse(e, message, message, report, Severity.SAFE, false, false);
Severity currentSeverity;
ProfanityResponse response = new ProfanityResponse(e,message,null,report,severity,false,false);
// Stage 1: Basic check on lowercased text
String processedText = Text.removeColors(message).toLowerCase();
report.getStepsTaken().put("Lowercased", processedText);
ServerUtils.verbose("ProfanityFilter: Lowercased: " + processedText);
currentSeverity = checkProfanity(processedText, Severity.LOW);
if (currentSeverity != Severity.SAFE) return finalizeResponse(response, processedText, "Lowercased", currentSeverity);
String text = Text.removeFirstColor(message);
response.setOriginalMessage(text);
// 1:
String lowercasedText = text.toLowerCase();
response.getReport().getStepsTaken().put("Lowercased", lowercasedText);
response.setProcessedMessage(highlightProfanity(lowercasedText,"<hs>", "<he>"));
ServerUtils.verbose("ProfanityFilter: Lowercased: " + lowercasedText);
// Stage 2: Mask allowed words
processedText = maskValidWords(processedText);
report.getStepsTaken().put("Masked Valid Words", processedText);
ServerUtils.verbose("ProfanityFilter: Masked Valid Words: " + processedText);
// 2:
String cleanedText = removeFalsePositives(lowercasedText);
response.getReport().getStepsTaken().put("Remove False Positives", cleanedText);
response.setProcessedMessage(highlightProfanity(cleanedText,"<hs>", "<he>"));
ServerUtils.verbose(("ProfanityFilter: Removed False positives: " + cleanedText));
// Stage 3: Convert LeetSpeak (e.g., @ -> a, 3 -> e)
processedText = convertLeetSpeakCharacters(processedText);
report.getStepsTaken().put("Convert LeetSpeak", processedText);
ServerUtils.verbose("ProfanityFilter: Leet Converted: " + processedText);
currentSeverity = checkProfanity(processedText, Severity.MEDIUM_LOW);
if (currentSeverity != Severity.SAFE) return finalizeResponse(response, processedText, "Convert LeetSpeak", currentSeverity);
response.setSeverity(checkProfanity(cleanedText, Severity.LOW));
if (response.getSeverity() != Severity.SAFE) {
response.getReport().getStepsTaken().replace("Remove False Positives", "%s %s".formatted(
highlightProfanity(cleanedText,"||","||"),
Emojis.alarm));
return response;
}
// Stage 4: Strip special characters
processedText = stripSpecialCharacters(processedText);
report.getStepsTaken().put("Remove Special Characters", processedText);
ServerUtils.verbose("ProfanityFilter: Specials Removed: " + processedText);
currentSeverity = checkProfanity(processedText, Severity.MEDIUM);
if (currentSeverity != Severity.SAFE) return finalizeResponse(response, processedText, "Remove Special Characters", currentSeverity);
// 4:
String convertedText = convertLeetSpeakCharacters(cleanedText);
response.getReport().getStepsTaken().put("Convert LeetSpeak", convertedText);
response.setProcessedMessage(highlightProfanity(convertedText,"<hs>", "<he>"));
ServerUtils.verbose(("ProfanityFilter: Leet Converted: " + convertedText));
// Stage 5: Simplify repeating letters (e.g., heeeello -> helo)
processedText = simplifyRepeatingLetters(processedText);
report.getStepsTaken().put("Remove Repeats", processedText);
ServerUtils.verbose("ProfanityFilter: Removed Repeating: " + processedText);
currentSeverity = checkProfanity(processedText, Severity.MEDIUM_HIGH);
if (currentSeverity != Severity.SAFE) return finalizeResponse(response, processedText, "Remove Repeats", currentSeverity);
response.setSeverity(checkProfanity(convertedText, Severity.MEDIUM_LOW));
if (response.getSeverity() != Severity.SAFE) {
response.getReport().getStepsTaken().replace("Convert LeetSpeak", "%s %s".formatted(
highlightProfanity(cleanedText,"||","||"),
Emojis.alarm));
return response;
}
// Stage 6: Remove all spaces and remaining punctuation
processedText = removePunctuation(processedText);
report.getStepsTaken().put("Remove Punctuation", processedText);
ServerUtils.verbose("ProfanityFilter: Remove Punctuation: " + processedText);
currentSeverity = checkProfanity(processedText, Severity.HIGH);
if (currentSeverity != Severity.SAFE) return finalizeResponse(response, processedText, "Remove Punctuation", currentSeverity);
// 6:
String strippedText = stripSpecialCharacters(convertedText);
response.getReport().getStepsTaken().put("Remove Special Characters", strippedText);
response.setProcessedMessage(highlightProfanity(strippedText,"<hs>", "<he>"));
ServerUtils.verbose(("ProfanityFilter: Specials Removed: " + strippedText));
response.setSeverity(checkProfanity(strippedText, Severity.MEDIUM));
if (response.getSeverity() != Severity.SAFE) {
response.getReport().getStepsTaken().replace("Remove Special Characters", "%s %s".formatted(
highlightProfanity(cleanedText,"||","||"),
Emojis.alarm));
return response;
}
// 8:
String simplifiedText = simplifyRepeatingLetters(strippedText);
response.getReport().getStepsTaken().put("Remove Repeats", simplifiedText);
response.setProcessedMessage(highlightProfanity(simplifiedText,"<hs>", "<he>"));
ServerUtils.verbose(("ProfanityFilter: Removed Repeating: " + simplifiedText));
response.setSeverity(checkProfanity(simplifiedText, Severity.MEDIUM_HIGH));
if (response.getSeverity() != Severity.SAFE) {
response.getReport().getStepsTaken().replace("Remove Repeats", "%s %s".formatted(
highlightProfanity(cleanedText,"||","||"),
Emojis.alarm));
return response;
}
// 10:
String finalText = removePeriodsAndSpaces(simplifiedText);
response.getReport().getStepsTaken().put("Remove Punctuation", finalText);
response.setProcessedMessage(highlightProfanity(finalText,"<hs>", "<he>"));
ServerUtils.verbose(("ProfanityFilter: Remove Punctuation: " + finalText));
response.setSeverity(checkProfanity(finalText, Severity.HIGH));
if (response.getSeverity() != Severity.SAFE) {
response.getReport().getStepsTaken().replace("Remove Punctuation", "%s %s".formatted(
highlightProfanity(cleanedText,"||","||"),
Emojis.alarm));
return response;
}
ServerUtils.verbose(("ProfanityFilter: Finished " + finalText));
if (e.isCancelled()) {
ServerUtils.verbose("Profanity response closing: Event is canceled.");
}
ServerUtils.verbose("ProfanityFilter: Finished. No profanity detected.");
return response;
}
private static Severity checkProfanity(String text, Severity backup) {
private static ProfanityResponse finalizeResponse(ProfanityResponse response, String text, String stage, Severity severity) {
response.setSeverity(severity);
String highlightedText = highlightAllProfanity(text, "||", "||");
response.getReport().getStepsTaken().replace(stage, "%s %s".formatted(highlightedText, Emojis.alarm));
response.setProcessedMessage(highlightAllProfanity(text,"█HS█","█HE█"));
ServerUtils.verbose("ProfanityFilter: Flagged at stage '%s' with severity '%s'", stage, severity)
;
return response;
}
private static Severity checkProfanity(String text, Severity current) {
if (containsSlurs(text)) return Severity.SLUR;
if (containsSwears(text)) return backup;
if (containsSwears(text)) return current;
return Severity.SAFE;
}
private static boolean containsSwears(String text) {
ServerUtils.verbose("ProfanityFilter: Checking for swears");
for (String swear : Sentinel.getInstance().getDirector().io.swearList.swears) {
ServerUtils.verbose("ProfanityFilter: Checking for swears in: " + text);
for (String swear : main.dir().io.swearList.swears) {
if (text.contains(swear)) return true;
}
Pattern pattern = Pattern.compile(Sentinel.getInstance().getDirector().io.swearList.regexSwears, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(text);
return matcher.find() && Sentinel.getInstance().getDirector().io.swearList.useRegex;
if (main.dir().io.swearList.useRegex) {
Pattern pattern = Pattern.compile(main.dir().io.swearList.regexSwears, Pattern.CASE_INSENSITIVE);
return pattern.matcher(text).find();
}
return false;
}
private static boolean containsSlurs(String text) {
ServerUtils.verbose("ProfanityFilter: Checking for slurs");
for (String slur : Sentinel.getInstance().getDirector().io.strictList.strict) {
ServerUtils.verbose("ProfanityFilter: Checking for slurs in: " + text);
for (String slur : main.dir().io.strictList.strict) {
if (text.contains(slur)) return true;
}
Pattern pattern = Pattern.compile(Sentinel.getInstance().getDirector().io.strictList.regexStrict, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(text);
return matcher.find() && Sentinel.getInstance().getDirector().io.strictList.useRegex;
}
private static String removeFalsePositives(String text) {
for (String falsePositive : Sentinel.getInstance().getDirector().io.falsePositiveList.swearWhitelist) {
text = text.replace(falsePositive, "");
if (main.dir().io.strictList.useRegex) {
Pattern pattern = Pattern.compile(main.dir().io.strictList.regexStrict, Pattern.CASE_INSENSITIVE);
return pattern.matcher(text).find();
}
if (Sentinel.getInstance().getDirector().io.falsePositiveList.useRegex) text = text.replaceAll(Sentinel.getInstance().getDirector().io.falsePositiveList.regexWhitelist,"");
return text;
return false;
}
private static String maskValidWords(String text) {
String result = text;
for (String falsePositive : main.dir().io.falsePositiveList.swearWhitelist) {
result = result.replace(falsePositive, "█SW█");
}
if (main.dir().io.falsePositiveList.useRegex) {
result = result.replaceAll(main.dir().io.falsePositiveList.regexWhitelist, "█RW█");
}
for (String falsePositive : main.dir().io.falsePositiveList.cleanWords) {
result = result.replace(falsePositive, "█CW█");
}
return result;
}
private static String convertLeetSpeakCharacters(String text) {
text = Text.fromLeetString(text);
Map<String, String> dictionary = Sentinel.getInstance().getDirector().io.advConfig.leetPatterns;
for (String key : dictionary.keySet()) {
if (!text.contains(key)) continue;
try {
if (key.equals("$")) {
text = text.replaceAll("\\$", "s");
}
else {
text = text.replaceAll(key, dictionary.get(key));
}
} catch (PatternSyntaxException ex) {
String regex = "[" + key + "]";
text = text.replaceAll(regex, dictionary.get(key));
}
}
return text;
}
private static String stripSpecialCharacters(String text) {
text = text.replaceAll("[^A-Za-z0-9.,!?;:'\"()\\[\\]{}]", "").trim();
return text;
return text.replaceAll("(?!█[A-Z]{2}█)[^a-zA-Z0-9\\s,.?!█]", "");
}
private static String simplifyRepeatingLetters(String text) {
text = Text.replaceRepeatingLetters(text);
return text;
return FormatUtils.replaceRepeatingLetters(text);
}
private static String removePeriodsAndSpaces(String text) {
return text.replaceAll("[^A-Za-z0-9]", "").replace(" ", "");
private static String removePunctuation(String text) {
return text.replaceAll("[.,!?\\s]", "");
}
private static String highlightProfanity(String text, String start, String end) {
String highlightedSwears = highlightSwears(fullSimplify(text), start, end);
return Text.color(highlightSlurs(highlightedSwears, start, end));
}
private static String highlightSwears(String text, String start, String end) {
for (String swear : Sentinel.getInstance().getDirector().io.swearList.swears) {
text = text.replace(swear, start + swear + end);
}
return text;
}
private static String highlightSlurs(String text, String start, String end) {
for (String slur : Sentinel.getInstance().getDirector().io.strictList.strict) {
text = text.replace(slur, start + slur + end);
}
return text;
}
private static String fullSimplify(String text) {
String lowercasedText = text.toLowerCase();
String cleanedText = removeFalsePositives(lowercasedText);
String convertedText =convertLeetSpeakCharacters(cleanedText);
String strippedText = stripSpecialCharacters(convertedText);
String simplifiedText = simplifyRepeatingLetters(strippedText);
return removePeriodsAndSpaces(simplifiedText);
}
private static String highlightAllProfanity(String text, String start, String end) {
String result = text;
for (String slur : main.dir().io.strictList.strict) {
result = result.replace(slur, start + slur + end);
}
for (String swear : main.dir().io.swearList.swears) {
result = result.replace(swear, start + swear + end);
}
return Text.legacyColor(result);
}
}

View File

@@ -1,15 +1,16 @@
package me.trouper.sentinel.server.functions.chatfilter.profanity;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.Main;
public enum Severity {
LOW(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.lowScore),
MEDIUM_LOW(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.mediumLowScore),
MEDIUM(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.mediumScore),
MEDIUM_HIGH(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.mediumHighScore),
HIGH(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.highScore),
REGEX(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.regexScore),
SLUR(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.highScore),
public enum Severity implements Main {
LOW(main.dir().io.mainConfig.chat.profanityFilter.lowScore),
MEDIUM_LOW(main.dir().io.mainConfig.chat.profanityFilter.mediumLowScore),
MEDIUM(main.dir().io.mainConfig.chat.profanityFilter.mediumScore),
MEDIUM_HIGH(main.dir().io.mainConfig.chat.profanityFilter.mediumHighScore),
HIGH(main.dir().io.mainConfig.chat.profanityFilter.highScore),
REGEX(main.dir().io.mainConfig.chat.profanityFilter.regexScore),
SLUR(main.dir().io.mainConfig.chat.profanityFilter.highScore),
SAFE(0);
private final int score;

View File

@@ -1,6 +1,5 @@
package me.trouper.sentinel.server.functions.chatfilter.spam;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.functions.chatfilter.AbstractActionHandler;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
@@ -14,55 +13,63 @@ public class SpamAction extends AbstractActionHandler<SpamResponse> {
@Override
public void punish(SpamResponse response) {
for (String spamPunishCommand : Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.punishCommands) {
for (String spamPunishCommand : main.dir().io.mainConfig.chat.spamFilter.punishCommands) {
ServerUtils.sendCommand(spamPunishCommand.replaceAll("%player%", response.getEvent().getPlayer().getName()));
}
}
@Override
public void staffWarning(SpamResponse report, Node tree) {
String messageText = Text.prefix("&b&n%s&r &7%s &8(&4%s&7/&c%s&8)".formatted(
report.getEvent().getPlayer().getName(),
report.isPunished() ? Sentinel.getInstance().getDirector().io.lang.violations.chat.spam.autoPunishNotification : Sentinel.getInstance().getDirector().io.lang.violations.chat.spam.preventNotification,
SpamFilter.heatMap.get(report.getEvent().getPlayer().getUniqueId()),
Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.punishHeat
));
String hoverText = HoverFormatter.format(tree);
public void staffWarning(SpamResponse response, Node tree) {
Component message = Text.getMessageAny(
Text.Pallet.INFO,
response.isPunished() ?
main.dir().io.lang.violations.chat.spam.autoPunishNotification :
main.dir().io.lang.violations.chat.spam.preventNotification,
response.getEvent().getPlayer().getName(),
SpamFilter.heatMap.get(response.getEvent().getPlayer().getUniqueId()),
main.dir().io.mainConfig.chat.spamFilter.punishHeat
);
PlayerUtils.forEachPlayer(player -> {
if (player.hasPermission("sentinel.chatfilter.spam.view")) player.sendMessage(Component.text(messageText).hoverEvent(Component.text(hoverText).asHoverEvent()));
if (!player.hasPermission("sentinel.chatfilter.spam.view")) return;
Text.message(Text.Pallet.INFO, player, message.hoverEvent(HoverFormatter.format(tree).asHoverEvent()));
});
}
@Override
public void playerWarning(SpamResponse response) {
String message = Text.prefix(response.isPunished() ? Sentinel.getInstance().getDirector().io.lang.violations.chat.spam.autoPunishWarning : Sentinel.getInstance().getDirector().io.lang.violations.chat.spam.preventWarning) ;
String hoverText = Sentinel.getInstance().getDirector().io.lang.automatedActions.reportable;
Component message = Text.getMessageAny(
Text.Pallet.INFO,
response.isPunished() ? main.dir().io.lang.violations.chat.spam.autoPunishWarning :
main.dir().io.lang.violations.chat.spam.preventWarning
);
String hoverText = main.dir().io.lang.automatedActions.reportable;
String command = "/sentinelcallback fpreport %s".formatted(response.getReport().getId());
response.getEvent().getPlayer().sendMessage(Component.text(message)
.hoverEvent(Component.text(hoverText).asHoverEvent())
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND,command)));
Text.message(Text.Pallet.INFO, response.getEvent().getPlayer(), message
.hoverEvent(Component.text(hoverText).asHoverEvent())
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, command))
);
}
@Override
public Node buildTree(SpamResponse response) {
Node root = new Node("Sentinel");
root.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.chat.spam.treeTitle);
root.addTextLine(Text.format(Text.Pallet.NEUTRAL, Component.text(main.dir().io.lang.violations.chat.spam.treeTitle),response.getPlayer().name()));
Node playerInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.playerInfo.formatted(response.getEvent().getPlayer().getName()));
playerInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.uuid, response.getEvent().getPlayer().getUniqueId().toString());
playerInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.chat.spam.heat, "%s/%s".formatted(SpamFilter.heatMap.get(response.getEvent().getPlayer().getUniqueId()),Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.punishHeat));
Node playerInfo = new Node(main.dir().io.lang.violations.protections.infoNode.playerInfo);
playerInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.uuid, response.getEvent().getPlayer().getUniqueId().toString());
playerInfo.addKeyValue(main.dir().io.lang.violations.chat.spam.heat, "%s/%s".formatted(SpamFilter.heatMap.get(response.getEvent().getPlayer().getUniqueId()),main.dir().io.mainConfig.chat.spamFilter.punishHeat));
root.addChild(playerInfo);
Node reportInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.chat.spam.reportInfoTitle);
reportInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.chat.spam.previousMessage, response.getPreviousMessage());
reportInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.chat.spam.currentMessage, response.getCurrentMessage());
reportInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.chat.spam.similarity, "%s/%s".formatted((int) Math.round(response.getSimilarity()),Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.blockSimilarity));
Node reportInfo = new Node(main.dir().io.lang.violations.chat.spam.reportInfoTitle);
reportInfo.addField(main.dir().io.lang.violations.chat.spam.previousMessage, response.getPreviousMessage());
reportInfo.addField(main.dir().io.lang.violations.chat.spam.currentMessage, response.getCurrentMessage());
reportInfo.addKeyValue(main.dir().io.lang.violations.chat.spam.similarity, "%s/%s".formatted((int) Math.round(response.getSimilarity()),main.dir().io.mainConfig.chat.spamFilter.blockSimilarity));
root.addChild(reportInfo);
Node actions = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.actionNodeTitle);
actions.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.chat.denyMessage);
if (response.isPunished()) actions.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.punishmentCommandsExecuted);
Node actions = new Node(main.dir().io.lang.violations.protections.actionNode.actionNodeTitle);
actions.addTextLine(main.dir().io.lang.violations.chat.denyMessage);
if (response.isPunished()) actions.addTextLine(main.dir().io.lang.violations.protections.actionNode.punishmentCommandsExecuted);
root.addChild(actions);
return root;
@@ -70,6 +77,6 @@ public class SpamAction extends AbstractActionHandler<SpamResponse> {
@Override
protected boolean shouldWarnPlayer(SpamResponse response) {
return !Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.silent;
return !main.dir().io.mainConfig.chat.spamFilter.silent;
}
}
}

View File

@@ -1,17 +1,19 @@
package me.trouper.sentinel.server.functions.chatfilter.spam;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.utils.FormatUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class SpamFilter {
public class SpamFilter implements Main {
public static Map<UUID, Integer> heatMap = new HashMap<>();
public static Map<UUID, String> lastMessageMap = new HashMap<>();
@@ -20,8 +22,8 @@ public class SpamFilter {
ServerUtils.verbose("Anti Spam Opening: Event is canceled.");
}
Player p = e.getPlayer();
String message = Text.removeFirstColor(LegacyComponentSerializer.legacySection().serialize(e.message()));
for (String whitelistedMessage : Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.whitelist) {
String message = PlainTextComponentSerializer.plainText().serialize(e.message());
for (String whitelistedMessage : main.dir().io.mainConfig.chat.spamFilter.whitelist) {
if (whitelistedMessage.equalsIgnoreCase(message)) return;
}
int currentHeat = heatMap.getOrDefault(p.getUniqueId(),0);
@@ -34,7 +36,7 @@ public class SpamFilter {
ServerUtils.verbose("AntiSpam responded");
response.getReport().getStepsTaken().put("Response came back", "Heat to add: %s".formatted(addHeat));
if (currentHeat > Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.punishHeat) {
if (currentHeat > main.dir().io.mainConfig.chat.spamFilter.punishHeat) {
response.setBlocked(true);
response.getReport().getStepsTaken().put("Punished user", "Their final heat was %s".formatted(currentHeat));
response.setPunished(true);
@@ -43,7 +45,7 @@ public class SpamFilter {
return;
}
if (currentHeat > Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.blockHeat) {
if (currentHeat > main.dir().io.mainConfig.chat.spamFilter.blockHeat) {
response.setBlocked(true);
response.getReport().getStepsTaken().put("Blocked message", "Their heat is %s".formatted(currentHeat));
new SpamAction().run(response);
@@ -51,7 +53,7 @@ public class SpamFilter {
return;
}
if (response.getSimilarity() > Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.blockSimilarity) {
if (response.getSimilarity() > main.dir().io.mainConfig.chat.spamFilter.blockSimilarity) {
response.setBlocked(true);
response.getReport().getStepsTaken().put("Blocked message", "The similarity was too high! %s".formatted(response.getSimilarity()));
new SpamAction().run(response);
@@ -69,7 +71,7 @@ public class SpamFilter {
for (UUID p : heatMap.keySet()) {
int heat = heatMap.getOrDefault(p,0);
if (heat > 0) {
heat = heat - Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.heatDecay;
heat = heat - main.dir().io.mainConfig.chat.spamFilter.heatDecay;
heatMap.put(p, Math.max(0, heat));
}
}

View File

@@ -2,9 +2,9 @@ package me.trouper.sentinel.server.functions.chatfilter.spam;
import io.github.retrooper.packetevents.adventure.serializer.legacy.LegacyComponentSerializer;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.functions.chatfilter.FilterResponse;
import me.trouper.sentinel.server.functions.helpers.Report;
import me.trouper.sentinel.utils.FormatUtils;
import me.trouper.sentinel.utils.MathUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
@@ -39,9 +39,9 @@ public class SpamResponse implements FilterResponse {
}
String message = LegacyComponentSerializer.legacySection().serialize(e.message());
Report report = Sentinel.getInstance().getDirector().reportHandler.initializeReport(message);
Report report = main.dir().reportHandler.initializeReport(message);
message = Text.removeFirstColor(message);
message = Text.removeColors(message);
String previousMessage = lastMessageMap.getOrDefault(e.getPlayer().getUniqueId(),"/* Placeholder Message from Sentinel */");
SpamResponse response = new SpamResponse(e,message,previousMessage,0,0,report,false,false);
@@ -51,25 +51,25 @@ public class SpamResponse implements FilterResponse {
response.setSimilarity(similarity);
report.getStepsTaken().put("Calculated Similarity: ","%s".formatted(similarity));
int addHeat = Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.defaultGain;
if (similarity > Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.blockSimilarity) {
addHeat = Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.highGain;
response.getReport().getStepsTaken().put("Similarity is greater than %s%%".formatted(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.blockSimilarity), "That is %s heat. (Auto-Block due to configured value)".formatted(addHeat));
int addHeat = main.dir().io.mainConfig.chat.spamFilter.defaultGain;
if (similarity > main.dir().io.mainConfig.chat.spamFilter.blockSimilarity) {
addHeat = main.dir().io.mainConfig.chat.spamFilter.highGain;
response.getReport().getStepsTaken().put("Similarity is greater than %s%%".formatted(main.dir().io.mainConfig.chat.spamFilter.blockSimilarity), "That is %s heat. (Auto-Block due to configured value)".formatted(addHeat));
response.setHeatAdded(addHeat);
return response;
} else if (similarity > 90) {
addHeat = Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.highGain;
addHeat = main.dir().io.mainConfig.chat.spamFilter.highGain;
response.getReport().getStepsTaken().put("Similarity is greater than 90%", "That is %s heat.".formatted(addHeat));
response.setHeatAdded(addHeat);
return response;
} else if (similarity > 50) {
addHeat = Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.mediumGain;
addHeat = main.dir().io.mainConfig.chat.spamFilter.mediumGain;
response.getReport().getStepsTaken().put("Similarity is greater than 50%", "That is %s heat.".formatted(addHeat));
response.setHeatAdded(addHeat);
return response;
} else if (similarity > 25) {
response.getReport().getStepsTaken().put("Similarity is greater than 25%", "That is %s heat.".formatted(addHeat));
addHeat = Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.lowGain;
addHeat = main.dir().io.mainConfig.chat.spamFilter.lowGain;
response.setHeatAdded(addHeat);
return response;
}

View File

@@ -1,6 +1,5 @@
package me.trouper.sentinel.server.functions.chatfilter.unicode;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.functions.chatfilter.AbstractActionHandler;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
@@ -13,51 +12,59 @@ import net.kyori.adventure.text.event.ClickEvent;
public class UnicodeAction extends AbstractActionHandler<UnicodeResponse> {
@Override
protected void punish(UnicodeResponse response) {
for (String punishCommand : Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.punishCommands) {
ServerUtils.sendCommand(punishCommand.replaceAll("%player%",response.getPlayer().getName()));
for (String punishCommand : main.dir().io.mainConfig.chat.unicodeFilter.punishCommands) {
ServerUtils.sendCommand(punishCommand.replaceAll("%player%", response.getPlayer().getName()));
}
}
@Override
protected void staffWarning(UnicodeResponse response, Node tree) {
String messageText = Text.prefix("&b&n%s&r &7%s".formatted(
response.getPlayer().getName(),
response.isPunished() ? Sentinel.getInstance().getDirector().io.lang.violations.chat.unicode.autoPunishNotification : Sentinel.getInstance().getDirector().io.lang.violations.chat.unicode.preventNotification
));
String hoverText = HoverFormatter.format(tree);
Component message = Text.getMessageAny(
Text.Pallet.INFO,
response.isPunished() ?
main.dir().io.lang.violations.chat.unicode.autoPunishNotification :
main.dir().io.lang.violations.chat.unicode.preventNotification,
response.getPlayer().getName()
);
PlayerUtils.forEachPlayer(player -> {
if (player.hasPermission("sentinel.chatfilter.unicode.view")) player.sendMessage(Component.text(messageText).hoverEvent(Component.text(hoverText).asHoverEvent()));
if (!player.hasPermission("sentinel.chatfilter.unicode.view")) return;
Text.message(Text.Pallet.INFO, player, message.hoverEvent(HoverFormatter.format(tree).asHoverEvent()));
});
}
@Override
protected void playerWarning(UnicodeResponse response) {
String message = Text.prefix(response.isPunished() ? Sentinel.getInstance().getDirector().io.lang.violations.chat.unicode.autoPunishWarning : Sentinel.getInstance().getDirector().io.lang.violations.chat.unicode.preventWarning);
String hoverText = Sentinel.getInstance().getDirector().io.lang.automatedActions.reportable;
Component message = Text.getMessageAny(
Text.Pallet.INFO,
response.isPunished() ? main.dir().io.lang.violations.chat.unicode.autoPunishWarning :
main.dir().io.lang.violations.chat.unicode.preventWarning
);
String hoverText = main.dir().io.lang.automatedActions.reportable;
String command = "/sentinelcallback fpreport %s".formatted(response.getReport().getId());
response.getPlayer().sendMessage(Component.text(message)
Text.message(Text.Pallet.INFO, response.getPlayer(), message
.hoverEvent(Component.text(hoverText).asHoverEvent())
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND,command)));
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, command))
);
}
@Override
protected Node buildTree(UnicodeResponse response) {
Node root = new Node("Sentinel");
root.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.chat.unicode.treeTitle);
root.addTextLine(Text.format(Text.Pallet.NEUTRAL,Component.text(main.dir().io.lang.violations.chat.unicode.treeTitle),response.getPlayer().name()));
Node playerInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.playerInfo.formatted(response.getPlayer().getName()));
playerInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.uuid, response.getPlayer().getUniqueId().toString());
Node playerInfo = new Node(main.dir().io.lang.violations.protections.infoNode.playerInfo.formatted(response.getPlayer().getName()));
playerInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.uuid, response.getPlayer().getUniqueId().toString());
root.addChild(playerInfo);
Node reportInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.chat.unicode.reportInfoTitle);
reportInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.chat.originalMessage, response.getOriginalMessage());
reportInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.chat.highlightedMessage, response.getHighlightedMessage());
Node reportInfo = new Node(main.dir().io.lang.violations.chat.unicode.reportInfoTitle);
reportInfo.addField(main.dir().io.lang.violations.chat.originalMessage, response.getOriginalMessage());
reportInfo.addField(Component.text(main.dir().io.lang.violations.chat.highlightedMessage), Node.parseLegacyText(response.getHighlightedMessage()));
root.addChild(reportInfo);
Node actions = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.actionNodeTitle);
actions.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.chat.denyMessage);
if (response.isPunished()) actions.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.punishmentCommandsExecuted);
Node actions = new Node(main.dir().io.lang.violations.protections.actionNode.actionNodeTitle);
actions.addTextLine(main.dir().io.lang.violations.chat.denyMessage);
if (response.isPunished()) actions.addTextLine(main.dir().io.lang.violations.protections.actionNode.punishmentCommandsExecuted);
root.addChild(actions);
return root;
@@ -65,6 +72,6 @@ public class UnicodeAction extends AbstractActionHandler<UnicodeResponse> {
@Override
protected boolean shouldWarnPlayer(UnicodeResponse response) {
return !Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.silent;
return !main.dir().io.mainConfig.chat.unicodeFilter.silent;
}
}
}

View File

@@ -2,10 +2,10 @@ package me.trouper.sentinel.server.functions.chatfilter.unicode;
import io.github.retrooper.packetevents.adventure.serializer.legacy.LegacyComponentSerializer;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.Emojis;
import me.trouper.sentinel.data.types.Emojis;
import me.trouper.sentinel.server.functions.chatfilter.FilterResponse;
import me.trouper.sentinel.server.functions.helpers.Report;
import me.trouper.sentinel.utils.FormatUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import org.bukkit.entity.Player;
@@ -37,29 +37,31 @@ public class UnicodeResponse implements FilterResponse {
}
String message = LegacyComponentSerializer.legacySection().serialize(e.message());
message = Text.removeFirstColor(message);
Report report = Sentinel.getInstance().getDirector().reportHandler.initializeReport(message);
message = Text.removeColors(message);
Report report = main.dir().reportHandler.initializeReport(message);
UnicodeResponse response = new UnicodeResponse(e,message,message,report,false,false);
String disallowedRegex = Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.regex;
ServerUtils.verbose("Regex: %s\nMessage: %s".formatted(disallowedRegex,message));
UnicodeResponse response = new UnicodeResponse(e, message, message, report, false, false);
String disallowedRegex = main.dir().io.mainConfig.chat.unicodeFilter.regex;
Pattern pattern = Pattern.compile(disallowedRegex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(message);
ServerUtils.verbose("Matcher result %s\nGroup 1: %s".formatted(matcher.find(),matcher.find() ? matcher.group() : ""));
boolean found = matcher.find();
response.getReport().getStepsTaken().put("Anti-URL", "`%s`".formatted(
message
));
ServerUtils.verbose("Matcher result: %s",found);
if (found) {
ServerUtils.verbose("Group 1: %s",matcher.group());
}
if (matcher.find()) {
ServerUtils.verbose("Unicode Filter: Caught Unicode: " + disallowedRegex);
response.getReport().getStepsTaken().put("Anti-Unicode", "`" + message + "`");
if (found) {
ServerUtils.verbose("Unicode Filter: Caught Unicode using regex: " + disallowedRegex);
response.getReport().getStepsTaken().replace("Anti-Unicode", "`%s` %s".formatted(message, Emojis.alarm));
response.setBlocked(true);
response.setPunished(Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.punished);
response.setHighlightedMessage(Text.regexHighlighter(message,Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.regex," > ", " < "));
response.setPunished(main.dir().io.mainConfig.chat.unicodeFilter.punished);
response.setHighlightedMessage(FormatUtils.regexHighlighter(message, disallowedRegex, "█HS█", "█HE█"));
}
return response;
@@ -117,4 +119,4 @@ public class UnicodeResponse implements FilterResponse {
public void setPunished(boolean punished) {
this.punished = punished;
}
}
}

View File

@@ -1,6 +1,5 @@
package me.trouper.sentinel.server.functions.chatfilter.url;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.functions.chatfilter.AbstractActionHandler;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.ServerUtils;
@@ -13,51 +12,59 @@ import net.kyori.adventure.text.event.ClickEvent;
public class UrlAction extends AbstractActionHandler<UrlResponse> {
@Override
protected void punish(UrlResponse response) {
for (String punishCommand : Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.punishCommands) {
ServerUtils.sendCommand(punishCommand.replaceAll("%player%",response.getPlayer().getName()));
for (String punishCommand : main.dir().io.mainConfig.chat.urlFilter.punishCommands) {
ServerUtils.sendCommand(punishCommand.replaceAll("%player%", response.getPlayer().getName()));
}
}
@Override
protected void staffWarning(UrlResponse response, Node tree) {
String messageText = Text.prefix("&b&n%s&r &7%s".formatted(
response.getPlayer().getName(),
response.isPunished() ? Sentinel.getInstance().getDirector().io.lang.violations.chat.url.autoPunishNotification : Sentinel.getInstance().getDirector().io.lang.violations.chat.url.preventNotification
));
String hoverText = HoverFormatter.format(tree);
Component message = Text.getMessageAny(
Text.Pallet.INFO,
response.isPunished() ?
main.dir().io.lang.violations.chat.url.autoPunishNotification :
main.dir().io.lang.violations.chat.url.preventNotification,
response.getPlayer().getName()
);
PlayerUtils.forEachPlayer(player -> {
if (player.hasPermission("sentinel.chatfilter.url.view")) player.sendMessage(Component.text(messageText).hoverEvent(Component.text(hoverText).asHoverEvent()));
if (!player.hasPermission("sentinel.chatfilter.url.view")) return;
Text.message(Text.Pallet.INFO, player, message.hoverEvent(HoverFormatter.format(tree).asHoverEvent()));
});
}
@Override
protected void playerWarning(UrlResponse response) {
String message = Text.prefix(response.isPunished() ? Sentinel.getInstance().getDirector().io.lang.violations.chat.url.autoPunishWarning : Sentinel.getInstance().getDirector().io.lang.violations.chat.url.preventWarning);
String hoverText = Sentinel.getInstance().getDirector().io.lang.automatedActions.reportable;
Component message = Text.getMessageAny(
Text.Pallet.INFO,
response.isPunished() ? main.dir().io.lang.violations.chat.url.autoPunishWarning :
main.dir().io.lang.violations.chat.url.preventWarning
);
String hoverText = main.dir().io.lang.automatedActions.reportable;
String command = "/sentinelcallback fpreport %s".formatted(response.getReport().getId());
response.getPlayer().sendMessage(Component.text(message)
Text.message(Text.Pallet.INFO, response.getPlayer(), message
.hoverEvent(Component.text(hoverText).asHoverEvent())
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND,command)));
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, command))
);
}
@Override
protected Node buildTree(UrlResponse response) {
Node root = new Node("Sentinel");
root.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.chat.url.treeTitle);
root.addTextLine(Text.format(Text.Pallet.NEUTRAL,Component.text(main.dir().io.lang.violations.chat.url.treeTitle),response.getPlayer().name()));
Node playerInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.playerInfo.formatted(response.getPlayer().getName()));
playerInfo.addKeyValue(Sentinel.getInstance().getDirector().io.lang.violations.protections.infoNode.uuid, response.getPlayer().getUniqueId().toString());
Node playerInfo = new Node(main.dir().io.lang.violations.protections.infoNode.playerInfo.formatted(response.getPlayer().getName()));
playerInfo.addKeyValue(main.dir().io.lang.violations.protections.infoNode.uuid, response.getPlayer().getUniqueId().toString());
root.addChild(playerInfo);
Node reportInfo = new Node(Sentinel.getInstance().getDirector().io.lang.violations.chat.url.reportInfoTitle);
reportInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.chat.originalMessage, response.getOriginalMessage());
reportInfo.addField(Sentinel.getInstance().getDirector().io.lang.violations.chat.highlightedMessage, response.getHighlightedMessage());
Node reportInfo = new Node(main.dir().io.lang.violations.chat.url.reportInfoTitle);
reportInfo.addField(main.dir().io.lang.violations.chat.originalMessage, response.getOriginalMessage());
reportInfo.addField(Component.text(main.dir().io.lang.violations.chat.highlightedMessage), Node.parseLegacyText(response.getHighlightedMessage()));
root.addChild(reportInfo);
Node actions = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.actionNodeTitle);
actions.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.chat.denyMessage);
if (response.isPunished()) actions.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.punishmentCommandsExecuted);
Node actions = new Node(main.dir().io.lang.violations.protections.actionNode.actionNodeTitle);
actions.addTextLine(main.dir().io.lang.violations.chat.denyMessage);
if (response.isPunished()) actions.addTextLine(main.dir().io.lang.violations.protections.actionNode.punishmentCommandsExecuted);
root.addChild(actions);
return root;
@@ -65,6 +72,6 @@ public class UrlAction extends AbstractActionHandler<UrlResponse> {
@Override
protected boolean shouldWarnPlayer(UrlResponse response) {
return !Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.silent;
return !main.dir().io.mainConfig.chat.urlFilter.silent;
}
}
}

View File

@@ -2,12 +2,11 @@ package me.trouper.sentinel.server.functions.chatfilter.url;
import io.github.retrooper.packetevents.adventure.serializer.legacy.LegacyComponentSerializer;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.Emojis;
import me.trouper.sentinel.data.types.Emojis;
import me.trouper.sentinel.server.functions.chatfilter.FilterResponse;
import me.trouper.sentinel.server.functions.helpers.Report;
import me.trouper.sentinel.utils.FormatUtils;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import org.bukkit.entity.Player;
import java.util.regex.Matcher;
@@ -35,9 +34,9 @@ public class UrlResponse implements FilterResponse {
}
String message = LegacyComponentSerializer.legacySection().serialize(e.message());
Report report = Sentinel.getInstance().getDirector().reportHandler.initializeReport(message);
Report report = main.dir().reportHandler.initializeReport(message);
UrlResponse response = new UrlResponse(e,message,message,report,false,false);
for (String allowed : Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.whitelist) {
for (String allowed : main.dir().io.mainConfig.chat.urlFilter.whitelist) {
message = message.replaceAll(allowed,"");
}
@@ -45,7 +44,7 @@ public class UrlResponse implements FilterResponse {
message
));
String urlRegex = Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.regex;
String urlRegex = main.dir().io.mainConfig.chat.urlFilter.regex;
Pattern pattern = Pattern.compile(urlRegex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(message);
@@ -55,12 +54,12 @@ public class UrlResponse implements FilterResponse {
));
if (matcher.find()) {
String highlighted = Text.regexHighlighter(message,Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.regex," > "," < ");
String highlighted = FormatUtils.regexHighlighter(message,main.dir().io.mainConfig.chat.urlFilter.regex,"█HS█","█HE█");
ServerUtils.verbose("Caught URL: " + highlighted);
response.getReport().getStepsTaken().replace("Anti-URL", "`%s` %s".formatted(highlighted, Emojis.alarm));
response.setBlocked(true);
response.setPunished(Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.punished);
response.setPunished(main.dir().io.mainConfig.chat.urlFilter.punished);
response.setHighlightedMessage(highlighted);
}

View File

@@ -1,7 +1,7 @@
package me.trouper.sentinel.server.functions.helpers;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.trees.Node;
import org.bukkit.Material;
@@ -14,7 +14,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
public class ActionConfiguration {
public class ActionConfiguration implements Main {
private Player player;
private boolean deop;
private Cancellable event;
@@ -162,7 +162,7 @@ public class ActionConfiguration {
private boolean punish;
private List<String> punishmentCommands = new ArrayList<>();
private boolean logToDiscord;
private Node actionNode = new Node(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.actionNodeTitle);
private Node actionNode = new Node(main.dir().io.lang.violations.protections.actionNode.actionNodeTitle);
private List<Consumer<ActionConfiguration>> actions = new ArrayList<>();
@@ -179,7 +179,7 @@ public class ActionConfiguration {
if (config.player != null) {
config.player.setOp(false);
}
config.actionNode.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.userDeoped);
config.actionNode.addTextLine(main.dir().io.lang.violations.protections.actionNode.userDeoped);
});
return this;
}
@@ -197,7 +197,7 @@ public class ActionConfiguration {
if (config.event != null) {
config.event.setCancelled(true);
}
config.actionNode.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.eventCancelled);
config.actionNode.addTextLine(main.dir().io.lang.violations.protections.actionNode.eventCancelled);
});
return this;
}
@@ -214,7 +214,7 @@ public class ActionConfiguration {
config.destroyBlock = destroyBlock;
if (config.block != null) {
config.block.setType(Material.AIR);
config.actionNode.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.destroyedBlock);
config.actionNode.addTextLine(main.dir().io.lang.violations.protections.actionNode.destroyedBlock);
}
});
return this;
@@ -225,11 +225,11 @@ public class ActionConfiguration {
actions.add(config -> {
config.restoreBlock = restoreBlock;
if (config.block != null) {
CommandBlockHolder holder = Sentinel.getInstance().getDirector().whitelistManager.getFromList(config.block.getLocation());
CommandBlockHolder holder = main.dir().whitelistManager.getFromList(config.block.getLocation());
if (holder != null && holder.restore()) {
config.actionNode.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.restore);
config.actionNode.addTextLine(main.dir().io.lang.violations.protections.actionNode.restore);
} else {
config.actionNode.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.restoreFailed);
config.actionNode.addTextLine(main.dir().io.lang.violations.protections.actionNode.restoreFailed);
}
}
});
@@ -267,7 +267,7 @@ public class ActionConfiguration {
for (String cmd : punishmentCommands) {
ServerUtils.sendCommand(cmd.replaceAll("%player%", config.player.getName()));
}
config.actionNode.addTextLine(Sentinel.getInstance().getDirector().io.lang.violations.protections.actionNode.punishmentCommandsExecuted);
config.actionNode.addTextLine(main.dir().io.lang.violations.protections.actionNode.punishmentCommandsExecuted);
}
});
return this;

View File

@@ -1,12 +1,12 @@
package me.trouper.sentinel.server.functions.helpers;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.misc.Selection;
import me.trouper.sentinel.data.misc.SerialLocation;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.data.types.Selection;
import me.trouper.sentinel.data.types.SerialLocation;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.server.events.admin.WandEvents;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
@@ -21,7 +21,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
public class CBWhitelistManager {
public class CBWhitelistManager implements Main {
public Set<UUID> autoWhitelist = new HashSet<>();
@@ -50,7 +50,7 @@ public class CBWhitelistManager {
public void removeSelectionFromWhitelist(Player player) {
Selection selection = WandEvents.selections.get(player.getUniqueId());
if (selection == null || !selection.isComplete()) {
player.sendMessage(Text.prefix("You must set 2 points first."));
errorAny(player,"You must set 2 points first.");
return;
}
AtomicInteger number = new AtomicInteger();
@@ -61,13 +61,13 @@ public class CBWhitelistManager {
}
});
player.sendMessage(Text.prefix("Removed all &b%s&7 command blocks from the whitelist in your selection.".formatted(number.get())));
successAny(player,"Removed all {0} command blocks from the whitelist in your selection.",number.get());
}
public void deleteSelection(Player player) {
Selection selection = WandEvents.selections.get(player.getUniqueId());
if (selection == null || !selection.isComplete()) {
player.sendMessage(Text.prefix("You must set 2 points first."));
errorAny(player,"You must set 2 points first.");
return;
}
AtomicInteger number = new AtomicInteger();
@@ -78,13 +78,13 @@ public class CBWhitelistManager {
}
});
player.sendMessage(Text.prefix("Deleted all &b%s&7 command blocks from the whitelist in your selection.".formatted(number.get())));
successAny(player,"Deleted all {0} command blocks from the whitelist in your selection.",number.get());
}
public void addSelectionToWhitelist(Player player) {
Selection selection = WandEvents.selections.get(player.getUniqueId());
if (selection == null || !selection.isComplete()) {
player.sendMessage(Text.prefix("You must set 2 points first."));
errorAny(player,"You must set 2 points first.");
return;
}
@@ -96,12 +96,12 @@ public class CBWhitelistManager {
}
});
player.sendMessage(Text.prefix("Whitelisted all &b%s&7 command blocks in your selection.".formatted(number.get())));
successAny(player,"Whitelisted all {0} command blocks in your selection.",number.get());
}
public int clearAll() {
int total = 0;
for (CommandBlockHolder cb : Sentinel.getInstance().getDirector().io.whitelistStorage.holders) {
for (CommandBlockHolder cb : main.dir().io.whitelistStorage.holders) {
cb.destroy();
cb.delete();
total++;
@@ -115,7 +115,7 @@ public class CBWhitelistManager {
public int clearAll(UUID who) {
int total = 0;
for (CommandBlockHolder cb : Sentinel.getInstance().getDirector().io.whitelistStorage.holders) {
for (CommandBlockHolder cb : main.dir().io.whitelistStorage.holders) {
if (!cb.owner().equals(who.toString())) continue;
cb.destroy();
cb.delete();
@@ -130,7 +130,7 @@ public class CBWhitelistManager {
public int restoreAll() {
int total = 0;
for (CommandBlockHolder cb : Sentinel.getInstance().getDirector().io.whitelistStorage.holders) {
for (CommandBlockHolder cb : main.dir().io.whitelistStorage.holders) {
if (cb.isWhitelisted() && cb.restore()) total++;
}
return total;
@@ -138,7 +138,7 @@ public class CBWhitelistManager {
public int restoreAll(UUID who) {
int total = 0;
for (CommandBlockHolder cb : Sentinel.getInstance().getDirector().io.whitelistStorage.holders) {
for (CommandBlockHolder cb : main.dir().io.whitelistStorage.holders) {
if (!cb.owner().equals(who.toString())) continue;
if (cb.isWhitelisted() && cb.restore()) total++;
}
@@ -165,7 +165,7 @@ public class CBWhitelistManager {
}
public CommandBlockHolder getFromList(UUID entityUUID) {
for (CommandBlockHolder existing : Sentinel.getInstance().getDirector().io.whitelistStorage.holders) {
for (CommandBlockHolder existing : main.dir().io.whitelistStorage.holders) {
if (existing.loc().isUUID() && existing.loc().toUIID().equals(entityUUID)) {
return existing;
}
@@ -174,7 +174,7 @@ public class CBWhitelistManager {
}
public CommandBlockHolder getFromList(Location loc) {
for (CommandBlockHolder existing : Sentinel.getInstance().getDirector().io.whitelistStorage.holders) {
for (CommandBlockHolder existing : main.dir().io.whitelistStorage.holders) {
if (existing.loc().isSameLocation(loc)) {
return existing;
}
@@ -183,7 +183,7 @@ public class CBWhitelistManager {
}
public CommandBlockHolder getFromList(SerialLocation loc) {
for (CommandBlockHolder existing : Sentinel.getInstance().getDirector().io.whitelistStorage.holders) {
for (CommandBlockHolder existing : main.dir().io.whitelistStorage.holders) {
if (existing.loc().isSameLocation(loc)) {
return existing;
}

View File

@@ -4,6 +4,7 @@ import io.github.itzispyder.pdk.utils.ServerUtils;
import io.papermc.paper.chat.ChatRenderer;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.server.commands.SentinelCommand;
import me.trouper.sentinel.server.events.violations.players.ChatEvent;
import net.kyori.adventure.chat.SignedMessage;
@@ -13,7 +14,7 @@ import org.bukkit.entity.Player;
import java.util.*;
public class MessageHandler {
public class MessageHandler implements Main {
public final Map<UUID,UUID> replyMap = new HashMap<>();
public void messagePlayer(Player sender, Player receiver, String message) {
AsyncChatEvent checkEvent = new AsyncChatEvent(true,sender, new HashSet<>(Arrays.asList(receiver, sender)), ChatRenderer.defaultRenderer(),Component.text(message),Component.text(message), SignedMessage.system(message,Component.text(message)));
@@ -21,8 +22,8 @@ public class MessageHandler {
new ChatEvent().handleEvent(checkEvent);
if (checkEvent.isCancelled()) return;
sender.sendMessage(Sentinel.getInstance().getDirector().io.lang.playerInteraction.messageSent.formatted(receiver.getName(),message));
receiver.sendMessage(Sentinel.getInstance().getDirector().io.lang.playerInteraction.messageReceived.formatted(sender.getName(),message));
sender.sendMessage(main.dir().io.lang.playerInteraction.messageSent.formatted(receiver.getName(),message)); // This "sendMessage" call is correct
receiver.sendMessage(main.dir().io.lang.playerInteraction.messageReceived.formatted(sender.getName(),message)); // This "sendMessage" call is correct
replyMap.put(receiver.getUniqueId(),sender.getUniqueId());
sendSpy(sender,receiver,message);
}
@@ -32,9 +33,9 @@ public class MessageHandler {
if (SentinelCommand.spyMap.getOrDefault(player.getUniqueId(),false)) {
TextComponent notification = Component
.text(Sentinel.getInstance().getDirector().io.lang.socialSpy.spyMessage.formatted(sender.getName(),receiver.getName()))
.hoverEvent(Component.text(Sentinel.getInstance().getDirector().io.lang.socialSpy.spyMessageHover.formatted(sender.getName(),receiver.getName(),message)));
player.sendMessage(notification);
.text(main.dir().io.lang.socialSpy.spyMessage.formatted(sender.getName(),receiver.getName()))
.hoverEvent(Component.text(main.dir().io.lang.socialSpy.spyMessageHover.formatted(sender.getName(),receiver.getName(),message)));
player.sendMessage(notification); // This "sendMessage" call is correct
}
});
}

View File

@@ -37,4 +37,8 @@ public class Report {
public void setStepsTaken(LinkedHashMap<String, String> stepsTaken) {
this.stepsTaken = stepsTaken;
}
public void addStep(String name, String step) {
getStepsTaken().put(name,step);
}
}

View File

@@ -2,7 +2,7 @@ package me.trouper.sentinel.server.functions.helpers;
import io.github.itzispyder.pdk.utils.SchedulerUtils;
import io.github.itzispyder.pdk.utils.discord.DiscordEmbed;
import me.trouper.sentinel.data.misc.Emojis;
import me.trouper.sentinel.data.types.Emojis;
import me.trouper.sentinel.utils.RandomUtils;
import me.trouper.sentinel.utils.trees.EmbedFormatter;
import org.bukkit.entity.Player;

View File

@@ -2,8 +2,9 @@ package me.trouper.sentinel.server.functions.hotbar;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.config.NBTConfig;
import me.trouper.sentinel.server.Main;
public abstract class AbstractCheck<T> {
public NBTConfig config = Sentinel.getInstance().getDirector().io.nbtConfig;
public abstract class AbstractCheck<T> implements Main {
public NBTConfig config = main.dir().io.nbtConfig;
public abstract boolean passes(T input);
}

View File

@@ -26,7 +26,7 @@ public class EnchantmentCheck extends AbstractCheck<ItemStack> {
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
Enchantment enchantment = entry.getKey();
int level = entry.getValue();
if (level > Sentinel.getInstance().getDirector().io.nbtConfig.globalMaxEnchant || isOverLimit(enchantment, level)) {
if (level > main.dir().io.nbtConfig.globalMaxEnchant || isOverLimit(enchantment, level)) {
return true;
}
}
@@ -35,92 +35,92 @@ public class EnchantmentCheck extends AbstractCheck<ItemStack> {
}
public static boolean isOverLimit(Enchantment enchantment, int level) {
int maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.globalMaxEnchant;
int maxLevel = main.dir().io.nbtConfig.globalMaxEnchant;
if (enchantment.equals(MENDING)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxMending;
maxLevel = main.dir().io.nbtConfig.maxMending;
} else if (enchantment.equals(Enchantment.UNBREAKING)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxUnbreaking;
maxLevel = main.dir().io.nbtConfig.maxUnbreaking;
} else if (enchantment.equals(Enchantment.VANISHING_CURSE)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxCurseOfVanishing;
maxLevel = main.dir().io.nbtConfig.maxCurseOfVanishing;
} else if (enchantment.equals(Enchantment.BINDING_CURSE)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxCurseOfBinding;
maxLevel = main.dir().io.nbtConfig.maxCurseOfBinding;
} else if (enchantment.equals(Enchantment.AQUA_AFFINITY)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxAquaAffinity;
maxLevel = main.dir().io.nbtConfig.maxAquaAffinity;
} else if (enchantment.equals(Enchantment.PROTECTION)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxProtection;
maxLevel = main.dir().io.nbtConfig.maxProtection;
} else if (enchantment.equals(Enchantment.BLAST_PROTECTION)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxBlastProtection;
maxLevel = main.dir().io.nbtConfig.maxBlastProtection;
} else if (enchantment.equals(Enchantment.DEPTH_STRIDER)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxDepthStrider;
maxLevel = main.dir().io.nbtConfig.maxDepthStrider;
} else if (enchantment.equals(Enchantment.FEATHER_FALLING)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxFeatherFalling;
maxLevel = main.dir().io.nbtConfig.maxFeatherFalling;
} else if (enchantment.equals(Enchantment.FIRE_PROTECTION)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxFireProtection;
maxLevel = main.dir().io.nbtConfig.maxFireProtection;
} else if (enchantment.equals(Enchantment.FROST_WALKER)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxFrostWalker;
maxLevel = main.dir().io.nbtConfig.maxFrostWalker;
} else if (enchantment.equals(Enchantment.PROJECTILE_PROTECTION)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxProjectileProtection;
maxLevel = main.dir().io.nbtConfig.maxProjectileProtection;
} else if (enchantment.equals(Enchantment.RESPIRATION)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxRespiration;
maxLevel = main.dir().io.nbtConfig.maxRespiration;
} else if (enchantment.equals(Enchantment.SOUL_SPEED)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxSoulSpeed;
maxLevel = main.dir().io.nbtConfig.maxSoulSpeed;
} else if (enchantment.equals(Enchantment.THORNS)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxThorns;
maxLevel = main.dir().io.nbtConfig.maxThorns;
} else if (enchantment.equals(Enchantment.SWEEPING_EDGE)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxSweepingEdge;
maxLevel = main.dir().io.nbtConfig.maxSweepingEdge;
} else if (enchantment.equals(Enchantment.SWIFT_SNEAK)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxSwiftSneak;
maxLevel = main.dir().io.nbtConfig.maxSwiftSneak;
} else if (enchantment.equals(Enchantment.BANE_OF_ARTHROPODS)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxBaneOfArthropods;
maxLevel = main.dir().io.nbtConfig.maxBaneOfArthropods;
} else if (enchantment.equals(Enchantment.FIRE_ASPECT)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxFireAspect;
maxLevel = main.dir().io.nbtConfig.maxFireAspect;
} else if (enchantment.equals(Enchantment.LOOTING)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxLooting;
maxLevel = main.dir().io.nbtConfig.maxLooting;
} else if (enchantment.equals(Enchantment.IMPALING)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxImpaling;
maxLevel = main.dir().io.nbtConfig.maxImpaling;
} else if (enchantment.equals(Enchantment.KNOCKBACK)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxKnockback;
maxLevel = main.dir().io.nbtConfig.maxKnockback;
} else if (enchantment.equals(Enchantment.SHARPNESS)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxSharpness;
maxLevel = main.dir().io.nbtConfig.maxSharpness;
} else if (enchantment.equals(Enchantment.SMITE)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxSmite;
maxLevel = main.dir().io.nbtConfig.maxSmite;
} else if (enchantment.equals(Enchantment.CHANNELING)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxChanneling;
maxLevel = main.dir().io.nbtConfig.maxChanneling;
} else if (enchantment.equals(Enchantment.FLAME)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxFlame;
maxLevel = main.dir().io.nbtConfig.maxFlame;
} else if (enchantment.equals(Enchantment.INFINITY)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxInfinity;
maxLevel = main.dir().io.nbtConfig.maxInfinity;
} else if (enchantment.equals(Enchantment.LOYALTY)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxLoyalty;
maxLevel = main.dir().io.nbtConfig.maxLoyalty;
} else if (enchantment.equals(Enchantment.RIPTIDE)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxRiptide;
maxLevel = main.dir().io.nbtConfig.maxRiptide;
} else if (enchantment.equals(Enchantment.MULTISHOT)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxMultishot;
maxLevel = main.dir().io.nbtConfig.maxMultishot;
} else if (enchantment.equals(Enchantment.PIERCING)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxPiercing;
maxLevel = main.dir().io.nbtConfig.maxPiercing;
} else if (enchantment.equals(Enchantment.POWER)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxPower;
maxLevel = main.dir().io.nbtConfig.maxPower;
} else if (enchantment.equals(Enchantment.PUNCH)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxPunch;
maxLevel = main.dir().io.nbtConfig.maxPunch;
} else if (enchantment.equals(Enchantment.QUICK_CHARGE)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxQuickCharge;
maxLevel = main.dir().io.nbtConfig.maxQuickCharge;
} else if (enchantment.equals(Enchantment.EFFICIENCY)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxEfficiency;
maxLevel = main.dir().io.nbtConfig.maxEfficiency;
} else if (enchantment.equals(Enchantment.FORTUNE)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxFortune;
maxLevel = main.dir().io.nbtConfig.maxFortune;
} else if (enchantment.equals(Enchantment.LUCK_OF_THE_SEA)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxLuckOfTheSea;
maxLevel = main.dir().io.nbtConfig.maxLuckOfTheSea;
} else if (enchantment.equals(Enchantment.LURE)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxLure;
maxLevel = main.dir().io.nbtConfig.maxLure;
} else if (enchantment.equals(Enchantment.SILK_TOUCH)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxSilkTouch;
maxLevel = main.dir().io.nbtConfig.maxSilkTouch;
} else if (enchantment.equals(Enchantment.BREACH)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxBreach;
maxLevel = main.dir().io.nbtConfig.maxBreach;
} else if (enchantment.equals(Enchantment.DENSITY)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxDensity;
maxLevel = main.dir().io.nbtConfig.maxDensity;
} else if (enchantment.equals(Enchantment.WIND_BURST)) {
maxLevel = Sentinel.getInstance().getDirector().io.nbtConfig.maxWindBurst;
maxLevel = main.dir().io.nbtConfig.maxWindBurst;
}
return level > maxLevel;

View File

@@ -1,5 +1,6 @@
package me.trouper.sentinel.server.functions.hotbar.items;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTItem;
import io.github.itzispyder.pdk.utils.misc.Pair;
import me.trouper.sentinel.Sentinel;
@@ -25,10 +26,10 @@ public class RateLimitCheck extends AbstractCheck<Pair<Player,ItemStack>> {
UUID uuid = player.getUniqueId();
ItemStack item = input.right;
return itemLimit(player,uuid,item) && dataLimit(player,uuid,item);
return itemLimit(uuid,item) && dataLimit(uuid,item);
}
private boolean itemLimit(Player player, UUID uuid, ItemStack item) {
private boolean itemLimit(UUID uuid, ItemStack item) {
int currentUsed = itemsUsed.getOrDefault(uuid,0);
ServerUtils.verbose("Current Player used items: " + currentUsed);
currentUsed++;
@@ -37,13 +38,12 @@ public class RateLimitCheck extends AbstractCheck<Pair<Player,ItemStack>> {
}
private boolean dataLimit(Player player, UUID uuid, ItemStack item) {
private boolean dataLimit(UUID uuid, ItemStack item) {
int currentData = dataUsed.getOrDefault(uuid,0);
ServerUtils.verbose("Current Player used data: " + currentData);
try {
NBTItem nbt = new NBTItem(item);
int itemData = nbt.toString().length();
int itemData = NBT.readNbt(item).toString().length();
ServerUtils.verbose("Item data: " + itemData);
if (currentData < config.rateLimit.maxOverhead) currentData += itemData;
} catch (Exception e) {

View File

@@ -1,9 +1,17 @@
package me.trouper.sentinel.server.gui;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.utils.ItemBuilder;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.OldTXT;
import me.trouper.sentinel.utils.Text;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
@@ -17,147 +25,171 @@ public class Items {
public static final ItemStack BLANK = ItemBuilder.create()
.material(Material.LIGHT_GRAY_STAINED_GLASS_PANE)
.name(Text.color("&7"))
.displayName(Component.empty())
.build();
public static final ItemStack GREEN = ItemBuilder.create()
.material(Material.LIME_STAINED_GLASS_PANE)
.name(Text.color("&7"))
.displayName(Component.empty())
.build();
public static final ItemStack RED = ItemBuilder.create()
.material(Material.RED_STAINED_GLASS_PANE)
.name(Text.color("&7"))
.displayName(Component.empty())
.build();
public static final ItemStack BACK = ItemBuilder.create()
.material(Material.ARROW)
.name(Text.color("&cBack"))
.lore(Text.color("&8&l➥&7 Return to the previous page"))
.displayName(Component.text("Back",NamedTextColor.RED).decoration(TextDecoration.ITALIC,false))
.loreComponent(Text.color("&8&l➥&7 Return to the previous page"))
.build();
public static final ItemStack CREDITS = ItemBuilder.create()
.material(Material.SHIELD)
.name(Text.color("&6&lSentinel &8&l|&f Anti-Nuke"))
.lore(" ")
.lore(Text.color("&bVersion&7: &f%s".formatted(Sentinel.getInstance().version)))
.lore(Text.color("&bLicensed to&7: &f%s".formatted(Sentinel.getInstance().nonce)))
.lore(" ")
.lore(Text.color("&e&nAuthor(s)&r&e: &e%s").formatted(Sentinel.getInstance().getPluginMeta().getAuthors()))
.displayName(Text.color("&6&lSentinel &8&l|&f Anti-Nuke").decoration(TextDecoration.ITALIC,false))
.loreComponent(
Component.empty(),
Text.color("&bVersion&7: &f%s".formatted(Sentinel.getInstance().version)),
Text.color("&bLicensed to&7: &f%s".formatted(Sentinel.getInstance().nonce)),
Component.empty(),
Text.color("&e&nAuthor(s)&r&e: &e%s".formatted(Sentinel.getInstance().getPluginMeta().getAuthors()))
)
.enchant(Enchantment.PROTECTION,64)
.flag(ItemFlag.HIDE_ENCHANTS)
.flags(ItemFlag.HIDE_ENCHANTS)
.build();
public static final ItemStack CONFIG = ItemBuilder.create()
.displayName(Component.text("Edit Config",Style.style(TextDecoration.BOLD, NamedTextColor.GOLD)).decoration(TextDecoration.ITALIC,false))
.material(Material.PISTON)
.name(Text.color("&6&lEdit Config"))
.lore(Text.color("&8&l➥&7 Click this if you hate JSON."))
.loreComponent(Text.color("&8&l➥&7 Click this if you hate JSON."))
.enchant(Enchantment.PROTECTION,64)
.flag(ItemFlag.HIDE_ENCHANTS)
.flags(ItemFlag.HIDE_ENCHANTS)
.build();
public static final ItemStack CHAT_CONFIG = ItemBuilder.create()
.material(Material.HOPPER)
.name(Text.color("&bChat Config"))
.lore(Text.color("&8&l➥&7 Spam Filter"))
.lore(Text.color("&8&l➥&7 Profanity Filter"))
.lore(Text.color("&8&l➥&7 Unicode Filter"))
.lore(Text.color("&8&l➥&7 URL Filter"))
.displayName(Component.text("Chat Config",NamedTextColor.AQUA).decoration(TextDecoration.ITALIC,false))
.loreComponent(
Text.color("&8&l➥&7 Spam Filter"),
Text.color("&8&l➥&7 Profanity Filter"),
Text.color("&8&l➥&7 Unicode Filter"),
Text.color("&8&l➥&7 URL Filter")
)
.enchant(Enchantment.PROTECTION,64)
.flag(ItemFlag.HIDE_ENCHANTS)
.flags(ItemFlag.HIDE_ENCHANTS)
.build();
public static final ItemStack ANTI_NUKE_CONFIG = ItemBuilder.create()
.material(Material.TNT)
.name(Text.color("&cAnti-Nuke Config"))
.lore(Text.color("&8&l➥&7 Manage all violations"))
.enchant(Enchantment.PROTECTION,64)
.flag(ItemFlag.HIDE_ENCHANTS)
.displayName(Component.text("Anti-Nuke Config", NamedTextColor.RED).decoration(TextDecoration.ITALIC,false))
.loreComponent(Text.color("&8&l➥&7 Manage all violations"))
.enchant(Enchantment.PROTECTION, 64)
.flags(ItemFlag.HIDE_ENCHANTS)
.build();
public static final ItemStack WHITELIST = ItemBuilder.create()
.material(Material.TNT)
.name(Text.color("&aCommand Block Whitelist"))
.lore(Text.color("&8&l➥&7 Manage running command blocks"))
.displayName(Component.text("Command Block Whitelist", NamedTextColor.GREEN).decoration(TextDecoration.ITALIC,false))
.loreComponent(Text.color("&8&l➥&7 Manage running command blocks"))
.enchant(Enchantment.PROTECTION, 64)
.flag(ItemFlag.HIDE_ENCHANTS)
.flags(ItemFlag.HIDE_ENCHANTS)
.build();
public static final ItemStack NBT = ItemBuilder.create()
.material(Material.HONEY_BOTTLE)
.name(Text.color("&aNBT Honeypot"))
.lore(Text.color("&8&l➥&7 View caught NBT"))
.displayName(Component.text("NBT Honeypot", NamedTextColor.GREEN).decoration(TextDecoration.ITALIC,false))
.loreComponent(Text.color("&8&l➥&7 View caught NBT"))
.enchant(Enchantment.PROTECTION, 64)
.flag(ItemFlag.HIDE_ENCHANTS)
.flags(ItemFlag.HIDE_ENCHANTS)
.build();
public static ItemStack configItem(String valueName, Material material, String description) {
ServerUtils.verbose("Creating a config item:\n Value Name -> %s\nMaterial in use -> %s".formatted(valueName,material.toString()));
ServerUtils.verbose("Creating a config item:\n Value Name -> %s\nMaterial in use -> %s",
valueName, material.toString());
List<String> desc = Arrays.stream(description.split("\n")).toList();
ItemBuilder item = ItemBuilder.create();
item.material(material);
item.name(Text.color("&6%s".formatted(valueName)));
ItemBuilder item = ItemBuilder.create()
.material(material)
.displayName(Component.text(valueName, NamedTextColor.GOLD).decoration(TextDecoration.ITALIC,false));
for (String s : desc) {
item.lore(Text.color("&e%s".formatted(s)));
item.loreComponent(Component.text(s, NamedTextColor.YELLOW));
}
item.lore(Text.color("&8&l➥&7 Click to set a &nnew&r&7 value."));
item.lore(Text.color("&8&l➥&7 Current Value: &b_ORIGINAL_"));
item.loreComponent(
Text.color("&8&l➥&7 Click to set a &nnew&r&7 value."),
Text.color("&8&l➥&7 Current Value: &b_ORIGINAL_")
);
return item.build();
}
public static ItemStack stringListItem(Iterable<String> values, Material material, String valueName, String description) {
ServerUtils.verbose("Items#stringListItem: Creating a config item:\n Value Name -> %s\nMaterial in use -> %s".formatted(valueName,material.toString()));
ItemBuilder itemBuilder = ItemBuilder.create();
itemBuilder.material(material);
itemBuilder.name(Text.color("&6%s".formatted(valueName)));
ServerUtils.verbose("Items#stringListItem: Creating a config item:\n Value Name -> %s\nMaterial in use -> %s",
valueName, material.toString());
ItemBuilder itemBuilder = ItemBuilder.create()
.material(material)
.displayName(Component.text(valueName, NamedTextColor.GOLD).decoration(TextDecoration.ITALIC,false));
List<String> desc = Arrays.stream(description.split("\n")).toList();
for (String s : desc) {
itemBuilder.lore(Text.color("&e%s".formatted(s)));
itemBuilder.loreComponent(Component.text(s, NamedTextColor.YELLOW));
}
itemBuilder.lore(Text.color("&8&l➥&7 Left-Click to add a new value."));
itemBuilder.lore(Text.color("&8&l➥&7 Right-Click to clear values."));
itemBuilder.lore(Text.color("&8&l➥&7 Current Values: "));
itemBuilder.flag(ItemFlag.HIDE_ATTRIBUTES);
itemBuilder.loreComponent(
Text.color("&8&l➥&7 Left-Click to add a new value."),
Text.color("&8&l➥&7 Right-Click to clear values."),
Text.color("&8&l➥&7 Current Values: ")
).flags(ItemFlag.HIDE_ATTRIBUTES);
for (String value : values) {
itemBuilder.lore(Text.color("&9 - &b%s".formatted(value)));
itemBuilder.loreComponent(
Component.text(" - ", NamedTextColor.BLUE)
.append(Component.text(value, NamedTextColor.AQUA))
);
}
return itemBuilder.build();
}
public static ItemStack stringItem(String originalValue, ItemStack originalItem) {
ServerUtils.verbose("Items#stringItem Creating a string item:\n Value -> %s".formatted(originalValue));
ServerUtils.verbose("Items#stringItem Creating a string item:\n Value -> %s", originalValue);
if (originalItem == null || !originalItem.hasItemMeta()) return originalItem;
ItemMeta meta = originalItem.getItemMeta();
if (meta == null || !meta.hasLore()) return originalItem;
List<String> lore = meta.getLore();
if (meta == null) return originalItem;
List<Component> lore = meta.lore();
if (lore == null) return originalItem;
for (int i = 0; i < lore.size(); i++) {
String line = lore.get(i);
ServerUtils.verbose("Items#stringItem Looping through lore line: %s/%s".formatted(i,lore.size()));
if (line.contains("_ORIGINAL_")) {
Component line = lore.get(i);
String plainText = PlainTextComponentSerializer.plainText().serialize(line);
ServerUtils.verbose("Items#stringItem Looping through lore line: %s/%s", i, lore.size());
if (plainText.contains("_ORIGINAL_")) {
try {
ServerUtils.verbose("Items#stringItem Found a lore on line %s, making replacement value".formatted(i));
String replace = line.replace("_ORIGINAL_", originalValue);
ServerUtils.verbose("Items#stringItem After replacement -> %s".formatted(replace));
lore.set(i,replace);
ServerUtils.verbose("Items#stringItem Just replaced line %s -> %s".formatted(i,lore.get(i)));
ServerUtils.verbose("Items#stringItem Found a lore on line %s, making replacement value", i);
Component newLine = line.replaceText(TextReplacementConfig.builder()
.matchLiteral("_ORIGINAL_")
.replacement(originalValue)
.build());
lore.set(i, newLine);
ServerUtils.verbose("Items#stringItem Just replaced line %s", i);
} catch (Exception e) {
e.printStackTrace();
}
}
ServerUtils.verbose("Items#stringItem end of loop %s. continue?".formatted(i));
ServerUtils.verbose("Items#stringItem end of loop %s. continue?", i);
}
ServerUtils.verbose("Items#stringItem Broke out of loop, setting the lore");
meta.setLore(lore);
meta.lore(lore);
ServerUtils.verbose("Items#stringItem Setting the meta");
originalItem.setItemMeta(meta);
ServerUtils.verbose("Items#stringItem Returning the item");
@@ -165,70 +197,52 @@ public class Items {
}
public static ItemStack booleanItem(boolean originalValue, ItemStack originalItem) {
ServerUtils.verbose("Items#booleanItem Creating a string item:\n Value -> %s".formatted(originalValue));
if (originalItem == null || !originalItem.hasItemMeta()) return originalItem;
ItemMeta meta = originalItem.getItemMeta();
if (meta == null || !meta.hasLore()) return originalItem;
List<String> lore = meta.getLore();
if (lore == null) return originalItem;
for (int i = 0; i < lore.size(); i++) {
String line = lore.get(i);
ServerUtils.verbose("Items#booleanItem Looping through lore line: %s/%s".formatted(i,lore.size()));
if (line.contains("_ORIGINAL_")) {
try {
ServerUtils.verbose("Items#booleanItem Found a lore on line %s, making replacement value".formatted(i));
String replace = line.replace("_ORIGINAL_", "" + originalValue);
ServerUtils.verbose("Items#booleanItem After replacement -> %s".formatted(replace));
lore.set(i,replace);
ServerUtils.verbose("Items#booleanItem Just replaced line %s -> %s".formatted(i,lore.get(i)));
} catch (Exception e) {
e.printStackTrace();
}
}
ServerUtils.verbose("Items#booleanItem end of loop %s. continue?".formatted(i));
}
ServerUtils.verbose("Items#booleanItem Broke out of loop, setting the lore");
meta.setLore(lore);
ServerUtils.verbose("Items#booleanItem Setting the meta");
originalItem.setItemMeta(meta);
ServerUtils.verbose("Items#booleanItem Returning the item");
return originalItem;
return replaceOriginalValue(String.valueOf(originalValue), originalItem, "booleanItem");
}
public static ItemStack intItem(int originalValue, ItemStack originalItem) {
ServerUtils.verbose("Items#intitem Creating a string item:\n Value -> %s".formatted(originalValue));
return replaceOriginalValue(String.valueOf(originalValue), originalItem, "intItem");
}
private static ItemStack replaceOriginalValue(String value, ItemStack originalItem, String methodName) {
ServerUtils.verbose("Items#%s Creating item with value: %s", methodName, value);
if (originalItem == null || !originalItem.hasItemMeta()) return originalItem;
ItemMeta meta = originalItem.getItemMeta();
if (meta == null || !meta.hasLore()) return originalItem;
List<String> lore = meta.getLore();
if (meta == null) return originalItem;
List<Component> lore = meta.lore();
if (lore == null) return originalItem;
for (int i = 0; i < lore.size(); i++) {
String line = lore.get(i);
ServerUtils.verbose("Items#intitem Looping through lore line: %s/%s".formatted(i,lore.size()));
if (line.contains("_ORIGINAL_")) {
Component line = lore.get(i);
String plainText = PlainTextComponentSerializer.plainText().serialize(line);
ServerUtils.verbose("Items#%s Looping through lore line: %s/%s", methodName, i, lore.size());
if (plainText.contains("_ORIGINAL_")) {
try {
ServerUtils.verbose("Items#intitem Found a lore on line %s, making replacement value".formatted(i));
String replace = line.replace("_ORIGINAL_", "" + originalValue);
ServerUtils.verbose("Items#intitem After replacement -> %s".formatted(replace));
lore.set(i,replace);
ServerUtils.verbose("Items#intitem Just replaced line %s -> %s".formatted(i,lore.get(i)));
ServerUtils.verbose("Items#%s Found a lore on line %s, making replacement value", methodName, i);
Component newLine = line.replaceText(TextReplacementConfig.builder()
.matchLiteral("_ORIGINAL_")
.replacement(value)
.build());
lore.set(i, newLine);
ServerUtils.verbose("Items#%s Just replaced line %s", methodName, i);
} catch (Exception e) {
e.printStackTrace();
}
}
ServerUtils.verbose("Items#intitem end of loop %s. continue?".formatted(i));
ServerUtils.verbose("Items#%s end of loop %s. continue?", methodName, i);
}
ServerUtils.verbose("Items#intitem Broke out of loop, setting the lore");
meta.setLore(lore);
ServerUtils.verbose("Items#intitem Setting the meta");
ServerUtils.verbose("Items#%s Broke out of loop, setting the lore", methodName);
meta.lore(lore);
ServerUtils.verbose("Items#%s Setting the meta", methodName);
originalItem.setItemMeta(meta);
ServerUtils.verbose("Items#intitem Returning the item");
ServerUtils.verbose("Items#%s Returning the item", methodName);
return originalItem;
}
}

View File

@@ -6,7 +6,7 @@ import me.trouper.sentinel.server.gui.config.ConfigGUI;
import me.trouper.sentinel.server.gui.nbt.NBTGui;
import me.trouper.sentinel.server.gui.whitelist.WhitelistGUI;
import me.trouper.sentinel.utils.PlayerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.entity.Player;
@@ -22,7 +22,7 @@ public class MainGUI {
public static Set<UUID> awaitingCallback = new HashSet<>();
public final CustomGui home = CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Home"))
.title(OldTXT.color("&6&lSentinel &8»&0 Home"))
.size(27)
.onDefine(this::blankPage)
.defineMain(this::mainClick)

View File

@@ -3,8 +3,9 @@ package me.trouper.sentinel.server.gui;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
@@ -17,7 +18,7 @@ import org.bukkit.inventory.ItemStack;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public abstract class PaginatedGUI<T> {
public abstract class PaginatedGUI<T> implements Main {
protected static final int ITEMS_PER_PAGE = 45;
protected static final Map<UUID, Integer> currentPages = new HashMap<>();
@@ -51,12 +52,10 @@ public abstract class PaginatedGUI<T> {
int page = currentPages.compute(p.getUniqueId(), (k, v) -> realizePage(p, v == null ? 0 : v));
FilterOperator operator = chosenOperator.computeIfAbsent(p.getUniqueId(), v -> FilterOperator.AND);
// Add persistent bottom items (navigation and filter)
inv.setItem(45, createNavigationItem("Previous", realizePage(p, page - 1)));
inv.setItem(49, createFilterItem(p));
inv.setItem(53, createNavigationItem("Next", realizePage(p, page + 1)));
// Fill the remaining bottom slots with red stained glass
for (int slot : new int[]{46, 47, 48, 50, 51, 52}) {
inv.setItem(slot, createPlaceholderItem(true));
}
@@ -71,7 +70,6 @@ public abstract class PaginatedGUI<T> {
AtomicInteger remaining = new AtomicInteger(pageSize);
// Process each entry and update GUI as each item loads
for (int i = 0; i < pageSize; i++) {
T entry = pageEntries.get(i);
ItemStack displayItem = createDisplayItem(entry);
@@ -81,7 +79,6 @@ public abstract class PaginatedGUI<T> {
inv.setItem(slot, displayItem);
if (runAsynchronously) p.playSound(p, Sound.UI_HUD_BUBBLE_POP, SoundCategory.MASTER,1,1.1F);
if (remaining.decrementAndGet() == 0) {
// Update remaining main slots and bottom slots to lime
for (int bottomSlot : new int[]{46, 47, 48, 50, 51, 52}) {
inv.setItem(bottomSlot, createPlaceholderItem(false));
}
@@ -90,7 +87,6 @@ public abstract class PaginatedGUI<T> {
});
}
// Handle case where there are no items
if (pageSize == 0) {
Bukkit.getScheduler().runTask(Sentinel.getInstance(), () -> {
for (int bottomSlot : new int[]{46, 47, 48, 50, 51, 52}) {
@@ -101,7 +97,6 @@ public abstract class PaginatedGUI<T> {
}
};
// Start async loading of items
if (runAsynchronously) Bukkit.getScheduler().runTaskAsynchronously(Sentinel.getInstance(), task);
else task.run();
}
@@ -115,7 +110,7 @@ public abstract class PaginatedGUI<T> {
Set<String> filters = activeFilters.computeIfAbsent(p.getUniqueId(), k -> new HashSet<>());
CustomGui.GuiBuilder filterGui = CustomGui.create()
.title(Text.color("&6&lFilters"))
.title(OldTXT.color("&6&lFilters"))
.size(27)
.defineMain(e -> e.setCancelled(true))
.define(26, Items.BACK, e -> {
@@ -180,8 +175,8 @@ public abstract class PaginatedGUI<T> {
}
return new ItemBuilder()
.material(Material.ARROW)
.name(Text.color("&b" + direction + "&7 Page"))
.lore(Text.color("&7 > &b" + pageTo))
.name(OldTXT.color("&b" + direction + "&7 Page"))
.lore(OldTXT.color("&7 > &b" + pageTo))
.build();
}
@@ -190,7 +185,7 @@ public abstract class PaginatedGUI<T> {
String name = isRed ? "&cComputing Entries..." : "&aAll Entries Loaded.";
return new ItemBuilder()
.material(material)
.name(Text.color(name))
.name(OldTXT.color(name))
.build();
}
@@ -198,15 +193,15 @@ public abstract class PaginatedGUI<T> {
List<String> operatorList = new ArrayList<>();
FilterOperator chosen = chosenOperator.computeIfAbsent(p.getUniqueId(), v -> FilterOperator.AND);
for (FilterOperator value : FilterOperator.values()) {
if (value.equals(chosen)) operatorList.add(Text.color("&b&n" + value.name()));
else operatorList.add(Text.color("&b" + value.name()));
if (value.equals(chosen)) operatorList.add(OldTXT.color("&b&n" + value.name()));
else operatorList.add(OldTXT.color("&b" + value.name()));
}
return new ItemBuilder()
.material(Material.HOPPER)
.name(Text.color("&6&lFilters"))
.lore(Text.color("&7Filters Selected: &e" + getFilterCount(p)))
.lore(Text.color("&7Shift-Click to cycle filter operator."))
.lore(Text.color("&7Operator: "))
.name(OldTXT.color("&6&lFilters"))
.lore(OldTXT.color("&7Filters Selected: &e" + getFilterCount(p)))
.lore(OldTXT.color("&7Shift-Click to cycle filter operator."))
.lore(OldTXT.color("&7Operator: "))
.lore(operatorList)
.build();
}
@@ -228,4 +223,22 @@ public abstract class PaginatedGUI<T> {
};
}
}
protected ItemStack createFilterToggleItem(String name, Material mat, boolean active) {
return new ItemBuilder()
.material(mat)
.name(OldTXT.color((active ? "&a" : "&c") + name))
.lore(OldTXT.color("&7Click to " + (active ? "disable" : "enable")))
.build();
}
protected ItemStack createFilterToggleItemValue(String name, Material mat, boolean active, String value) {
return new ItemBuilder()
.material(mat)
.name(OldTXT.color((active ? "&a" : "&c") + name))
.lore(OldTXT.color("&7Value&f: &b" + value))
.lore(OldTXT.color("&7Left Click to " + (active ? "disable" : "enable")))
.lore(OldTXT.color("&7Right Click to set value."))
.build();
}
}

View File

@@ -24,7 +24,7 @@ import me.trouper.sentinel.server.events.violations.whitelist.CommandBlockExecut
import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
@@ -33,7 +33,7 @@ import org.bukkit.inventory.ItemStack;
public class AntiNukeGUI {
public final CustomGui home = CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Choose a check"))
.title(OldTXT.color("&6&lSentinel &8»&0 Choose a check"))
.size(9*5)
.onDefine(this::blankPage)
.defineMain(this::mainClick)
@@ -95,8 +95,8 @@ public class AntiNukeGUI {
private static ItemStack getCheckItem(Material item, String name) {
return ItemBuilder.create()
.material(item)
.name(Text.color("&b" + name))
.lore(Text.color("&8&l➥&7 Modify this check"))
.name(OldTXT.color("&b" + name))
.lore(OldTXT.color("&8&l➥&7 Modify this check"))
.build();
}
}

View File

@@ -4,7 +4,7 @@ import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.chat.ChatGUI;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
import org.bukkit.entity.Player;
@@ -13,7 +13,7 @@ import org.bukkit.inventory.Inventory;
public class ConfigGUI {
public final CustomGui home = CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Config Home"))
.title(OldTXT.color("&6&lSentinel &8»&0 Config Home"))
.size(27)
.onDefine(this::blankPage)
.defineMain(this::mainClick)

View File

@@ -5,7 +5,7 @@ import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.config.ConfigGUI;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.SoundCategory;
@@ -16,7 +16,7 @@ import org.bukkit.inventory.ItemStack;
public class ChatGUI {
public final CustomGui home = CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Edit a Filter"))
.title(OldTXT.color("&6&lSentinel &8»&0 Edit a Filter"))
.size(27)
.onDefine(this::blankPage)
.defineMain(this::mainClick)
@@ -55,25 +55,25 @@ public class ChatGUI {
private static final ItemStack PROFANITY_FILTER = ItemBuilder.create()
.material(Material.COAL)
.name(Text.color("&bProfanity Filter"))
.lore(Text.color("&8&l➥&7 Edit Score Settings"))
.name(OldTXT.color("&bProfanity Filter"))
.lore(OldTXT.color("&8&l➥&7 Edit Score Settings"))
.build();
private static final ItemStack SPAM_FILTER = ItemBuilder.create()
.material(Material.PORKCHOP)
.name(Text.color("&bSpam Filter"))
.lore(Text.color("&8&l➥&7 Edit Heat Settings"))
.name(OldTXT.color("&bSpam Filter"))
.lore(OldTXT.color("&8&l➥&7 Edit Heat Settings"))
.build();
private static final ItemStack UNICODE_FILTER = ItemBuilder.create()
.material(Material.PAPER)
.name(Text.color("&bUnicode Filter"))
.lore(Text.color("&8&l➥&7 Edit regex"))
.name(OldTXT.color("&bUnicode Filter"))
.lore(OldTXT.color("&8&l➥&7 Edit regex"))
.build();
private static final ItemStack URL_FILTER = ItemBuilder.create()
.material(Material.CHAIN)
.name(Text.color("&bURL Filter"))
.lore(Text.color("&8&l➥&7 Edit regex"))
.name(OldTXT.color("&bURL Filter"))
.lore(OldTXT.color("&8&l➥&7 Edit regex"))
.build();
}

View File

@@ -4,12 +4,12 @@ import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import io.github.itzispyder.pdk.utils.misc.config.ConfigUpdater;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.config.MainConfig;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@@ -21,9 +21,9 @@ import org.bukkit.inventory.ItemStack;
import java.util.function.BiConsumer;
public class ProfanityFilterGUI {
public class ProfanityFilterGUI implements Main {
public final CustomGui home = CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Editing Profanity Filter"))
.title(OldTXT.color("&6&lSentinel &8»&0 Editing Profanity Filter"))
.size(54)
.onDefine(this::blankPage)
.defineMain(this::mainClick)
@@ -42,7 +42,7 @@ public class ProfanityFilterGUI {
}
ServerUtils.verbose("ProfanityFilterGUI#blankPage Page now blank");
ItemStack top = Items.RED;
if (Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.enabled) {
if (main.dir().io.mainConfig.chat.profanityFilter.enabled) {
top = Items.GREEN;
}
@@ -52,18 +52,18 @@ public class ProfanityFilterGUI {
ServerUtils.verbose("ProfanityFilterGUI#blankPage Adding GUI Items");
inv.setItem(53,Items.BACK);
inv.setItem(3,Items.booleanItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.enabled, Items.configItem("Profanity Filter Toggle",Material.CLOCK,"Enable or Disable the whole Profanity filter")));
inv.setItem(5,Items.booleanItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.silent, Items.configItem("Silent Mode",Material.FEATHER,"Whether to notify players that their messages \nwere blocked. Enabling could help deter bypassing.")));
inv.setItem(10,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.lowScore, Items.configItem("Low Score Gain", Material.WHITE_WOOL, "How much score will be added if the player \ndid not attempt to bypass the filter.")));
inv.setItem(19,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.mediumLowScore, Items.configItem("Medium-Low Score Gain", Material.LIME_WOOL, "How much score will be added if the player \nused l33t speak to attempt a bypass")));
inv.setItem(28,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.mediumScore, Items.configItem("Medium Score Gain", Material.YELLOW_WOOL, "How much score will be added if the player \nused sp/ecia|l characters to attempt a bypass")));
inv.setItem(37,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.mediumHighScore, Items.configItem("Medium-High Score Gain", Material.ORANGE_WOOL, "How much score will be added if the player \nused reeeeeeepeating letters to attempt a bypass")));
inv.setItem(46,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.highScore, Items.configItem("High Score Gain", Material.RED_WOOL, "How much score will be added if the player \nused pun. ctua, tion or spaces to attempt a bypass")));
inv.setItem(29,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.regexScore, Items.configItem("Regex Score Gain", Material.DISPENSER, "How much score will be added if the player \nmatched the regex setting throughout \nthe processing of the message")));
inv.setItem(22,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.punishScore, Items.configItem("Punish Score", Material.IRON_BARS, "If the player's score is above this \nthe punishment commands will be ran.")));
inv.setItem(33,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.scoreDecay, Items.configItem("Score Decay", Material.DEAD_BUBBLE_CORAL_BLOCK, "How much score players will loose each minute.")));
inv.setItem(31,Items.stringListItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.profanityPunishCommands,Material.WOODEN_AXE, "Default Punishment Commands", "%player% will be replaced with the offender's name"));
inv.setItem(40,Items.stringListItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.strictPunishCommands,Material.DIAMOND_AXE, "Strict Punishment Commands", "If words from the strict words list are flagged, \nthis list will be ran instead \n%player% will be replaced with the offender's name"));
inv.setItem(3,Items.booleanItem(main.dir().io.mainConfig.chat.profanityFilter.enabled, Items.configItem("Profanity Filter Toggle",Material.CLOCK,"Enable or Disable the whole Profanity filter")));
inv.setItem(5,Items.booleanItem(main.dir().io.mainConfig.chat.profanityFilter.silent, Items.configItem("Silent Mode",Material.FEATHER,"Whether to notify players that their messages \nwere blocked. Enabling could help deter bypassing.")));
inv.setItem(10,Items.intItem(main.dir().io.mainConfig.chat.profanityFilter.lowScore, Items.configItem("Low Score Gain", Material.WHITE_WOOL, "How much score will be added if the player \ndid not attempt to bypass the filter.")));
inv.setItem(19,Items.intItem(main.dir().io.mainConfig.chat.profanityFilter.mediumLowScore, Items.configItem("Medium-Low Score Gain", Material.LIME_WOOL, "How much score will be added if the player \nused l33t speak to attempt a bypass")));
inv.setItem(28,Items.intItem(main.dir().io.mainConfig.chat.profanityFilter.mediumScore, Items.configItem("Medium Score Gain", Material.YELLOW_WOOL, "How much score will be added if the player \nused sp/ecia|l characters to attempt a bypass")));
inv.setItem(37,Items.intItem(main.dir().io.mainConfig.chat.profanityFilter.mediumHighScore, Items.configItem("Medium-High Score Gain", Material.ORANGE_WOOL, "How much score will be added if the player \nused reeeeeeepeating letters to attempt a bypass")));
inv.setItem(46,Items.intItem(main.dir().io.mainConfig.chat.profanityFilter.highScore, Items.configItem("High Score Gain", Material.RED_WOOL, "How much score will be added if the player \nused pun. ctua, tion or spaces to attempt a bypass")));
inv.setItem(29,Items.intItem(main.dir().io.mainConfig.chat.profanityFilter.regexScore, Items.configItem("Regex Score Gain", Material.DISPENSER, "How much score will be added if the player \nmatched the regex setting throughout \nthe processing of the message")));
inv.setItem(22,Items.intItem(main.dir().io.mainConfig.chat.profanityFilter.punishScore, Items.configItem("Punish Score", Material.IRON_BARS, "If the player's score is above this \nthe punishment commands will be ran.")));
inv.setItem(33,Items.intItem(main.dir().io.mainConfig.chat.profanityFilter.scoreDecay, Items.configItem("Score Decay", Material.DEAD_BUBBLE_CORAL_BLOCK, "How much score players will loose each minute.")));
inv.setItem(31,Items.stringListItem(main.dir().io.mainConfig.chat.profanityFilter.profanityPunishCommands,Material.WOODEN_AXE, "Default Punishment Commands", "%player% will be replaced with the offender's name"));
inv.setItem(40,Items.stringListItem(main.dir().io.mainConfig.chat.profanityFilter.strictPunishCommands,Material.DIAMOND_AXE, "Strict Punishment Commands", "If words from the strict words list are flagged, \nthis list will be ran instead \n%player% will be replaced with the offender's name"));
} catch (Exception e) {
e.printStackTrace();
}
@@ -74,35 +74,35 @@ public class ProfanityFilterGUI {
if (!MainGUI.verify((Player) e.getWhoClicked())) return;
switch (e.getSlot()) {
case 3 -> {
Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.enabled = !Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.enabled;
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.profanityFilter.enabled = !main.dir().io.mainConfig.chat.profanityFilter.enabled;
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
case 5 -> {
Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.silent = !Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.silent;
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.profanityFilter.silent = !main.dir().io.mainConfig.chat.profanityFilter.silent;
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
case 10 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.lowScore = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.lowScore);
case 19 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.mediumLowScore = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.mediumLowScore);
case 28 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.mediumScore = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.mediumScore);
case 37 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.mediumHighScore = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.mediumHighScore);
case 46 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.highScore = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.highScore);
case 29 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.regexScore = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.regexScore);
case 22 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.punishScore = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.punishScore);
case 33 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.scoreDecay = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.scoreDecay);
case 10 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.lowScore = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.profanityFilter.lowScore);
case 19 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.mediumLowScore = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.profanityFilter.mediumLowScore);
case 28 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.mediumScore = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.profanityFilter.mediumScore);
case 37 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.mediumHighScore = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.profanityFilter.mediumHighScore);
case 46 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.highScore = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.profanityFilter.highScore);
case 29 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.regexScore = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.profanityFilter.regexScore);
case 22 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.punishScore = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.profanityFilter.punishScore);
case 33 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.profanityFilter.scoreDecay = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.profanityFilter.scoreDecay);
case 31 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> {
cfg.chat.profanityFilter.profanityPunishCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.profanityPunishCommands);
},"" + main.dir().io.mainConfig.chat.profanityFilter.profanityPunishCommands);
return;
}
Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.profanityPunishCommands.clear();
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.profanityFilter.profanityPunishCommands.clear();
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
@@ -110,17 +110,17 @@ public class ProfanityFilterGUI {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> {
cfg.chat.profanityFilter.strictPunishCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.strictPunishCommands);
},"" + main.dir().io.mainConfig.chat.profanityFilter.strictPunishCommands);
return;
}
Sentinel.getInstance().getDirector().io.mainConfig.chat.profanityFilter.strictPunishCommands.clear();
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.profanityFilter.strictPunishCommands.clear();
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
}
}
public static ConfigUpdater<AsyncChatEvent, MainConfig> updater = new ConfigUpdater<>(Sentinel.getInstance().getDirector().io.mainConfig);
public static ConfigUpdater<AsyncChatEvent, MainConfig> updater = new ConfigUpdater<>(main.dir().io.mainConfig);
private void queuePlayer(Player player, BiConsumer<MainConfig, Args> action, String currentValue) {
MainGUI.awaitingCallback.add(player.getUniqueId());
@@ -131,9 +131,9 @@ public class ProfanityFilterGUI {
}, (cfg, newValue) -> {
action.accept(cfg,new Args(newValue.split("\\s+")));
cfg.save();
player.sendMessage(Text.prefix("Value updated successfully"));
successAny(player,"Value updated successfully");
player.openInventory(home.getInventory());
});
player.sendMessage(Component.text(Text.prefix("Enter the new value in chat. The value is currently set to &b%s&7. (Click to insert)".formatted(currentValue))).clickEvent(ClickEvent.suggestCommand(currentValue)));
message(player,Component.text("Enter the new value in chat. The value is currently set to {0}. (Click to insert)").clickEvent(ClickEvent.suggestCommand(currentValue)),Component.text(currentValue));
}
}

View File

@@ -4,11 +4,11 @@ import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import io.github.itzispyder.pdk.utils.misc.config.ConfigUpdater;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.config.MainConfig;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@@ -20,10 +20,10 @@ import org.bukkit.inventory.ItemStack;
import java.util.function.BiConsumer;
public class SpamFilterGUI {
public class SpamFilterGUI implements Main {
public final CustomGui home = CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Editing Spam Filter"))
.title(OldTXT.color("&6&lSentinel &8»&0 Editing Spam Filter"))
.size(54)
.onDefine(this::blankPage)
.defineMain(this::mainClick)
@@ -31,16 +31,14 @@ public class SpamFilterGUI {
e.getWhoClicked().openInventory(new ChatGUI().home.getInventory());
})
.build();
private void blankPage(Inventory inv) {
for (int i = 0; i < inv.getSize(); i++) {
inv.setItem(i,Items.BLANK);
}
ItemStack top = Items.RED;
if (Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.enabled) {
if (main.dir().io.mainConfig.chat.spamFilter.enabled) {
top = Items.GREEN;
}
@@ -49,18 +47,18 @@ public class SpamFilterGUI {
}
inv.setItem(53,Items.BACK);
inv.setItem(3,Items.booleanItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.enabled, Items.configItem("Spam Filter Toggle", Material.CLOCK, "Enable or disable the whole Spam Filter")));
inv.setItem(5,Items.booleanItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.silent, Items.configItem("Silent Toggle", Material.FEATHER, "Whether to notify players that their messages \nwere blocked. Enabling could help deter bypassing.")));
inv.setItem(10,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.defaultGain, Items.configItem("Default Heat Gain", Material.BUCKET, "How much heat will be added to each message.")));
inv.setItem(19,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.lowGain, Items.configItem("Low Heat Gain", Material.WATER_BUCKET, "Extra heat to be added if the \nmessage is greater than 25% similar \nto their previous message.")));
inv.setItem(28,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.mediumGain, Items.configItem("Medium Heat Gain", Material.COD_BUCKET, "Extra heat to be added if the \nmessage is greater than 50% similar \nto their previous message.")));
inv.setItem(37,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.highGain, Items.configItem("High Heat Gain", Material.PUFFERFISH_BUCKET, "Extra heat to be added if the \nmessage is greater than 90% similar \nto their previous message.")));
inv.setItem(46,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.blockHeat, Items.configItem("Block Heat", Material.BARRIER, "If the player's heat is above this \nthen their message will be blocked and \nflagged as spam.")));
inv.setItem(21,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.blockSimilarity, Items.configItem("Block Similarity", Material.BARRIER, "If the message's similarity is above \nthis, it will get automatically blocked \nand flagged as spam.")));
inv.setItem(23,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.punishHeat, Items.configItem("Punish Heat", Material.IRON_BARS, "If the player's heat is above this \nthe punishment commands will be ran.")));
inv.setItem(25,Items.intItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.heatDecay, Items.configItem("Heat Decay", Material.DEAD_BUBBLE_CORAL_BLOCK, "How much heat players will loose each second.")));
inv.setItem(32,Items.stringListItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.punishCommands,Material.DIAMOND_AXE, "Punishment Commands", "%player% will be replaced with the offender's name"));
inv.setItem(34,Items.stringListItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.whitelist,Material.PAPER, "Message Whitelist", "Messages which will be ignored by the spam filter"));
inv.setItem(3,Items.booleanItem(main.dir().io.mainConfig.chat.spamFilter.enabled, Items.configItem("Spam Filter Toggle", Material.CLOCK, "Enable or disable the whole Spam Filter")));
inv.setItem(5,Items.booleanItem(main.dir().io.mainConfig.chat.spamFilter.silent, Items.configItem("Silent Toggle", Material.FEATHER, "Whether to notify players that their messages \nwere blocked. Enabling could help deter bypassing.")));
inv.setItem(10,Items.intItem(main.dir().io.mainConfig.chat.spamFilter.defaultGain, Items.configItem("Default Heat Gain", Material.BUCKET, "How much heat will be added to each message.")));
inv.setItem(19,Items.intItem(main.dir().io.mainConfig.chat.spamFilter.lowGain, Items.configItem("Low Heat Gain", Material.WATER_BUCKET, "Extra heat to be added if the \nmessage is greater than 25% similar \nto their previous message.")));
inv.setItem(28,Items.intItem(main.dir().io.mainConfig.chat.spamFilter.mediumGain, Items.configItem("Medium Heat Gain", Material.COD_BUCKET, "Extra heat to be added if the \nmessage is greater than 50% similar \nto their previous message.")));
inv.setItem(37,Items.intItem(main.dir().io.mainConfig.chat.spamFilter.highGain, Items.configItem("High Heat Gain", Material.PUFFERFISH_BUCKET, "Extra heat to be added if the \nmessage is greater than 90% similar \nto their previous message.")));
inv.setItem(46,Items.intItem(main.dir().io.mainConfig.chat.spamFilter.blockHeat, Items.configItem("Block Heat", Material.BARRIER, "If the player's heat is above this \nthen their message will be blocked and \nflagged as spam.")));
inv.setItem(21,Items.intItem(main.dir().io.mainConfig.chat.spamFilter.blockSimilarity, Items.configItem("Block Similarity", Material.BARRIER, "If the message's similarity is above \nthis, it will get automatically blocked \nand flagged as spam.")));
inv.setItem(23,Items.intItem(main.dir().io.mainConfig.chat.spamFilter.punishHeat, Items.configItem("Punish Heat", Material.IRON_BARS, "If the player's heat is above this \nthe punishment commands will be ran.")));
inv.setItem(25,Items.intItem(main.dir().io.mainConfig.chat.spamFilter.heatDecay, Items.configItem("Heat Decay", Material.DEAD_BUBBLE_CORAL_BLOCK, "How much heat players will loose each second.")));
inv.setItem(32,Items.stringListItem(main.dir().io.mainConfig.chat.spamFilter.punishCommands,Material.DIAMOND_AXE, "Punishment Commands", "%player% will be replaced with the offender's name"));
inv.setItem(34,Items.stringListItem(main.dir().io.mainConfig.chat.spamFilter.whitelist,Material.PAPER, "Message Whitelist", "Messages which will be ignored by the spam filter"));
}
private void mainClick(InventoryClickEvent e) {
@@ -70,40 +68,40 @@ public class SpamFilterGUI {
switch (e.getSlot()) {
case 3 -> {
Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.enabled = !Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.enabled;
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.spamFilter.enabled = !main.dir().io.mainConfig.chat.spamFilter.enabled;
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
case 5 -> {
Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.silent = !Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.silent;
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.spamFilter.silent = !main.dir().io.mainConfig.chat.spamFilter.silent;
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
case 10 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.defaultGain = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.defaultGain);
case 19 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.lowGain = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.lowGain);
case 28 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.mediumGain = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.mediumGain);
case 37 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.highGain = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.highGain);
case 46 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.blockHeat = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.blockHeat);
case 21 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.blockSimilarity = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.blockSimilarity);
case 23 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.punishHeat = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.punishHeat);
case 25 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.heatDecay = args.getAll().toInt(),"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.heatDecay);
case 10 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.defaultGain = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.spamFilter.defaultGain);
case 19 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.lowGain = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.spamFilter.lowGain);
case 28 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.mediumGain = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.spamFilter.mediumGain);
case 37 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.highGain = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.spamFilter.highGain);
case 46 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.blockHeat = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.spamFilter.blockHeat);
case 21 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.blockSimilarity = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.spamFilter.blockSimilarity);
case 23 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.punishHeat = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.spamFilter.punishHeat);
case 25 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.spamFilter.heatDecay = args.getAll().toInt(),"" + main.dir().io.mainConfig.chat.spamFilter.heatDecay);
case 32 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> {
cfg.chat.spamFilter.punishCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.punishCommands);
},"" + main.dir().io.mainConfig.chat.spamFilter.punishCommands);
return;
}
Sentinel.getInstance().getDirector().io.mainConfig.chat.spamFilter.punishCommands.clear();
main.dir().io.mainConfig.chat.spamFilter.punishCommands.clear();
blankPage(e.getInventory());
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.save();
}
}
}
public static ConfigUpdater<AsyncChatEvent, MainConfig> updater = new ConfigUpdater<>(Sentinel.getInstance().getDirector().io.mainConfig);
public static ConfigUpdater<AsyncChatEvent, MainConfig> updater = new ConfigUpdater<>(main.dir().io.mainConfig);
private void queuePlayer(Player player, BiConsumer<MainConfig, Args> action, String currentValue) {
MainGUI.awaitingCallback.add(player.getUniqueId());
@@ -114,9 +112,9 @@ public class SpamFilterGUI {
}, (cfg, newValue) -> {
action.accept(cfg,new Args(newValue.split("\\s+")));
cfg.save();
player.sendMessage(Text.prefix("Value updated successfully"));
messageAny(player,"Value updated successfully");
player.openInventory(home.getInventory());
});
player.sendMessage(Component.text(Text.prefix("Enter the new value in chat. The value is currently set to &b%s&7. (Click to insert)".formatted(currentValue))).clickEvent(ClickEvent.suggestCommand(currentValue)));
message(player,Component.text("Enter the new value in chat. The value is currently set to {0}. (Click to insert)").clickEvent(ClickEvent.suggestCommand(currentValue)),Component.text(currentValue));
}
}

View File

@@ -4,12 +4,12 @@ import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import io.github.itzispyder.pdk.utils.misc.config.ConfigUpdater;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.config.MainConfig;
import me.trouper.sentinel.server.Main;
import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@@ -21,10 +21,10 @@ import org.bukkit.inventory.ItemStack;
import java.util.function.BiConsumer;
public class UnicodeFilterGUI {
public class UnicodeFilterGUI implements Main {
public final CustomGui home = CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Editing Unicode Filter"))
.title(OldTXT.color("&6&lSentinel &8»&0 Editing Unicode Filter"))
.size(36)
.onDefine(this::blankPage)
.defineMain(this::mainClick)
@@ -40,7 +40,7 @@ public class UnicodeFilterGUI {
}
ServerUtils.verbose("Unicode Filter GUI blank!");
ItemStack top = Items.RED;
if (Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.enabled) {
if (main.dir().io.mainConfig.chat.unicodeFilter.enabled) {
top = Items.GREEN;
}
@@ -48,11 +48,11 @@ public class UnicodeFilterGUI {
inv.setItem(i,top);
}
inv.setItem(3,Items.booleanItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.enabled, Items.configItem("Unicode Filter Toggle", Material.CLOCK,"Enable or Disable the whole Unicode filter")));
inv.setItem(5,Items.booleanItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.silent, Items.configItem("Silent Mode",Material.FEATHER,"Whether to notify players that their messages \nwere blocked. Enabling could help deter bypassing.")));
inv.setItem(20,Items.booleanItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.punished,Items.configItem("Punished",Material.IRON_BARS,"Toggles execution of punishment commands.")));
inv.setItem(22,Items.stringItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.regex,Items.configItem("Allowed Char Regex",Material.DISPENSER,"Toggles execution of punishment commands.")));
inv.setItem(24,Items.stringListItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.punishCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands which will be executed if punishment is enabled."));
inv.setItem(3,Items.booleanItem(main.dir().io.mainConfig.chat.unicodeFilter.enabled, Items.configItem("Unicode Filter Toggle", Material.CLOCK,"Enable or Disable the whole Unicode filter")));
inv.setItem(5,Items.booleanItem(main.dir().io.mainConfig.chat.unicodeFilter.silent, Items.configItem("Silent Mode",Material.FEATHER,"Whether to notify players that their messages \nwere blocked. Enabling could help deter bypassing.")));
inv.setItem(20,Items.booleanItem(main.dir().io.mainConfig.chat.unicodeFilter.punished,Items.configItem("Punished",Material.IRON_BARS,"Toggles execution of punishment commands.")));
inv.setItem(22,Items.stringItem(main.dir().io.mainConfig.chat.unicodeFilter.regex,Items.configItem("Allowed Char Regex",Material.DISPENSER,"Toggles execution of punishment commands.")));
inv.setItem(24,Items.stringListItem(main.dir().io.mainConfig.chat.unicodeFilter.punishCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands which will be executed if punishment is enabled."));
}
@@ -62,41 +62,41 @@ public class UnicodeFilterGUI {
switch (e.getSlot()) {
case 3 -> {
Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.enabled = !Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.enabled;
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.unicodeFilter.enabled = !main.dir().io.mainConfig.chat.unicodeFilter.enabled;
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
case 5 -> {
Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.silent = !Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.silent;
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.unicodeFilter.silent = !main.dir().io.mainConfig.chat.unicodeFilter.silent;
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
case 20 -> {
Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.punished = !Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.punished;
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.unicodeFilter.punished = !main.dir().io.mainConfig.chat.unicodeFilter.punished;
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
case 22 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.unicodeFilter.regex = args.getAll().toString(),Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.regex);
case 22 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.unicodeFilter.regex = args.getAll().toString(),main.dir().io.mainConfig.chat.unicodeFilter.regex);
case 24 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> {
cfg.chat.unicodeFilter.punishCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.punishCommands);
},"" + main.dir().io.mainConfig.chat.unicodeFilter.punishCommands);
return;
}
Sentinel.getInstance().getDirector().io.mainConfig.chat.unicodeFilter.punishCommands.clear();
main.dir().io.mainConfig.chat.unicodeFilter.punishCommands.clear();
blankPage(e.getInventory());
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.save();
}
}
}
public static ConfigUpdater<AsyncChatEvent, MainConfig> updater = new ConfigUpdater<>(Sentinel.getInstance().getDirector().io.mainConfig);
public static ConfigUpdater<AsyncChatEvent, MainConfig> updater = new ConfigUpdater<>(main.dir().io.mainConfig);
private void queuePlayer(Player player, BiConsumer<MainConfig, Args> action, String currentValue) {
MainGUI.awaitingCallback.add(player.getUniqueId());
@@ -107,9 +107,9 @@ public class UnicodeFilterGUI {
}, (cfg, newValue) -> {
action.accept(cfg,new Args(newValue.split("\\s+")));
cfg.save();
player.sendMessage(Text.prefix("Value updated successfully"));
messageAny(player,"Value updated successfully");
player.openInventory(home.getInventory());
});
player.sendMessage(Component.text(Text.prefix("Enter the new value in chat. The value is currently set to &b%s&7. (Click to insert)".formatted(currentValue))).clickEvent(ClickEvent.suggestCommand(currentValue)));
message(player,Component.text("Enter the new value in chat. The value is currently set to {0}. (Click to insert)").clickEvent(ClickEvent.suggestCommand(currentValue)),Component.text(currentValue));
}
}

View File

@@ -1,15 +1,14 @@
package me.trouper.sentinel.server.gui.config.chat;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.events.CustomListener;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import io.github.itzispyder.pdk.utils.misc.config.ConfigUpdater;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.config.MainConfig;
import me.trouper.sentinel.server.events.QuickListener;
import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@@ -21,9 +20,9 @@ import org.bukkit.inventory.ItemStack;
import java.util.function.BiConsumer;
public class UrlFilterGUI implements CustomListener {
public class UrlFilterGUI implements QuickListener {
public final CustomGui home = CustomGui.create()
.title(Text.color("&6&lSentinel &8»&0 Editing Unicode Filter"))
.title(OldTXT.color("&6&lSentinel &8»&0 Editing Unicode Filter"))
.size(36)
.onDefine(this::blankPage)
.defineMain(this::mainClick)
@@ -39,7 +38,7 @@ public class UrlFilterGUI implements CustomListener {
}
ItemStack top = Items.RED;
if (Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.enabled) {
if (main.dir().io.mainConfig.chat.urlFilter.enabled) {
top = Items.GREEN;
}
@@ -47,12 +46,12 @@ public class UrlFilterGUI implements CustomListener {
inv.setItem(i,top);
}
inv.setItem(3,Items.booleanItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.enabled, Items.configItem("Unicode Filter Toggle", Material.CLOCK,"Enable or Disable the whole Unicode filter")));
inv.setItem(5,Items.booleanItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.silent, Items.configItem("Silent Mode",Material.FEATHER,"Whether to notify players that their messages \nwere blocked. Enabling could help deter bypassing.")));
inv.setItem(19,Items.booleanItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.punished,Items.configItem("Punished",Material.IRON_BARS,"Toggles execution of punishment commands.")));
inv.setItem(21,Items.stringItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.regex,Items.configItem("Allowed Char Regex",Material.DISPENSER,"Toggles execution of punishment commands.")));
inv.setItem(23,Items.stringListItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.punishCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands which will be executed if punishment is enabled."));
inv.setItem(25,Items.stringListItem(Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.whitelist,Material.PAPER,"Whitelist","URLs which will not flag the filter."));
inv.setItem(3,Items.booleanItem(main.dir().io.mainConfig.chat.urlFilter.enabled, Items.configItem("Unicode Filter Toggle", Material.CLOCK,"Enable or Disable the whole Unicode filter")));
inv.setItem(5,Items.booleanItem(main.dir().io.mainConfig.chat.urlFilter.silent, Items.configItem("Silent Mode",Material.FEATHER,"Whether to notify players that their messages \nwere blocked. Enabling could help deter bypassing.")));
inv.setItem(19,Items.booleanItem(main.dir().io.mainConfig.chat.urlFilter.punished,Items.configItem("Punished",Material.IRON_BARS,"Toggles execution of punishment commands.")));
inv.setItem(21,Items.stringItem(main.dir().io.mainConfig.chat.urlFilter.regex,Items.configItem("Allowed Char Regex",Material.DISPENSER,"Toggles execution of punishment commands.")));
inv.setItem(23,Items.stringListItem(main.dir().io.mainConfig.chat.urlFilter.punishCommands,Material.DIAMOND_AXE,"Punishment Commands","Commands which will be executed if punishment is enabled."));
inv.setItem(25,Items.stringListItem(main.dir().io.mainConfig.chat.urlFilter.whitelist,Material.PAPER,"Whitelist","URLs which will not flag the filter."));
}
@@ -62,53 +61,53 @@ public class UrlFilterGUI implements CustomListener {
switch (e.getSlot()) {
case 3 -> {
Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.enabled = !Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.enabled;
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.urlFilter.enabled = !main.dir().io.mainConfig.chat.urlFilter.enabled;
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
case 5 -> {
Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.silent = !Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.silent;
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.urlFilter.silent = !main.dir().io.mainConfig.chat.urlFilter.silent;
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
case 19 -> {
Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.punished = !Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.punished;
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.chat.urlFilter.punished = !main.dir().io.mainConfig.chat.urlFilter.punished;
main.dir().io.mainConfig.save();
blankPage(e.getInventory());
}
case 21 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.urlFilter.regex = args.getAll().toString(),Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.regex);
case 21 -> queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> cfg.chat.urlFilter.regex = args.getAll().toString(),main.dir().io.mainConfig.chat.urlFilter.regex);
case 23 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> {
cfg.chat.urlFilter.punishCommands.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.punishCommands);
},"" + main.dir().io.mainConfig.chat.urlFilter.punishCommands);
return;
}
Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.punishCommands.clear();
main.dir().io.mainConfig.chat.urlFilter.punishCommands.clear();
blankPage(e.getInventory());
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.save();
}
case 25 -> {
if (e.isLeftClick()) {
queuePlayer((Player) e.getWhoClicked(), (cfg,args) -> {
cfg.chat.urlFilter.whitelist.add(args.getAll().toString());
},"" + Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.whitelist);
},"" + main.dir().io.mainConfig.chat.urlFilter.whitelist);
return;
}
Sentinel.getInstance().getDirector().io.mainConfig.chat.urlFilter.whitelist.clear();
main.dir().io.mainConfig.chat.urlFilter.whitelist.clear();
blankPage(e.getInventory());
Sentinel.getInstance().getDirector().io.mainConfig.save();
main.dir().io.mainConfig.save();
}
}
}
public static ConfigUpdater<AsyncChatEvent, MainConfig> updater = new ConfigUpdater<>(Sentinel.getInstance().getDirector().io.mainConfig);
public static ConfigUpdater<AsyncChatEvent, MainConfig> updater = new ConfigUpdater<>(main.dir().io.mainConfig);
private void queuePlayer(Player player, BiConsumer<MainConfig, Args> action, String currentValue) {
MainGUI.awaitingCallback.add(player.getUniqueId());
@@ -119,9 +118,9 @@ public class UrlFilterGUI implements CustomListener {
}, (cfg, newValue) -> {
action.accept(cfg,new Args(newValue.split("\\s+")));
cfg.save();
player.sendMessage(Text.prefix("Value updated successfully"));
successAny(player,"Value updated successfully");
player.openInventory(home.getInventory());
});
player.sendMessage(Component.text(Text.prefix("Enter the new value in chat. The value is currently set to &b%s&7. (Click to insert)".formatted(currentValue))).clickEvent(ClickEvent.suggestCommand(currentValue)));
message(player,Component.text("Enter the new value in chat. The value is currently set to {0}. (Click to insert)").clickEvent(ClickEvent.suggestCommand(currentValue)),Component.text(currentValue));
}
}

View File

@@ -1,30 +1,36 @@
package me.trouper.sentinel.server.gui.nbt;
import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.commands.Args;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import io.github.itzispyder.pdk.utils.misc.config.ConfigUpdater;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.config.ViolationConfig;
import me.trouper.sentinel.data.storage.NBTStorage;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.PaginatedGUI;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.*;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
public class NBTGui
extends PaginatedGUI<Map.Entry<String, String>> {
public class NBTGui extends PaginatedGUI<Map.Entry<String, NBTStorage.Metadata>> {
private final NBTStorage nbtStorage;
private static final Map<UUID, String> chosenPlayer = new HashMap<>();
public NBTGui() {
this.nbtStorage = Sentinel.getInstance().getDirector().io.nbtStorage;
this.nbtStorage = main.dir().io.nbtStorage;
}
@Override
@@ -39,16 +45,16 @@ public class NBTGui
@Override
protected String getTitle(Player p) {
return Text.color("&6&lCaught NBT &7(%s/%s filtered)".formatted(this.getFilteredCount(p), Sentinel.getInstance().getDirector().io.nbtStorage.caughtItems.size()));
return FormatUtils.legacyColor("&6&lCaught NBT &7(%s/%s filtered)".formatted(this.getFilteredCount(p), main.dir().io.nbtStorage.caughtItems.size()));
}
@Override
protected void handleMainClick(Player p, InventoryClickEvent e) {
e.setCancelled(true);
MainGUI.verify(p);
Map.Entry<String, String> entry;
Map.Entry<String, NBTStorage.Metadata> entry;
ItemStack item;
List<Map.Entry<String, String>> filtered;
List<Map.Entry<String, NBTStorage.Metadata>> filtered;
int slot = e.getSlot();
if (slot >= 45) {
return;
@@ -64,60 +70,101 @@ public class NBTGui
p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1.0f, 1.0f);
} else if (e.isRightClick() && this.nbtStorage.deleteItem(entry.getKey())) {
p.playSound(p.getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 1.0f, 2.0f);
e.getClickedInventory().setItem(slot, ItemBuilder.create()
.material(Material.STRUCTURE_VOID)
.name(Text.color("&cDeleted Item"))
.lore(Text.color("&7You have deleted this item."))
.lore(Text.color("&7This will disappear next refresh."))
e.getClickedInventory().setItem(slot, ItemBuilder.of(Material.BARRIER)
.displayName(Component.text("Deleted Item", NamedTextColor.RED))
.loreComponent(
Component.text("You have deleted this item.",NamedTextColor.GRAY),
Component.text("This will disappear next refresh.",NamedTextColor.GRAY)
)
.build());
}
}
}
@Override
protected ItemStack createDisplayItem(Map.Entry<String, String> entry) {
protected ItemStack createDisplayItem(Map.Entry<String, NBTStorage.Metadata> entry) {
ItemStack item = NBTStorage.getItem(entry.getKey());
if (item == null) {
return null;
}
ArrayList<String> lore = new ArrayList<>();
lore.add(Text.color("&7NBT Name: " + LegacyComponentSerializer.legacyAmpersand().serialize(item.effectiveName())));
lore.add("");
lore.add(Text.color("&7Owner: " + Bukkit.getOfflinePlayer(UUID.fromString(entry.getValue())).getName()));
lore.add("");
lore.add(Text.color("&eLeft-Click to give item"));
lore.add(Text.color("&eRight-Click to delete item"));
return new ItemBuilder().material(item.getType()).name(Text.color("&b" + item.getType().name())).lore(lore).build();
String name = LegacyComponentSerializer.legacySection().serialize(item.effectiveName());
Component owner = Component.text(Bukkit.getOfflinePlayer(entry.getValue().owner).getName(), NamedTextColor.WHITE);
if (name.length() >= 64) {
name = name.substring(0,64) + "...";
}
return ItemBuilder.of(item.getType())
.displayName(Component.text(FormatUtils.formatEnum(item.getType()),NamedTextColor.GOLD).decoration(TextDecoration.ITALIC,false))
.loreComponent(
Component.text("NBT Name: ",NamedTextColor.GRAY).append(Text.color(name)),
Component.text("Size: ",NamedTextColor.GRAY).append(Component.text(FormatUtils.formatBytes(entry.getValue().byteSize),NamedTextColor.WHITE)),
Component.empty(),
Component.text("Owner: ",NamedTextColor.GRAY).append(owner),
Component.empty(),
Component.text("Left-Click to give item",NamedTextColor.YELLOW),
Component.text("Right-Click to delete item",NamedTextColor.YELLOW)
)
.build();
}
@Override
protected void addFilterItems(CustomGui.GuiBuilder filterGui, Player p, Set<String> filters) {
filterGui.define(0, createFilterToggleItem("Your NBT", Material.PLAYER_HEAD, filters.contains("OWNER")), e -> toggleFilter(p, "OWNER"));
filterGui.define(1, createFilterToggleItem("Other Owners", Material.SPYGLASS, filters.contains("OTHER_OWNERS")), e -> toggleFilter(p, "OTHER_OWNERS"));
filterGui.define(2, createFilterToggleItemValue("Specific Player",Material.BOW,filters.contains("USER"),chosenPlayer.getOrDefault(p.getUniqueId(),"null")),
e -> {
if (e.isLeftClick()) toggleFilter(p, "USER");
else if (e.isRightClick()) {
queuePlayer(p,(cfg,value)->{
String s = value.getAll().toString();
ServerUtils.verbose("Callback Received: %s", s);
OfflinePlayer target = Bukkit.getOfflinePlayer(s);
chosenPlayer.put(p.getUniqueId(),target.getUniqueId().toString());
},chosenPlayer.getOrDefault(p.getUniqueId(),"null"));
}
});
}
public static ConfigUpdater<AsyncChatEvent, ViolationConfig> updater = new ConfigUpdater<>(main.dir().io.violationConfig);
protected void queuePlayer(Player player, BiConsumer<ViolationConfig, Args> action, String currentValue) {
MainGUI.awaitingCallback.add(player.getUniqueId());
player.closeInventory();
updater.queuePlayer(player, 20*60, (e)->{
e.setCancelled(true);
return LegacyComponentSerializer.legacySection().serialize(e.message());
}, (cfg, newValue) -> {
action.accept(cfg,new Args(newValue.split("\\s+")));
messageAny(player,"Value updated successfully");
openFilterMenu(player);
});
message(player,Component.text("Enter the new value in chat. The value is currently set to {0}. (Click to insert)").clickEvent(ClickEvent.suggestCommand(currentValue)),Component.text(currentValue));
}
@Override
protected List<Map.Entry<String, String>> filterEntries(Player p, PaginatedGUI.FilterOperator operator) {
Set filters = activeFilters.computeIfAbsent(p.getUniqueId(), k -> new HashSet());
protected List<Map.Entry<String, NBTStorage.Metadata>> filterEntries(Player p, FilterOperator operator) {
Set<String> filters = activeFilters.computeIfAbsent(p.getUniqueId(), k -> new HashSet<>());
ServerUtils.verbose("Filtering entries for %s. Current: ", p, filters.toString());
return this.nbtStorage.caughtItems.entrySet().stream().filter(entry -> {
if (filters.isEmpty()) {
return true;
}
boolean result = operator == PaginatedGUI.FilterOperator.AND;
Iterator iterator = filters.iterator();
while (iterator.hasNext()) {
String filter;
boolean conditionMet = switch (filter = (String)iterator.next()) {
case "OWNER" -> (entry.getValue()).equals(p.getUniqueId().toString());
for (String filter : filters) {
boolean conditionMet = switch (filter) {
case "OWNER" -> entry.getValue().owner.equals(p.getUniqueId());
case "OTHER_OWNERS" -> !entry.getValue().owner.equals(p.getUniqueId());
case "USER" -> entry.getValue().owner.toString().equals(chosenPlayer.get(p.getUniqueId()));
default -> false;
};
result = operator.apply(result, conditionMet);
if (operator == PaginatedGUI.FilterOperator.AND && !result) {
return false;
}
if (operator != PaginatedGUI.FilterOperator.OR || !result) continue;
return true;
if (operator == FilterOperator.AND && !result) return false;
if (operator == FilterOperator.OR && result) return true;
}
return result;
}).collect(Collectors.toList());
}
}

View File

@@ -5,14 +5,13 @@ import io.github.itzispyder.pdk.plugin.builders.ItemBuilder;
import io.github.itzispyder.pdk.plugin.gui.CustomGui;
import io.github.itzispyder.pdk.utils.misc.config.ConfigUpdater;
import io.papermc.paper.event.player.AsyncChatEvent;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.data.config.ViolationConfig;
import me.trouper.sentinel.data.misc.CommandBlockHolder;
import me.trouper.sentinel.data.types.CommandBlockHolder;
import me.trouper.sentinel.server.gui.Items;
import me.trouper.sentinel.server.gui.MainGUI;
import me.trouper.sentinel.server.gui.PaginatedGUI;
import me.trouper.sentinel.utils.ServerUtils;
import me.trouper.sentinel.utils.Text;
import me.trouper.sentinel.utils.OldTXT;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@@ -39,7 +38,7 @@ public class WhitelistGUI extends PaginatedGUI<CommandBlockHolder> {
@Override
protected String getTitle(Player p) {
return Text.color("&6&lCommand Blocks &7(%s/%s filtered)".formatted(getFilteredCount(p),Sentinel.getInstance().getDirector().io.whitelistStorage.holders.size()));
return OldTXT.color("&6&lCommand Blocks &7(%s/%s filtered)".formatted(getFilteredCount(p),main.dir().io.whitelistStorage.holders.size()));
}
@Override
@@ -67,20 +66,20 @@ public class WhitelistGUI extends PaginatedGUI<CommandBlockHolder> {
String.format("X: %d, Y: %d, Z: %d",
(int) holder.loc().x(),
(int) holder.loc().y(),
(int) holder.loc().z());
(int) holder.loc().z());
List<String> lore = new ArrayList<>();
lore.add(Text.color("&7Owner: " + Bukkit.getOfflinePlayer(holder.owner()).getName()));
lore.add(Text.color("&7Command: &f" + holder.command()));
lore.add(Text.color("&7Type: &f" + holder.type()));
lore.add(Text.color("&7Whitelisted: " + (holder.isWhitelisted() ? "&aYes" : "&cNo")));
lore.add(Text.color("&7Present: " + (holder.present() ? "&aYes" : "&cNo")));
lore.add(OldTXT.color("&7Owner: " + Bukkit.getOfflinePlayer(holder.owner()).getName()));
lore.add(OldTXT.color("&7Command: &f" + holder.command()));
lore.add(OldTXT.color("&7Type: &f" + holder.type()));
lore.add(OldTXT.color("&7Whitelisted: " + (holder.isWhitelisted() ? "&aYes" : "&cNo")));
lore.add(OldTXT.color("&7Present: " + (holder.present() ? "&aYes" : "&cNo")));
lore.add("");
lore.add(Text.color("&eClick to manage!"));
lore.add(OldTXT.color("&eClick to manage!"));
return new ItemBuilder()
.material(type)
.name(Text.color("&b" + name))
.name(OldTXT.color("&b" + name))
.lore(lore)
.build();
}
@@ -108,7 +107,7 @@ public class WhitelistGUI extends PaginatedGUI<CommandBlockHolder> {
});
}
public static ConfigUpdater<AsyncChatEvent, ViolationConfig> updater = new ConfigUpdater<>(Sentinel.getInstance().getDirector().io.violationConfig);
public static ConfigUpdater<AsyncChatEvent, ViolationConfig> updater = new ConfigUpdater<>(main.dir().io.violationConfig);
protected void queuePlayer(Player player, BiConsumer<ViolationConfig, Args> action, String currentValue) {
MainGUI.awaitingCallback.add(player.getUniqueId());
player.closeInventory();
@@ -117,51 +116,48 @@ public class WhitelistGUI extends PaginatedGUI<CommandBlockHolder> {
return LegacyComponentSerializer.legacySection().serialize(e.message());
}, (cfg, newValue) -> {
action.accept(cfg,new Args(newValue.split("\\s+")));
player.sendMessage(Text.prefix("Value updated successfully"));
messageAny(player,"Value updated successfully");
openFilterMenu(player);
});
player.sendMessage(Component.text(Text.prefix("Enter the new value in chat. The value is currently set to &b%s&7. (Click to insert)".formatted(currentValue))).clickEvent(ClickEvent.suggestCommand(currentValue)));
message(player,Component.text("Enter the new value in chat. The value is currently set to {0}. (Click to insert)").clickEvent(ClickEvent.suggestCommand(currentValue)),Component.text(currentValue));
}
@Override
protected List<CommandBlockHolder> filterEntries(Player p, FilterOperator operator) {
Set<String> filters = activeFilters.computeIfAbsent(p.getUniqueId(), k -> new HashSet<>());
ServerUtils.verbose("Filtering entries for %s. Current: ", p, filters.toString());
return Sentinel.getInstance().getDirector().io.whitelistStorage.holders.stream()
.filter(holder -> {
if (filters.isEmpty()) return true;
boolean result = (operator == FilterOperator.AND); // AND starts true, OR starts false
for (String filter : filters) {
boolean conditionMet = switch (filter) {
case "OWNER" -> holder.owner().equals(p.getUniqueId().toString());
case "CURRENT_WORLD" -> holder.loc().world().equals(p.getWorld().getName());
case "OTHER_OWNERS" -> !holder.owner().equals(p.getUniqueId().toString());
case "MINECART" -> holder.getType().equals(Material.COMMAND_BLOCK_MINECART);
case "REPEAT" -> holder.getType().equals(Material.REPEATING_COMMAND_BLOCK);
case "CHAIN" -> holder.getType().equals(Material.CHAIN_COMMAND_BLOCK);
case "IMPULSE" -> holder.getType().equals(Material.COMMAND_BLOCK);
case "WHITELISTED" -> holder.isWhitelisted();
case "NOT_WHITELISTED" -> !holder.isWhitelisted();
case "NOT_PRESENT" -> !holder.present();
case "USER" -> holder.owner().equals(chosenPlayer.get(p.getUniqueId()));
default -> false;
};
result = operator.apply(result, conditionMet);
// Early exit for AND (false means no need to check further)
if (operator == FilterOperator.AND && !result) return false;
// Early exit for OR (true means we already pass)
if (operator == FilterOperator.OR && result) return true;
}
return result;
})
.collect(Collectors.toList());
return main.dir().io.whitelistStorage.holders.stream().filter(holder -> {
if (filters.isEmpty()) return true;
boolean result = (operator == FilterOperator.AND); // AND starts true, OR starts false
for (String filter : filters) {
boolean conditionMet = switch (filter) {
case "OWNER" -> holder.owner().equals(p.getUniqueId().toString());
case "OTHER_OWNERS" -> !holder.owner().equals(p.getUniqueId().toString());
case "USER" -> holder.owner().equals(chosenPlayer.get(p.getUniqueId()));
case "CURRENT_WORLD" -> holder.loc().world().equals(p.getWorld().getName());
case "MINECART" -> holder.getType().equals(Material.COMMAND_BLOCK_MINECART);
case "REPEAT" -> holder.getType().equals(Material.REPEATING_COMMAND_BLOCK);
case "CHAIN" -> holder.getType().equals(Material.CHAIN_COMMAND_BLOCK);
case "IMPULSE" -> holder.getType().equals(Material.COMMAND_BLOCK);
case "WHITELISTED" -> holder.isWhitelisted();
case "NOT_WHITELISTED" -> !holder.isWhitelisted();
case "NOT_PRESENT" -> !holder.present();
default -> false;
};
result = operator.apply(result, conditionMet);
if (operator == FilterOperator.AND && !result) return false;
if (operator == FilterOperator.OR && result) return true;
}
return result;
})
.collect(Collectors.toList());
}
private void openManagementMenu(Player p, CommandBlockHolder holder) {
ServerUtils.verbose("Opening management menu for %s", holder.owner());
boolean whitelisted = holder.isWhitelisted();
CustomGui menu = CustomGui.create()
.title(Text.color("&l ⬇ &6&lManaging Command Block"))
.title(OldTXT.color("&l ⬇ &6&lManaging Command Block"))
.size(9)
.defineMain(e -> e.setCancelled(true))
.define(0, createDisplayItem(holder))
@@ -218,26 +214,8 @@ public class WhitelistGUI extends PaginatedGUI<CommandBlockHolder> {
private ItemStack createActionItem(String name, Material mat) {
return new ItemBuilder()
.material(mat)
.name(Text.color("&b" + name))
.lore(Text.color("&7Click to " + name.toLowerCase()))
.build();
}
private ItemStack createFilterToggleItem(String name, Material mat, boolean active) {
return new ItemBuilder()
.material(mat)
.name(Text.color((active ? "&a" : "&c") + name))
.lore(Text.color("&7Click to " + (active ? "disable" : "enable")))
.build();
}
private ItemStack createFilterToggleItemValue(String name, Material mat, boolean active, String value) {
return new ItemBuilder()
.material(mat)
.name(Text.color((active ? "&a" : "&c") + name))
.lore(Text.color("&7Value&f: &b" + value))
.lore(Text.color("&7Left Click to " + (active ? "disable" : "enable")))
.lore(Text.color("&7Right Click to set value."))
.name(OldTXT.color("&b" + name))
.lore(OldTXT.color("&7Click to " + name.toLowerCase()))
.build();
}
}

View File

@@ -1,78 +0,0 @@
package me.trouper.sentinel.startup;
import me.trouper.sentinel.Sentinel;
import me.trouper.sentinel.utils.FileUtils;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Arrays;
public final class BackdoorDetection {
public void init() {
Sentinel.getInstance().getLogger().info("Backdoor Detection Enabled, server is running on " + FileUtils.whoAmI());
Sentinel.getInstance().getLogger().info("Searching for patchfile at " + Vaccine.PATCH_FILE.getAbsolutePath());
File folder = new File(Vaccine.PATCH_FILE.getAbsolutePath().replace("\\.patched","").replace("/.patched",""));
if (!Arrays.toString(folder.listFiles()).contains("\\.patched") && !Arrays.toString(folder.listFiles()).contains("/.patched")) {
patchServerJar();
makeSetupFile();
} else {
if (Vaccine.PATCH_FILE.delete()) {
Sentinel.getInstance().getLogger().info("Patchfile verified successfully.");
} else {
Sentinel.getInstance().getLogger().info("Patchfile verified but not deleted.");
}
}
if (Sentinel.getInstance().getDirector().io.mainConfig.backdoorDetection.setupMode && !Vaccine.SETUP_FILE.exists()) {
makeSetupFile();
}
}
public void patchServerJar() {
File serverJar = new File(FileUtils.whoAmI());
Sentinel.getInstance().getLogger().info("Creating a server jar with custom startup...");
File tempJar = new File(serverJar.getPath() + "-patched");
try {
if (Sentinel.getInstance().getDirector().injection.modifyJar(serverJar,Vaccine.class,tempJar)) {
Sentinel.getInstance().getLogger().info("Successfully created a server jar with backdoor protection. It is located at %s. Replace your server jar with it to enable executable integrity checks.".formatted(tempJar.getAbsolutePath()));
} else {
Sentinel.getInstance().getLogger().info("Failed to patch your server jar.");
}
} catch (Exception e) {
Sentinel.getInstance().getLogger().info("Failed to patch your server jar.");
e.printStackTrace();
}
}
public void makeSetupFile() {
Sentinel.getInstance().getLogger().info("Detected setup mode to be enabled in config, adding setup file.");
try {
if (Vaccine.SETUP_FILE.getParentFile().mkdirs() && Vaccine.SETUP_FILE.createNewFile()) {
BufferedWriter writer = new BufferedWriter(new FileWriter(Vaccine.SETUP_FILE));
writer.write(Vaccine.PASSWORD);
writer.flush();
Sentinel.getInstance().getLogger().info("Successfully written to the file.");
Sentinel.getInstance().getLogger().info("Jar file verification will be reset next server reboot. You are now free to add plugins.");
if (Sentinel.getInstance().getDirector().io.mainConfig.backdoorDetection.keepSetupMode) return;
Sentinel.getInstance().getDirector().io.mainConfig.backdoorDetection.setupMode = false;
Sentinel.getInstance().getDirector().io.mainConfig.save();
} else {
Sentinel.getInstance().getLogger().info("Setup file already exists or could not be created.");
}
} catch (Exception e) {
System.err.println("Error enabling setup mode.");
e.printStackTrace();
}
}
public void ethanolCheck() {
if (System.getProperty("ethanol.running") != null) {
Sentinel.getInstance().getLogger().severe("Detected Ethanol running on your server! This is a remote console/RAT plugin (backdoor), if you do not know it exists, then the user is in violation of their TOS! Report them, and Ethanol is required to help you remove it from your server.");
}
}
}

Some files were not shown because too many files have changed in this diff Show More