Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common/src/main/java/com/lishid/openinv/util/Permissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public enum Permissions {
SPECTATE_CLICK("spectate.click"),

CONTAINER_ANY("container.any"),
CONTAINER_ANY_USE("container.any.use"),
CONTAINER_SILENT("container.silent"),
CONTAINER_SILENT_USE("container.silent.use"),
SEARCH_INVENTORY("search.inventory"),
SEARCH_CONTAINER("search.container");

Expand All @@ -63,4 +65,9 @@ public boolean hasPermission(@NotNull Permissible permissible) {
return permissible.hasPermission(permission);
}

public boolean hasPermission(@NotNull Permissible permissible, @NotNull Permissions parent) {
if (permissible.hasPermission(permission)) return true;
if (permissible.isPermissionSet(permission) && !permissible.hasPermission(permission)) return false;
return permissible.hasPermission(parent.permission);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't actually notice this at the time, but this doesn't quite do what I had intended here. This effectively does nothing (or wastes CPU time) because of how Bukkit's permissions system works and how the permissions are laid out in our plugin.yml.

If the user has the permission, it might be because it is granted by the parent node or the node directly, but Bukkit calculates it out either way. If they don't have the node, either it is denied or it is not set and the parent is denied/not set as well. In those cases this just adds 2 extra permissions checks that are guaranteed to fail.

My goal was a simple is set or parent is set, because I don't want to allow people to create permissions setups where a player can access the toggle but not access the feature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's true, you're right. I had completely forgotten about that. I'm really sorry for the inconvenience

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ private void onPlayerInteract(@NotNull PlayerInteractEvent event) {

Player player = event.getPlayer();
UUID playerId = player.getUniqueId();
boolean any = Permissions.CONTAINER_ANY.hasPermission(player) && PlayerToggles.any().is(playerId);
boolean any = Permissions.CONTAINER_ANY_USE.hasPermission(player, Permissions.CONTAINER_ANY) && PlayerToggles.any().is(playerId);
boolean needsAny = accessor.getAnySilentContainer().isAnyContainerNeeded(event.getClickedBlock());

if (!any && needsAny) {
return;
}

boolean silent = Permissions.CONTAINER_SILENT.hasPermission(player) && PlayerToggles.silent().is(playerId);
boolean silent = Permissions.CONTAINER_SILENT_USE.hasPermission(player, Permissions.CONTAINER_SILENT) && PlayerToggles.silent().is(playerId);

// If anycontainer or silentcontainer is active
if (any || silent) {
Expand Down
12 changes: 10 additions & 2 deletions plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@ permissions:
# Container features
openinv.container:
children:
openinv.container.any: true
openinv.container.silent: true
openinv.container.any:
children:
openinv.container.any.use: true
openinv.container.any.use:
default: false
openinv.container.silent:
children:
openinv.container.silent.use: true
openinv.container.silent.use:
default: false
# Search functionality
openinv.search:
children:
Expand Down