Assume placeholders can be added and removed dynamically

This commit is contained in:
filoghost 2020-10-17 23:15:05 +02:00
parent 612c9bb329
commit e727a03fb9
2 changed files with 6 additions and 13 deletions

View File

@ -39,7 +39,7 @@ public class PlaceholderManager {
}
public static boolean hasDynamicPlaceholders(String text) {
if (new PlaceholderScanner(text).anyMatch(PlaceholderManager::isValidPlaceholder)) {
if (new PlaceholderScanner(text).containsAny()) {
return true;
}
@ -60,10 +60,6 @@ public class PlaceholderManager {
return text;
}
private static boolean isValidPlaceholder(PlaceholderMatch placeholderMatch) {
return relativePlaceholderRegistry.getPlaceholder(placeholderMatch) != null;
}
private static @Nullable String getReplacement(PlaceholderMatch placeholderMatch, Player player) {
Placeholder placeholder = dynamicPlaceholderRegistry.getPlaceholder(placeholderMatch);

View File

@ -8,7 +8,6 @@ package me.filoghost.chestcommands.placeholder.scanner;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
public class PlaceholderScanner {
@ -25,17 +24,15 @@ public class PlaceholderScanner {
this.inputLength = input.length();
}
public boolean anyMatch(Predicate<PlaceholderMatch> predicate) {
AtomicBoolean matchFound = new AtomicBoolean(false);
public boolean containsAny() {
AtomicBoolean placeholderFound = new AtomicBoolean(false);
scan(identifier -> {
if (predicate.test(identifier)) {
matchFound.set(true);
stopExecution = true;
}
stopExecution = true;
placeholderFound.set(true);
});
return matchFound.get();
return placeholderFound.get();
}
public String replace(Function<PlaceholderMatch, String> replaceFunction) {