Skip to content

Commit 83e197a

Browse files
committed
Implement config option for debug permission
1 parent 9884ec2 commit 83e197a

File tree

5 files changed

+56
-7
lines changed

5 files changed

+56
-7
lines changed

src/main/java/org/mvplugins/multiverse/core/api/MVConfig.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,18 @@ public interface MVConfig {
270270
*/
271271
int getGlobalDebug();
272272

273+
/**
274+
* Sets debugPermissions
275+
* @param debugPermissions The new value
276+
*/
277+
void setDebugPermissions(boolean debugPermissions);
278+
279+
/**
280+
* gets debugPermissions.
281+
* @return debugPermissions.
282+
*/
283+
boolean getDebugPermissions();
284+
273285
/**
274286
* Sets whether to suppress startup messages.
275287
*

src/main/java/org/mvplugins/multiverse/core/commandtools/MVCommandPermissions.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
@Service
2020
public class MVCommandPermissions {
2121
private final Map<String, Predicate<CommandIssuer>> permissionsCheckMap;
22+
private final CorePermissionsChecker permissionsChecker;
2223

2324
@Inject
2425
MVCommandPermissions(@NotNull CorePermissionsChecker permissionsChecker) {
25-
permissionsCheckMap = new HashMap<>();
26+
this.permissionsCheckMap = new HashMap<>();
27+
this.permissionsChecker = permissionsChecker;
2628

2729
registerPermissionChecker("mvteleport", issuer -> permissionsChecker.hasAnyTeleportPermission(issuer.getIssuer()));
2830
registerPermissionChecker("mvspawn", issuer -> permissionsChecker.hasAnySpawnPermission(issuer.getIssuer()));
@@ -52,6 +54,6 @@ public void registerPermissionChecker(String id, Predicate<CommandIssuer> checke
5254
boolean hasPermission(CommandIssuer issuer, String permission) {
5355
return Option.of(permissionsCheckMap.get(permission))
5456
.map(checker -> checker.test(issuer))
55-
.getOrElse(() -> issuer.hasPermission(permission));
57+
.getOrElse(() -> permissionsChecker.hasPermission(issuer.getIssuer(), permission));
5658
}
5759
}

src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,16 @@ public int getGlobalDebug() {
354354
return configHandle.get(configNodes.GLOBAL_DEBUG);
355355
}
356356

357+
@Override
358+
public void setDebugPermissions(boolean debugPermissions) {
359+
configHandle.set(configNodes.DEBUG_PERMISSIONS, debugPermissions);
360+
}
361+
362+
@Override
363+
public boolean getDebugPermissions() {
364+
return configHandle.get(configNodes.DEBUG_PERMISSIONS);
365+
}
366+
357367
@Override
358368
public void setSilentStart(boolean silentStart) {
359369
configHandle.set(configNodes.SILENT_START, silentStart);

src/main/java/org/mvplugins/multiverse/core/config/MVCoreConfigNodes.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private <N extends Node> N node(N node) {
306306
.defaultValue(0)
307307
.name("global-debug")
308308
.validator(value -> (value < 0 || value > 3)
309-
? Try.failure(new MultiverseException("Debug level must be between 0 and 3.", null))
309+
? Try.failure(new MultiverseException("Debug level must be between 0 and 3."))
310310
: Try.success(null))
311311
.onSetValue((oldValue, newValue) -> {
312312
int level = Logging.getDebugLevel();
@@ -317,6 +317,13 @@ private <N extends Node> N node(N node) {
317317
})
318318
.build());
319319

320+
final ConfigNode<Boolean> DEBUG_PERMISSIONS = node(ConfigNode.builder("misc.debug-permissions", Boolean.class)
321+
.comment("Sets whether console will log every permission check done by all multiverse plugins.")
322+
.comment("This will only work if the above 'global-debug' is set to 1 or more.")
323+
.defaultValue(false)
324+
.name("debug-permissions")
325+
.build());
326+
320327
final ConfigNode<Boolean> SILENT_START = node(ConfigNode.builder("misc.silent-start", Boolean.class)
321328
.comment("")
322329
.comment("If true, the startup console messages will no longer show.")

src/main/java/org/mvplugins/multiverse/core/permissions/CorePermissionsChecker.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,34 @@ public boolean hasAnyTeleportPermission(CommandSender sender) {
127127
return false;
128128
}
129129

130-
private String concatPermission(String permission, String... child) {
130+
/**
131+
* Joins permissions with a dot.
132+
*
133+
* @param permission The permission
134+
* @param child The string(s) to join
135+
* @return The newly joined permission node.
136+
*/
137+
public String concatPermission(String permission, String... child) {
131138
return permission + "." + String.join(".", child);
132139
}
133140

134-
private boolean hasPermission(CommandSender sender, String permission) {
141+
/**
142+
* Check and log if the sender has the permission.
143+
*
144+
* @param sender The sender
145+
* @param permission The permission
146+
* @return True if the sender has the permission, else false.
147+
*/
148+
public boolean hasPermission(CommandSender sender, String permission) {
135149
if (sender.hasPermission(permission)) {
136-
Logging.finer("Checking to see if sender [%s] has permission [%s]... YES", sender.getName(), permission);
150+
if (config.getDebugPermissions()) {
151+
Logging.finer("Checking sender [%s] has permission [%s] : YES", sender.getName(), permission);
152+
}
137153
return true;
138154
}
139-
Logging.finer("Checking to see if sender [%s] has permission [%s]... NO", sender.getName(), permission);
155+
if (config.getDebugPermissions()) {
156+
Logging.finer("Checking sender [%s] has permission [%s] : NO", sender.getName(), permission);
157+
}
140158
return false;
141159
}
142160
}

0 commit comments

Comments
 (0)