From 5eaaf8faa56cae06688bd75cad1793b063d248bd Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 25 Jul 2021 20:14:06 +0200 Subject: [PATCH] Add debug log for permission resolution + change api for Log debug --- .../lib/core/permissions/PermEntity.java | 31 +++++++++++-------- .../core/permissions/PermissionsResolver.java | 14 +++++---- .../java/fr/pandacube/lib/core/util/Log.java | 4 +-- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Core/src/main/java/fr/pandacube/lib/core/permissions/PermEntity.java b/Core/src/main/java/fr/pandacube/lib/core/permissions/PermEntity.java index ecfdae3..40d2643 100644 --- a/Core/src/main/java/fr/pandacube/lib/core/permissions/PermEntity.java +++ b/Core/src/main/java/fr/pandacube/lib/core/permissions/PermEntity.java @@ -8,6 +8,7 @@ import java.util.Set; import fr.pandacube.lib.core.chat.ChatUtil.DisplayTreeNode; import fr.pandacube.lib.core.permissions.PermissionsCachedBackendReader.CachedEntity; import fr.pandacube.lib.core.permissions.SQLPermissions.EntityType; +import fr.pandacube.lib.core.util.Log; public abstract class PermEntity { protected final String name; @@ -78,11 +79,11 @@ public abstract class PermEntity { public Map listEffectivePermissions() { - return Permissions.resolver.getEffectivePermissionList(name, type, null, null); + return listEffectivePermissions(null, null); } public Map listEffectivePermissions(String server) { - return Permissions.resolver.getEffectivePermissionList(name, type, server, null); + return listEffectivePermissions(server, null); } public Map listEffectivePermissions(String server, String world) { @@ -91,24 +92,28 @@ public abstract class PermEntity { public Boolean hasPermission(String permission) { - return Permissions.resolver.getEffectivePermission(name, type, permission, null, null); + return hasPermission(permission, null, null); } public Boolean hasPermission(String permission, String server) { - return Permissions.resolver.getEffectivePermission(name, type, permission, server, null); + return hasPermission(permission, server, null); } public Boolean hasPermission(String permission, String server, String world) { - return Permissions.resolver.getEffectivePermission(name, type, permission, server, world); + Boolean ret = Permissions.resolver.getEffectivePermission(name, type, permission, server, world); + if (Log.isDebugEnabled()) { + Log.debug("[Perm] For " + type.toString().toLowerCase() + " " + getName() + ", '" + permission + "' is " + ret); + } + return ret; } public DisplayTreeNode debugPermission(String permission) { - return Permissions.resolver.debugPermission(name, type, permission, null, null); + return debugPermission(permission, null, null); } public DisplayTreeNode debugPermission(String permission, String server) { - return Permissions.resolver.debugPermission(name, type, permission, server, null); + return debugPermission(permission, server, null); } public DisplayTreeNode debugPermission(String permission, String server, String world) { @@ -117,11 +122,11 @@ public abstract class PermEntity { public void addSelfPermission(String permission) { - Permissions.backendWriter.addSelfPermission(name, type, permission, null, null); + addSelfPermission(permission, null, null); } public void addSelfPermission(String permission, String server) { - Permissions.backendWriter.addSelfPermission(name, type, permission, server, null); + addSelfPermission(permission, server, null); } public void addSelfPermission(String permission, String server, String world) { @@ -130,11 +135,11 @@ public abstract class PermEntity { public void removeSelfPermission(String permission) { - Permissions.backendWriter.removeSelfPermission(name, type, permission, null, null); + removeSelfPermission(permission, null, null); } public void removeSelfPermission(String permission, String server) { - Permissions.backendWriter.removeSelfPermission(name, type, permission, server, null); + removeSelfPermission(permission, server, null); } public void removeSelfPermission(String permission, String server, String world) { @@ -152,11 +157,11 @@ public abstract class PermEntity { } public List getSelfPermissions() { - return getBackendEntity().getSelfPermissions(null, null); + return getSelfPermissions(null, null); } public List getSelfPermissions(String server) { - return getBackendEntity().getSelfPermissions(server, null); + return getSelfPermissions(server, null); } public List getSelfPermissions(String server, String world) { diff --git a/Core/src/main/java/fr/pandacube/lib/core/permissions/PermissionsResolver.java b/Core/src/main/java/fr/pandacube/lib/core/permissions/PermissionsResolver.java index d2c8885..801e0a0 100644 --- a/Core/src/main/java/fr/pandacube/lib/core/permissions/PermissionsResolver.java +++ b/Core/src/main/java/fr/pandacube/lib/core/permissions/PermissionsResolver.java @@ -106,9 +106,10 @@ public class PermissionsResolver { DataResolutionNode resolutionResult = resolveData(entity, dataType); if (resolutionResult.conflict) { - Log.warning("For data " + dataType + ":"); - for (Chat cmp : ChatUtil.treeView(resolutionResult.toDisplayTreeNode(), true)) - Log.warning(cmp.getLegacyText()); + Log.warning("For data " + dataType + ":\n" + + ChatUtil.treeView(resolutionResult.toDisplayTreeNode(), true).stream() + .map(cmp -> cmp.getLegacyText()) + .collect(Collectors.joining(ChatColor.RESET + "\n"))); } return resolutionResult.result != null ? resolutionResult.result : ""; @@ -309,9 +310,10 @@ public class PermissionsResolver { PermResolutionNode resolutionResult = resolvePermission(entity, permission, server, world, true); if (resolutionResult.conflict) { - Log.warning("For permission " + permission + ":"); - for (Chat cmp : ChatUtil.treeView(resolutionResult.toDisplayTreeNode(), true)) - Log.warning(cmp.getLegacyText()); + Log.warning("For permission " + permission + ":\n" + + ChatUtil.treeView(resolutionResult.toDisplayTreeNode(), true).stream() + .map(cmp -> cmp.getLegacyText()) + .collect(Collectors.joining(ChatColor.RESET + "\n"))); } return resolutionResult.result; diff --git a/Core/src/main/java/fr/pandacube/lib/core/util/Log.java b/Core/src/main/java/fr/pandacube/lib/core/util/Log.java index b082532..430ed7d 100644 --- a/Core/src/main/java/fr/pandacube/lib/core/util/Log.java +++ b/Core/src/main/java/fr/pandacube/lib/core/util/Log.java @@ -9,11 +9,11 @@ public class Log { private static Logger logger; private static AtomicBoolean logDebug = new AtomicBoolean(false); - public static void setDebugState(boolean newVal) { + public static void setDebug(boolean newVal) { logDebug.set(newVal); } - public static boolean getDebugState() { + public static boolean isDebugEnabled() { return logDebug.get(); }