From dc7913ca145d626c9ea0ca6ccd52e5d75c0b66a4 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 8 Sep 2016 19:44:03 +0200 Subject: [PATCH] Fixed formatting! --- src/buttondevteam/chat/ChatProcessing.java | 11 +++++++++-- .../chat/formatting/ChatFormatter.java | 2 +- .../chat/formatting/TellrawEvent.java | 2 +- .../chat/formatting/TellrawPart.java | 9 +++++---- .../chat/formatting/TellrawSerializer.java | 15 +++++++++++++++ 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/buttondevteam/chat/ChatProcessing.java b/src/buttondevteam/chat/ChatProcessing.java index a68a63c..c8c9e5d 100644 --- a/src/buttondevteam/chat/ChatProcessing.java +++ b/src/buttondevteam/chat/ChatProcessing.java @@ -27,7 +27,12 @@ import buttondevteam.chat.formatting.TellrawPart; import buttondevteam.chat.formatting.TellrawSerializableEnum; import buttondevteam.chat.formatting.TellrawSerializer; import buttondevteam.chat.formatting.ChatFormatter.Color; +import buttondevteam.chat.formatting.ChatFormatter.Format; import buttondevteam.chat.formatting.ChatFormatter.Priority; +import buttondevteam.chat.formatting.TellrawEvent.ClickAction; +import buttondevteam.chat.formatting.TellrawEvent.HoverAction; +import buttondevteam.chat.formatting.TellrawSerializer.TwCollection; +import buttondevteam.chat.formatting.TellrawSerializer.TwEnum; public class ChatProcessing { private static final Pattern CONSOLE_PING_PATTERN = Pattern.compile("(?i)" + Pattern.quote("@console")); @@ -35,7 +40,8 @@ public class ChatProcessing { private static final Pattern URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),]+)"); private static final Pattern ENTIRE_MESSAGE_PATTERN = Pattern.compile(".+"); private static final Pattern UNDERLINED_PATTERN = Pattern.compile("(?= 32767) { sender.sendMessage( diff --git a/src/buttondevteam/chat/formatting/ChatFormatter.java b/src/buttondevteam/chat/formatting/ChatFormatter.java index 1962cb7..492e40e 100644 --- a/src/buttondevteam/chat/formatting/ChatFormatter.java +++ b/src/buttondevteam/chat/formatting/ChatFormatter.java @@ -146,7 +146,7 @@ public final class ChatFormatter { replacewith = formatter.replacewith; } TellrawPart newtp = new TellrawPart(""); - if (replacewith != null) + if (replacewith != null) // TODO: The ranges may change when formattings are nested, and this can't handle that newtp.setText(replacewith.replace("$1", section.Matches.get(0))); else newtp.setText(originaltext); diff --git a/src/buttondevteam/chat/formatting/TellrawEvent.java b/src/buttondevteam/chat/formatting/TellrawEvent.java index 3600aca..b989d45 100644 --- a/src/buttondevteam/chat/formatting/TellrawEvent.java +++ b/src/buttondevteam/chat/formatting/TellrawEvent.java @@ -4,7 +4,7 @@ import java.io.Serializable; public final class TellrawEvent implements Serializable { private static final long serialVersionUID = -1681364161210561505L; - private boolean hoverEvent; + private transient boolean hoverEvent; private T action; private Object value; diff --git a/src/buttondevteam/chat/formatting/TellrawPart.java b/src/buttondevteam/chat/formatting/TellrawPart.java index ee7dde8..d71f3e4 100644 --- a/src/buttondevteam/chat/formatting/TellrawPart.java +++ b/src/buttondevteam/chat/formatting/TellrawPart.java @@ -4,11 +4,12 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; +@SuppressWarnings("unused") public final class TellrawPart implements Serializable { private static final long serialVersionUID = 4125357644462144024L; private ChatFormatter.Color color; private transient ChatFormatter.Format format; - private boolean italics; + private boolean italic; private boolean bold; private boolean underlined; private boolean strikethrough; @@ -37,13 +38,13 @@ public final class TellrawPart implements Serializable { public TellrawPart setFormat(ChatFormatter.Format format) { this.format = format; - this.italics = false; + this.italic = false; this.bold = false; this.underlined = false; this.strikethrough = false; this.obfuscated = false; if (format.equals(ChatFormatter.Format.Italic)) - this.italics = true; + this.italic = true; else if (format.equals(ChatFormatter.Format.Bold)) this.bold = true; else if (format.equals(ChatFormatter.Format.Underlined)) @@ -52,7 +53,7 @@ public final class TellrawPart implements Serializable { this.strikethrough = true; else if (format.equals(ChatFormatter.Format.Obfuscated)) this.obfuscated = true; - else // TODO: Don't serialize false values, find out why is it bugging + else throw new UnsupportedOperationException("Trying to set to an unknown format!"); return this; } diff --git a/src/buttondevteam/chat/formatting/TellrawSerializer.java b/src/buttondevteam/chat/formatting/TellrawSerializer.java index e8354d2..2eee0cf 100644 --- a/src/buttondevteam/chat/formatting/TellrawSerializer.java +++ b/src/buttondevteam/chat/formatting/TellrawSerializer.java @@ -39,4 +39,19 @@ public abstract class TellrawSerializer { return array; } } + + public static class TwBool extends TypeAdapter { + @Override + public Boolean read(JsonReader reader) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void write(JsonWriter writer, Boolean val) throws IOException { + if (val) + writer.value(val); + else + writer.nullValue(); + } + } }