Add placeholder support, explained in disguises.yml. fixes #296

This commit is contained in:
libraryaddict 2019-03-05 17:46:47 +13:00
parent 2cf86b9cd8
commit a43f46628a
12 changed files with 278 additions and 111 deletions

View File

@ -6,6 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.AbstractHorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.DyeColor;
import org.bukkit.Material;
@ -25,8 +26,8 @@ import java.util.Map;
public class DisguiseAPI {
private static int selfDisguiseId = ReflectionManager.getNewEntityId(true);
public static Disguise getCustomDisguise(String disguiseName) {
Map.Entry<String, Disguise> entry = DisguiseConfig.getCustomDisguise(disguiseName);
public static String getCustomDisguise(String disguiseName) {
Map.Entry<DisguisePerm, String> entry = DisguiseConfig.getCustomDisguise(disguiseName);
if (entry == null)
return null;

View File

@ -6,6 +6,7 @@ import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
import me.libraryaddict.disguise.utilities.parser.DisguiseParseException;
import me.libraryaddict.disguise.utilities.parser.DisguiseParser;
import me.libraryaddict.disguise.utilities.parser.DisguisePerm;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
@ -35,7 +36,7 @@ public class DisguiseConfig {
private static boolean collectEnabled;
private static boolean colorizeSheep;
private static boolean colorizeWolf;
private static HashMap<String, Disguise> customDisguises = new HashMap<>();
private static HashMap<DisguisePerm, String> customDisguises = new HashMap<>();
private static boolean disableInvisibility;
private static int disguiseCloneExpire;
private static int disguiseEntityExpire;
@ -117,10 +118,11 @@ public class DisguiseConfig {
explicitDisguisePermissions = explictDisguisePermission;
}
public static Entry<String, Disguise> getCustomDisguise(String disguise) {
for (Entry<String, Disguise> entry : customDisguises.entrySet()) {
if (!entry.getKey().equalsIgnoreCase(disguise) &&
!entry.getKey().replaceAll("_", "").equalsIgnoreCase(disguise))
public static Entry<DisguisePerm, String> getCustomDisguise(String disguise) {
for (Entry<DisguisePerm, String> entry : customDisguises.entrySet()) {
String name = entry.getKey().toReadable();
if (!name.equalsIgnoreCase(disguise) && !name.replaceAll("_", "").equalsIgnoreCase(disguise))
continue;
return entry;
@ -183,7 +185,7 @@ public class DisguiseConfig {
return disablePushing;
}
public static HashMap<String, Disguise> getCustomDisguises() {
public static HashMap<DisguisePerm, String> getCustomDisguises() {
return customDisguises;
}
@ -353,11 +355,27 @@ public class DisguiseConfig {
}
try {
String[] disguiseArgs = DisguiseUtilities.split(toParse);
for (int i = 0; i < disguiseArgs.length; i++) {
String arg = disguiseArgs[i];
// If argument is for the command user name
if (arg.equals("%player%")) {
disguiseArgs[i] = "libraryaddict";
} else if (arg.equals("%skin%")) { // If argument is for the command user skin
disguiseArgs[i] = "{\"id\":\"a149f81bf7844f8987c554afdd4db533\",\"name\":\"libraryaddict\"," +
"\"properties\":[]}";
}
}
Disguise disguise = DisguiseParser
.parseDisguise(Bukkit.getConsoleSender(), "disguise", DisguiseUtilities.split(toParse),
.parseTestDisguise(Bukkit.getConsoleSender(), "disguise", disguiseArgs,
DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise"));
customDisguises.put(key, disguise);
DisguisePerm perm = new DisguisePerm(disguise.getType(), key);
customDisguises.put(perm, toParse);
DisguiseUtilities.getLogger().info("Loaded custom disguise " + key);
}

View File

@ -44,16 +44,13 @@ import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scoreboard.Team;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class DisguiseListener implements Listener {
private String currentVersion;
private HashMap<String, Boolean[]> disguiseClone = new HashMap<>();
private HashMap<String, Disguise> disguiseEntity = new HashMap<>();
private HashMap<String, String[]> disguiseEntity = new HashMap<>();
private HashMap<String, String[]> disguiseModify = new HashMap<>();
private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<>();
private String latestVersion;
@ -175,10 +172,6 @@ public class DisguiseListener implements Listener {
r.cancel();
}
for (Disguise d : disguiseEntity.values()) {
d.removeDisguise();
}
disguiseClone.clear();
updaterTask.cancel();
}
@ -505,9 +498,27 @@ public class DisguiseListener implements Listener {
DisguiseUtilities.createClonedDisguise(p, entity, options);
} else if (disguiseEntity.containsKey(p.getName())) {
Disguise disguise = disguiseEntity.remove(p.getName());
String[] disguiseArgs = disguiseEntity.remove(p.getName());
if (disguiseArgs != null) {
Disguise disguise;
try {
disguise = DisguiseParser.parseDisguise(p, entity, "disguiseentity", disguiseArgs,
DisguiseParser.getPermissions(p, "disguiseentity"));
}
catch (DisguiseParseException e) {
if (e.getMessage() != null) {
p.sendMessage(e.getMessage());
}
return;
}
catch (Exception e) {
e.printStackTrace();
return;
}
if (disguise != null) {
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() &&
entity instanceof LivingEntity) {
p.sendMessage(LibsMsg.DISABLED_LIVING_TO_MISC.get());
@ -596,6 +607,10 @@ public class DisguiseListener implements Listener {
return;
}
options = DisguiseParser
.parsePlaceholders(options, p.getName(), DisguiseParser.getSkin(p), DisguiseParser.getName(entity),
DisguiseParser.getSkin(entity));
DisguisePermissions perms = DisguiseParser.getPermissions(p, "disguiseentitymodify");
DisguisePerm disguisePerm = new DisguisePerm(disguise.getType());
@ -605,7 +620,8 @@ public class DisguiseListener implements Listener {
}
try {
DisguiseParser.callMethods(p, disguise, perms, disguisePerm, Arrays.asList(options), options);
DisguiseParser.callMethods(p, disguise, perms, disguisePerm, new ArrayList<>(Arrays.asList(options)),
options);
p.sendMessage(LibsMsg.LISTENER_MODIFIED_DISG.get());
}
catch (DisguiseParseException ex) {
@ -779,7 +795,7 @@ public class DisguiseListener implements Listener {
disguiseClone.put(player, options);
}
public void setDisguiseEntity(final String player, Disguise disguise) {
public void setDisguiseEntity(final String player, String[] disguise) {
if (disguiseRunnable.containsKey(player)) {
BukkitRunnable run = disguiseRunnable.remove(player);
run.cancel();

View File

@ -36,9 +36,8 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
Disguise disguise;
try {
disguise = DisguiseParser
.parseDisguise(sender, getPermNode(), DisguiseUtilities.split(StringUtils.join(args, " ")),
getPermissions(sender));
disguise = DisguiseParser.parseDisguise(sender, (Entity) sender, getPermNode(),
DisguiseUtilities.split(StringUtils.join(args, " ")), getPermissions(sender));
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {

View File

@ -37,12 +37,12 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
return true;
}
Disguise disguise;
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(args, " "));
Disguise testDisguise;
try {
disguise = DisguiseParser
.parseDisguise(sender, getPermNode(), DisguiseUtilities.split(StringUtils.join(args, " ")),
getPermissions(sender));
testDisguise = DisguiseParser
.parseTestDisguise(sender, getPermNode(), disguiseArgs, getPermissions(sender));
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
@ -56,10 +56,10 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
return true;
}
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguise);
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguiseArgs);
sender.sendMessage(
LibsMsg.DISG_ENT_CLICK.get(DisguiseConfig.getDisguiseEntityExpire(), disguise.getType().toReadable()));
sender.sendMessage(LibsMsg.DISG_ENT_CLICK
.get(DisguiseConfig.getDisguiseEntityExpire(), testDisguise.getType().toReadable()));
return true;
}

View File

@ -53,9 +53,14 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom
return true;
}
String[] options = DisguiseUtilities.split(StringUtils.join(args, " "));
options = DisguiseParser
.parsePlaceholders(options, sender.getName(), DisguiseParser.getSkin(sender), sender.getName(),
DisguiseParser.getSkin(sender));
try {
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(),
DisguiseUtilities.split(StringUtils.join(args, " ")));
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), options);
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {

View File

@ -14,10 +14,12 @@ 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.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements TabCompleter {
@ -35,9 +37,19 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
return true;
}
Player player = Bukkit.getPlayer(args[0]);
Entity entityTarget = Bukkit.getPlayer(args[0]);
if (player == null) {
if (entityTarget == null) {
if (args[0].contains("-")) {
try {
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
}
catch (Exception ignored) {
}
}
}
if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
return true;
}
@ -53,13 +65,13 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
Disguise disguise = null;
if (sender instanceof Player)
disguise = DisguiseAPI.getDisguise((Player) sender, player);
disguise = DisguiseAPI.getDisguise((Player) sender, entityTarget);
if (disguise == null)
disguise = DisguiseAPI.getDisguise(player);
disguise = DisguiseAPI.getDisguise(entityTarget);
if (disguise == null) {
sender.sendMessage(LibsMsg.DMODPLAYER_NODISGUISE.get(player.getName()));
sender.sendMessage(LibsMsg.DMODPLAYER_NODISGUISE.get(entityTarget.getName()));
return true;
}
@ -70,9 +82,15 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
return true;
}
String[] options = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
options = DisguiseParser
.parsePlaceholders(options, sender.getName(), DisguiseParser.getSkin(sender), DisguiseParser.getName(entityTarget),
DisguiseParser.getSkin(entityTarget));
try {
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(),
DisguiseUtilities.split(StringUtils.join(newArgs, " ")));
options);
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
@ -86,7 +104,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
return true;
}
sender.sendMessage(LibsMsg.DMODPLAYER_MODIFIED.get(player.getName()));
sender.sendMessage(LibsMsg.DMODPLAYER_MODIFIED.get(entityTarget.getName()));
return true;
}

View File

@ -18,10 +18,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.*;
public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
private int maxRadius = 30;
@ -127,6 +124,8 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
int modifiedDisguises = 0;
int noPermission = 0;
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
for (Entity entity : getNearbyEntities(sender, radius)) {
if (entity == sender) {
continue;
@ -150,9 +149,12 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
continue;
}
String[] tempArgs = Arrays.copyOf(disguiseArgs, disguiseArgs.length);
tempArgs = DisguiseParser.parsePlaceholders(tempArgs, sender.getName(), DisguiseParser.getSkin(sender),
DisguiseParser.getName(entity), DisguiseParser.getSkin(entity));
try {
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(),
DisguiseUtilities.split(StringUtils.join(newArgs, " ")));
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), tempArgs);
modifiedDisguises++;
}
catch (DisguiseParseException ex) {

View File

@ -44,19 +44,19 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
return true;
}
Entity entity = Bukkit.getPlayer(args[0]);
Entity entityTarget = Bukkit.getPlayer(args[0]);
if (entity == null) {
if (entityTarget == null) {
if (args[0].contains("-")) {
try {
entity = Bukkit.getEntity(UUID.fromString(args[0]));
entityTarget = Bukkit.getEntity(UUID.fromString(args[0]));
}
catch (Exception ignored) {
}
}
}
if (entity == null) {
if (entityTarget == null) {
sender.sendMessage(LibsMsg.CANNOT_FIND_PLAYER.get(args[0]));
return true;
}
@ -72,9 +72,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
Disguise disguise;
try {
disguise = DisguiseParser
.parseDisguise(sender, getPermNode(), DisguiseUtilities.split(StringUtils.join(newArgs, " ")),
permissions);
disguise = DisguiseParser.parseDisguise(sender, entityTarget, getPermNode(),
DisguiseUtilities.split(StringUtils.join(newArgs, " ")), permissions);
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
@ -95,14 +94,15 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
disguise.getWatcher().setCustomName(getDisplayName(entity));
disguise.getWatcher().setCustomName(getDisplayName(entityTarget));
if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
disguise.getWatcher().setCustomNameVisible(true);
}
}
}
disguise.setEntity(entity);
disguise.setEntity(entityTarget);
if (!setViewDisguise(args)) {
// They prefer to have the opposite of whatever the view disguises option is
@ -114,13 +114,12 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
disguise.startDisguise();
if (disguise.isDisguiseInUse()) {
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG
.get(entity instanceof Player ? entity.getName() : DisguiseType.getType(entity).toReadable(),
disguise.getType().toReadable()));
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable()));
} else {
sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG_FAIL
.get(entity instanceof Player ? entity.getName() : DisguiseType.getType(entity).toReadable(),
disguise.getType().toReadable()));
.get(entityTarget instanceof Player ? entityTarget.getName() :
DisguiseType.getType(entityTarget).toReadable(), disguise.getType().toReadable()));
}
return true;

View File

@ -124,55 +124,47 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
String[] newArgs = new String[args.length - (starting + 1)];
System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length);
Disguise disguise;
if (newArgs.length == 0) {
sendCommandUsage(sender, permissions);
return true;
}
String[] disguiseArgs = DisguiseUtilities.split(StringUtils.join(newArgs, " "));
try {
disguise = DisguiseParser
.parseDisguise(sender, getPermNode(), DisguiseUtilities.split(StringUtils.join(newArgs, " ")),
permissions);
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
Disguise testDisguise = DisguiseParser.parseTestDisguise(sender, getPermNode(), disguiseArgs, permissions);
// Time to use it!
int disguisedEntitys = 0;
int miscDisguises = 0;
Location center;
if (sender instanceof Player) {
center = ((Player) sender).getLocation();
} else {
center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
}
return true;
}
catch (Exception ex) {
ex.printStackTrace();
return true;
}
for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) {
if (entity == sender) {
continue;
}
// Time to use it!
int disguisedEntitys = 0;
int miscDisguises = 0;
if (type != null ? entity.getType() != type : !entityClass.isAssignableFrom(entity.getClass())) {
continue;
}
Location center;
if (sender instanceof Player) {
center = ((Player) sender).getLocation();
} else {
center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
}
for (Entity entity : center.getWorld().getNearbyEntities(center, radius, radius, radius)) {
if (entity == sender) {
continue;
}
if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass())) {
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() &&
if (testDisguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() &&
entity instanceof LivingEntity) {
miscDisguises++;
continue;
}
disguise = disguise.clone();
Disguise disguise = DisguiseParser
.parseDisguise(sender, entity, getPermNode(), disguiseArgs, permissions);
if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
if (disguise.getWatcher() instanceof LivingWatcher) {
@ -193,22 +185,29 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
}
disguise.startDisguise();
DisguiseAPI.disguiseEntity(entity, disguise);
if (disguise.isDisguiseInUse()) {
disguisedEntitys++;
}
}
}
if (disguisedEntitys > 0) {
sender.sendMessage(LibsMsg.DISRADIUS.get(disguisedEntitys));
} else {
sender.sendMessage(LibsMsg.DISRADIUS_FAIL.get());
}
if (disguisedEntitys > 0) {
sender.sendMessage(LibsMsg.DISRADIUS.get(disguisedEntitys));
} else {
sender.sendMessage(LibsMsg.DISRADIUS_FAIL.get());
}
if (miscDisguises > 0) {
sender.sendMessage(LibsMsg.DRADIUS_MISCDISG.get(miscDisguises));
if (miscDisguises > 0) {
sender.sendMessage(LibsMsg.DRADIUS_MISCDISG.get(miscDisguises));
}
}
catch (DisguiseParseException ex) {
if (ex.getMessage() != null) {
sender.sendMessage(ex.getMessage());
}
}
catch (Exception ex) {
ex.printStackTrace();
}
return true;

View File

@ -1,14 +1,17 @@
package me.libraryaddict.disguise.utilities.parser;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.parser.params.ParamInfo;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import me.libraryaddict.disguise.utilities.translations.TranslateType;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.PermissionAttachmentInfo;
@ -86,8 +89,8 @@ public class DisguiseParser {
perms[i++] = new DisguisePerm(disguiseType);
}
for (Entry<String, Disguise> entry : DisguiseConfig.getCustomDisguises().entrySet()) {
perms[i++] = new DisguisePerm(entry.getValue().getType(), entry.getKey());
for (Entry<DisguisePerm, String> entry : DisguiseConfig.getCustomDisguises().entrySet()) {
perms[i++] = entry.getKey();
}
return perms;
@ -122,7 +125,7 @@ public class DisguiseParser {
/**
* Returns true if the string is found in the map, or it's not a whitelisted setup
*
* <p>
* Returns if command user can access the disguise creation permission type
*/
private static boolean hasPermissionOption(HashMap<String, Boolean> disguiseOptions, String string) {
@ -140,13 +143,101 @@ public class DisguiseParser {
return disguiseOptions.containsValue(true);
}
public static String getName(Entity entity) {
if (entity == null) {
return "??";
}
if (entity instanceof Player) {
return entity.getName();
}
if (entity.getCustomName() != null && entity.getCustomName().length() > 0) {
return entity.getCustomName();
}
return entity.getName();
}
public static String getSkin(CommandSender entity) {
if (entity == null) {
return "??";
}
if (entity instanceof Player) {
WrappedGameProfile gameProfile = ReflectionManager.getGameProfile((Player) entity);
if (gameProfile != null) {
return DisguiseUtilities.getGson().toJson(gameProfile);
}
}
return "{}";
}
public static String[] parsePlaceholders(String[] args, String userName, String userSkin, String targetName,
String targetSkin) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if (arg.contains("%user-name%")) {
arg = arg.replace("%user-name%", userName);
}
if (arg.contains("%user-skin%")) {
arg = arg.replace("%user-skin%", userSkin);
}
if (arg.contains("%target-name%")) {
arg = arg.replace("%target-name%", targetName);
}
if (arg.contains("%target-skin%")) {
arg = arg.replace("%target-skin%", targetSkin);
}
args[i] = arg;
}
return args;
}
/**
* Experimentally parses the arguments to test if this is a valid disguise
*
* @param sender
* @param permNode
* @param args
* @param permissions
* @return
* @throws DisguiseParseException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public static Disguise parseTestDisguise(CommandSender sender, String permNode, String[] args,
DisguisePermissions permissions) throws DisguiseParseException, IllegalAccessException,
InvocationTargetException {
// Clone array so original array isn't modified
args = Arrays.copyOf(args, args.length);
String skin = "{\"id\":\"a149f81bf7844f8987c554afdd4db533\",\"name\":\"libraryaddict\"," + "\"properties\":[]}";
// Fill in fake data
args = parsePlaceholders(args, "libraryaddict", skin, "libraryaddict", skin);
// Parse disguise
return parseDisguise(sender, null, permNode, args, permissions);
}
/**
* Returns the disguise if it all parsed correctly. Returns a exception with a complete message if it didn't. The
* commandsender is purely used for checking permissions. Would defeat the purpose otherwise. To reach this
* point, the
* disguise has been feed a proper disguisetype.
*/
public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args,
public static Disguise parseDisguise(CommandSender sender, Entity target, String permNode, String[] args,
DisguisePermissions permissions) throws DisguiseParseException, IllegalAccessException,
InvocationTargetException {
if (sender instanceof Player) {
@ -195,12 +286,14 @@ public class DisguiseParser {
}
} else {
disguisePerm = getDisguisePerm(args[0]);
Entry<String, Disguise> customDisguise = DisguiseConfig.getCustomDisguise(args[0]);
Entry<DisguisePerm, String> customDisguise = DisguiseConfig.getCustomDisguise(args[0]);
if (customDisguise != null) {
disguise = customDisguise.getValue().clone();
args = DisguiseUtilities.split(customDisguise.getValue());
}
args = parsePlaceholders(args, sender.getName(), getSkin(sender), getName(target), getSkin(target));
if (disguisePerm == null) {
throw new DisguiseParseException(LibsMsg.PARSE_DISG_NO_EXIST, args[0]);
}

View File

@ -6,6 +6,23 @@
# To get the skin signiture, you can find it on mojang's servers. Such as https://sessionserver.mojang.com/session/minecraft/profile/<uuid>?unsigned=false
# Just remember to remove the slashes from the UUID, remember the UUID is the unique code given to a player, just google for a tool to see someone's UUID
# Example: https://sessionserver.mojang.com/session/minecraft/profile/a149f81bf7844f8987c554afdd4db533?unsigned=false
# You can also use placeholders in the disguises to create disguises that have the command users skin
# %user-name% - Replaces %user-name% with the command user's name.
# %user-skin% - Replaces %user-skin% with the command user's skin for use with player disguises.
# %target-name% - Finds first viable name from: Player name, entity custom nametag, then entity type (Pig, Horse, Cow)
# %target-skin% - If target is a player, replaces %target-skin% with their skin for use with player disguises
# If target is not a player, will silently fail
# The below disguise would give a disguised sheep the nametag; Me: libraryaddict, Them: Sheep
# Example: 'cow setCustomName "Me: %user-name%, Them: %target-name%"'
#
# This would give the disguised target a player disguise of their own name, but using the skin of the command user
# Example2: 'player %target-name% setSkin %user-skin%'
Disguises:
libraryaddict: 'player libraryaddict setArmor GOLDEN_BOOTS,GOLDEN_LEGGINGS,GOLDEN_CHESTPLATE,GOLDEN_HELMET setItemInMainHand WRITTEN_BOOK setGlowing setSkin {"id":"a149f81bf7844f8987c554afdd4db533","name":"libraryaddict","properties":[{"signature":"afoGOO45t3iGvTyQ732AlugPOvj13/RNjM0/utYlD4PZ4ab4Jopbzr8Px75+ALdkyegoKNcfaH4aXzylMvL6mIwaRdL0af7pfGibMMCMJ8F1RAMl2WqRslKBKXHGS1OXxMweoXW+RRatGgZsUC1BjxHMwd4RuXxrV9ZZ7x1r4xouUXmMzn19wqNO9EeG2q8AgF/hZdrnJPdTTrqJs04r4vCQiFiQsTWiY/B5CBOTh6fw4NpOHeeiJwHOLvN+6xKnAm77nKawaKCSciDwt54EeZoE/Q5ReQUEFgj++jdyHb5PJbhGytr//mazpTVzvlDnO06CZqigbiueV2/ush2gKSXQeimCXeNZzcj/CFgqAmMSEZQW3qHp+DgoqqtBNabJa0FBzpbQQ/jQWzoHfmUC/hTf0A0+hgOe4NqDc+xXYf4A9M/6/0JHz0voWhQJi8QriM699DeeUa31bVdTdKjcyK6Zw6/HIOJt++eFnkf++/zKt0fMiqfdRamSqR/K3w+Kk7cs2D345BNubl5L83YWmLbebUcAPKaza5gi17lUW+h/FitzfKAJZ+xsfSdj27nQLa24xYsyB3Fi5DcFLI2oQt5BYAvViT37sabGOXbDBsrijS4t3++mIbC+pCDiKi0hwZzvy0TPRTle2RMhJ6D66DmpykwqBOxzD73fEsieWX4=","name":"textures","value":"eyJ0aW1lc3RhbXAiOjE0ODA1MjA3NjAxNTksInByb2ZpbGVJZCI6ImExNDlmODFiZjc4NDRmODk4N2M1NTRhZmRkNGRiNTMzIiwicHJvZmlsZU5hbWUiOiJsaWJyYXJ5YWRkaWN0Iiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS84ZTQ5NDVkMzZjZjVhNjI1OGZjOGY4ZTM5NmZlZWYzMzY1ZjM2MjgyYjE2MjY0OWI2M2NmZWQzNzNmNzY1OSJ9LCJDQVBFIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZWZkNjFjM2M0YWM4OGYxYTM0NjhmYmRlZWY0NWNlYzg5ZTVhZmI4N2I5N2ExYTg0NWJmYjNjNjRmZDBiODgzIn19fQ=="}]}'
# Warrior: 'zombie setArmor DIAMOND_BOOTS,DIAMOND_LEGGINGS,DIAMOND_CHESTPLATE,DIAMOND_HELMET setItemInMainHand DIAMOND_SWORD setItemInOffHand SHIELD'
# Warrior: 'zombie setArmor DIAMOND_BOOTS,DIAMOND_LEGGINGS,DIAMOND_CHESTPLATE,DIAMOND_HELMET setItemInMainHand DIAMOND_SWORD setItemInOffHand SHIELD'
# Topsy: 'player Dinnerbone setSkin %target-skin%'