From cbb2b4d2322285cb3b4f41c91fc74144814f4c3a Mon Sep 17 00:00:00 2001 From: Jikoo Date: Tue, 7 Nov 2017 18:16:38 -0500 Subject: [PATCH] Lowercase permissions can wait for a major version bump I don't want to double our permissions checks for backwards compatibility. --- README.MD | 39 ++++++++++---- .../com/lishid/openinv/util/Permissions.java | 51 +++++++++++-------- .../plugin-core/src/main/resources/plugin.yml | 18 +++---- 3 files changed, 67 insertions(+), 41 deletions(-) diff --git a/README.MD b/README.MD index b9ddba6..cf5a5f5 100644 --- a/README.MD +++ b/README.MD @@ -11,8 +11,8 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi - Read-only mode! No edits allowed! Don't grant `OpenInv.editender` - Cross-world support! Don't grant `OpenInv.crossworld` - No opening others! Don't grant `OpenInv.openenderall` -- **SilentChest**: Open containers without displaying an animation or making sound. -- **AnyChest**: Open containers, even if blocked by ocelots or blocks. +- **SilentContainer**: Open containers without displaying an animation or making sound. +- **AnyContainer**: Open containers, even if blocked by ocelots or blocks. ## Commands @@ -42,14 +42,19 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi - - - + + + - - - + + + + + + + +
Lists all online players that have a certain item in their ender chest.
/anychest [check]acCheck or toggle the AnyChest function, allowing opening blocked containers./searchenchant <[enchantment] [MinLevel]>searchenchantsLists all online players with a specific enchantment.
/silentchest [check]scCheck or toggle the SilentChest function, allowing opening containers silently./anycontainer [check]ac, anychestCheck or toggle the AnyContainer function, allowing opening blocked containers.
/silentcontainer [check]sc, silentchestCheck or toggle the SilentContainer function, allowing opening containers silently.
@@ -103,18 +108,30 @@ OpenInv is a [Bukkit plugin](https://dev.bukkit.org/bukkit-plugins/openinv/) whi OpenInv.search Required to use /searchinv and /searchender. + + OpenInv.searchenchant + Required to use /searchenchant. + OpenInv.anychest Required to use /anychest. + + OpenInv.any.default + Cause AnyContainer to be enabled by default. + OpenInv.silent - Required to use /silentchest. + Required to use /silentcontainer. + + + OpenInv.silent.default + Cause SilentContainer to be enabled by default. ## For Developers -To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin. +To compile, the relevant Craftbukkit/Spigot jars must be installed in your local repository using the install plugin. Ex: `mvn install:install-file -Dpackaging=jar -Dfile=spigot-1.11-R0.1-SNAPSHOT.jar -DgroupId=org.spigotmc -DartifactId=spigot -Dversion=1.11-R0.1-SNAPSHOT` To compile for a specific version or set of versions, you'll need to use a profile. Provided profiles are `latest`, `modern` (versions 1.8+), and `all`. Select an existing profile using the `-P` argument (ex: `mvn clean package -am -P all`) or make your own. For more information, check out the [official guide](http://maven.apache.org/guides/introduction/introduction-to-profiles.html). @@ -136,4 +153,4 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . -``` \ No newline at end of file +``` diff --git a/common/src/main/java/com/lishid/openinv/util/Permissions.java b/common/src/main/java/com/lishid/openinv/util/Permissions.java index 8fdf8a6..2e9476b 100644 --- a/common/src/main/java/com/lishid/openinv/util/Permissions.java +++ b/common/src/main/java/com/lishid/openinv/util/Permissions.java @@ -4,35 +4,44 @@ import org.bukkit.permissions.Permissible; public enum Permissions { - OPENINV("OpenInv.openinv"), - OVERRIDE("OpenInv.override"), - EXEMPT("OpenInv.exempt"), - CROSSWORLD("OpenInv.crossworld"), - SILENT("OpenInv.silent"), - ANYCHEST("OpenInv.anychest"), - ENDERCHEST("OpenInv.openender"), - ENDERCHEST_ALL("OpenInv.openenderall"), - SEARCH("OpenInv.search"), - EDITINV("OpenInv.editinv"), - EDITENDER("OpenInv.editender"), - OPENSELF("OpenInv.openself"); + OPENINV("openinv"), + OVERRIDE("override"), + EXEMPT("exempt"), + CROSSWORLD("crossworld"), + SILENT("silent"), + ANYCHEST("anychest"), + ENDERCHEST("openender"), + ENDERCHEST_ALL("openenderall"), + SEARCH("search"), + EDITINV("editinv"), + EDITENDER("editender"), + OPENSELF("openself"); - private final String permission; + private final String[] permission; - private Permissions(String permission) { - this.permission = permission; + Permissions(String... permission) { + this.permission = new String[permission.length + 1]; + this.permission[0] = "OpenInv"; + System.arraycopy(permission, 0, permission, 1, permission.length); } public boolean hasPermission(Permissible permissible) { - String[] parts = permission.split("\\."); - String perm = ""; - for (int i = 0; i < parts.length; i++) { - if (permissible.hasPermission(perm + "*")) { + StringBuilder permissionBuilder = new StringBuilder(); + + // Support wildcard nodes. + for (int i = 0; i < permission.length; i++) { + if (permissible.hasPermission(permissionBuilder.toString() + "*")) { return true; } - perm += parts[i] + "."; + permissionBuilder.append(permission[i]).append('.'); } - return permissible.hasPermission(permission); + + // Delete trailing period. + if (permissionBuilder.length() > 0) { + permissionBuilder.deleteCharAt(permissionBuilder.length() - 1); + } + + return permissible.hasPermission(permissionBuilder.toString()); } } diff --git a/plugin/plugin-core/src/main/resources/plugin.yml b/plugin/plugin-core/src/main/resources/plugin.yml index 7b76544..c9079e8 100644 --- a/plugin/plugin-core/src/main/resources/plugin.yml +++ b/plugin/plugin-core/src/main/resources/plugin.yml @@ -7,10 +7,10 @@ description: > This plugin allows you to open a player's inventory as a chest and interact with it in real time. permissions: - openinv.any.default: + OpenInv.any.default: description: Permission for AnyContainer to default on prior to toggling. default: false - openinv.silent.default: + OpenInv.silent.default: description: Permission for SilentContainer to default on prior to toggling. default: false @@ -18,42 +18,42 @@ commands: openinv: aliases: [oi, inv, open] description: Open a player's inventory - permission: OpenInv.*;OpenInv.openinv;openinv.*;openinv.openinv + permission: OpenInv.*;OpenInv.openinv usage: |- / [Player] - Open a player's inventory openender: aliases: [oe] description: Opens the enderchest of a player - permission: OpenInv.*;OpenInv.openender;openinv.*;openinv.openender + permission: OpenInv.*;OpenInv.openender usage: |- / [Player] - Open a player's enderchest searchinv: aliases: [si] description: Search and list players having a specific item - permission: OpenInv.*;OpenInv.search;openinv.*;openinv.search + permission: OpenInv.*;OpenInv.search usage: |- / [MinAmount] - Item is the ID or the Bukkit Material, MinAmount is the minimum amount required searchender: aliases: [se] - permission: OpenInv.*;OpenInv.search;openinv.*;openinv.search + permission: OpenInv.*;OpenInv.search description: Searches and lists players having a specific item in their ender chest usage: |- / [MinAmount] - Item is the ID or the Bukkit Material, MinAmount is the minimum amount required silentcontainer: aliases: [sc, silent, silentchest] description: Toggle SilentContainer function, which stops sounds and animations when using containers. - permission: OpenInv.*;OpenInv.silent;openinv.*;openinv.silent + permission: OpenInv.*;OpenInv.silent usage: |- / [Check] - Check or toggle silent chest anycontainer: aliases: [ac, anychest] description: Toggle AnyContainer function, which allows opening of blocked containers. - permission: OpenInv.*;OpenInv.anychest;openinv.*;openinv.any + permission: OpenInv.*;OpenInv.anychest usage: |- / [Check] - Checks or toggle anychest searchenchant: aliases: [searchenchants] description: Search and list players with a specific enchantment. - permission: OpenInv.*;OpenInv.searchenchant;openinv.*;openinv.searchenchant + permission: OpenInv.*;OpenInv.searchenchant usage: |- / <[enchantment] [MinLevel]> - Enchantment is the enchantment type, MinLevel is the minimum level. One is optional