fix: Resolve issue where permission is not registering

This commit is contained in:
Ben Woo 2023-03-01 15:48:27 +08:00
parent a6eea018ac
commit 913618101a
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
2 changed files with 23 additions and 15 deletions

View File

@ -21,15 +21,15 @@ public class PermissionsRegistrar {
public static void setup() {
worldPermissions = new ArrayList<>() {{
worldAccessPermission = new PrefixPermission("multiverse.access.", "Allows access to a world.");
worldGamemodeBypassPermission = new PrefixPermission("mv.bypass.gamemode.", "Allows bypassing of gamemode restrictions.", PermissionDefault.FALSE);
worldExemptPermission = new PrefixPermission("multiverse.exempt.", "A player who has this does not pay to enter this world.");
worldPlayerLimitBypassPermission = new PrefixPermission("mv.bypass.playerlimit.", "Allows bypassing of player limit restrictions.");
add(worldAccessPermission = new PrefixPermission("multiverse.access.", "Allows access to a world."));
add(worldGamemodeBypassPermission = new PrefixPermission("mv.bypass.gamemode.", "Allows bypassing of gamemode restrictions.", PermissionDefault.FALSE));
add(worldExemptPermission = new PrefixPermission("multiverse.exempt.", "A player who has this does not pay to enter this world."));
add(worldPlayerLimitBypassPermission = new PrefixPermission("mv.bypass.playerlimit.", "Allows bypassing of player limit restrictions."));
}};
destinationPermissions = new ArrayList<>() {{
teleportSelfPermission = new PrefixPermission("multiverse.teleport.self.", "Allows teleporting to a world.");
teleportOtherPermission = new PrefixPermission("multiverse.teleport.other.", "Allows teleporting other players to a world.");
add(teleportSelfPermission = new PrefixPermission("multiverse.teleport.self.", "Allows teleporting to a world."));
add(teleportOtherPermission = new PrefixPermission("multiverse.teleport.other.", "Allows teleporting other players to a world."));
}};
}
@ -57,15 +57,15 @@ public class PermissionsRegistrar {
removeAllPrefixPermissions(destinationPermissions);
}
private static void removePrefixPermissions(List<PrefixPermission> worldPermissions, String name) {
for (PrefixPermission permission : worldPermissions) {
permission.removePermission(name);
private static void registerPrefixPermissionList(List<PrefixPermission> permissions, String permissionSuffix) {
for (PrefixPermission permission : permissions) {
permission.registerPermission(permissionSuffix);
}
}
private static void registerPrefixPermissionList(List<PrefixPermission> permissions, String permissionSuffix) {
for (PrefixPermission permission : permissions) {
permission.registerWildcardPermission();
private static void removePrefixPermissions(List<PrefixPermission> worldPermissions, String name) {
for (PrefixPermission permission : worldPermissions) {
permission.removePermission(name);
}
}

View File

@ -1,5 +1,6 @@
package com.onarandombox.MultiverseCore.utils.permission;
import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.Bukkit;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
@ -26,9 +27,10 @@ public class PrefixPermission {
}
public Permission registerPermission(String permissionSuffix) {
String permissionName = permissionPrefix + permissionSuffix;
String permissionName = getPermissionName(permissionSuffix);
Permission permission = pluginManager.getPermission(permissionName);
if (permission != null) {
Logging.warning("Permission already registered: " + permission.getName());
return permission;
}
@ -38,6 +40,9 @@ public class PrefixPermission {
registerWildcardPermission();
}
permission.addParent(wildcardPermission, true);
pluginManager.recalculatePermissionDefaults(permission);
pluginManager.recalculatePermissionDefaults(wildcardPermission);
Logging.finest("Registered permission: " + permission.getName());
return permission;
}
@ -49,6 +54,7 @@ public class PrefixPermission {
}
wildcardPermission = new Permission(permissionName, description, permissionDefault);
pluginManager.addPermission(wildcardPermission);
pluginManager.recalculatePermissionDefaults(wildcardPermission);
}
public boolean removePermission(String permissionSuffix) {
@ -68,8 +74,10 @@ public class PrefixPermission {
public boolean removeAllPermissions() {
try {
wildcardPermission.getChildren().forEach((child, value) -> pluginManager.removePermission(child));
pluginManager.removePermission(wildcardPermission);
if (wildcardPermission != null) {
wildcardPermission.getChildren().forEach((child, value) -> pluginManager.removePermission(child));
pluginManager.removePermission(wildcardPermission);
}
} catch (IllegalArgumentException e) {
return false;
}