-
-
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 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. The changes in this file are only because you downgraded the version |
|
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 |
|---|---|---|
|
|
@@ -29,4 +29,4 @@ include 'NMS:v1_20_4' | |
| include 'NMS:v1_21' | ||
| include 'NMS:v1_21_3' | ||
| include 'NMS:v1_21_4' | ||
| include 'NMS:v1_21_5' | ||
| // include 'NMS:v1_21_5' // Temporarily disabled due to API incompatibilities | ||
|
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. ?? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,6 +160,14 @@ public List<Chest> getChests(World world) { | |
| Collections.unmodifiableList(new LinkedList<>(chunkChests)); | ||
| } | ||
|
|
||
| @Override | ||
| public int getChestCount(UUID placer, String chestType) { | ||
|
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.
|
||
| return (int) chests.values().stream() | ||
| .filter(chest -> chest.getPlacer().equals(placer)) | ||
| .filter(chest -> chest.getData().getName().equals(chestType)) | ||
|
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. Combine both filters to a single predicate
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. Instead of comparing the names of the chestType, get the chest data of the provided |
||
| .count(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Chest> getNearbyChests(Location location) { | ||
| return getChests(location.getWorld()).stream() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.bgsoftware.wildchests.utils; | ||
|
|
||
| import com.bgsoftware.wildchests.WildChestsPlugin; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.permissions.PermissionAttachmentInfo; | ||
|
|
||
| public final class ChestLimitUtils { | ||
|
|
||
| private ChestLimitUtils() {} | ||
|
|
||
| public static int getPlayerChestLimit(Player player, String chestType) { | ||
|
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. Calling |
||
| String permissionPrefix = "wildchests.limit." + chestType + "."; | ||
|
|
||
| int maxLimit = 0; | ||
| boolean hasPermission = false; | ||
|
|
||
| for (PermissionAttachmentInfo permissionInfo : player.getEffectivePermissions()) { | ||
| String permission = permissionInfo.getPermission(); | ||
| if (permission.startsWith(permissionPrefix) && permissionInfo.getValue()) { | ||
| hasPermission = true; | ||
| try { | ||
| String limitStr = permission.substring(permissionPrefix.length()); | ||
| int limit = Integer.parseInt(limitStr); | ||
| if (limit > maxLimit) { | ||
| maxLimit = limit; | ||
| } | ||
| } catch (NumberFormatException ignored) { | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!hasPermission) { | ||
| Integer defaultLimit = WildChestsPlugin.getPlugin().getSettings().defaultChestLimits.get(chestType); | ||
| if (defaultLimit != null) { | ||
| return defaultLimit == 0 ? Integer.MAX_VALUE : defaultLimit; | ||
| } | ||
| return Integer.MAX_VALUE; | ||
| } | ||
|
|
||
| return maxLimit; | ||
| } | ||
|
|
||
| public static boolean hasChestLimit(Player player, String chestType) { | ||
| String permissionPrefix = "wildchests.limit." + chestType + "."; | ||
|
|
||
| boolean hasPermission = player.getEffectivePermissions().stream() | ||
| .anyMatch(permissionInfo -> permissionInfo.getPermission().startsWith(permissionPrefix) && permissionInfo.getValue()); | ||
|
|
||
| if (!hasPermission) { | ||
| Integer defaultLimit = WildChestsPlugin.getPlugin().getSettings().defaultChestLimits.get(chestType); | ||
| return defaultLimit != null && defaultLimit != -1; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,24 @@ maximum-pickup-delay: 32767 | |
| # You can disable this feature by setting it to -1. | ||
| max-stacks-on-drop: -1 | ||
|
|
||
| # Enable permission-based chest placement limits. | ||
| # When enabled, players can only place a limited number of each chest type based on permissions. | ||
| # Permission format: wildchests.limit.<type>.<amount> | ||
| # For example: wildchests.limit.linked_chest.5 allows placing up to 5 linked chests | ||
| enable-chest-limits: false | ||
|
|
||
| # Default limits for each chest type when no specific permission is given. | ||
| # Set to 0 for unlimited, or any positive number for the default limit. | ||
| # Set to -1 to disable this chest type entirely. | ||
| # These only apply when enable-chest-limits is true. | ||
| default-chest-limits: | ||
| linked_chest: 0 | ||
| large_chest: 0 | ||
| sell_chest: 0 | ||
| auto_crafter: 0 | ||
| storage_unit: 0 | ||
| chunk_collector: 0 | ||
|
|
||
|
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. Change this to: |
||
| # The plugin brings tons of new custom and unique chests to your server. All the chests are configurable, and | ||
| # you can create and mix between them. You can create chests that stores infinite amount of items, chests that | ||
| # are connected to player vaults or factions, linked chests and many more! | ||
|
|
||
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.
Why did you downgrade the version?