mirror of
https://github.com/ryandw11/UltraChat.git
synced 2025-01-03 06:38:05 +01:00
Work on 2.5
- Implemented the API correctly. - Fixed hex color chatting. - New color gui system.
This commit is contained in:
parent
b9dcfaf3d9
commit
62df20ae69
@ -17,6 +17,7 @@ chat_colors:
|
||||
'&c': 'default'
|
||||
'&d': 'default'
|
||||
'&e': 'default'
|
||||
'&f': 'default'
|
||||
|
||||
###############################################
|
||||
# Chat Color GUI #
|
||||
|
@ -33,4 +33,5 @@ sjoin-hide: '&bYour Join/Leave message will no longer be shown!'
|
||||
sjoin-other-show: '&b%p Join/Leave message will now be shown!'
|
||||
sjoin-other-hide: '&b%p Join/Leave message will no longer be shown!'
|
||||
help-page-error: '&cThere are only two help pages!'
|
||||
chat-color-change: 'Your chat color has been changed!'
|
||||
|
||||
|
@ -59,11 +59,6 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
*/
|
||||
public class UltraChat extends JavaPlugin {
|
||||
|
||||
/**
|
||||
* TODO : I just finished allowing Hex colors in chat and removing the option for chat without JSON.
|
||||
* Next on the list is to add in the color chat picker.
|
||||
*/
|
||||
|
||||
public static UltraChat plugin;
|
||||
public Permission perms = null;
|
||||
public Chat chat = null;
|
||||
|
@ -1,8 +1,10 @@
|
||||
package me.ryandw11.ultrachat.api;
|
||||
|
||||
/**
|
||||
* The different modes chat can be in.
|
||||
*/
|
||||
public enum ChatType {
|
||||
NORMAL,
|
||||
CHANNEL,
|
||||
RANGE
|
||||
|
||||
}
|
||||
|
@ -39,7 +39,8 @@ public enum Lang {
|
||||
SJOIN_HIDE("sjoin-hide", "&bYour Join/Leave message will no longer be shown!"),
|
||||
SJOIN_OTHER_SHOW("sjoin-other-show", "&b%p Join/Leave message will now be shown!"),
|
||||
SJOIN_OTHER_HIDE("sjoin-other-hide", "&b%p Join/Leave message will no longer be shown!"),
|
||||
HELP_PAGE_ERROR("help-page-error", "&cThere are only two help pages!");
|
||||
HELP_PAGE_ERROR("help-page-error", "&cThere are only two help pages!"),
|
||||
CHAT_COLOR_CHANGE("chat-color-change", "Your chat color has been changed!");
|
||||
|
||||
|
||||
private String path;
|
||||
|
@ -14,9 +14,9 @@ import net.md_5.bungee.api.chat.TextComponent;
|
||||
*/
|
||||
public class MessageBuilder {
|
||||
|
||||
private ComponentBuilder compon;
|
||||
private ComponentBuilder component;
|
||||
public MessageBuilder() {
|
||||
compon = new ComponentBuilder("");
|
||||
component = new ComponentBuilder("");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -25,7 +25,7 @@ public class MessageBuilder {
|
||||
* @return The MessageBuilder to chain.
|
||||
*/
|
||||
public MessageBuilder addJSON(JSONChatBuilder json) {
|
||||
compon.append(json.build(), FormatRetention.FORMATTING);
|
||||
component.append(json.build(), FormatRetention.NONE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class MessageBuilder {
|
||||
*/
|
||||
public MessageBuilder addString(String s) {
|
||||
TextComponent tc = new TextComponent(s);
|
||||
compon.append(tc, FormatRetention.FORMATTING);
|
||||
component.append(tc, FormatRetention.NONE);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -46,11 +46,11 @@ public class MessageBuilder {
|
||||
* @return The Buider to chain
|
||||
*/
|
||||
public MessageBuilder addBaseComponent(BaseComponent[] bc) {
|
||||
compon.append(bc, FormatRetention.FORMATTING);
|
||||
component.append(bc, FormatRetention.NONE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseComponent[] build() {
|
||||
return this.compon.create();
|
||||
return this.component.create();
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package me.ryandw11.ultrachat.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
import me.ryandw11.ultrachat.api.managers.ChannelManager;
|
||||
import me.ryandw11.ultrachat.chatcolor.ChatColorManager;
|
||||
import me.ryandw11.ultrachat.chatcolor.ChatColorUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -16,7 +16,7 @@ import me.ryandw11.ultrachat.formatting.PlayerFormatting;
|
||||
/**
|
||||
* UltraChatAPI
|
||||
* @author Ryandw11
|
||||
* @version 2.4
|
||||
* @version 2.5
|
||||
*/
|
||||
|
||||
public class UltraChatAPI{
|
||||
@ -25,31 +25,11 @@ public class UltraChatAPI{
|
||||
this.plugin = UltraChat.plugin;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a format's json.
|
||||
* @param number
|
||||
* @return Json array
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayList<String> getChatFormatJson(String number){
|
||||
return (ArrayList<String>) plugin.getConfig().get("Custom_Chat." + number + ".JSON");
|
||||
}
|
||||
/**
|
||||
* Set a format's json.
|
||||
* @param json
|
||||
* @param number
|
||||
*
|
||||
*/
|
||||
public void setChatFormatJson(ArrayList<String> json, String number){
|
||||
plugin.getConfig().set("Custom_Chat." + number + ".JSON", json);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current channel of a player.
|
||||
* @param player The uuid of the player you want to get.
|
||||
* @return The chat channel.
|
||||
* @deprecated Use the channel manager instead.
|
||||
*/
|
||||
public ChatChannel getPlayerCurrentChannel(UUID player) {
|
||||
return new ChannelBuilder(plugin.data.getString(player + ".channel")).build();
|
||||
@ -91,114 +71,88 @@ public class UltraChatAPI{
|
||||
* Grab the player's formatting.
|
||||
* @param p The player.
|
||||
* @return The player's formatting.
|
||||
* @deprecated Construct the {@link PlayerFormatting} class yourself.
|
||||
*/
|
||||
public PlayerFormatting getPlayerFormatting(Player p){
|
||||
PlayerFormatting pf = new PlayerFormatting(p);
|
||||
return pf;
|
||||
return new PlayerFormatting(p);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a chat format.
|
||||
* @param number
|
||||
* @return Chat format.
|
||||
*/
|
||||
public String getFormat(String number){
|
||||
return plugin.getConfig().getString("Custom_Chat." + number + ".Format");
|
||||
}
|
||||
/**
|
||||
* Get the op format.
|
||||
* @return op format.
|
||||
*/
|
||||
public String getOpFormat(){
|
||||
return plugin.getConfig().getString("Custom_Chat.Op_Chat.Format");
|
||||
}
|
||||
/**
|
||||
* Get the default format.
|
||||
* @return op format.
|
||||
*/
|
||||
public String getDefaultFormat(){
|
||||
return plugin.getConfig().getString("Custom_Chat.Default.Format");
|
||||
}
|
||||
/**
|
||||
* Get the permission of a chat group.
|
||||
* @param number
|
||||
* @return permission
|
||||
*/
|
||||
public String getPermission(String number){
|
||||
return plugin.getConfig().getString("Custom_Chat." + number + ".Permission");
|
||||
}
|
||||
/**
|
||||
* Get the number of formats
|
||||
* @return Chat Count
|
||||
*/
|
||||
public int getChatCount(){
|
||||
return plugin.getConfig().getInt("Custom_Chat.Chat_Count");
|
||||
}
|
||||
/**
|
||||
* Get a player's color. Example: &4
|
||||
* @param player
|
||||
* Get a player's color.
|
||||
* <p>This will return a string Such as &4 or {#FFFFFF}.</p>
|
||||
* <p>Note: The colors interpreted are from the chatcolor.yml file. To also get color data from the use {@link me.ryandw11.ultrachat.util.ChatUtil#translateColorCode(String)}</p>
|
||||
* @param player The player to get the color for
|
||||
* @return color code.
|
||||
*/
|
||||
public String getPlayerColor(Player player){
|
||||
return plugin.data.getString(player.getUniqueId() + ".color");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a player's color.
|
||||
* @param player
|
||||
* @param color
|
||||
* @param player The player color to set
|
||||
* @param color The color to set
|
||||
* <p>Keep in mind that this color is interpreted from the chatcolor.yml file, not the default colors.</p>
|
||||
*/
|
||||
public void setPlayerColor(Player player, String color){
|
||||
plugin.data.set(player.getUniqueId() + ".color", color);
|
||||
plugin.saveFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the swear word list.
|
||||
* @return Block swear words.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ArrayList<String> getSwearWords(){
|
||||
return (ArrayList<String>) plugin.getConfig().get("Blocked_Words");
|
||||
public List<String> getSwearWords(){
|
||||
return plugin.getConfig().getStringList("Blocked_Words");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the swear word list.
|
||||
* @param words
|
||||
* @param words The words to add
|
||||
*/
|
||||
public void setSwearWords(ArrayList<String> words){
|
||||
public void setSwearWords(List<String> words){
|
||||
plugin.getConfig().set("Blocked_Words", words);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* If components are enabled.
|
||||
* @return If components are enabled.
|
||||
*/
|
||||
public boolean isComponents() {
|
||||
return plugin.getConfig().getBoolean("Components_Enabled");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current formatting type.
|
||||
* @return The value of the config.
|
||||
*/
|
||||
public String getFormattingType(){
|
||||
return plugin.getConfig().getString("chat_format");
|
||||
public ChatType getFormattingType(){
|
||||
return plugin.md;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* See if default channel exists.
|
||||
* @param chan - The channel in the config.
|
||||
* @return True if it does, false if not.
|
||||
* Get the chat color utility interface.
|
||||
* <p>Note: Most methods from this interface are wrapped in the {@link me.ryandw11.ultrachat.util.ChatUtil} class.</p>
|
||||
* @return The chat color utility interface.
|
||||
*/
|
||||
public boolean legitDefaultChannel(String chan){
|
||||
if(plugin.channel.contains(chan))
|
||||
return true;
|
||||
return false;
|
||||
public ChatColorUtils getChatColorUtil(){
|
||||
return plugin.chatColorUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the chat color manager.
|
||||
* <p>Note: Most uses for this class is covered by the {@link me.ryandw11.ultrachat.util.ChatUtil} class.</p>
|
||||
* <p><b>This class is only available on 1.16+ servers. This WILL return null on any version below 1.16.</b></p>
|
||||
* @return The chat color manager.
|
||||
*/
|
||||
public ChatColorManager getChatColorManager(){
|
||||
return plugin.chatColorManager;
|
||||
}
|
||||
|
||||
public ChannelManager getChannelManager(){
|
||||
return new ChannelManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current active hooks.
|
||||
* @return The set witht the names of the plugins. Returns null if no hooks are active.
|
||||
* @return The set with the names of the plugins. Returns null if no hooks are active.
|
||||
*/
|
||||
public Set<String> getActiveHooks(){
|
||||
Set<String> s = new HashSet<String>();
|
||||
Set<String> s = new HashSet<>();
|
||||
if(Bukkit.getServer().getPluginManager().getPlugin("AdvancedBan") != null && plugin.getConfig().getBoolean("pluginhooks.Essentials")){
|
||||
s.add("Essentials");
|
||||
}
|
||||
|
@ -1,49 +0,0 @@
|
||||
package me.ryandw11.ultrachat.api;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class Util {
|
||||
/**
|
||||
*
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static ChatColor getColorFromCode(String s){
|
||||
String b = s.substring(1);
|
||||
switch (b){
|
||||
case "1":
|
||||
return ChatColor.DARK_BLUE;
|
||||
case "2":
|
||||
return ChatColor.DARK_GREEN;
|
||||
case "3":
|
||||
return ChatColor.DARK_AQUA;
|
||||
case "4":
|
||||
return ChatColor.DARK_RED;
|
||||
case "5":
|
||||
return ChatColor.DARK_PURPLE;
|
||||
case "6":
|
||||
return ChatColor.GOLD;
|
||||
case "7":
|
||||
return ChatColor.GRAY;
|
||||
case "8":
|
||||
return ChatColor.DARK_GRAY;
|
||||
case "9":
|
||||
return ChatColor.BLUE;
|
||||
case "c":
|
||||
return ChatColor.RED;
|
||||
case "d":
|
||||
return ChatColor.LIGHT_PURPLE;
|
||||
case "e":
|
||||
return ChatColor.YELLOW;
|
||||
case "f":
|
||||
return ChatColor.WHITE;
|
||||
case "a":
|
||||
return ChatColor.GREEN;
|
||||
case "b":
|
||||
return ChatColor.AQUA;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -4,6 +4,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* This event is called when the staff chat is used.
|
||||
*/
|
||||
public class StaffChatEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
@ -9,6 +9,10 @@ import org.bukkit.event.HandlerList;
|
||||
import me.ryandw11.ultrachat.api.ChatType;
|
||||
import me.ryandw11.ultrachat.api.events.properties.ChatProperties;
|
||||
|
||||
/**
|
||||
* The UltraChatEvent is used when a player chats. This event gives you more information than the normal AsyncChatEvent.
|
||||
* <p>Note: Since API Version 2.5 this event is only needed when you want specific ultraChat information.</p>
|
||||
*/
|
||||
public class UltraChatEvent extends Event{
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
@ -36,7 +40,7 @@ public class UltraChatEvent extends Event{
|
||||
}
|
||||
/**
|
||||
* Set the recipients.
|
||||
* @param recipents The set of recipients.
|
||||
* @param recipients The set of recipients.
|
||||
*/
|
||||
public void setRecipients(Set<Player> recipients){
|
||||
this.recipients = recipients;
|
||||
|
@ -4,7 +4,7 @@ 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;
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
package me.ryandw11.ultrachat.api.events.properties;
|
||||
|
||||
public interface ChatProperties {
|
||||
|
||||
public boolean isComponent();
|
||||
|
||||
/**
|
||||
* @deprecated As of version 2.5 this will always be true as the plugin is always in JSON mode.
|
||||
* @return If the plugin has json components enabled.
|
||||
*/
|
||||
boolean isComponent();
|
||||
|
||||
}
|
||||
|
@ -3,5 +3,5 @@ package me.ryandw11.ultrachat.api.events.properties;
|
||||
public enum RangeType {
|
||||
LOCAL,
|
||||
WORLD,
|
||||
GLBOAL
|
||||
GLOBAL
|
||||
}
|
||||
|
@ -4,26 +4,45 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import me.ryandw11.ultrachat.api.UltraChatAPI;
|
||||
import me.ryandw11.ultrachat.api.placeholders.PlaceholderAddon;
|
||||
|
||||
/**
|
||||
* This class handles any addons to the plugin.
|
||||
* <p>The instance of this class can be retrieved from {@link UltraChatAPI#getAddonManager()}</p>
|
||||
*/
|
||||
public class AddonManager {
|
||||
private List<PlaceholderAddon> pa;
|
||||
public AddonManager() {
|
||||
pa = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an addon
|
||||
* @param pa The addon to add.
|
||||
*/
|
||||
public void addAddon(PlaceholderAddon pa) {
|
||||
this.pa.add(pa);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the list of addons.
|
||||
* @return The list of addons.
|
||||
*/
|
||||
public List<PlaceholderAddon> getAddons(){
|
||||
return pa;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replace the placeholders in a string.
|
||||
* @param s The string.
|
||||
* @param p The player UUID.
|
||||
* @return The string with the placeholders replaced.
|
||||
*/
|
||||
public String replacePlaceholders(String s, UUID p) {
|
||||
String output = s;
|
||||
for(PlaceholderAddon fs : pa) {
|
||||
output.replace(fs.getName(), fs.getString(p));
|
||||
output = output.replace(fs.getName(), fs.getString(p));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package me.ryandw11.ultrachat.api.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,6 +9,10 @@ import me.ryandw11.ultrachat.UltraChat;
|
||||
import me.ryandw11.ultrachat.api.channels.ChannelBuilder;
|
||||
import me.ryandw11.ultrachat.api.channels.ChatChannel;
|
||||
|
||||
/**
|
||||
* This class handles the channels of the plugin.
|
||||
* <p>Get the instance of this class from {@link me.ryandw11.ultrachat.api.UltraChatAPI#getChannelManager()}</p>
|
||||
*/
|
||||
public class ChannelManager {
|
||||
private UltraChat plugin;
|
||||
public ChannelManager() {
|
||||
@ -29,7 +31,7 @@ public class ChannelManager {
|
||||
|
||||
/**
|
||||
* Grab the player's current channel.
|
||||
* @param player
|
||||
* @param player The player to get the channel from.
|
||||
* @return The player's current channel.
|
||||
*/
|
||||
public ChatChannel getPlayerChannel(Player player){
|
||||
@ -39,8 +41,8 @@ public class ChannelManager {
|
||||
|
||||
/**
|
||||
* Grab an offline player's current channel.
|
||||
* @param player
|
||||
* @return
|
||||
* @param player The player to get the channel from.
|
||||
* @return That UUID's current channel.
|
||||
*/
|
||||
public ChatChannel getPlayerChannel(UUID player) {
|
||||
ChannelBuilder cb = new ChannelBuilder(plugin.data.getString(player + ".channel"));
|
||||
@ -58,8 +60,8 @@ public class ChannelManager {
|
||||
|
||||
/**
|
||||
* Set the player's channel.
|
||||
* @param player
|
||||
* @param channel
|
||||
* @param player The player to set.
|
||||
* @param channel The channel.
|
||||
*/
|
||||
public void setPlayerChannel(Player player, ChatChannel channel){
|
||||
plugin.data.set(player.getUniqueId() + ".channel", channel.getName());
|
||||
@ -68,8 +70,8 @@ public class ChannelManager {
|
||||
|
||||
/**
|
||||
* Set the player's channel.
|
||||
* @param player
|
||||
* @param channel
|
||||
* @param player The player to set.
|
||||
* @param channel The channel.
|
||||
*/
|
||||
public void setPlayerChannel(UUID player, ChatChannel channel) {
|
||||
plugin.data.set(player + ".channel", channel.getName());
|
||||
@ -79,7 +81,7 @@ public class ChannelManager {
|
||||
|
||||
/**
|
||||
* Set the default channel
|
||||
* @param channel
|
||||
* @param channel The channel.
|
||||
*/
|
||||
public void setDefaultChannel(ChatChannel channel){
|
||||
plugin.getConfig().set("Default_Config", channel.getName());
|
||||
@ -88,7 +90,8 @@ public class ChannelManager {
|
||||
|
||||
/**
|
||||
* If a given channel exists (In this instance if it is save in the files)
|
||||
* @param channel
|
||||
* @param channel The channel to check.
|
||||
* @return If the channel exists.
|
||||
*/
|
||||
public boolean channelExists(ChatChannel channel) {
|
||||
return plugin.channel.contains(channel.getName());
|
||||
@ -96,8 +99,8 @@ public class ChannelManager {
|
||||
|
||||
/**
|
||||
* If a given channel exists based upon the name.
|
||||
* @param name
|
||||
* @return
|
||||
* @param name The name of the channel to check
|
||||
* @return If the channel exists.
|
||||
*/
|
||||
public boolean channelExists(String name) {
|
||||
return plugin.channel.contains(name);
|
||||
@ -105,8 +108,8 @@ public class ChannelManager {
|
||||
|
||||
/**
|
||||
* Get all online players in a given channel.
|
||||
* @param channel
|
||||
* @return
|
||||
* @param channel The channel to get the players from.
|
||||
* @return The list of players. (Unmodifiable)
|
||||
*/
|
||||
public List<Player> getPlayersInChannel(ChatChannel channel){
|
||||
List<Player> output = new ArrayList<>();
|
||||
@ -115,23 +118,23 @@ public class ChannelManager {
|
||||
output.add(p);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
return Collections.unmodifiableList(output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all players in a channel online or offline.
|
||||
* @param channel
|
||||
* @return
|
||||
* @param channel The channel to get the UUIDs from.
|
||||
* @return The list of UUIDs. (Unmodifiable)
|
||||
*/
|
||||
public List<UUID> getAllPlayersInChannel(ChatChannel channel){
|
||||
List<UUID> output = new ArrayList<>();
|
||||
for(String s : plugin.data.getConfigurationSection("").getKeys(false)) {
|
||||
for(String s : Objects.requireNonNull(plugin.data.getConfigurationSection("")).getKeys(false)) {
|
||||
UUID ud = UUID.fromString(s);
|
||||
if(this.getPlayerChannel(ud).getName().equals(channel.getName())) {
|
||||
output.add(ud);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
return Collections.unmodifiableList(output);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,7 @@
|
||||
package me.ryandw11.ultrachat.chatcolor;
|
||||
|
||||
import me.ryandw11.ultrachat.UltraChat;
|
||||
import me.ryandw11.ultrachat.formatting.PlayerFormatting;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.tuple.MutablePair;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ChatColorUtil_Latest implements ChatColorUtils {
|
||||
|
||||
@ -25,41 +17,6 @@ public class ChatColorUtil_Latest implements ChatColorUtils {
|
||||
return finalMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translateChatColor(Player p, String message) {
|
||||
String finalMessage = message;
|
||||
if(p.hasPermission("ultrachat.chatcolor.hex"))
|
||||
finalMessage = translateHexColor(finalMessage);
|
||||
if(p.hasPermission("ultrachat.chatcolor.colorcodes"))
|
||||
finalMessage = plugin.chatColorManager.translateMapColors(finalMessage);
|
||||
return finalMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> splitColors(String message, PlayerFormatting pf) {
|
||||
List<String> normalMessage = new ArrayList<>(Arrays.asList(message.split("\\{(#[^}]+)}|&[^&]")));
|
||||
List<String> colorCodes = new ArrayList<>();
|
||||
// TODO fix this
|
||||
colorCodes.add(pf.getColor().toString());
|
||||
Matcher m = Pattern.compile("\\{(#[^}]+)}|&[^&]").matcher(message);
|
||||
while(m.find()) {
|
||||
colorCodes.add(m.group());
|
||||
}
|
||||
for(int i = 0; i < colorCodes.size(); i++){
|
||||
if(!isChatCode(colorCodes.get(i)) && i != 0){
|
||||
normalMessage.set(i-1, normalMessage.get(i-1) +colorCodes.get(i)+normalMessage.get(i));
|
||||
normalMessage.remove(i);
|
||||
colorCodes.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
Map<String, String> output = new LinkedHashMap<>();
|
||||
for(int i = 0; i < normalMessage.size(); i++){
|
||||
output.put(normalMessage.get(i), colorCodes.get(i));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatColor translateChatCode(String code) {
|
||||
if(code.startsWith("&")){
|
||||
@ -87,11 +44,6 @@ public class ChatColorUtil_Latest implements ChatColorUtils {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatColor translateChatCode(Player p, String code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static String translateHexColor(String message){
|
||||
if(!message.contains("{"))
|
||||
return message;
|
||||
|
@ -1,13 +1,6 @@
|
||||
package me.ryandw11.ultrachat.chatcolor;
|
||||
|
||||
import me.ryandw11.ultrachat.formatting.PlayerFormatting;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
public class ChatColorUtil_Old implements ChatColorUtils {
|
||||
|
||||
@ -17,17 +10,7 @@ public class ChatColorUtil_Old implements ChatColorUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translateChatColor(Player p, String message) {
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> splitColors(String message, PlayerFormatting pf) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.md_5.bungee.api.ChatColor translateChatCode(String code) {
|
||||
public ChatColor translateChatCode(String code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -35,9 +18,4 @@ public class ChatColorUtil_Old implements ChatColorUtils {
|
||||
public boolean isChatCode(String code) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.md_5.bungee.api.ChatColor translateChatCode(Player p, String message) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,9 @@
|
||||
package me.ryandw11.ultrachat.chatcolor;
|
||||
|
||||
import me.ryandw11.ultrachat.formatting.PlayerFormatting;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
|
||||
public interface ChatColorUtils {
|
||||
String translateChatColor(String message);
|
||||
String translateChatColor(Player p, String message);
|
||||
Map<String, String> splitColors(String message, PlayerFormatting pf);
|
||||
ChatColor translateChatCode(String code);
|
||||
boolean isChatCode(String code);
|
||||
ChatColor translateChatCode(Player p, String message);
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ public class ChatCommand implements CommandExecutor {
|
||||
}
|
||||
else if(args.length == 1 && args[0].equalsIgnoreCase("color")){
|
||||
if(p.hasPermission("ultrachat.color")){
|
||||
plugin.getColorGUI().openGUI(p.getPlayer());
|
||||
plugin.getColorGUI().openGUI(p.getPlayer(), 1);
|
||||
}
|
||||
else{
|
||||
p.sendMessage(Lang.NO_PERM.toString());
|
||||
|
@ -34,13 +34,11 @@ public class Global implements CommandExecutor {
|
||||
p.sendMessage(Lang.NO_PERM.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
UltraChatAPI uapi = new UltraChatAPI();
|
||||
PlayerFormatting pf = new PlayerFormatting(p);
|
||||
|
||||
RangeProperties rp = new RangeProperties(uapi.isComponents(), RangeType.GLBOAL);
|
||||
RangeProperties rp = new RangeProperties(true, RangeType.GLOBAL);
|
||||
UltraChatEvent uce = new UltraChatEvent(p, this.getMessage(args, p),
|
||||
new HashSet<Player>(Bukkit.getOnlinePlayers()), ChatType.RANGE, rp);
|
||||
new HashSet<>(Bukkit.getOnlinePlayers()), ChatType.RANGE, rp);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(UltraChat.plugin, () ->{
|
||||
Bukkit.getServer().getPluginManager().callEvent(uce);
|
||||
|
@ -34,12 +34,11 @@ public class World implements CommandExecutor {
|
||||
p.sendMessage(Lang.NO_PERM.toString());
|
||||
return true;
|
||||
}
|
||||
UltraChatAPI uapi = new UltraChatAPI();
|
||||
PlayerFormatting pf = new PlayerFormatting(p);
|
||||
|
||||
RangeProperties rp = new RangeProperties(uapi.isComponents(), RangeType.WORLD);
|
||||
RangeProperties rp = new RangeProperties(true, RangeType.WORLD);
|
||||
UltraChatEvent uce = new UltraChatEvent(p, this.getMessage(args, p),
|
||||
new HashSet<Player>(p.getWorld().getPlayers()), ChatType.RANGE, rp);
|
||||
new HashSet<>(p.getWorld().getPlayers()), ChatType.RANGE, rp);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(UltraChat.plugin, () -> {
|
||||
Bukkit.getServer().getPluginManager().callEvent(uce);
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class ChannelJSON implements Listener {
|
||||
|
||||
ComponentBuilder cb = new ComponentBuilder("");
|
||||
cb.append(JComponentManager.formatComponents(format, p));
|
||||
cb.append(ChatUtil.translateColorCodesChat(uce.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
cb.append(new TextComponent(TextComponent.fromLegacyText(plugin.chatColorUtil.translateChatColor(uce.getMessage()), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
}
|
||||
}
|
||||
@ -80,7 +80,7 @@ public class ChannelJSON implements Listener {
|
||||
|
||||
ComponentBuilder cb = new ComponentBuilder("");
|
||||
cb.append(JComponentManager.formatComponents(formats, p));
|
||||
cb.append(ChatUtil.translateColorCodesChat(uce.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
cb.append(new TextComponent(TextComponent.fromLegacyText(plugin.chatColorUtil.translateChatColor(uce.getMessage()), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
package me.ryandw11.ultrachat.formatting;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -42,7 +39,7 @@ public class NormalJSON implements Listener {
|
||||
|
||||
// Call the UltraChatEvent (This is an optional Event).
|
||||
NormalProperties np = new NormalProperties(true);
|
||||
UltraChatEvent event = new UltraChatEvent(p, e.getMessage(), new HashSet<Player>(e.getRecipients()), ChatType.NORMAL, np);
|
||||
UltraChatEvent event = new UltraChatEvent(p, e.getMessage(), new HashSet<>(e.getRecipients()), ChatType.NORMAL, np);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
@ -55,12 +52,12 @@ public class NormalJSON implements Listener {
|
||||
String formats = pf.getOpFormat()
|
||||
.replace("%prefix%", pf.getPrefix())
|
||||
.replace("%suffix%", pf.getSuffix())
|
||||
.replace("%player%", p.getDisplayName());
|
||||
.replace("%player%", p.getDisplayName()) + pf.getColor();
|
||||
|
||||
for (Player pl : event.getRecipients()) {
|
||||
ComponentBuilder cb = new ComponentBuilder("");
|
||||
cb.append(JComponentManager.formatComponents(formats, p));
|
||||
cb.append(ChatUtil.translateColorCodesChat(event.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
cb.append(new TextComponent(TextComponent.fromLegacyText(pf.getColor() + plugin.chatColorUtil.translateChatColor(event.getMessage()), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
}
|
||||
return;
|
||||
@ -77,7 +74,7 @@ public class NormalJSON implements Listener {
|
||||
for (Player pl : event.getRecipients()) {
|
||||
ComponentBuilder cb = new ComponentBuilder("");
|
||||
cb.append(JComponentManager.formatComponents(formats, p));
|
||||
cb.append(ChatUtil.translateColorCodesChat(event.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
cb.append(new TextComponent(TextComponent.fromLegacyText(plugin.chatColorUtil.translateChatColor(event.getMessage()), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
}
|
||||
return;
|
||||
@ -95,7 +92,7 @@ public class NormalJSON implements Listener {
|
||||
for (Player pl : event.getRecipients()) {
|
||||
ComponentBuilder cb = new ComponentBuilder("");
|
||||
cb.append(JComponentManager.formatComponents(formats, p));
|
||||
cb.append(ChatUtil.translateColorCodesChat(event.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
cb.append(new TextComponent(TextComponent.fromLegacyText(plugin.chatColorUtil.translateChatColor(event.getMessage()), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
package me.ryandw11.ultrachat.formatting;
|
||||
|
||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import me.ryandw11.ultrachat.UltraChat;
|
||||
import me.ryandw11.ultrachat.api.Util;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -63,7 +63,7 @@ public class PlayerFormatting {
|
||||
return suffix;
|
||||
}
|
||||
public ChatColor getColor(){
|
||||
return Util.getColorFromCode(color);
|
||||
return ChatUtil.translateColorCode(color);
|
||||
}
|
||||
public String getOpFormat(){
|
||||
return formatOp;
|
||||
|
@ -54,7 +54,7 @@ public class RangeJSON implements Listener {
|
||||
|
||||
ComponentBuilder cb = new ComponentBuilder("");
|
||||
cb.append(JComponentManager.formatComponents(formats, p));
|
||||
cb.append(ChatUtil.translateColorCodesChat(uce.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
cb.append(new TextComponent(TextComponent.fromLegacyText(plugin.chatColorUtil.translateChatColor(uce.getMessage()), pf.getColor())), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,13 @@ package me.ryandw11.ultrachat.formatting;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import me.ryandw11.ultrachat.UltraChat;
|
||||
import me.ryandw11.ultrachat.api.ChatType;
|
||||
import me.ryandw11.ultrachat.api.UltraChatAPI;
|
||||
import me.ryandw11.ultrachat.api.Util;
|
||||
import me.ryandw11.ultrachat.api.channels.ChatChannel;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
@ -80,7 +80,7 @@ private UltraChat plugin;
|
||||
return suffix;
|
||||
}
|
||||
public ChatColor getColor(){
|
||||
return Util.getColorFromCode(color);
|
||||
return ChatUtil.translateColorCode(color);
|
||||
}
|
||||
public String getOpFormat(){
|
||||
return formatOp;
|
||||
|
@ -7,5 +7,5 @@ import org.bukkit.entity.Player;
|
||||
*
|
||||
*/
|
||||
public interface ColorGUI {
|
||||
void openGUI(Player p);
|
||||
void openGUI(Player p, int page);
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class ColorGUI_1_15_R1 implements CommandExecutor, Listener, ColorGUI{
|
||||
public ColorGUI_1_15_R1(){
|
||||
plugin = UltraChat.plugin;
|
||||
}
|
||||
public void openGUI(Player p){
|
||||
public void openGUI(Player p, int page){
|
||||
Inventory i = Bukkit.createInventory(null, InventoryType.CHEST, Lang.COLOR_GUI.toString());
|
||||
|
||||
ItemStack darkblueitem = new ItemStack(Material.BLUE_WOOL);
|
||||
@ -166,7 +166,7 @@ public class ColorGUI_1_15_R1 implements CommandExecutor, Listener, ColorGUI{
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
if(p.hasPermission("ultrachat.color")){
|
||||
openGUI(p.getPlayer());
|
||||
openGUI(p.getPlayer(), 0);
|
||||
}
|
||||
else{
|
||||
p.sendMessage(Lang.NO_PERM.toString());
|
||||
|
@ -1,16 +1,19 @@
|
||||
package me.ryandw11.ultrachat.gui;
|
||||
|
||||
import com.sun.istack.internal.NotNull;
|
||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -18,6 +21,8 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import me.ryandw11.ultrachat.UltraChat;
|
||||
import me.ryandw11.ultrachat.api.Lang;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* ColorGUI class.
|
||||
* Updated for 1.16+
|
||||
@ -27,147 +32,127 @@ import me.ryandw11.ultrachat.api.Lang;
|
||||
public class ColorGUI_Latest implements CommandExecutor, Listener, ColorGUI{
|
||||
|
||||
private UltraChat plugin;
|
||||
private List<String> colors;
|
||||
public ColorGUI_Latest(){
|
||||
plugin = UltraChat.plugin;
|
||||
colors = new ArrayList<>(Objects.requireNonNull(plugin.chatColorFC.getConfigurationSection("color_gui")).getKeys(false));
|
||||
}
|
||||
public void openGUI(Player p){
|
||||
Inventory i = Bukkit.createInventory(null, InventoryType.CHEST, Lang.COLOR_GUI.toString());
|
||||
|
||||
ItemStack darkblueitem = new ItemStack(Material.BLUE_WOOL);
|
||||
ItemMeta darkbluemeta = darkblueitem.getItemMeta();
|
||||
|
||||
ItemStack greenitem = new ItemStack(Material.GREEN_WOOL);
|
||||
ItemMeta greenmeta = greenitem.getItemMeta();
|
||||
|
||||
ItemStack lightblueitem = new ItemStack(Material.CYAN_WOOL);
|
||||
ItemMeta lightbluemeta = lightblueitem.getItemMeta();
|
||||
|
||||
ItemStack reditem = new ItemStack(Material.RED_WOOL);
|
||||
ItemMeta redmeta = reditem.getItemMeta();
|
||||
|
||||
ItemStack purpleitem = new ItemStack(Material.PURPLE_WOOL);
|
||||
ItemMeta purplemeta = purpleitem.getItemMeta();
|
||||
|
||||
ItemStack golditem = new ItemStack(Material.ORANGE_WOOL);
|
||||
ItemMeta goldmeta = golditem.getItemMeta();
|
||||
|
||||
ItemStack lightgrayitem = new ItemStack(Material.LIGHT_GRAY_WOOL);
|
||||
ItemMeta lightgraymeta = lightgrayitem.getItemMeta();
|
||||
|
||||
ItemStack grayitem = new ItemStack(Material.GRAY_WOOL);
|
||||
ItemMeta graymeta = grayitem.getItemMeta();
|
||||
|
||||
ItemStack blueitem = new ItemStack(Material.LAPIS_BLOCK);
|
||||
ItemMeta bluemeta = blueitem.getItemMeta();
|
||||
|
||||
ItemStack lightgreenitem = new ItemStack(Material.LIME_WOOL);
|
||||
ItemMeta lightgreenmeta = lightgreenitem.getItemMeta();
|
||||
|
||||
ItemStack aquaitem = new ItemStack(Material.LIGHT_BLUE_WOOL);
|
||||
ItemMeta aquameta = aquaitem.getItemMeta();
|
||||
|
||||
ItemStack lightreditem = new ItemStack(Material.PINK_WOOL);
|
||||
ItemMeta lightredmeta = lightreditem.getItemMeta();
|
||||
|
||||
ItemStack pinkitem = new ItemStack(Material.MAGENTA_WOOL);
|
||||
ItemMeta pinkmeta = pinkitem.getItemMeta();
|
||||
|
||||
ItemStack yellowitem = new ItemStack(Material.YELLOW_WOOL);
|
||||
ItemMeta yellowmeta = yellowitem.getItemMeta();
|
||||
|
||||
ItemStack whiteitem = new ItemStack(Material.WHITE_WOOL);
|
||||
ItemMeta whitemeta = whiteitem.getItemMeta();
|
||||
|
||||
//==========================================================
|
||||
|
||||
darkbluemeta.setDisplayName("<EFBFBD>1Dark Blue Color Chat");
|
||||
darkblueitem.setItemMeta(darkbluemeta);
|
||||
|
||||
greenmeta.setDisplayName("<EFBFBD>2Green Color Chat");
|
||||
greenitem.setItemMeta(greenmeta);
|
||||
|
||||
lightbluemeta.setDisplayName("<EFBFBD>3Cyan Color Chat");
|
||||
lightblueitem.setItemMeta(lightbluemeta);
|
||||
|
||||
redmeta.setDisplayName("<EFBFBD>4Red Color Chat");
|
||||
reditem.setItemMeta(redmeta);
|
||||
|
||||
purplemeta.setDisplayName("<EFBFBD>5Purple Color Chat");
|
||||
purpleitem.setItemMeta(purplemeta);
|
||||
|
||||
goldmeta.setDisplayName("<EFBFBD>6Gold Color Chat");
|
||||
golditem.setItemMeta(goldmeta);
|
||||
|
||||
lightgraymeta.setDisplayName("<EFBFBD>7Light Gray Color Chat");
|
||||
lightgrayitem.setItemMeta(lightgraymeta);
|
||||
|
||||
graymeta.setDisplayName("<EFBFBD>8Gray Color Chat");
|
||||
grayitem.setItemMeta(graymeta);
|
||||
|
||||
bluemeta.setDisplayName("<EFBFBD>9Blue Color Chat");
|
||||
blueitem.setItemMeta(bluemeta);
|
||||
|
||||
lightgreenmeta.setDisplayName("<EFBFBD>aLight Green Color Chat");
|
||||
lightgreenitem.setItemMeta(lightgreenmeta);
|
||||
|
||||
aquameta.setDisplayName("<EFBFBD>bAqua Color Chat");
|
||||
aquaitem.setItemMeta(aquameta);
|
||||
|
||||
lightredmeta.setDisplayName("<EFBFBD>cLight Red Color Chat");
|
||||
lightreditem.setItemMeta(lightredmeta);
|
||||
|
||||
pinkmeta.setDisplayName("<EFBFBD>dMagenta Color Chat");
|
||||
pinkitem.setItemMeta(pinkmeta);
|
||||
|
||||
yellowmeta.setDisplayName("<EFBFBD>eYellow Color Chat");
|
||||
yellowitem.setItemMeta(yellowmeta);
|
||||
|
||||
whitemeta.setDisplayName("<EFBFBD>fWhite Color Chat");
|
||||
whiteitem.setItemMeta(whitemeta);
|
||||
//==========================================================
|
||||
|
||||
ItemStack holder = new ItemStack(Material.GRAY_STAINED_GLASS_PANE, 1);
|
||||
ItemMeta holderM = holder.getItemMeta();
|
||||
holderM.setDisplayName(" ");
|
||||
holder.setItemMeta(holderM);
|
||||
|
||||
for(int o = 15; o < 27; o++) {
|
||||
i.setItem(o, holder);
|
||||
|
||||
public void openGUI(Player p, int page){
|
||||
Inventory inv = Bukkit.createInventory(null, 9*3, Lang.COLOR_GUI.toString());
|
||||
|
||||
int i = getMin(page);
|
||||
int invSlot = 0;
|
||||
while(i < colors.size() && i < getMax(page)){
|
||||
ConfigurationSection section = plugin.chatColorFC.getConfigurationSection("color_gui." + colors.get(i));
|
||||
assert section != null;
|
||||
if(p.hasPermission(Objects.requireNonNull(section.getString("permission")))){
|
||||
ItemStack item = new ItemStack(Objects.requireNonNull(Material.getMaterial(Objects.requireNonNull(section.getString("item")))));
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(ChatUtil.translateColorCode(section.getString("color")) + section.getName());
|
||||
meta.setLore(Collections.singletonList(ChatColor.AQUA + "Click this to set your chat color!"));
|
||||
item.setItemMeta(meta);
|
||||
inv.setItem(invSlot, item);
|
||||
}else{
|
||||
inv.setItem(invSlot, getNoPermItem());
|
||||
}
|
||||
|
||||
invSlot++;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
i.setItem(0, darkblueitem);
|
||||
i.setItem(1, greenitem);
|
||||
i.setItem(2, lightblueitem);
|
||||
i.setItem(3, reditem);
|
||||
i.setItem(4, purpleitem);
|
||||
i.setItem(5, golditem);
|
||||
i.setItem(6, lightgrayitem);
|
||||
i.setItem(7, grayitem);
|
||||
i.setItem(8, blueitem);
|
||||
i.setItem(9, lightgreenitem);
|
||||
i.setItem(10, aquaitem);
|
||||
i.setItem(11, lightreditem);
|
||||
i.setItem(12, pinkitem);
|
||||
i.setItem(13, yellowitem);
|
||||
i.setItem(14, whiteitem);
|
||||
|
||||
|
||||
p.openInventory(i);
|
||||
setBottom(inv, page);
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
private int getMax(int page){
|
||||
return 9 * (2 * page);
|
||||
}
|
||||
private int getMin(int page){
|
||||
return (9 * (page*2)) - (9*2);
|
||||
}
|
||||
|
||||
private ItemStack getNoPermItem(){
|
||||
ItemStack itemStack = new ItemStack(Material.LIGHT_GRAY_STAINED_GLASS_PANE);
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName(ChatColor.RED + "You do not have permission for this color!");
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
private ItemStack getBottomStack(){
|
||||
ItemStack bottomStack = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
|
||||
ItemMeta bottomMeta = bottomStack.getItemMeta();
|
||||
assert bottomMeta != null;
|
||||
bottomMeta.setDisplayName(ChatColor.GRAY + " ");
|
||||
bottomStack.setItemMeta(bottomMeta);
|
||||
return bottomStack;
|
||||
}
|
||||
|
||||
private ItemStack getPrevStack(int page){
|
||||
ItemStack prevPage = new ItemStack(Material.PURPLE_STAINED_GLASS_PANE);
|
||||
ItemMeta prevMeta = prevPage.getItemMeta();
|
||||
assert prevMeta != null;
|
||||
prevMeta.setDisplayName(ChatColor.LIGHT_PURPLE + "<< Previous Page");
|
||||
prevPage.setItemMeta(prevMeta);
|
||||
if(page > 1)
|
||||
prevPage.setAmount(page-1);
|
||||
return prevPage;
|
||||
}
|
||||
|
||||
private ItemStack getCurrentStack(int page){
|
||||
ItemStack currentPage = new ItemStack(Material.GRAY_STAINED_GLASS_PANE);
|
||||
ItemMeta currentMeta = currentPage.getItemMeta();
|
||||
assert currentMeta != null;
|
||||
currentMeta.setDisplayName(ChatColor.GRAY + "Current Page: " + page);
|
||||
currentPage.setItemMeta(currentMeta);
|
||||
currentPage.setAmount(page);
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
private ItemStack getNextStack(int page){
|
||||
ItemStack nextPage = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
||||
ItemMeta nextMeta = nextPage.getItemMeta();
|
||||
assert nextMeta != null;
|
||||
nextMeta.setDisplayName(ChatColor.RED + "Next Page >>");
|
||||
nextPage.setItemMeta(nextMeta);
|
||||
nextPage.setAmount(page+1);
|
||||
return nextPage;
|
||||
}
|
||||
|
||||
private void setBottom(Inventory inventory, int page){
|
||||
ItemStack bottomStack = getBottomStack();
|
||||
ItemStack prevPage = getPrevStack(page);
|
||||
ItemStack currentPage = getCurrentStack(page);
|
||||
ItemStack nextPage = getNextStack(page);
|
||||
for(int i = 18; i < 27; i++){
|
||||
if(i == 21 && page > 1){
|
||||
inventory.setItem(i, prevPage);
|
||||
}else if(i == 22){
|
||||
inventory.setItem(i, currentPage);
|
||||
}else if(i == 23 && colors.size() > getMax(page)){
|
||||
inventory.setItem(i, nextPage);
|
||||
}else{
|
||||
inventory.setItem(i, bottomStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Command
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, @NotNull String[] args) {
|
||||
if(!(sender instanceof Player)){
|
||||
plugin.getLogger().info("This command is for players only!");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
if(p.hasPermission("ultrachat.color")){
|
||||
openGUI(p.getPlayer());
|
||||
openGUI(p.getPlayer(), 1);
|
||||
}
|
||||
else{
|
||||
p.sendMessage(Lang.NO_PERM.toString());
|
||||
@ -194,177 +179,35 @@ public class ColorGUI_Latest implements CommandExecutor, Listener, ColorGUI{
|
||||
if(e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR || !e.getCurrentItem().hasItemMeta()){
|
||||
return;
|
||||
}
|
||||
//================
|
||||
|
||||
int page = Objects.requireNonNull(e.getInventory().getItem(22)).getAmount();
|
||||
|
||||
ItemStack item = e.getCurrentItem();
|
||||
|
||||
if(!e.getInventory().contains(item)) return;
|
||||
|
||||
switch(item.getType()) {
|
||||
case LAPIS_BLOCK:
|
||||
if(p.hasPermission("ultrachat.color.blue")){
|
||||
p.sendMessage(ChatColor.BLUE + "You choose blue color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&9");
|
||||
plugin.saveFile();
|
||||
}
|
||||
else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
case WHITE_WOOL:
|
||||
p.sendMessage(ChatColor.WHITE + "You choose white color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&f");
|
||||
plugin.saveFile();
|
||||
break;
|
||||
case ORANGE_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.gold")){
|
||||
p.sendMessage(ChatColor.GOLD + "You choose gold color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&6");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
|
||||
case MAGENTA_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.magenta")){
|
||||
p.sendMessage(ChatColor.LIGHT_PURPLE + "You choose magenta color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&d");
|
||||
plugin.saveFile();
|
||||
}
|
||||
else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
if(item.equals(getBottomStack()) || item.equals(getCurrentStack(page))) return;
|
||||
if(item.equals(getNextStack(page))){
|
||||
p.closeInventory();
|
||||
openGUI(p, page+1);
|
||||
}else if(item.equals(getPrevStack(page))){
|
||||
p.closeInventory();
|
||||
openGUI(p, page-1);
|
||||
}else{
|
||||
ConfigurationSection section = plugin.chatColorFC.getConfigurationSection("color_gui."
|
||||
+ ChatColor.stripColor(Objects.requireNonNull(item.getItemMeta()).getDisplayName()));
|
||||
|
||||
case LIGHT_BLUE_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.aqua")){
|
||||
p.sendMessage(ChatColor.AQUA + "You choose Aqua color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&b");
|
||||
plugin.saveFile();
|
||||
}
|
||||
else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case YELLOW_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.yellow")){
|
||||
p.sendMessage(ChatColor.YELLOW + "You choose yellow color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&e");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
|
||||
case LIME_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.lightgreen")){
|
||||
p.sendMessage(ChatColor.GREEN + "You choose light green color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&a");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
case PINK_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.lightred")){
|
||||
p.sendMessage(ChatColor.RED + "You choose light red color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&c");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
case GRAY_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.gray")){
|
||||
p.sendMessage(ChatColor.DARK_GRAY + "You choose gray color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&8");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
case LIGHT_GRAY_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.lightgray")){
|
||||
p.sendMessage(ChatColor.GRAY + "You choose light gray color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&7");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
case CYAN_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.cyan")){
|
||||
p.sendMessage(ChatColor.DARK_AQUA + "You choose cyan color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&3");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
case PURPLE_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.purple")){
|
||||
p.sendMessage(ChatColor.DARK_PURPLE + "You choose purple color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&5");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
case BLUE_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.darkblue")){
|
||||
p.sendMessage(ChatColor.DARK_BLUE + "You choose dark blue color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&1");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
case GREEN_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.green")){
|
||||
p.sendMessage(ChatColor.DARK_GREEN + "You choose green color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&2");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
case RED_WOOL:
|
||||
if(p.hasPermission("ultrachat.color.red")){
|
||||
p.sendMessage(ChatColor.DARK_RED + "You choose red color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&4");
|
||||
plugin.saveFile();
|
||||
}else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
break;
|
||||
case GRAY_STAINED_GLASS_PANE:
|
||||
break;
|
||||
default:
|
||||
p.sendMessage(ChatColor.WHITE + "You choose white color chat!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&f");
|
||||
plugin.saveFile();
|
||||
break;
|
||||
assert section != null;
|
||||
if(!p.hasPermission(Objects.requireNonNull(section.getString("permission")))){
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission to use this chat color!");
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.data.set(p.getUniqueId() + ".color", section.getString("color"));
|
||||
plugin.saveFile();
|
||||
|
||||
p.spigot().sendMessage(TextComponent.fromLegacyText(plugin.chatColorUtil.translateChatColor(section.getString("color") + Lang.CHAT_COLOR_CHANGE)));
|
||||
|
||||
p.closeInventory();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,7 @@
|
||||
package me.ryandw11.ultrachat.util;
|
||||
|
||||
import me.ryandw11.ultrachat.UltraChat;
|
||||
import me.ryandw11.ultrachat.formatting.PlayerFormatting;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.tuple.Pair;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.SortedMap;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
/**
|
||||
* This is a utility class to make chat easier.
|
||||
@ -26,18 +18,7 @@ public class ChatUtil {
|
||||
return UltraChat.plugin.chatColorUtil.translateChatColor(message);
|
||||
}
|
||||
|
||||
public static String translateColorCodes(Player p, String message){
|
||||
return UltraChat.plugin.chatColorUtil.translateChatColor(p, message);
|
||||
}
|
||||
|
||||
public static ComponentBuilder translateColorCodesChat(String message, PlayerFormatting pf){
|
||||
Map<String, String> result = UltraChat.plugin.chatColorUtil.splitColors(message, pf);
|
||||
ComponentBuilder builder = new ComponentBuilder();
|
||||
for(Map.Entry<String, String> s : result.entrySet()){
|
||||
TextComponent textComponent = new TextComponent(s.getKey());
|
||||
textComponent.setColor(UltraChat.plugin.chatColorUtil.translateChatCode(s.getValue()));
|
||||
builder.append(textComponent);
|
||||
}
|
||||
return builder;
|
||||
public static ChatColor translateColorCode(String code){
|
||||
return UltraChat.plugin.chatColorUtil.translateChatCode(code);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user