Fixed colors in the ActionBuilder, and optimized the NBT Pull Event

This commit is contained in:
TheTrouper
2023-12-07 11:41:46 -06:00
parent 228f8a848f
commit 9de3f03e22
2 changed files with 39 additions and 41 deletions

View File

@@ -166,17 +166,17 @@ public class Action {
if (notifyTrusted) { if (notifyTrusted) {
TextComponent notification = new TextComponent(); TextComponent notification = new TextComponent();
notification.setText(Text.prefix(" " + actionTop)); notification.setText(Text.prefix(" " + actionTop));
String body = "]=- Sentinel -=[\n" + actionTitle + "\n"; String body = "&b]=- Sentinel -=[&f\n" + actionTitle + "&r\n";
body += (player != null) ? "Player: " + player.getName() + "\n" : ""; body += (player != null) ? "&fPlayer: &b" + player.getName() + "&r\n" : "";
body += (command != null) ? ((loggedCommand != null && loggedCommand.length() > 64) ? "Command: Too long to show here!\n | Saved to file: " + commandLog + "\n" : "Command: " + command + "\n") : ""; body += (command != null) ? ((loggedCommand != null && loggedCommand.length() > 64) ? "&fCommand: &cToo long to show here!&r\n &7&l| &fSaved to file: &b" + commandLog + "&r\n" : "&fCommand: &b" + command + "&r\n") : "";
body += (item != null) ? "Item: /Sentinel/LoggedNBT/" + itemLog + "\n" : ""; body += (item != null) ? "&fItem: &b/Sentinel/LoggedNBT/&b" + itemLog + "\n" : "";
body += (block != null) ? "Block: " + block.getType().toString().toLowerCase().replace("_", " ") + "\nLocation: " + block.getLocation().getX() + " " + block.getLocation().getY() + " " + block.getLocation().getZ() + "\n" : ""; body += (block != null) ? "&fBlock: &b" + block.getType().toString().toLowerCase().replace("_", " ") + "\n&fLocation: &b" + block.getLocation().getX() + " " + block.getLocation().getY() + " " + block.getLocation().getZ() + "&r\n" : "";
body += "Denied: " + (denied ? "\u00a7a\u2714" : "\u00a7c\u2718") + "\n"; body += "&fDenied: &b" + (denied ? "&a\u2714" : "&c\u2718") + "&r\n";
body += "Deoped: " + (deoped ? "\u00a7a\u2714" : "\u00a7c\u2718") + "\n"; body += "&fDeoped: " + (deoped ? "&a\u2714" : "&c\u2718") + "&r\n";
body += "Punished: " + (punished ? "\u00a7a\u2714" : "\u00a7c\u2718") + "\n"; body += "&fPunished: " + (punished ? "&a\u2714" : "&c\u2718") + "&r\n";
body += (revertGM) ? "RevertGM: \u00a7a\u2714\n" : ""; body += (revertGM) ? "&fRevertGM: &a\u2714\n" : "";
body += "Logged: " + (notifyDiscord ? "\u00a7a\u2714" : "\u00a7c\u2718"); body += "&fLogged: " + (notifyDiscord ? "&a\u2714" : "&c\u2718");
notification.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new net.md_5.bungee.api.chat.hover.content.Text(body))); notification.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new net.md_5.bungee.api.chat.hover.content.Text(Text.color(body))));
ServerUtils.forEachPlayer(trusted -> { ServerUtils.forEachPlayer(trusted -> {
if (Sentinel.isTrusted(trusted)) { if (Sentinel.isTrusted(trusted)) {
trusted.spigot().sendMessage(notification); trusted.spigot().sendMessage(notification);

View File

@@ -20,36 +20,34 @@ public class NBTEvents implements Listener {
@EventHandler @EventHandler
private void onNBTPull(InventoryCreativeEvent e) { private void onNBTPull(InventoryCreativeEvent e) {
ServerUtils.sendDebugMessage("NBT: Detected creative mode action"); ServerUtils.sendDebugMessage("NBT: Detected creative mode action");
if (Config.preventNBT) { if (!Config.preventNBT) return;
ServerUtils.sendDebugMessage("NBT: Enabled"); ServerUtils.sendDebugMessage("NBT: Enabled");
if (!(e.getWhoClicked() instanceof Player p)) return; if (!(e.getWhoClicked() instanceof Player p)) return;
ServerUtils.sendDebugMessage("NBT: Clicker is a player"); ServerUtils.sendDebugMessage("NBT: Clicker is a player");
if (e.getCursor() == null) return; if (e.getCursor() == null) return;
ServerUtils.sendDebugMessage("NBT: Cursor isn't null"); ServerUtils.sendDebugMessage("NBT: Cursor isn't null");
ItemStack i = e.getCursor(); ItemStack i = e.getCursor();
if (!Sentinel.isTrusted(p)) { if (Sentinel.isTrusted(p)) return;
ServerUtils.sendDebugMessage("NBT: Not trusted"); ServerUtils.sendDebugMessage("NBT: Not trusted");
if (e.getCursor().getItemMeta() == null) return; if (e.getCursor().getItemMeta() == null) return;
ServerUtils.sendDebugMessage("NBT: Cursor has meta"); ServerUtils.sendDebugMessage("NBT: Cursor has meta");
if (i.hasItemMeta() && i.getItemMeta() != null) { if (i.hasItemMeta() && i.getItemMeta() != null) {
ServerUtils.sendDebugMessage("NBT: Item has meta"); ServerUtils.sendDebugMessage("NBT: Item has meta");
if (!itemPasses(i)) { if (!itemPasses(i)) {
ServerUtils.sendDebugMessage("NBT: Item doesn't pass, preforming action"); ServerUtils.sendDebugMessage("NBT: Item doesn't pass, preforming action");
Action a = new Action.Builder() Action a = new Action.Builder()
.setEvent(e) .setEvent(e)
.setAction(ActionType.NBT) .setAction(ActionType.NBT)
.setPlayer(Bukkit.getPlayer(e.getWhoClicked().getName())) .setPlayer(Bukkit.getPlayer(e.getWhoClicked().getName()))
.setItem(e.getCursor()) .setItem(e.getCursor())
.setDenied(Config.preventNBT) .setDenied(Config.preventNBT)
.setDeoped(Config.deop) .setDeoped(Config.deop)
.setPunished(Config.nbtPunish) .setPunished(Config.nbtPunish)
.setRevertGM(Config.preventNBT) .setRevertGM(Config.preventNBT)
.setNotifyConsole(true) .setNotifyConsole(true)
.setNotifyTrusted(true) .setNotifyTrusted(true)
.setnotifyDiscord(Config.logNBT) .setnotifyDiscord(Config.logNBT)
.execute(); .execute();
}
}
} }
} }
} }