mirror of
https://github.com/Aust1n46/VentureChat.git
synced 2025-05-23 02:19:05 +00:00
Added documentation
This commit is contained in:
parent
d4a693d213
commit
663d11689d
@ -9,38 +9,45 @@ import org.bukkit.configuration.ConfigurationSection;
|
|||||||
import mineverse.Aust1n46.chat.MineverseChat;
|
import mineverse.Aust1n46.chat.MineverseChat;
|
||||||
import mineverse.Aust1n46.chat.utilities.Format;
|
import mineverse.Aust1n46.chat.utilities.Format;
|
||||||
|
|
||||||
//This class is used to create ChatChannel objects, which store all the information for a channel. This
|
/**
|
||||||
//information is read in from the config file when the server starts up.
|
* Chat channel object pojo. Class also contains static initialization methods
|
||||||
|
* for reading chat channels from the config file.
|
||||||
|
*
|
||||||
|
* @author Aust1n46
|
||||||
|
*/
|
||||||
public class ChatChannel {
|
public class ChatChannel {
|
||||||
private static final String PERMISSION_PREFIX = "venturechat.";
|
private static final String PERMISSION_PREFIX = "venturechat.";
|
||||||
private static final String NO_PERMISSIONS = "venturechat.none";
|
private static final String NO_PERMISSIONS = "venturechat.none";
|
||||||
|
|
||||||
private static MineverseChat plugin = MineverseChat.getInstance();
|
private static MineverseChat plugin = MineverseChat.getInstance();
|
||||||
private static ChatChannel defaultChatChannel;
|
private static ChatChannel defaultChatChannel;
|
||||||
private static ChatChannel[] channels;
|
private static ChatChannel[] channels;
|
||||||
private static String defaultColor;
|
private static String defaultColor;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String permission;
|
private String permission;
|
||||||
private String speakPermission;
|
private String speakPermission;
|
||||||
private Boolean mutable;
|
private boolean mutable;
|
||||||
private String color;
|
private String color;
|
||||||
private String chatColor;
|
private String chatColor;
|
||||||
private Boolean defaultChannel;
|
private boolean defaultChannel;
|
||||||
private Boolean autojoin;
|
private boolean autojoin;
|
||||||
private String alias;
|
private String alias;
|
||||||
private Double distance;
|
private double distance;
|
||||||
private Boolean filter;
|
private boolean filter;
|
||||||
private Boolean bungee;
|
private boolean bungee;
|
||||||
private String format;
|
private String format;
|
||||||
private int cooldown;
|
private int cooldown;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read chat channels from config file and initialize channel array.
|
||||||
|
*/
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("channels");
|
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("channels");
|
||||||
int len = (cs.getKeys(false)).size();
|
int len = (cs.getKeys(false)).size();
|
||||||
channels = new ChatChannel[len];
|
channels = new ChatChannel[len];
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for(String key : cs.getKeys(false)) {
|
for (String key : cs.getKeys(false)) {
|
||||||
String color = cs.getString(key + ".color", "white");
|
String color = cs.getString(key + ".color", "white");
|
||||||
String chatColor = cs.getString(key + ".chatcolor", "white");
|
String chatColor = cs.getString(key + ".chatcolor", "white");
|
||||||
String name = key;
|
String name = key;
|
||||||
@ -55,51 +62,106 @@ public class ChatChannel {
|
|||||||
double distance = cs.getDouble(key + ".distance", (double) 0);
|
double distance = cs.getDouble(key + ".distance", (double) 0);
|
||||||
int cooldown = cs.getInt(key + ".cooldown", 0);
|
int cooldown = cs.getInt(key + ".cooldown", 0);
|
||||||
boolean autojoin = cs.getBoolean(key + ".autojoin", false);
|
boolean autojoin = cs.getBoolean(key + ".autojoin", false);
|
||||||
ChatChannel chatChannel = new ChatChannel(name, color, chatColor, permission, speakPermission, mutable, filter, defaultChannel, alias, distance, autojoin, bungee, cooldown, format);
|
ChatChannel chatChannel = new ChatChannel(name, color, chatColor, permission, speakPermission, mutable,
|
||||||
|
filter, defaultChannel, alias, distance, autojoin, bungee, cooldown, format);
|
||||||
channels[counter++] = chatChannel;
|
channels[counter++] = chatChannel;
|
||||||
if(defaultChannel) {
|
if (defaultChannel) {
|
||||||
defaultChatChannel = chatChannel;
|
defaultChatChannel = chatChannel;
|
||||||
defaultColor = color;
|
defaultColor = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get array of chat channels.
|
||||||
|
*
|
||||||
|
* @return {@link ChatChannel}[]
|
||||||
|
*/
|
||||||
public static ChatChannel[] getChannels() {
|
public static ChatChannel[] getChannels() {
|
||||||
return channels;
|
return channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatChannel getChannel(String ChannelName) {
|
/**
|
||||||
for(ChatChannel c : channels) {
|
* Get a chat channel by name.
|
||||||
if(c.getName().equalsIgnoreCase(ChannelName) || c.getAlias().equalsIgnoreCase(ChannelName)) {
|
*
|
||||||
|
* @param channelName
|
||||||
|
* name of channel to get.
|
||||||
|
* @return {@link ChatChannel}
|
||||||
|
*/
|
||||||
|
public static ChatChannel getChannel(String channelName) {
|
||||||
|
for (ChatChannel c : channels) {
|
||||||
|
if (c.getName().equalsIgnoreCase(channelName) || c.getAlias().equalsIgnoreCase(channelName)) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isChannel(String channel) {
|
/**
|
||||||
return getChannel(channel) != null;
|
* Checks if the chat channel exists.
|
||||||
|
*
|
||||||
|
* @param channelName
|
||||||
|
* name of channel to check.
|
||||||
|
* @return true if channel exists, false otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean isChannel(String channelName) {
|
||||||
|
return getChannel(channelName) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default chat channel color.
|
||||||
|
*
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public static String getDefaultColor() {
|
public static String getDefaultColor() {
|
||||||
return defaultColor;
|
return defaultColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default chat channel.
|
||||||
|
*
|
||||||
|
* @return {@link ChatChannel}
|
||||||
|
*/
|
||||||
public static ChatChannel getDefaultChannel() {
|
public static ChatChannel getDefaultChannel() {
|
||||||
return defaultChatChannel;
|
return defaultChatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of chat channels with autojoin set to true.
|
||||||
|
*
|
||||||
|
* @return {@link List}<{@link ChatChannel}>
|
||||||
|
*/
|
||||||
public static List<ChatChannel> getAutojoinList() {
|
public static List<ChatChannel> getAutojoinList() {
|
||||||
List<ChatChannel> joinlist = new ArrayList<ChatChannel>();
|
List<ChatChannel> joinlist = new ArrayList<ChatChannel>();
|
||||||
for(ChatChannel c : channels) {
|
for (ChatChannel c : channels) {
|
||||||
if(c.getAutojoin()) {
|
if (c.getAutojoin()) {
|
||||||
joinlist.add(c);
|
joinlist.add(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return joinlist;
|
return joinlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatChannel(String name, String color, String chatColor, String permission, String speakPermission, Boolean mutable, Boolean filter, Boolean defaultChannel, String alias, Double distance, Boolean autojoin, Boolean bungee, int cooldown, String format) {
|
/**
|
||||||
|
* Parameterized constructor a {@link ChatChannel}.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* @param color
|
||||||
|
* @param chatColor
|
||||||
|
* @param permission
|
||||||
|
* @param speakPermission
|
||||||
|
* @param mutable
|
||||||
|
* @param filter
|
||||||
|
* @param defaultChannel
|
||||||
|
* @param alias
|
||||||
|
* @param distance
|
||||||
|
* @param autojoin
|
||||||
|
* @param bungee
|
||||||
|
* @param cooldown
|
||||||
|
* @param format
|
||||||
|
*/
|
||||||
|
public ChatChannel(String name, String color, String chatColor, String permission, String speakPermission,
|
||||||
|
boolean mutable, boolean filter, boolean defaultChannel, String alias, double distance, boolean autojoin,
|
||||||
|
boolean bungee, int cooldown, String format) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
this.chatColor = chatColor;
|
this.chatColor = chatColor;
|
||||||
@ -116,101 +178,213 @@ public class ChatChannel {
|
|||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the name of the chat channel.
|
||||||
|
*
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the format of the chat channel.
|
||||||
|
*
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public String getFormat() {
|
public String getFormat() {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the cooldown of the chat channel in seconds.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
public int getCooldown() {
|
public int getCooldown() {
|
||||||
return cooldown;
|
return cooldown;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getBungee() {
|
/**
|
||||||
|
* Check if the chat channel is BungeeCord enabled.
|
||||||
|
*
|
||||||
|
* @return true if the chat channel is BungeeCord enabled, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean getBungee() {
|
||||||
return bungee;
|
return bungee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the permissions node for the chat channel.
|
||||||
|
*
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public String getPermission() {
|
public String getPermission() {
|
||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getAutojoin() {
|
/**
|
||||||
|
* Check if autojoin is enabled for the chat channel.
|
||||||
|
*
|
||||||
|
* @return true if autojoin is enabled, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean getAutojoin() {
|
||||||
return autojoin;
|
return autojoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isMutable() {
|
/**
|
||||||
|
* Check if the chat channel allows muting.
|
||||||
|
*
|
||||||
|
* @return true if muting is allowed, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isMutable() {
|
||||||
return mutable;
|
return mutable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the formatted color of the chat channel.
|
||||||
|
*
|
||||||
|
* @return {@link String}. Returns {@link Format#DEFAULT_COLOR_CODE} if the
|
||||||
|
* color is invalid.
|
||||||
|
*/
|
||||||
public String getColor() {
|
public String getColor() {
|
||||||
if(Format.isValidColor(color)) {
|
if (Format.isValidColor(color)) {
|
||||||
return String.valueOf(ChatColor.valueOf(color.toUpperCase()));
|
return String.valueOf(ChatColor.valueOf(color.toUpperCase()));
|
||||||
}
|
}
|
||||||
if(Format.isValidHexColor(color)) {
|
if (Format.isValidHexColor(color)) {
|
||||||
return Format.convertHexColorCodeToBukkitColorCode(color);
|
return Format.convertHexColorCodeToBukkitColorCode(color);
|
||||||
}
|
}
|
||||||
return Format.DEFAULT_COLOR_CODE;
|
return Format.DEFAULT_COLOR_CODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the raw color value of the chat channel.
|
||||||
|
*
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public String getColorRaw() {
|
public String getColorRaw() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the formatted chat color of the chat channel.
|
||||||
|
*
|
||||||
|
* @return {@link String}. Returns {@link Format#DEFAULT_COLOR_CODE} if the chat
|
||||||
|
* color is invalid.
|
||||||
|
*/
|
||||||
public String getChatColor() {
|
public String getChatColor() {
|
||||||
if(chatColor.equalsIgnoreCase("None")) {
|
if (chatColor.equalsIgnoreCase("None")) {
|
||||||
return chatColor;
|
return chatColor;
|
||||||
}
|
}
|
||||||
if(Format.isValidColor(chatColor)) {
|
if (Format.isValidColor(chatColor)) {
|
||||||
return String.valueOf(ChatColor.valueOf(chatColor.toUpperCase()));
|
return String.valueOf(ChatColor.valueOf(chatColor.toUpperCase()));
|
||||||
}
|
}
|
||||||
if(Format.isValidHexColor(chatColor)) {
|
if (Format.isValidHexColor(chatColor)) {
|
||||||
return Format.convertHexColorCodeToBukkitColorCode(chatColor);
|
return Format.convertHexColorCodeToBukkitColorCode(chatColor);
|
||||||
}
|
}
|
||||||
return Format.DEFAULT_COLOR_CODE;
|
return Format.DEFAULT_COLOR_CODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the raw chat color value of the chat channel.
|
||||||
|
*
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public String getChatColorRaw() {
|
public String getChatColorRaw() {
|
||||||
return chatColor;
|
return chatColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isDefaultchannel() {
|
/**
|
||||||
|
* Check if the chat channel is the default chat channel.
|
||||||
|
*
|
||||||
|
* @return true if the chat channel is the default chat channel, false
|
||||||
|
* otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isDefaultchannel() {
|
||||||
return defaultChannel;
|
return defaultChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the alias of the chat channel.
|
||||||
|
*
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public String getAlias() {
|
public String getAlias() {
|
||||||
return alias;
|
return alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getDistance() {
|
/**
|
||||||
|
* Get the distance of the chat channel in blocks.
|
||||||
|
*
|
||||||
|
* @return double
|
||||||
|
*/
|
||||||
|
public double getDistance() {
|
||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean hasDistance() {
|
/**
|
||||||
|
* Checks if the chat channel has a distance set.
|
||||||
|
*
|
||||||
|
* @return true if the distance is greater than zero, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasDistance() {
|
||||||
return distance > 0;
|
return distance > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean hasCooldown() {
|
/**
|
||||||
|
* Checks if the chat channel has a cooldown set.
|
||||||
|
*
|
||||||
|
* @return true if the cooldown is greater than zero, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasCooldown() {
|
||||||
return cooldown > 0;
|
return cooldown > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean hasPermission() {
|
/**
|
||||||
|
* Checks if the chat channel has a permission set.
|
||||||
|
*
|
||||||
|
* @return true if the permission does not equal
|
||||||
|
* {@link ChatChannel#NO_PERMISSIONS}, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean hasPermission() {
|
||||||
return !permission.equalsIgnoreCase(NO_PERMISSIONS);
|
return !permission.equalsIgnoreCase(NO_PERMISSIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the chat channel has a speak permission set.
|
||||||
|
*
|
||||||
|
* @return true if the speak permission does not equal
|
||||||
|
* {@link ChatChannel#NO_PERMISSIONS}, false otherwise.
|
||||||
|
*/
|
||||||
public boolean hasSpeakPermission() {
|
public boolean hasSpeakPermission() {
|
||||||
return !speakPermission.equalsIgnoreCase(NO_PERMISSIONS);
|
return !speakPermission.equalsIgnoreCase(NO_PERMISSIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the speak permissions node for the chat channel.
|
||||||
|
*
|
||||||
|
* @return {@link String}
|
||||||
|
*/
|
||||||
public String getSpeakPermission() {
|
public String getSpeakPermission() {
|
||||||
return speakPermission;
|
return speakPermission;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isFiltered() {
|
/**
|
||||||
|
* Checks if the chat channel has the filter enabled.
|
||||||
|
*
|
||||||
|
* @return true if the chat channel has the filter enabled, false otherwise.
|
||||||
|
*/
|
||||||
|
public boolean isFiltered() {
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares the chat channel by name to determine equality.
|
||||||
|
*
|
||||||
|
* @param channel
|
||||||
|
* Object to compare for equality.
|
||||||
|
* @return true if the objects are equal, false otherwise.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
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());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user