diff --git a/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java b/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java index f287393..ce5ee72 100644 --- a/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java +++ b/src/main/java/com/extendedclip/deluxemenus/config/DeluxeMenusConfig.java @@ -1194,6 +1194,19 @@ private RequirementList getRequirements(FileConfiguration c, String path) { ); } break; + case BOOLEAN: + case REVERSE_BOOLEAN: + if (c.contains(rPath + ".input")) { + invert = type == RequirementType.REVERSE_BOOLEAN; + req = new BooleanRequirement(c.getString(rPath + ".input"), invert); + } else { + DeluxeMenus.debug( + DebugLevel.HIGHEST, + Level.WARNING, + "Boolean requirement at path: " + rPath + " does not contain a input: entry" + ); + } + break; case JAVASCRIPT: if (c.contains(rPath + ".expression")) { req = new JavascriptRequirement(c.getString(rPath + ".expression")); diff --git a/src/main/java/com/extendedclip/deluxemenus/requirement/BooleanRequirement.java b/src/main/java/com/extendedclip/deluxemenus/requirement/BooleanRequirement.java new file mode 100644 index 0000000..0e32808 --- /dev/null +++ b/src/main/java/com/extendedclip/deluxemenus/requirement/BooleanRequirement.java @@ -0,0 +1,29 @@ +package com.extendedclip.deluxemenus.requirement; + +import com.extendedclip.deluxemenus.menu.MenuHolder; + +public class BooleanRequirement extends Requirement { + + private final String bool; + private final boolean invert; + + public BooleanRequirement(String bool, boolean invert) { + this.bool = bool; + this.invert = invert; + } + + @Override + public boolean evaluate(MenuHolder holder) { + String check = holder.setPlaceholdersAndArguments(bool); + try { + boolean bool = Boolean.parseBoolean(check); + if (invert) { + return !bool; + } else { + return bool; + } + } catch (Exception e) { + return false; + } + } +} diff --git a/src/main/java/com/extendedclip/deluxemenus/requirement/RequirementType.java b/src/main/java/com/extendedclip/deluxemenus/requirement/RequirementType.java index ef39bcc..ce0e3f0 100644 --- a/src/main/java/com/extendedclip/deluxemenus/requirement/RequirementType.java +++ b/src/main/java/com/extendedclip/deluxemenus/requirement/RequirementType.java @@ -53,6 +53,10 @@ public enum RequirementType { "Checks if a string does not contain another string", Arrays.asList("input", "output")), STRING_EQUALS(Arrays.asList("string equals", "stringequals", "equals"), "Checks if a string equals another string", Arrays.asList("input", "output")), + BOOLEAN(Arrays.asList("boolean", "bool"), + "Checks if a player has a set amount of permissions", Collections.singletonList("input")), + REVERSE_BOOLEAN(Arrays.asList("!boolean", "!bool"), + "Checks if a player has a set amount of permissions", Collections.singletonList("input")), STRING_DOES_NOT_EQUAL(Arrays.asList("!string equals", "!stringequals", "!equals"), "Checks if a string does not equal another string", Arrays.asList("input", "output")), STRING_EQUALS_IGNORECASE(