diff --git a/channel.yml b/channel.yml index ba213de..6663555 100644 --- a/channel.yml +++ b/channel.yml @@ -15,17 +15,11 @@ global: #Messages from this channel will always appear no matter what channel the player is in. always_appear: false #This is the chat format ***Note the channel prefix is added by default. + #The format support components from the config.yml. See the Normal Chat for an example. format: '%prefix% %player% %suffix%&7>> ' - #This is the JSON format: - JSON: - - '&3Money: $&b%vault_eco_balance_fixed%' - - '&3Username: &f%player_name%' #Example Channel: vip: prefix: '&a[&6VIP&a]&r' permission: 'channel.vip' always_appear: false - format: '%prefix% %player% %suffix%&7>> ' - JSON: - - '&3Money: $&b%vault_eco_balance_fixed%' - - '&3Username: &f%player_name%' \ No newline at end of file + format: '%prefix% %player% %suffix%&7>> ' \ No newline at end of file diff --git a/config.yml b/config.yml index 01df505..8f27fdc 100644 --- a/config.yml +++ b/config.yml @@ -18,9 +18,7 @@ apirestrict: false pluginhooks: Essentials: true AdvancedBan: true -#Join / Leave messages: -Join_Message: '&e %player% has joined the server!' -Leave_Message: '&e %player% has left the server!' + ############################################# # Anti - Swear # @@ -39,81 +37,10 @@ Blocked_Words: - sh*t - asshole - fucker + ############################################# -# JSON Component # +# Join Settings # ############################################# -# This is a system to create JSON pockets with in a message. -# It uses a placerholder system to use. -#The name of the component: -JSON_Components: - 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 # -############################################## -# Vailed types: normal, channel, channel_json, json, range. -# Set to nothing to not format the chat. -# Check the wiki for an explenation of each type! -chat_format: 'normal' - -#The default color that opped players chat in. Do &r for none. -Op_Chat_Color: '&c' -############################################## -# Channels # -############################################## -#Note: Custom Chat must be enabled for this to work! -#Edit the channels.yml when the server is stopped! -#Default Channel. This is the channel the player first joins the server. It is also given when the channel the player is on does not exsist. -Default_Channel: 'global' -#This is a list for the channels. It will only affect the list of channels. (Name should match the same as the one in the channels.yml) -Channel_List: -- global -- vip - -############################################## -# Range # -############################################## -#If json should be enabled on the range chat or not. -Range_Json: false -#The global channel which everyone can see. -Global: - format: '&6[Global]&r %prefix% %player% %suffix% &7>>' - json: - - Example - - Text -World: - format: '&d[World]&r %prefix% %player% %suffix% &7>>' - json: - - Example - - Text -Local: - format: '&b[Local]&r %prefix% %player% %suffix% &7>>' - json: - - Example - - Text - range: 100 -############################################## -# Chat # -# Json / Normal # -############################################## - -#Console Chat Log: (JSON chat only!) -#With json on the chat no longer prints to the console. This option fixes that issue! Set to true if you want it enabled! -console_log: false - - #New player join. If the player hasn't joined the server before then this message will play. If you don't want it put none. New_Player: '&d%player% has just joined the server for the first time! Welcome!' @@ -123,6 +50,48 @@ Motd_Enabled: true Motd: - '&6Welcome to the server,&r %player_name%&6.' - '&6There are currently&b %server_online% &6players online!' + +Join_Message: '&e%player% has joined the server!' +Leave_Message: '&e%player% has left the server!' +############################################# +# JSON Component # +############################################# +# This is a system to create JSON pockets with in a message. +# It uses a placerholder system to use. +#If Components are enabled. +Components_Enabled: true +#The name of the component: +JSON_Components: + normal_chat: + #The base message of the component + Message: '%prefix% %player% %suffix%' + #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} + Suggest_Command: '/msg %player%' + # When the player hovers over the base text. + Hover: + Show_Text: + - '&bLine One' + - '&3Line Two' +############################################## +# # +# Chat # +# # +############################################## +# Vailed types: normal, channel, and range. +# Set to nothing to not format the chat. +# Check the wiki for an explenation of each type! +chat_format: 'normal' + +#The default color that opped players chat in. Do &r for none. +Op_Chat_Color: '&c' + +#Console Chat Log: (JSON chat only!) +#With json on the chat no longer prints to the console. This option fixes that issue! Set to true if you want it enabled! +console_log: false #Variables: %prefix% - Gives you the players prefix. %suffix% - gives you the player suffix! #You can use PlaceHolderAPI here! Check out the placeholders here: https://www.spigotmc.org/wiki/placeholderapi-placeholders/ @@ -143,46 +112,49 @@ Custom_Chat: #The permission node you want to give it. *Does not need to match up with the number above* Permission: 'ultrachat.chat.1' #The custom format in the chat. The message is added after the end of the string. - Format: '%prefix% %player% %suffix%&7>> ' - #JSON formating if enabled. In order to use color codes surround the message in single quotes. '' - JSON: - - Example - - Example 2 - #You can now also suggest a command to a player who clicks it. %player% is the only valid placeholder. + Format: '{normal_chat} &7>> ' 2: Permission: 'ultrachat.chat.2' - Format: '%prefix% %player% %suffix% &7>> ' - JSON: - - Example - - Example 2 + Format: '{normal_chat} &7>> ' 3: Permission: 'ultrachat.chat.3' - Format: '%prefix% %player% %suffix%&7>> ' - JSON: - - '&cNotice' - - '&7Use colorcodes in quotes' + Format: '{normal_chat} &7>> ' 4: Permission: 'ultrachat.chat.4' + #If components are not enabled then you would put this. Format: '%prefix% %player% %suffix%&7>> ' - JSON: - - '45' - - Same with numbers 5: Permission: 'ultrachat.chat.5' Format: '%prefix% %player% %suffix%&7>> ' - JSON: - - Example - - Example 2 #For any player opped. Op_Chat: #The format. - Format: '%prefix% %player% %suffix%&c>> ' - JSON: - - Example - - Example 2 + Format: '{normal_chat} &c>> ' #The default chat when a player does not have a custom one. Default_Chat: - Format: '<%prefix% %player% %suffix%&f>' - JSON: - - Example - - Example 2 \ No newline at end of file + Format: '{normal_chat} &7>>' + +############################################## +# Channels # +############################################## +#Note: Custom Chat must be enabled for this to work! +#Edit the channels.yml when the server is stopped! +#Default Channel. This is the channel the player first joins the server. It is also given when the channel the player is on does not exsist. +Default_Channel: 'global' +#This is a list for the channels. It will only affect the list of channels. (Name should match the same as the one in the channels.yml) +Channel_List: +- global +- vip + +############################################## +# Range # +############################################## +#The global channel which everyone can see. +#All of these formats support Components. See Normal Chat for an example. +Global: + format: '&6[Global]&r %prefix% %player% %suffix% &7>>' +World: + format: '&d[World]&r %prefix% %player% %suffix% &7>>' +Local: + format: '&b[Local]&r %prefix% %player% %suffix% &7>>' + range: 100 \ No newline at end of file diff --git a/src/me/ryandw11/ultrachat/UltraChat.java b/src/me/ryandw11/ultrachat/UltraChat.java index e50d3c2..63e9550 100644 --- a/src/me/ryandw11/ultrachat/UltraChat.java +++ b/src/me/ryandw11/ultrachat/UltraChat.java @@ -6,7 +6,7 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.UUID; -import me.ryandw11.ultrachat.api.ChatMode; +import me.ryandw11.ultrachat.api.ChatType; import me.ryandw11.ultrachat.api.Lang; import me.ryandw11.ultrachat.commands.ChannelCmd; import me.ryandw11.ultrachat.commands.ChatCommand; @@ -16,10 +16,12 @@ import me.ryandw11.ultrachat.commands.StaffChat; import me.ryandw11.ultrachat.commands.StaffChatToggle; import me.ryandw11.ultrachat.commands.World; import me.ryandw11.ultrachat.commands.SpyCommand; +import me.ryandw11.ultrachat.formatting.ChannelJSON; import me.ryandw11.ultrachat.formatting.Channels; -import me.ryandw11.ultrachat.formatting.Chat_Json; import me.ryandw11.ultrachat.formatting.Normal; +import me.ryandw11.ultrachat.formatting.NormalJSON; import me.ryandw11.ultrachat.formatting.Range; +import me.ryandw11.ultrachat.formatting.RangeJSON; import me.ryandw11.ultrachat.gui.ColorGUI; import me.ryandw11.ultrachat.gui.ColorGUI_1_13_R2; import me.ryandw11.ultrachat.gui.ColorGUI_Latest; @@ -62,7 +64,7 @@ public class UltraChat extends JavaPlugin{ public Boolean chatStop = false; public Boolean channelEnabled = false; public Boolean JSON = false; - public ChatMode md; + public ChatType md; public String defaultChannel; public ArrayList stafftoggle = new ArrayList<>(); public ArrayList spytoggle = new ArrayList<>(); @@ -143,47 +145,43 @@ public class UltraChat extends JavaPlugin{ getLogger().info("UltraChat will not format the chat. To change this go into the config."); return; } + + boolean isComponents = plugin.getConfig().getBoolean("Components_Enabled"); + switch(type.toLowerCase()){ case "normal": - Bukkit.getServer().getPluginManager().registerEvents(new Normal(), this); - JSON = false; - channelEnabled = false; - md = ChatMode.NORMAL; + if(isComponents) + Bukkit.getServer().getPluginManager().registerEvents(new NormalJSON(), this); + else + Bukkit.getServer().getPluginManager().registerEvents(new Normal(), this); + md = ChatType.NORMAL; getLogger().info("Normal chat mode activated!"); break; - case "json": - Bukkit.getServer().getPluginManager().registerEvents(new Chat_Json(), this); - JSON = true; - channelEnabled = false; - md = ChatMode.JSON; - getLogger().info("Json chat activated!"); - break; case "channel": - channelEnabled = true; - JSON = false; - Bukkit.getServer().getPluginManager().registerEvents(new Channels(), this); - md = ChatMode.CHANNEL; + if(isComponents) + Bukkit.getServer().getPluginManager().registerEvents(new ChannelJSON(), this); + else + Bukkit.getServer().getPluginManager().registerEvents(new Channels(), this); + md = ChatType.CHANNEL; getLogger().info("Channel chat mode enabled."); break; - case "channel_json": - JSON = true; - channelEnabled = true; - md = ChatMode.JSON_CHANNEL; - Bukkit.getServer().getPluginManager().registerEvents(new Chat_Json(), this); - getLogger().info("Channel chat mode enabled with json."); - break; case "range": - Bukkit.getServer().getPluginManager().registerEvents(new Range(), this); + if(isComponents) + Bukkit.getServer().getPluginManager().registerEvents(new RangeJSON(), this); + else + Bukkit.getServer().getPluginManager().registerEvents(new Range(), this); getCommand("global").setExecutor(new Global()); getCommand("world").setExecutor(new World()); getLogger().info("Range chat mode enabled. The commands /global and /world are now also active."); - md = ChatMode.RANGE; + md = ChatType.RANGE; break; default: - getLogger().warning("§cThe chat format value is not correct!"); - getLogger().warning("§cIt most be one of the following: Normal, Json, Channel, Range. (Caps do not matter)"); - getLogger().warning("§cNo formatting has been enabled!"); - md = ChatMode.NONE; + if(isComponents) + Bukkit.getServer().getPluginManager().registerEvents(new NormalJSON(), this); + else + Bukkit.getServer().getPluginManager().registerEvents(new Normal(), this); + md = ChatType.NORMAL; + getLogger().info("Normal chat mode activated!"); break; } } diff --git a/src/me/ryandw11/ultrachat/api/ChatMode.java b/src/me/ryandw11/ultrachat/api/ChatMode.java deleted file mode 100644 index 2452bc2..0000000 --- a/src/me/ryandw11/ultrachat/api/ChatMode.java +++ /dev/null @@ -1,10 +0,0 @@ -package me.ryandw11.ultrachat.api; - -public enum ChatMode { - NORMAL, - JSON, - CHANNEL, - JSON_CHANNEL, - RANGE, - NONE; -} diff --git a/src/me/ryandw11/ultrachat/api/ChatType.java b/src/me/ryandw11/ultrachat/api/ChatType.java new file mode 100644 index 0000000..86e114a --- /dev/null +++ b/src/me/ryandw11/ultrachat/api/ChatType.java @@ -0,0 +1,8 @@ +package me.ryandw11.ultrachat.api; + +public enum ChatType { + NORMAL, + CHANNEL, + RANGE + +} diff --git a/src/me/ryandw11/ultrachat/api/JSON.java b/src/me/ryandw11/ultrachat/api/JSON.java deleted file mode 100644 index 046884a..0000000 --- a/src/me/ryandw11/ultrachat/api/JSON.java +++ /dev/null @@ -1,84 +0,0 @@ -package me.ryandw11.ultrachat.api; - -import java.util.ArrayList; - -import org.bukkit.entity.Player; - -import me.clip.placeholderapi.PlaceholderAPI; -import me.ryandw11.ultrachat.formatting.PlayerFormatting; -//import me.ryandw11.ultrachat.UltraChat; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.chat.BaseComponent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; -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; - public JSON(){ - //plugin = UltraChat.plugin; - } - - /** - * Builds the hover message. - * @param msg The play name and format around it. - * @param lore The lore of the text. - * @param p The player it is being applied to. - * @return TextComponent with hover message. - */ - public BaseComponent[] hoverMessage(String msg, ArrayList lore, String chat, ChatColor color, Player p){ - PlayerFormatting pf = new PlayerFormatting(p); - int i = 0; - int l = lore.size() - 1; - msg = ChatColor.translateAlternateColorCodes('&', msg); - ComponentBuilder build = new ComponentBuilder(""); - for(String s : lore){ - build.append(PlaceholderAPI.setPlaceholders(p, ChatColor.translateAlternateColorCodes('&', s))); - if(i json){ - plugin.channel.set(channel + ".prefix", prefix); - plugin.channel.set(channel + ".permission", permission); - plugin.channel.set(channel + ".always_appear", always_appear); - plugin.channel.set(channel + ".format", format); - plugin.channel.set(channel + ".JSON", json); - plugin.saveChannel(); - } /** - * Remove a channel. - * @deprecated - * @param channel + * If components are enabled. + * @return If components are enabled. */ - public void removeChannel(String channel){ - plugin.channel.set(channel, null); - plugin.saveChannel(); + public boolean isComponents() { + return plugin.getConfig().getBoolean("Components_Enabled"); } /** @@ -192,13 +166,6 @@ public class UltraChatAPI{ public String getFormattingType(){ return plugin.getConfig().getString("chat_format"); } - /** - * Get if the channel has json enabled or not. - * @return True or false. - */ - public boolean isChannelJson(){ - return plugin.getConfig().getBoolean("Channel_Json"); - } /** * See if default channel exists. @@ -210,13 +177,6 @@ public class UltraChatAPI{ return true; return false; } - /** - * Get if range has json or not. - * @return True or False. - */ - public boolean isRangeJson(){ - return plugin.getConfig().getBoolean("Range_Json"); - } /** * Get the current active hooks. * @return The set witht the names of the plugins. Returns null if no hooks are active. diff --git a/src/me/ryandw11/ultrachat/api/events/GlobalChatEvent.java b/src/me/ryandw11/ultrachat/api/events/GlobalChatEvent.java deleted file mode 100644 index f166587..0000000 --- a/src/me/ryandw11/ultrachat/api/events/GlobalChatEvent.java +++ /dev/null @@ -1,51 +0,0 @@ -package me.ryandw11.ultrachat.api.events; - - -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -/** - * Event class - * @author Ryandw11 - * - */ -public class GlobalChatEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - private Player player; - private String chat; - private boolean cancelled; - - public GlobalChatEvent(Player p, String chat) { - super(false); - player = p; - this.chat = chat; - } - - public Player getPlayer() { - return player; - } - - public String getMessage() { - return chat; - } - - public void setMessage(String message){ - chat = message; - } - - public boolean isCancelled(){ - return cancelled; - } - - public void setCancelled(boolean cancel){ - cancelled = cancel; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } -} diff --git a/src/me/ryandw11/ultrachat/api/events/JsonChatEvent.java b/src/me/ryandw11/ultrachat/api/events/JsonChatEvent.java deleted file mode 100644 index 81fb026..0000000 --- a/src/me/ryandw11/ultrachat/api/events/JsonChatEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -package me.ryandw11.ultrachat.api.events; - -import java.util.Set; - -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -/** - * Event class - - * Async Event - * @author Ryandw11 - */ -public class JsonChatEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - private Player player; - private String chat; - private Set recipients; - private boolean cancelled; - - public JsonChatEvent(Player p, String chat, Set recipients) { - super(true); - player = p; - this.chat = chat; - this.recipients = recipients; - } - /** - * Grab the recipients. - * @return The recipients. - */ - public Set getRecipients(){ - return recipients; - } - /** - * Set the recipients. - * @param recipents The set of recipients. - */ - public void setRecipients(Set recipients){ - this.recipients = recipients; - } - - public Player getPlayer() { - return player; - } - - public String getMessage() { - return chat; - } - - public void setMessage(String message){ - chat = message; - } - - public boolean isCancelled(){ - return cancelled; - } - - public void setCancelled(boolean cancel){ - cancelled = cancel; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } -} diff --git a/src/me/ryandw11/ultrachat/api/events/StaffChatEvent.java b/src/me/ryandw11/ultrachat/api/events/StaffChatEvent.java new file mode 100644 index 0000000..7a4c558 --- /dev/null +++ b/src/me/ryandw11/ultrachat/api/events/StaffChatEvent.java @@ -0,0 +1,46 @@ +package me.ryandw11.ultrachat.api.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class StaffChatEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + private Player player; + private String message; + private boolean cancelled; + + public StaffChatEvent(Player p, String message) { + player = p; + this.message = message; + } + + /** + * Get the player + * @return The player. (Can be null if sent by the console) + */ + public Player getPlayer() { + return player; + } + + public String getMessage() { + return message; + } + + public boolean isCancelled() { + return cancelled; + } + + public void setCancelled(boolean cancel) { + cancelled = cancel; + } + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/me/ryandw11/ultrachat/api/events/ChannelChatEvent.java b/src/me/ryandw11/ultrachat/api/events/UltraChatEvent.java similarity index 57% rename from src/me/ryandw11/ultrachat/api/events/ChannelChatEvent.java rename to src/me/ryandw11/ultrachat/api/events/UltraChatEvent.java index d08b66e..14bcb27 100644 --- a/src/me/ryandw11/ultrachat/api/events/ChannelChatEvent.java +++ b/src/me/ryandw11/ultrachat/api/events/UltraChatEvent.java @@ -6,28 +6,26 @@ import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import me.ryandw11.ultrachat.api.channels.ChatChannel; -import me.ryandw11.ultrachat.api.managers.ChannelManager; -/** - * Event class - - * Async Event - * @author Ryandw11 - * - */ -public class ChannelChatEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - private Player player; +import me.ryandw11.ultrachat.api.ChatType; +import me.ryandw11.ultrachat.api.events.properties.ChatProperties; + +public class UltraChatEvent extends Event{ + + private static final HandlerList handlers = new HandlerList(); + private Player player; private String chat; - private ChatChannel channel; private Set recipients; + private ChatType type; + private ChatProperties prop; private boolean cancelled; - public ChannelChatEvent(Player p, String chat, Set recipients) { + public UltraChatEvent(Player p, String chat, Set recipients, ChatType ct, ChatProperties properties) { super(true); player = p; this.chat = chat; this.recipients = recipients; - this.channel = new ChannelManager().getPlayerChannel(p); + this.type = ct; + this.prop = properties; } /** * Grab the recipients. @@ -52,10 +50,10 @@ public class ChannelChatEvent extends Event { return chat; } - public ChatChannel getChannel() { - return channel; - } - + /** + * Set the message + * @param message The message. + */ public void setMessage(String message){ chat = message; } @@ -68,6 +66,22 @@ public class ChannelChatEvent extends Event { cancelled = cancel; } + /** + * Get the type of the chat used. + * @return The type of chat used. + */ + public ChatType getType() { + return type; + } + + /** + * Get the properties. + * @return Get the information for a certain chat event. + */ + public ChatProperties getProperties() { + return prop; + } + public HandlerList getHandlers() { return handlers; } @@ -75,4 +89,5 @@ public class ChannelChatEvent extends Event { public static HandlerList getHandlerList() { return handlers; } + } diff --git a/src/me/ryandw11/ultrachat/api/events/WorldChatEvent.java b/src/me/ryandw11/ultrachat/api/events/WorldChatEvent.java deleted file mode 100644 index e7d0d2e..0000000 --- a/src/me/ryandw11/ultrachat/api/events/WorldChatEvent.java +++ /dev/null @@ -1,69 +0,0 @@ -package me.ryandw11.ultrachat.api.events; - -import java.util.Set; - -import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -/** - * Event class - - * Async Event - * @author Ryandw11 - * - */ -public class WorldChatEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - private Player player; - private String chat; - private Set recipients; - private boolean cancelled; - - public WorldChatEvent(Player p, String chat, Set recipients) { - super(true); - player = p; - this.chat = chat; - this.recipients = recipients; - } - /** - * Grab the recipients. - * @return The recipients. - */ - public Set getRecipients(){ - return recipients; - } - /** - * Set the recipients. - * @param recipents The set of recipients. - */ - public void setRecipients(Set recipients){ - this.recipients = recipients; - } - - public Player getPlayer() { - return player; - } - - public String getMessage() { - return chat; - } - - public void setMessage(String message){ - chat = message; - } - - public boolean isCancelled(){ - return cancelled; - } - - public void setCancelled(boolean cancel){ - cancelled = cancel; - } - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } -} diff --git a/src/me/ryandw11/ultrachat/api/events/properties/ChannelProperties.java b/src/me/ryandw11/ultrachat/api/events/properties/ChannelProperties.java new file mode 100644 index 0000000..9a8bf90 --- /dev/null +++ b/src/me/ryandw11/ultrachat/api/events/properties/ChannelProperties.java @@ -0,0 +1,26 @@ +package me.ryandw11.ultrachat.api.events.properties; + +import me.ryandw11.ultrachat.api.channels.ChannelBuilder; +import me.ryandw11.ultrachat.api.channels.ChatChannel; + +public class ChannelProperties implements ChatProperties { + + private boolean json; + private String channel; + + public ChannelProperties(boolean json, String channel) { + this.json = json; + this.channel = channel; + } + + @Override + public boolean isComponent() { + return json; + } + + public ChatChannel getChannel() { + ChatChannel cc = new ChannelBuilder(channel).build(); + return cc; + } + +} diff --git a/src/me/ryandw11/ultrachat/api/events/properties/ChatProperties.java b/src/me/ryandw11/ultrachat/api/events/properties/ChatProperties.java new file mode 100644 index 0000000..505a3f4 --- /dev/null +++ b/src/me/ryandw11/ultrachat/api/events/properties/ChatProperties.java @@ -0,0 +1,7 @@ +package me.ryandw11.ultrachat.api.events.properties; + +public interface ChatProperties { + + public boolean isComponent(); + +} diff --git a/src/me/ryandw11/ultrachat/api/events/properties/NormalProperties.java b/src/me/ryandw11/ultrachat/api/events/properties/NormalProperties.java new file mode 100644 index 0000000..b46907a --- /dev/null +++ b/src/me/ryandw11/ultrachat/api/events/properties/NormalProperties.java @@ -0,0 +1,17 @@ +package me.ryandw11.ultrachat.api.events.properties; + +public class NormalProperties implements ChatProperties { + + private boolean json; + public NormalProperties(boolean isJson) { + this.json = isJson; + } + + @Override + public boolean isComponent() { + return json; + } + + + +} diff --git a/src/me/ryandw11/ultrachat/api/events/properties/RangeProperties.java b/src/me/ryandw11/ultrachat/api/events/properties/RangeProperties.java new file mode 100644 index 0000000..77cd327 --- /dev/null +++ b/src/me/ryandw11/ultrachat/api/events/properties/RangeProperties.java @@ -0,0 +1,25 @@ +package me.ryandw11.ultrachat.api.events.properties; + +public class RangeProperties implements ChatProperties { + + private boolean json; + private RangeType rt; + public RangeProperties(boolean json, RangeType rt) { + this.json = json; + this.rt = rt; + } + + @Override + public boolean isComponent() { + return json; + } + + /** + * Get the Range mode in use. + * @return The range type. + */ + public RangeType getType() { + return rt; + } + +} diff --git a/src/me/ryandw11/ultrachat/api/events/properties/RangeType.java b/src/me/ryandw11/ultrachat/api/events/properties/RangeType.java new file mode 100644 index 0000000..3669a78 --- /dev/null +++ b/src/me/ryandw11/ultrachat/api/events/properties/RangeType.java @@ -0,0 +1,7 @@ +package me.ryandw11.ultrachat.api.events.properties; + +public enum RangeType { + LOCAL, + WORLD, + GLBOAL +} diff --git a/src/me/ryandw11/ultrachat/commands/Global.java b/src/me/ryandw11/ultrachat/commands/Global.java index cbe210e..aaebdb7 100644 --- a/src/me/ryandw11/ultrachat/commands/Global.java +++ b/src/me/ryandw11/ultrachat/commands/Global.java @@ -1,6 +1,6 @@ package me.ryandw11.ultrachat.commands; -import java.util.ArrayList; +import java.util.HashSet; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -10,60 +10,68 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import me.ryandw11.ultrachat.UltraChat; -import me.ryandw11.ultrachat.api.JSON; +import me.ryandw11.ultrachat.api.ChatType; import me.ryandw11.ultrachat.api.Lang; import me.ryandw11.ultrachat.api.UltraChatAPI; -import me.ryandw11.ultrachat.api.events.GlobalChatEvent; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; +import me.ryandw11.ultrachat.api.events.properties.RangeProperties; +import me.ryandw11.ultrachat.api.events.properties.RangeType; +import me.ryandw11.ultrachat.api.managers.JComponentManager; import me.ryandw11.ultrachat.formatting.PlayerFormatting; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.TextComponent; public class Global implements CommandExecutor { - private UltraChat plugin; - public Global(){ - plugin = UltraChat.plugin; - } - @SuppressWarnings("unchecked") @Override public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) { - if(!(sender instanceof Player)){ - sender.sendMessage("§cThis command is for players only!"); + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is for players only!"); return true; } Player p = (Player) sender; - if(!p.hasPermission("ultrachat.global")){ + if (!p.hasPermission("ultrachat.global")) { p.sendMessage(Lang.NO_PERM.toString()); return true; } + UltraChatAPI uapi = new UltraChatAPI(); PlayerFormatting pf = new PlayerFormatting(p); - if(!uapi.isRangeJson()){ - GlobalChatEvent e = new GlobalChatEvent(p, this.getMessage(args, p)); - Bukkit.getServer().getPluginManager().callEvent(e); - if(!e.isCancelled()){ - Bukkit.broadcastMessage(pf.getGlobal().replace("%player%", p.getDisplayName()).replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()) + pf.getColor() + e.getMessage()); - Bukkit.getLogger().info(pf.getGlobal().replace("%player%", p.getDisplayName()).replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace('&', '§') + pf.getColor() + e.getMessage().replace('&', '§')); - } - }else{ - GlobalChatEvent e = new GlobalChatEvent(p, this.getMessage(args, p)); - Bukkit.getServer().getPluginManager().callEvent(e); - if(!e.isCancelled()){ - JSON j = new JSON(); - for(Player pl : Bukkit.getOnlinePlayers()){ - pl.spigot().sendMessage(j.hoverMessage(pf.getGlobal().replace("%player%", p.getDisplayName()).replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()), (ArrayList) plugin.getConfig().get("Global.json"), e.getMessage(), pf.getColor(), p)); - } - Bukkit.getLogger().info(pf.getGlobal().replace("%player%", p.getDisplayName()).replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace('&', '§') + pf.getColor() + e.getMessage().replace('&', '§')); - } - } + + RangeProperties rp = new RangeProperties(uapi.isComponents(), RangeType.GLBOAL); + UltraChatEvent uce = new UltraChatEvent(p, this.getMessage(args, p), + new HashSet(Bukkit.getOnlinePlayers()), ChatType.RANGE, rp); + Bukkit.getScheduler().runTaskAsynchronously(UltraChat.plugin, () ->{ + Bukkit.getServer().getPluginManager().callEvent(uce); + + if (uce.isCancelled()) { + return; + } + + String form = pf.getGlobal().replace("%player%", p.getDisplayName()) + .replace("%prefix%", pf.getPrefix()) + .replace("%suffix%", pf.getSuffix()) + + pf.getColor(); + + ComponentBuilder cb = new ComponentBuilder(""); + cb.append(JComponentManager.formatComponents(form, p)); + TextComponent ct = new TextComponent(uce.getMessage()); + cb.append(ct); + + for (Player pl : uce.getRecipients()) { + pl.spigot().sendMessage(cb.create()); + } + }); return false; } - - private String getMessage(String[] args, Player p){ + + private String getMessage(String[] args, Player p) { String end = ""; - for(String s : args){ + for (String s : args) { end += s + " "; } - if(p.hasPermission("ultrachat.color")) + if (p.hasPermission("ultrachat.color")) return ChatColor.translateAlternateColorCodes('&', end); return end; } diff --git a/src/me/ryandw11/ultrachat/commands/StaffChat.java b/src/me/ryandw11/ultrachat/commands/StaffChat.java index d69d59e..f934771 100644 --- a/src/me/ryandw11/ultrachat/commands/StaffChat.java +++ b/src/me/ryandw11/ultrachat/commands/StaffChat.java @@ -9,6 +9,8 @@ import org.bukkit.entity.Player; import me.ryandw11.ultrachat.UltraChat; import me.ryandw11.ultrachat.api.Lang; +import me.ryandw11.ultrachat.api.events.StaffChatEvent; +import me.ryandw11.ultrachat.api.managers.JComponentManager; public class StaffChat implements CommandExecutor { private UltraChat plugin; @@ -28,12 +30,24 @@ public class StaffChat implements CommandExecutor { for (int i = 0; i < args.length; i++){ message = message + " " + args[i]; - } + StaffChatEvent sce; + if (p instanceof Player) + sce = new StaffChatEvent((Player) p, message); + else + sce = new StaffChatEvent(null, message); + + Bukkit.getServer().getPluginManager().callEvent(sce); + + if(sce.isCancelled()) return true; + for(Player p1 : Bukkit.getOnlinePlayers()){ if(p1.hasPermission("ultrachat.staffchat")){ if(!plugin.stafftoggle.contains(p1.getUniqueId())){ - p1.sendMessage(Lang.STAFF_CHAT_FORMAT.toString().replace("%p", p.getName()).replace("%s", message)); + if (p instanceof Player) + p1.spigot().sendMessage(JComponentManager.formatComponents(Lang.STAFF_CHAT_FORMAT.toString().replace("%p", p.getName()).replace("%s", message), (Player) p)); + else + p1.spigot().sendMessage(JComponentManager.formatComponents(Lang.STAFF_CHAT_FORMAT.toString().replace("%p", p.getName()).replace("%s", message))); }// end of if } }//end of for diff --git a/src/me/ryandw11/ultrachat/commands/World.java b/src/me/ryandw11/ultrachat/commands/World.java index 3cd8305..92adb9f 100644 --- a/src/me/ryandw11/ultrachat/commands/World.java +++ b/src/me/ryandw11/ultrachat/commands/World.java @@ -1,6 +1,5 @@ package me.ryandw11.ultrachat.commands; -import java.util.ArrayList; import java.util.HashSet; import org.bukkit.Bukkit; @@ -11,62 +10,65 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import me.ryandw11.ultrachat.UltraChat; -import me.ryandw11.ultrachat.api.JSON; +import me.ryandw11.ultrachat.api.ChatType; import me.ryandw11.ultrachat.api.Lang; import me.ryandw11.ultrachat.api.UltraChatAPI; -import me.ryandw11.ultrachat.api.events.WorldChatEvent; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; +import me.ryandw11.ultrachat.api.events.properties.RangeProperties; +import me.ryandw11.ultrachat.api.events.properties.RangeType; +import me.ryandw11.ultrachat.api.managers.JComponentManager; import me.ryandw11.ultrachat.formatting.PlayerFormatting; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.TextComponent; public class World implements CommandExecutor { - private UltraChat plugin; - public World(){ - plugin = UltraChat.plugin; - } - @SuppressWarnings("unchecked") @Override public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) { - if(!(sender instanceof Player)){ - sender.sendMessage("§cThis command is for players only!"); + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is for players only!"); return true; } Player p = (Player) sender; - if(!p.hasPermission("ultrachat.world")){ + if (!p.hasPermission("ultrachat.world")) { p.sendMessage(Lang.NO_PERM.toString()); return true; } UltraChatAPI uapi = new UltraChatAPI(); PlayerFormatting pf = new PlayerFormatting(p); - if(!uapi.isRangeJson()){ - WorldChatEvent e = new WorldChatEvent(p, this.getMessage(args, p), new HashSet( p.getWorld().getPlayers())); - Bukkit.getServer().getPluginManager().callEvent(e); - if(!e.isCancelled()){ - for(Player pl : e.getRecipients()){ - pl.sendMessage(pf.getWorld().replace("%player%", p.getDisplayName()).replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()) + pf.getColor() + e.getMessage()); - } - Bukkit.getLogger().info(pf.getWorld().replace("%player%", p.getDisplayName()).replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace('&', '§') + pf.getColor() + e.getMessage().replace('&', '§')); + + RangeProperties rp = new RangeProperties(uapi.isComponents(), RangeType.WORLD); + UltraChatEvent uce = new UltraChatEvent(p, this.getMessage(args, p), + new HashSet(p.getWorld().getPlayers()), ChatType.RANGE, rp); + Bukkit.getScheduler().runTaskAsynchronously(UltraChat.plugin, () -> { + Bukkit.getServer().getPluginManager().callEvent(uce); + + if (uce.isCancelled()) { + return; } - }else{ - WorldChatEvent e = new WorldChatEvent(p, this.getMessage(args, p), new HashSet( p.getWorld().getPlayers())); - Bukkit.getServer().getPluginManager().callEvent(e); - if(!e.isCancelled()){ - JSON j = new JSON(); - for(Player pl : e.getRecipients()){ - pl.spigot().sendMessage(j.hoverMessage(pf.getWorld().replace("%player%", p.getDisplayName()).replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()), (ArrayList) plugin.getConfig().get("World.json"), e.getMessage(), pf.getColor(), p)); - } - Bukkit.getLogger().info(pf.getWorld().replace("%player%", p.getDisplayName()).replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace('&', '§') + pf.getColor() + e.getMessage().replace('&', '§')); + + String form = pf.getWorld().replace("%player%", p.getDisplayName()) + .replace("%prefix%", pf.getPrefix()) + .replace("%suffix%", pf.getSuffix()) + pf.getColor(); + ComponentBuilder cb = new ComponentBuilder(""); + cb.append(JComponentManager.formatComponents(form, p)); + TextComponent ct = new TextComponent(uce.getMessage()); + cb.append(ct); + + for (Player pl : uce.getRecipients()) { + pl.spigot().sendMessage(cb.create()); } - } - + }); + return false; } - - private String getMessage(String[] args, Player p){ + + private String getMessage(String[] args, Player p) { String end = ""; - for(String s : args){ + for (String s : args) { end += s + " "; } - if(p.hasPermission("ultrachat.color")) + if (p.hasPermission("ultrachat.color")) return ChatColor.translateAlternateColorCodes('&', end); return end; } diff --git a/src/me/ryandw11/ultrachat/formatting/ChannelJSON.java b/src/me/ryandw11/ultrachat/formatting/ChannelJSON.java new file mode 100644 index 0000000..2da5062 --- /dev/null +++ b/src/me/ryandw11/ultrachat/formatting/ChannelJSON.java @@ -0,0 +1,85 @@ +package me.ryandw11.ultrachat.formatting; + +import java.util.HashSet; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import me.ryandw11.ultrachat.UltraChat; +import me.ryandw11.ultrachat.api.ChatType; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; +import me.ryandw11.ultrachat.api.events.properties.ChannelProperties; +import me.ryandw11.ultrachat.api.managers.JComponentManager; +import net.md_5.bungee.api.ChatColor; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.TextComponent; + +/** + * Handles channels with components enabled. + * @author Ryandw11 + * @since 2.4 + * + */ +public class ChannelJSON implements Listener { + + private UltraChat plugin; + public ChannelJSON() { + this.plugin = UltraChat.plugin; + } + + @EventHandler + public void onChat(AsyncPlayerChatEvent e){ + Player p = e.getPlayer(); + PlayerFormatting pf = new PlayerFormatting(p); + e.setCancelled(true); + String channel = plugin.data.getString(p.getUniqueId() + ".channel"); + + ChannelProperties cp = new ChannelProperties(true, channel); + + if(!plugin.channel.getBoolean(channel + ".always_appear")){ + UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet(Bukkit.getOnlinePlayers()), ChatType.CHANNEL, cp); + Bukkit.getServer().getPluginManager().callEvent(uce); + if(uce.isCancelled()) return; + for(Player pl : uce.getRecipients()){ + if(plugin.data.getString(pl.getUniqueId() + ".channel").equals(channel)){ + if(pl.hasPermission(plugin.channel.getString(channel + ".permission")) || plugin.channel.getString(channel + ".permission").equalsIgnoreCase("none")){ + String form = ChatColor.translateAlternateColorCodes('&', plugin.channel.getString(channel + ".prefix")) + + ChatColor.translateAlternateColorCodes('&', plugin.channel.getString(channel + ".format")) + .replace("%prefix%", pf.getPrefix()) + .replace("%suffix%", pf.getSuffix()) + .replace("%player%", p.getDisplayName()) + + pf.getColor(); + + ComponentBuilder cb = new ComponentBuilder(""); + cb.append(JComponentManager.formatComponents(form, p)); + TextComponent tc = new TextComponent(uce.getMessage()); + cb.append(tc); + pl.spigot().sendMessage(cb.create()); + } + } + } + } + else{ + UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet(Bukkit.getOnlinePlayers()), ChatType.CHANNEL, cp); + Bukkit.getServer().getPluginManager().callEvent(uce); + if(!uce.isCancelled()) + for(Player pl : uce.getRecipients()){ + String form = ChatColor.translateAlternateColorCodes('&', plugin.channel.getString(channel + ".prefix")) + + ChatColor.translateAlternateColorCodes('&', plugin.channel.getString(channel + ".format")) + .replace("%prefix%", pf.getPrefix()) + .replace("%suffix%", pf.getSuffix()) + .replace("%player%", p.getDisplayName()) + + pf.getColor(); + ComponentBuilder cb = new ComponentBuilder(""); + cb.append(JComponentManager.formatComponents(form, p)); + TextComponent tc = new TextComponent(uce.getMessage()); + cb.append(tc); + pl.spigot().sendMessage(cb.create()); + } + } + } + +} diff --git a/src/me/ryandw11/ultrachat/formatting/Channels.java b/src/me/ryandw11/ultrachat/formatting/Channels.java index 1fd7c5f..6dec79f 100644 --- a/src/me/ryandw11/ultrachat/formatting/Channels.java +++ b/src/me/ryandw11/ultrachat/formatting/Channels.java @@ -9,6 +9,9 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import me.clip.placeholderapi.PlaceholderAPI; import me.ryandw11.ultrachat.UltraChat; +import me.ryandw11.ultrachat.api.ChatType; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; +import me.ryandw11.ultrachat.api.events.properties.ChannelProperties; /** * Channels without any kind of json involved. * @author Ryandw11 @@ -39,6 +42,23 @@ public class Channels implements Listener { } } } + + ChannelProperties cp = new ChannelProperties(false, channel); + UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), e.getRecipients(), ChatType.CHANNEL, cp); + Bukkit.getServer().getPluginManager().callEvent(uce); + + if (uce.isCancelled()) { + e.setCancelled(true); + return; + } + if(uce.getRecipients() != e.getRecipients()) { + e.getRecipients().removeAll(Bukkit.getOnlinePlayers()); + e.getRecipients().addAll(uce.getRecipients()); + } + + e.setMessage(uce.getMessage()); + + e.setFormat(PlaceholderAPI.setPlaceholders(p, ChatColor.translateAlternateColorCodes('&', plugin.channel.getString(channel + ".prefix")) + ChatColor.translateAlternateColorCodes('&', plugin.channel.getString(channel + ".format").replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace("%player%", "%s") + pf.getColor() + "%s"))); } } diff --git a/src/me/ryandw11/ultrachat/formatting/Chat_Json.java b/src/me/ryandw11/ultrachat/formatting/Chat_Json.java deleted file mode 100644 index 54cccee..0000000 --- a/src/me/ryandw11/ultrachat/formatting/Chat_Json.java +++ /dev/null @@ -1,99 +0,0 @@ -package me.ryandw11.ultrachat.formatting; - -import java.util.ArrayList; -import java.util.HashSet; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; - -import me.ryandw11.ultrachat.UltraChat; -import me.ryandw11.ultrachat.api.JSON; -import me.ryandw11.ultrachat.api.events.JsonChatEvent; -/** - * If JSON is enabled. - * @author Ryandw11 - * - */ -public class Chat_Json implements Listener{ - private UltraChat plugin; - private JSON json; - public Chat_Json(){ - plugin = UltraChat.plugin; - json = new JSON(); - } - - @SuppressWarnings("unchecked") - @EventHandler - public void onChat(AsyncPlayerChatEvent e){ - Player p = e.getPlayer(); - PlayerFormatting pf = new PlayerFormatting(p); - /* - * Check if Channel and JSON is enabled. - */ - if(plugin.channelEnabled){ - e.setCancelled(true); - String channel = plugin.data.getString(p.getUniqueId() + ".channel"); - if(!plugin.channel.getBoolean(channel + ".always_appear")){ - JsonChatEvent event = new JsonChatEvent(p, e.getMessage(), new HashSet(Bukkit.getOnlinePlayers())); - Bukkit.getServer().getPluginManager().callEvent(event); - if(!event.isCancelled()) - for(Player pl : event.getRecipients()){ - if(plugin.data.getString(pl.getUniqueId() + ".channel").equals(channel)){ - if(pl.hasPermission(plugin.channel.getString(channel + ".permission")) || plugin.channel.getString(channel + ".permission").equalsIgnoreCase("none")){ - - pl.spigot().sendMessage(json.hoverMessage(plugin.channel.getString(channel + ".prefix") + plugin.channel.getString(channel + ".format").replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace("%player%", p.getDisplayName()), (ArrayList) plugin.channel.get(channel + ".JSON"), event.getMessage(), pf.getColor(), p)); - } - } - - } - } - else{ - JsonChatEvent event = new JsonChatEvent(p, e.getMessage(), new HashSet(Bukkit.getOnlinePlayers())); - Bukkit.getServer().getPluginManager().callEvent(event); - if(!event.isCancelled()) - for(Player pl : event.getRecipients()){ - pl.spigot().sendMessage(json.hoverMessage(plugin.channel.getString(channel + ".prefix") + plugin.channel.getString(channel + ".format").replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace("%player%", p.getDisplayName()), (ArrayList) plugin.channel.get(channel + ".JSON"), event.getMessage(), pf.getColor(), p)); //fixed suffix bug - } - } - }else{ //if Channel is not enabled. - boolean complete = false; - e.setCancelled(true); - JsonChatEvent event = new JsonChatEvent(p, e.getMessage(), new HashSet(Bukkit.getOnlinePlayers())); - Bukkit.getServer().getPluginManager().callEvent(event); - if(!event.isCancelled()){ - if(p.isOp()){ - for(Player pl : event.getRecipients()){ - pl.spigot().sendMessage(json.hoverMessage(pf.getOpFormat().replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace("%player%", p.getDisplayName()), (ArrayList) plugin.getConfig().get("Custom_Chat.Op_Chat.JSON"), event.getMessage(), pf.getColor(), p)); - } - return; - }else{ - int i = 1; - while(i <= plugin.getConfig().getInt("Custom_Chat.Chat_Count")){ - if(p.hasPermission(plugin.getConfig().getString("Custom_Chat." + i + ".Permission"))){ - for(Player pl : event.getRecipients()){ - pl.spigot().sendMessage(json.hoverMessage(plugin.getConfig().getString("Custom_Chat." + i +".Format").replace("%player%", p.getDisplayName()).replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()), (ArrayList) plugin.getConfig().get("Custom_Chat." + i +".JSON"), event.getMessage(), pf.getColor(), p)); //fixed error. - complete = true; - break; - } - } - i++; - } - } - if(complete) - return; - /* - * Normal player check - */ - if(!complete){ - for(Player pl : event.getRecipients()){ // Fixed for normal players - pl.spigot().sendMessage(json.hoverMessage(pf.getDefaultFormat().replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace("%player%", p.getDisplayName()), (ArrayList) plugin.getConfig().get("Custom_Chat.Default_Chat.JSON"), event.getMessage(), pf.getColor(), p)); - } - } - } // if the vent is canccels - } - } -} - diff --git a/src/me/ryandw11/ultrachat/formatting/Normal.java b/src/me/ryandw11/ultrachat/formatting/Normal.java index f0a5d20..6b5051f 100644 --- a/src/me/ryandw11/ultrachat/formatting/Normal.java +++ b/src/me/ryandw11/ultrachat/formatting/Normal.java @@ -11,6 +11,9 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import me.clip.placeholderapi.PlaceholderAPI; import me.ryandw11.ultrachat.UltraChat; +import me.ryandw11.ultrachat.api.ChatType; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; +import me.ryandw11.ultrachat.api.events.properties.NormalProperties; /** * Normal chat formatting with no channels or Json. * @author Ryandw11 @@ -21,15 +24,32 @@ public class Normal implements Listener { public Normal(){ plugin = UltraChat.plugin; } - //TODO Fix this and make it work @EventHandler public void onChat(AsyncPlayerChatEvent e){ PlayerFormatting pf = new PlayerFormatting(e.getPlayer()); Player p = e.getPlayer(); + if(p.hasPermission("ultrachat.chat.color")){ e.setMessage(ChatColor.translateAlternateColorCodes('&', e.getMessage())); } + + NormalProperties np = new NormalProperties(false); + UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), e.getRecipients(), ChatType.NORMAL, np); + Bukkit.getServer().getPluginManager().callEvent(uce); + + if(uce.isCancelled()) { + e.setCancelled(true); + return; + } + + if(e.getRecipients() != uce.getRecipients()) { + e.getRecipients().removeAll(e.getRecipients()); + e.getRecipients().addAll(uce.getRecipients()); + } + + e.setMessage(uce.getMessage()); + if(p.isOp()){ try{ e.setFormat(pf.getOpFormat().replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace("%player%", "%s") + pf.getColor() + "%s"); diff --git a/src/me/ryandw11/ultrachat/formatting/NormalJSON.java b/src/me/ryandw11/ultrachat/formatting/NormalJSON.java new file mode 100644 index 0000000..c2ecace --- /dev/null +++ b/src/me/ryandw11/ultrachat/formatting/NormalJSON.java @@ -0,0 +1,103 @@ +package me.ryandw11.ultrachat.formatting; + +import java.util.HashSet; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import me.ryandw11.ultrachat.UltraChat; +import me.ryandw11.ultrachat.api.ChatType; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; +import me.ryandw11.ultrachat.api.events.properties.NormalProperties; +import me.ryandw11.ultrachat.api.managers.JComponentManager; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.TextComponent; + +/** + * Handles the Normal Chat when in JSON mode. + * @author Ryandw11 + * @since 2.4 + * + */ +public class NormalJSON implements Listener { + + private UltraChat plugin; + + public NormalJSON() { + this.plugin = UltraChat.plugin; + } + + @EventHandler + public void onChat(AsyncPlayerChatEvent e) { + Player p = e.getPlayer(); + e.setCancelled(true); + PlayerFormatting pf = new PlayerFormatting(p); + NormalProperties np = new NormalProperties(true); + UltraChatEvent event = new UltraChatEvent(p, e.getMessage(), new HashSet(Bukkit.getOnlinePlayers()), ChatType.NORMAL, np); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + return; + } + if (p.isOp()) { + String formats = pf.getOpFormat() + .replace("%prefix%", pf.getPrefix()) + .replace("%suffix%", pf.getSuffix()) + .replace("%player%", p.getDisplayName()) + + pf.getColor(); + + for (Player pl : event.getRecipients()) { + ComponentBuilder cb = new ComponentBuilder(""); + cb.append(JComponentManager.formatComponents(formats, p)); + TextComponent tc = new TextComponent(event.getMessage()); + cb.append(tc); + pl.spigot().sendMessage(cb.create()); + } + return; + } + // If the player is not op + int i = 1; + boolean complete = false; + while (i <= plugin.getConfig().getInt("Custom_Chat.Chat_Count")) { + if (p.hasPermission(plugin.getConfig().getString("Custom_Chat." + i + ".Permission"))) { + String formats = pf.getCustomFormat(i) + .replace("%prefix%", pf.getPrefix()) + .replace("%suffix%", pf.getSuffix()) + .replace("%player%", p.getDisplayName()) + + pf.getColor(); + + for (Player pl : event.getRecipients()) { + ComponentBuilder cb = new ComponentBuilder(""); + cb.append(JComponentManager.formatComponents(formats, p)); + TextComponent tc = new TextComponent(event.getMessage()); + cb.append(tc); + pl.spigot().sendMessage(cb.create()); + complete = true; + break; + } + } + if (complete) + return; + i++; + } + + /* + * Normal player check + */ + String formats = pf.getDefaultFormat() + .replace("%prefix%", pf.getPrefix()) + .replace("%suffix%", pf.getSuffix()) + .replace("%player%", p.getDisplayName()) + + pf.getColor(); + for (Player pl : event.getRecipients()) { + ComponentBuilder cb = new ComponentBuilder(""); + cb.append(JComponentManager.formatComponents(formats, p)); + TextComponent tc = new TextComponent(event.getMessage()); + cb.append(tc); + pl.spigot().sendMessage(cb.create()); + } + } + +} diff --git a/src/me/ryandw11/ultrachat/formatting/PlayerFormatting.java b/src/me/ryandw11/ultrachat/formatting/PlayerFormatting.java index 2a86e37..df1d371 100644 --- a/src/me/ryandw11/ultrachat/formatting/PlayerFormatting.java +++ b/src/me/ryandw11/ultrachat/formatting/PlayerFormatting.java @@ -1,14 +1,12 @@ package me.ryandw11.ultrachat.formatting; -import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; -import me.clip.placeholderapi.PlaceholderAPI; import me.ryandw11.ultrachat.UltraChat; import me.ryandw11.ultrachat.api.Util; import net.md_5.bungee.api.ChatColor; /** - * Class for formatting player chat easily. (Demo: May not stay). + * Class for formatting player chat easily. * @author Ryandw11 * */ @@ -25,30 +23,11 @@ public class PlayerFormatting { color = ChatColor.translateAlternateColorCodes('&', plugin.data.getString(p.getUniqueId() + ".color")); prefix = ChatColor.translateAlternateColorCodes('&', plugin.chat.getPlayerPrefix(p)); suffix = ChatColor.translateAlternateColorCodes('&', plugin.chat.getPlayerSuffix(p)); - formatOp = PlaceholderAPI.setPlaceholders(p, ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Custom_Chat.Op_Chat.Format"))); - defaults = PlaceholderAPI.setPlaceholders(p, ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Custom_Chat.Default_Chat.Format"))); - global = PlaceholderAPI.setPlaceholders(p, ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Global.format"))); - world = PlaceholderAPI.setPlaceholders(p, ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("World.format"))); - local = PlaceholderAPI.setPlaceholders(p, ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Local.format"))); - } - - /** - * Get the formatting for an offline player. - *

Note: Placeholders will not work in this mode.

- * @param op The offline player - * @param worldname The name of the world to get the preffix and suffix from. - * @since 2.3.3 - */ - public PlayerFormatting(OfflinePlayer op, String worldname) { - plugin = UltraChat.plugin; - color = ChatColor.translateAlternateColorCodes('&', plugin.data.getString(op.getUniqueId() + ".color")); - prefix = ChatColor.translateAlternateColorCodes('&', plugin.chat.getPlayerPrefix(worldname, op)); - suffix = ChatColor.translateAlternateColorCodes('&', plugin.chat.getPlayerSuffix(worldname, op)); - formatOp = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Custom_Chat.Op_Chat.Format")); - defaults = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Custom_Chat.Default_Chat.Format")); - global = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Global.format")); - world = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("World.format")); - local = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Local.format")); + formatOp = plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Custom_Chat.Op_Chat.Format")), p); + defaults = plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Custom_Chat.Default_Chat.Format")), p); + global = plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Global.format")), p); + world = plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("World.format")), p); + local = plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Local.format")), p); } private String prefix; @@ -88,4 +67,8 @@ public class PlayerFormatting { return defaults; } + public String getCustomFormat(int num) { + return plugin.getConfig().getString("Custom_Chat." + num + ".Format"); + } + } diff --git a/src/me/ryandw11/ultrachat/formatting/Range.java b/src/me/ryandw11/ultrachat/formatting/Range.java index 16e7c87..82602dd 100644 --- a/src/me/ryandw11/ultrachat/formatting/Range.java +++ b/src/me/ryandw11/ultrachat/formatting/Range.java @@ -13,59 +13,62 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; import me.ryandw11.ultrachat.UltraChat; -import me.ryandw11.ultrachat.api.JSON; -import me.ryandw11.ultrachat.api.UltraChatAPI; -import me.ryandw11.ultrachat.api.events.JsonChatEvent; +import me.ryandw11.ultrachat.api.ChatType; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; +import me.ryandw11.ultrachat.api.events.properties.RangeProperties; +import me.ryandw11.ultrachat.api.events.properties.RangeType; -public class Range implements Listener{ +public class Range implements Listener { private UltraChat plugin; - public Range(){ + + public Range() { plugin = UltraChat.plugin; } - - @SuppressWarnings("unchecked") + @EventHandler - public void onChat(AsyncPlayerChatEvent e){ + public void onChat(AsyncPlayerChatEvent e) { Player p = e.getPlayer(); PlayerFormatting pf = new PlayerFormatting(p); - UltraChatAPI uapi = new UltraChatAPI(); - if(p.hasPermission("ultrachat.chat.color")){ + + if (p.hasPermission("ultrachat.chat.color")) { e.setMessage(ChatColor.translateAlternateColorCodes('&', e.getMessage())); } - if(!uapi.isRangeJson()){ - e.getRecipients().removeAll(Bukkit.getOnlinePlayers()); - e.getRecipients().addAll(getNearbyPlayers(p)); - e.getRecipients().add(p); - try{ - e.setFormat(pf.getLocal().replace("%player%", "%s").replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()) + pf.getColor() + "%s"); - }catch(UnknownFormatConversionException ex){ - Bukkit.getLogger().severe("A fatal error has occured! The local formatting is not correct!"); - } - }else{ - e.getRecipients().removeAll(Bukkit.getOnlinePlayers()); - e.getRecipients().addAll(getNearbyPlayers(p)); - e.getRecipients().add(p); + e.getRecipients().removeAll(Bukkit.getOnlinePlayers()); + e.getRecipients().addAll(getNearbyPlayers(p)); + e.getRecipients().add(p); + + RangeProperties rp = new RangeProperties(false, RangeType.LOCAL); + UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet(Bukkit.getOnlinePlayers()), ChatType.RANGE, rp); + Bukkit.getServer().getPluginManager().callEvent(uce); + + if(uce.isCancelled()) { e.setCancelled(true); - - JsonChatEvent event = new JsonChatEvent(p, e.getMessage(), new HashSet(e.getRecipients())); - Bukkit.getServer().getPluginManager().callEvent(event); - if(!event.isCancelled()){ - JSON j = new JSON(); - for(Player pl : event.getRecipients()){ - pl.spigot().sendMessage(j.hoverMessage(pf.getLocal().replace("%player%", p.getDisplayName()).replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()), (ArrayList) plugin.getConfig().get("Local.json"), event.getMessage(), pf.getColor(), p)); - } - } + return; + } + + if(e.getRecipients() != uce.getRecipients()) { + e.getRecipients().removeAll(e.getRecipients()); + e.getRecipients().addAll(uce.getRecipients()); + } + + e.setMessage(uce.getMessage()); + + try { + e.setFormat(pf.getLocal().replace("%player%", "%s").replace("%prefix%", pf.getPrefix()).replace("%suffix%", + pf.getSuffix()) + pf.getColor() + "%s"); + } catch (UnknownFormatConversionException ex) { + Bukkit.getLogger().severe("A fatal error has occured! The local formatting is not correct!"); } } - - public ArrayList getNearbyPlayers(Player pl){ - ArrayList nearby = new ArrayList(); - double range = plugin.getConfig().getDouble("Local.range"); - for (Entity e : pl.getNearbyEntities(range, range, range)){ - if (e instanceof Player){ - nearby.add((Player) e); - } - } - return nearby; - } + + public ArrayList getNearbyPlayers(Player pl) { + ArrayList nearby = new ArrayList(); + double range = plugin.getConfig().getDouble("Local.range"); + for (Entity e : pl.getNearbyEntities(range, range, range)) { + if (e instanceof Player) { + nearby.add((Player) e); + } + } + return nearby; + } } diff --git a/src/me/ryandw11/ultrachat/formatting/RangeJSON.java b/src/me/ryandw11/ultrachat/formatting/RangeJSON.java new file mode 100644 index 0000000..a9e117f --- /dev/null +++ b/src/me/ryandw11/ultrachat/formatting/RangeJSON.java @@ -0,0 +1,76 @@ +package me.ryandw11.ultrachat.formatting; + +import java.util.ArrayList; +import java.util.HashSet; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import me.ryandw11.ultrachat.UltraChat; +import me.ryandw11.ultrachat.api.ChatType; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; +import me.ryandw11.ultrachat.api.events.properties.RangeProperties; +import me.ryandw11.ultrachat.api.events.properties.RangeType; +import me.ryandw11.ultrachat.api.managers.JComponentManager; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.TextComponent; + +public class RangeJSON implements Listener { + + private UltraChat plugin; + + public RangeJSON() { + this.plugin = UltraChat.plugin; + } + + @EventHandler + public void onChat(AsyncPlayerChatEvent e) { + Player p = e.getPlayer(); + PlayerFormatting pf = new PlayerFormatting(p); + if (p.hasPermission("ultrachat.chat.color")) { + e.setMessage(ChatColor.translateAlternateColorCodes('&', e.getMessage())); + } + e.getRecipients().removeAll(Bukkit.getOnlinePlayers()); + e.getRecipients().addAll(getNearbyPlayers(p)); + e.getRecipients().add(p); + e.setCancelled(true); + + RangeProperties rp = new RangeProperties(true, RangeType.LOCAL); + + UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet(e.getRecipients()), ChatType.RANGE, rp); + Bukkit.getServer().getPluginManager().callEvent(uce); + if (!uce.isCancelled()) { + for (Player pl : uce.getRecipients()) { + + String form = pf.getLocal() + .replace("%player%", p.getDisplayName()) + .replace("%prefix%", pf.getPrefix()) + .replace("%suffix%", pf.getSuffix()) + + pf.getColor(); + + ComponentBuilder cb = new ComponentBuilder(""); + cb.append(JComponentManager.formatComponents(form, p)); + TextComponent tc = new TextComponent(uce.getMessage()); + cb.append(tc); + pl.spigot().sendMessage(cb.create()); + } + } + } + + private ArrayList getNearbyPlayers(Player pl) { + ArrayList nearby = new ArrayList(); + double range = plugin.getConfig().getDouble("Local.range"); + for (Entity e : pl.getNearbyEntities(range, range, range)) { + if (e instanceof Player) { + nearby.add((Player) e); + } + } + return nearby; + } + +} diff --git a/src/me/ryandw11/ultrachat/formatting/UUIDFormating.java b/src/me/ryandw11/ultrachat/formatting/UUIDFormating.java new file mode 100644 index 0000000..01c8820 --- /dev/null +++ b/src/me/ryandw11/ultrachat/formatting/UUIDFormating.java @@ -0,0 +1,82 @@ +package me.ryandw11.ultrachat.formatting; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; + +import me.ryandw11.ultrachat.UltraChat; +import me.ryandw11.ultrachat.api.Util; +import net.md_5.bungee.api.ChatColor; + +/** + * + * @author Ryandw11 + * @since 2.4 + */ +public class UUIDFormating { + +private UltraChat plugin; + + /** + * Get the formatting for an offline player. + * @param ud The UUID for the player. + * @param world The world the plugin grabs the prefixes for. + */ + public UUIDFormating(UUID ud, String world){ + plugin = UltraChat.plugin; + + OfflinePlayer op = Bukkit.getOfflinePlayer(ud); + + color = ChatColor.translateAlternateColorCodes('&', plugin.data.getString(ud + ".color")); + prefix = ChatColor.translateAlternateColorCodes('&', plugin.chat.getPlayerPrefix(world, op)); + suffix = ChatColor.translateAlternateColorCodes('&', plugin.chat.getPlayerSuffix(world, op)); + formatOp = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Custom_Chat.Op_Chat.Format")); + defaults = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Custom_Chat.Default_Chat.Format")); + global = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Global.format")); + this.world = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("World.format")); + local = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Local.format")); + } + + private String prefix; + private String suffix; + public String color; + private String formatOp; + private String defaults; + private String global; + private String world; + private String local; + + public String getGlobal(){ + return global; + } + + public String getWorld(){ + return world; + } + + public String getLocal(){ + return local; + } + + public String getPrefix(){ + return prefix; + } + public String getSuffix(){ + return suffix; + } + public ChatColor getColor(){ + return Util.getColorFromCode(color); + } + public String getOpFormat(){ + return formatOp; + } + public String getDefaultFormat(){ + return defaults; + } + + public String getCustomFormat(int num) { + return plugin.getConfig().getString("Custom_Chat." + num + ".Format"); + } + +} diff --git a/src/me/ryandw11/ultrachat/listner/ConsoleLogChat.java b/src/me/ryandw11/ultrachat/listner/ConsoleLogChat.java index 4794f41..f8a97f3 100644 --- a/src/me/ryandw11/ultrachat/listner/ConsoleLogChat.java +++ b/src/me/ryandw11/ultrachat/listner/ConsoleLogChat.java @@ -7,12 +7,13 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import me.ryandw11.ultrachat.api.Lang; -import me.ryandw11.ultrachat.api.events.JsonChatEvent; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; public class ConsoleLogChat implements Listener{ @EventHandler - public void jsonChat(JsonChatEvent e){ + public void jsonChat(UltraChatEvent e){ + if(!e.getProperties().isComponent()) return; String msg = e.getMessage(); String pname = e.getPlayer().getDisplayName(); Bukkit.getLogger().log(Level.INFO, Lang.CONSOLE_CHAT_LOG.toString().replace("%p", pname).replace("%s", msg).replace('&', '§')); diff --git a/src/me/ryandw11/ultrachat/listner/NoSwear.java b/src/me/ryandw11/ultrachat/listner/NoSwear.java index fe358ad..7f86910 100644 --- a/src/me/ryandw11/ultrachat/listner/NoSwear.java +++ b/src/me/ryandw11/ultrachat/listner/NoSwear.java @@ -4,12 +4,11 @@ import java.util.List; import me.ryandw11.ultrachat.UltraChat; import me.ryandw11.ultrachat.api.Lang; -import me.ryandw11.ultrachat.api.events.JsonChatEvent; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; /** * @author Ryandw11 */ @@ -20,35 +19,8 @@ public class NoSwear implements Listener { plugin = UltraChat.plugin; } - - @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) { - if(plugin.JSON) return; - - if(plugin.getConfig().getBoolean("Anti_Swear_Enabled")){ - Player p = event.getPlayer(); - - - List swear = plugin.getConfig().getStringList("Blocked_Words"); - int times = 0; - - String Message = " " + event.getMessage().toLowerCase().replace(".", "") + " "; - - for(String swearWord : swear){ - //Check if world chat is enabled - if(Message.contains(swearWord + " ") && times == 0 || Message.contains(" " + swearWord + " ") && times == 0 || Message.contains(" " + swearWord) && times == 0 || Message.contains(swearWord)){ - //else do this: - event.setCancelled(true); - p.sendMessage(Lang.NO_SWEAR.toString()); - break; - } - } - } - } - - @EventHandler - public void onJsonChat(JsonChatEvent event){ + public void onJsonChat(UltraChatEvent event){ if(plugin.getConfig().getBoolean("Anti_Swear_Enabled")){ Player p = event.getPlayer(); diff --git a/src/me/ryandw11/ultrachat/listner/Notify.java b/src/me/ryandw11/ultrachat/listner/Notify.java index 546fb6c..0683ee9 100644 --- a/src/me/ryandw11/ultrachat/listner/Notify.java +++ b/src/me/ryandw11/ultrachat/listner/Notify.java @@ -5,11 +5,9 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import me.ryandw11.ultrachat.UltraChat; import me.ryandw11.ultrachat.api.Lang; -import me.ryandw11.ultrachat.api.events.JsonChatEvent; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; /** * * @author Ryandw11 @@ -17,26 +15,9 @@ import me.ryandw11.ultrachat.api.events.JsonChatEvent; * */ public class Notify implements Listener { - - private UltraChat plugin; - public Notify(){ - plugin = UltraChat.plugin; - } - @EventHandler - public void onChat(AsyncPlayerChatEvent event){ - if(plugin.JSON) return; - for(Player p : Bukkit.getOnlinePlayers()){ - if(event.getMessage().contains("@" + p.getName())){ - p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 10, 0); - p.sendMessage(Lang.MENTION.toString().replace("%p", event.getPlayer().getDisplayName())); - } - } - } - - @EventHandler - public void onJsonChat(JsonChatEvent e){ + public void onJsonChat(UltraChatEvent e){ for(Player p : Bukkit.getOnlinePlayers()){ if(e.getMessage().contains("@" + p.getName())){ p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_PLING, 10, 0); diff --git a/src/me/ryandw11/ultrachat/listner/Notify_1_12.java b/src/me/ryandw11/ultrachat/listner/Notify_1_12.java index a600a7a..05d946a 100644 --- a/src/me/ryandw11/ultrachat/listner/Notify_1_12.java +++ b/src/me/ryandw11/ultrachat/listner/Notify_1_12.java @@ -4,34 +4,17 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; -import me.ryandw11.ultrachat.UltraChat; import me.ryandw11.ultrachat.api.Lang; -import me.ryandw11.ultrachat.api.events.JsonChatEvent; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; /** * For 1.12 and below servers. */ public class Notify_1_12 implements Listener { - private UltraChat plugin; - public Notify_1_12(){ - plugin = UltraChat.plugin; - } - @EventHandler - public void onChat(AsyncPlayerChatEvent event){ - if(plugin.JSON) return; - for(Player p : Bukkit.getOnlinePlayers()){ - if(event.getMessage().contains("@" + p.getName())){ - p.sendMessage(Lang.MENTION.toString().replace("%p", event.getPlayer().getDisplayName())); - } - } - } - - @EventHandler - public void onJsonChat(JsonChatEvent e){ + public void onJsonChat(UltraChatEvent e){ for(Player p : Bukkit.getOnlinePlayers()){ if(e.getMessage().contains("@" + p.getName())){ p.sendMessage(Lang.MENTION.toString().replace("%p", e.getPlayer().getDisplayName())); diff --git a/src/me/ryandw11/ultrachat/listner/StopChat.java b/src/me/ryandw11/ultrachat/listner/StopChat.java index 008569c..56c1ca9 100644 --- a/src/me/ryandw11/ultrachat/listner/StopChat.java +++ b/src/me/ryandw11/ultrachat/listner/StopChat.java @@ -3,11 +3,10 @@ package me.ryandw11.ultrachat.listner; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.player.AsyncPlayerChatEvent; import me.ryandw11.ultrachat.UltraChat; import me.ryandw11.ultrachat.api.Lang; -import me.ryandw11.ultrachat.api.events.JsonChatEvent; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; /** * Prevent players from chatting when the chat is stopped. * @author Ryandw11 @@ -21,19 +20,7 @@ public class StopChat implements Listener { } @EventHandler - public void onPlayerChat(AsyncPlayerChatEvent event) { - if(plugin.JSON) return; - Player p = event.getPlayer(); - if(plugin.chatStop){ - if(!p.hasPermission("ultrachat.stopchat.bypass")){ - event.setCancelled(true); - p.sendMessage(Lang.STOP_CHAT_MESSAGE.toString()); - } - } - } - - @EventHandler - public void onChat(JsonChatEvent e){ + public void onChat(UltraChatEvent e){ Player p = e.getPlayer(); if(plugin.chatStop){ if(!p.hasPermission("ultrachat.stopchat.bypass")){ diff --git a/src/me/ryandw11/ultrachat/pluginhooks/AdvancedBanMute.java b/src/me/ryandw11/ultrachat/pluginhooks/AdvancedBanMute.java index 66878f4..08271da 100644 --- a/src/me/ryandw11/ultrachat/pluginhooks/AdvancedBanMute.java +++ b/src/me/ryandw11/ultrachat/pluginhooks/AdvancedBanMute.java @@ -6,30 +6,12 @@ import org.bukkit.event.Listener; import me.leoko.advancedban.manager.PunishmentManager; import me.leoko.advancedban.manager.UUIDManager; -import me.ryandw11.ultrachat.api.events.GlobalChatEvent; -import me.ryandw11.ultrachat.api.events.JsonChatEvent; -import me.ryandw11.ultrachat.api.events.WorldChatEvent; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; public class AdvancedBanMute implements Listener{ @EventHandler - public void jsonChat(JsonChatEvent e){ - Player p = e.getPlayer(); - if(PunishmentManager.get().isMuted(UUIDManager.get().getUUID(p.getName()))){ - e.setCancelled(true); - } - } - - @EventHandler - public void globalChat(GlobalChatEvent e){ - Player p = e.getPlayer(); - if(PunishmentManager.get().isMuted(UUIDManager.get().getUUID(p.getName()))){ - e.setCancelled(true); - } - } - - @EventHandler - public void worldChat(WorldChatEvent e){ + public void jsonChat(UltraChatEvent e){ Player p = e.getPlayer(); if(PunishmentManager.get().isMuted(UUIDManager.get().getUUID(p.getName()))){ e.setCancelled(true); diff --git a/src/me/ryandw11/ultrachat/pluginhooks/EssentialsMute.java b/src/me/ryandw11/ultrachat/pluginhooks/EssentialsMute.java index 11f45e0..ae26c16 100644 --- a/src/me/ryandw11/ultrachat/pluginhooks/EssentialsMute.java +++ b/src/me/ryandw11/ultrachat/pluginhooks/EssentialsMute.java @@ -7,32 +7,12 @@ import org.bukkit.event.Listener; import com.earth2me.essentials.Essentials; -import me.ryandw11.ultrachat.api.events.GlobalChatEvent; -import me.ryandw11.ultrachat.api.events.JsonChatEvent; -import me.ryandw11.ultrachat.api.events.WorldChatEvent; +import me.ryandw11.ultrachat.api.events.UltraChatEvent; public class EssentialsMute implements Listener{ @EventHandler - public void jsonChat(JsonChatEvent e){ - Player p = e.getPlayer(); - Essentials ess = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials"); - if(ess.getUser(p).isMuted()){ - e.setCancelled(true); - } - } - - @EventHandler - public void globalChat(GlobalChatEvent e){ - Player p = e.getPlayer(); - Essentials ess = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials"); - if(ess.getUser(p).isMuted()){ - e.setCancelled(true); - } - } - - @EventHandler - public void worldChat(WorldChatEvent e){ + public void jsonChat(UltraChatEvent e){ Player p = e.getPlayer(); Essentials ess = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials"); if(ess.getUser(p).isMuted()){