2019-07-29 01:34:38 +02:00
|
|
|
package me.ryandw11.ultrachat.formatting;
|
|
|
|
|
2020-06-25 11:47:08 +02:00
|
|
|
import java.util.Objects;
|
2019-07-29 01:34:38 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2020-06-26 04:13:07 +02:00
|
|
|
import me.ryandw11.ultrachat.util.ChatUtil;
|
2019-07-29 01:34:38 +02:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.OfflinePlayer;
|
|
|
|
|
|
|
|
import me.ryandw11.ultrachat.UltraChat;
|
2019-07-31 07:31:48 +02:00
|
|
|
import me.ryandw11.ultrachat.api.ChatType;
|
|
|
|
import me.ryandw11.ultrachat.api.UltraChatAPI;
|
|
|
|
import me.ryandw11.ultrachat.api.channels.ChatChannel;
|
2019-07-29 01:34:38 +02:00
|
|
|
import net.md_5.bungee.api.ChatColor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @author Ryandw11
|
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public class UUIDFormating {
|
|
|
|
|
|
|
|
private UltraChat plugin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the formatting for an offline player.
|
|
|
|
* @param ud The UUID for the player.
|
|
|
|
* @param world The world the plugin grabs the prefixes for.
|
|
|
|
*/
|
|
|
|
public UUIDFormating(UUID ud, String world){
|
|
|
|
plugin = UltraChat.plugin;
|
|
|
|
|
|
|
|
OfflinePlayer op = Bukkit.getOfflinePlayer(ud);
|
|
|
|
|
2020-06-25 11:47:08 +02:00
|
|
|
color = Objects.requireNonNull(plugin.data.getString(ud + ".color"));
|
2019-07-31 07:31:48 +02:00
|
|
|
try {
|
2020-06-26 12:20:54 +02:00
|
|
|
prefix = ChatUtil.translateColorCodes( plugin.chat.getPlayerPrefix(world, op));
|
|
|
|
suffix = ChatUtil.translateColorCodes( plugin.chat.getPlayerSuffix(world, op));
|
2019-07-31 07:31:48 +02:00
|
|
|
}
|
|
|
|
catch(NullPointerException ex) {
|
|
|
|
prefix = plugin.chat.getPlayerPrefix(world, op);
|
|
|
|
suffix = plugin.chat.getPlayerSuffix(world, op);
|
|
|
|
}
|
2020-06-26 12:20:54 +02:00
|
|
|
formatOp = ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.Op_Chat")));
|
|
|
|
defaults = ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("Custom_Chat.Default_Chat")));
|
|
|
|
global = ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("Global.format")));
|
|
|
|
this.world = ChatUtil.translateColorCodes( Objects.requireNonNull(plugin.getConfig().getString("World.format")));
|
|
|
|
local = ChatUtil.translateColorCodes(Objects.requireNonNull(plugin.getConfig().getString("Local.format")));
|
2019-07-31 07:31:48 +02:00
|
|
|
this.op = op;
|
|
|
|
worldName = world;
|
2019-07-29 01:34:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private String prefix;
|
|
|
|
private String suffix;
|
|
|
|
public String color;
|
|
|
|
private String formatOp;
|
|
|
|
private String defaults;
|
|
|
|
private String global;
|
|
|
|
private String world;
|
|
|
|
private String local;
|
2019-07-31 07:31:48 +02:00
|
|
|
private OfflinePlayer op;
|
|
|
|
private String worldName;
|
2019-07-29 01:34:38 +02:00
|
|
|
|
|
|
|
public String getGlobal(){
|
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getWorld(){
|
|
|
|
return world;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLocal(){
|
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPrefix(){
|
|
|
|
return prefix;
|
|
|
|
}
|
|
|
|
public String getSuffix(){
|
|
|
|
return suffix;
|
|
|
|
}
|
|
|
|
public ChatColor getColor(){
|
2020-06-26 04:13:07 +02:00
|
|
|
return ChatUtil.translateColorCode(color);
|
2019-07-29 01:34:38 +02:00
|
|
|
}
|
|
|
|
public String getOpFormat(){
|
|
|
|
return formatOp;
|
|
|
|
}
|
|
|
|
public String getDefaultFormat(){
|
|
|
|
return defaults;
|
|
|
|
}
|
|
|
|
|
2020-06-26 12:20:54 +02:00
|
|
|
public String getCustomFormat(String key) {
|
|
|
|
return plugin.getConfig().getString("Custom_Chat.permission_format." + key + ".format");
|
2019-07-29 01:34:38 +02:00
|
|
|
}
|
2019-07-31 07:31:48 +02:00
|
|
|
|
|
|
|
public OfflinePlayer getOfflinePlayer() {
|
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the active format for a player.
|
|
|
|
* @return The active format
|
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public String getActiveFormat() {
|
|
|
|
UltraChatAPI uapi = new UltraChatAPI();
|
|
|
|
if(uapi.getChatType() == ChatType.NORMAL) {
|
|
|
|
if(op.isOp()) return this.getOpFormat();
|
2020-06-25 11:47:08 +02:00
|
|
|
|
2020-06-26 12:20:54 +02:00
|
|
|
for (String key : Objects.requireNonNull(plugin.getConfig().getConfigurationSection("Custom_Chat.permission_format")).getKeys(false)) {
|
|
|
|
String permission = plugin.getConfig().getString("Custom_Chat.permission_format." + key + ".permission");
|
|
|
|
assert permission != null;
|
2020-06-25 11:47:08 +02:00
|
|
|
if (plugin.perms.playerHas(worldName, op, plugin.getConfig().getString(permission))) {
|
2020-06-26 12:20:54 +02:00
|
|
|
return this.getCustomFormat(key);
|
2019-07-31 07:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this.getDefaultFormat();
|
|
|
|
}
|
|
|
|
else if(uapi.getChatType() == ChatType.CHANNEL) {
|
|
|
|
ChatChannel cc = uapi.getPlayerCurrentChannel(op.getUniqueId());
|
|
|
|
return cc.getFormat();
|
|
|
|
}
|
|
|
|
else if(uapi.getChatType() == ChatType.RANGE) {
|
|
|
|
return plugin.getConfig().getString("Local.format");
|
|
|
|
}
|
|
|
|
|
|
|
|
return "ERROR: COULD NOT GET ACTIVE TYPE";
|
|
|
|
}
|
2019-07-29 01:34:38 +02:00
|
|
|
|
|
|
|
}
|