From c5a964337a2ecca94a5aab0a463beb843dcba7dc Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sun, 14 Sep 2025 14:42:26 +0200 Subject: [PATCH] Cleans permissions, and reduces redundancy in permission checking code --- .../stargate/command/CommandConfig.java | 4 +- .../stargate/command/CommandReload.java | 4 +- .../command/StarGateTabCompleter.java | 6 +- .../knarcraft/stargate/config/Permission.java | 68 ++++++++++++ .../stargate/config/addons/EconomyConfig.java | 13 ++- .../listener/PlayerEventListener.java | 5 +- .../stargate/portal/PortalHandler.java | 3 +- .../portal/property/PortalOption.java | 35 +++--- .../portal/property/PortalOptions.java | 4 +- .../stargate/utility/EconomyHelper.java | 3 +- .../stargate/utility/PermissionHelper.java | 103 +++++++++--------- src/main/resources/plugin.yml | 4 +- 12 files changed, 165 insertions(+), 87 deletions(-) create mode 100644 src/main/java/net/knarcraft/stargate/config/Permission.java diff --git a/src/main/java/net/knarcraft/stargate/command/CommandConfig.java b/src/main/java/net/knarcraft/stargate/command/CommandConfig.java index 58f4e63..9aac7b8 100644 --- a/src/main/java/net/knarcraft/stargate/command/CommandConfig.java +++ b/src/main/java/net/knarcraft/stargate/command/CommandConfig.java @@ -4,12 +4,14 @@ import net.knarcraft.stargate.Stargate; import net.knarcraft.stargate.config.ConfigOption; import net.knarcraft.stargate.config.ConfigTag; import net.knarcraft.stargate.config.OptionDataType; +import net.knarcraft.stargate.config.Permission; import net.knarcraft.stargate.config.addons.DynmapManager; import net.knarcraft.stargate.config.formatting.Message; import net.knarcraft.stargate.config.formatting.SGFormatBuilder; import net.knarcraft.stargate.portal.Portal; import net.knarcraft.stargate.portal.PortalRegistry; import net.knarcraft.stargate.portal.PortalSignDrawer; +import net.knarcraft.stargate.utility.PermissionHelper; import net.md_5.bungee.api.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; @@ -32,7 +34,7 @@ public class CommandConfig implements CommandExecutor { public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { if (commandSender instanceof Player player) { - if (!player.hasPermission("stargate.admin.config")) { + if (!PermissionHelper.hasPermission(player, Permission.CONFIG)) { new SGFormatBuilder("Permission Denied").error(commandSender); return true; } diff --git a/src/main/java/net/knarcraft/stargate/command/CommandReload.java b/src/main/java/net/knarcraft/stargate/command/CommandReload.java index 296ed6a..740f301 100644 --- a/src/main/java/net/knarcraft/stargate/command/CommandReload.java +++ b/src/main/java/net/knarcraft/stargate/command/CommandReload.java @@ -1,7 +1,9 @@ package net.knarcraft.stargate.command; import net.knarcraft.stargate.Stargate; +import net.knarcraft.stargate.config.Permission; import net.knarcraft.stargate.config.formatting.SGFormatBuilder; +import net.knarcraft.stargate.utility.PermissionHelper; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -17,7 +19,7 @@ public class CommandReload implements CommandExecutor { public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { if (commandSender instanceof Player player) { - if (!player.hasPermission("stargate.admin.reload")) { + if (!PermissionHelper.hasPermission(player, Permission.RELOAD)) { new SGFormatBuilder("Permission Denied").error(commandSender); return true; } diff --git a/src/main/java/net/knarcraft/stargate/command/StarGateTabCompleter.java b/src/main/java/net/knarcraft/stargate/command/StarGateTabCompleter.java index 25c1d1d..4a2fd10 100644 --- a/src/main/java/net/knarcraft/stargate/command/StarGateTabCompleter.java +++ b/src/main/java/net/knarcraft/stargate/command/StarGateTabCompleter.java @@ -1,5 +1,7 @@ package net.knarcraft.stargate.command; +import net.knarcraft.stargate.config.Permission; +import net.knarcraft.stargate.utility.PermissionHelper; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -47,10 +49,10 @@ public class StarGateTabCompleter implements TabCompleter { private List getAvailableCommands(@NotNull CommandSender commandSender) { List commands = new ArrayList<>(); commands.add("about"); - if (!(commandSender instanceof Player player) || player.hasPermission("stargate.admin.reload")) { + if (!(commandSender instanceof Player player) || PermissionHelper.hasPermission(player, Permission.RELOAD)) { commands.add("reload"); } - if (!(commandSender instanceof Player player) || player.hasPermission("stargate.admin.config")) { + if (!(commandSender instanceof Player player) || PermissionHelper.hasPermission(player, Permission.CONFIG)) { commands.add("config"); } return commands; diff --git a/src/main/java/net/knarcraft/stargate/config/Permission.java b/src/main/java/net/knarcraft/stargate/config/Permission.java new file mode 100644 index 0000000..2d3f6c2 --- /dev/null +++ b/src/main/java/net/knarcraft/stargate/config/Permission.java @@ -0,0 +1,68 @@ +package net.knarcraft.stargate.config; + +import org.jetbrains.annotations.NotNull; + +/** + * A representation of all Stargate permissions + */ +public enum Permission { + + ADMIN("admin"), + CONFIG("admin.config"), + RELOAD("admin.reload"), + CREATE_BUNGEE("admin.bungee"), + DYE_SIGN("admin.dye"), + + SEE_HIDDEN("admin.hidden"), + USE_PRIVATE("admin.private"), + + FREE_USAGE("free.use"), + FREE_DESTRUCTION("free.destroy"), + FREE_CREATION("free.create"), + + ACCESS_SERVER("server"), + ACCESS_NETWORK("network"), + ACCESS_WORLD("world"), + + CREATE_GATE("create.gate"), + CREATE_NETWORK("create.network"), + CREATE_PERSONAL("create.personal"), + + DESTROY_NETWORK("destroy.network"), + DESTROY_PERSONAL("destroy.personal"), + + OPTION_HIDDEN("option.hidden"), + OPTION_ALWAYS_ON("option.alwayson"), + OPTIONS_PRIVATE("options.private"), + OPTIONS_FREE("options.free"), + OPTIONS_BACKWARDS("options.backwards"), + OPTIONS_SHOW("options.show"), + OPTIONS_NO_NETWORK("options.nonetwork"), + OPTIONS_RANDOM("options.random"), + OPTIONS_BUNGEE("options.bungee"), + OPTIONS_QUIET("options.quiet"), + OPTIONS_INVISIBLE("options.invisible"), + ; + + private final String node; + + /** + * Instantiates a new permission + * + * @param node

The permission node

+ */ + Permission(@NotNull String node) { + this.node = node; + } + + /** + * Gets the permission node of this permission + * + * @return

The node of this permission

+ */ + @NotNull + public String getNode() { + return "stargate." + this.node; + } + +} diff --git a/src/main/java/net/knarcraft/stargate/config/addons/EconomyConfig.java b/src/main/java/net/knarcraft/stargate/config/addons/EconomyConfig.java index 9bbc356..6c94ff4 100644 --- a/src/main/java/net/knarcraft/stargate/config/addons/EconomyConfig.java +++ b/src/main/java/net/knarcraft/stargate/config/addons/EconomyConfig.java @@ -2,6 +2,7 @@ package net.knarcraft.stargate.config.addons; import net.knarcraft.stargate.Stargate; import net.knarcraft.stargate.config.ConfigOption; +import net.knarcraft.stargate.config.Permission; import net.knarcraft.stargate.config.formatting.Message; import net.knarcraft.stargate.config.formatting.SGFormatBuilder; import net.knarcraft.stargate.portal.PortalSignDrawer; @@ -221,7 +222,7 @@ public final class EconomyConfig { * @return

The cost of creating the gate

*/ public int getCreateCost(@NotNull Player player, @NotNull Gate gate) { - if (isFree(player, "create")) { + if (isFree(player, Permission.FREE_CREATION)) { return 0; } else { return gate.getCreateCost(); @@ -236,7 +237,7 @@ public final class EconomyConfig { * @return

The cost of destroying the gate

*/ public int getDestroyCost(@NotNull Player player, @NotNull Gate gate) { - if (isFree(player, "destroy")) { + if (isFree(player, Permission.FREE_DESTRUCTION)) { return 0; } else { return gate.getDestroyCost(); @@ -246,12 +247,12 @@ public final class EconomyConfig { /** * Determines if a player can do a gate action for free * - * @param player

The player to check

- * @param permissionNode

The free.permissionNode necessary to allow free gate {action}

+ * @param player

The player to check

+ * @param permission

The permission necessary to allow free gate {action}

* @return

*/ - private boolean isFree(@NotNull Player player, @NotNull String permissionNode) { - return !useEconomy() || PermissionHelper.hasPermission(player, "stargate.free." + permissionNode); + private boolean isFree(@NotNull Player player, @NotNull Permission permission) { + return !useEconomy() || PermissionHelper.hasPermission(player, permission.getNode()); } } diff --git a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java index 2a1dbb8..922bd60 100644 --- a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java @@ -3,6 +3,7 @@ package net.knarcraft.stargate.listener; import net.knarcraft.knarlib.formatting.FormatBuilder; import net.knarcraft.knarlib.util.UpdateChecker; import net.knarcraft.stargate.Stargate; +import net.knarcraft.stargate.config.Permission; import net.knarcraft.stargate.config.formatting.Message; import net.knarcraft.stargate.config.formatting.SGFormatBuilder; import net.knarcraft.stargate.portal.Portal; @@ -53,7 +54,7 @@ public class PlayerEventListener implements Listener { //Notify joining admins about the available update String availableUpdate = Stargate.getUpdateAvailable(); if (availableUpdate != null && Stargate.getStargateConfig().alertAdminsAboutUpdates() && - player.hasPermission("stargate.admin")) { + PermissionHelper.hasPermission(player, Permission.ADMIN)) { String updateMessage = UpdateChecker.getUpdateAvailableString(availableUpdate, Stargate.getPluginVersion()); new SGFormatBuilder(updateMessage).error(player); } @@ -162,7 +163,7 @@ public class PlayerEventListener implements Listener { private boolean dyeSign(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull Portal portal) { EquipmentSlot hand = event.getHand(); // Check if the player is allowed to dye the sign - if (hand == null || (!PermissionHelper.hasPermission(player, "stargate.admin.dye") && + if (hand == null || (!PermissionHelper.hasPermission(player, Permission.DYE_SIGN) && !portal.isOwner(player))) { return false; } diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java index 4bd6102..e5bebf9 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalHandler.java @@ -1,6 +1,7 @@ package net.knarcraft.stargate.portal; import net.knarcraft.stargate.Stargate; +import net.knarcraft.stargate.config.Permission; import net.knarcraft.stargate.config.formatting.Message; import net.knarcraft.stargate.config.formatting.SGFormatBuilder; import net.knarcraft.stargate.config.material.BukkitTagSpecifier; @@ -148,7 +149,7 @@ public class PortalHandler { if (!portalOptions.get(PortalOption.BUNGEE)) { return true; } - if (!PermissionHelper.hasPermission(player, "stargate.admin.bungee")) { + if (!PermissionHelper.hasPermission(player, Permission.CREATE_BUNGEE)) { new SGFormatBuilder(Message.BUNGEE_CREATION_DENIED).error(player); return false; } else if (!Stargate.getGateConfig().enableBungee()) { diff --git a/src/main/java/net/knarcraft/stargate/portal/property/PortalOption.java b/src/main/java/net/knarcraft/stargate/portal/property/PortalOption.java index c3fe5cf..6c93769 100644 --- a/src/main/java/net/knarcraft/stargate/portal/property/PortalOption.java +++ b/src/main/java/net/knarcraft/stargate/portal/property/PortalOption.java @@ -1,5 +1,6 @@ package net.knarcraft.stargate.portal.property; +import net.knarcraft.stargate.config.Permission; import org.jetbrains.annotations.NotNull; /** @@ -10,71 +11,71 @@ public enum PortalOption { /** * This option allows a portal to be hidden from others */ - HIDDEN('h', "hidden", 11), + HIDDEN('h', Permission.OPTION_HIDDEN, 11), /** * This option allows a portal that's always on and does not need to be activated or opened each time */ - ALWAYS_ON('a', "alwayson", 12), + ALWAYS_ON('a', Permission.OPTION_ALWAYS_ON, 12), /** * This option allows a portal that's private to the stargate's owner */ - PRIVATE('p', "private", 13), + PRIVATE('p', Permission.OPTIONS_PRIVATE, 13), /** * This option allows a portal that's free even if stargates usually are not */ - FREE('f', "free", 15), + FREE('f', Permission.OPTIONS_FREE, 15), /** * This option allows a portal where players exit through the back of the portal */ - BACKWARDS('b', "backwards", 16), + BACKWARDS('b', Permission.OPTIONS_BACKWARDS, 16), /** * This option shows the gate in the network list even if it's always on */ - SHOW('s', "show", 17), + SHOW('s', Permission.OPTIONS_SHOW, 17), /** * This option hides the network name on the sign */ - NO_NETWORK('n', "nonetwork", 18), + NO_NETWORK('n', Permission.OPTIONS_NO_NETWORK, 18), /** * This option allows a portal where players teleport to a random exit portal in the network */ - RANDOM('r', "random", 19), + RANDOM('r', Permission.OPTIONS_RANDOM, 19), /** * This option allows a portal to teleport to another server connected through BungeeCord */ - BUNGEE('u', "bungee", 20), + BUNGEE('u', Permission.OPTIONS_BUNGEE, 20), /** * This option allows a portal which does not display a teleportation message, for better immersion */ - QUIET('q', "quiet", 21), + QUIET('q', Permission.OPTIONS_QUIET, 21), /** * This option causes a fixed portal's sign to be removed after creation */ - NO_SIGN('v', "nosign", 22); + INVISIBLE('v', Permission.OPTIONS_INVISIBLE, 22); private final char characterRepresentation; - private final String permissionString; + private final Permission permission; private final int saveIndex; /** * Instantiates a new portal options * * @param characterRepresentation

The character representation used on the sign to allow this option

- * @param permissionString

The permission necessary to use this option

+ * @param permission

The permission necessary to use this option

*/ - PortalOption(final char characterRepresentation, @NotNull String permissionString, int saveIndex) { + PortalOption(final char characterRepresentation, @NotNull Permission permission, int saveIndex) { this.characterRepresentation = characterRepresentation; - this.permissionString = "stargate.option." + permissionString; + this.permission = permission; this.saveIndex = saveIndex; } @@ -93,8 +94,8 @@ public enum PortalOption { * @return

The permission necessary for this option

*/ @NotNull - public String getPermissionString() { - return this.permissionString; + public Permission getPermission() { + return this.permission; } /** diff --git a/src/main/java/net/knarcraft/stargate/portal/property/PortalOptions.java b/src/main/java/net/knarcraft/stargate/portal/property/PortalOptions.java index 570b74d..341b528 100644 --- a/src/main/java/net/knarcraft/stargate/portal/property/PortalOptions.java +++ b/src/main/java/net/knarcraft/stargate/portal/property/PortalOptions.java @@ -35,7 +35,7 @@ public class PortalOptions { } if (this.hasNoSign() && !this.isFixed) { - this.options.put(PortalOption.NO_SIGN, false); + this.options.put(PortalOption.INVISIBLE, false); Stargate.debug("PortalOptions", "Gate marked with no sign, but not fixed. Setting NoSign = false"); } } @@ -191,7 +191,7 @@ public class PortalOptions { * @return

Whether this portal has no sign

*/ public boolean hasNoSign() { - return this.options.get(PortalOption.NO_SIGN); + return this.options.get(PortalOption.INVISIBLE); } } diff --git a/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java b/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java index 42dfa8a..08bb104 100644 --- a/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/EconomyHelper.java @@ -2,6 +2,7 @@ package net.knarcraft.stargate.utility; import net.knarcraft.knarlib.formatting.FormatBuilder; import net.knarcraft.stargate.Stargate; +import net.knarcraft.stargate.config.Permission; import net.knarcraft.stargate.config.addons.EconomyConfig; import net.knarcraft.stargate.config.formatting.Message; import net.knarcraft.stargate.config.formatting.SGFormatBuilder; @@ -142,7 +143,7 @@ public final class EconomyHelper { return 0; } //Player gets free gate use - if (PermissionHelper.hasPermission(player, "stargate.free.use")) { + if (PermissionHelper.hasPermission(player, Permission.FREE_USAGE)) { return 0; } diff --git a/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java b/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java index 2afac41..9e8573c 100644 --- a/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java @@ -1,6 +1,7 @@ package net.knarcraft.stargate.utility; import net.knarcraft.stargate.Stargate; +import net.knarcraft.stargate.config.Permission; import net.knarcraft.stargate.config.formatting.Message; import net.knarcraft.stargate.config.formatting.SGFormatBuilder; import net.knarcraft.stargate.event.StargateAccessEvent; @@ -172,6 +173,19 @@ public final class PermissionHelper { return player.hasPermission(permission); } + /** + * Checks whether a player has the given permission + * + *

This is the same as player.hasPermission(), but this function allows for printing permission debugging info.

+ * + * @param player

The player to check

+ * @param permission

The permission to check

+ * @return

True if the player has the permission

+ */ + public static boolean hasPermission(@NotNull Player player, @NotNull Permission permission) { + return hasPermission(player, permission.getNode()); + } + /** * Check if a player has been given a permission implicitly * @@ -183,13 +197,14 @@ public final class PermissionHelper { * @return

True if the player has the permission implicitly or explicitly

*/ public static boolean hasPermissionImplicit(@NotNull Player player, @NotNull String permission) { + boolean debug = Stargate.getStargateConfig().isPermissionDebuggingEnabled(); if (!player.isPermissionSet(permission)) { - if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) { + if (debug) { Stargate.debug("hasPermissionImplicit::Permission", permission + " => implicitly true"); } return true; } - if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) { + if (debug) { Stargate.debug("hasPermissionImplicit::Permission", permission + " => " + player.hasPermission(permission)); } @@ -204,13 +219,7 @@ public final class PermissionHelper { * @return

False if the player should be allowed to access the world

*/ public static boolean cannotAccessWorld(@NotNull Player player, @NotNull String world) { - //The player can access all worlds - if (hasPermission(player, "stargate.world")) { - //Check if the world permission has been explicitly denied - return !hasPermissionImplicit(player, "stargate.world." + world); - } - //The player can access the destination world - return !hasPermission(player, "stargate.world." + world); + return hasPermission(player, Permission.ACCESS_WORLD, world); } /** @@ -221,21 +230,16 @@ public final class PermissionHelper { * @return

True if the player is denied from accessing the network

*/ public static boolean cannotAccessNetwork(@NotNull Player player, @NotNull String network) { - //The player can access all networks - if (hasPermission(player, "stargate.network")) { - //Check if the world permission has been explicitly denied - return !hasPermissionImplicit(player, "stargate.network." + network); - } - //Check if the player can access this network - if (hasPermission(player, "stargate.network." + network)) { + if (hasPermission(player, Permission.ACCESS_NETWORK, network)) { return false; } + //Is able to create personal gates (Assumption is made they can also access them) String playerName = player.getName(); if (playerName.length() > getMaxNameNetworkLength()) { playerName = playerName.substring(0, getMaxNameNetworkLength()); } - return !network.equals(playerName) || !hasPermission(player, "stargate.create.personal"); + return !network.equals(playerName) || !hasPermission(player, Permission.CREATE_PERSONAL); } /** @@ -246,13 +250,7 @@ public final class PermissionHelper { * @return

True if the player is allowed to access the given server

*/ public static boolean canAccessServer(@NotNull Player player, @NotNull String server) { - //The player can access all servers - if (hasPermission(player, "stargate.server")) { - //Check if the server permission has been explicitly denied - return hasPermissionImplicit(player, "stargate.server." + server); - } - //The player can access the destination server - return hasPermission(player, "stargate.server." + server); + return hasPermission(player, Permission.ACCESS_SERVER, server); } /** @@ -269,7 +267,7 @@ public final class PermissionHelper { return true; } //Player can use this portal for free - if (hasPermission(player, "stargate.free.use")) { + if (hasPermission(player, Permission.FREE_USAGE)) { return true; } //Don't charge for free destinations unless specified in the config @@ -291,7 +289,7 @@ public final class PermissionHelper { return true; } //The player can see all hidden portals - if (hasPermission(player, "stargate.admin.hidden")) { + if (hasPermission(player, Permission.SEE_HIDDEN)) { return true; } //The player is the owner of the portal @@ -311,7 +309,7 @@ public final class PermissionHelper { return true; } //The player is an admin with the ability to use private gates - return hasPermission(player, "stargate.admin.private"); + return hasPermission(player, Permission.USE_PRIVATE); } /** @@ -322,7 +320,7 @@ public final class PermissionHelper { * @return

True if the player is allowed to create a portal with the given option

*/ public static boolean canUseOption(@NotNull Player player, @NotNull PortalOption option) { - return hasPermission(player, option.getPermissionString()); + return hasPermission(player, option.getPermission()); } /** @@ -333,13 +331,7 @@ public final class PermissionHelper { * @return

True if the player is allowed to create the new gate

*/ public static boolean canCreateNetworkGate(@NotNull Player player, @NotNull String network) { - //Check if the player is allowed to create a portal on any network - if (hasPermission(player, "stargate.create.network")) { - //Check if the network has been explicitly denied - return hasPermissionImplicit(player, "stargate.create.network." + network); - } - //Check if the player is allowed to create on this specific network - return hasPermission(player, "stargate.create.network." + network); + return hasPermission(player, Permission.CREATE_NETWORK, network); } /** @@ -349,7 +341,7 @@ public final class PermissionHelper { * @return

True if the player is allowed

*/ public static boolean canCreatePersonalPortal(@NotNull Player player) { - return hasPermission(player, "stargate.create.personal"); + return hasPermission(player, Permission.CREATE_PERSONAL); } /** @@ -360,13 +352,7 @@ public final class PermissionHelper { * @return

True if the player is allowed to create a portal with the given gate layout

*/ public static boolean canCreatePortal(@NotNull Player player, @NotNull String gate) { - //Check if the player is allowed to create all gates - if (hasPermission(player, "stargate.create.gate")) { - //Check if the gate type has been explicitly denied - return hasPermissionImplicit(player, "stargate.create.gate." + gate); - } - //Check if the player can create the specific gate type - return hasPermission(player, "stargate.create.gate." + gate); + return hasPermission(player, Permission.CREATE_GATE, gate); } /** @@ -381,20 +367,14 @@ public final class PermissionHelper { //Use a special check for bungee portals if (portal.getOptions().isBungee()) { - return hasPermission(player, "stargate.admin.bungee"); + return hasPermission(player, Permission.CREATE_BUNGEE); } - //Check if the player is allowed to destroy on all networks - if (hasPermission(player, "stargate.destroy.network")) { - //Check if the network has been explicitly denied - return hasPermissionImplicit(player, "stargate.destroy.network." + network); - } - //Check if the player is allowed to destroy on the network - if (hasPermission(player, "stargate.destroy.network." + network)) { + if (hasPermission(player, Permission.DESTROY_NETWORK, network)) { return true; } //Check if personal portal and if the player is allowed to destroy it - return portal.isOwner(player) && hasPermission(player, "stargate.destroy.personal"); + return portal.isOwner(player) && hasPermission(player, Permission.DESTROY_PERSONAL); } /** @@ -448,4 +428,23 @@ public final class PermissionHelper { return false; } + /** + * Checks if the given player has a permission for the given value, or has the catch-all permission + * + * @param player

The player trying to create a portal

+ * @param permission

The parent permission to check

+ * @param value

The child node to check

+ * @return

True if the player has the explicit child node, or gets the permission implicitly from the parent

+ */ + private static boolean hasPermission(@NotNull Player player, @NotNull Permission permission, @NotNull String value) { + String fullNode = permission.getNode() + "." + value; + //Check if the player is allowed to create all gates + if (hasPermission(player, permission)) { + //Check if the gate type has been explicitly denied + return hasPermissionImplicit(player, fullNode); + } + //Check if the player can create the specific gate type + return hasPermission(player, fullNode); + } + } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 70bd08d..46578c0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -99,7 +99,7 @@ permissions: stargate.option.nonetwork: true stargate.option.random: true stargate.option.quiet: true - stargate.option.nosign: true + stargate.option.invisible: true stargate.option.hidden: description: Allows the creation of a hidden stargate default: false @@ -127,7 +127,7 @@ permissions: stargate.option.quiet: description: Allows the creation of a stargate which does not output anything to the chat default: false - stargate.option.nosign: + stargate.option.invisible: description: Allows the creation of a stargate which has no sign default: false stargate.admin.hidden: