Skip to content

Commit

Permalink
fixed view-conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanguygab committed Jun 25, 2023
1 parent 6678753 commit 8611676
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ public BungeeAudiences getKyori() {

@Override
@SuppressWarnings("UnstableApiUsage")
public void sendToDiscord(TabPlayer player, String msg, String channel, boolean viewCondition, List<String> plugins) {
public void sendToDiscord(TabPlayer player, String msg, String channel, List<String> 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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> plugins);
public abstract void sendToDiscord(TabPlayer player, String msg, String channel, List<String> plugins);
public abstract boolean supportsChatSuggestions();
public abstract void updateChatComplete(TabPlayer p, List<String> emojis, boolean add);
public abstract ChatItem getItem(TabPlayer p, boolean offhand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,28 +282,23 @@ 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<String> discord = new ArrayList<>(2);
if (discordSRV) discord.add("DiscordSRV");
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,16 @@ public BukkitAudiences getKyori() {
}

@Override
public void sendToDiscord(TabPlayer player, String msg, String channel, boolean viewCondition, List<String> plugins) {
public void sendToDiscord(TabPlayer player, String msg, String channel, List<String> 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);
Expand Down

0 comments on commit 8611676

Please sign in to comment.