From b35f52ecf281b07fa8e681f75834f147ed365c2a Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Fri, 23 Aug 2024 18:28:04 -0400 Subject: [PATCH] added toggle for old crate opening permission system --- .../crazycrates/api/builders/CrateBuilder.java | 7 ++++++- .../crazycrates/config/impl/ConfigKeys.java | 14 ++++++++++++++ .../listeners/crates/CrateOpenListener.java | 5 ++++- .../crazycrates/support/MetricsWrapper.java | 7 +++++++ .../crazycrates/tasks/crates/CrateManager.java | 16 ++++++++++------ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/badbones69/crazycrates/api/builders/CrateBuilder.java b/src/main/java/com/badbones69/crazycrates/api/builders/CrateBuilder.java index 510e04285..30986b477 100644 --- a/src/main/java/com/badbones69/crazycrates/api/builders/CrateBuilder.java +++ b/src/main/java/com/badbones69/crazycrates/api/builders/CrateBuilder.java @@ -1,8 +1,11 @@ package com.badbones69.crazycrates.api.builders; +import ch.jalu.configme.SettingsManager; import com.badbones69.crazycrates.api.builders.types.CratePrizeMenu; import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.api.objects.Tier; +import com.badbones69.crazycrates.config.ConfigManager; +import com.badbones69.crazycrates.config.impl.ConfigKeys; import com.badbones69.crazycrates.tasks.crates.CrateManager; import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; import com.badbones69.crazycrates.tasks.crates.effects.SoundEffect; @@ -327,6 +330,8 @@ public void setCustomGlassPane(final int slot) { return MiscUtils.getRandomPaneColor().setDisplayName(" ").getStack(); } + private final SettingsManager config = ConfigManager.getConfig(); + /** * Calls the crate open event and returns true/false if successful or not. * @@ -342,7 +347,7 @@ public final boolean isCrateEventValid(@NotNull final KeyType keyType, final boo if (MiscUtils.isLogging()) { final String fileName = crate.getFileName(); - if (this.player.hasPermission("crazycrates.deny.open." + fileName)) { + if (this.player.hasPermission(this.config.getProperty(ConfigKeys.use_old_permission_system) ? "crazycrates.open." + fileName : "crazycrates.deny.open." + fileName)) { this.plugin.getComponentLogger().warn("{} could not open {} due to having the permission preventing them from opening the crate.", this.player.getName(), fileName); } else { this.plugin.getComponentLogger().warn("{} could not open {} due to no valid prizes being found which led to the event being cancelled.", this.player.getName(), fileName); diff --git a/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java b/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java index 7d908c4a5..fcca3b24a 100644 --- a/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java +++ b/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java @@ -91,6 +91,20 @@ public void registerComments(CommentsConfiguration conf) { }) public static final Property item_editor_toggle = newProperty("root.use-old-editor", false); + @Comment({ + "A recent change to permissions related to opening crates was made", + "The way I assumed wildcard permissions worked isn't how they worked", + "The superperms system for wildcards is stupid... but I digress", + "", + "It feels right to make a toggle for it regardless.", + "", + "true -> crazycrates.open.", + "false -> crazycrates.deny.open.", + "", + "Eventually, one of these options will be either removed or kept." + }) + public static final Property use_old_permission_system = newProperty("root.use-old-permission-system", false); + @Comment({ "This option will tell the plugin to send all messages as action bars or messages in chat.", "", diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java index 226d6f6c0..17b895698 100644 --- a/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/CrateOpenListener.java @@ -1,5 +1,6 @@ package com.badbones69.crazycrates.listeners.crates; +import ch.jalu.configme.SettingsManager; import com.badbones69.crazycrates.CrazyCrates; import com.badbones69.crazycrates.config.ConfigManager; import com.badbones69.crazycrates.config.impl.ConfigKeys; @@ -29,6 +30,8 @@ public class CrateOpenListener implements Listener { private @NotNull final BukkitUserManager userManager = this.plugin.getUserManager(); + private final SettingsManager config = ConfigManager.getConfig(); + @EventHandler public void onCrateOpen(CrateOpenEvent event) { final Player player = event.getPlayer(); @@ -50,7 +53,7 @@ public void onCrateOpen(CrateOpenEvent event) { } } - if (player.hasPermission("crazycrates.deny.open." + fileName)) { + if (player.hasPermission(this.config.getProperty(ConfigKeys.use_old_permission_system) ? "crazycrates.open." + fileName : "crazycrates.deny.open." + fileName)) { Messages.no_crate_permission.sendMessage(player, "{crate}", fancyName); this.crateManager.removePlayerFromOpeningList(player); diff --git a/src/main/java/com/badbones69/crazycrates/support/MetricsWrapper.java b/src/main/java/com/badbones69/crazycrates/support/MetricsWrapper.java index db5f5b0d3..3208bafdf 100644 --- a/src/main/java/com/badbones69/crazycrates/support/MetricsWrapper.java +++ b/src/main/java/com/badbones69/crazycrates/support/MetricsWrapper.java @@ -1,7 +1,10 @@ package com.badbones69.crazycrates.support; +import ch.jalu.configme.SettingsManager; import com.badbones69.crazycrates.CrazyCrates; import com.badbones69.crazycrates.api.objects.Crate; +import com.badbones69.crazycrates.config.ConfigManager; +import com.badbones69.crazycrates.config.impl.ConfigKeys; import com.badbones69.crazycrates.tasks.crates.CrateManager; import com.ryderbelserion.vital.paper.api.bStats; import us.crazycrew.crazycrates.api.enums.types.CrateType; @@ -12,6 +15,8 @@ public class MetricsWrapper extends bStats { private final CrateManager crateManager; + private final SettingsManager config = ConfigManager.getConfig(); + /** * Creates a new Metrics instance. * @@ -38,5 +43,7 @@ public void start() { addCustomChart(chart); }); + + addCustomChart(new SimplePie("use_old_permission_system", () -> String.valueOf(this.config.getProperty(ConfigKeys.use_old_permission_system)))); } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java index 6d8948d33..50560d323 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java @@ -251,6 +251,8 @@ public List getCrateNames() { return this.plugin.getInstance().getCrateFiles(); } + private final SettingsManager config = ConfigManager.getConfig(); + /** * Loads the crates. */ @@ -404,12 +406,14 @@ public void loadCrates() { final PluginManager server = this.plugin.getServer().getPluginManager(); - if (server.getPermission("crazycrates.deny.open." + crateName) == null) { - Permission permission = new Permission( - "crazycrates.deny.open." + crateName, - "Prevents you from opening " + crateName, - PermissionDefault.FALSE - ); + final boolean isOldSystemEnabled = this.config.getProperty(ConfigKeys.use_old_permission_system); + + final String node = isOldSystemEnabled ? "crazycrates.open." + crateName : "crazycrates.deny.open." + crateName; + final String description = isOldSystemEnabled ? "Lets you open " + crateName : "Prevents you from opening " + crateName; + final PermissionDefault permissionDefault = isOldSystemEnabled ? PermissionDefault.TRUE : PermissionDefault.FALSE; + + if (server.getPermission(node) == null) { + final Permission permission = new Permission(node, description, permissionDefault); server.addPermission(permission); }