forked from espidev/ProtectionStones
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
limit region owners and members by new semi generic perm:
protectionstones.members-amount.<integer> protectionstones.owners-amount.<integer> perm is necessary to add any member/owner #1
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/main/java/dev/espi/protectionstones/utils/PermUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |