Added spoiler support

This commit is contained in:
Norbi Peti 2019-02-01 17:53:54 +01:00
parent 21bf41db2b
commit e2a6afd16a
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 13 additions and 4 deletions

View file

@ -48,7 +48,8 @@ public class ChatProcessing {
private static final Pattern CODE_PATTERN = Pattern.compile("`");
private static final Pattern MASKED_LINK_PATTERN = Pattern.compile("\\[([^\\[\\]]+)]\\(([^()]+)\\)");
private static final Pattern SOMEONE_PATTERN = Pattern.compile("@someone"); //TODO
private static final Pattern STRIKETHROUGH_PATTERN = Pattern.compile("~~");
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,
Color.Blue, Color.DarkPurple};
private static boolean pingedconsole = false;
@ -61,8 +62,13 @@ public class ChatProcessing {
ChatFormatter.builder().regex(ITALIC_PATTERN).italic(true).removeCharCount((short) 1).type(ChatFormatter.Type.Range).build(),
ChatFormatter.builder().regex(UNDERLINED_PATTERN).underlined(true).removeCharCount((short) 1).type(ChatFormatter.Type.Range)
.build(),
ChatFormatter.builder().regex(STRIKETHROUGH_PATTERN).strikethrough(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
.build(),
ChatFormatter.builder().regex(STRIKETHROUGH_PATTERN).strikethrough(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
.build(),
ChatFormatter.builder().regex(SPOILER_PATTERN).obfuscated(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
.onmatch((match, cf, fs) -> {
cf.setHoverText(match);
return match;
}).build(),
ESCAPE_FORMATTER, ChatFormatter.builder().regex(NULL_MENTION_PATTERN).color(Color.DarkRed).build(), // Properly added a bug as a feature
ChatFormatter.builder().regex(CONSOLE_PING_PATTERN).color(Color.Aqua).onmatch((match, builder, section) -> {
if (!pingedconsole) {

View file

@ -40,8 +40,9 @@ public final class ChatFormatter {
short removeCharCount = 0;
@Builder.Default
Type type = Type.Normal;
String hoverText;
public enum Type {
public enum Type {
Normal,
/**
* Matches a start and an end section which gets converted to one section (for example see italics)
@ -353,6 +354,8 @@ public final class ChatFormatter {
newtp.setObfuscated(formatter.obfuscated);
if (formatter.openlink != null)
openlink = formatter.openlink;
if (formatter.hoverText != null)
newtp.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, formatter.hoverText));
}
if (lasttp != null && newtp.getColor() == lasttp.getColor()
&& newtp.isBold() == lasttp.isBold()