Skip to content

Commit

Permalink
idk why there is no boolean for it
Browse files Browse the repository at this point in the history
  • Loading branch information
FakEEE14 committed Nov 28, 2024
1 parent abd23c9 commit 5af0541
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5af0541

Please sign in to comment.