diff --git a/build.gradle b/build.gradle index 4dab700..7a464a6 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'io.github.tanguygab' -version = '2.0.10' +version = '2.0.11' compileJava.options.encoding = 'UTF-8' diff --git a/src/main/java/io/github/tanguygab/tabadditions/shared/TABAdditions.java b/src/main/java/io/github/tanguygab/tabadditions/shared/TABAdditions.java index 39496b6..5b2cfc2 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/shared/TABAdditions.java +++ b/src/main/java/io/github/tanguygab/tabadditions/shared/TABAdditions.java @@ -124,13 +124,11 @@ private void onPlaceholderRegister(TabPlaceholderRegisterEvent e) { PlaceholderManagerImpl pm = tab.getPlaceholderManager(); if (identifier.startsWith("%rel_viewer:")) { Placeholder placeholder = pm.getPlaceholder("%" + identifier.substring(12)); - if (placeholder instanceof RelationalPlaceholderImpl) { - RelationalPlaceholderImpl rel = (RelationalPlaceholderImpl) placeholder; + if (placeholder instanceof RelationalPlaceholderImpl rel) { e.setRelationalPlaceholder((viewer, target) -> rel.getLastValue((TabPlayer) target, (TabPlayer) viewer)); return; } - if (placeholder instanceof PlayerPlaceholderImpl) { - PlayerPlaceholderImpl player = (PlayerPlaceholderImpl) placeholder; + if (placeholder instanceof PlayerPlaceholderImpl player) { e.setRelationalPlaceholder((viewer, target) -> player.getLastValue((TabPlayer) viewer)); } return; diff --git a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/Chat.java b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/Chat.java index 4caf5b9..d957094 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/Chat.java +++ b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/Chat.java @@ -11,10 +11,11 @@ import lombok.Getter; import me.leoko.advancedban.manager.PunishmentManager; import me.leoko.advancedban.manager.UUIDManager; -import me.neznamy.tab.api.placeholder.PlaceholderManager; import me.neznamy.tab.shared.TAB; import me.neznamy.tab.shared.config.file.ConfigurationFile; +import me.neznamy.tab.shared.features.PlaceholderManagerImpl; import me.neznamy.tab.shared.features.types.*; +import me.neznamy.tab.shared.placeholders.expansion.TabExpansion; import me.neznamy.tab.shared.placeholders.types.PlayerPlaceholderImpl; import me.neznamy.tab.shared.placeholders.types.RelationalPlaceholderImpl; import me.neznamy.tab.shared.platform.TabPlayer; @@ -30,11 +31,10 @@ import java.util.*; import java.util.stream.Collectors; -public class Chat extends TabFeature implements UnLoadable, JoinListener, CommandListener, Refreshable { +public class Chat extends TabFeature implements UnLoadable, JoinListener, Refreshable { @Getter private final String featureName = "Chat"; @Getter private final String refreshDisplayName = "&aChat&r"; - @Getter private final String command = "/togglechat"; private final TABAdditions plugin = TABAdditions.getInstance(); private final TAB tab = TAB.getInstance(); public final MiniMessage mm = MiniMessage.miniMessage(); @@ -62,6 +62,7 @@ public class Chat extends TabFeature implements UnLoadable, JoinListener, Comman private final boolean toggleCmd; private List toggled; private PlayerPlaceholderImpl toggleChatPlaceholder; + public final List placeholders = new ArrayList<>(); private final boolean ignoreCmd; private final Map> ignored = new HashMap<>(); @@ -95,8 +96,8 @@ public Chat(ConfigurationFile config) { channel == null ? "" : channel, ChatUtils.componentsToMM(display))); }); - PlaceholderManager pm = tab.getPlaceholderManager(); - pm.registerPlayerPlaceholder("%chat-format%",1000,p->getFormat((TabPlayer) p).getDisplayName()); + PlaceholderManagerImpl pm = tab.getPlaceholderManager(); + placeholders.add(pm.registerPlayerPlaceholder("%chat-format%",1000,p->getFormat((TabPlayer) p).getDisplayName())); emojiManager = config.getBoolean("emojis.enabled",false) ? new EmojiManager(this, @@ -145,7 +146,8 @@ public Chat(ConfigurationFile config) { toggleCmd = config.getBoolean("/togglechat",true); if (toggleCmd) { plugin.getPlatform().registerCommand("togglechat"); - toggleChatPlaceholder = tab.getPlaceholderManager().registerPlayerPlaceholder("%chat-status%",-1,p->hasChatToggled((TabPlayer)p) ? "Off" : "On"); + toggleChatPlaceholder = pm.registerPlayerPlaceholder("%chat-status%",-1,p->hasChatToggled((TabPlayer)p) ? "Off" : "On"); + placeholders.add(toggleChatPlaceholder); toggled = plugin.loadData("chat-off",true); } @@ -166,8 +168,8 @@ public Chat(ConfigurationFile config) { chatPlaceholderFormat = config.getString("chat-placeholder.format","%msg%"); chatPlaceholderRelational = config.getBoolean("chat-placeholder.relational",false); if (chatPlaceholderRelational) - relChatPlaceholder = tab.getPlaceholderManager().registerRelationalPlaceholder("%rel_chat%",-1,(v,t)->""); - else chatPlaceholder = tab.getPlaceholderManager().registerPlayerPlaceholder("%chat%",-1,p->""); + relChatPlaceholder = pm.registerRelationalPlaceholder("%rel_chat%",-1,(v,t)->""); + else placeholders.add(chatPlaceholder = pm.registerPlayerPlaceholder("%chat%",-1,p->"")); chatPlaceholderStay = config.getInt("chat-placeholder.stay",3000); bukkitBridgeChatEnabled = plugin.getPlatform().isProxy() && config.getBoolean("chat-from-bukkit-bridge",false); @@ -179,6 +181,9 @@ private void loadProperties(TabPlayer player) { player.loadPropertyFromConfig(this,"chatprefix"); player.loadPropertyFromConfig(this,"customchatname", player.getName()); player.loadPropertyFromConfig(this,"chatsuffix"); + TabExpansion exp = tab.getPlaceholderManager().getTabExpansion(); + placeholders.forEach(placeholder -> exp.setPlaceholderValue(player,placeholder.getIdentifier(), placeholder.getLastValue(player))); + } @Override @@ -210,7 +215,6 @@ public void onJoin(@NotNull TabPlayer player) { emojiManager.loadAutoComplete(player); } - @Override public boolean onCommand(@NotNull TabPlayer p, @NotNull String cmd) { if (cmd.startsWith("/emojis") || cmd.equals("/toggleemojis")) return emojiManager != null && emojiManager.onCommand(p,cmd); if (cmd.equals("/togglementions")) return mentionManager != null && mentionManager.onCommand(p,cmd); @@ -219,7 +223,7 @@ public boolean onCommand(@NotNull TabPlayer p, @NotNull String cmd) { if (cmd.equals("/socialspy")) return p.hasPermission("tabadditions.chat.socialspy") && socialSpyManager != null && socialSpyManager.onCommand(p,cmd); TranslationFile msgs = plugin.getTranslation(); - if (cmd.equals(command)) return plugin.toggleCmd(toggleCmd,p,toggled,toggleChatPlaceholder,msgs.chatOn,msgs.chatOff,false); + if (cmd.equals("/togglechat")) return plugin.toggleCmd(toggleCmd,p,toggled,toggleChatPlaceholder,msgs.chatOn,msgs.chatOff,false); if (cmd.equals("/clearchat")) { if (!clearchatEnabled || !p.hasPermission("tabadditions.chat.clearchat")) return false; diff --git a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/ChatManager.java b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/ChatManager.java index 17e1588..d17b601 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/ChatManager.java +++ b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/ChatManager.java @@ -35,6 +35,7 @@ public ChatManager(Chat chat, boolean toggleCmd, String data, String cmd, String if (!toggleCmd) return; plugin.getPlatform().registerCommand(cmd); this.placeholder = tab.getPlaceholderManager().registerPlayerPlaceholder("%"+placeholder+"%",-1,p->hasCmdToggled((TabPlayer)p) ? "Off" : "On"); + chat.placeholders.add(this.placeholder); toggled = plugin.loadData(data,true); } diff --git a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/emojis/EmojiManager.java b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/emojis/EmojiManager.java index 9e6d0ef..5df9149 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/emojis/EmojiManager.java +++ b/src/main/java/io/github/tanguygab/tabadditions/shared/features/chat/emojis/EmojiManager.java @@ -42,9 +42,8 @@ public EmojiManager(Chat chat, String emojiOutput, boolean untranslateEmojis, bo if (!hasCmdToggled(p)) loadAutoComplete(p); - PlaceholderManager pm = tab.getPlaceholderManager(); - pm.registerServerPlaceholder("%chat-emoji-total%",-1, ()->String.valueOf(totalEmojiCount)); - pm.registerPlayerPlaceholder("%chat-emoji-owned%",5000,p->String.valueOf(ownedEmojis((TabPlayer) p))); + tab.getPlaceholderManager().registerServerPlaceholder("%chat-emoji-total%",-1, ()->String.valueOf(totalEmojiCount)); + chat.placeholders.add(tab.getPlaceholderManager().registerPlayerPlaceholder("%chat-emoji-owned%",5000,p->String.valueOf(ownedEmojis((TabPlayer) p)))); } @Override