Package com.petarmc.lib.chat
Class ChatPatternMatcher
java.lang.Object
com.petarmc.lib.chat.ChatPatternMatcher
A reusable chat pattern matching system that allows registration of regex patterns
and exact string matches with associated handlers.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<String, ExactMatchHandler> private final List<ChatPatternMatcher.PatternEntry> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Remove all registered patterns and exact matches.voidprocessMessage(String message) Process a chat message against all registered patterns and exact matches.voidregisterExactMatch(String matchId, String exactMessage, ExactMatchHandler handler) Register an exact string match with a handler.voidregisterPattern(String patternId, String regex, int flags, ChatMatchHandler handler) Register a regex pattern with flags.voidregisterPattern(String patternId, String regex, ChatMatchHandler handler) Register a regex pattern with a handler.voidregisterPattern(String patternId, Pattern pattern, ChatMatchHandler handler) Register a regex pattern with a handler.booleanremoveExactMatch(String exactMessage) Remove a specific exact match.booleanremovePattern(String patternId) Remove a specific pattern by ID.
-
Field Details
-
patterns
-
exactMatches
-
-
Constructor Details
-
ChatPatternMatcher
public ChatPatternMatcher()
-
-
Method Details
-
registerPattern
Register a regex pattern with a handler.- Parameters:
patternId- Unique identifier for this patternpattern- The regex pattern to matchhandler- The handler to call when a match is found
-
registerPattern
Register a regex pattern with a handler.- Parameters:
patternId- Unique identifier for this patternregex- The regex string to compile and matchhandler- The handler to call when a match is found
-
registerPattern
Register a regex pattern with flags.- Parameters:
patternId- Unique identifier for this patternregex- The regex string to compile and matchflags- Pattern compilation flags (e.g., Pattern.CASE_INSENSITIVE)handler- The handler to call when a match is found
-
registerExactMatch
Register an exact string match with a handler.- Parameters:
matchId- Unique identifier for this exact matchexactMessage- The exact message to matchhandler- The handler to call when the exact message is found
-
processMessage
Process a chat message against all registered patterns and exact matches.- Parameters:
message- The chat message to process
-
clear
public void clear()Remove all registered patterns and exact matches. -
removePattern
Remove a specific pattern by ID.- Parameters:
patternId- The ID of the pattern to remove- Returns:
- true if a pattern was removed
-
removeExactMatch
Remove a specific exact match.- Parameters:
exactMessage- The exact message to remove- Returns:
- true if an exact match was removed
-