Skip to content

Commit

Permalink
feat: inverted permission-node
Browse files Browse the repository at this point in the history
You can now use the ! symbol to invert the permission requirement from permission-node on custom items.
  • Loading branch information
RockinChaos committed Aug 29, 2024
1 parent 16ac732 commit 300f5d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/main/java/me/RockinChaos/itemjoin/item/ItemMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -2627,14 +2627,16 @@ public void setCustomConsumable(final boolean bool) {
*/
public boolean hasPermission(final Player player, final World world) {
final String customPerm = PermissionsHandler.customPermissions(this.permissionNode, world.getName() + "." + this.configName);
final boolean isNeeded = !customPerm.startsWith("!");
final String permissionString = (isNeeded ? customPerm : customPerm.substring(1));
final boolean hasPermission = player.isPermissionSet(permissionString) && player.hasPermission(permissionString);
final boolean hasCustomPermission = (!isNeeded && !hasPermission) || (isNeeded && hasPermission);
if (!this.isPermissionNeeded() && !player.isOp() || (!this.isOPPermissionNeeded() && player.isOp())) {
return true;
} else if (this.isOPPermissionNeeded() && player.isOp()) {
return player.isPermissionSet(customPerm) && player.hasPermission(customPerm) && (!player.isPermissionSet("itemjoin." + world.getName() + ".*")
|| (player.isPermissionSet("itemjoin." + world.getName() + ".*") && player.hasPermission("itemjoin." + world.getName() + ".*")))
|| ((player.isPermissionSet("itemjoin." + world.getName() + ".*") && player.hasPermission("itemjoin." + world.getName() + ".*")) || (player.isPermissionSet(customPerm) && player.hasPermission(customPerm)));
return hasCustomPermission || (player.isPermissionSet("itemjoin." + world.getName() + ".*") && player.hasPermission("itemjoin." + world.getName() + ".*"));
}
return (player.isPermissionSet("itemjoin." + world.getName() + ".*") && player.hasPermission("itemjoin." + world.getName() + ".*")) || (player.isPermissionSet(customPerm) && player.hasPermission(customPerm));
return (player.isPermissionSet("itemjoin." + world.getName() + ".*") && player.hasPermission("itemjoin." + world.getName() + ".*")) || hasCustomPermission;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/RockinChaos/itemjoin/utils/menus/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,8 @@ private static void creatingPane(final Player player, final ItemMap itemMap) {
(!StringUtils.nullCheck(itemMap.getItemFlags()).equals("NONE") ? "&a" + itemflagsList : "NONE")), event -> flagPane(player, itemMap)));
creatingPane.addButton(new Button(ItemHandler.getItem("REDSTONE", 1, false, false, "&b&lTriggers", "&7", "&7*When the players act upon these", "&7events, the item will be given.", "&9&lTRIGGERS: &a" +
(!StringUtils.nullCheck(itemMap.getTriggers()).equals("NONE") ? "&a" + triggersList : "NONE")), event -> triggerPane(player, itemMap)));
creatingPane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "REDSTONE_TORCH" : "76"), 1, false, false, "&b&lPermission Node", "&7", "&7*Custom permission node that", "&7will be required by a permission", "&7plugin to receive the item.", "&7&lNote: &7Do NOT include",
"&7any spaces or special characters.", "&7Setting this bypasses the", "&7config.yml Permissions Settings.", "&9&lPERMISSION-NODE: &a" + StringUtils.nullCheck(itemMap.getPermissionNode())), event -> {
creatingPane.addButton(new Button(ItemHandler.getItem((ServerUtils.hasSpecificUpdate("1_13") ? "REDSTONE_TORCH" : "76"), 1, false, false, "&b&lPermission Node", "&7", "&7*Custom permission node that", "&7will be required by a permission", "&7plugin to receive the item.", "&7", "&c&lNote: &7You can use a &c&l! &7symbol", "&7to invert the requirement such", "&7as !fish.cakes, do NOT include any",
"&7other special characters or spaces.", "&7", "&7Setting this bypasses the", "&7config.yml Permissions Settings.", "&7", "&9&lPERMISSION-NODE: &a" + StringUtils.nullCheck(itemMap.getPermissionNode())), event -> {
if (!StringUtils.nullCheck(itemMap.getPermissionNode()).equals("NONE")) {
itemMap.setPerm(null);
creatingPane(player, itemMap);
Expand Down Expand Up @@ -7608,7 +7608,7 @@ private static void commandPPane(final Player player, final ItemMap itemMap, fin
permissionsPane.setReturnButton(new Button(ItemHandler.getItem("BARRIER", 1, false, false, "&c&l&nReturn", "&7", "&7*Returns you to the command actions menu."), event -> commandPermissionPane(player, itemMap)));
SchedulerUtils.runAsync(() -> {
permissionsPane.addButton(new Button(ItemHandler.getItem("FEATHER", 1, true, false, "&b&lAdd Permission", "&7", "&7*Permissions(s) that must be met",
"&7in order to execute the", "&7" + commandAction.config().replace("-", " ").replace(".", "") + " item commands.", "&7", "&cNote: &7You can use a ! symbol", "&7to invert the requirement", "&7such as !fish.cakes"),
"&7in order to execute the", "&7" + commandAction.config().replace("-", " ").replace(".", "") + " item commands.", "&7", "&c&lNote: &7You can use a &c&l! &7symbol", "&7to invert the requirement", "&7such as !fish.cakes"),
event -> {
player.closeInventory();
final PlaceHolder placeHolders = new PlaceHolder().with(Holder.INPUT, "PERMISSION").with(Holder.INPUT_EXAMPLE, "fish.cakes");
Expand Down

0 comments on commit 300f5d2

Please sign in to comment.