Skip to content

Commit

Permalink
limit region owners and members by new semi generic perm:
Browse files Browse the repository at this point in the history
protectionstones.members-amount.<integer>
protectionstones.owners-amount.<integer>

perm is necessary to add any member/owner #1
  • Loading branch information
Galajus committed Jul 22, 2024
1 parent 82e5481 commit 5e53020
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public boolean executeArgument(CommandSender s, String[] args, HashMap<String, S
PSL.msg(p, PSL.CANNOT_REMOVE_YOURSELF_LAST_OWNER.msg());
return;
}

regions = Collections.singletonList(r);
}

Expand Down
34 changes: 34 additions & 0 deletions src/main/java/dev/espi/protectionstones/utils/PermUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package dev.espi.protectionstones.utils;

import org.apache.commons.lang3.math.NumberUtils;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;

import java.util.Optional;

public class PermUtil {

/**
* Getting number variable on end of perm
* @param player Bukkit player
* @param searchingPerm permission without number variable on end like "protectionstones.owners-amount."
* @return perm int variable
*/
public static int getLimitOwnersFromPermission(Player player, String searchingPerm) {
Optional<PermissionAttachmentInfo> perm = player.getEffectivePermissions().stream()
.filter(p -> p.getPermission().startsWith(searchingPerm)).findFirst();
if (perm.isEmpty()) {
return 0;
}
String[] split = perm.get().getPermission().split("\\.");
if (split.length < 3) {
return 0;
}
String limitString = split[2];

if (NumberUtils.isCreatable(limitString)) {
return Integer.parseInt(limitString);
}
return 0;
}
}

0 comments on commit 5e53020

Please sign in to comment.