Skip to content

Commit

Permalink
Replace crate open permission with deny open permission (#763)
Browse files Browse the repository at this point in the history
* Deny Open Perm

Changed crate open permission over to being a deny open permission.
This change should simplify how crate permissions are handled by reducing it to a single permission per crate that is more self-explanatory.

* update permission registration on startup

* update straggling permission check to reflect new change

* update default message for no permission to use crate

* don't check for lowercase permission

the check should be case-sensitive

* send more verbose messages to console if the CrateOpenEvent is cancelled.

* remove : from logging message

* add player name to logging message

---------

Signed-off-by: Ryder Belserion <[email protected]>
Co-authored-by: TrueDarkLord <[email protected]>
  • Loading branch information
ryderbelserion and TrueDarkLord authored Jul 25, 2024
1 parent 3fb4bc4 commit 788d71a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
- Messages that send a list to chat will by default never be sent to actionbar as it would not look pretty.

### Changes:
- If a message in the `messages.yml` is blank, it will not send the message.
- The permission check for whether a player can open a crate has been changed.
- `crazycrates.open.<crate_name>` is now `crazycrates.deny.open.<crate_name>`
- The crate name is case-sensitive, so it must match exactly the crate name in the `crates` folder
- If the file name is CrateBeans.yml, it must be `crazycrates.deny.open.CrateBeans`
- If a message in the `messages.yml` is blank, it will not send the message.
- Update default message for `crates.crate-no-permission`
- Update some comments because of grammar.
- Update logger message when the `CrateOpenEvent` is cancelled to be more verbose.
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,11 @@ public final boolean isCrateEventValid(@NotNull final KeyType keyType, final boo

if (event.isCancelled()) {
if (MiscUtils.isLogging()) {
List.of(
"Crate " + this.crate.getName() + " event has been cancelled.",
"A few reasons for why this happened can be found below",
"",
" 1) No valid prizes can be found, Likely a yaml issue.",
" 2) The player does not have the permission to open the crate."
).forEach(this.plugin.getComponentLogger()::warn);
if (this.player.hasPermission("crazycrates.deny.open." + this.crate.getName())) {
this.plugin.getComponentLogger().warn("{} could not open {} due to having the permission preventing them from opening the crate.", this.player.getName(), this.crate.getName());
} 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(), this.crate.getName());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void registerComments(CommentsConfiguration conf) {
public static final Property<String> cannot_set_type = newProperty("crates.cannot-set-menu-type", "{prefix}<red>You cannot set the Menu to a block because the crate menu is disabled");

@Comment("A list of available placeholders: {prefix}, {crate}")
public static final Property<String> no_crate_permission = newProperty("crates.crate-no-permission", "{prefix}<red>You do not have permission to use that {crate}.");
public static final Property<String> no_crate_permission = newProperty("crates.crate-no-permission", "{prefix}<red>You do not have permission to use {crate}.");

@Comment("A list of available placeholders: {prefix}, {crate}")
public static final Property<String> preview_disabled = newProperty("crates.crate-preview-disabled", "{prefix}<red>The preview for <gold>{crate} <red>is currently disabled.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void onCrateOpen(CrateOpenEvent event) {
}
}

if (!player.hasPermission("crazycrates.open." + crate.getName()) || !player.hasPermission("crazycrates.open." + crate.getName().toLowerCase())) {
if (player.hasPermission("crazycrates.deny.open." + crate.getName())) {
Messages.no_crate_permission.sendMessage(player, "{crate}", crate.getName());

this.crateManager.removePlayerFromOpeningList(player);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.Nullable;
import us.crazycrew.crazycrates.api.enums.types.CrateType;
Expand Down Expand Up @@ -383,16 +384,16 @@ public void loadCrates() {
file.getStringList("Crate.Hologram.Message"));
addCrate(new Crate(crateName, previewName, crateType, getKey(file), file.getString("Crate.PhysicalKey.Name", "Crate.PhysicalKey.Name is missing from " + crateName + ".yml"), prizes, file, newPlayersKeys, tiers, maxMassOpen, requiredKeys, prizeMessage, prizeCommands, holo));

final Permission doesExist = this.plugin.getServer().getPluginManager().getPermission("crazycrates.open." + crateName);
final PluginManager server = this.plugin.getServer().getPluginManager();

if (doesExist == null) {
if (server.getPermission("crazycrates.deny.open." + crateName) == null) {
Permission permission = new Permission(
"crazycrates.open." + crateName,
"crazycrates.deny.open." + crateName,
"Allows you to open " + crateName,
PermissionDefault.TRUE
PermissionDefault.FALSE
);

this.plugin.getServer().getPluginManager().addPermission(permission);
server.addPermission(permission);
}
} catch (Exception exception) {
this.brokeCrates.add(crateName);
Expand Down

0 comments on commit 788d71a

Please sign in to comment.