Introduce /ld pushing and have it print off potential causes for packet modifiers

This commit is contained in:
libraryaddict 2021-02-13 14:52:48 +13:00
parent 1790032f75
commit c05b8f8e02

View File

@ -1,12 +1,20 @@
package me.libraryaddict.disguise.commands.libsdisguises; 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.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; 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.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -19,6 +27,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
/** /**
* Created by libraryaddict on 20/04/2020. * Created by libraryaddict on 20/04/2020.
@ -26,7 +35,7 @@ import java.util.Set;
public class LDScoreboard implements LDCommand { public class LDScoreboard implements LDCommand {
@Override @Override
public List<String> getTabComplete() { public List<String> getTabComplete() {
return Arrays.asList("teams", "scoreboard", "board"); return Arrays.asList("teams", "scoreboard", "board", "pushing");
} }
@Override @Override
@ -48,8 +57,8 @@ public class LDScoreboard implements LDCommand {
if (!((PlayerDisguise) disguise).hasScoreboardName()) { if (!((PlayerDisguise) disguise).hasScoreboardName()) {
if (unexpected++ < 3) { if (unexpected++ < 3) {
sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName() + sender.sendMessage(
" isn't using a scoreboard name? This is unexpected"); "The player disguise " + ((PlayerDisguise) disguise).getName() + " isn't using a scoreboard name? This is unexpected");
} }
continue; continue;
} }
@ -70,24 +79,20 @@ public class LDScoreboard implements LDCommand {
if (team == null) { if (team == null) {
if (issuesFound++ < 5) { if (issuesFound++ < 5) {
sender.sendMessage("The player disguise " + sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') +
((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') + " is missing a scoreboard team '" + scoreboardName.getTeamName() + "' on " + player.getName() +
" is missing a scoreboard team '" + scoreboardName.getTeamName() + "' on " + " and possibly more players!");
player.getName() + " and possibly more players!");
} }
continue; continue;
} }
if (!team.getPrefix().equals("Colorize") && if (!team.getPrefix().equals("Colorize") &&
(!team.getPrefix().equals(scoreboardName.getPrefix()) || (!team.getPrefix().equals(scoreboardName.getPrefix()) || !team.getSuffix().equals(scoreboardName.getSuffix()))) {
!team.getSuffix().equals(scoreboardName.getSuffix()))) {
if (issuesFound++ < 5) { if (issuesFound++ < 5) {
sender.sendMessage("The player disguise " + sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') +
((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') + " on scoreboard team '" + scoreboardName.getTeamName() + "' on " + player.getName() +
" on scoreboard team '" + scoreboardName.getTeamName() + "' on " + " has an unexpected prefix/suffix of '" + team.getPrefix().replace(ChatColor.COLOR_CHAR, '&') + "' & '" +
player.getName() + " has an unexpected prefix/suffix of '" +
team.getPrefix().replace(ChatColor.COLOR_CHAR, '&') + "' & '" +
team.getSuffix().replace(ChatColor.COLOR_CHAR, '&') + "'! Expected '" + team.getSuffix().replace(ChatColor.COLOR_CHAR, '&') + "'! Expected '" +
scoreboardName.getPrefix().replace(ChatColor.COLOR_CHAR, '&') + "' & '" + scoreboardName.getPrefix().replace(ChatColor.COLOR_CHAR, '&') + "' & '" +
scoreboardName.getSuffix().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 (!team.hasEntry(scoreboardName.getPlayer())) {
if (issuesFound++ < 5) { if (issuesFound++ < 5) {
sender.sendMessage("The player disguise " + sender.sendMessage("The player disguise " + ((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') +
((PlayerDisguise) disguise).getName().replace(ChatColor.COLOR_CHAR, '&') + " on scoreboard team '" + scoreboardName.getTeamName() + "' on " + player.getName() +
" on scoreboard team '" + scoreboardName.getTeamName() + "' on " + " does not have the player entry expected! Instead has '" +
player.getName() + " does not have the player entry expected! Instead has '" + StringUtils.join(team.getEntries(), ", ").replace(ChatColor.COLOR_CHAR, '&') + "'");
StringUtils.join(team.getEntries(), ", ").replace(ChatColor.COLOR_CHAR, '&') +
"'");
} }
} }
} }
@ -118,6 +121,44 @@ public class LDScoreboard implements LDCommand {
LibsMsg.LIBS_SCOREBOARD_NAMES_DISABLED.send(sender); LibsMsg.LIBS_SCOREBOARD_NAMES_DISABLED.send(sender);
} }
List<PacketListener> 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); LibsMsg.LIBS_SCOREBOARD_IGNORE_TEST.send(sender);
if (DisguiseConfig.getPushingOption() == DisguiseConfig.DisguisePushing.IGNORE_SCOREBOARD) { if (DisguiseConfig.getPushingOption() == DisguiseConfig.DisguisePushing.IGNORE_SCOREBOARD) {
@ -171,6 +212,7 @@ public class LDScoreboard implements LDCommand {
if (Bukkit.getPluginManager().getPlugin("TAB") != null) { if (Bukkit.getPluginManager().getPlugin("TAB") != null) {
LibsMsg.PLUGIN_TAB_DETECTED.send(sender); LibsMsg.PLUGIN_TAB_DETECTED.send(sender);
} }
} }
@Override @Override