Skip to content

Commit

Permalink
2.0.11 - fixed /togglechat & placeholders through %tab_placeholder_<p…
Browse files Browse the repository at this point in the history
…laceholder>%
  • Loading branch information
Tanguygab committed May 10, 2024
1 parent 1627409 commit 3e43bfb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'io.github.tanguygab'
version = '2.0.10'
version = '2.0.11'

compileJava.options.encoding = 'UTF-8'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -62,6 +62,7 @@ public class Chat extends TabFeature implements UnLoadable, JoinListener, Comman
private final boolean toggleCmd;
private List<UUID> toggled;
private PlayerPlaceholderImpl toggleChatPlaceholder;
public final List<PlayerPlaceholderImpl> placeholders = new ArrayList<>();

private final boolean ignoreCmd;
private final Map<UUID,List<UUID>> ignored = new HashMap<>();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e43bfb

Please sign in to comment.