From ff5cd601665f6a4159e7e427d04deba643668074 Mon Sep 17 00:00:00 2001 From: Ryandw11 <6239385+ryandw11@users.noreply.github.com> Date: Mon, 8 Jul 2019 22:54:39 -0700 Subject: [PATCH] Did some work with the JSONBuilder Did some work with the JSONBuilder. Laid out the config for the JSON Component idea. --- config.yml | 20 +++++ src/me/ryandw11/ultrachat/api/JSON.java | 8 +- .../ultrachat/api/JSONChatBuilder.java | 77 +++++++++++++++++++ .../ultrachat/api/MessageBuilder.java | 53 +++++++++++++ 4 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 src/me/ryandw11/ultrachat/api/JSONChatBuilder.java create mode 100644 src/me/ryandw11/ultrachat/api/MessageBuilder.java diff --git a/config.yml b/config.yml index bdcd1f8..ad85733 100644 --- a/config.yml +++ b/config.yml @@ -39,6 +39,26 @@ Blocked_Words: - sh*t - asshole - fucker +############################################# +# JSON Component # +############################################# +# This is a system to create JSON pockets with in a message. +# It uses a placerholder system to use. +#The name of the component: +example: + #The base message of the component + Message: 'Example Message' + #The component events + Events: + #A click event {Optional} + Click: + # One and only one of the Click Operations. Full list includes: {Open_URL, Run_Command, Suggest_Command} + Open_URL: 'https://www.spigotmc.org/' + # When the player hovers over the base text. + Hover: + Show_Text: + - 'This is the first line' + - '&cThis is the second line' ############################################## # Chat Format Type # ############################################## diff --git a/src/me/ryandw11/ultrachat/api/JSON.java b/src/me/ryandw11/ultrachat/api/JSON.java index 9f8ce31..046884a 100644 --- a/src/me/ryandw11/ultrachat/api/JSON.java +++ b/src/me/ryandw11/ultrachat/api/JSON.java @@ -16,7 +16,13 @@ import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention; - +/** + * + * This class is deperecated. Use {@link JSONChatBuilder} with {@link MessageBuilder} instead. + * @deprecated + * @author Ryandw11 + * + */ public class JSON { //private UltraChat plugin; diff --git a/src/me/ryandw11/ultrachat/api/JSONChatBuilder.java b/src/me/ryandw11/ultrachat/api/JSONChatBuilder.java new file mode 100644 index 0000000..25fd76c --- /dev/null +++ b/src/me/ryandw11/ultrachat/api/JSONChatBuilder.java @@ -0,0 +1,77 @@ +package me.ryandw11.ultrachat.api; + +import java.util.List; + +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; + +/** + * API to standardize JSONChatBuilding + *

To be used with the MessageBuilder {@link MessageBuilder} + * @author Ryandw11 + * @since 2.4 + * + */ +public class JSONChatBuilder { + + private ComponentBuilder displayMessage; + + public JSONChatBuilder(String displayMessage) { + this.displayMessage = new ComponentBuilder(displayMessage); + } + + /** + * Add a hove message. + * @param lore Lore + */ + public JSONChatBuilder setHoverShowText(List lore) { + ComponentBuilder lores = new ComponentBuilder(""); + for(String s : lore) { + lores.append(ChatColor.translateAlternateColorCodes('&', s)); + } + this.displayMessage.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, lores.create())); + return this; + } + + /** + * Have the JSON open up a url. + * @param url The url + * @return The builder + */ + public JSONChatBuilder setClickOpenUrl(String url) { + this.displayMessage.event(new ClickEvent(ClickEvent.Action.OPEN_URL, url)); + return this; + } + + /** + * Have the JSON run a command. + * @param command The command to run + * @return The builder + */ + public JSONChatBuilder setClickRunCommand(String command) { + this.displayMessage.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)); + return this; + } + + /** + * Have the JSON suggest a command + * @param command The command + * @return The Builder + */ + public JSONChatBuilder setClickSuggestCommand(String command) { + this.displayMessage.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)); + return this; + } + + /** + * Build the JSONChatMessage + * @return The BaseComponent[] + */ + public BaseComponent[] build() { + return this.displayMessage.create(); + } + +} diff --git a/src/me/ryandw11/ultrachat/api/MessageBuilder.java b/src/me/ryandw11/ultrachat/api/MessageBuilder.java new file mode 100644 index 0000000..68af6c3 --- /dev/null +++ b/src/me/ryandw11/ultrachat/api/MessageBuilder.java @@ -0,0 +1,53 @@ +package me.ryandw11.ultrachat.api; + +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.ComponentBuilder; + +/** + * Easy Builder to build several JSON sections into a single message. + * {@link JSONChatBuilder} + * @author Ryandw11 + * @since 2.4 + * + */ +public class MessageBuilder { + + private ComponentBuilder compon; + public MessageBuilder() { + compon = new ComponentBuilder(""); + } + + /** + * Add a JSONChatBuilder to the message + * @param json the JSONChatBuilder to add + * @return The MessageBuilder to chain. + */ + public MessageBuilder addJSON(JSONChatBuilder json) { + compon.append(json.build()); + return this; + } + + /** + * Add a string to the message + * @param s the string to add + * @return the builder to chain + */ + public MessageBuilder addString(String s) { + compon.append(s); + return this; + } + + /** + * Add a base component to the message + * @param bc the component to add + * @return The Buider to chain + */ + public MessageBuilder addBaseComponent(BaseComponent[] bc) { + compon.append(bc); + return this; + } + + public BaseComponent[] build() { + return this.compon.create(); + } +}