-
-
Notifications
You must be signed in to change notification settings - Fork 32
Add permission based chest placement limits #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -231,4 +231,4 @@ public interface ChestData { | |
| */ | ||
| void setParticles(List<String> particles); | ||
|
|
||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert changes |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert changes |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package com.bgsoftware.wildchests.utils; | ||
|
|
||
| import com.bgsoftware.wildchests.WildChestsPlugin; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.permissions.PermissionAttachmentInfo; | ||
|
|
||
| import java.util.OptionalInt; | ||
|
|
||
| public final class ChestLimitUtils { | ||
|
|
||
| private ChestLimitUtils() {} | ||
|
|
||
| /** | ||
| * Result class to hold both limit existence and value information | ||
| */ | ||
| public static class ChestLimitResult { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to |
||
| private final boolean hasLimit; | ||
| private final int limit; | ||
|
|
||
| private ChestLimitResult(boolean hasLimit, int limit) { | ||
| this.hasLimit = hasLimit; | ||
| this.limit = limit; | ||
| } | ||
|
|
||
| public boolean hasLimit() { | ||
| return hasLimit; | ||
| } | ||
|
|
||
| public int getLimit() { | ||
| return limit; | ||
| } | ||
|
|
||
| public static ChestLimitResult noLimit() { | ||
| return new ChestLimitResult(false, Integer.MAX_VALUE); | ||
| } | ||
|
|
||
| public static ChestLimitResult withLimit(int limit) { | ||
| return new ChestLimitResult(true, limit); | ||
| } | ||
| } | ||
|
|
||
| public static ChestLimitResult getPlayerChestLimitResult(Player player, String chestDataName) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to |
||
| String permissionPrefix = "wildchests.limit." + chestDataName + "."; | ||
|
|
||
| OptionalInt maxPermissionLimit = player.getEffectivePermissions().stream() | ||
| .filter(PermissionAttachmentInfo::getValue) | ||
| .map(PermissionAttachmentInfo::getPermission) | ||
| .filter(permission -> permission.startsWith(permissionPrefix)) | ||
| .map(permission -> permission.substring(permissionPrefix.length())) | ||
| .mapToInt(limitStr -> { | ||
| try { | ||
| return Integer.parseInt(limitStr); | ||
| } catch (NumberFormatException e) { | ||
| return -1; | ||
| } | ||
| }) | ||
| .filter(limit -> limit >= 0) | ||
| .max(); | ||
|
|
||
| if (maxPermissionLimit.isPresent()) { | ||
| return ChestLimitResult.withLimit(maxPermissionLimit.getAsInt()); | ||
| } | ||
|
|
||
| Integer defaultLimit = WildChestsPlugin.getPlugin().getSettings().defaultChestLimits.get(chestDataName); | ||
| if (defaultLimit != null && defaultLimit != -1) { | ||
| int actualLimit = defaultLimit == 0 ? Integer.MAX_VALUE : defaultLimit; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should support limit 0 - this means players won't be able to place that chest |
||
| return ChestLimitResult.withLimit(actualLimit); | ||
| } | ||
|
|
||
| return ChestLimitResult.noLimit(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert changes