Skip to content

Commit e3d3183

Browse files
committed
Parse PlaceholderAPI placeholders in expected value
1 parent 53c6c5d commit e3d3183

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/main/java/cloud/grabsky/dialogs/Condition.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ public final class Condition {
2323
private final String value;
2424

2525
public boolean testCondition(final @NotNull Player player) {
26-
final String parsed = PlaceholderAPI.setPlaceholders(player, placeholder);
26+
final String parsedPlaceholder = PlaceholderAPI.setPlaceholders(player, placeholder);
27+
final String parsedValue = PlaceholderAPI.setPlaceholders(player, value);
2728
return switch (operator) {
28-
case EQUALS -> parsed.equals(value);
29-
case NOT_EQUALS -> parsed.equals(value) == false;
29+
case EQUALS -> parsedPlaceholder.equals(parsedValue);
30+
case NOT_EQUALS -> parsedPlaceholder.equals(parsedValue) == false;
3031
case GREATER_THAN, GREATER_THAN_OR_EQUALS, SMALLER_THAN, SMALLER_THAN_OR_EQUALS -> {
3132
// Parsing values to Double.
32-
final Double a = toDouble(parsed);
33-
final Double b = toDouble(value);
33+
final Double a = toDouble(parsedPlaceholder);
34+
final Double b = toDouble(parsedValue);
3435
// Returning false if first value is not a number.
3536
if (a == null) {
36-
Dialogs.getInstance().getLogger().warning("Tried to compare placeholder '" + placeholder + "' but output is not a number: '" + parsed + "'");
37+
Dialogs.getInstance().getLogger().warning("Tried to compare placeholder '" + placeholder + "' but output is not a number: '" + parsedPlaceholder + "'");
3738
yield false;
3839
}
3940
// Returning false if second value is not a number.
4041
if (b == null) {
41-
Dialogs.getInstance().getLogger().warning("Tried to compare placeholder '" + placeholder + "' but expected value is not a number: '" + value + "'");
42+
Dialogs.getInstance().getLogger().warning("Tried to compare placeholder '" + placeholder + "' but expected value is not a number: '" + parsedValue + "'");
4243
yield false;
4344
}
4445
// Comparing numbers based on the specified operator and returning the result.
@@ -53,10 +54,10 @@ public boolean testCondition(final @NotNull Player player) {
5354
// In any other case, false is returned.
5455
yield false;
5556
}
56-
case CONTAINS -> parsed.contains(value);
57-
case NOT_CONTAINS -> parsed.contains(value) == false;
58-
case STARTS_WITH -> parsed.startsWith(value);
59-
case ENDS_WITH -> parsed.endsWith(value);
57+
case CONTAINS -> parsedPlaceholder.contains(parsedValue);
58+
case NOT_CONTAINS -> parsedPlaceholder.contains(parsedValue) == false;
59+
case STARTS_WITH -> parsedPlaceholder.startsWith(parsedValue);
60+
case ENDS_WITH -> parsedPlaceholder.endsWith(parsedValue);
6061
};
6162
}
6263

0 commit comments

Comments
 (0)