From a63e617b0a2068618768a195fe95cb44040338ec Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 24 Apr 2020 18:09:15 +1200 Subject: [PATCH] Add /ld debug - To help debug with scoreboard issues on a player --- .../commands/LibsDisguisesCommand.java | 1 + .../commands/libsdisguises/LDDebugPlayer.java | 97 +++++++++++++++++++ .../utilities/translations/LibsMsg.java | 4 +- src/main/resources/plugin.yml | 2 + 4 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDDebugPlayer.java diff --git a/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java b/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java index 2b668223..786bc064 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/LibsDisguisesCommand.java @@ -30,6 +30,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { getCommands().add(new LDJson()); getCommands().add(new LDMods()); getCommands().add(new LDMetaInfo()); + getCommands().add(new LDDebugPlayer()); } protected ArrayList filterTabs(ArrayList list, String[] origArgs) { diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDDebugPlayer.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDDebugPlayer.java new file mode 100644 index 00000000..de816626 --- /dev/null +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDDebugPlayer.java @@ -0,0 +1,97 @@ +package me.libraryaddict.disguise.commands.libsdisguises; + +import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.LibsDisguises; +import me.libraryaddict.disguise.disguisetypes.Disguise; +import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; +import me.libraryaddict.disguise.utilities.LibsEntityInteract; +import me.libraryaddict.disguise.utilities.translations.LibsMsg; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.Team; + +import java.util.Collections; +import java.util.List; + +/** + * Created by libraryaddict on 24/04/2020. + */ +public class LDDebugPlayer implements LDCommand { + public class DebugInteraction implements LibsEntityInteract { + @Override + public void onInteract(Player player, Entity entity) { + Disguise disguise = DisguiseAPI.getDisguise(player, entity); + + if (disguise == null) { + player.sendMessage(LibsMsg.TARGET_NOT_DISGUISED.get()); + return; + } + + if (!disguise.isPlayerDisguise()) { + player.sendMessage(ChatColor.RED + "Meant to be used on player disguises!"); + return; + } + + PlayerDisguise disg = (PlayerDisguise) disguise; + + player.sendMessage(ChatColor.RED + "Name: " + disg.getName().replace(ChatColor.COLOR_CHAR, '&')); + + if (!disg.hasScoreboardName()) { + player.sendMessage(ChatColor.RED + "Disguise doesn't have scoreboard name, can't say more."); + return; + } + + DisguiseUtilities.DScoreTeam name = disg.getScoreboardName(); + + player.sendMessage(ChatColor.RED + + String.format("Prefix: '%s', Suffix: '%s', Disguise Name: '%s', Team '%s'", + name.getPrefix().replace(ChatColor.COLOR_CHAR, '&'), + name.getSuffix().replace(ChatColor.COLOR_CHAR, '&'), + name.getPlayer().replace(ChatColor.COLOR_CHAR, '&'), name.getTeamName())); + + Team team = player.getScoreboard().getTeam(name.getTeamName()); + + if (team == null) { + player.sendMessage(ChatColor.RED + "That team doesn't exist to you"); + return; + } + + player.sendMessage(ChatColor.RED + String.format("Prefix Matches: %s, Suffix Matches: %s, In Team: %s", + team.getPrefix().equals(name.getPrefix()), team.getSuffix().equals(name.getSuffix()), + team.hasEntry(name.getPlayer()))); + } + } + + @Override + public List getTabComplete() { + return Collections.singletonList("debug"); + } + + @Override + public boolean hasPermission(CommandSender sender) { + return sender.hasPermission(getPermission()); + } + + @Override + public String getPermission() { + return "libsdisguises.debug"; + } + + @Override + public void onCommand(CommandSender sender, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(LibsMsg.NO_PERM.get()); + } + + LibsDisguises.getInstance().getListener().addInteraction(sender.getName(), new DebugInteraction(), 60); + sender.sendMessage(ChatColor.DARK_GREEN + "Right click a disguised player to get some debug outta em"); + } + + @Override + public LibsMsg getHelp() { + return LibsMsg.LD_COMMAND_DEBUG; + } +} diff --git a/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java b/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java index ca7d38f5..9eac4bbe 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java @@ -321,7 +321,9 @@ public enum LibsMsg { LD_COMMAND_SCOREBOARD(ChatColor.BLUE + "/libsdisguises scoreboard - " + ChatColor.AQUA + "Does a test to see if there's any scoreboard issues it can detect"), LD_COMMAND_RELOAD(ChatColor.BLUE + "/libsdisguises reload - " + ChatColor.AQUA + - "Reload's the plugin config and possibly blows disguises"); + "Reload's the plugin config and possibly blows disguises"), + LD_COMMAND_DEBUG(ChatColor.BLUE + "/libsdisguises debug - " + ChatColor.AQUA + + "Used to help debug scoreboard issues on a player disguise"); private String string; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4eb95e8a..fe84bd7d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -116,6 +116,8 @@ permissions: description: Test if the scoreboard is valid, this is a simple test. libsdisguises.config: description: Allows player to check Lib's Disguises config for values + libsdisguises.debug: + description: Allows a server admin to test a player disguise for scoreboard issues libsdisguises.noactionbar: description: Hides the action bar even if enabled in config default: false