From bad4f555cfbf3d2bd8f90ad78baebd45a24c1dbf Mon Sep 17 00:00:00 2001 From: Kyzderp Date: Sat, 10 Sep 2016 05:05:25 -0700 Subject: [PATCH] Add dlist and fix dradius error --- plugin.yml | 7 ++ .../libraryaddict/disguise/LibsDisguises.java | 1 + .../commands/DisguiseListCommand.java | 68 +++++++++++++++++++ .../commands/RadiusDisguiseCommand.java | 5 ++ 4 files changed, 81 insertions(+) create mode 100644 src/me/libraryaddict/disguise/commands/DisguiseListCommand.java diff --git a/plugin.yml b/plugin.yml index bb923226..2e18e0ca 100644 --- a/plugin.yml +++ b/plugin.yml @@ -53,6 +53,10 @@ commands: aliases: [dviewself, dvs, disguisevs, disvs, vsd, viewselfdisguise, viewselfd] permission: libsdisguises.seecmd.viewself description: Toggle seeing your own disguise on or off. + disguiselist: + aliases: [dlist] + permission: libsdisguises.seecmd.disguiselist + description: See a list of who is disguised as what. permissions: libsdisguises.reload: @@ -77,6 +81,7 @@ permissions: libsdisguises.seecmd.undisguiseradius: true libsdisguises.seecmd.disguiseclone: true libsdisguises.seecmd.disguiseviewself: true + libsdisguises.seecmd.disguiselist: true libsdisguises.seecmd.libsdisguises: description: See the /libsdisguises command in tab-completion libsdisguises.seecmd.disguiseviewself: @@ -101,3 +106,5 @@ permissions: description: See the /undisguiseradius command in tab-completion libsdisguises.seecmd.disguiseclone: description: See the /disguiseclone command in tab-completion + libsdisguises.seecmd.disguiselist: + description: See the /disguiselist command in tab-completion diff --git a/src/me/libraryaddict/disguise/LibsDisguises.java b/src/me/libraryaddict/disguise/LibsDisguises.java index 55a364c3..268e6dd6 100644 --- a/src/me/libraryaddict/disguise/LibsDisguises.java +++ b/src/me/libraryaddict/disguise/LibsDisguises.java @@ -112,6 +112,7 @@ public class LibsDisguises extends JavaPlugin getCommand("disguiseclone").setExecutor(new CloneDisguiseCommand()); getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand()); getCommand("disguiseviewself").setExecutor(new DisguiseViewSelf()); + getCommand("disguiselist").setExecutor(new DisguiseListCommand()); registerValues(); diff --git a/src/me/libraryaddict/disguise/commands/DisguiseListCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseListCommand.java new file mode 100644 index 00000000..3acb8faa --- /dev/null +++ b/src/me/libraryaddict/disguise/commands/DisguiseListCommand.java @@ -0,0 +1,68 @@ +package me.libraryaddict.disguise.commands; + +import java.util.UUID; + +import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; +import me.libraryaddict.disguise.disguisetypes.TargetedDisguise; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class DisguiseListCommand implements CommandExecutor +{ + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) + { + if (sender.hasPermission("libsdisguises.seecmd.disguiselist")) + { + String players = ""; + int numPlayers = 0; + int numOther = 0; + + // Go through all disguises + for (UUID uuid: DisguiseUtilities.getDisguises().keySet()) + { + Player player = Bukkit.getPlayer(uuid); + TargetedDisguise disguise = DisguiseUtilities.getMainDisguise(uuid); + + if (player == null || !player.isOnline()) + { + // Assume this is a non-player entity + numOther++; + } + else + { + // This is a player + numPlayers++; + players += " " + ChatColor.AQUA + player.getName() + ChatColor.GRAY + "(" + + disguise.getType().toReadable(); + + // Special treatment if the disguise is a player + if (disguise.getType() == DisguiseType.PLAYER && disguise instanceof PlayerDisguise) + players += ":" + ((PlayerDisguise)disguise).getName(); + + players += ")"; + } + } + + // Formatting + players = "" + ChatColor.AQUA + numPlayers + ChatColor.DARK_AQUA + + " disguised players:" + players; + String entities = ChatColor.DARK_AQUA + "Also " + ChatColor.AQUA + + numOther + ChatColor.DARK_AQUA + " other diguised entities."; + + sender.sendMessage(new String[] {players, entities}); + } + else + { + sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); + } + return true; + } +} diff --git a/src/me/libraryaddict/disguise/commands/RadiusDisguiseCommand.java b/src/me/libraryaddict/disguise/commands/RadiusDisguiseCommand.java index f0e898b9..de65fab1 100644 --- a/src/me/libraryaddict/disguise/commands/RadiusDisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/RadiusDisguiseCommand.java @@ -117,6 +117,11 @@ public class RadiusDisguiseCommand extends BaseDisguiseCommand + (starting != 0 ? " and EntityType" : "")); return true; } + else if (args.length < 2) + { + sender.sendMessage(ChatColor.RED + "You need to supply a radius as well as the disguise"); + return true; + } if (!isNumeric(args[starting])) {