From bdad4c3f1d18ebcde11ceb8869817a75ca33b0f5 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 7 Oct 2017 15:12:55 +1300 Subject: [PATCH] Changed Disguise/Undisguise player to support UUID's as well, including UUID's of non-players. Changed LibsMsg to reflect this --- .../commands/DisguisePlayerCommand.java | 27 +++++++++++++------ .../commands/UndisguisePlayerCommand.java | 24 ++++++++++++++--- .../disguise/utilities/DisguiseUtilities.java | 2 +- .../disguise/utilities/LibsMsg.java | 4 +-- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index 40569199..f05448ba 100644 --- a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -11,20 +11,17 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; -import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; +import java.util.*; public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCompleter { @@ -47,7 +44,17 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom return true; } - Player player = Bukkit.getPlayer(args[0]); + Entity player = Bukkit.getPlayer(args[0]); + + if (player == null) { + if (args[0].contains("-")) { + try { + player = Bukkit.getEntity(UUID.fromString(args[0])); + } + catch (Exception ignored) { + } + } + } if (player == null) { sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); @@ -97,9 +104,13 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom DisguiseAPI.disguiseToAll(player, disguise); if (disguise.isDisguiseInUse()) { - sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG.get(player.getName(), disguise.getType().toReadable())); + sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG + .get(player instanceof Player ? player.getName() : DisguiseType.getType(player).toReadable(), + disguise.getType().toReadable())); } else { - sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL.get(player.getName(), disguise.getType().toReadable())); + sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL + .get(player instanceof Player ? player.getName() : DisguiseType.getType(player).toReadable(), + disguise.getType().toReadable())); } return true; diff --git a/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java index 99f12df5..5c82ed4a 100644 --- a/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/UndisguisePlayerCommand.java @@ -1,17 +1,20 @@ package me.libraryaddict.disguise.commands; import me.libraryaddict.disguise.DisguiseAPI; +import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.utilities.LibsMsg; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.UUID; public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { protected ArrayList filterTabs(ArrayList list, String[] origArgs) { @@ -52,13 +55,28 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.hasPermission("libsdisguises.undisguiseplayer")) { if (args.length > 0) { - Player p = Bukkit.getPlayer(args[0]); + Entity p = Bukkit.getPlayer(args[0]); + + if (p == null) { + if (p == null) { + if (args[0].contains("-")) { + try { + p = Bukkit.getEntity(UUID.fromString(args[0])); + } + catch (Exception ignored) { + } + } + } + } + if (p != null) { if (DisguiseAPI.isDisguised(p)) { DisguiseAPI.undisguiseToAll(p); - sender.sendMessage(LibsMsg.UNDISG_PLAYER.get(p.getName())); + sender.sendMessage(LibsMsg.UNDISG_PLAYER + .get(p instanceof Player ? p.getName() : DisguiseType.getType(p).toReadable())); } else { - sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL.get(p.getName())); + sender.sendMessage(LibsMsg.UNDISG_PLAYER_FAIL + .get(p instanceof Player ? p.getName() : DisguiseType.getType(p).toReadable())); } } else { sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0])); diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index ad4ffe6e..ba698889 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -1317,7 +1317,7 @@ public class DisguiseUtilities { break; } - // If the player is in a team already + // If the player is in a team already and the team isn't one controlled by Lib's Disguises if (prevTeam != null && !(prevTeam.getName().equals("LD Pushing") || prevTeam.getName() .endsWith("_LDP"))) { // If we're creating a scoreboard diff --git a/src/me/libraryaddict/disguise/utilities/LibsMsg.java b/src/me/libraryaddict/disguise/utilities/LibsMsg.java index 93de1283..2e993072 100644 --- a/src/me/libraryaddict/disguise/utilities/LibsMsg.java +++ b/src/me/libraryaddict/disguise/utilities/LibsMsg.java @@ -8,7 +8,7 @@ import org.bukkit.ChatColor; public enum LibsMsg { BLOWN_DISGUISE(ChatColor.RED + "Your disguise was blown!"), CAN_USE_DISGS(ChatColor.DARK_GREEN + "You can use the disguises: %s"), - CANNOT_FIND_PLAYER(ChatColor.RED + "Cannot find the player '%s'"), + CANNOT_FIND_PLAYER(ChatColor.RED + "Cannot find the player/uuid '%s'"), CLICK_TIMER(ChatColor.RED + "Right click a entity in the next %s seconds to grab the disguise reference!"), CLONE_HELP1( ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other disguise commands!"), @@ -76,7 +76,7 @@ public enum LibsMsg { DMODRADIUS_NOPERM(ChatColor.RED + "No permission to modify %s disguises!"), DMODRADIUS_UNRECOGNIZED(ChatColor.RED + "Unrecognised DisguiseType %s"), DMODRADIUS_USABLE(ChatColor.DARK_GREEN + "DisguiseTypes usable are: %s" + ChatColor.DARK_GREEN + "."), - DPLAYER_SUPPLY(ChatColor.RED + "You need to supply a disguise as well as the player"), + DPLAYER_SUPPLY(ChatColor.RED + "You need to supply a disguise as well as the player/uuid"), DRADIUS_ENTITIES(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"), DRADIUS_HELP1(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"), DRADIUS_HELP3(