mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-25 19:45:44 +01:00
Assume placeholders can be added and removed dynamically
This commit is contained in:
parent
612c9bb329
commit
e727a03fb9
@ -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);
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user