From c05b8f8e02f00bef1d5aecd5e78ad4f694ce0df7 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 13 Feb 2021 14:52:48 +1300 Subject: [PATCH] Introduce /ld pushing and have it print off potential causes for packet modifiers --- .../commands/libsdisguises/LDScoreboard.java | 82 ++++++++++++++----- 1 file changed, 62 insertions(+), 20 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java index 5b9afc9e..696465cf 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDScoreboard.java @@ -1,12 +1,20 @@ package me.libraryaddict.disguise.commands.libsdisguises; +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.events.PacketListener; import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseConfig; +import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; +import net.minecraft.server.v1_16_R1.Packet; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -19,6 +27,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; /** * Created by libraryaddict on 20/04/2020. @@ -26,7 +35,7 @@ import java.util.Set; public class LDScoreboard implements LDCommand { @Override public List getTabComplete() { - return Arrays.asList("teams", "scoreboard", "board"); + return Arrays.asList("teams", "scoreboard", "board", "pushing"); } @Override @@ -48,8 +57,8 @@ public class LDScoreboard implements LDCommand { if (!((PlayerDisguise) disguise).hasScoreboardName()) { if (unexpected++ < 3) { - sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName() + - " isn't using a scoreboard name? This is unexpected"); + sender.sendMessage( + "The player disguise " + ((PlayerDisguise) disguise).getName() + " isn't using a scoreboard name? This is unexpected"); } continue; } @@ -70,24 +79,20 @@ public class LDScoreboard implements LDCommand { if (team == null) { if (issuesFound++ < 5) { - sender.sendMessage("The player disguise " + - ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') + - " is missing a scoreboard team '" + scoreboardName.getTeamName() + "' on " + - player.getName() + " and possibly more players!"); + sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') + + " is missing a scoreboard team '" + scoreboardName.getTeamName() + "' on " + player.getName() + + " and possibly more players!"); } continue; } if (!team.getPrefix().equals("Colorize") && - (!team.getPrefix().equals(scoreboardName.getPrefix()) || - !team.getSuffix().equals(scoreboardName.getSuffix()))) { + (!team.getPrefix().equals(scoreboardName.getPrefix()) || !team.getSuffix().equals(scoreboardName.getSuffix()))) { if (issuesFound++ < 5) { - sender.sendMessage("The player disguise " + - ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') + - " on scoreboard team '" + scoreboardName.getTeamName() + "' on " + - player.getName() + " has an unexpected prefix/suffix of '" + - team.getPrefix().replace(ChatColor.COLOR_CHAR, '&') + "' & '" + + sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') + + " on scoreboard team '" + scoreboardName.getTeamName() + "' on " + player.getName() + + " has an unexpected prefix/suffix of '" + team.getPrefix().replace(ChatColor.COLOR_CHAR, '&') + "' & '" + team.getSuffix().replace(ChatColor.COLOR_CHAR, '&') + "'! Expected '" + scoreboardName.getPrefix().replace(ChatColor.COLOR_CHAR, '&') + "' & '" + scoreboardName.getSuffix().replace(ChatColor.COLOR_CHAR, '&') + "'"); @@ -97,12 +102,10 @@ public class LDScoreboard implements LDCommand { if (!team.hasEntry(scoreboardName.getPlayer())) { if (issuesFound++ < 5) { - sender.sendMessage("The player disguise " + - ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') + - " on scoreboard team '" + scoreboardName.getTeamName() + "' on " + - player.getName() + " does not have the player entry expected! Instead has '" + - StringUtils.join(team.getEntries(), ", ").replace(ChatColor.COLOR_CHAR, '&') + - "'"); + sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') + + " on scoreboard team '" + scoreboardName.getTeamName() + "' on " + player.getName() + + " does not have the player entry expected! Instead has '" + + StringUtils.join(team.getEntries(), ", ").replace(ChatColor.COLOR_CHAR, '&') + "'"); } } } @@ -118,6 +121,44 @@ public class LDScoreboard implements LDCommand { LibsMsg.LIBS_SCOREBOARD_NAMES_DISABLED.send(sender); } + List listeners = ProtocolLibrary.getProtocolManager().getPacketListeners().stream() + .filter(listener -> listener.getPlugin() != LibsDisguises.getInstance() && listener.getSendingWhitelist().getTypes().contains(PacketType.Play.Server.SCOREBOARD_TEAM)).collect(Collectors.toList()); + + if (!listeners.isEmpty()) { + ComponentBuilder builder = + new ComponentBuilder(""); + builder.append("The following plugins are listening for scoreboard teams using ProtocolLib, and could be modifying collisions: "); + builder.color(net.md_5.bungee.api.ChatColor.BLUE); + + boolean comma = false; + + for (PacketListener listener : listeners) { + if (comma) { + builder.reset(); + builder.append(", "); + builder.color(net.md_5.bungee.api.ChatColor.BLUE); + } + + comma = true; + + builder.reset(); + builder.append(listener.getPlugin().getName()); + builder.color(net.md_5.bungee.api.ChatColor.AQUA); + + String plugin = ChatColor.GOLD + "Plugin: " + ChatColor.YELLOW + listener.getPlugin().getName() + " v" + + listener.getPlugin().getDescription().getVersion(); + String listenerClass = ChatColor.GOLD + "Listener: " + ChatColor.YELLOW + listener.getClass().toString(); + String packets = ChatColor.GOLD + "Packets: " + ChatColor.YELLOW + StringUtils.join(listener.getSendingWhitelist().getTypes(), ", "); + String priority = ChatColor.GOLD + "Priority: " + ChatColor.YELLOW + listener.getSendingWhitelist().getPriority(); + String options = ChatColor.GOLD + "Options: " + ChatColor.YELLOW + StringUtils.join(listener.getSendingWhitelist().getOptions(), ", "); + + builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, + TextComponent.fromLegacyText(plugin + "\n" + listenerClass + "\n" + packets + "\n" + priority + "\n" + options))); + } + + sender.spigot().sendMessage(builder.create()); + } + LibsMsg.LIBS_SCOREBOARD_IGNORE_TEST.send(sender); if (DisguiseConfig.getPushingOption() == DisguiseConfig.DisguisePushing.IGNORE_SCOREBOARD) { @@ -171,6 +212,7 @@ public class LDScoreboard implements LDCommand { if (Bukkit.getPluginManager().getPlugin("TAB") != null) { LibsMsg.PLUGIN_TAB_DETECTED.send(sender); } + } @Override