Fixed formatting!
This commit is contained in:
parent
6648bc6901
commit
dc7913ca14
5 changed files with 31 additions and 8 deletions
|
@ -27,7 +27,12 @@ import buttondevteam.chat.formatting.TellrawPart;
|
||||||
import buttondevteam.chat.formatting.TellrawSerializableEnum;
|
import buttondevteam.chat.formatting.TellrawSerializableEnum;
|
||||||
import buttondevteam.chat.formatting.TellrawSerializer;
|
import buttondevteam.chat.formatting.TellrawSerializer;
|
||||||
import buttondevteam.chat.formatting.ChatFormatter.Color;
|
import buttondevteam.chat.formatting.ChatFormatter.Color;
|
||||||
|
import buttondevteam.chat.formatting.ChatFormatter.Format;
|
||||||
import buttondevteam.chat.formatting.ChatFormatter.Priority;
|
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 {
|
public class ChatProcessing {
|
||||||
private static final Pattern CONSOLE_PING_PATTERN = Pattern.compile("(?i)" + Pattern.quote("@console"));
|
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 URL_PATTERN = Pattern.compile("(http[\\w:/?=$\\-_.+!*'(),]+)");
|
||||||
private static final Pattern ENTIRE_MESSAGE_PATTERN = Pattern.compile(".+");
|
private static final Pattern ENTIRE_MESSAGE_PATTERN = Pattern.compile(".+");
|
||||||
private static final Pattern UNDERLINED_PATTERN = Pattern.compile("(?<!\\\\)\\_((?:\\\\\\_|[^\\_])+[^\\_\\\\])\\_");
|
private static final Pattern UNDERLINED_PATTERN = Pattern.compile("(?<!\\\\)\\_((?:\\\\\\_|[^\\_])+[^\\_\\\\])\\_");
|
||||||
private static final Pattern ITALIC_PATTERN = Pattern.compile("(?<!\\\\)\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*");
|
private static final Pattern ITALIC_PATTERN = Pattern
|
||||||
|
.compile("(?<![\\\\\\*])\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*(?!\\*)");
|
||||||
private static final Pattern BOLD_PATTERN = Pattern.compile("(?<!\\\\)\\*\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*\\*");
|
private static final Pattern BOLD_PATTERN = Pattern.compile("(?<!\\\\)\\*\\*((?:\\\\\\*|[^\\*])+[^\\*\\\\])\\*\\*");
|
||||||
private static final String[] RainbowPresserColors = new String[] { "red", "gold", "yellow", "green", "blue",
|
private static final String[] RainbowPresserColors = new String[] { "red", "gold", "yellow", "green", "blue",
|
||||||
"dark_purple" }; // TODO
|
"dark_purple" }; // TODO
|
||||||
|
@ -235,7 +241,8 @@ public class ChatProcessing {
|
||||||
Gson gson = new GsonBuilder()
|
Gson gson = new GsonBuilder()
|
||||||
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
.registerTypeHierarchyAdapter(TellrawSerializableEnum.class, new TellrawSerializer.TwEnum())
|
||||||
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
.registerTypeHierarchyAdapter(Collection.class, new TellrawSerializer.TwCollection())
|
||||||
.disableHtmlEscaping().create();
|
.registerTypeAdapter(Boolean.class, new TellrawSerializer.TwBool())
|
||||||
|
.registerTypeAdapter(boolean.class, new TellrawSerializer.TwBool()).disableHtmlEscaping().create();
|
||||||
String jsonstr = gson.toJson(json);
|
String jsonstr = gson.toJson(json);
|
||||||
if (jsonstr.length() >= 32767) {
|
if (jsonstr.length() >= 32767) {
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
|
|
|
@ -146,7 +146,7 @@ public final class ChatFormatter {
|
||||||
replacewith = formatter.replacewith;
|
replacewith = formatter.replacewith;
|
||||||
}
|
}
|
||||||
TellrawPart newtp = new TellrawPart("");
|
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)));
|
newtp.setText(replacewith.replace("$1", section.Matches.get(0)));
|
||||||
else
|
else
|
||||||
newtp.setText(originaltext);
|
newtp.setText(originaltext);
|
||||||
|
|
|
@ -4,7 +4,7 @@ import java.io.Serializable;
|
||||||
|
|
||||||
public final class TellrawEvent<T extends TellrawEvent.Action> implements Serializable {
|
public final class TellrawEvent<T extends TellrawEvent.Action> implements Serializable {
|
||||||
private static final long serialVersionUID = -1681364161210561505L;
|
private static final long serialVersionUID = -1681364161210561505L;
|
||||||
private boolean hoverEvent;
|
private transient boolean hoverEvent;
|
||||||
private T action;
|
private T action;
|
||||||
private Object value;
|
private Object value;
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,12 @@ import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public final class TellrawPart implements Serializable {
|
public final class TellrawPart implements Serializable {
|
||||||
private static final long serialVersionUID = 4125357644462144024L;
|
private static final long serialVersionUID = 4125357644462144024L;
|
||||||
private ChatFormatter.Color color;
|
private ChatFormatter.Color color;
|
||||||
private transient ChatFormatter.Format format;
|
private transient ChatFormatter.Format format;
|
||||||
private boolean italics;
|
private boolean italic;
|
||||||
private boolean bold;
|
private boolean bold;
|
||||||
private boolean underlined;
|
private boolean underlined;
|
||||||
private boolean strikethrough;
|
private boolean strikethrough;
|
||||||
|
@ -37,13 +38,13 @@ public final class TellrawPart implements Serializable {
|
||||||
|
|
||||||
public TellrawPart setFormat(ChatFormatter.Format format) {
|
public TellrawPart setFormat(ChatFormatter.Format format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.italics = false;
|
this.italic = false;
|
||||||
this.bold = false;
|
this.bold = false;
|
||||||
this.underlined = false;
|
this.underlined = false;
|
||||||
this.strikethrough = false;
|
this.strikethrough = false;
|
||||||
this.obfuscated = false;
|
this.obfuscated = false;
|
||||||
if (format.equals(ChatFormatter.Format.Italic))
|
if (format.equals(ChatFormatter.Format.Italic))
|
||||||
this.italics = true;
|
this.italic = true;
|
||||||
else if (format.equals(ChatFormatter.Format.Bold))
|
else if (format.equals(ChatFormatter.Format.Bold))
|
||||||
this.bold = true;
|
this.bold = true;
|
||||||
else if (format.equals(ChatFormatter.Format.Underlined))
|
else if (format.equals(ChatFormatter.Format.Underlined))
|
||||||
|
@ -52,7 +53,7 @@ public final class TellrawPart implements Serializable {
|
||||||
this.strikethrough = true;
|
this.strikethrough = true;
|
||||||
else if (format.equals(ChatFormatter.Format.Obfuscated))
|
else if (format.equals(ChatFormatter.Format.Obfuscated))
|
||||||
this.obfuscated = true;
|
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!");
|
throw new UnsupportedOperationException("Trying to set to an unknown format!");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,4 +39,19 @@ public abstract class TellrawSerializer {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class TwBool extends TypeAdapter<Boolean> {
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue