Interface MatchContext
- All Known Subinterfaces:
MatchContext.ChatMatchContext
public interface MatchContext
This is the core of the matcher system.
A MatchContext is made out of some input string with forInput(java.lang.String)
.
It's then given to each matcher, which can parse it however it sees fit
and add new matches on a given range.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
An extension of MatchContext that has the player sending the message. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addMatch
(int start, int end, InlineMatch match) Attaches the given match to all characters in the range.int
finalToOrig
(int fin) Converts the given index from its position in the final string returned bygetFinalText()
to the corresponding position in the original string.static MatchContext
Creates a MatchContext with the given input as its base.static MatchContext
forTextInput
(net.minecraft.text.Text inputText) void
freeze()
Freeze this context so that it no longer accepts new matches.Gets a map of all matches added.net.minecraft.text.Text
Gets the final text with the style baked into it already.Gets the text with all matched characters replaced by placeholders for the length of the match.getMatchableText
(char redactedChar) Gets the input but with already matched characters being replaced with redactedCharGets a map of all matches added.Gets the raw inputGets all unmatched segments.boolean
isFrozen()
If this context is 'frozen', meaning it no longer accepts new matches.int
origToFinal
(int orig) Converts the given index from its position in the original string to the corresponding position in the final string returned bygetFinalText()
-
Method Details
-
forInput
Creates a MatchContext with the given input as its base.- Parameters:
inputText
-- Returns:
- a MatchContext for the input.
-
forTextInput
-
isFrozen
boolean isFrozen()If this context is 'frozen', meaning it no longer accepts new matches.- Returns:
- if this context is read-only or not.
-
freeze
void freeze()Freeze this context so that it no longer accepts new matches. -
getOriginalText
String getOriginalText()Gets the raw input- Returns:
- the original text being matched against.
-
getMatchableText
Gets the input but with already matched characters being replaced with redactedChar- Parameters:
redactedChar
- character to replace already matched characters with- Returns:
- the redacted input
-
addMatch
Attaches the given match to all characters in the range.Note that the same match object repeated consecutively will be treated as a single match until it's interrupted.
- Parameters:
start
- start of range inclusiveend
- end of range exclusivematch
- match to assign- Returns:
- whether the match was successfully added. will return false if any character in this range is already matched or if the context is frozen.
-
getUnmatchedSequences
Gets all unmatched segments.For example, with the input string
texta :emote: textb
, if the:emote:
is matched, then this returns amap
with:map.size() == 2
,map.get(0) == "texta "
, andmap.get(13) == " textb"
- Returns:
- a map with unmatched segments as entries, their starting index as the key and the segment string as the value
-
getFinalText
String getFinalText()Gets the text with all matched characters replaced by placeholders for the length of the match. This is mostly for internal use.For example,
"texta :emote: textb"
with a single length match on":emote:"
would return"texta . textb"
- Returns:
-
getFinalStyledText
net.minecraft.text.Text getFinalStyledText()Gets the final text with the style baked into it already. This is mostly for internal use.- Returns:
-
getFinalMatches
Map<Integer,InlineMatch> getFinalMatches()Gets a map of all matches added. The key is the start index of the match in the string returned bygetFinalText()
, the value is the match. This is mostly for internal use.Note again that the same match object on consecutive characters will count as a single match.
- Returns:
-
getMatches
Map<Integer,InlineMatch> getMatches()Gets a map of all matches added. The key is the start index of the match in the original string input, the value is the match.- Returns:
-
origToFinal
int origToFinal(int orig) Converts the given index from its position in the original string to the corresponding position in the final string returned bygetFinalText()
- Parameters:
orig
- index to convert- Returns:
- the index in the final string.
-
finalToOrig
int finalToOrig(int fin) Converts the given index from its position in the final string returned bygetFinalText()
to the corresponding position in the original string.- Parameters:
fin
- index to convert- Returns:
- the index in the original string. If fin is a match then it returns the index of the first character matched in the original.
-