Add /ld debug - To help debug with scoreboard issues on a player

This commit is contained in:
libraryaddict 2020-04-24 18:09:15 +12:00
parent ab1a7bffe4
commit a63e617b0a
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
4 changed files with 103 additions and 1 deletions

View File

@ -30,6 +30,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
getCommands().add(new LDJson()); getCommands().add(new LDJson());
getCommands().add(new LDMods()); getCommands().add(new LDMods());
getCommands().add(new LDMetaInfo()); getCommands().add(new LDMetaInfo());
getCommands().add(new LDDebugPlayer());
} }
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) { protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {

View File

@ -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<String> 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;
}
}

View File

@ -321,7 +321,9 @@ public enum LibsMsg {
LD_COMMAND_SCOREBOARD(ChatColor.BLUE + "/libsdisguises scoreboard <Player?> - " + ChatColor.AQUA + LD_COMMAND_SCOREBOARD(ChatColor.BLUE + "/libsdisguises scoreboard <Player?> - " + ChatColor.AQUA +
"Does a test to see if there's any scoreboard issues it can detect"), "Does a test to see if there's any scoreboard issues it can detect"),
LD_COMMAND_RELOAD(ChatColor.BLUE + "/libsdisguises reload - " + ChatColor.AQUA + 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; private String string;

View File

@ -116,6 +116,8 @@ permissions:
description: Test if the scoreboard is valid, this is a simple test. description: Test if the scoreboard is valid, this is a simple test.
libsdisguises.config: libsdisguises.config:
description: Allows player to check Lib's Disguises config for values 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: libsdisguises.noactionbar:
description: Hides the action bar even if enabled in config description: Hides the action bar even if enabled in config
default: false default: false