From e2a6afd16a5ef65f4ca1bf6876ad386c5375f960 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 1 Feb 2019 17:53:54 +0100 Subject: [PATCH] Added spoiler support --- src/main/java/buttondevteam/chat/ChatProcessing.java | 12 +++++++++--- .../buttondevteam/chat/formatting/ChatFormatter.java | 5 ++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 9404259..cb593df 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -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) { diff --git a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java index e60efbf..aa7eb96 100644 --- a/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java +++ b/src/main/java/buttondevteam/chat/formatting/ChatFormatter.java @@ -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()