GH Releases, formatter work, removed old code

TBMCPlugins/ChromaCore#76
This commit is contained in:
Norbi Peti 2020-02-10 13:46:39 +01:00
parent 0a4cdd01ce
commit 1dc801575a
10 changed files with 122 additions and 219 deletions

View file

@ -19,7 +19,7 @@
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.0" level="project" /> <orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.19" level="project" /> <orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.19" level="project" />
<orderEntry type="library" name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT" level="project" /> <orderEntry type="library" name="Maven: net.md-5:bungeecord-chat:1.12-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.github.TBMCPlugins.ButtonCore:ButtonCore:master-d48a2d17d3-1" level="project" /> <orderEntry type="library" name="Maven: com.github.TBMCPlugins.ChromaCore:Chroma-Core:master-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: net.sourceforge.htmlcleaner:htmlcleaner:2.16" level="project" /> <orderEntry type="library" name="Maven: net.sourceforge.htmlcleaner:htmlcleaner:2.16" level="project" />
<orderEntry type="library" name="Maven: org.jdom:jdom2:2.0.5" level="project" /> <orderEntry type="library" name="Maven: org.jdom:jdom2:2.0.5" level="project" />
<orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" /> <orderEntry type="library" name="Maven: org.reflections:reflections:0.9.10" level="project" />

View file

@ -13,15 +13,10 @@ jdk:
sudo: true sudo: true
dist: trusty # Needed for Java 8, although we might not need Java 8 dist: trusty # Needed for Java 8, although we might not need Java 8
deploy: deploy:
# deploy develop to the staging environment - provider: releases
- provider: script api_key:
script: chmod +x deploy.sh && sh deploy.sh staging secure: "F5YiEuD6LyRENUDMCslcSl0O0dg4IDk+nNeb4X2VLYlmb8dW9beMuIgjH8efTMeaQ3D/ntIkN0Dtf2GKvpOduhwkSbAgw4WM028X60SY9f2hmpEO3LmM4T1tKoDlI1T3BmhYP4KeTKBYn+etV1mSPbT07vUybCm/vGzvr96yMZGNFEoKsWLaEu7dZfBFULj4tXOwrLh/KO6BsdAHvZcGKWNVupPq3YoUVT0dpGcUudf5cpn+aaqMwyd709zgMbyCuqf+c5Udps43q4EKvr9z7TWxFUkGTPVVAcUVygJsi2ytuyA8TLMPq/KhYe9htnkNUnizbqv/j49xww0gVaD7OJXENJ4hAUTV4sdn1DXG45JXW+dir3V7YzbRYn3M+eCuKB2O77SXRZBkxcGtTMtCmghP9/tcRAQlXDXnxu7oAnlUVp17g/+aFApvlzZEZVx2N+fkyEe7JrUFlRCixtHyrmTLWhyV0Px9p0FHJpvSSCL0S0UKVAT/sNHYHhD5gouK7owEomEbG58XCsRDH6Et7RuDksB98ekK8brZp6S7dNIS2CVuVx1vIkXC8PzUGcpJQoztvEYUE20Axahh5s8AkE9n/O9jzs9ajcfYaHhWzYeUZzHdHllOYF9l6VoCUitTk4Sl8eJifSq3GzI+T6wGMBepZHLpe230MvBIrqGZ+Vg="
file: 'Chroma-Core/target/Chroma-Core.jar'
on: on:
branch: dev tags: true
skip_cleanup: true
# deploy master to production
- provider: script
script: chmod +x deploy.sh && sh deploy.sh production
on:
branch: master
skip_cleanup: true skip_cleanup: true

View file

@ -1,8 +1,6 @@
package buttondevteam.chat.components.formatter.formatting; package buttondevteam.chat.components.formatter.formatting;
import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
import buttondevteam.chat.components.formatter.ChatProcessing;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.IHaveConfig; import buttondevteam.lib.architecture.IHaveConfig;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
import lombok.Builder; import lombok.Builder;
@ -11,7 +9,6 @@ import lombok.val;
import java.util.*; import java.util.*;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -21,35 +18,10 @@ import java.util.stream.Collectors;
* *
* @author NorbiPeti * @author NorbiPeti
*/ */
@SuppressWarnings("UnusedAssignment")
@Data @Data
@Builder @Builder
public final class ChatFormatter { public final class ChatFormatter {
Pattern regex; private ChatFormatter() {
@Builder.Default
short removeCharCount = 0;
@Builder.Default
Type type = Type.Normal;
String hoverText;
String name;
@Override
public String toString() {
return "ChatFormatter{" +
"name='" + name + '\'' +
'}';
}
public static ChatFormatterBuilder builder(String name, Pattern regex) {
return builder().regex(regex).name(name);
}
private static ChatFormatterBuilder builder() {
return new ChatFormatterBuilder();
}
private ConfigData<Boolean> enabled(IHaveConfig config) {
return config.getData(name + ".enabled", true);
} }
@FunctionalInterface @FunctionalInterface
@ -57,7 +29,7 @@ public final class ChatFormatter {
R apply(T1 x1, T2 x2, T3 x3); R apply(T1 x1, T2 x2, T3 x3);
} }
public static void Combine(List<ChatFormatter> formatters, String str, TellrawPart tp, IHaveConfig config) { public static void Combine(List<MatchProviderBase> formatters, String str, TellrawPart tp, IHaveConfig config) {
/* /*
* This method assumes that there is always a global formatter * This method assumes that there is always a global formatter
*/ */
@ -66,22 +38,14 @@ public final class ChatFormatter {
if (config != null) //null if testing if (config != null) //null if testing
formatters.removeIf(cf -> !cf.enabled(config).get()); //Remove disabled formatters formatters.removeIf(cf -> !cf.enabled(config).get()); //Remove disabled formatters
createSections(formatters, str, sections, true); var excluded = new ArrayList<int[]>();
header("Section creation (excluders done)");
createSections(formatters, str, sections, false);
sortSections(sections);
/* /*
* 0: Start - 1: End index * 0: Start - 1: End index
*/ */
val remchars = new ArrayList<int[]>(); val remchars = new ArrayList<int[]>();
header("Range section creation"); createSections(formatters, str, sections, excluded, remchars);
sections = createRangeSections(str, sections, formatters, remchars); sortSections(sections);
header("Adding remove chars (RC)"); // Important to add after the range section conversion
addRemChars(sections, remchars, str);
header("Section combining"); header("Section combining");
combineSections(str, sections); combineSections(str, sections);
@ -91,123 +55,16 @@ public final class ChatFormatter {
header("ChatFormatter.Combine done"); header("ChatFormatter.Combine done");
} }
private static void createSections(List<ChatFormatter> formatters, String str, ArrayList<FormattedSection> sections, private static void createSections(List<MatchProviderBase> formatters, String str, ArrayList<FormattedSection> sections,
boolean excluders) { ArrayList<int[]> excludedAreas, ArrayList<int[]> removedCharacters) {
} sections.add(new FormattedSection(FormatSettings.builder().color(Color.White).build(), 0, str.length() - 1, Collections.emptyList()));
for (var formatter : formatters) {
private static void newCombine(String str, ArrayList<FormattedSection> sections, ArrayList<int[]> remchars) { var sect = formatter.getNextSection(str, excludedAreas, removedCharacters);
var stack = new Stack<FormattedSection>(); if (sect != null)
for (int i = 0; i < str.length(); i++) { sections.add(sect);
for (Iterator<FormattedSection> iterator = sections.iterator(); iterator.hasNext(); ) {
FormattedSection section = iterator.next();
if (section.Start <= i) {
stack.push(section);
iterator.remove();
}
}
} }
} }
private static ArrayList<FormattedSection> createRangeSections(String str, List<ChatFormatter> formatters, ArrayList<int[]> remchars) {
ArrayList<FormattedSection> combined = new ArrayList<>();
Map<ChatFormatter, FormattedSection> nextSection = new HashMap<>();
boolean escaped = false;
int takenStart = -1, takenEnd = -1;
ChatFormatter takenFormatter = null;
boolean takenByBigGuy = false; //Can't win against him (finished sections take precedence)
for (final FormattedSection section : sections) {
// Set ending to -1 until closed with another 1 long "section" - only do this if IsRange is true
if (section.type != Type.Range) {
escaped = section.Formatters.contains(ChatProcessing.ESCAPE_FORMATTER) && !escaped; // Enable escaping on first \, disable on second
if (escaped) {// Don't add the escape character
remchars.add(new int[]{section.Start, section.Start});
DebugCommand.SendDebugMessage("Found escaper section: " + section);
} else {
combined.add(section); // The above will delete the \
DebugCommand.SendDebugMessage("Added section: " + section);
}
ChatFormatUtils.sendMessageWithPointer(str, section.Start, section.End);
continue;
}
if (!escaped) {
ChatFormatter formatter = section.Formatters.get(0);
if (section.Start == takenStart || (section.Start > takenStart && section.Start < takenEnd)) {
/*
* if (nextSection.containsKey(section.Formatters.get(0)) ? section.RemCharFromStart <= takenEnd - takenStart : section.RemCharFromStart > takenEnd - takenStart) {
*/
if (takenByBigGuy || formatter.removeCharCount < takenEnd - takenStart) {
DebugCommand.SendDebugMessage("Lose: " + section);
ChatFormatUtils.sendMessageWithPointer(str, section.Start, section.End);
DebugCommand.SendDebugMessage("And win: " + takenFormatter);
continue; // The current section loses
}
nextSection.remove(takenFormatter); // The current section wins
DebugCommand.SendDebugMessage("Win: " + section);
ChatFormatUtils.sendMessageWithPointer(str, section.Start, section.End);
DebugCommand.SendDebugMessage("And lose: " + takenFormatter);
}
boolean hasFormatter = nextSection.containsKey(formatter);
/*if (!hasFormatter) {
val ff = formatter;
val cfo = nextSection.keySet().stream().filter(f -> f.removeCharCount > ff.removeCharCount).findAny();
if (cfo.isPresent()) {
//formatter = cfo.get();
val s = nextSection.get(cfo.get());
int takenS = section.Start, takenE = section.Start + formatter.removeCharCount;
if (s.Start == takenS || (s.Start > takenS && s.Start < takenE)) { //Peek()
hasFormatter = true;
continue; //Not the formatter we're looking for - TODO: It doesn't fix the problem of italics at the end
}
}
}*/
takenStart = section.Start;
takenEnd = section.Start + formatter.removeCharCount;
takenFormatter = formatter;
if (hasFormatter) {
FormattedSection s = nextSection.remove(formatter);
//HACK? If we can find another section that removes more characters, finish that instead
// section: the ending marker section - s: the to-be full section
s.End = takenEnd - 1; //Take the remCharCount into account as well
// s.IsRange = false; // IsRange means it's a 1 long section indicating a start or an end
combined.add(s);
takenByBigGuy = true;
DebugCommand.SendDebugMessage("Finished section: " + s);
ChatFormatUtils.sendMessageWithPointer(str, s.Start, s.End);
} else {
DebugCommand.SendDebugMessage("Adding next section: " + section);
ChatFormatUtils.sendMessageWithPointer(str, section.Start, section.End);
nextSection.put(formatter, section);
takenByBigGuy = false;
}
DebugCommand
.SendDebugMessage("New area taken: (" + takenStart + "-" + takenEnd + ") " + takenFormatter);
ChatFormatUtils.sendMessageWithPointer(str, takenStart, takenEnd);
} else {
DebugCommand.SendDebugMessage("Skipping section: " + section); // This will keep the text (character)
ChatFormatUtils.sendMessageWithPointer(str, section.Start, section.End);
escaped = false; // Reset escaping if applied, like if we're at the '*' in '\*'
}
}
//Do not finish unfinished sections, ignore them
sections = combined;
return sections;
}
private static void addRemChars(ArrayList<FormattedSection> sections, ArrayList<int[]> remchars, String str) {
sections.stream()
.flatMap(fs -> fs.Formatters.stream().filter(cf -> cf.removeCharCount > 0)
.mapToInt(cf -> cf.removeCharCount).mapToObj(rcc -> new int[]{fs.Start, fs.Start + rcc - 1}))
.forEach(remchars::add);
sections.stream()
.flatMap(fs -> fs.Formatters.stream().filter(cf -> cf.removeCharCount > 0)
.mapToInt(cf -> cf.removeCharCount).mapToObj(rcc -> new int[]{fs.End - rcc + 1, fs.End}))
.forEach(remchars::add);
DebugCommand.SendDebugMessage("Added remchars:");
DebugCommand.SendDebugMessage(remchars.stream().map(Arrays::toString).collect(Collectors.joining("; ")));
ChatFormatUtils.sendMessageWithPointer(str,
remchars.stream().flatMapToInt(Arrays::stream).toArray());
}
private static void combineSections(String str, ArrayList<FormattedSection> sections) { private static void combineSections(String str, ArrayList<FormattedSection> sections) {
for (int i = 1; i < sections.size(); i++) { for (int i = 1; i < sections.size(); i++) {
DebugCommand.SendDebugMessage("i: " + i); DebugCommand.SendDebugMessage("i: " + i);
@ -229,9 +86,8 @@ public final class ChatFormatter {
DebugCommand.SendDebugMessage(" and " + lastSection); DebugCommand.SendDebugMessage(" and " + lastSection);
ChatFormatUtils.sendMessageWithPointer(str, lastSection.Start, lastSection.End); ChatFormatUtils.sendMessageWithPointer(str, lastSection.Start, lastSection.End);
if (firstSection.Start == lastSection.Start && firstSection.End == lastSection.End) { if (firstSection.Start == lastSection.Start && firstSection.End == lastSection.End) {
firstSection.Formatters.addAll(lastSection.Formatters); firstSection.Settings.copyFrom(lastSection.Settings);
firstSection.Matches.addAll(lastSection.Matches); firstSection.Matches.addAll(lastSection.Matches);
firstSection.type = lastSection.type;
DebugCommand.SendDebugMessage("To section " + firstSection); DebugCommand.SendDebugMessage("To section " + firstSection);
ChatFormatUtils.sendMessageWithPointer(str, firstSection.Start, firstSection.End); ChatFormatUtils.sendMessageWithPointer(str, firstSection.Start, firstSection.End);
sections.remove(i); sections.remove(i);
@ -242,14 +98,13 @@ public final class ChatFormatter {
int origend2 = firstSection.End; int origend2 = firstSection.End;
firstSection.End = lastSection.Start - 1; firstSection.End = lastSection.Start - 1;
int origend = lastSection.End; int origend = lastSection.End;
FormattedSection section = new FormattedSection(firstSection.Formatters, lastSection.Start, origend, FormattedSection section = new FormattedSection(firstSection.Settings, lastSection.Start, origend,
firstSection.Matches, Type.Normal); firstSection.Matches);
section.Formatters.addAll(lastSection.Formatters); section.Settings.copyFrom(lastSection.Settings);
section.Matches.addAll(lastSection.Matches); // TODO: Clean section.Matches.addAll(lastSection.Matches); // TODO: Clean
sections.add(i, section); sections.add(i, section);
// Use the properties of the first section not the second one // Use the properties of the first section not the second one
lastSection.Formatters.clear(); lastSection.Settings = firstSection.Settings;
lastSection.Formatters.addAll(firstSection.Formatters);
lastSection.Matches.clear(); lastSection.Matches.clear();
lastSection.Matches.addAll(firstSection.Matches); lastSection.Matches.addAll(firstSection.Matches);
@ -331,29 +186,28 @@ public final class ChatFormatter {
} }
DebugCommand.SendDebugMessage("Section text: " + originaltext); DebugCommand.SendDebugMessage("Section text: " + originaltext);
String openlink = null; String openlink = null;
section.Formatters.sort(Comparator.comparing(cf2 -> cf2.priority.GetValue())); //Apply the highest last, to overwrite previous ones //section.Formatters.sort(Comparator.comparing(cf2 -> cf2.priority.GetValue())); //Apply the highest last, to overwrite previous ones
TellrawPart newtp = new TellrawPart(""); TellrawPart newtp = new TellrawPart("");
for (ChatFormatter formatter : section.Formatters) { var settings = section.Settings;
DebugCommand.SendDebugMessage("Applying formatter: " + formatter); DebugCommand.SendDebugMessage("Applying settings: " + settings);
if (formatter.onmatch != null) if (settings.onmatch != null)
originaltext = formatter.onmatch.apply(originaltext, formatter, section); originaltext = settings.onmatch.apply(originaltext, settings, section);
if (formatter.color != null) if (settings.color != null)
newtp.setColor(formatter.color); newtp.setColor(settings.color);
if (formatter.bold) if (settings.bold)
newtp.setBold(true); newtp.setBold(true);
if (formatter.italic) if (settings.italic)
newtp.setItalic(true); newtp.setItalic(true);
if (formatter.underlined) if (settings.underlined)
newtp.setUnderlined(true); newtp.setUnderlined(true);
if (formatter.strikethrough) if (settings.strikethrough)
newtp.setStrikethrough(true); newtp.setStrikethrough(true);
if (formatter.obfuscated) if (settings.obfuscated)
newtp.setObfuscated(true); newtp.setObfuscated(true);
if (formatter.openlink != null) if (settings.openlink != null)
openlink = formatter.openlink; openlink = settings.openlink;
if (formatter.hoverText != null) if (settings.hoverText != null)
newtp.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, formatter.hoverText)); newtp.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, settings.hoverText));
}
if (lasttp != null && newtp.getColor() == lasttp.getColor() if (lasttp != null && newtp.getColor() == lasttp.getColor()
&& newtp.isBold() == lasttp.isBold() && newtp.isBold() == lasttp.isBold()
&& newtp.isItalic() == lasttp.isItalic() && newtp.isItalic() == lasttp.isItalic()
@ -381,8 +235,7 @@ public final class ChatFormatter {
private static void sortSections(ArrayList<FormattedSection> sections) { private static void sortSections(ArrayList<FormattedSection> sections) {
sections.sort( sections.sort(
(s1, s2) -> s1.Start == s2.Start (s1, s2) -> s1.Start == s2.Start
? s1.End == s2.End ? Integer.compare(s2.Formatters.get(0).priority.GetValue(), ? s1.End == s2.End ? 0 : Integer.compare(s1.End, s2.End) //TODO: Test
s1.Formatters.get(0).priority.GetValue()) : Integer.compare(s1.End, s2.End)
: Integer.compare(s1.Start, s2.Start)); : Integer.compare(s1.Start, s2.Start));
} }

View file

@ -13,6 +13,19 @@ public class FormatSettings {
boolean strikethrough; boolean strikethrough;
boolean obfuscated; boolean obfuscated;
Color color; Color color;
ChatFormatter.TriFunc<String, ChatFormatter, FormattedSection, String> onmatch; ChatFormatter.TriFunc<String, FormatSettings, FormattedSection, String> onmatch;
String openlink; String openlink;
String hoverText;
public void copyFrom(FormatSettings settings) {
try {
for (var field : FormatSettings.class.getDeclaredFields())
if (field.getType() == boolean.class && field.getBoolean(settings))
field.setBoolean(this, true); //Set to true if either of them are true
else if (field.get(this) == null)
field.set(this, field.get(settings));
} catch (Exception e) {
e.printStackTrace();
}
}
} }

View file

@ -1,14 +1,15 @@
package buttondevteam.chat.components.formatter.formatting; package buttondevteam.chat.components.formatter.formatting;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class FormattedSection { public class FormattedSection {
public int Start; public int Start;
public int End; public int End;
public FormatSettings Settings; public FormatSettings Settings;
public ArrayList<String> Matches = new ArrayList<String>(); public List<String> Matches = new ArrayList<String>();
FormattedSection(FormatSettings settings, int start, int end, ArrayList<String> matches) { FormattedSection(FormatSettings settings, int start, int end, List<String> matches) {
Start = start; Start = start;
End = end; End = end;
Settings = settings; Settings = settings;

View file

@ -8,4 +8,6 @@ public interface MatchProvider {
FormattedSection getNextSection(String message, ArrayList<int[]> ignoredAreas, ArrayList<int[]> removedCharacters); FormattedSection getNextSection(String message, ArrayList<int[]> ignoredAreas, ArrayList<int[]> removedCharacters);
boolean isFinished(); boolean isFinished();
String getName();
} }

View file

@ -0,0 +1,26 @@
package buttondevteam.chat.components.formatter.formatting;
import buttondevteam.lib.architecture.ConfigData;
import buttondevteam.lib.architecture.IHaveConfig;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import javax.annotation.Nullable;
import java.util.ArrayList;
@RequiredArgsConstructor
public abstract class MatchProviderBase implements MatchProvider {
@Getter
protected boolean finished;
@Getter
private final String name;
@Nullable
@Override
public abstract FormattedSection getNextSection(String message, ArrayList<int[]> ignoredAreas, ArrayList<int[]> removedCharacters);
ConfigData<Boolean> enabled(IHaveConfig config) {
return config.getData(name + ".enabled", true);
}
}

View file

@ -1,19 +1,22 @@
package buttondevteam.chat.components.formatter.formatting; package buttondevteam.chat.components.formatter.formatting;
import lombok.Getter; import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
import lombok.RequiredArgsConstructor;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
@RequiredArgsConstructor public class RangeMatchProvider extends MatchProviderBase {
public class RangeMatchProvider implements MatchProvider {
private final String pattern; private final String pattern;
private final FormatSettings settings; private final FormatSettings settings;
@Getter
private boolean finished;
private int nextIndex = 0; private int nextIndex = 0;
private FormattedSection startedSection; private FormattedSection startedSection;
public RangeMatchProvider(String name, String pattern, FormatSettings settings) {
super(name);
this.pattern = pattern;
this.settings = settings;
}
@SuppressWarnings("DuplicatedCode") @SuppressWarnings("DuplicatedCode")
@Override @Override
public FormattedSection getNextSection(String message, ArrayList<int[]> ignoredAreas, ArrayList<int[]> removedCharacters) { public FormattedSection getNextSection(String message, ArrayList<int[]> ignoredAreas, ArrayList<int[]> removedCharacters) {
@ -29,9 +32,15 @@ public class RangeMatchProvider implements MatchProvider {
} }
removedCharacters.add(new int[]{i, i + len - 1}); removedCharacters.add(new int[]{i, i + len - 1});
if (startedSection == null) { if (startedSection == null) {
startedSection = new FormattedSection(settings, i, i + len - 1, new ArrayList<>(0)); DebugCommand.SendDebugMessage("Started range match from " + i + " to " + (i + len - 1));
DebugCommand.SendDebugMessage("With settings: " + settings);
ChatFormatUtils.sendMessageWithPointer(message, i, i + len - 1);
startedSection = new FormattedSection(settings, i, i + len - 1, Collections.emptyList());
return null; return null;
} else { } else {
DebugCommand.SendDebugMessage("Finished range match from " + i + " to " + (i + len - 1));
DebugCommand.SendDebugMessage("With settings: " + settings);
ChatFormatUtils.sendMessageWithPointer(message, i, i + len - 1);
startedSection.End = i + len - 1; startedSection.End = i + len - 1;
return startedSection; return startedSection;
} }

View file

@ -1,21 +1,22 @@
package buttondevteam.chat.components.formatter.formatting; package buttondevteam.chat.components.formatter.formatting;
import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@RequiredArgsConstructor public class RegexMatchProvider extends MatchProviderBase {
public class RegexMatchProvider implements MatchProvider {
private final Pattern pattern; private final Pattern pattern;
private final FormatSettings settings; private final FormatSettings settings;
private Matcher matcher; private Matcher matcher;
@Getter
private boolean finished; public RegexMatchProvider(String name, Pattern pattern, FormatSettings settings) {
super(name);
this.pattern = pattern;
this.settings = settings;
}
@Nullable @Nullable
@Override @Override

View file

@ -1,15 +1,14 @@
package buttondevteam.chat.components.formatter.formatting; package buttondevteam.chat.components.formatter.formatting;
import lombok.Getter; import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
public class StringMatchProvider implements MatchProvider { public class StringMatchProvider extends MatchProviderBase {
private final String[] strings; private final String[] strings;
private final FormatSettings settings; private final FormatSettings settings;
@Getter
private boolean finished;
private int nextIndex = 0; private int nextIndex = 0;
/** /**
@ -18,7 +17,8 @@ public class StringMatchProvider implements MatchProvider {
* @param settings The format settings * @param settings The format settings
* @param strings The strings to match in the correct order * @param strings The strings to match in the correct order
*/ */
public StringMatchProvider(FormatSettings settings, String... strings) { public StringMatchProvider(String name, FormatSettings settings, String... strings) {
super(name);
this.settings = settings; this.settings = settings;
this.strings = strings; this.strings = strings;
} }
@ -37,6 +37,9 @@ public class StringMatchProvider implements MatchProvider {
return null; return null;
} }
nextIndex = i + len; nextIndex = i + len;
return new FormattedSection(settings, i, i + len - 1, new ArrayList<>(0)); DebugCommand.SendDebugMessage("Found string match from " + i + " to " + (i + len - 1));
DebugCommand.SendDebugMessage("With settings: " + settings);
ChatFormatUtils.sendMessageWithPointer(message, i, i + len - 1);
return new FormattedSection(settings, i, i + len - 1, Collections.emptyList());
} }
} }