Class ChatPatternMatcher

java.lang.Object
com.petarmc.lib.chat.ChatPatternMatcher

public class ChatPatternMatcher extends Object
A reusable chat pattern matching system that allows registration of regex patterns and exact string matches with associated handlers.
  • Field Details

  • Constructor Details

    • ChatPatternMatcher

      public ChatPatternMatcher()
  • Method Details

    • registerPattern

      public void registerPattern(String patternId, Pattern pattern, ChatMatchHandler handler)
      Register a regex pattern with a handler.
      Parameters:
      patternId - Unique identifier for this pattern
      pattern - The regex pattern to match
      handler - The handler to call when a match is found
    • registerPattern

      public void registerPattern(String patternId, String regex, ChatMatchHandler handler)
      Register a regex pattern with a handler.
      Parameters:
      patternId - Unique identifier for this pattern
      regex - The regex string to compile and match
      handler - The handler to call when a match is found
    • registerPattern

      public void registerPattern(String patternId, String regex, int flags, ChatMatchHandler handler)
      Register a regex pattern with flags.
      Parameters:
      patternId - Unique identifier for this pattern
      regex - The regex string to compile and match
      flags - Pattern compilation flags (e.g., Pattern.CASE_INSENSITIVE)
      handler - The handler to call when a match is found
    • registerExactMatch

      public void registerExactMatch(String matchId, String exactMessage, ExactMatchHandler handler)
      Register an exact string match with a handler.
      Parameters:
      matchId - Unique identifier for this exact match
      exactMessage - The exact message to match
      handler - The handler to call when the exact message is found
    • processMessage

      public void processMessage(String message)
      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

      public boolean removePattern(String patternId)
      Remove a specific pattern by ID.
      Parameters:
      patternId - The ID of the pattern to remove
      Returns:
      true if a pattern was removed
    • removeExactMatch

      public boolean removeExactMatch(String exactMessage)
      Remove a specific exact match.
      Parameters:
      exactMessage - The exact message to remove
      Returns:
      true if an exact match was removed