use of net.sacredlabyrinth.phaed.simpleclans.managers.SettingsManager in project UltimateChat by FabioZumbi12.
the class UCMessages method formatTags.
@SuppressWarnings("deprecation")
public static String formatTags(String tag, String text, Object cmdSender, Object receiver, String msg, UCChannel ch) {
if (receiver instanceof CommandSender && tag.equals("message")) {
text = text.replace("{message}", mention(cmdSender, (CommandSender) receiver, msg));
if (UChat.get().getUCConfig().getBoolean("general.item-hand.enable")) {
text = text.replace(UChat.get().getUCConfig().getString("general.item-hand.placeholder"), formatTags("", ChatColor.translateAlternateColorCodes('&', UChat.get().getUCConfig().getString("general.item-hand.format")), cmdSender, receiver, msg, ch));
}
} else {
text = text.replace("{message}", msg);
}
if (tag.equals("message") && !UChat.get().getUCConfig().getBoolean("general.enable-tags-on-messages")) {
return text;
}
text = text.replace("{ch-color}", ch.getColor()).replace("{ch-name}", ch.getName()).replace("{ch-alias}", ch.getAlias());
if (UChat.get().getUCConfig().getBoolean("jedis.enable") && ch.useJedis()) {
text = text.replace("{jedis-id}", UChat.get().getUCConfig().getString("jedis.server-id"));
}
if (ch.isBungee()) {
text = text.replace("{bungee-id}", UChat.get().getUCConfig().getString("bungee.server-id"));
}
if (cmdSender instanceof CommandSender) {
text = text.replace("{playername}", ((CommandSender) cmdSender).getName());
if (receiver instanceof CommandSender)
text = text.replace("{receivername}", ((CommandSender) receiver).getName());
if (receiver instanceof String)
text = text.replace("{receivername}", (String) receiver);
} else {
text = text.replace("{playername}", (String) cmdSender).replace("{receivername}", (String) receiver);
}
for (String repl : registeredReplacers.keySet()) {
if (registeredReplacers.get(repl).equals(repl)) {
text = text.replace(repl, "");
continue;
}
text = text.replace(repl, registeredReplacers.get(repl));
}
StringBuilder def = new StringBuilder();
for (int i = 0; i < defFormat.length; i++) {
text = text.replace("{default-format-" + i + "}", defFormat[i]);
def.append(" ").append(defFormat[i]);
}
if (def.length() > 0) {
text = text.replace("{default-format-full}", def.substring(1));
}
if (text.contains("{time-now}")) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
text = text.replace("{time-now}", sdf.format(cal.getTime()));
}
if (cmdSender instanceof Player) {
Player sender = (Player) cmdSender;
if (text.contains("{world}")) {
String world = UChat.get().getUCConfig().getString("general.world-names." + sender.getWorld().getName());
text = text.replace("{world}", world != null ? world : sender.getWorld().getName());
}
text = text.replace("{nickname}", sender.getDisplayName());
// replace item hand
text = text.replace(UChat.get().getUCConfig().getString("general.item-hand.placeholder"), ChatColor.translateAlternateColorCodes('&', UChat.get().getUCConfig().getString("general.item-hand.format")));
if (text.contains("{hand-") && !sender.getItemInHand().getType().equals(Material.AIR)) {
ItemStack item = sender.getItemInHand();
text = text.replace("{hand-durability}", String.valueOf(item.getDurability()));
if (item.hasItemMeta()) {
ItemMeta meta = item.getItemMeta();
if (UCUtil.getBukkitVersion() >= 1112 && meta.hasLocalizedName()) {
text = text.replace("{hand-name}", item.getItemMeta().getLocalizedName());
} else if (meta.hasDisplayName()) {
text = text.replace("{hand-name}", item.getItemMeta().getDisplayName());
} else {
text = text.replace("{hand-name}", UCUtil.capitalize(item.getType().toString()));
}
if (meta.hasLore()) {
StringBuilder lorestr = new StringBuilder();
for (String lore : meta.getLore()) {
lorestr.append("\n ").append(lore);
}
if (lorestr.length() >= 2) {
text = text.replace("{hand-lore}", lorestr.toString().substring(0, lorestr.length() - 1));
}
}
if (meta.hasEnchants()) {
StringBuilder str = new StringBuilder();
for (Entry<Enchantment, Integer> enchant : meta.getEnchants().entrySet()) {
str.append("\n ").append(enchant.getKey().getName()).append(": ").append(enchant.getValue());
}
if (str.length() >= 2) {
text = text.replace("{hand-enchants}", str.toString().substring(0, str.length() - 1));
}
}
}
text = text.replace("{hand-amount}", String.valueOf(item.getAmount()));
text = text.replace("{hand-name}", UCUtil.capitalize(item.getType().toString()));
text = text.replace("{hand-type}", UCUtil.capitalize(item.getType().toString()));
} else {
text = text.replace("{hand-name}", UChat.get().getLang().get("chat.emptyslot"));
text = text.replace("{hand-type}", "Air");
}
if (UChat.get().getVaultChat() != null && (text.contains("-prefix") || text.contains("-suffix"))) {
text = text.replace("{group-suffix}", UCVaultCache.getVaultChat(sender).getPlayerSuffix()).replace("{group-prefix}", UCVaultCache.getVaultChat(sender).getPlayerPrefix());
String[] pgs = UCVaultCache.getVaultPerms(sender).getPlayerGroups();
if (pgs.length > 0) {
text = text.replace("{player-groups-prefixes}", UCVaultCache.getVaultChat(sender).getGroupPrefixes()).replace("{player-groups-suffixes}", UCVaultCache.getVaultChat(sender).getGroupSuffixes());
}
}
if (UChat.get().getVaultEco() != null && text.contains("{balance}")) {
text = text.replace("{balance}", "" + UChat.get().getVaultEco().getBalance(sender, sender.getWorld().getName()));
}
if (UChat.get().getVaultPerms() != null && (text.contains("-group}") || text.contains("-groups}"))) {
String[] pgs = UCVaultCache.getVaultPerms(sender).getPlayerGroups();
if (pgs.length > 0) {
StringBuilder groups = new StringBuilder();
for (String g : pgs) {
groups.append(g).append(",");
}
text = text.replace("{player-groups}", groups.toString().substring(0, groups.length() - 1));
}
String primGroup = UCVaultCache.getVaultPerms(sender).getPrimaryGroup();
String group = UChat.get().getUCConfig().getString("general.group-names." + primGroup);
text = text.replace("{prim-group}", group == null ? primGroup : group);
}
if (text.contains("{clan-") && UChat.SClans) {
ClanPlayer cp = UChat.sc.getClanManager().getClanPlayer(sender.getUniqueId());
SettingsManager scm = UChat.sc.getSettingsManager();
if (cp != null) {
String fulltag = scm.getTagBracketColor() + scm.getTagBracketLeft() + scm.getTagDefaultColor() + cp.getClan().getColorTag() + scm.getTagBracketColor() + scm.getTagBracketRight() + scm.getTagSeparatorColor() + scm.getTagSeparator();
text = text.replace("{clan-tag}", cp.getTag()).replace("{clan-fulltag}", fulltag).replace("{clan-name}", checkEmpty(cp.getClan().getName())).replace("{clan-kdr}", "" + cp.getKDR()).replace("{clan-rank}", checkEmpty(cp.getRank())).replace("{clan-totalkdr}", "" + cp.getClan().getTotalKDR()).replace("{clan-deaths}", "" + cp.getDeaths()).replace("{clan-isleader}", "" + cp.isLeader()).replace("{clan-totalkdr}", "" + cp.getClan().getTotalKDR()).replace("{clan-ctag}", cp.getClan().getColorTag());
}
}
if (UChat.Factions) {
text = UCFactionsHook.formatFac(text, sender, receiver);
}
if (text.contains("{marry-")) {
if (UChat.MarryReloded && sender.hasMetadata("marriedTo")) {
String partner = sender.getMetadata("marriedTo").get(0).asString();
String prefix = UChat.mapi.getBukkitConfig("config.yml").getString("chat.status-format");
UChat.mapi.getMPlayer(sender.getUniqueId()).getGender().getChatPrefix();
prefix = prefix.replace("{icon:male}", "♂").replace("{icon:female}", "♀").replace("{icon:genderless}", "⚤").replace("{icon:heart}", "❤");
String gender = UChat.mapi.getMPlayer(sender.getUniqueId()).getGender().getChatPrefix();
gender = gender.replace("{icon:male}", "♂").replace("{icon:female}", "♀").replace("{icon:genderless}", "⚤").replace("{icon:heart}", "❤");
text = text.replace("{marry-partner}", partner).replace("{marry-prefix}", prefix).replace("{marry-suffix}", gender);
}
if (UChat.MarryMaster) {
if (UChat.mm.HasPartner(sender)) {
text = text.replace("{marry-partner}", UChat.mm.DB.GetPartner(sender)).replace("{marry-prefix}", UChat.mm.config.GetPrefix().replace("<heart>", ChatColor.RED + "❤" + ChatColor.WHITE)).replace("{marry-suffix}", UChat.mm.config.GetSuffix().replace("<heart>", ChatColor.RED + "❤" + ChatColor.WHITE));
}
}
}
if (UChat.PlaceHolderAPI) {
if (receiver instanceof Player && UChat.get().isRelation()) {
while (text.contains("%rel_")) {
text = PlaceholderAPI.setRelationalPlaceholders(sender, (Player) receiver, text);
}
}
text = PlaceholderAPI.setPlaceholders(sender, text);
if (tag.equals("message")) {
text = composeColor(sender, text);
}
}
}
if (cmdSender instanceof CommandSender) {
text = text.replace("{nickname}", UChat.get().getUCConfig().getString("general.console-tag").replace("{console}", ((CommandSender) cmdSender).getName()));
} else {
text = text.replace("{nickname}", UChat.get().getUCConfig().getString("general.console-tag").replace("{console}", (String) cmdSender));
}
// colorize tags (not message)
if (!tag.equals("message")) {
text = ChatColor.translateAlternateColorCodes('&', text);
}
// remove blank items
text = text.replaceAll("\\{.*\\}", "");
// remove remain PlaceholderAPI
if (UChat.get().getUCConfig().getBoolean("general.remove-unnused-placeholderapi")) {
text = text.replaceAll("\\%.*\\%", "");
}
if (!tag.equals("message")) {
for (String rpl : UChat.get().getUCConfig().getStringList("general.remove-from-chat")) {
text = text.replace(ChatColor.translateAlternateColorCodes('&', rpl), "");
}
}
if (text.equals(" ") || text.equals(" ")) {
text = "";
}
return text;
}
Aggregations