Removed RC messages, fixed URLs probably
#63 Added URL test Smaller refactors
This commit is contained in:
parent
1c32dbd949
commit
437d9e8f98
5 changed files with 71 additions and 60 deletions
|
@ -52,8 +52,7 @@ public class ChatProcessing {
|
||||||
new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN).setUnderlined(true).setRemoveCharCount((short) 1)
|
new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN).setUnderlined(true).setRemoveCharCount((short) 1)
|
||||||
.setRange(true).build(),
|
.setRange(true).build(),
|
||||||
ESCAPE_FORMATTER,
|
ESCAPE_FORMATTER,
|
||||||
new ChatFormatterBuilder().setRegex(URL_PATTERN).setUnderlined(true).setOpenlink("$1").setRange(true)
|
new ChatFormatterBuilder().setRegex(URL_PATTERN).setUnderlined(true).setOpenlink("$1").build(),
|
||||||
.build(),
|
|
||||||
new ChatFormatterBuilder().setRegex(NULL_MENTION_PATTERN).setColor(Color.DarkRed).build(), // Properly added a bug as a feature
|
new ChatFormatterBuilder().setRegex(NULL_MENTION_PATTERN).setColor(Color.DarkRed).build(), // Properly added a bug as a feature
|
||||||
new ChatFormatterBuilder().setRegex(CONSOLE_PING_PATTERN).setColor(Color.Aqua)
|
new ChatFormatterBuilder().setRegex(CONSOLE_PING_PATTERN).setColor(Color.Aqua)
|
||||||
.setOnmatch((match, builder) ->
|
.setOnmatch((match, builder) ->
|
||||||
|
@ -162,53 +161,60 @@ public class ChatProcessing {
|
||||||
final String channelidentifier) {
|
final String channelidentifier) {
|
||||||
TellrawPart json = new TellrawPart("");
|
TellrawPart json = new TellrawPart("");
|
||||||
if (mp != null && mp.ChatOnly) {
|
if (mp != null && mp.ChatOnly) {
|
||||||
json.addExtra(new TellrawPart("[C]").setHoverEvent(
|
json.addExtra(new TellrawPart("[C]")
|
||||||
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
|
||||||
}
|
}
|
||||||
json.addExtra(
|
json.addExtra(
|
||||||
new TellrawPart(channelidentifier)
|
new TellrawPart(channelidentifier)
|
||||||
.setHoverEvent(
|
.setHoverEvent(
|
||||||
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT,
|
||||||
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
|
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
|
||||||
+ "Copy message").setColor(Color.Blue)))
|
+ "Copy message").setColor(Color.Blue)))
|
||||||
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC,
|
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
||||||
TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
|
|
||||||
json.addExtra(new TellrawPart(" <"));
|
json.addExtra(new TellrawPart(" <"));
|
||||||
json.addExtra(
|
json.addExtra(
|
||||||
new TellrawPart(
|
new TellrawPart(
|
||||||
(player != null ? player.getDisplayName() : sender.getName()))
|
(player != null ? player.getDisplayName()
|
||||||
.setHoverEvent(
|
: sender.getName()))
|
||||||
TellrawEvent
|
.setHoverEvent(
|
||||||
.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
TellrawEvent
|
||||||
new TellrawPart("")
|
.create(TellrawEvent.HoverAction.SHOW_TEXT,
|
||||||
.addExtra(new TellrawPart(String.format("Flair: %s",
|
new TellrawPart("")
|
||||||
(mp != null ? mp.GetFormattedFlair() : "-"))))
|
.addExtra(new TellrawPart(String.format(
|
||||||
.addExtra(new TellrawPart(
|
"Flair: %s",
|
||||||
String.format("\nPlayername: %s\n",
|
(mp != null ? mp.GetFormattedFlair()
|
||||||
|
: "-"))))
|
||||||
|
.addExtra(new TellrawPart(String.format(
|
||||||
|
"\nPlayername: %s\n",
|
||||||
(player != null ? player.getName()
|
(player != null ? player.getName()
|
||||||
: sender.getName())))
|
: sender.getName())))
|
||||||
.setColor(Color.Aqua))
|
.setColor(Color.Aqua))
|
||||||
.addExtra(new TellrawPart(String.format("World: %s\n",
|
.addExtra(new TellrawPart(String.format(
|
||||||
(player != null ? player.getWorld().getName()
|
"World: %s\n",
|
||||||
: "-"))))
|
(player != null
|
||||||
.addExtra(new TellrawPart(String.format(
|
? player.getWorld().getName()
|
||||||
"Respect: %s%s%s",
|
: "-"))))
|
||||||
(mp != null
|
.addExtra(new TellrawPart(String.format(
|
||||||
? (mp.FCount().get()
|
"Respect: %s%s%s",
|
||||||
|
(mp != null ? (mp.FCount().get()
|
||||||
/ (double) mp.FDeaths().get())
|
/ (double) mp.FDeaths().get())
|
||||||
: "Infinite"),
|
: "Infinite"),
|
||||||
(mp != null && mp.UserName().get() != null
|
(mp != null
|
||||||
&& !mp.UserName().get().isEmpty()
|
&& mp.UserName().get() != null
|
||||||
? "\nUserName: "
|
&& !mp.UserName().get()
|
||||||
+ mp.UserName().get()
|
.isEmpty()
|
||||||
: ""),
|
? "\nUserName: "
|
||||||
(mp != null && mp.PlayerName().get()
|
+ mp.UserName()
|
||||||
.equals("\nAlpha_Bacca44")
|
.get()
|
||||||
? "\nDeaths: "
|
: ""),
|
||||||
+ PlayerListener.AlphaDeaths
|
(mp != null && mp.PlayerName().get()
|
||||||
: ""))))
|
.equals("\nAlpha_Bacca44")
|
||||||
.addExtra(new TellrawPart("\nFor more, do /u info "
|
? "\nDeaths: "
|
||||||
+ sender.getName())))));
|
+ PlayerListener.AlphaDeaths
|
||||||
|
: ""))))
|
||||||
|
.addExtra(new TellrawPart(
|
||||||
|
"\nFor more, do /u info "
|
||||||
|
+ sender.getName())))));
|
||||||
json.addExtra(new TellrawPart("> "));
|
json.addExtra(new TellrawPart("> "));
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
|
||||||
setupEconomy();
|
setupEconomy();
|
||||||
setupPermissions();
|
setupPermissions();
|
||||||
|
|
||||||
new Thread(() -> FlairGetterThreadMethod()).start();
|
new Thread(this::FlairGetterThreadMethod).start();
|
||||||
new Thread(new AnnouncerThread()).start();
|
new Thread(new AnnouncerThread()).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,23 +177,23 @@ public final class ChatFormatter {
|
||||||
}
|
}
|
||||||
thirdFormattedSection.Start = origend + 1;
|
thirdFormattedSection.Start = origend + 1;
|
||||||
thirdFormattedSection.End = origend2;
|
thirdFormattedSection.End = origend2;
|
||||||
System.out.println("RC start");
|
DebugCommand.SendDebugMessage("RC start");
|
||||||
for (short ii = 0; ii < 3; ii += 2) // Only check first and third section
|
for (short ii = 0; ii < 3; ii += 2) // Only check first and third section
|
||||||
for (short iii = 0; iii < 2; iii++) {
|
for (short iii = 0; iii < 2; iii++) {
|
||||||
final int startorend = iii == 0 ? section.Start : section.End;
|
final int startorend = iii == 0 ? section.Start : section.End;
|
||||||
if (rc[ii][iii][0] <= startorend && rc[ii][iii][1] >= startorend) {
|
if (rc[ii][iii][0] <= startorend && rc[ii][iii][1] >= startorend) {
|
||||||
final String startorendText = iii == 0 ? "Start" : "End";
|
final String startorendText = iii == 0 ? "Start" : "End";
|
||||||
System.out.println("rc[" + ii + "][" + iii + "][0] <= section." + startorendText + " && rc["
|
DebugCommand.SendDebugMessage("rc[" + ii + "][" + iii + "][0] <= section." + startorendText
|
||||||
+ ii + "][" + iii + "][1] >= section." + startorendText);
|
+ " && rc[" + ii + "][" + iii + "][1] >= section." + startorendText);
|
||||||
System.out.println(rc[ii][iii][0] + " <= " + startorend + " && " + rc[ii][iii][1] + " >= "
|
DebugCommand.SendDebugMessage(rc[ii][iii][0] + " <= " + startorend + " && " + rc[ii][iii][1]
|
||||||
+ startorend);
|
+ " >= " + startorend);
|
||||||
rc[1][iii] = new int[] { startorend, rc[ii][iii][1] };
|
rc[1][iii] = new int[] { startorend, rc[ii][iii][1] };
|
||||||
rc[ii][iii][1] = startorend - 1;
|
rc[ii][iii][1] = startorend - 1;
|
||||||
System.out.println("rc[1][" + iii + "]: " + rc[1][iii][0] + " " + rc[1][iii][1]);
|
DebugCommand.SendDebugMessage("rc[1][" + iii + "]: " + rc[1][iii][0] + " " + rc[1][iii][1]);
|
||||||
System.out.println("rc[" + ii + "][" + iii + "][1]: " + rc[ii][iii][1]);
|
DebugCommand.SendDebugMessage("rc[" + ii + "][" + iii + "][1]: " + rc[ii][iii][1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("RC done");
|
DebugCommand.SendDebugMessage("RC done");
|
||||||
Function<int[], Integer> getRemCharStart = arr -> arr[1] - arr[0] < 0 ? 0 : arr[1] - arr[0];
|
Function<int[], Integer> getRemCharStart = arr -> arr[1] - arr[0] < 0 ? 0 : arr[1] - arr[0];
|
||||||
firstSection.RemCharFromStart = (short) (int) getRemCharStart.apply(rc[0][0]);
|
firstSection.RemCharFromStart = (short) (int) getRemCharStart.apply(rc[0][0]);
|
||||||
firstSection.RemCharFromEnd = (short) (int) getRemCharStart.apply(rc[0][1]);
|
firstSection.RemCharFromEnd = (short) (int) getRemCharStart.apply(rc[0][1]);
|
||||||
|
@ -296,9 +296,9 @@ public final class ChatFormatter {
|
||||||
newtp.setStrikethrough(strikethrough);
|
newtp.setStrikethrough(strikethrough);
|
||||||
newtp.setObfuscated(obfuscated);
|
newtp.setObfuscated(obfuscated);
|
||||||
if (openlink != null && openlink.length() > 0) {
|
if (openlink != null && openlink.length() > 0) {
|
||||||
newtp.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC, TellrawEvent.ClickAction.OPEN_URL,
|
newtp.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.OPEN_URL,
|
||||||
(section.Matches.size() > 0 ? openlink.replace("$1", section.Matches.get(0)) : openlink)))
|
(section.Matches.size() > 0 ? openlink.replace("$1", section.Matches.get(0)) : openlink)))
|
||||||
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
|
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT,
|
||||||
new TellrawPart("Click to open").setColor(Color.Blue)));
|
new TellrawPart("Click to open").setColor(Color.Blue)));
|
||||||
}
|
}
|
||||||
tp.addExtra(newtp);
|
tp.addExtra(newtp);
|
||||||
|
|
|
@ -10,27 +10,24 @@ public final class TellrawEvent<T extends TellrawEvent.Action> implements Serial
|
||||||
private T action;
|
private T action;
|
||||||
private Object value;
|
private Object value;
|
||||||
|
|
||||||
private TellrawEvent(Class<T> cl, T action, String value) {
|
private TellrawEvent(T action, String value) {
|
||||||
this.hoverEvent = HoverAction.class.equals(cl);
|
this.hoverEvent = action instanceof HoverAction;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TellrawEvent(Class<T> cl, T action, TellrawPart value) {
|
private TellrawEvent(T action, TellrawPart value) {
|
||||||
this.hoverEvent = HoverAction.class.equals(cl);
|
this.hoverEvent = action instanceof HoverAction;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Class<HoverAction> HoverAC = HoverAction.class;
|
public static <V extends TellrawEvent.Action> TellrawEvent<V> create(V action, String value) {
|
||||||
public static final Class<ClickAction> ClickAC = ClickAction.class;
|
return new TellrawEvent<>(action, value);
|
||||||
|
|
||||||
public static <V extends TellrawEvent.Action> TellrawEvent<V> create(Class<V> cl, V action, String value) {
|
|
||||||
return new TellrawEvent<>(cl, action, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <V extends TellrawEvent.Action> TellrawEvent<V> create(Class<V> cl, V action, TellrawPart value) {
|
public static <V extends TellrawEvent.Action> TellrawEvent<V> create(V action, TellrawPart value) {
|
||||||
return new TellrawEvent<>(cl, action, value);
|
return new TellrawEvent<>(action, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isHoverEvent() {
|
public boolean isHoverEvent() {
|
||||||
|
|
|
@ -11,6 +11,9 @@ import org.mockito.Mockito;
|
||||||
import buttondevteam.chat.ObjectTestRunner.Objects;
|
import buttondevteam.chat.ObjectTestRunner.Objects;
|
||||||
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||||
import buttondevteam.chat.formatting.ChatFormatter;
|
import buttondevteam.chat.formatting.ChatFormatter;
|
||||||
|
import buttondevteam.chat.formatting.TellrawEvent;
|
||||||
|
import buttondevteam.chat.formatting.TellrawEvent.ClickAction;
|
||||||
|
import buttondevteam.chat.formatting.TellrawEvent.HoverAction;
|
||||||
import buttondevteam.chat.formatting.TellrawPart;
|
import buttondevteam.chat.formatting.TellrawPart;
|
||||||
import buttondevteam.core.TestPrepare;
|
import buttondevteam.core.TestPrepare;
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
|
@ -38,6 +41,11 @@ public class ChatFormatTest extends TestCase {
|
||||||
list.add(new ChatFormatTest(sender, "¯\\\\\\_(ツ)\\_/¯", new TellrawPart("¯").setColor(Color.White),
|
list.add(new ChatFormatTest(sender, "¯\\\\\\_(ツ)\\_/¯", new TellrawPart("¯").setColor(Color.White),
|
||||||
new TellrawPart("\\").setColor(Color.White), new TellrawPart("_(ツ)").setColor(Color.White),
|
new TellrawPart("\\").setColor(Color.White), new TellrawPart("_(ツ)").setColor(Color.White),
|
||||||
new TellrawPart("_/¯").setColor(Color.White)));
|
new TellrawPart("_/¯").setColor(Color.White)));
|
||||||
|
list.add(new ChatFormatTest(sender, "https://google.hu/",
|
||||||
|
new TellrawPart("https://google.hu/").setColor(Color.White).setUnderlined(true)
|
||||||
|
.setHoverEvent(TellrawEvent.create(HoverAction.SHOW_TEXT,
|
||||||
|
new TellrawPart("Click to open").setColor(Color.Blue)))
|
||||||
|
.setClickEvent(TellrawEvent.create(ClickAction.OPEN_URL, "https://google.hu/"))));
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
@ -46,10 +54,10 @@ public class ChatFormatTest extends TestCase {
|
||||||
private final String message;
|
private final String message;
|
||||||
private final TellrawPart[] extras;
|
private final TellrawPart[] extras;
|
||||||
|
|
||||||
public ChatFormatTest(CommandSender sender, String message, TellrawPart... extras) {
|
public ChatFormatTest(CommandSender sender, String message, TellrawPart... expectedextras) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.extras = extras;
|
this.extras = expectedextras;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue