Fix remaining compiler errors

The italics test works so far
This commit is contained in:
Norbi Peti 2020-02-12 19:16:05 +01:00
parent 30ee99d495
commit 0dbfaa65a5
9 changed files with 83 additions and 49 deletions

View file

@ -88,5 +88,43 @@
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-core:2.8.1" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-core:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-api:2.8.1" level="project" /> <orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-api:2.8.1" level="project" />
<orderEntry type="library" name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:21.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: net.md-5:bungeecord-chat:1.12-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.github.TBMCPlugins.ChromaCore:Chroma-Core:master-8f6ee349de-1" 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.reflections:reflections:0.9.10" level="project" />
<orderEntry type="library" name="Maven: org.javassist:javassist:3.19.0-GA" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.ess3:EssentialsX:2.17.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: io.papermc:paperlib:1.0.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.ess3:NMSProvider:2.17.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.ess3:UpdatedMetaProvider:2.17.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.ess3:1_8_R1Provider:2.17.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.ess3:1_8_R2Provider:2.17.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.ess3:LegacyProvider:2.17.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.ess3:ReflectionProvider:2.17.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.ess3:FlattenedProvider:2.17.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.palmergames.bukkit.towny:Towny:0.95.2.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.milkbowl:VaultAPI:master-89c00e1cb8-1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot:1.12.2-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.github.webbukkit:Dynmap-Towny:master-0.60-g924051d-7" level="project" />
<orderEntry type="library" name="Maven: com.github.webbukkit:Dynmap:v2.5" level="project" />
<orderEntry type="library" name="Maven: com.nijikokun.bukkit:Permissions:3.1.6" level="project" />
<orderEntry type="library" name="Maven: org.bukkit:bukkit:1.7.10-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: ru.tehkode:PermissionsEx:1.19.1" level="project" />
<orderEntry type="library" name="Maven: de.bananaco:bPermissions:2.9.1" level="project" />
<orderEntry type="library" name="Maven: com.platymuus.bukkit.permissions:PermissionsBukkit:1.6" level="project" />
<orderEntry type="library" name="Maven: org.anjocaido:EssentialsGroupManager:2.10.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-core:2.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-api:2.8.1" level="project" />
</component> </component>
</module> </module>

View file

@ -16,7 +16,6 @@ import buttondevteam.lib.TBMCChatEvent;
import buttondevteam.lib.TBMCChatEventBase; import buttondevteam.lib.TBMCChatEventBase;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.Priority;
import buttondevteam.lib.chat.TellrawSerializableEnum; import buttondevteam.lib.chat.TellrawSerializableEnum;
import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.ChromaGamerBase;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
@ -40,21 +39,9 @@ import java.util.function.Predicate;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class ChatProcessing { public class ChatProcessing {
private static final Pattern NULL_MENTION_PATTERN = Pattern.compile("null");
private static final Pattern CYAN_PATTERN = Pattern.compile("cyan");
private static final Pattern ESCAPE_PATTERN = Pattern.compile("\\\\");
private static final Pattern CONSOLE_PING_PATTERN = Pattern.compile("(?i)" + Pattern.quote("@console"));
private static final Pattern HASHTAG_PATTERN = Pattern.compile("#(\\w+)"); private static final Pattern HASHTAG_PATTERN = Pattern.compile("#(\\w+)");
private static final Pattern URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),&]+(?:#[\\w]+)?)"); private static final Pattern URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),&]+(?:#[\\w]+)?)");
private static final Pattern UNDERLINED_PATTERN = Pattern.compile("__");
private static final Pattern ITALIC_PATTERN = Pattern.compile("\\*");
private static final Pattern ITALIC_PATTERN_2 = Pattern.compile("_");
private static final Pattern BOLD_PATTERN = Pattern.compile("\\*\\*");
private static final Pattern CODE_PATTERN = Pattern.compile("`");
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]]+)]\\(([^()]+)\\)"); private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]]+)]\\(([^()]+)\\)");
private static final Pattern SOMEONE_PATTERN = Pattern.compile("@someone");
private static final Pattern STRIKETHROUGH_PATTERN = Pattern.compile("~~");
private static final Pattern SPOILER_PATTERN = Pattern.compile("\\|\\|");
private static final Color[] RainbowPresserColors = new Color[]{Color.Red, Color.Gold, Color.Yellow, Color.Green, private static final Color[] RainbowPresserColors = new Color[]{Color.Red, Color.Gold, Color.Yellow, Color.Green,
Color.Blue, Color.DarkPurple}; Color.Blue, Color.DarkPurple};
private static final Pattern WORD_PATTERN = Pattern.compile("\\S+"); private static final Pattern WORD_PATTERN = Pattern.compile("\\S+");
@ -149,7 +136,7 @@ public class ChatProcessing {
ArrayList<MatchProviderBase> formatters; ArrayList<MatchProviderBase> formatters;
if (component.allowFormatting().get()) { if (component.allowFormatting().get()) {
formatters = addFormatters(colormode, e::shouldSendTo, component); formatters = addFormatters(e::shouldSendTo, component);
if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color
createRPC(colormode, formatters); createRPC(colormode, formatters);
} }
@ -159,7 +146,7 @@ public class ChatProcessing {
TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin()); TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin());
long combinetime = System.nanoTime(); long combinetime = System.nanoTime();
ChatFormatter.Combine(formatters, message, json, component.getConfig()); ChatFormatter.Combine(formatters, message, json, component.getConfig(), FormatSettings.builder().color(colormode).build());
combinetime = System.nanoTime() - combinetime; combinetime = System.nanoTime() - combinetime;
String jsonstr = toJson(json); String jsonstr = toJson(json);
if (jsonstr.length() >= 32767) { if (jsonstr.length() >= 32767) {
@ -204,12 +191,12 @@ public class ChatProcessing {
return false; return false;
} }
static void createRPC(Color colormode, ArrayList<ChatFormatter> formatters) { static void createRPC(Color colormode, ArrayList<MatchProviderBase> formatters) {
final AtomicInteger rpc = new AtomicInteger(0); final AtomicInteger rpc = new AtomicInteger(0);
formatters.add(ChatFormatter.builder("rpc", WORD_PATTERN).color(colormode).onmatch((match, cf, s) -> { formatters.add(new RegexMatchProvider("rpc", WORD_PATTERN, FormatSettings.builder().color(colormode).onmatch((match, cf, s) -> {
cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]); cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]);
return match; return match;
}).build()); }).build()));
} }
public static String toJson(TellrawPart json) { public static String toJson(TellrawPart json) {
@ -255,7 +242,7 @@ public class ChatProcessing {
+ "]"; + "]";
} }
static ArrayList<MatchProviderBase> addFormatters(Color colormode, Predicate<Player> canSee, @Nullable FormatterComponent component) { static ArrayList<MatchProviderBase> addFormatters(Predicate<Player> canSee, @Nullable FormatterComponent component) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<MatchProviderBase> formatters = (ArrayList<MatchProviderBase>) commonFormatters.clone(); ArrayList<MatchProviderBase> formatters = (ArrayList<MatchProviderBase>) commonFormatters.clone();
@ -268,18 +255,8 @@ public class ChatProcessing {
names = new String[testPlayers.length]; names = new String[testPlayers.length];
System.arraycopy(testPlayers, 0, names, 0, testPlayers.length); System.arraycopy(testPlayers, 0, names, 0, testPlayers.length);
} }
StringBuilder nicksb = new StringBuilder("(?i)("); String[] nicknames = Bukkit.getOnlinePlayers().stream().filter(canSee).map(Player::getUniqueId).map(PlayerListener.nicknames.inverse()::get)
boolean addNickFormatter = false; .filter(Objects::nonNull).toArray(String[]::new);
for (Player p : Bukkit.getOnlinePlayers()) {
if (!canSee.test(p)) continue;
final String nick = PlayerListener.nicknames.inverse().get(p.getUniqueId());
if (nick != null) {
nicksb.append(nick).append("|");
addNickFormatter = true;
}
}
nicksb.deleteCharAt(nicksb.length() - 1);
nicksb.append(")");
Consumer<String> error = message -> { Consumer<String> error = message -> {
if (PluginMain.Instance != null) if (PluginMain.Instance != null)
@ -289,7 +266,7 @@ public class ChatProcessing {
}; };
if (names.length > 0) if (names.length > 0)
formatters.add(ChatFormatter.builder("name", Pattern.compile(namesb.toString())).color(Color.Aqua) formatters.add(new StringMatchProvider("name", FormatSettings.builder().color(Color.Aqua)
.onmatch((match, builder, section) -> { .onmatch((match, builder, section) -> {
Player p = Bukkit.getPlayer(match); Player p = Bukkit.getPlayer(match);
Optional<String> pn = nottest ? Optional.empty() Optional<String> pn = nottest ? Optional.empty()
@ -304,10 +281,10 @@ public class ChatProcessing {
} }
String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor())); String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor()));
return color + (nottest ? p.getName() : pn.get()) + "§r"; //Fix name casing, except when testing return color + (nottest ? p.getName() : pn.get()) + "§r"; //Fix name casing, except when testing
}).priority(Priority.High).type(ChatFormatter.Type.Excluder).build()); }).build(), names));
if (addNickFormatter) if (nicknames.length > 0)
formatters.add(ChatFormatter.builder("nickname", Pattern.compile(nicksb.toString())).color(Color.Aqua) formatters.add(new StringMatchProvider("nickname", FormatSettings.builder().color(Color.Aqua)
.onmatch((match, builder, section) -> { .onmatch((match, builder, section) -> {
if (PlayerListener.nicknames.containsKey(match.toLowerCase())) { //Made a stream and all that but I can actually store it lowercased if (PlayerListener.nicknames.containsKey(match.toLowerCase())) { //Made a stream and all that but I can actually store it lowercased
Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match.toLowerCase())); Player p = Bukkit.getPlayer(PlayerListener.nicknames.get(match.toLowerCase()));
@ -322,7 +299,7 @@ public class ChatProcessing {
error.accept("Player nicknamed " + match.toLowerCase() error.accept("Player nicknamed " + match.toLowerCase()
+ " not found in nickname map but was reported as online."); + " not found in nickname map but was reported as online.");
return "§c" + match + "§r"; return "§c" + match + "§r";
}).priority(Priority.High).type(ChatFormatter.Type.Excluder).build()); }).build(), nicknames));
} }
return formatters; return formatters;
} }

View file

@ -25,7 +25,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<MatchProviderBase> formatters, String str, TellrawPart tp, IHaveConfig config) { public static void Combine(List<MatchProviderBase> formatters, String str, TellrawPart tp, IHaveConfig config, FormatSettings defaults) {
/* /*
* A global formatter is no longer needed * A global formatter is no longer needed
*/ */
@ -40,7 +40,7 @@ public final class ChatFormatter {
*/ */
val remchars = new ArrayList<int[]>(); val remchars = new ArrayList<int[]>();
createSections(formatters, str, sections, excluded, remchars); createSections(formatters, str, sections, excluded, remchars, defaults);
sortSections(sections); sortSections(sections);
header("Section combining"); header("Section combining");
@ -52,12 +52,18 @@ public final class ChatFormatter {
} }
private static void createSections(List<MatchProviderBase> formatters, String str, ArrayList<FormattedSection> sections, private static void createSections(List<MatchProviderBase> formatters, String str, ArrayList<FormattedSection> sections,
ArrayList<int[]> excludedAreas, ArrayList<int[]> removedCharacters) { ArrayList<int[]> excludedAreas, ArrayList<int[]> removedCharacters, FormatSettings defaults) {
sections.add(new FormattedSection(FormatSettings.builder().color(Color.White).build(), 0, str.length() - 1, Collections.emptyList())); //Add entire message sections.add(new FormattedSection(defaults, 0, str.length() - 1, Collections.emptyList())); //Add entire message
for (var formatter : formatters) { while (formatters.size() > 0) {
var sect = formatter.getNextSection(str, excludedAreas, removedCharacters); for (var iterator = formatters.iterator(); iterator.hasNext(); ) {
if (sect != null) MatchProviderBase formatter = iterator.next();
sections.add(sect); DebugCommand.SendDebugMessage("Checking provider: " + formatter);
var sect = formatter.getNextSection(str, excludedAreas, removedCharacters);
if (sect != null)
sections.add(sect);
if (formatter.isFinished())
iterator.remove();
}
} }
} }

View file

@ -1,8 +1,11 @@
package buttondevteam.chat.components.formatter.formatting; package buttondevteam.chat.components.formatter.formatting;
import lombok.ToString;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ToString
public class FormattedSection { public class FormattedSection {
public int Start; public int Start;
public int End; public int End;

View file

@ -19,6 +19,9 @@ public abstract class MatchProviderBase implements MatchProvider {
@Override @Override
public abstract FormattedSection getNextSection(String message, ArrayList<int[]> ignoredAreas, ArrayList<int[]> removedCharacters); public abstract FormattedSection getNextSection(String message, ArrayList<int[]> ignoredAreas, ArrayList<int[]> removedCharacters);
@Override
public abstract String toString();
ConfigData<Boolean> enabled(IHaveConfig config) { ConfigData<Boolean> enabled(IHaveConfig config) {
return config.getData(name + ".enabled", true); return config.getData(name + ".enabled", true);
} }

View file

@ -1,12 +1,15 @@
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.ToString;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ToString
public class RangeMatchProvider extends MatchProviderBase { public class RangeMatchProvider extends MatchProviderBase {
private final String pattern; private final String pattern;
@ToString.Exclude
private final FormatSettings settings; private final FormatSettings settings;
private int nextIndex = 0; private int nextIndex = 0;
private FormattedSection startedSection; private FormattedSection startedSection;

View file

@ -1,14 +1,17 @@
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.ToString;
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;
@ToString
public class RegexMatchProvider extends MatchProviderBase { public class RegexMatchProvider extends MatchProviderBase {
private final Pattern pattern; private final Pattern pattern;
@ToString.Exclude
private final FormatSettings settings; private final FormatSettings settings;
private Matcher matcher; private Matcher matcher;

View file

@ -1,13 +1,16 @@
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.ToString;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ToString
public class StringMatchProvider extends MatchProviderBase { public class StringMatchProvider extends MatchProviderBase {
private final String[] strings; private final String[] strings;
@ToString.Exclude
private final FormatSettings settings; private final FormatSettings settings;
private int nextIndex = 0; private int nextIndex = 0;

View file

@ -5,11 +5,9 @@ import buttondevteam.chat.ObjectTestRunner;
import buttondevteam.chat.ObjectTestRunner.Objects; import buttondevteam.chat.ObjectTestRunner.Objects;
import buttondevteam.chat.PluginMain; import buttondevteam.chat.PluginMain;
import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
import buttondevteam.chat.components.formatter.formatting.ChatFormatter; import buttondevteam.chat.components.formatter.formatting.*;
import buttondevteam.chat.components.formatter.formatting.TellrawEvent;
import buttondevteam.chat.components.formatter.formatting.TellrawEvent.ClickAction; import buttondevteam.chat.components.formatter.formatting.TellrawEvent.ClickAction;
import buttondevteam.chat.components.formatter.formatting.TellrawEvent.HoverAction; import buttondevteam.chat.components.formatter.formatting.TellrawEvent.HoverAction;
import buttondevteam.chat.components.formatter.formatting.TellrawPart;
import buttondevteam.core.TestPrepare; import buttondevteam.core.TestPrepare;
import buttondevteam.core.component.channel.Channel; import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
@ -109,12 +107,12 @@ public class ChatFormatIT {
@Test @Test
public void testMessage() { public void testMessage() {
ArrayList<ChatFormatter> cfs = ChatProcessing.addFormatters(Color.White, p -> true, null); ArrayList<MatchProviderBase> cfs = ChatProcessing.addFormatters(p -> true, null);
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatUtils.MCORIGIN); final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatUtils.MCORIGIN);
if (rainbowMode) if (rainbowMode)
ChatProcessing.createRPC(Color.White, cfs); ChatProcessing.createRPC(Color.White, cfs);
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN); final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);
ChatFormatter.Combine(cfs, message, tp, null); ChatFormatter.Combine(cfs, message, tp, null, FormatSettings.builder().color(Color.White).build());
System.out.println("Testing: " + message); System.out.println("Testing: " + message);
// System.out.println(ChatProcessing.toJson(tp)); // System.out.println(ChatProcessing.toJson(tp));
final TellrawPart expectedtp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN); final TellrawPart expectedtp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);