From e3cd50cf75179b190446e461ac94738239c96bcd Mon Sep 17 00:00:00 2001 From: Phoenix616 Date: Wed, 6 Jul 2022 00:54:44 +0100 Subject: [PATCH] Add some debug logging for shop sign creation --- src/main/java/com/Acrobot/ChestShop/ChestShop.java | 6 ++++++ .../ChestShop/Listeners/Block/SignCreate.java | 3 +++ .../com/Acrobot/ChestShop/UUIDs/NameManager.java | 13 ++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/Acrobot/ChestShop/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/ChestShop.java index fd6b406..3613374 100644 --- a/src/main/java/com/Acrobot/ChestShop/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/ChestShop.java @@ -535,6 +535,12 @@ public class ChestShop extends JavaPlugin { return logger; } + public static void logDebug(String message) { + if (Properties.DEBUG) { + getBukkitLogger().info("[DEBUG] " + message); + } + } + public static Server getBukkitServer() { return server; } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java index e7fdd5a..fd7252d 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/SignCreate.java @@ -34,6 +34,7 @@ public class SignCreate implements Listener { if (ChestShopSign.isValid(event.getLines()) && !NameManager.canUseName(event.getPlayer(), OTHER_NAME_DESTROY, ChestShopSign.getOwner(event.getLines()))) { event.setCancelled(true); sign.update(); + ChestShop.logDebug("Shop sign creation at " + sign.getLocation() + " by " + event.getPlayer().getName() + " was cancelled as they weren't able to create a shop for the account '" + ChestShopSign.getOwner(event.getLines()) + "'"); return; } @@ -49,6 +50,7 @@ public class SignCreate implements Listener { if (preEvent.getOutcome().shouldBreakSign()) { event.setCancelled(true); signBlock.breakNaturally(); + ChestShop.logDebug("Shop sign creation at " + sign.getLocation() + " by " + event.getPlayer().getName() + " was cancelled (creation outcome: " + preEvent.getOutcome() + ") and the sign broken"); return; } @@ -57,6 +59,7 @@ public class SignCreate implements Listener { } if (preEvent.isCancelled()) { + ChestShop.logDebug("Shop sign creation at " + sign.getLocation() + " by " + event.getPlayer().getName() + " was cancelled (creation outcome: " + preEvent.getOutcome() + ") and sign lines were set to " + String.join(", ", preEvent.getSignLines())); return; } diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index 4295852..2f1c26b 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -271,7 +271,12 @@ public class NameManager implements Listener { public static boolean canUseName(Player player, Permission base, String name) { if (ChestShopSign.isAdminShop(name)) { - return Permission.has(player, Permission.ADMIN_SHOP); + if (Permission.has(player, Permission.ADMIN_SHOP)) { + return true; + } else { + ChestShop.logDebug(player.getName() + " cannot use the name " + name + " as it's an admin shop and they don't have the permission " + Permission.ADMIN_SHOP); + return false; + } } if (Permission.otherName(player, base, name)) { @@ -282,6 +287,7 @@ public class NameManager implements Listener { ChestShop.callEvent(queryEvent); Account account = queryEvent.getAccount(); if (account == null) { + ChestShop.logDebug(player.getName() + " cannot use the name " + name + " for a shop as no account with that name exists"); return false; } if (!account.getName().equalsIgnoreCase(name) && Permission.otherName(player, base, account.getName())) { @@ -296,6 +302,11 @@ public class NameManager implements Listener { public static void onAccountAccessCheck(AccountAccessEvent event) { if (!event.canAccess()) { event.setAccess(event.getPlayer().getUniqueId().equals(event.getAccount().getUuid())); + if (!event.canAccess()) { + ChestShop.logDebug(event.getPlayer().getName() + "/" + event.getPlayer().getUniqueId() + + " cannot access the account " + event.getAccount().getName() + "/" + event.getAccount().getUuid() + + " as their UUID doesn't match!"); + } } }