mirror of
https://github.com/ryandw11/UltraChat.git
synced 2024-11-22 10:15:50 +01:00
Did some work with the JSONBuilder
Did some work with the JSONBuilder. Laid out the config for the JSON Component idea.
This commit is contained in:
parent
ba2705429b
commit
ff5cd60166
20
config.yml
20
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 #
|
||||
##############################################
|
||||
|
@ -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;
|
||||
|
77
src/me/ryandw11/ultrachat/api/JSONChatBuilder.java
Normal file
77
src/me/ryandw11/ultrachat/api/JSONChatBuilder.java
Normal file
@ -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
|
||||
* <p>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<String> 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();
|
||||
}
|
||||
|
||||
}
|
53
src/me/ryandw11/ultrachat/api/MessageBuilder.java
Normal file
53
src/me/ryandw11/ultrachat/api/MessageBuilder.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user