Make JsonMessage a little easier to use, might be worth it to increase functionality later as more complicated things are added to json text

This commit is contained in:
Shaun Bennett 2014-12-04 17:48:06 -06:00
parent f48085d5ca
commit 03bd2ed2c1
4 changed files with 121 additions and 1 deletions

View File

@ -0,0 +1,22 @@
package mineplex.core.common.jsonchat;
public enum ClickEvent
{
RUN_COMMAND("run_command"),
SUGGEST_COMMAND("suggest_command"),
OPEN_URL("open_url"),
CHANGE_PAGE("change_page"); // Change Page only applies to books, which we haven't been able to use yet
private String _minecraftString;
ClickEvent(String minecraftString)
{
_minecraftString = minecraftString;
}
@Override
public String toString()
{
return _minecraftString;
}
}

View File

@ -0,0 +1,34 @@
package mineplex.core.common.jsonchat;
public enum Color
{
BLACK("black"),
DARK_BLUE("dark_blue"),
DARK_GREEN("dark_green"),
DARK_AQUA("dark_aqua"),
DARK_RED("dark_red"),
DARK_PURPLE("dark_purple"),
GOLD("gold"),
GRAY("gray"),
DARK_GRAY("dark_gray"),
BLUE("blue"),
GREEN("green"),
AQUA("aqua"),
RED("red"),
LIGHT_PURPLE("light_purple"),
YELLOW("yellow"),
WHITE("white");
private String _minecraftString;
Color(String minecraftString)
{
_minecraftString = minecraftString;
}
@Override
public String toString()
{
return _minecraftString;
}
}

View File

@ -0,0 +1,21 @@
package mineplex.core.common.jsonchat;
public enum HoverEvent
{
SHOW_TEXT("show_text"),
SHOW_ITEM("show_item"),
SHOW_ACHIEVEMENT("show_achievement");
private String _minecraftString;
HoverEvent(String minecraftString)
{
_minecraftString = minecraftString;
}
@Override
public String toString()
{
return _minecraftString;
}
}

View File

@ -35,6 +35,34 @@ public class JsonMessage
return this;
}
public JsonMessage italic()
{
Builder.append(", italic:true");
return this;
}
public JsonMessage underlined()
{
Builder.append(", underlined:true");
return this;
}
public JsonMessage strikethrough()
{
Builder.append(", strikethrough:true");
return this;
}
public JsonMessage obfuscated()
{
Builder.append(", obfuscated:true");
return this;
}
public ChildJsonMessage extra(String text)
{
@ -48,13 +76,28 @@ public class JsonMessage
return this;
}
public JsonMessage hover(String action, String value)
{
Builder.append(", \"hoverEvent\":{\"action\":\"" + action + "\",\"value\":\"" + value + "\"}");
return this;
}
public JsonMessage click(ClickEvent event, String value)
{
return click(event.toString(), value);
}
public JsonMessage hover(HoverEvent event, String value)
{
return hover(event.toString(), value);
}
public JsonMessage color(Color color)
{
return color(color.toString());
}
public String toString()
{