diff --git a/MineverseChat/mineverse/Aust1n46/chat/channel/ChatChannel.java b/MineverseChat/mineverse/Aust1n46/chat/channel/ChatChannel.java index 740e263..b9c205a 100644 --- a/MineverseChat/mineverse/Aust1n46/chat/channel/ChatChannel.java +++ b/MineverseChat/mineverse/Aust1n46/chat/channel/ChatChannel.java @@ -9,38 +9,45 @@ import org.bukkit.configuration.ConfigurationSection; import mineverse.Aust1n46.chat.MineverseChat; 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 { private static final String PERMISSION_PREFIX = "venturechat."; private static final String NO_PERMISSIONS = "venturechat.none"; - + private static MineverseChat plugin = MineverseChat.getInstance(); private static ChatChannel defaultChatChannel; private static ChatChannel[] channels; private static String defaultColor; - + private String name; private String permission; private String speakPermission; - private Boolean mutable; + private boolean mutable; private String color; private String chatColor; - private Boolean defaultChannel; - private Boolean autojoin; + private boolean defaultChannel; + private boolean autojoin; private String alias; - private Double distance; - private Boolean filter; - private Boolean bungee; + private double distance; + private boolean filter; + private boolean bungee; private String format; private int cooldown; - + + /** + * Read chat channels from config file and initialize channel array. + */ public static void initialize() { ConfigurationSection cs = plugin.getConfig().getConfigurationSection("channels"); int len = (cs.getKeys(false)).size(); channels = new ChatChannel[len]; int counter = 0; - for(String key : cs.getKeys(false)) { + for (String key : cs.getKeys(false)) { String color = cs.getString(key + ".color", "white"); String chatColor = cs.getString(key + ".chatcolor", "white"); String name = key; @@ -55,51 +62,106 @@ public class ChatChannel { double distance = cs.getDouble(key + ".distance", (double) 0); int cooldown = cs.getInt(key + ".cooldown", 0); 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; - if(defaultChannel) { + if (defaultChannel) { defaultChatChannel = chatChannel; defaultColor = color; } } } - + + /** + * Get array of chat channels. + * + * @return {@link ChatChannel}[] + */ public static ChatChannel[] getChannels() { return channels; } - - public static ChatChannel getChannel(String ChannelName) { - for(ChatChannel c : channels) { - if(c.getName().equalsIgnoreCase(ChannelName) || c.getAlias().equalsIgnoreCase(ChannelName)) { + + /** + * Get a chat channel by name. + * + * @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 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() { return defaultColor; } - + + /** + * Get default chat channel. + * + * @return {@link ChatChannel} + */ public static ChatChannel getDefaultChannel() { return defaultChatChannel; } - + + /** + * Get list of chat channels with autojoin set to true. + * + * @return {@link List}<{@link ChatChannel}> + */ public static List getAutojoinList() { List joinlist = new ArrayList(); - for(ChatChannel c : channels) { - if(c.getAutojoin()) { + for (ChatChannel c : channels) { + if (c.getAutojoin()) { joinlist.add(c); } } 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.color = color; this.chatColor = chatColor; @@ -116,101 +178,213 @@ public class ChatChannel { this.format = format; } + /** + * Get the name of the chat channel. + * + * @return {@link String} + */ public String getName() { return name; } + /** + * Get the format of the chat channel. + * + * @return {@link String} + */ public String getFormat() { return format; } + /** + * Get the cooldown of the chat channel in seconds. + * + * @return int + */ public int getCooldown() { 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; } + /** + * Get the permissions node for the chat channel. + * + * @return {@link String} + */ public String getPermission() { 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; } - public Boolean isMutable() { + /** + * Check if the chat channel allows muting. + * + * @return true if muting is allowed, false otherwise. + */ + public boolean isMutable() { 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() { - if(Format.isValidColor(color)) { + if (Format.isValidColor(color)) { return String.valueOf(ChatColor.valueOf(color.toUpperCase())); } - if(Format.isValidHexColor(color)) { + if (Format.isValidHexColor(color)) { return Format.convertHexColorCodeToBukkitColorCode(color); } return Format.DEFAULT_COLOR_CODE; } - + + /** + * Get the raw color value of the chat channel. + * + * @return {@link String} + */ public String getColorRaw() { 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() { - if(chatColor.equalsIgnoreCase("None")) { + if (chatColor.equalsIgnoreCase("None")) { return chatColor; } - if(Format.isValidColor(chatColor)) { + if (Format.isValidColor(chatColor)) { return String.valueOf(ChatColor.valueOf(chatColor.toUpperCase())); } - if(Format.isValidHexColor(chatColor)) { + if (Format.isValidHexColor(chatColor)) { return Format.convertHexColorCodeToBukkitColorCode(chatColor); } return Format.DEFAULT_COLOR_CODE; } - + + /** + * Get the raw chat color value of the chat channel. + * + * @return {@link String} + */ public String getChatColorRaw() { 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; } + /** + * Get the alias of the chat channel. + * + * @return {@link String} + */ public String getAlias() { return alias; } - public Double getDistance() { + /** + * Get the distance of the chat channel in blocks. + * + * @return double + */ + public double getDistance() { 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; } - 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; } - 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); } - + + /** + * 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() { return !speakPermission.equalsIgnoreCase(NO_PERMISSIONS); } - + + /** + * Get the speak permissions node for the chat channel. + * + * @return {@link String} + */ public String getSpeakPermission() { 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; } - + + /** + * 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 public boolean equals(Object channel) { return channel instanceof ChatChannel && this.name.equals(((ChatChannel) channel).getName());