Added spoiler support
This commit is contained in:
parent
21bf41db2b
commit
e2a6afd16a
|
@ -48,7 +48,8 @@ public class ChatProcessing {
|
||||||
private static final Pattern CODE_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"); //TODO
|
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,
|
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 boolean pingedconsole = false;
|
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(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)
|
ChatFormatter.builder().regex(UNDERLINED_PATTERN).underlined(true).removeCharCount((short) 1).type(ChatFormatter.Type.Range)
|
||||||
.build(),
|
.build(),
|
||||||
ChatFormatter.builder().regex(STRIKETHROUGH_PATTERN).strikethrough(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
|
ChatFormatter.builder().regex(STRIKETHROUGH_PATTERN).strikethrough(true).removeCharCount((short) 2).type(ChatFormatter.Type.Range)
|
||||||
.build(),
|
.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
|
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) -> {
|
ChatFormatter.builder().regex(CONSOLE_PING_PATTERN).color(Color.Aqua).onmatch((match, builder, section) -> {
|
||||||
if (!pingedconsole) {
|
if (!pingedconsole) {
|
||||||
|
|
|
@ -40,8 +40,9 @@ public final class ChatFormatter {
|
||||||
short removeCharCount = 0;
|
short removeCharCount = 0;
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
Type type = Type.Normal;
|
Type type = Type.Normal;
|
||||||
|
String hoverText;
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
Normal,
|
Normal,
|
||||||
/**
|
/**
|
||||||
* Matches a start and an end section which gets converted to one section (for example see italics)
|
* 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);
|
newtp.setObfuscated(formatter.obfuscated);
|
||||||
if (formatter.openlink != null)
|
if (formatter.openlink != null)
|
||||||
openlink = formatter.openlink;
|
openlink = formatter.openlink;
|
||||||
|
if (formatter.hoverText != null)
|
||||||
|
newtp.setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, formatter.hoverText));
|
||||||
}
|
}
|
||||||
if (lasttp != null && newtp.getColor() == lasttp.getColor()
|
if (lasttp != null && newtp.getColor() == lasttp.getColor()
|
||||||
&& newtp.isBold() == lasttp.isBold()
|
&& newtp.isBold() == lasttp.isBold()
|
||||||
|
|
Loading…
Reference in a new issue