Changed Disguise/Undisguise player to support UUID's as well, including UUID's of non-players. Changed LibsMsg to reflect this

This commit is contained in:
libraryaddict 2017-10-07 15:12:55 +13:00
parent 6dc4f29786
commit bdad4c3f1d
4 changed files with 43 additions and 14 deletions

View File

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

View File

@ -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<String> filterTabs(ArrayList<String> 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]));

View File

@ -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

View File

@ -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(