Removed RC messages, fixed URLs probably

#63
Added URL test
Smaller refactors
This commit is contained in:
Norbi Peti 2017-08-05 01:23:37 +02:00
parent 1c32dbd949
commit 437d9e8f98
5 changed files with 71 additions and 60 deletions

View file

@ -52,8 +52,7 @@ public class ChatProcessing {
new ChatFormatterBuilder().setRegex(UNDERLINED_PATTERN).setUnderlined(true).setRemoveCharCount((short) 1)
.setRange(true).build(),
ESCAPE_FORMATTER,
new ChatFormatterBuilder().setRegex(URL_PATTERN).setUnderlined(true).setOpenlink("$1").setRange(true)
.build(),
new ChatFormatterBuilder().setRegex(URL_PATTERN).setUnderlined(true).setOpenlink("$1").build(),
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)
.setOnmatch((match, builder) ->
@ -162,53 +161,60 @@ public class ChatProcessing {
final String channelidentifier) {
TellrawPart json = new TellrawPart("");
if (mp != null && mp.ChatOnly) {
json.addExtra(new TellrawPart("[C]").setHoverEvent(
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
json.addExtra(new TellrawPart("[C]")
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only")));
}
json.addExtra(
new TellrawPart(channelidentifier)
.setHoverEvent(
TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT,
new TellrawPart((sender instanceof IDiscordSender ? "From Discord\n" : "")
+ "Copy message").setColor(Color.Blue)))
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAC,
TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
.setClickEvent(TellrawEvent.create(TellrawEvent.ClickAction.SUGGEST_COMMAND, message)));
json.addExtra(new TellrawPart(" <"));
json.addExtra(
new TellrawPart(
(player != null ? player.getDisplayName() : sender.getName()))
.setHoverEvent(
TellrawEvent
.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
new TellrawPart("")
.addExtra(new TellrawPart(String.format("Flair: %s",
(mp != null ? mp.GetFormattedFlair() : "-"))))
.addExtra(new TellrawPart(
String.format("\nPlayername: %s\n",
(player != null ? player.getDisplayName()
: sender.getName()))
.setHoverEvent(
TellrawEvent
.create(TellrawEvent.HoverAction.SHOW_TEXT,
new TellrawPart("")
.addExtra(new TellrawPart(String.format(
"Flair: %s",
(mp != null ? mp.GetFormattedFlair()
: "-"))))
.addExtra(new TellrawPart(String.format(
"\nPlayername: %s\n",
(player != null ? player.getName()
: sender.getName())))
.setColor(Color.Aqua))
.addExtra(new TellrawPart(String.format("World: %s\n",
(player != null ? player.getWorld().getName()
: "-"))))
.addExtra(new TellrawPart(String.format(
"Respect: %s%s%s",
(mp != null
? (mp.FCount().get()
.addExtra(new TellrawPart(String.format(
"World: %s\n",
(player != null
? player.getWorld().getName()
: "-"))))
.addExtra(new TellrawPart(String.format(
"Respect: %s%s%s",
(mp != null ? (mp.FCount().get()
/ (double) mp.FDeaths().get())
: "Infinite"),
(mp != null && mp.UserName().get() != null
&& !mp.UserName().get().isEmpty()
? "\nUserName: "
+ mp.UserName().get()
: ""),
(mp != null && mp.PlayerName().get()
.equals("\nAlpha_Bacca44")
? "\nDeaths: "
+ PlayerListener.AlphaDeaths
: ""))))
.addExtra(new TellrawPart("\nFor more, do /u info "
+ sender.getName())))));
: "Infinite"),
(mp != null
&& mp.UserName().get() != null
&& !mp.UserName().get()
.isEmpty()
? "\nUserName: "
+ mp.UserName()
.get()
: ""),
(mp != null && mp.PlayerName().get()
.equals("\nAlpha_Bacca44")
? "\nDeaths: "
+ PlayerListener.AlphaDeaths
: ""))))
.addExtra(new TellrawPart(
"\nFor more, do /u info "
+ sender.getName())))));
json.addExtra(new TellrawPart("> "));
return json;
}

View file

@ -98,7 +98,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15.
setupEconomy();
setupPermissions();
new Thread(() -> FlairGetterThreadMethod()).start();
new Thread(this::FlairGetterThreadMethod).start();
new Thread(new AnnouncerThread()).start();
}

View file

@ -177,23 +177,23 @@ public final class ChatFormatter {
}
thirdFormattedSection.Start = origend + 1;
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 iii = 0; iii < 2; iii++) {
final int startorend = iii == 0 ? section.Start : section.End;
if (rc[ii][iii][0] <= startorend && rc[ii][iii][1] >= startorend) {
final String startorendText = iii == 0 ? "Start" : "End";
System.out.println("rc[" + ii + "][" + iii + "][0] <= section." + startorendText + " && rc["
+ ii + "][" + iii + "][1] >= section." + startorendText);
System.out.println(rc[ii][iii][0] + " <= " + startorend + " && " + rc[ii][iii][1] + " >= "
+ startorend);
DebugCommand.SendDebugMessage("rc[" + ii + "][" + iii + "][0] <= section." + startorendText
+ " && rc[" + ii + "][" + iii + "][1] >= section." + startorendText);
DebugCommand.SendDebugMessage(rc[ii][iii][0] + " <= " + startorend + " && " + rc[ii][iii][1]
+ " >= " + startorend);
rc[1][iii] = new int[] { startorend, rc[ii][iii][1] };
rc[ii][iii][1] = startorend - 1;
System.out.println("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[1][" + iii + "]: " + rc[1][iii][0] + " " + rc[1][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];
firstSection.RemCharFromStart = (short) (int) getRemCharStart.apply(rc[0][0]);
firstSection.RemCharFromEnd = (short) (int) getRemCharStart.apply(rc[0][1]);
@ -296,9 +296,9 @@ public final class ChatFormatter {
newtp.setStrikethrough(strikethrough);
newtp.setObfuscated(obfuscated);
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)))
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAC, TellrawEvent.HoverAction.SHOW_TEXT,
.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT,
new TellrawPart("Click to open").setColor(Color.Blue)));
}
tp.addExtra(newtp);

View file

@ -10,27 +10,24 @@ public final class TellrawEvent<T extends TellrawEvent.Action> implements Serial
private T action;
private Object value;
private TellrawEvent(Class<T> cl, T action, String value) {
this.hoverEvent = HoverAction.class.equals(cl);
private TellrawEvent(T action, String value) {
this.hoverEvent = action instanceof HoverAction;
this.action = action;
this.value = value;
}
private TellrawEvent(Class<T> cl, T action, TellrawPart value) {
this.hoverEvent = HoverAction.class.equals(cl);
private TellrawEvent(T action, TellrawPart value) {
this.hoverEvent = action instanceof HoverAction;
this.action = action;
this.value = value;
}
public static final Class<HoverAction> HoverAC = HoverAction.class;
public static final Class<ClickAction> ClickAC = ClickAction.class;
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(V action, String value) {
return new TellrawEvent<>(action, value);
}
public static <V extends TellrawEvent.Action> TellrawEvent<V> create(Class<V> cl, V action, TellrawPart value) {
return new TellrawEvent<>(cl, action, value);
public static <V extends TellrawEvent.Action> TellrawEvent<V> create(V action, TellrawPart value) {
return new TellrawEvent<>(action, value);
}
public boolean isHoverEvent() {

View file

@ -11,6 +11,9 @@ import org.mockito.Mockito;
import buttondevteam.chat.ObjectTestRunner.Objects;
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
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.core.TestPrepare;
import buttondevteam.lib.chat.Channel;
@ -38,6 +41,11 @@ public class ChatFormatTest extends TestCase {
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)));
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;
}
@ -46,10 +54,10 @@ public class ChatFormatTest extends TestCase {
private final String message;
private final TellrawPart[] extras;
public ChatFormatTest(CommandSender sender, String message, TellrawPart... extras) {
public ChatFormatTest(CommandSender sender, String message, TellrawPart... expectedextras) {
this.sender = sender;
this.message = message;
this.extras = extras;
this.extras = expectedextras;
}
@Test