mirror of
https://github.com/ryandw11/UltraChat.git
synced 2024-11-25 03:35:24 +01:00
Started work on the 1.16 update.
This commit is contained in:
parent
29ab38ca4b
commit
b9dcfaf3d9
15
.classpath
15
.classpath
@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="lib" path="D:/Spigot Development Dependencies/Vault.jar"/>
|
||||
<classpathentry kind="lib" path="D:/Spigot Development Dependencies/Spigot 1.10/PlaceholderAPI (1).jar"/>
|
||||
<classpathentry kind="lib" path="D:/Spigot Development Dependencies/1.12/AdvancedBan-2.1.4-RELEASE.jar"/>
|
||||
<classpathentry kind="lib" path="D:/Spigot Development Dependencies/1.12/EssentialsX-2.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="D:/Spigot Development Dependencies/Spigot 1.13.2/spigot-1.13.2.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -10,6 +10,12 @@
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
|
||||
# Intellij Files
|
||||
.idea/
|
||||
bin/
|
||||
*.iml
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
|
17
.project
17
.project
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>UltraChat</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
1
bin/.gitignore
vendored
1
bin/.gitignore
vendored
@ -1 +0,0 @@
|
||||
/me/
|
88
src/chatcolor.yml
Normal file
88
src/chatcolor.yml
Normal file
@ -0,0 +1,88 @@
|
||||
###############################################
|
||||
# Chat Color #
|
||||
###############################################
|
||||
chat_colors:
|
||||
'&0': 'default'
|
||||
'&1': 'default'
|
||||
'&2': 'default'
|
||||
'&3': 'default'
|
||||
'&4': 'default'
|
||||
'&5': 'default'
|
||||
'&6': 'default'
|
||||
'&7': 'default'
|
||||
'&8': 'default'
|
||||
'&9': 'default'
|
||||
'&a': 'default'
|
||||
'&b': 'default'
|
||||
'&c': 'default'
|
||||
'&d': 'default'
|
||||
'&e': 'default'
|
||||
|
||||
###############################################
|
||||
# Chat Color GUI #
|
||||
###############################################
|
||||
color_gui:
|
||||
'Dark Blue':
|
||||
color: '&1'
|
||||
item: 'BLUE_WOOL'
|
||||
permission: 'ultrachat.chatcolor.darkblue'
|
||||
'Green':
|
||||
color: '&2'
|
||||
item: 'GREEN_WOOL'
|
||||
permission: 'ultrachat.chatcolor.green'
|
||||
'Cyan':
|
||||
color: '&3'
|
||||
item: 'CYAN_WOOL'
|
||||
permission: 'ultrachat.chatcolor.cyan'
|
||||
'Red':
|
||||
color: '&4'
|
||||
item: 'RED_WOOL'
|
||||
permission: 'ultrachat.chatcolor.red'
|
||||
'Purple':
|
||||
color: '&5'
|
||||
item: 'PURPLE_WOOL'
|
||||
permission: 'ultrachat.chatcolor.purple'
|
||||
'Orange':
|
||||
color: '&6'
|
||||
item: 'ORANGE_WOOL'
|
||||
permission: 'ultrachat.chatcolor.orange'
|
||||
'Light Gray':
|
||||
color: '&7'
|
||||
item: 'LIGHT_GRAY_WOOL'
|
||||
permission: 'ultrachat.chatcolor.lightgray'
|
||||
'Gray':
|
||||
color: '&8'
|
||||
item: 'GRAY_WOOL'
|
||||
permission: 'ultrachat.chatcolor.gray'
|
||||
'Blue':
|
||||
color: '&9'
|
||||
item: 'LAPIS_BLOCK'
|
||||
permission: 'ultrachat.chatcolor.blue'
|
||||
'Lime':
|
||||
color: '&a'
|
||||
item: 'LIME_WOOL'
|
||||
permission: 'ultrachat.chatcolor.lime'
|
||||
'Light Blue':
|
||||
color: '&b'
|
||||
item: 'BLUE_WOOL'
|
||||
permission: 'ultrachat.chatcolor.lightblue'
|
||||
'Pink':
|
||||
color: '&c'
|
||||
item: 'PINK_WOOL'
|
||||
permission: 'ultrachat.chatcolor.pink'
|
||||
'Magenta':
|
||||
color: '&d'
|
||||
item: 'MAGENTA_WOOL'
|
||||
permission: 'ultrachat.chatcolor.magenta'
|
||||
'Yellow':
|
||||
color: '&e'
|
||||
item: 'YELLOW_WOOL'
|
||||
permission: 'ultrachat.chatcolor.yellow'
|
||||
'White':
|
||||
color: '&f'
|
||||
item: 'WHITE_WOOL'
|
||||
permission: 'ultrachat.chatcolor.white'
|
||||
'Black':
|
||||
color: '&0'
|
||||
item: 'BLACK_WOOL'
|
||||
permission: 'ultrachat.chatcolor.black'
|
@ -58,8 +58,6 @@ Leave_Message: '&e%player% has left the server!'
|
||||
#############################################
|
||||
# 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:
|
||||
@ -103,36 +101,14 @@ console_log: false
|
||||
########################
|
||||
# If you give a player the '*' permission they will have every single custom chat.
|
||||
# When json is enabled the message is sent several times based on the number of custom formats you have!
|
||||
# To advoid this give them the permission -(yourpermission). Ex: -ultrachat.chat.1
|
||||
# To avoid this give them the permission -(yourpermission). Ex: -ultrachat.chat.1
|
||||
Custom_Chat:
|
||||
#The Chat_Count number must represent how many custom chats you have.
|
||||
Chat_Count: 5
|
||||
#Each new custom chat must be a single number and all of them must go 1 - (what ever number you have last). There can't be any numbers skipped.
|
||||
1:
|
||||
#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: '{normal_chat} &7>> '
|
||||
2:
|
||||
Permission: 'ultrachat.chat.2'
|
||||
Format: '{normal_chat} &7>> '
|
||||
3:
|
||||
Permission: 'ultrachat.chat.3'
|
||||
Format: '{normal_chat} &7>> '
|
||||
4:
|
||||
Permission: 'ultrachat.chat.4'
|
||||
#If components are not enabled then you would put this.
|
||||
Format: '%prefix% %player% %suffix%&7>> '
|
||||
5:
|
||||
Permission: 'ultrachat.chat.5'
|
||||
Format: '%prefix% %player% %suffix%&7>> '
|
||||
#For any player opped.
|
||||
Op_Chat:
|
||||
#The format.
|
||||
Format: '{normal_chat} &c>> '
|
||||
permission_format:
|
||||
'ultrachat.chat.example': '{normal_chat} &7>>'
|
||||
#For any player oped.
|
||||
Op_Chat: '{normal_chat} &c>> '
|
||||
#The default chat when a player does not have a custom one.
|
||||
Default_Chat:
|
||||
Format: '{normal_chat} &7>>'
|
||||
Default_Chat: '{normal_chat} &7>>'
|
||||
|
||||
##############################################
|
||||
# Channels #
|
@ -1,14 +1,20 @@
|
||||
package me.ryandw11.ultrachat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import me.ryandw11.ultrachat.api.ChatType;
|
||||
import me.ryandw11.ultrachat.api.Lang;
|
||||
import me.ryandw11.ultrachat.api.managers.AddonManager;
|
||||
import me.ryandw11.ultrachat.chatcolor.ChatColorManager;
|
||||
import me.ryandw11.ultrachat.chatcolor.ChatColorUtil_Latest;
|
||||
import me.ryandw11.ultrachat.chatcolor.ChatColorUtil_Old;
|
||||
import me.ryandw11.ultrachat.chatcolor.ChatColorUtils;
|
||||
import me.ryandw11.ultrachat.commands.ChannelCmd;
|
||||
import me.ryandw11.ultrachat.commands.ChatCommand;
|
||||
import me.ryandw11.ultrachat.commands.CommandTabCompleter;
|
||||
@ -18,20 +24,13 @@ 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.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;
|
||||
import me.ryandw11.ultrachat.gui.ColorGUI_Outdated;
|
||||
import me.ryandw11.ultrachat.gui.*;
|
||||
import me.ryandw11.ultrachat.listner.ConsoleLogChat;
|
||||
import me.ryandw11.ultrachat.listner.JoinListner;
|
||||
import me.ryandw11.ultrachat.listner.NoSwear;
|
||||
import me.ryandw11.ultrachat.listner.Notify;
|
||||
import me.ryandw11.ultrachat.listner.Notify_1_12;
|
||||
import me.ryandw11.ultrachat.listner.Spy;
|
||||
import me.ryandw11.ultrachat.listner.StopChat;
|
||||
import me.ryandw11.ultrachat.pluginhooks.AdvancedBanMute;
|
||||
@ -49,153 +48,142 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
* Main Class
|
||||
*
|
||||
* @author Ryandw11
|
||||
* @version 2.4
|
||||
* Updated for 1.14.
|
||||
* (Very few API methods here)
|
||||
*/
|
||||
public class UltraChat extends JavaPlugin{
|
||||
public class UltraChat extends JavaPlugin {
|
||||
|
||||
public static UltraChat plugin;
|
||||
public Permission perms = null;
|
||||
public Chat chat = null;
|
||||
public Boolean Vault;
|
||||
public Boolean chatStop = false;
|
||||
public Boolean channelEnabled = false;
|
||||
public Boolean JSON = false;
|
||||
public ChatType md;
|
||||
public String defaultChannel;
|
||||
public ArrayList<UUID> stafftoggle = new ArrayList<>();
|
||||
public ArrayList<UUID> spytoggle = new ArrayList<>();
|
||||
/**
|
||||
* 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 PlaceHolderAPIHook papi;
|
||||
public static UltraChat plugin;
|
||||
public Permission perms = null;
|
||||
public Chat chat = null;
|
||||
public Boolean chatStop = false;
|
||||
public ChatType md;
|
||||
public ArrayList<UUID> stafftoggle = new ArrayList<>();
|
||||
public ArrayList<UUID> spytoggle = new ArrayList<>();
|
||||
|
||||
public File datafile = new File(getDataFolder() + "/data/players.yml");
|
||||
public FileConfiguration data = YamlConfiguration.loadConfiguration(datafile);
|
||||
public File channelfile;
|
||||
public FileConfiguration channel;
|
||||
public String prefix;
|
||||
public static YamlConfiguration LANG;
|
||||
public static File LANG_FILE;
|
||||
public PlaceHolderAPIHook papi;
|
||||
|
||||
private ColorGUI colorGUI;
|
||||
public AddonManager addonManager;
|
||||
public File datafile = new File(getDataFolder() + "/data/players.yml");
|
||||
public FileConfiguration data = YamlConfiguration.loadConfiguration(datafile);
|
||||
public File channelfile;
|
||||
public FileConfiguration channel;
|
||||
|
||||
public File chatColorFile = new File(getDataFolder() + "/chatcolor.yml");
|
||||
public FileConfiguration chatColorFC = YamlConfiguration.loadConfiguration(chatColorFile);
|
||||
|
||||
public String prefix;
|
||||
public static YamlConfiguration LANG;
|
||||
public static File LANG_FILE;
|
||||
|
||||
private ColorGUI colorGUI;
|
||||
public ChatColorManager chatColorManager;
|
||||
public AddonManager addonManager;
|
||||
public ChatColorUtils chatColorUtil;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable(){
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
|
||||
/*
|
||||
* Plugin setup area
|
||||
*/
|
||||
plugin = this;
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null && !setupChat()) {
|
||||
getLogger().info(String.format("[%s] - Vault is not found!", getDescription().getName()));
|
||||
getLogger().severe("§cWarning: You do not have Vault installed! This plugin is now disabled!");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
getLogger().info("Hooked into PlaceholderAPI! You can use the place holders!");
|
||||
papi = new PAPIEnabled();
|
||||
}else {
|
||||
papi = new PAPIDisabled();
|
||||
}
|
||||
getLogger().info(String.format("UltraChat is enabled and running fine! V: %s", getDescription().getVersion()));
|
||||
if(getServer().getPluginManager().getPlugin("AdvancedBan") != null && getConfig().getBoolean("pluginhooks.AdvancedBan")){
|
||||
getLogger().info("AdvancedBan detected! Activating hook!");
|
||||
getLogger().info("Mutes will now work with the chat types.");
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new AdvancedBanMute(), this);
|
||||
}
|
||||
if(getServer().getPluginManager().getPlugin("Essentials") != null && getConfig().getBoolean("pluginhooks.Essentials")){
|
||||
getLogger().info("Essentials detected! Activating hook!");
|
||||
getLogger().info("Mutes will now work with the chat types.");
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new EssentialsMute(), this);
|
||||
}
|
||||
loadMethod();
|
||||
registerConfig();
|
||||
loadFile();
|
||||
loadChannel();
|
||||
/*
|
||||
* Plugin setup area
|
||||
*/
|
||||
plugin = this;
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null && !setupChat()) {
|
||||
getLogger().info(String.format("[%s] - Vault is not found!", getDescription().getName()));
|
||||
getLogger().severe("§cWarning: You do not have Vault installed! This plugin is now disabled!");
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||
getLogger().info("Hooked into PlaceholderAPI! You can use the place holders!");
|
||||
papi = new PAPIEnabled();
|
||||
} else {
|
||||
papi = new PAPIDisabled();
|
||||
}
|
||||
getLogger().info(String.format("UltraChat is enabled and running fine! V: %s", getDescription().getVersion()));
|
||||
if (getServer().getPluginManager().getPlugin("AdvancedBan") != null && getConfig().getBoolean("pluginhooks.AdvancedBan")) {
|
||||
getLogger().info("AdvancedBan detected! Activating hook!");
|
||||
getLogger().info("Mutes will now work with the chat types.");
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new AdvancedBanMute(), this);
|
||||
}
|
||||
if (getServer().getPluginManager().getPlugin("Essentials") != null && getConfig().getBoolean("pluginhooks.Essentials")) {
|
||||
getLogger().info("Essentials detected! Activating hook!");
|
||||
getLogger().info("Mutes will now work with the chat types.");
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new EssentialsMute(), this);
|
||||
}
|
||||
loadFile();
|
||||
loadMethod();
|
||||
registerConfig();
|
||||
loadChannel();
|
||||
|
||||
setupPermissions();
|
||||
setupChat();
|
||||
setupFormatting();
|
||||
loadLang();
|
||||
if(plugin.getConfig().getBoolean("bstats")){
|
||||
@SuppressWarnings("unused")
|
||||
Metrics m = new Metrics(this);
|
||||
}
|
||||
addonManager = new AddonManager();
|
||||
}
|
||||
setupPermissions();
|
||||
setupChat();
|
||||
setupFormatting();
|
||||
loadLang();
|
||||
if (plugin.getConfig().getBoolean("bstats")) {
|
||||
@SuppressWarnings("unused")
|
||||
Metrics m = new Metrics(this);
|
||||
}
|
||||
addonManager = new AddonManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(){
|
||||
getLogger().info("[UltraChat] has been disabled correctly!");
|
||||
saveFile();
|
||||
saveChannel();
|
||||
}
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info("[UltraChat] has been disabled correctly!");
|
||||
saveFile();
|
||||
saveChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the chat formatting.
|
||||
*/
|
||||
public void setupFormatting(){
|
||||
String type = getConfig().getString("chat_format");
|
||||
if(type.equals("")){
|
||||
getLogger().info("UltraChat will not format the chat. To change this go into the config.");
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Setup the chat formatting.
|
||||
*/
|
||||
public void setupFormatting() {
|
||||
String type = getConfig().getString("chat_format");
|
||||
if (type.equals("")) {
|
||||
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 "channel":
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new ChannelJSON(), this);
|
||||
md = ChatType.CHANNEL;
|
||||
getLogger().info("Channel chat mode enabled.");
|
||||
break;
|
||||
case "range":
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new RangeJSON(), 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 = ChatType.RANGE;
|
||||
break;
|
||||
default:
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new NormalJSON(), this);
|
||||
md = ChatType.NORMAL;
|
||||
getLogger().info("Normal chat mode activated!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(type.toLowerCase()){
|
||||
case "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 "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 "range":
|
||||
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 = ChatType.RANGE;
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
}
|
||||
}
|
||||
//Vault set-up =========================================================
|
||||
|
||||
//Vault set-up =========================================================
|
||||
|
||||
private boolean setupChat() {
|
||||
RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
|
||||
chat = rsp.getProvider();
|
||||
return chat != null;
|
||||
}
|
||||
private boolean setupChat() {
|
||||
RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
|
||||
chat = rsp.getProvider();
|
||||
return chat != null;
|
||||
}
|
||||
|
||||
private boolean setupPermissions() {
|
||||
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
|
||||
@ -203,202 +191,214 @@ public class UltraChat extends JavaPlugin{
|
||||
return perms != null;
|
||||
}
|
||||
//========================================================================= END ===============================
|
||||
|
||||
/**
|
||||
* Save the data file.
|
||||
*/
|
||||
public void saveFile(){
|
||||
public void saveFile() {
|
||||
try {
|
||||
data.save(datafile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
try{
|
||||
data.save(datafile);
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* load the data file
|
||||
*/
|
||||
public void loadFile() {
|
||||
if (datafile.exists()) {
|
||||
try {
|
||||
data.load(datafile);
|
||||
|
||||
}
|
||||
/**
|
||||
* load the data file
|
||||
*/
|
||||
public void loadFile(){
|
||||
if(datafile.exists()){
|
||||
try {
|
||||
data.load(datafile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
data.save(datafile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else{
|
||||
try {
|
||||
data.save(datafile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Save the channel file.
|
||||
*/
|
||||
public void saveChannel(){
|
||||
if (chatColorFile.exists()) {
|
||||
try {
|
||||
chatColorFC.load(chatColorFile);
|
||||
|
||||
try{
|
||||
channel.save(channelfile);
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
saveResource("chatcolor.yml", false);
|
||||
chatColorFC = YamlConfiguration.loadConfiguration(chatColorFile);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Save the channel file.
|
||||
*/
|
||||
public void saveChannel() {
|
||||
|
||||
/**
|
||||
* Load the cannel file.
|
||||
*/
|
||||
public void loadChannel(){
|
||||
channelfile = new File(getDataFolder(), "channel.yml");
|
||||
if (!channelfile.exists()) {
|
||||
channelfile.getParentFile().mkdirs();
|
||||
saveResource("channel.yml", false);
|
||||
}
|
||||
channel = new YamlConfiguration();
|
||||
try {
|
||||
channel.load(channelfile);
|
||||
try {
|
||||
channel.save(channelfile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
}
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the language file.
|
||||
* @return The language file.
|
||||
*/
|
||||
public File getLangFile() {
|
||||
return LANG_FILE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public YamlConfiguration getLang() {
|
||||
return LANG;
|
||||
}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("static-access")
|
||||
public void loadLang() {
|
||||
File lang = new File(getDataFolder(), "lang.yml");
|
||||
if (!lang.exists()) {
|
||||
try {
|
||||
getDataFolder().mkdir();
|
||||
lang.createNewFile();
|
||||
InputStream defConfigStream = this.getResource("lang.yml");
|
||||
if (defConfigStream != null) {
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream));
|
||||
/**
|
||||
* Load the cannel file.
|
||||
*/
|
||||
public void loadChannel() {
|
||||
channelfile = new File(getDataFolder(), "channel.yml");
|
||||
if (!channelfile.exists()) {
|
||||
channelfile.getParentFile().mkdirs();
|
||||
saveResource("channel.yml", false);
|
||||
}
|
||||
channel = new YamlConfiguration();
|
||||
try {
|
||||
channel.load(channelfile);
|
||||
|
||||
defConfig.save(lang);
|
||||
Lang.setFile(defConfig);
|
||||
return;
|
||||
}
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace(); // So they notice
|
||||
getLogger().severe("The language file could not be created. Disabling plugin.");
|
||||
this.setEnabled(false);
|
||||
}
|
||||
}
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
|
||||
for(Lang item:Lang.values()) {
|
||||
if (conf.getString(item.getPath()) == null) {
|
||||
conf.set(item.getPath(), item.getDefault());
|
||||
}
|
||||
}
|
||||
Lang.setFile(conf);
|
||||
this.LANG = conf;
|
||||
this.LANG_FILE = lang;
|
||||
try {
|
||||
conf.save(getLangFile());
|
||||
} catch(IOException e) {
|
||||
getLogger().warning( "Failed to save lang.yml.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the language file.
|
||||
*
|
||||
* @return The language file.
|
||||
*/
|
||||
public File getLangFile() {
|
||||
return LANG_FILE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public YamlConfiguration getLang() {
|
||||
return LANG;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("static-access")
|
||||
public void loadLang() {
|
||||
File lang = new File(getDataFolder(), "lang.yml");
|
||||
if (!lang.exists()) {
|
||||
try {
|
||||
getDataFolder().mkdir();
|
||||
lang.createNewFile();
|
||||
InputStream defConfigStream = this.getResource("lang.yml");
|
||||
if (defConfigStream != null) {
|
||||
YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(defConfigStream));
|
||||
|
||||
defConfig.save(lang);
|
||||
Lang.setFile(defConfig);
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); // So they notice
|
||||
getLogger().severe("The language file could not be created. Disabling plugin.");
|
||||
this.setEnabled(false);
|
||||
}
|
||||
}
|
||||
YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
|
||||
for (Lang item : Lang.values()) {
|
||||
if (conf.getString(item.getPath()) == null) {
|
||||
conf.set(item.getPath(), item.getDefault());
|
||||
}
|
||||
}
|
||||
Lang.setFile(conf);
|
||||
this.LANG = conf;
|
||||
this.LANG_FILE = lang;
|
||||
try {
|
||||
conf.save(getLangFile());
|
||||
} catch (IOException e) {
|
||||
getLogger().warning("Failed to save lang.yml.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void registerConfig() {
|
||||
saveDefaultConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all of the Events and Commands.
|
||||
*/
|
||||
public void loadMethod() {
|
||||
getCommand("chat").setExecutor(new ChatCommand());
|
||||
getCommand("chat").setTabCompleter(new CommandTabCompleter());
|
||||
getCommand("sc").setExecutor(new StaffChat());
|
||||
getCommand("sctoggle").setExecutor(new StaffChatToggle());
|
||||
getCommand("spy").setExecutor(new SpyCommand());
|
||||
getCommand("channel").setExecutor(new ChannelCmd());
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new StopChat(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new NoSwear(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new Spy(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new JoinListner(), this);
|
||||
//Bukkit.getServer().getPluginManager().registerEvents(new Format(this), this);
|
||||
if (getConfig().getBoolean("console_log"))
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new ConsoleLogChat(), this);
|
||||
loadVersions();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void registerConfig() {
|
||||
saveDefaultConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads all of the Events and Commands.
|
||||
*/
|
||||
public void loadMethod(){
|
||||
getCommand("chat").setExecutor(new ChatCommand());
|
||||
getCommand("chat").setTabCompleter(new CommandTabCompleter());
|
||||
getCommand("sc").setExecutor(new StaffChat());
|
||||
getCommand("sctoggle").setExecutor(new StaffChatToggle());
|
||||
getCommand("spy").setExecutor(new SpyCommand());
|
||||
getCommand("channel").setExecutor(new ChannelCmd());
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new StopChat(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new NoSwear(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new Spy(), this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new JoinListner(), this);
|
||||
//Bukkit.getServer().getPluginManager().registerEvents(new Format(this), this);
|
||||
if(getConfig().getBoolean("console_log"))
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new ConsoleLogChat(), this);
|
||||
loadVersions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads classes based upon the server version.
|
||||
*/
|
||||
private void loadVersions() {
|
||||
String version;
|
||||
/**
|
||||
* Loads classes based upon the server version.
|
||||
*/
|
||||
private void loadVersions() {
|
||||
String version;
|
||||
|
||||
try {
|
||||
|
||||
version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
|
||||
} catch (ArrayIndexOutOfBoundsException w0w) {
|
||||
version = " ";
|
||||
version = " ";
|
||||
}
|
||||
if (version.equals("v1_13_R2") || version.equals("v1_14_R1") || version.equals("v1_15_R1")) {
|
||||
if (version.equals("v1_14_R1") || version.equals("v1_15_R1")) {
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new Notify(), this);
|
||||
if(version.equals("v1_13_R2")) {
|
||||
colorGUI = new ColorGUI_1_13_R2();
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new ColorGUI_1_13_R2(), this);
|
||||
if(!(plugin.getConfig().getBoolean("ChatColor_Command")))
|
||||
getCommand("color").setExecutor(new ColorGUI_1_13_R2());
|
||||
}else {
|
||||
colorGUI = new ColorGUI_Latest();
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new ColorGUI_Latest(), this);
|
||||
if(!(plugin.getConfig().getBoolean("ChatColor_Command")))
|
||||
getCommand("color").setExecutor(new ColorGUI_Latest());
|
||||
}
|
||||
}else {
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new Notify_1_12(), this);
|
||||
colorGUI = new ColorGUI_Outdated();
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new ColorGUI_Outdated(), this);
|
||||
if(!(plugin.getConfig().getBoolean("ChatColor_Command")))
|
||||
getCommand("color").setExecutor(new ColorGUI_Outdated());
|
||||
getLogger().info("1.12 or below version detected. Activating compatibility mode.");
|
||||
colorGUI = new ColorGUI_1_15_R1();
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new ColorGUI_Latest(), this);
|
||||
if (!(plugin.getConfig().getBoolean("ChatColor_Command")))
|
||||
getCommand("color").setExecutor(new ColorGUI_1_15_R1());
|
||||
|
||||
this.chatColorUtil = new ChatColorUtil_Old();
|
||||
|
||||
} else {
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new Notify(), this);
|
||||
colorGUI = new ColorGUI_Latest();
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new ColorGUI_Latest(), this);
|
||||
|
||||
chatColorManager = new ChatColorManager(this, Objects.requireNonNull(chatColorFC.getConfigurationSection("chat_colors")));
|
||||
|
||||
if (!(plugin.getConfig().getBoolean("ChatColor_Command")))
|
||||
getCommand("color").setExecutor(new ColorGUI_Latest());
|
||||
|
||||
this.chatColorUtil = new ChatColorUtil_Latest(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ColorGUI class for the right version.
|
||||
* @return A class that implements ColorGUI
|
||||
*/
|
||||
public ColorGUI getColorGUI() {
|
||||
return colorGUI;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ColorGUI class for the right version.
|
||||
*
|
||||
* @return A class that implements ColorGUI
|
||||
*/
|
||||
public ColorGUI getColorGUI() {
|
||||
return colorGUI;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
49
src/me/ryandw11/ultrachat/chatcolor/ChatColorManager.java
Normal file
49
src/me/ryandw11/ultrachat/chatcolor/ChatColorManager.java
Normal file
@ -0,0 +1,49 @@
|
||||
package me.ryandw11.ultrachat.chatcolor;
|
||||
|
||||
import me.ryandw11.ultrachat.UltraChat;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This class handles the chatcolor.yml file.
|
||||
*/
|
||||
public class ChatColorManager {
|
||||
private Map<String, ChatColor> colorCodeMap;
|
||||
|
||||
public ChatColorManager(UltraChat plugin, ConfigurationSection section){
|
||||
colorCodeMap = new HashMap<>();
|
||||
for(String s : section.getKeys(false)){
|
||||
String color = Objects.requireNonNull(section.getString(s));
|
||||
if(color.equalsIgnoreCase("default"))
|
||||
colorCodeMap.put(s, ChatColor.getByChar(s.replace("&", "").charAt(0)));
|
||||
else{
|
||||
try{
|
||||
color = color.replace("{", "").replace("}", "");
|
||||
colorCodeMap.put(s, ChatColor.of(color));
|
||||
}catch(IllegalArgumentException ex){
|
||||
plugin.getLogger().warning("Invalid chat color for " + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, ChatColor> getMap(){
|
||||
return colorCodeMap;
|
||||
}
|
||||
|
||||
public String translateMapColors(String message){
|
||||
String finalMessage = message;
|
||||
for(Map.Entry<String, ChatColor> entry : colorCodeMap.entrySet()){
|
||||
finalMessage = finalMessage.replace(entry.getKey(), entry.getValue().toString());
|
||||
}
|
||||
return finalMessage;
|
||||
}
|
||||
|
||||
public ChatColor getChatColor(String s){
|
||||
return colorCodeMap.get(s);
|
||||
}
|
||||
}
|
140
src/me/ryandw11/ultrachat/chatcolor/ChatColorUtil_Latest.java
Normal file
140
src/me/ryandw11/ultrachat/chatcolor/ChatColorUtil_Latest.java
Normal file
@ -0,0 +1,140 @@
|
||||
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 {
|
||||
|
||||
private UltraChat plugin;
|
||||
public ChatColorUtil_Latest(UltraChat plugin){
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translateChatColor(String message) {
|
||||
String finalMessage = translateHexColor(message);
|
||||
finalMessage = plugin.chatColorManager.translateMapColors(finalMessage);
|
||||
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("&")){
|
||||
return plugin.chatColorManager.getChatColor(code);
|
||||
}
|
||||
String hexCode = code.replace("{", "").replace("}", "");
|
||||
try{
|
||||
return ChatColor.of(hexCode);
|
||||
}catch(IllegalArgumentException ex){
|
||||
return ChatColor.RED;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChatCode(String code) {
|
||||
if(code.startsWith("&")){
|
||||
return plugin.chatColorManager.getMap().containsKey(code);
|
||||
}
|
||||
String hexCode = code.replace("{", "").replace("}", "");
|
||||
try{
|
||||
ChatColor.of(hexCode);
|
||||
}catch(IllegalArgumentException ex){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatColor translateChatCode(Player p, String code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static String translateHexColor(String message){
|
||||
if(!message.contains("{"))
|
||||
return message;
|
||||
StringBuilder finalMessage = new StringBuilder();
|
||||
StringBuilder interior = new StringBuilder();
|
||||
boolean readInterior = false;
|
||||
for (int i = 0; i < message.length(); i++){
|
||||
char c = message.charAt(i);
|
||||
if(c == '{' && !readInterior){
|
||||
readInterior = true;
|
||||
}else if(!readInterior){
|
||||
finalMessage.append(c);
|
||||
} else if(c == '{'){
|
||||
finalMessage.append('{');
|
||||
finalMessage.append(interior);
|
||||
interior = new StringBuilder();
|
||||
}else if(c == '}' && interior.toString().contains("#")){
|
||||
readInterior = false;
|
||||
try {
|
||||
finalMessage.append(ChatColor.of(interior.toString()));
|
||||
}catch(IllegalArgumentException ex){
|
||||
finalMessage.append("{");
|
||||
finalMessage.append(interior);
|
||||
finalMessage.append("}");
|
||||
}finally{
|
||||
interior = new StringBuilder();
|
||||
}
|
||||
|
||||
}else if(c == '}'){
|
||||
readInterior = false;
|
||||
finalMessage.append("{");
|
||||
finalMessage.append(interior);
|
||||
finalMessage.append("}");
|
||||
interior = new StringBuilder();
|
||||
}
|
||||
else{
|
||||
interior.append(c);
|
||||
}
|
||||
}
|
||||
if(interior.toString().length() > 0){
|
||||
finalMessage.append('{');
|
||||
finalMessage.append(interior);
|
||||
}
|
||||
return finalMessage.toString();
|
||||
}
|
||||
}
|
43
src/me/ryandw11/ultrachat/chatcolor/ChatColorUtil_Old.java
Normal file
43
src/me/ryandw11/ultrachat/chatcolor/ChatColorUtil_Old.java
Normal file
@ -0,0 +1,43 @@
|
||||
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;
|
||||
|
||||
public class ChatColorUtil_Old implements ChatColorUtils {
|
||||
|
||||
@Override
|
||||
public String translateChatColor(String message) {
|
||||
return ChatColor.translateAlternateColorCodes('&', message);
|
||||
}
|
||||
|
||||
@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) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChatCode(String code) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.md_5.bungee.api.ChatColor translateChatCode(Player p, String message) {
|
||||
return null;
|
||||
}
|
||||
}
|
19
src/me/ryandw11/ultrachat/chatcolor/ChatColorUtils.java
Normal file
19
src/me/ryandw11/ultrachat/chatcolor/ChatColorUtils.java
Normal file
@ -0,0 +1,19 @@
|
||||
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);
|
||||
}
|
@ -1,10 +1,13 @@
|
||||
package me.ryandw11.ultrachat.formatting;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
@ -20,7 +23,7 @@ import net.md_5.bungee.api.chat.TextComponent;
|
||||
/**
|
||||
* Handles channels with components enabled.
|
||||
* @author Ryandw11
|
||||
* @since 2.4
|
||||
* @since 2.5
|
||||
*
|
||||
*/
|
||||
public class ChannelJSON implements Listener {
|
||||
@ -30,53 +33,54 @@ public class ChannelJSON implements Listener {
|
||||
this.plugin = UltraChat.plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
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<Player>(Bukkit.getOnlinePlayers()), ChatType.CHANNEL, cp);
|
||||
UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet<>(e.getRecipients()), ChatType.CHANNEL, cp);
|
||||
Bukkit.getServer().getPluginManager().callEvent(uce);
|
||||
// Remove recipients from main events to prevent double messages.
|
||||
e.getRecipients().clear();
|
||||
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"))
|
||||
if(pl.hasPermission(Objects.requireNonNull(plugin.channel.getString(channel + ".permission"))) || Objects.requireNonNull(plugin.channel.getString(channel + ".permission")).equalsIgnoreCase("none")){
|
||||
String format = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.channel.getString(channel + ".prefix")))
|
||||
+ ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(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);
|
||||
cb.append(JComponentManager.formatComponents(format, p));
|
||||
cb.append(ChatUtil.translateColorCodesChat(uce.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet<Player>(Bukkit.getOnlinePlayers()), ChatType.CHANNEL, cp);
|
||||
UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet<>(e.getRecipients()), ChatType.CHANNEL, cp);
|
||||
Bukkit.getServer().getPluginManager().callEvent(uce);
|
||||
e.getRecipients().clear();
|
||||
if(!uce.isCancelled())
|
||||
for(Player pl : uce.getRecipients()){
|
||||
String form = ChatColor.translateAlternateColorCodes('&', plugin.channel.getString(channel + ".prefix"))
|
||||
+ ChatColor.translateAlternateColorCodes('&', plugin.channel.getString(channel + ".format"))
|
||||
String formats = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.channel.getString(channel + ".prefix")))
|
||||
+ ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(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);
|
||||
cb.append(JComponentManager.formatComponents(formats, p));
|
||||
cb.append(ChatUtil.translateColorCodesChat(uce.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
}
|
||||
}
|
||||
|
@ -1,64 +0,0 @@
|
||||
package me.ryandw11.ultrachat.formatting;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
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
|
||||
*
|
||||
*/
|
||||
public class Channels implements Listener {
|
||||
private UltraChat plugin;
|
||||
public Channels(){
|
||||
plugin = UltraChat.plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e){
|
||||
PlayerFormatting pf = new PlayerFormatting(e.getPlayer());
|
||||
Player p = e.getPlayer();
|
||||
|
||||
String channel = plugin.data.getString(p.getUniqueId() + ".channel");
|
||||
if(!plugin.channel.getBoolean(channel + ".always_appear")){
|
||||
e.getRecipients().removeAll(Bukkit.getOnlinePlayers());
|
||||
if(p.hasPermission("ultrachat.chat.color")){
|
||||
e.setMessage(ChatColor.translateAlternateColorCodes('&', e.getMessage()));
|
||||
}
|
||||
for(Player pl : Bukkit.getOnlinePlayers()){
|
||||
if(plugin.data.getString(pl.getUniqueId() + ".channel").equals(channel)){
|
||||
if(pl.hasPermission(plugin.channel.getString(channel + ".permission")) || plugin.channel.getString(channel + ".permission").equalsIgnoreCase("none")){
|
||||
e.getRecipients().add(pl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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")));
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
package me.ryandw11.ultrachat.formatting;
|
||||
|
||||
import java.util.UnknownFormatConversionException;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
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
|
||||
*
|
||||
*/
|
||||
public class Normal implements Listener {
|
||||
private UltraChat plugin;
|
||||
public Normal(){
|
||||
plugin = UltraChat.plugin;
|
||||
}
|
||||
|
||||
@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() && p.hasPermission("ultrachat.formatting.op")){
|
||||
try{
|
||||
e.setFormat(pf.getOpFormat().replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace("%player%", "%s") + pf.getColor() + "%s");
|
||||
}catch (UnknownFormatConversionException ex){
|
||||
p.sendMessage(ChatColor.RED + "A fatal error has occured. Check the console for more info!");
|
||||
Bukkit.getLogger().warning(ChatColor.RED + "A fatal error has occured!");
|
||||
Bukkit.getLogger().warning(ChatColor.RED + "Your formatting seems to be a bit off! Check the config.yml Fortmat: OP");
|
||||
}
|
||||
}else{
|
||||
int i = 1;
|
||||
while(i <= plugin.getConfig().getInt("Custom_Chat.Chat_Count")){
|
||||
if(p.hasPermission(plugin.getConfig().getString("Custom_Chat." + i + ".Permission"))){
|
||||
try{
|
||||
e.setFormat(PlaceholderAPI.setPlaceholders(p, ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Custom_Chat." + i +".Format").replace("%player%", "%s").replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix())) + pf.getColor() + "%s"));
|
||||
}catch (UnknownFormatConversionException ex){
|
||||
p.sendMessage(ChatColor.RED + "A fatal error has occured. Contact an administrator!");
|
||||
Bukkit.getLogger().warning(ChatColor.RED + "A fatal error has occured!");
|
||||
Bukkit.getLogger().warning(ChatColor.RED + "Your formatting seems to be a bit off! Check the config.yml Fortmat #: " + i);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
try{
|
||||
e.setFormat(pf.getDefaultFormat().replace("%prefix%", pf.getPrefix()).replace("%suffix%", pf.getSuffix()).replace("%player%", "%s") + pf.getColor() + "%s");
|
||||
}catch(UnknownFormatConversionException ex){
|
||||
p.sendMessage(ChatColor.RED + "A fatal error has occured. Contact an administrator!");
|
||||
Bukkit.getLogger().warning(ChatColor.RED + "A fatal error has occured!");
|
||||
Bukkit.getLogger().warning(ChatColor.RED + "Your formatting seems to be a bit off! Check the config.yml Fortmat: Defualt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,15 @@
|
||||
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;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
@ -19,7 +24,7 @@ import net.md_5.bungee.api.chat.TextComponent;
|
||||
/**
|
||||
* Handles the Normal Chat when in JSON mode.
|
||||
* @author Ryandw11
|
||||
* @since 2.4
|
||||
* @since 2.5
|
||||
*
|
||||
*/
|
||||
public class NormalJSON implements Listener {
|
||||
@ -30,39 +35,40 @@ public class NormalJSON implements Listener {
|
||||
this.plugin = UltraChat.plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
e.setCancelled(true);
|
||||
PlayerFormatting pf = new PlayerFormatting(p);
|
||||
|
||||
// Call the UltraChatEvent (This is an optional Event).
|
||||
NormalProperties np = new NormalProperties(true);
|
||||
UltraChatEvent event = new UltraChatEvent(p, e.getMessage(), new HashSet<Player>(Bukkit.getOnlinePlayers()), ChatType.NORMAL, np);
|
||||
UltraChatEvent event = new UltraChatEvent(p, e.getMessage(), new HashSet<Player>(e.getRecipients()), ChatType.NORMAL, np);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (p.isOp() && p.hasPermission("ultrachat.formatting.op")) {
|
||||
|
||||
//Remove all players from the normal event.
|
||||
e.getRecipients().clear();
|
||||
|
||||
if (p.isOp()) {
|
||||
String formats = pf.getOpFormat()
|
||||
.replace("%prefix%", pf.getPrefix())
|
||||
.replace("%suffix%", pf.getSuffix())
|
||||
.replace("%player%", p.getDisplayName())
|
||||
+ pf.getColor();
|
||||
.replace("%player%", p.getDisplayName());
|
||||
|
||||
for (Player pl : event.getRecipients()) {
|
||||
ComponentBuilder cb = new ComponentBuilder("");
|
||||
cb.append(JComponentManager.formatComponents(formats, p));
|
||||
TextComponent tc = new TextComponent(event.getMessage());
|
||||
cb.append(tc);
|
||||
cb.append(ChatUtil.translateColorCodesChat(event.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
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)
|
||||
for (String permission : Objects.requireNonNull(plugin.getConfig().getConfigurationSection("Custom_Chat.permission_format")).getKeys(false)) {
|
||||
if (p.hasPermission(permission)) {
|
||||
String formats = pf.getCustomFormat(permission)
|
||||
.replace("%prefix%", pf.getPrefix())
|
||||
.replace("%suffix%", pf.getSuffix())
|
||||
.replace("%player%", p.getDisplayName())
|
||||
@ -71,16 +77,11 @@ public class NormalJSON implements Listener {
|
||||
for (Player pl : event.getRecipients()) {
|
||||
ComponentBuilder cb = new ComponentBuilder("");
|
||||
cb.append(JComponentManager.formatComponents(formats, p));
|
||||
TextComponent tc = new TextComponent(event.getMessage());
|
||||
cb.append(tc);
|
||||
cb.append(ChatUtil.translateColorCodesChat(event.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
complete = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (complete)
|
||||
return;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -94,8 +95,7 @@ public class NormalJSON implements Listener {
|
||||
for (Player pl : event.getRecipients()) {
|
||||
ComponentBuilder cb = new ComponentBuilder("");
|
||||
cb.append(JComponentManager.formatComponents(formats, p));
|
||||
TextComponent tc = new TextComponent(event.getMessage());
|
||||
cb.append(tc);
|
||||
cb.append(ChatUtil.translateColorCodesChat(event.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,9 @@ 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;
|
||||
|
||||
/**
|
||||
* Class for formatting player chat easily.
|
||||
* @author Ryandw11
|
||||
@ -20,14 +23,14 @@ public class PlayerFormatting {
|
||||
public PlayerFormatting(Player p){
|
||||
plugin = UltraChat.plugin;
|
||||
|
||||
color = ChatColor.translateAlternateColorCodes('&', plugin.data.getString(p.getUniqueId() + ".color"));
|
||||
color = plugin.data.getString(p.getUniqueId() + ".color");
|
||||
prefix = ChatColor.translateAlternateColorCodes('&', plugin.chat.getPlayerPrefix(p));
|
||||
suffix = ChatColor.translateAlternateColorCodes('&', plugin.chat.getPlayerSuffix(p));
|
||||
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);
|
||||
formatOp = plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.Op_Chat"))), p);
|
||||
defaults = plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.Default_Chat"))), p);
|
||||
global = plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Global.format"))), p);
|
||||
world = plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("World.format"))), p);
|
||||
local = plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Local.format"))), p);
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
@ -69,8 +72,8 @@ public class PlayerFormatting {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
public String getCustomFormat(int num) {
|
||||
return plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Custom_Chat." + num + ".Format")), p);
|
||||
public String getCustomFormat(String name) {
|
||||
return plugin.papi.translatePlaceholders(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.permission_format." + name))), p);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,74 +0,0 @@
|
||||
package me.ryandw11.ultrachat.formatting;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.UnknownFormatConversionException;
|
||||
|
||||
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;
|
||||
|
||||
public class Range implements Listener {
|
||||
private UltraChat plugin;
|
||||
|
||||
public Range() {
|
||||
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);
|
||||
|
||||
RangeProperties rp = new RangeProperties(false, RangeType.LOCAL);
|
||||
UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet<Player>(Bukkit.getOnlinePlayers()), ChatType.RANGE, rp);
|
||||
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());
|
||||
|
||||
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<Player> getNearbyPlayers(Player pl) {
|
||||
ArrayList<Player> nearby = new ArrayList<Player>();
|
||||
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;
|
||||
}
|
||||
}
|
@ -3,11 +3,13 @@ package me.ryandw11.ultrachat.formatting;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import me.ryandw11.ultrachat.util.ChatUtil;
|
||||
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.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
@ -28,35 +30,31 @@ public class RangeJSON implements Listener {
|
||||
this.plugin = UltraChat.plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
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<Player>(e.getRecipients()), ChatType.RANGE, rp);
|
||||
UltraChatEvent uce = new UltraChatEvent(p, e.getMessage(), new HashSet<>(e.getRecipients()), ChatType.RANGE, rp);
|
||||
Bukkit.getServer().getPluginManager().callEvent(uce);
|
||||
e.getRecipients().clear();
|
||||
if (!uce.isCancelled()) {
|
||||
for (Player pl : uce.getRecipients()) {
|
||||
|
||||
String form = pf.getLocal()
|
||||
String formats = 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);
|
||||
cb.append(JComponentManager.formatComponents(formats, p));
|
||||
cb.append(ChatUtil.translateColorCodesChat(uce.getMessage(), pf).create(), ComponentBuilder.FormatRetention.NONE);
|
||||
pl.spigot().sendMessage(cb.create());
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.ryandw11.ultrachat.formatting;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -31,7 +32,7 @@ private UltraChat plugin;
|
||||
|
||||
OfflinePlayer op = Bukkit.getOfflinePlayer(ud);
|
||||
|
||||
color = ChatColor.translateAlternateColorCodes('&', plugin.data.getString(ud + ".color"));
|
||||
color = Objects.requireNonNull(plugin.data.getString(ud + ".color"));
|
||||
try {
|
||||
prefix = ChatColor.translateAlternateColorCodes('&', plugin.chat.getPlayerPrefix(world, op));
|
||||
suffix = ChatColor.translateAlternateColorCodes('&', plugin.chat.getPlayerSuffix(world, op));
|
||||
@ -40,11 +41,11 @@ private UltraChat plugin;
|
||||
prefix = plugin.chat.getPlayerPrefix(world, op);
|
||||
suffix = 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"));
|
||||
formatOp = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.Op_Chat")));
|
||||
defaults = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.Default_Chat")));
|
||||
global = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Global.format")));
|
||||
this.world = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("World.format")));
|
||||
local = ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(plugin.getConfig().getString("Local.format")));
|
||||
this.op = op;
|
||||
worldName = world;
|
||||
}
|
||||
@ -88,8 +89,8 @@ private UltraChat plugin;
|
||||
return defaults;
|
||||
}
|
||||
|
||||
public String getCustomFormat(int num) {
|
||||
return plugin.getConfig().getString("Custom_Chat." + num + ".Format");
|
||||
public String getCustomFormat(String name) {
|
||||
return plugin.getConfig().getString("Custom_Chat.permission_format." + name);
|
||||
}
|
||||
|
||||
public OfflinePlayer getOfflinePlayer() {
|
||||
@ -106,12 +107,10 @@ private UltraChat plugin;
|
||||
if(uapi.getChatType() == ChatType.NORMAL) {
|
||||
if(op.isOp()) return this.getOpFormat();
|
||||
|
||||
int i = 1;
|
||||
while (i <= plugin.getConfig().getInt("Custom_Chat.Chat_Count")) {
|
||||
if (plugin.perms.playerHas(worldName, op, plugin.getConfig().getString("Custom_Chat." + i + ".Permission"))) {
|
||||
return this.getCustomFormat(i);
|
||||
for (String permission : Objects.requireNonNull(plugin.getConfig().getConfigurationSection("Custom_Chat.permission_format")).getKeys(false)) {
|
||||
if (plugin.perms.playerHas(worldName, op, plugin.getConfig().getString(permission))) {
|
||||
return this.getCustomFormat(permission);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return this.getDefaultFormat();
|
||||
}
|
||||
|
@ -7,5 +7,5 @@ import org.bukkit.entity.Player;
|
||||
*
|
||||
*/
|
||||
public interface ColorGUI {
|
||||
public void openGUI(Player p);
|
||||
void openGUI(Player p);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package me.ryandw11.ultrachat.gui;
|
||||
|
||||
import me.ryandw11.ultrachat.UltraChat;
|
||||
import me.ryandw11.ultrachat.api.Lang;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@ -10,27 +12,25 @@ 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;
|
||||
|
||||
import me.ryandw11.ultrachat.UltraChat;
|
||||
import me.ryandw11.ultrachat.api.Lang;
|
||||
|
||||
/**
|
||||
* ColorGUI class.
|
||||
* Updated for 1.13.
|
||||
* Updated for 1.14-1.15
|
||||
* @author Ryandw11
|
||||
*
|
||||
*/
|
||||
public class ColorGUI_1_13_R2 implements CommandExecutor, Listener, ColorGUI{
|
||||
public class ColorGUI_1_15_R1 implements CommandExecutor, Listener, ColorGUI{
|
||||
|
||||
private UltraChat plugin;
|
||||
public ColorGUI_1_13_R2(){
|
||||
public ColorGUI_1_15_R1(){
|
||||
plugin = UltraChat.plugin;
|
||||
}
|
||||
public void openGUI(Player p){
|
||||
Inventory i = Bukkit.createInventory(null, 9*2, Lang.COLOR_GUI.toString());
|
||||
Inventory i = Bukkit.createInventory(null, InventoryType.CHEST, Lang.COLOR_GUI.toString());
|
||||
|
||||
ItemStack darkblueitem = new ItemStack(Material.BLUE_WOOL);
|
||||
ItemMeta darkbluemeta = darkblueitem.getItemMeta();
|
||||
@ -79,52 +79,61 @@ public class ColorGUI_1_13_R2 implements CommandExecutor, Listener, ColorGUI{
|
||||
|
||||
//==========================================================
|
||||
|
||||
darkbluemeta.setDisplayName("§1Dark Blue Color Chat");
|
||||
darkbluemeta.setDisplayName("§1Dark Blue Color Chat");
|
||||
darkblueitem.setItemMeta(darkbluemeta);
|
||||
|
||||
greenmeta.setDisplayName("§2Green Color Chat");
|
||||
greenmeta.setDisplayName("§2Green Color Chat");
|
||||
greenitem.setItemMeta(greenmeta);
|
||||
|
||||
lightbluemeta.setDisplayName("§3Cyan Color Chat");
|
||||
lightbluemeta.setDisplayName("§3Cyan Color Chat");
|
||||
lightblueitem.setItemMeta(lightbluemeta);
|
||||
|
||||
redmeta.setDisplayName("§4Red Color Chat");
|
||||
redmeta.setDisplayName("§4Red Color Chat");
|
||||
reditem.setItemMeta(redmeta);
|
||||
|
||||
purplemeta.setDisplayName("§5Purple Color Chat");
|
||||
purplemeta.setDisplayName("§5Purple Color Chat");
|
||||
purpleitem.setItemMeta(purplemeta);
|
||||
|
||||
goldmeta.setDisplayName("§6Gold Color Chat");
|
||||
goldmeta.setDisplayName("§6Gold Color Chat");
|
||||
golditem.setItemMeta(goldmeta);
|
||||
|
||||
lightgraymeta.setDisplayName("§7Light Gray Color Chat");
|
||||
lightgraymeta.setDisplayName("§7Light Gray Color Chat");
|
||||
lightgrayitem.setItemMeta(lightgraymeta);
|
||||
|
||||
graymeta.setDisplayName("§8Gray Color Chat");
|
||||
graymeta.setDisplayName("§8Gray Color Chat");
|
||||
grayitem.setItemMeta(graymeta);
|
||||
|
||||
bluemeta.setDisplayName("§9Blue Color Chat");
|
||||
bluemeta.setDisplayName("§9Blue Color Chat");
|
||||
blueitem.setItemMeta(bluemeta);
|
||||
|
||||
lightgreenmeta.setDisplayName("§aLight Green Color Chat");
|
||||
lightgreenmeta.setDisplayName("§aLight Green Color Chat");
|
||||
lightgreenitem.setItemMeta(lightgreenmeta);
|
||||
|
||||
aquameta.setDisplayName("§bAqua Color Chat");
|
||||
aquameta.setDisplayName("§bAqua Color Chat");
|
||||
aquaitem.setItemMeta(aquameta);
|
||||
|
||||
lightredmeta.setDisplayName("§cLight Red Color Chat");
|
||||
lightredmeta.setDisplayName("§cLight Red Color Chat");
|
||||
lightreditem.setItemMeta(lightredmeta);
|
||||
|
||||
pinkmeta.setDisplayName("§dMagenta Color Chat");
|
||||
pinkmeta.setDisplayName("§dMagenta Color Chat");
|
||||
pinkitem.setItemMeta(pinkmeta);
|
||||
|
||||
yellowmeta.setDisplayName("§eYellow Color Chat");
|
||||
yellowmeta.setDisplayName("§eYellow Color Chat");
|
||||
yellowitem.setItemMeta(yellowmeta);
|
||||
|
||||
whitemeta.setDisplayName("§fWhite Color Chat");
|
||||
whitemeta.setDisplayName("§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);
|
||||
}
|
||||
|
||||
|
||||
i.setItem(0, darkblueitem);
|
||||
i.setItem(1, greenitem);
|
||||
@ -171,18 +180,24 @@ public class ColorGUI_1_13_R2 implements CommandExecutor, Listener, ColorGUI{
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClickEvent(InventoryClickEvent e){
|
||||
if(!e.getInventory().getTitle().equalsIgnoreCase(Lang.COLOR_GUI.toString())) return;
|
||||
try {
|
||||
if(e.getView() == null || e.getView().getTitle() == null) return;
|
||||
if(!e.getView().getTitle().equalsIgnoreCase(Lang.COLOR_GUI.toString())) return;
|
||||
}catch(IllegalStateException ex) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
e.setCancelled(true);
|
||||
|
||||
if(e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR || !e.getCurrentItem().hasItemMeta()){
|
||||
p.closeInventory();
|
||||
return;
|
||||
}
|
||||
//================
|
||||
ItemStack item = e.getCurrentItem();
|
||||
|
||||
if(!e.getInventory().contains(item)) return;
|
||||
|
||||
switch(item.getType()) {
|
||||
case LAPIS_BLOCK:
|
||||
if(p.hasPermission("ultrachat.color.blue")){
|
||||
@ -341,6 +356,8 @@ public class ColorGUI_1_13_R2 implements CommandExecutor, Listener, ColorGUI{
|
||||
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();
|
@ -20,7 +20,7 @@ import me.ryandw11.ultrachat.api.Lang;
|
||||
|
||||
/**
|
||||
* ColorGUI class.
|
||||
* Updated for 1.14+
|
||||
* Updated for 1.16+
|
||||
* @author Ryandw11
|
||||
*
|
||||
*/
|
||||
@ -80,49 +80,49 @@ public class ColorGUI_Latest implements CommandExecutor, Listener, ColorGUI{
|
||||
|
||||
//==========================================================
|
||||
|
||||
darkbluemeta.setDisplayName("§1Dark Blue Color Chat");
|
||||
darkbluemeta.setDisplayName("<EFBFBD>1Dark Blue Color Chat");
|
||||
darkblueitem.setItemMeta(darkbluemeta);
|
||||
|
||||
greenmeta.setDisplayName("§2Green Color Chat");
|
||||
greenmeta.setDisplayName("<EFBFBD>2Green Color Chat");
|
||||
greenitem.setItemMeta(greenmeta);
|
||||
|
||||
lightbluemeta.setDisplayName("§3Cyan Color Chat");
|
||||
lightbluemeta.setDisplayName("<EFBFBD>3Cyan Color Chat");
|
||||
lightblueitem.setItemMeta(lightbluemeta);
|
||||
|
||||
redmeta.setDisplayName("§4Red Color Chat");
|
||||
redmeta.setDisplayName("<EFBFBD>4Red Color Chat");
|
||||
reditem.setItemMeta(redmeta);
|
||||
|
||||
purplemeta.setDisplayName("§5Purple Color Chat");
|
||||
purplemeta.setDisplayName("<EFBFBD>5Purple Color Chat");
|
||||
purpleitem.setItemMeta(purplemeta);
|
||||
|
||||
goldmeta.setDisplayName("§6Gold Color Chat");
|
||||
goldmeta.setDisplayName("<EFBFBD>6Gold Color Chat");
|
||||
golditem.setItemMeta(goldmeta);
|
||||
|
||||
lightgraymeta.setDisplayName("§7Light Gray Color Chat");
|
||||
lightgraymeta.setDisplayName("<EFBFBD>7Light Gray Color Chat");
|
||||
lightgrayitem.setItemMeta(lightgraymeta);
|
||||
|
||||
graymeta.setDisplayName("§8Gray Color Chat");
|
||||
graymeta.setDisplayName("<EFBFBD>8Gray Color Chat");
|
||||
grayitem.setItemMeta(graymeta);
|
||||
|
||||
bluemeta.setDisplayName("§9Blue Color Chat");
|
||||
bluemeta.setDisplayName("<EFBFBD>9Blue Color Chat");
|
||||
blueitem.setItemMeta(bluemeta);
|
||||
|
||||
lightgreenmeta.setDisplayName("§aLight Green Color Chat");
|
||||
lightgreenmeta.setDisplayName("<EFBFBD>aLight Green Color Chat");
|
||||
lightgreenitem.setItemMeta(lightgreenmeta);
|
||||
|
||||
aquameta.setDisplayName("§bAqua Color Chat");
|
||||
aquameta.setDisplayName("<EFBFBD>bAqua Color Chat");
|
||||
aquaitem.setItemMeta(aquameta);
|
||||
|
||||
lightredmeta.setDisplayName("§cLight Red Color Chat");
|
||||
lightredmeta.setDisplayName("<EFBFBD>cLight Red Color Chat");
|
||||
lightreditem.setItemMeta(lightredmeta);
|
||||
|
||||
pinkmeta.setDisplayName("§dMagenta Color Chat");
|
||||
pinkmeta.setDisplayName("<EFBFBD>dMagenta Color Chat");
|
||||
pinkitem.setItemMeta(pinkmeta);
|
||||
|
||||
yellowmeta.setDisplayName("§eYellow Color Chat");
|
||||
yellowmeta.setDisplayName("<EFBFBD>eYellow Color Chat");
|
||||
yellowitem.setItemMeta(yellowmeta);
|
||||
|
||||
whitemeta.setDisplayName("§fWhite Color Chat");
|
||||
whitemeta.setDisplayName("<EFBFBD>fWhite Color Chat");
|
||||
whiteitem.setItemMeta(whitemeta);
|
||||
//==========================================================
|
||||
|
||||
|
@ -1,371 +0,0 @@
|
||||
package me.ryandw11.ultrachat.gui;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.material.Wool;
|
||||
|
||||
import me.ryandw11.ultrachat.UltraChat;
|
||||
import me.ryandw11.ultrachat.api.Lang;
|
||||
|
||||
/**
|
||||
* ColorGUI class.
|
||||
* Old and outdated. Only in for compatibility.
|
||||
* (When compiling for 1.13+ only it is ok to leave this class out (Just remove references to it in the UltraChat main class))
|
||||
* @author Ryandw11
|
||||
*
|
||||
*/
|
||||
public class ColorGUI_Outdated implements CommandExecutor, Listener, ColorGUI{
|
||||
|
||||
private UltraChat plugin;
|
||||
public ColorGUI_Outdated(){
|
||||
plugin = UltraChat.plugin;
|
||||
}
|
||||
@SuppressWarnings("deprecation")
|
||||
public void openGUI(Player p){
|
||||
Inventory i = Bukkit.createInventory(null, 9*2, Lang.COLOR_GUI.toString());
|
||||
|
||||
Wool darkblue = new Wool(DyeColor.BLUE);
|
||||
ItemStack darkblueitem = darkblue.toItemStack(1);
|
||||
ItemMeta darkbluemeta = darkblueitem.getItemMeta();
|
||||
|
||||
Wool green = new Wool(DyeColor.GREEN);
|
||||
ItemStack greenitem = green.toItemStack(1);
|
||||
ItemMeta greenmeta = greenitem.getItemMeta();
|
||||
|
||||
Wool lightblue = new Wool(DyeColor.CYAN);
|
||||
ItemStack lightblueitem = lightblue.toItemStack(1);
|
||||
ItemMeta lightbluemeta = lightblueitem.getItemMeta();
|
||||
|
||||
Wool red = new Wool(DyeColor.RED);
|
||||
ItemStack reditem = red.toItemStack(1);
|
||||
ItemMeta redmeta = reditem.getItemMeta();
|
||||
|
||||
Wool purple = new Wool(DyeColor.PURPLE);
|
||||
ItemStack purpleitem = purple.toItemStack(1);
|
||||
ItemMeta purplemeta = purpleitem.getItemMeta();
|
||||
|
||||
Wool gold = new Wool(DyeColor.ORANGE);
|
||||
ItemStack golditem = gold.toItemStack(1);
|
||||
ItemMeta goldmeta = golditem.getItemMeta();
|
||||
|
||||
ItemStack lightgrayitem = new ItemStack(Material.CLAY);
|
||||
ItemMeta lightgraymeta = lightgrayitem.getItemMeta();
|
||||
|
||||
Wool gray = new Wool(DyeColor.GRAY);
|
||||
ItemStack grayitem = gray.toItemStack(1);
|
||||
ItemMeta graymeta = grayitem.getItemMeta();
|
||||
|
||||
ItemStack blueitem = new ItemStack(Material.LAPIS_BLOCK);
|
||||
ItemMeta bluemeta = blueitem.getItemMeta();
|
||||
|
||||
Wool lightgreen = new Wool(DyeColor.LIME);
|
||||
ItemStack lightgreenitem = lightgreen.toItemStack(1);
|
||||
ItemMeta lightgreenmeta = lightgreenitem.getItemMeta();
|
||||
|
||||
Wool aqua = new Wool(DyeColor.LIGHT_BLUE);
|
||||
ItemStack aquaitem = aqua.toItemStack(1);
|
||||
ItemMeta aquameta = aquaitem.getItemMeta();
|
||||
|
||||
Wool lightred = new Wool(DyeColor.PINK);
|
||||
ItemStack lightreditem = lightred.toItemStack(1);
|
||||
ItemMeta lightredmeta = lightreditem.getItemMeta();
|
||||
|
||||
Wool pink = new Wool(DyeColor.MAGENTA);
|
||||
ItemStack pinkitem = pink.toItemStack(1);
|
||||
ItemMeta pinkmeta = pinkitem.getItemMeta();
|
||||
|
||||
Wool yellow = new Wool(DyeColor.YELLOW);
|
||||
ItemStack yellowitem = yellow.toItemStack(1);
|
||||
ItemMeta yellowmeta = yellowitem.getItemMeta();
|
||||
|
||||
Wool white = new Wool(DyeColor.WHITE);
|
||||
ItemStack whiteitem = white.toItemStack(1);
|
||||
ItemMeta whitemeta = whiteitem.getItemMeta();
|
||||
|
||||
//==========================================================
|
||||
|
||||
darkbluemeta.setDisplayName("§1Dark Blue Color Chat");
|
||||
darkblueitem.setItemMeta(darkbluemeta);
|
||||
|
||||
greenmeta.setDisplayName("§2Green Color Chat");
|
||||
greenitem.setItemMeta(greenmeta);
|
||||
|
||||
lightbluemeta.setDisplayName("§3Cyan Color Chat");
|
||||
lightblueitem.setItemMeta(lightbluemeta);
|
||||
|
||||
redmeta.setDisplayName("§4Red Color Chat");
|
||||
reditem.setItemMeta(redmeta);
|
||||
|
||||
purplemeta.setDisplayName("§5Purple Color Chat");
|
||||
purpleitem.setItemMeta(purplemeta);
|
||||
|
||||
goldmeta.setDisplayName("§6Gold Color Chat");
|
||||
golditem.setItemMeta(goldmeta);
|
||||
|
||||
lightgraymeta.setDisplayName("§7Light Gray Color Chat");
|
||||
lightgrayitem.setItemMeta(lightgraymeta);
|
||||
|
||||
graymeta.setDisplayName("§8Gray Color Chat");
|
||||
grayitem.setItemMeta(graymeta);
|
||||
|
||||
bluemeta.setDisplayName("§9Blue Color Chat");
|
||||
blueitem.setItemMeta(bluemeta);
|
||||
|
||||
lightgreenmeta.setDisplayName("§aLight Green Color Chat");
|
||||
lightgreenitem.setItemMeta(lightgreenmeta);
|
||||
|
||||
aquameta.setDisplayName("§bAqua Color Chat");
|
||||
aquaitem.setItemMeta(aquameta);
|
||||
|
||||
lightredmeta.setDisplayName("§cLight Red Color Chat");
|
||||
lightreditem.setItemMeta(lightredmeta);
|
||||
|
||||
pinkmeta.setDisplayName("§dMagenta Color Chat");
|
||||
pinkitem.setItemMeta(pinkmeta);
|
||||
|
||||
yellowmeta.setDisplayName("§eYellow Color Chat");
|
||||
yellowitem.setItemMeta(yellowmeta);
|
||||
|
||||
whitemeta.setDisplayName("§fWhite Chat");
|
||||
whiteitem.setItemMeta(whitemeta);
|
||||
//==========================================================
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
/*
|
||||
* Command
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String s, 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());
|
||||
}
|
||||
else{
|
||||
p.sendMessage(Lang.NO_PERM.toString());
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
/*
|
||||
* Event
|
||||
*/
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClickEvent(InventoryClickEvent e){
|
||||
if(!e.getInventory().getName().equalsIgnoreCase(Lang.COLOR_GUI.toString())) return;
|
||||
|
||||
Player p = (Player) e.getWhoClicked();
|
||||
e.setCancelled(true);
|
||||
|
||||
if(e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR || !e.getCurrentItem().hasItemMeta()){
|
||||
p.closeInventory();
|
||||
return;
|
||||
}
|
||||
//================
|
||||
ItemStack item = e.getCurrentItem();
|
||||
@SuppressWarnings("deprecation")
|
||||
int data = item.getDurability();
|
||||
|
||||
if(item.getType() == Material.LAPIS_BLOCK){
|
||||
if(p.hasPermission("ultrachat.color.blue")){
|
||||
p.sendMessage(ChatColor.BLUE + "You choose blue chat color!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&9");
|
||||
plugin.saveFile();
|
||||
}
|
||||
else{
|
||||
p.sendMessage(ChatColor.RED + "You do not have permission for this color!");
|
||||
}
|
||||
}
|
||||
else if(item.getType() == Material.CLAY){
|
||||
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!");
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
switch(data) {
|
||||
case 0:
|
||||
p.sendMessage(ChatColor.WHITE + "You choose white chat color!");
|
||||
p.closeInventory();
|
||||
plugin.data.set(p.getUniqueId() + ".color", "&f");
|
||||
plugin.saveFile();
|
||||
break;
|
||||
case 1:
|
||||
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 2:
|
||||
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;
|
||||
|
||||
|
||||
|
||||
case 3:
|
||||
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 4:
|
||||
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 5:
|
||||
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 6:
|
||||
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 7:
|
||||
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 9:
|
||||
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 10:
|
||||
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 11:
|
||||
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 13:
|
||||
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 14:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
43
src/me/ryandw11/ultrachat/util/ChatUtil.java
Normal file
43
src/me/ryandw11/ultrachat/util/ChatUtil.java
Normal file
@ -0,0 +1,43 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* This is a utility class to make chat easier.
|
||||
*/
|
||||
public class ChatUtil {
|
||||
|
||||
/**
|
||||
* Translates the message into color codes.
|
||||
* <p>This also translates hex color codes: {#FFFFFF}</p>
|
||||
* @param message The message to translate
|
||||
* @return The translated message.
|
||||
*/
|
||||
public static String translateColorCodes(String message){
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user