Skip to content

Commit

Permalink
added toggle for old crate opening permission system
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Aug 23, 2024
1 parent 5a18a8c commit b35f52e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
*
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ public void registerComments(CommentsConfiguration conf) {
})
public static final Property<Boolean> 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.<crate-name>",
"false -> crazycrates.deny.open.<crate_name>",
"",
"Eventually, one of these options will be either removed or kept."
})
public static final Property<Boolean> 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.",
"",
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +15,8 @@ public class MetricsWrapper extends bStats {

private final CrateManager crateManager;

private final SettingsManager config = ConfigManager.getConfig();

/**
* Creates a new Metrics instance.
*
Expand All @@ -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))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ public List<String> getCrateNames() {
return this.plugin.getInstance().getCrateFiles();
}

private final SettingsManager config = ConfigManager.getConfig();

/**
* Loads the crates.
*/
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b35f52e

Please sign in to comment.