Improve test coverage, preparations, fixes
Removed an unnnecessary bit of code from ChatFormatter
This commit is contained in:
parent
7646db4487
commit
dc6df53c96
15 changed files with 45 additions and 75 deletions
|
@ -7,17 +7,15 @@ before_install: | # Wget BuildTools and run if cached folder not found
|
|||
# grep so that download counts don't appear in log files
|
||||
java -jar BuildTools.jar --rev 1.12.2 | grep -vE "[^/ ]*/[^/ ]*\s*KB\s*$" | grep -v "^\s*$"
|
||||
fi
|
||||
cp ci/settings.xml $HOME/.m2/
|
||||
language: java
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
- oraclejdk11
|
||||
sudo: true
|
||||
dist: trusty # Needed for Java 8, although we might not need Java 8
|
||||
deploy:
|
||||
- provider: releases
|
||||
api_key:
|
||||
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'
|
||||
file: 'target/Chroma-Chat.jar'
|
||||
on:
|
||||
tags: true
|
||||
skip_cleanup: true
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
|
||||
http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||
|
||||
<activeProfiles>
|
||||
<activeProfile>github</activeProfile>
|
||||
</activeProfiles>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>github</id>
|
||||
<repositories>
|
||||
<!-- <repository>
|
||||
<id>central</id>
|
||||
<url>https://repo1.maven.org/maven2</url>
|
||||
<releases><enabled>true</enabled></releases>
|
||||
<snapshots><enabled>false</enabled></snapshots>
|
||||
</repository> -->
|
||||
<repository>
|
||||
<id>github</id>
|
||||
<name>GitHub Towny Apache Maven Packages</name>
|
||||
<url>https://maven.pkg.github.com/TownyAdvanced/Towny</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<servers>
|
||||
<server>
|
||||
<id>github</id>
|
||||
<username>NorbiPeti</username>
|
||||
<password>${env.GHTOKEN}</password>
|
||||
</server>
|
||||
</servers>
|
||||
</settings>
|
6
pom.xml
6
pom.xml
|
@ -12,12 +12,6 @@
|
|||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src</directory>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
|
|
|
@ -10,7 +10,10 @@ import org.bukkit.command.CommandSender;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
@CommandClass(modOnly = true)
|
||||
@CommandClass(modOnly = true, helpText = {
|
||||
"Snap",
|
||||
"Perfectly balanced as all things should be."
|
||||
})
|
||||
public class SnapCommand extends ICommand2MC {
|
||||
@Command2.Subcommand
|
||||
public void def(CommandSender sender) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import buttondevteam.chat.PluginMain;
|
|||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ComponentMetadata;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.ListConfigData;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
|
@ -12,6 +13,7 @@ import org.bukkit.Bukkit;
|
|||
/**
|
||||
* Displays the configured messages at the set interval when someone is online.
|
||||
*/
|
||||
@ComponentMetadata(enabledByDefault = false)
|
||||
public class AnnouncerComponent extends Component<PluginMain> implements Runnable {
|
||||
/**
|
||||
* The messages to display to players.
|
||||
|
|
|
@ -75,7 +75,7 @@ public class ChatProcessing {
|
|||
.onmatch((match, builder, section) -> {
|
||||
String text, link;
|
||||
if (section.Matches.size() < 2 || (text = section.Matches.get(0)).length() == 0 || (link = section.Matches.get(1)).length() == 0)
|
||||
return "";
|
||||
return "[MISSING LINK]"; //Doesn't actually happen, because of the regex
|
||||
builder.setOpenlink(link);
|
||||
return text;
|
||||
}).build()),
|
||||
|
|
|
@ -166,16 +166,6 @@ public final class ChatFormatter {
|
|||
i = 0;
|
||||
}
|
||||
sortSections(sections);
|
||||
if (i == 0) continue;
|
||||
for (int j = i - 1; j <= i + 1; j++) {
|
||||
if (j < sections.size() && sections.get(j).End < sections.get(j).Start) {
|
||||
DebugCommand.SendDebugMessage("Removing section: " + sections.get(j));
|
||||
ChatFormatUtils.sendMessageWithPointer(str, sections.get(j).Start, sections.get(j).End);
|
||||
sections.remove(j);
|
||||
j--;
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ public class FormatSettings {
|
|||
if (field.getBoolean(settings))
|
||||
field.setBoolean(this, true); //Set to true if either of them are true
|
||||
} else if (field.get(settings) != null) {
|
||||
//System.out.println("Setting " + field.getType() + " " + field.getName() + " from " + field.get(this) + " to " + field.get(settings));
|
||||
field.set(this, field.get(settings));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ public class StringMatchProvider extends MatchProviderBase {
|
|||
@ToString.Exclude
|
||||
private final FormatSettings settings;
|
||||
private int nextIndex = 0;
|
||||
private boolean ignoreCase;
|
||||
private final boolean ignoreCase;
|
||||
|
||||
/**
|
||||
* Matches the given strings in the order given
|
||||
|
|
|
@ -14,7 +14,7 @@ public final class TellrawPart implements Serializable {
|
|||
private boolean underlined;
|
||||
private boolean strikethrough;
|
||||
private boolean obfuscated;
|
||||
private List<TellrawPart> extra = new ArrayList<>();
|
||||
private final List<TellrawPart> extra = new ArrayList<>();
|
||||
private String text;
|
||||
private TellrawEvent<TellrawEvent.HoverAction> hoverEvent;
|
||||
private TellrawEvent<TellrawEvent.ClickAction> clickEvent;
|
||||
|
|
|
@ -8,6 +8,7 @@ import buttondevteam.lib.chat.Command2;
|
|||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.ICommand2MC;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -44,5 +45,7 @@ public class PressCommand extends ICommand2MC implements Listener {
|
|||
command = event.getCommand();
|
||||
pressers = new HashSet<>();
|
||||
startTicks = event.getRestartTicks();
|
||||
if (Bukkit.getOnlinePlayers().size() > 0)
|
||||
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, "§b-- Do /press to reset the timer. You may only press once.", command.getComponent().getRestartBroadcast());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
|
|||
public static final Map<String, Color> NationColor = new HashMap<>();
|
||||
|
||||
/**
|
||||
* The amount of town colors allowed. If more than one is used, players can change how many letters to be in a specific color using /u ncolor.
|
||||
* The amount of town colors allowed. If more than one is used (or nation colors are enabled), players can change how many letters to be in a specific color using /u ncolor.
|
||||
*/
|
||||
public final ConfigData<Byte> colorCount = getConfig().getData("colorCount", (byte) 1, cc -> ((Integer) cc).byteValue(), Byte::intValue);
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.util.stream.Collectors;
|
|||
/**
|
||||
* This component manages the town and nation chat. It's also needed for the TownColorComponent.
|
||||
* It provides the TC and NC channels, and posts Towny messages (global, town, nation) to the correct channels for other platforms like Discord.
|
||||
* You can disable /tc and /nc in Chroma-Core's config if you only want to use the TownColorComponent.
|
||||
*/
|
||||
public class TownyComponent extends Component<PluginMain> {
|
||||
public static TownyDataSource dataSource;
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
name: Chroma-Chat
|
||||
main: buttondevteam.chat.PluginMain
|
||||
version: '1.0'
|
||||
version: '${noprefix.version}'
|
||||
commands:
|
||||
u:
|
||||
description: Auto-flair system. Accept or ignore flair.
|
||||
ooc:
|
||||
description: Send message Out-of-Character.
|
||||
alias: nrp
|
||||
description: The main command for Chroma-Chat.
|
||||
unlol:
|
||||
description: Unlaugh the last laugh.
|
||||
alias: unlaugh
|
||||
mwiki:
|
||||
description: Search the wiki.
|
||||
dontrunthiscmd: null
|
||||
tableflip:
|
||||
description: Flip a table.
|
||||
unflip:
|
||||
|
@ -36,7 +32,7 @@ author: NorbiPeti
|
|||
depend:
|
||||
- Essentials
|
||||
- Vault
|
||||
- ChromaCore
|
||||
- Chroma-Core
|
||||
soft-depend:
|
||||
- Dynmap-Towny
|
||||
- Towny
|
||||
|
|
|
@ -10,7 +10,10 @@ import buttondevteam.chat.components.formatter.formatting.TellrawEvent.ClickActi
|
|||
import buttondevteam.chat.components.formatter.formatting.TellrawEvent.HoverAction;
|
||||
import buttondevteam.core.TestPrepare;
|
||||
import buttondevteam.core.component.channel.Channel;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Color;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Assert;
|
||||
|
@ -20,6 +23,7 @@ import org.mockito.Mockito;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@RunWith(ObjectTestRunner.class)
|
||||
public class ChatFormatIT {
|
||||
|
@ -29,6 +33,7 @@ public class ChatFormatIT {
|
|||
final CommandSender sender = Mockito.mock(CommandSender.class);
|
||||
DebugCommand.DebugMode = true;
|
||||
PluginMain.permission = Mockito.mock(Permission.class);
|
||||
TBMCCoreAPI.RegisterUserClass(TBMCPlayerBase.class, TBMCPlayer::new);
|
||||
|
||||
List<Object> list = new ArrayList<>();
|
||||
|
||||
|
@ -88,6 +93,23 @@ public class ChatFormatIT {
|
|||
list.add(new ChatFormatIT(sender, "***test*** test", new TellrawPart("test").setColor(Color.White)
|
||||
.setItalic(true).setBold(true), new TellrawPart(" test").setColor(Color.White)));
|
||||
list.add(new ChatFormatIT(sender, ">test message\nheh", new TellrawPart(">test message\nheh").setColor(Color.Green)));
|
||||
list.add(new ChatFormatIT(sender, "[here's a link]()", new TellrawPart("[here's a link]()").setColor(Color.White)));
|
||||
list.add(new ChatFormatIT(sender, "[](fakelink)", new TellrawPart("[](fakelink)").setColor(Color.White)));
|
||||
list.add(new ChatFormatIT(sender, "||this is a spoiler||", new TellrawPart("this is a spoiler").setColor(Color.White)
|
||||
.setObfuscated(true).setHoverEvent(TellrawEvent.create(HoverAction.SHOW_TEXT, "this is a spoiler"))));
|
||||
Function<String, TellrawPart> whiteBoldItalic = text -> new TellrawPart(text).setColor(Color.White).setBold(true).setItalic(true);
|
||||
list.add(new ChatFormatIT(sender, "***some complicated ||test message|| with [links](https://chromagaming.figytuna.com) and other __greatness__ by NorbiPeti***",
|
||||
whiteBoldItalic.apply("some complicated "),
|
||||
whiteBoldItalic.apply("test message").setObfuscated(true).setHoverEvent(TellrawEvent.create(HoverAction.SHOW_TEXT, "test message")),
|
||||
whiteBoldItalic.apply(" with "),
|
||||
whiteBoldItalic.apply("links").setClickEvent(TellrawEvent.create(ClickAction.OPEN_URL, "https://chromagaming.figytuna.com")).setUnderlined(true)
|
||||
.setHoverEvent(TellrawEvent.create(HoverAction.SHOW_TEXT, new TellrawPart("Click to open").setColor(Color.Blue))),
|
||||
whiteBoldItalic.apply(" and other "),
|
||||
whiteBoldItalic.apply("greatness").setUnderlined(true),
|
||||
whiteBoldItalic.apply(" by "),
|
||||
whiteBoldItalic.apply("§bNorbiPeti§r").setColor(Color.Aqua))); //§b: flair color
|
||||
list.add(new ChatFormatIT(sender, "hey @console", new TellrawPart("hey ").setColor(Color.White),
|
||||
new TellrawPart("@console").setColor(Color.Aqua)));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
@ -97,10 +119,10 @@ public class ChatFormatIT {
|
|||
private final TellrawPart[] extras;
|
||||
private boolean rainbowMode;
|
||||
|
||||
public ChatFormatIT(CommandSender sender, String message, TellrawPart... expectedextras) {
|
||||
public ChatFormatIT(CommandSender sender, String message, TellrawPart... expectedExtras) {
|
||||
this.sender = sender;
|
||||
this.message = message;
|
||||
this.extras = expectedextras;
|
||||
this.extras = expectedExtras;
|
||||
}
|
||||
|
||||
private ChatFormatIT setRainbowMode() {
|
||||
|
@ -110,16 +132,14 @@ public class ChatFormatIT {
|
|||
|
||||
@Test
|
||||
public void testMessage() {
|
||||
System.out.println("Testing: " + message);
|
||||
ArrayList<MatchProviderBase> cfs = ChatProcessing.addFormatters(p -> true, null);
|
||||
final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatUtils.MCORIGIN);
|
||||
if (rainbowMode)
|
||||
ChatProcessing.createRPC(Color.White, cfs);
|
||||
final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);
|
||||
ChatFormatter.Combine(cfs, message, tp, null, FormatSettings.builder().color(Color.White).build());
|
||||
System.out.println("Testing: " + message);
|
||||
// System.out.println(ChatProcessing.toJson(tp));
|
||||
final TellrawPart expectedtp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatUtils.MCORIGIN);
|
||||
// System.out.println("Raw: " + ChatProcessing.toJson(expectedtp));
|
||||
for (TellrawPart extra : extras)
|
||||
expectedtp.addExtra(extra);
|
||||
Assert.assertEquals(ChatProcessing.toJson(expectedtp), ChatProcessing.toJson(tp));
|
||||
|
|
Loading…
Reference in a new issue