diff --git a/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeePlatform.java b/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeePlatform.java index 44398b9..11275e5 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeePlatform.java +++ b/src/main/java/io/github/tanguygab/tabadditions/bungee/BungeePlatform.java @@ -94,12 +94,11 @@ public BungeeAudiences getKyori() { @Override @SuppressWarnings("UnstableApiUsage") - public void sendToDiscord(TabPlayer player, String msg, String channel, boolean viewCondition, List plugins) { + public void sendToDiscord(TabPlayer player, String msg, String channel, List plugins) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF(String.join(",",plugins)); out.writeUTF(msg); out.writeUTF(channel); - out.writeUTF(viewCondition+""); ((ProxiedPlayer)player.getPlayer()).sendData("tabadditions:channel",out.toByteArray()); } diff --git a/src/main/java/io/github/tanguygab/tabadditions/shared/Platform.java b/src/main/java/io/github/tanguygab/tabadditions/shared/Platform.java index 1771071..5f7decb 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/shared/Platform.java +++ b/src/main/java/io/github/tanguygab/tabadditions/shared/Platform.java @@ -21,7 +21,7 @@ public abstract class Platform { public abstract void sendActionbar(TabPlayer p, String text); public abstract AudienceProvider getKyori(); - public abstract void sendToDiscord(TabPlayer player, String msg, String channel, boolean viewCondition, List plugins); + public abstract void sendToDiscord(TabPlayer player, String msg, String channel, List plugins); public abstract boolean supportsChatSuggestions(); public abstract void updateChatComplete(TabPlayer p, List emojis, boolean add); public abstract ChatItem getItem(TabPlayer p, boolean offhand); diff --git a/src/main/java/io/github/tanguygab/tabadditions/shared/features/advancedconditions/AdvancedConditions.java b/src/main/java/io/github/tanguygab/tabadditions/shared/features/advancedconditions/AdvancedConditions.java index dceff20..b65145b 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/shared/features/advancedconditions/AdvancedConditions.java +++ b/src/main/java/io/github/tanguygab/tabadditions/shared/features/advancedconditions/AdvancedConditions.java @@ -32,7 +32,7 @@ public class AdvancedConditions { put("-|", line -> new StringCondition(line.split("-|"), String::endsWith)::isMet); put("!=", line -> new StringCondition(line.split("!="), (left, right) -> !left.equals(right))::isMet); put("=", line -> new StringCondition(line.split("="), String::equals)::isMet); - put("permission:", line -> (viewer,target) -> target.hasPermission(line.split(":")[1])); + put("permission:", line -> (viewer,target) -> viewer == null || viewer.hasPermission(line.split(":")[1])); }}; /** Name of this condition defined in configuration */ 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 ab82199..77b04aa 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 @@ -282,16 +282,15 @@ else if (commandsManager.contains(sender)) for (TabPlayer viewer : tab.getOnlinePlayers()) { if (socialSpyManager != null) socialSpyManager.process(sender,viewer,message,socialSpyManager.isSpying(sender,viewer,format)); - if (canSee(sender,viewer,format)) { - sendMessage(viewer, createMessage(sender, viewer, message, text)); - if (!chatPlaceholderRelational) continue; - String placeholderMsg = legacySerializer.serialize(createMessage(sender,viewer,message,chatPlaceholderFormat)); - relChatPlaceholder.updateValue(viewer, sender, placeholderMsg); - TAB.getInstance().getCPUManager().runTaskLater(chatPlaceholderStay, featureName, "update %rel_chat% for "+viewer.getName()+" and "+ sender.getName(), () -> { - if (relChatPlaceholder.getLastValue(viewer,sender).equals(placeholderMsg)) - relChatPlaceholder.updateValue(viewer,sender, ""); - }); - } + if (!canSee(sender,viewer,format)) continue; + sendMessage(viewer, createMessage(sender, viewer, message, text)); + if (!chatPlaceholderRelational) continue; + String placeholderMsg = legacySerializer.serialize(createMessage(sender,viewer,message,chatPlaceholderFormat)); + relChatPlaceholder.updateValue(viewer, sender, placeholderMsg); + TAB.getInstance().getCPUManager().runTaskLater(chatPlaceholderStay, featureName, "update %rel_chat% for "+viewer.getName()+" and "+ sender.getName(), () -> { + if (relChatPlaceholder.getLastValue(viewer,sender).equals(placeholderMsg)) + relChatPlaceholder.updateValue(viewer,sender, ""); + }); } List discord = new ArrayList<>(2); @@ -299,11 +298,7 @@ else if (commandsManager.contains(sender)) if (discordEssX) discord.add("EssentialsX"); if (discord.isEmpty()) return; String msgToDiscord = plainTextSerializer.serialize(createMessage(sender,null,message,discordFormat)); - if (canSee(sender,null,format)) - plugin.getPlatform().sendToDiscord(sender,msgToDiscord,format.getChannel(),false,discord); - else if (getFormat(sender).isViewConditionMet(sender,null)) - plugin.getPlatform().sendToDiscord(sender,msgToDiscord,format.getChannel(),true,discord); - + if (!format.hasViewCondition()) plugin.getPlatform().sendToDiscord(sender,msgToDiscord,format.getChannel(),discord); } public void sendMessage(TabPlayer player, Component component) { diff --git a/src/main/java/io/github/tanguygab/tabadditions/spigot/SpigotPlatform.java b/src/main/java/io/github/tanguygab/tabadditions/spigot/SpigotPlatform.java index 7921336..a56c0e9 100644 --- a/src/main/java/io/github/tanguygab/tabadditions/spigot/SpigotPlatform.java +++ b/src/main/java/io/github/tanguygab/tabadditions/spigot/SpigotPlatform.java @@ -121,17 +121,16 @@ public BukkitAudiences getKyori() { } @Override - public void sendToDiscord(TabPlayer player, String msg, String channel, boolean viewCondition, List plugins) { + public void sendToDiscord(TabPlayer player, String msg, String channel, List plugins) { Player p = (Player) player.getPlayer(); - if (plugins.contains("DiscordSRV") && isPluginEnabled("DiscordSRV")) sendDiscordSRV(p,msg,channel,viewCondition); - if (plugins.contains("EssentialsX") && isPluginEnabled("EssentialsDiscord") && !viewCondition) sendEssentialsX(p,msg); + if (plugins.contains("DiscordSRV") && isPluginEnabled("DiscordSRV")) sendDiscordSRV(p,msg,channel); + if (plugins.contains("EssentialsX") && isPluginEnabled("EssentialsDiscord") && !channel.equals("")) sendEssentialsX(p,msg); } - private void sendDiscordSRV(Player p, String msg, String channel, boolean viewCondition) { + private void sendDiscordSRV(Player p, String msg, String channel) { DiscordSRV discord = DiscordSRV.getPlugin(); - if (!viewCondition) - discord.processChatMessage(p, msg, discord.getMainChatChannel(), false); - else if (!discord.getOptionalChannel(channel).equals(discord.getMainChatChannel())) - discord.processChatMessage(p, msg, discord.getOptionalChannel(channel),false); + String mainChannel = discord.getMainChatChannel(); + String optionalChannel = discord.getOptionalChannel(channel); + discord.processChatMessage(p, msg, msg.equals("") || optionalChannel.equals(mainChannel) ? mainChannel : optionalChannel, false); } private void sendEssentialsX(Player p, String msg) { DiscordService api = plugin.getServer().getServicesManager().load(DiscordService.class);