mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-23 02:19:05 +00:00
Refactored JsonFormat and ChatChannel implementations.
This commit is contained in:
parent
e9a6da45fe
commit
d429327952
@ -47,7 +47,7 @@ import mineverse.Aust1n46.chat.command.mute.MuteContainer;
|
|||||||
import mineverse.Aust1n46.chat.database.Database;
|
import mineverse.Aust1n46.chat.database.Database;
|
||||||
import mineverse.Aust1n46.chat.database.PlayerData;
|
import mineverse.Aust1n46.chat.database.PlayerData;
|
||||||
import mineverse.Aust1n46.chat.gui.GuiSlot;
|
import mineverse.Aust1n46.chat.gui.GuiSlot;
|
||||||
import mineverse.Aust1n46.chat.json.JsonFormatInfo;
|
import mineverse.Aust1n46.chat.json.JsonFormat;
|
||||||
import mineverse.Aust1n46.chat.listeners.ChatListener;
|
import mineverse.Aust1n46.chat.listeners.ChatListener;
|
||||||
import mineverse.Aust1n46.chat.listeners.CommandListener;
|
import mineverse.Aust1n46.chat.listeners.CommandListener;
|
||||||
import mineverse.Aust1n46.chat.listeners.LoginListener;
|
import mineverse.Aust1n46.chat.listeners.LoginListener;
|
||||||
@ -79,7 +79,6 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
|||||||
|
|
||||||
// Misc --------------------------------
|
// Misc --------------------------------
|
||||||
public static AliasInfo aaInfo;
|
public static AliasInfo aaInfo;
|
||||||
public static JsonFormatInfo jfInfo;
|
|
||||||
public boolean quickchat = true;
|
public boolean quickchat = true;
|
||||||
private static final Logger log = Logger.getLogger("Minecraft");
|
private static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
@ -155,8 +154,8 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
|
|||||||
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Registering Listeners"));
|
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Registering Listeners"));
|
||||||
// Channel information reference
|
// Channel information reference
|
||||||
aaInfo = new AliasInfo(this);
|
aaInfo = new AliasInfo(this);
|
||||||
jfInfo = new JsonFormatInfo(this);
|
|
||||||
|
|
||||||
|
JsonFormat.initialize();
|
||||||
GuiSlot.initialize();
|
GuiSlot.initialize();
|
||||||
|
|
||||||
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Loading player data"));
|
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Loading player data"));
|
||||||
|
@ -9,7 +9,6 @@ import java.util.Set;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import mineverse.Aust1n46.chat.ChatMessage;
|
import mineverse.Aust1n46.chat.ChatMessage;
|
||||||
import mineverse.Aust1n46.chat.MineverseChat;
|
|
||||||
import mineverse.Aust1n46.chat.channel.ChatChannel;
|
import mineverse.Aust1n46.chat.channel.ChatChannel;
|
||||||
import mineverse.Aust1n46.chat.command.mute.MuteContainer;
|
import mineverse.Aust1n46.chat.command.mute.MuteContainer;
|
||||||
import mineverse.Aust1n46.chat.json.JsonFormat;
|
import mineverse.Aust1n46.chat.json.JsonFormat;
|
||||||
@ -527,12 +526,12 @@ public class MineverseChatPlayer {
|
|||||||
|
|
||||||
public void setJsonFormat() {
|
public void setJsonFormat() {
|
||||||
this.jsonFormat = "Default";
|
this.jsonFormat = "Default";
|
||||||
for(JsonFormat j : MineverseChat.jfInfo.getJsonFormats()) {
|
for(JsonFormat j : JsonFormat.getJsonFormats()) {
|
||||||
if(this.getPlayer().isPermissionSet("venturechat.json." + j.getName())) {
|
if(this.getPlayer().isPermissionSet("venturechat.json." + j.getName())) {
|
||||||
if(MineverseChat.jfInfo.getJsonFormat(this.getJsonFormat()).getPriority() > j.getPriority()) {
|
if(JsonFormat.getJsonFormat(this.getJsonFormat()).getPriority() > j.getPriority()) {
|
||||||
this.jsonFormat = j.getName();
|
this.jsonFormat = j.getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package mineverse.Aust1n46.chat.channel;
|
package mineverse.Aust1n46.chat.channel;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -21,10 +23,12 @@ public class ChatChannel {
|
|||||||
|
|
||||||
private static MineverseChat plugin = MineverseChat.getInstance();
|
private static MineverseChat plugin = MineverseChat.getInstance();
|
||||||
private static ChatChannel defaultChatChannel;
|
private static ChatChannel defaultChatChannel;
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private static ChatChannel[] channels;
|
private static ChatChannel[] channels;
|
||||||
|
|
||||||
private static String defaultColor;
|
private static String defaultColor;
|
||||||
private static List<ChatChannel> chatChannels = new ArrayList<ChatChannel>();
|
private static HashMap<String, ChatChannel> chatChannels = new HashMap<String, ChatChannel>();
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String permission;
|
private String permission;
|
||||||
@ -67,7 +71,8 @@ public class ChatChannel {
|
|||||||
ChatChannel chatChannel = new ChatChannel(name, color, chatColor, permission, speakPermission, mutable,
|
ChatChannel chatChannel = new ChatChannel(name, color, chatColor, permission, speakPermission, mutable,
|
||||||
filter, defaultChannel, alias, distance, autojoin, bungee, cooldown, format);
|
filter, defaultChannel, alias, distance, autojoin, bungee, cooldown, format);
|
||||||
channels[counter++] = chatChannel;
|
channels[counter++] = chatChannel;
|
||||||
chatChannels.add(chatChannel);
|
chatChannels.put(name.toLowerCase(), chatChannel);
|
||||||
|
chatChannels.put(alias.toLowerCase(), chatChannel);
|
||||||
if (defaultChannel) {
|
if (defaultChannel) {
|
||||||
defaultChatChannel = chatChannel;
|
defaultChatChannel = chatChannel;
|
||||||
defaultColor = color;
|
defaultColor = color;
|
||||||
@ -90,8 +95,8 @@ public class ChatChannel {
|
|||||||
*
|
*
|
||||||
* @return {@link List}<{@link ChatChannel}>
|
* @return {@link List}<{@link ChatChannel}>
|
||||||
*/
|
*/
|
||||||
public static List<ChatChannel> getChatChannels() {
|
public static Collection<ChatChannel> getChatChannels() {
|
||||||
return chatChannels;
|
return chatChannels.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -102,12 +107,7 @@ public class ChatChannel {
|
|||||||
* @return {@link ChatChannel}
|
* @return {@link ChatChannel}
|
||||||
*/
|
*/
|
||||||
public static ChatChannel getChannel(String channelName) {
|
public static ChatChannel getChannel(String channelName) {
|
||||||
for (ChatChannel c : channels) {
|
return chatChannels.get(channelName.toLowerCase());
|
||||||
if (c.getName().equalsIgnoreCase(channelName) || c.getAlias().equalsIgnoreCase(channelName)) {
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -446,4 +446,4 @@ public class ChatChannel {
|
|||||||
public boolean equals(Object channel) {
|
public boolean equals(Object channel) {
|
||||||
return channel instanceof ChatChannel && this.name.equals(((ChatChannel) channel).getName());
|
return channel instanceof ChatChannel && this.name.equals(((ChatChannel) channel).getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,17 @@
|
|||||||
package mineverse.Aust1n46.chat.json;
|
package mineverse.Aust1n46.chat.json;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
//This class is used to create JsonFormat objects using data from the config file.
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
|
import mineverse.Aust1n46.chat.MineverseChat;
|
||||||
|
|
||||||
public class JsonFormat {
|
public class JsonFormat {
|
||||||
|
private static MineverseChat plugin = MineverseChat.getInstance();
|
||||||
|
private static HashMap<String, JsonFormat> jsonFormats = new HashMap<String, JsonFormat>();
|
||||||
|
|
||||||
private List<String> hoverTextName;
|
private List<String> hoverTextName;
|
||||||
private List<String> hoverTextPrefix;
|
private List<String> hoverTextPrefix;
|
||||||
private List<String> hoverTextSuffix;
|
private List<String> hoverTextSuffix;
|
||||||
@ -30,47 +38,73 @@ public class JsonFormat {
|
|||||||
this.hoverTextSuffix = hoverTextSuffix;
|
this.hoverTextSuffix = hoverTextSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void initialize() {
|
||||||
|
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("jsonformatting");
|
||||||
|
for(String key : cs.getKeys(false)) {
|
||||||
|
String name = key;
|
||||||
|
int priority = cs.getInt(key + ".priority", 0);
|
||||||
|
List<String> hoverTextName = cs.getStringList(key + ".hover_name");
|
||||||
|
List<String> hoverTextPrefix = cs.getStringList(key + ".hover_prefix");
|
||||||
|
List<String> hoverTextSuffix = cs.getStringList(key + ".hover_suffix");
|
||||||
|
String clickPrefix = cs.getString(key + ".click_prefix");
|
||||||
|
String clickName = cs.getString(key + ".click_name");
|
||||||
|
String clickNameText = cs.getString(key + ".click_name_text");
|
||||||
|
String clickPrefixText = cs.getString(key + ".click_prefix_text");
|
||||||
|
String clickSuffixText = cs.getString(key + ".click_suffix_text");
|
||||||
|
String clickSuffix = cs.getString(key + ".click_suffix");
|
||||||
|
jsonFormats.put(name.toLowerCase(), new JsonFormat(name, priority, hoverTextName, clickName, clickNameText, hoverTextPrefix, clickPrefix, clickPrefixText, clickSuffix, clickSuffixText, hoverTextSuffix));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Collection<JsonFormat> getJsonFormats() {
|
||||||
|
return jsonFormats.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonFormat getJsonFormat(String name) {
|
||||||
|
return jsonFormats.get(name.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClickName() {
|
public String getClickName() {
|
||||||
return this.clickName;
|
return clickName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClickNameText() {
|
public String getClickNameText() {
|
||||||
return this.clickNameText;
|
return clickNameText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClickSuffix() {
|
public String getClickSuffix() {
|
||||||
return this.clickSuffix;
|
return clickSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClickSuffixText() {
|
public String getClickSuffixText() {
|
||||||
return this.clickSuffixText;
|
return clickSuffixText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPriority() {
|
public int getPriority() {
|
||||||
return this.priority;
|
return priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getHoverTextName() {
|
public List<String> getHoverTextName() {
|
||||||
return this.hoverTextName;
|
return hoverTextName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getHoverTextPrefix() {
|
public List<String> getHoverTextPrefix() {
|
||||||
return this.hoverTextPrefix;
|
return hoverTextPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getHoverTextSuffix() {
|
public List<String> getHoverTextSuffix() {
|
||||||
return this.hoverTextSuffix;
|
return hoverTextSuffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClickPrefix() {
|
public String getClickPrefix() {
|
||||||
return this.clickPrefix;
|
return clickPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getClickPrefixText() {
|
public String getClickPrefixText() {
|
||||||
return this.clickPrefixText;
|
return clickPrefixText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,56 +0,0 @@
|
|||||||
package mineverse.Aust1n46.chat.json;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
|
|
||||||
import mineverse.Aust1n46.chat.MineverseChat;
|
|
||||||
|
|
||||||
//This class stores JsonFormat objects in an array and the constructor creates them by reading in data from the config file.
|
|
||||||
public class JsonFormatInfo {
|
|
||||||
private JsonFormat[] jf;
|
|
||||||
|
|
||||||
public JsonFormatInfo(MineverseChat plugin) {
|
|
||||||
String name;
|
|
||||||
int priority = 0;
|
|
||||||
List<String> hoverTextName;
|
|
||||||
List<String> hoverTextPrefix;
|
|
||||||
List<String> hoverTextSuffix;
|
|
||||||
String clickPrefix;
|
|
||||||
String clickName;
|
|
||||||
String clickNameText;
|
|
||||||
String clickPrefixText;
|
|
||||||
String clickSuffix;
|
|
||||||
String clickSuffixText;
|
|
||||||
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("jsonformatting");
|
|
||||||
jf = new JsonFormat[cs.getKeys(false).size()];
|
|
||||||
int x = 0;
|
|
||||||
for(String key : cs.getKeys(false)) {
|
|
||||||
name = key;
|
|
||||||
priority = cs.getInt(key + ".priority", 0);
|
|
||||||
hoverTextName = cs.getStringList(key + ".hover_name");
|
|
||||||
hoverTextPrefix = cs.getStringList(key + ".hover_prefix");
|
|
||||||
hoverTextSuffix = cs.getStringList(key + ".hover_suffix");
|
|
||||||
clickPrefix = cs.getString(key + ".click_prefix");
|
|
||||||
clickName = cs.getString(key + ".click_name");
|
|
||||||
clickNameText = cs.getString(key + ".click_name_text");
|
|
||||||
clickPrefixText = cs.getString(key + ".click_prefix_text");
|
|
||||||
clickSuffixText = cs.getString(key + ".click_suffix_text");
|
|
||||||
clickSuffix = cs.getString(key + ".click_suffix");
|
|
||||||
JsonFormat j = new JsonFormat(name, priority, hoverTextName, clickName, clickNameText, hoverTextPrefix, clickPrefix, clickPrefixText, clickSuffix, clickSuffixText, hoverTextSuffix);
|
|
||||||
jf[x ++] = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonFormat[] getJsonFormats() {
|
|
||||||
return this.jf;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JsonFormat getJsonFormat(String name) {
|
|
||||||
for(JsonFormat j : this.jf) {
|
|
||||||
if(j.getName().equalsIgnoreCase(name))
|
|
||||||
return j;
|
|
||||||
}
|
|
||||||
return getJsonFormat("Default");
|
|
||||||
}
|
|
||||||
}
|
|
@ -66,7 +66,7 @@ public class Format {
|
|||||||
* @return {@link String}
|
* @return {@link String}
|
||||||
*/
|
*/
|
||||||
public static String convertToJson(MineverseChatPlayer sender, String format, String chat) {
|
public static String convertToJson(MineverseChatPlayer sender, String format, String chat) {
|
||||||
JsonFormat JSONformat = MineverseChat.jfInfo.getJsonFormat(sender.getJsonFormat());
|
JsonFormat JSONformat = JsonFormat.getJsonFormat(sender.getJsonFormat());
|
||||||
String f = escapeJsonChars(format);
|
String f = escapeJsonChars(format);
|
||||||
String c = escapeJsonChars(chat);
|
String c = escapeJsonChars(chat);
|
||||||
String json = "[\"\",{\"text\":\"\",\"extra\":[";
|
String json = "[\"\",{\"text\":\"\",\"extra\":[";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user