From 0d66003163f806359af288de63ba781f11a6276e Mon Sep 17 00:00:00 2001 From: TheJoshue <56804505+TheJoshue@users.noreply.github.com> Date: Sat, 4 Nov 2023 02:10:21 +0100 Subject: [PATCH] Update PaginatedCommand.java --- .../MultiverseCore/commands/PaginatedCommand.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/PaginatedCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/PaginatedCommand.java index c3ddf09b..2dd11a2a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/PaginatedCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/PaginatedCommand.java @@ -13,12 +13,14 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import java.util.List; +import java.util.regex.Pattern; /** * A generic paginated command. * @param The type of items on the page. */ public abstract class PaginatedCommand extends Command { + private final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]"); private static final int DEFAULT_ITEMS_PER_PAGE = 9; /** * The number of items per page. @@ -40,12 +42,23 @@ public abstract class PaginatedCommand extends Command { /** * Gets filtered items. + * * @param availableItems All available items. * @param filter The filter-{@link String}. * @return A list of items that match the filter. */ protected abstract List getFilteredItems(List availableItems, String filter); + /** + * Escape regex special characters from filter + * + * @param filter The filter-{@link String}. + * @return String with regex characters escaped + */ + protected String cleanFilter(String filter) { + return REGEX_SPECIAL_CHARS.matcher(filter).replaceAll("\\\\$0"); + } + /** * Constructs a single string from a list of strings. *