From e727a03fb92446918e568db5901cc6675be36964 Mon Sep 17 00:00:00 2001 From: filoghost Date: Sat, 17 Oct 2020 23:15:05 +0200 Subject: [PATCH] Assume placeholders can be added and removed dynamically --- .../placeholder/PlaceholderManager.java | 6 +----- .../placeholder/scanner/PlaceholderScanner.java | 13 +++++-------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java index aba7797..e3773a1 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/PlaceholderManager.java @@ -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); diff --git a/plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java index b00ad9b..c5dd5b6 100644 --- a/plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java +++ b/plugin/src/main/java/me/filoghost/chestcommands/placeholder/scanner/PlaceholderScanner.java @@ -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 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 replaceFunction) {