Added recursive container search
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
# Plugin
|
# Plugin
|
||||||
group = 'io.github.thetrouper'
|
group = 'io.github.thetrouper'
|
||||||
version = 0.2.1
|
version = 0.2.2
|
||||||
|
|
||||||
# Minecraft
|
# Minecraft
|
||||||
mc_version = 1.19.4
|
mc_version = 1.19.4
|
||||||
|
|||||||
@@ -32,13 +32,10 @@ public final class Sentinel extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
log.info("\n]======------ Pre-load started! ------======[");
|
log.info("\n]======------ Pre-load started! ------======[");
|
||||||
instance = this;
|
instance = this;
|
||||||
log.info("Loading Config...");
|
log.info("Loading Config...");
|
||||||
Config.loadConfiguration();
|
loadConfig();
|
||||||
log.info("Loading Dictionary (" + Config.lang + ")...");
|
|
||||||
dict = JsonSerializable.load(LanguageFile.PATH,LanguageFile.class,new LanguageFile());
|
|
||||||
log.info("Initializing Server ID...");
|
log.info("Initializing Server ID...");
|
||||||
String serverID = Authenticator.getServerID();
|
String serverID = Authenticator.getServerID();
|
||||||
identifier = serverID;
|
identifier = serverID;
|
||||||
@@ -56,6 +53,7 @@ public final class Sentinel extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
switch (authStatus) {
|
switch (authStatus) {
|
||||||
case "AUTHORIZED" -> {
|
case "AUTHORIZED" -> {
|
||||||
|
log.info("\n]======----- Auth Success! -----======[");
|
||||||
startup();
|
startup();
|
||||||
authstatus = authstatus.replaceAll("ur a skid lmao","get out of here kiddo");
|
authstatus = authstatus.replaceAll("ur a skid lmao","get out of here kiddo");
|
||||||
}
|
}
|
||||||
@@ -88,14 +86,9 @@ public final class Sentinel extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startup() {
|
public void startup() {
|
||||||
log.info("\n]======----- Auth Success! -----======[");
|
log.info("\n]======----- Loading Sentinel! -----======[");
|
||||||
// Init
|
loadConfig();
|
||||||
log.info("Verifying Config...");
|
|
||||||
getConfig().options().copyDefaults();
|
|
||||||
saveDefaultConfig();
|
|
||||||
|
|
||||||
|
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
log.info("Starting Up! (" + getDescription().getVersion() + ")...");
|
log.info("Starting Up! (" + getDescription().getVersion() + ")...");
|
||||||
|
|
||||||
@@ -137,6 +130,18 @@ public final class Sentinel extends JavaPlugin {
|
|||||||
" ]====---- Advanced Anti-Grief & Chat Filter ----====[");
|
" ]====---- Advanced Anti-Grief & Chat Filter ----====[");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadConfig() {
|
||||||
|
// Init
|
||||||
|
Config.loadConfiguration();
|
||||||
|
|
||||||
|
log.info("Loading Dictionary (" + Config.lang + ")...");
|
||||||
|
dict = JsonSerializable.load(LanguageFile.PATH,LanguageFile.class,new LanguageFile());
|
||||||
|
|
||||||
|
log.info("Verifying Config...");
|
||||||
|
getConfig().options().copyDefaults();
|
||||||
|
saveDefaultConfig();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugin shutdown logic
|
* Plugin shutdown logic
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -34,7 +34,14 @@ public class SentinelCommand extends CustomCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void dispatchCommand(CommandSender sender, Command command, String label, String[] args) {
|
public void dispatchCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
Player p = (Player) sender;
|
Player p = (Player) sender;
|
||||||
|
Sentinel instance = Sentinel.getInstance();
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
|
case "reload" -> {
|
||||||
|
if (!Sentinel.isTrusted(p)) return;
|
||||||
|
p.sendMessage(Text.prefix("Reloading Sentinel!"));
|
||||||
|
Sentinel.log.info("[Sentinel] Re-Initializing Sentinel!");
|
||||||
|
instance.loadConfig();
|
||||||
|
}
|
||||||
case "debug" -> {
|
case "debug" -> {
|
||||||
switch (args[1]) {
|
switch (args[1]) {
|
||||||
case "antiswear" -> {
|
case "antiswear" -> {
|
||||||
@@ -82,7 +89,8 @@ public class SentinelCommand extends CustomCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void registerCompletions(CompletionBuilder builder) {
|
public void registerCompletions(CompletionBuilder builder) {
|
||||||
builder.addCompletion(1, "debug",
|
builder.addCompletion(1, "debug",
|
||||||
"getHeat");
|
"getHeat",
|
||||||
|
"reload");
|
||||||
if (builder.args.length >= 2 && builder.args[1].equals("debug")) {
|
if (builder.args.length >= 2 && builder.args[1].equals("debug")) {
|
||||||
builder.addCompletion(2, "antiswear",
|
builder.addCompletion(2, "antiswear",
|
||||||
"antispam",
|
"antispam",
|
||||||
|
|||||||
@@ -6,12 +6,17 @@ import io.github.thetrouper.sentinel.data.Action;
|
|||||||
import io.github.thetrouper.sentinel.data.ActionType;
|
import io.github.thetrouper.sentinel.data.ActionType;
|
||||||
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
import io.github.thetrouper.sentinel.server.util.ServerUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
|
import org.bukkit.block.Container;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.BlockStateMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -52,30 +57,85 @@ public class NBTEvents implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isContainer(ItemStack itemStack) {
|
||||||
|
return itemStack.getType() == Material.CHEST ||
|
||||||
|
itemStack.getType() == Material.TRAPPED_CHEST ||
|
||||||
|
itemStack.getType() == Material.FURNACE ||
|
||||||
|
itemStack.getType() == Material.BLAST_FURNACE ||
|
||||||
|
itemStack.getType() == Material.DROPPER ||
|
||||||
|
itemStack.getType() == Material.DISPENSER ||
|
||||||
|
itemStack.getType() == Material.HOPPER ||
|
||||||
|
itemStack.getType() == Material.BARREL;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Inventory getSubInventory(ItemStack containerItem) {
|
||||||
|
ServerUtils.sendDebugMessage("NBT: GetSubInv checking item: " + containerItem);
|
||||||
|
if (containerItem.getItemMeta() instanceof BlockStateMeta blockStateMeta) {
|
||||||
|
ServerUtils.sendDebugMessage("NBT: subInv has (is) blockStateMeta: " + blockStateMeta);
|
||||||
|
BlockState blockState = blockStateMeta.getBlockState();
|
||||||
|
if (blockState instanceof Container) {
|
||||||
|
ServerUtils.sendDebugMessage("NBT: subInv has (is) container: " + (Container) blockState);
|
||||||
|
return ((Container) blockState).getInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ServerUtils.sendDebugMessage("NBT: Inv is null: " + containerItem);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean containerPasses(Inventory inventory) {
|
||||||
|
for (ItemStack itemStack : inventory.getContents()) {
|
||||||
|
if (itemStack == null || itemStack.getType().isAir()) continue;
|
||||||
|
if (!itemPasses(itemStack)) {
|
||||||
|
ServerUtils.sendDebugMessage("NBT: No pass C(I)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!isContainer(itemStack)) continue;
|
||||||
|
|
||||||
|
Inventory subInventory = getSubInventory(itemStack);
|
||||||
|
if (!containerPasses(subInventory)) {
|
||||||
|
ServerUtils.sendDebugMessage("NBT: No pass C(R)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ServerUtils.sendDebugMessage("NBT: Item passes recursion check.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean itemPasses(ItemStack i) {
|
private boolean itemPasses(ItemStack i) {
|
||||||
ServerUtils.sendDebugMessage("NBT: Checking if item passes: " + i.getItemMeta());
|
ServerUtils.sendDebugMessage("NBT: Checking if item passes: " + i.getItemMeta());
|
||||||
if (i.getItemMeta() != null) {
|
if (i.getItemMeta() == null) {
|
||||||
|
ServerUtils.sendDebugMessage("NBT: Item passes because of no meta");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
ServerUtils.sendDebugMessage("NBT: Item meta isn't null");
|
ServerUtils.sendDebugMessage("NBT: Item meta isn't null");
|
||||||
ItemMeta meta = i.getItemMeta();
|
ItemMeta meta = i.getItemMeta();
|
||||||
|
Inventory inv = getSubInventory(i);
|
||||||
|
if (inv != null) {
|
||||||
|
ServerUtils.sendDebugMessage("NBT: Item has a SubInv: " + inv);
|
||||||
|
if (!containerPasses(inv)) {
|
||||||
|
ServerUtils.sendDebugMessage("NBT: No pass C");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!Config.allowName && meta.hasDisplayName()) {
|
if (!Config.allowName && meta.hasDisplayName()) {
|
||||||
ServerUtils.sendDebugMessage("NBT: No pass N");
|
ServerUtils.sendDebugMessage("NBT: No pass N");
|
||||||
return false;
|
return false;
|
||||||
} else if (!Config.allowLore && meta.hasLore()) {
|
}
|
||||||
|
if (!Config.allowLore && meta.hasLore()) {
|
||||||
ServerUtils.sendDebugMessage("NBT: No Pass L ");
|
ServerUtils.sendDebugMessage("NBT: No Pass L ");
|
||||||
return false;
|
return false;
|
||||||
} else if (!Config.allowAttributes && meta.hasAttributeModifiers()) {
|
}
|
||||||
|
if (!Config.allowAttributes && meta.hasAttributeModifiers()) {
|
||||||
ServerUtils.sendDebugMessage("NBT: No pass A");
|
ServerUtils.sendDebugMessage("NBT: No pass A");
|
||||||
return false;
|
return false;
|
||||||
} else if (Config.globalMaxEnchant != 0 && hasIllegalEnchants(i)) {
|
}
|
||||||
|
if (Config.globalMaxEnchant != 0 && hasIllegalEnchants(i)) {
|
||||||
ServerUtils.sendDebugMessage("NBT: No pass E");
|
ServerUtils.sendDebugMessage("NBT: No pass E");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ServerUtils.sendDebugMessage("NBT: All checks passed");
|
ServerUtils.sendDebugMessage("NBT: All checks passed");
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
ServerUtils.sendDebugMessage("NBT: Item passes because of no meta");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Detected creative mode action
|
[01:23:03 INFO]: [Sentinel] [DEBUG]: NBT: Detected creative mode action
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ public class AntiUnicode {
|
|||||||
public static void handleAntiUnicode(AsyncPlayerChatEvent e) {
|
public static void handleAntiUnicode(AsyncPlayerChatEvent e) {
|
||||||
String message = Text.removeFirstColor(e.getMessage());
|
String message = Text.removeFirstColor(e.getMessage());
|
||||||
String nonAllowed = message.replaceAll("[A-Za-z0-9\\[,./?><|\\]§()*&^%$#@!~`{}:;'\"-_]", "").trim();
|
String nonAllowed = message.replaceAll("[A-Za-z0-9\\[,./?><|\\]§()*&^%$#@!~`{}:;'\"-_]", "").trim();
|
||||||
|
if (message.matches("https?://(www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)")) {
|
||||||
|
|
||||||
|
}
|
||||||
if (nonAllowed.length() != 0) {
|
if (nonAllowed.length() != 0) {
|
||||||
e.getPlayer().sendMessage(Text.prefix(Sentinel.dict.get("unicode-warn")));
|
e.getPlayer().sendMessage(Text.prefix(Sentinel.dict.get("unicode-warn")));
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class Authenticator {
|
|||||||
String authStatus = "";
|
String authStatus = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL url = new URL("https://sentinelauth.000webhostapp.com/index.html");
|
URL url = new URL("https://trouper.me/auth/sentinel");
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
|
||||||
List<String> lines = readLines(reader);
|
List<String> lines = readLines(reader);
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public class Authenticator {
|
|||||||
|
|
||||||
if (key.equals(licenseKey)) {
|
if (key.equals(licenseKey)) {
|
||||||
if (Arrays.asList(allowedArr).contains(serverID)) {
|
if (Arrays.asList(allowedArr).contains(serverID)) {
|
||||||
authStatus = "AUTHORIZED";
|
authStatus = "AUTHOReIZED";
|
||||||
return authStatus;
|
return authStatus;
|
||||||
} else {
|
} else {
|
||||||
if (Arrays.asList(allowedArr).contains("minehut")) {
|
if (Arrays.asList(allowedArr).contains("minehut")) {
|
||||||
|
|||||||
@@ -42,7 +42,15 @@ public class FileUtils {
|
|||||||
public static String createNBTLog(String contents) {
|
public static String createNBTLog(String contents) {
|
||||||
ServerUtils.sendDebugMessage("FileUtils: Creating NBT log");
|
ServerUtils.sendDebugMessage("FileUtils: Creating NBT log");
|
||||||
String fileName = "nbt_log-" + Randomizer.generateID();
|
String fileName = "nbt_log-" + Randomizer.generateID();
|
||||||
File file = new File(Sentinel.getInstance().getDataFolder() + "/LoggedNBT/" + fileName + ".txt");
|
|
||||||
|
File dataFolder = Sentinel.getInstance().getDataFolder();
|
||||||
|
|
||||||
|
File loggedNBTFolder = new File(dataFolder,"LoggedNBT");
|
||||||
|
if (!loggedNBTFolder.exists()) {
|
||||||
|
loggedNBTFolder.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(loggedNBTFolder, fileName + ".txt");
|
||||||
try {
|
try {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
|
|||||||
Reference in New Issue
Block a user