diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index ecf33f2b..c3edf1ad 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -9,10 +9,13 @@ 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.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Entity; import java.io.File; +import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map.Entry; @@ -127,6 +130,28 @@ public class DisguiseConfig { explicitDisguisePermissions = explictDisguisePermission; } + public static Entry getParsedCustomDisguise( + String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException { + Entry entry = getCustomDisguise(disguise); + + return new HashMap.SimpleEntry(entry.getKey(), DisguiseParser.parseDisguise(entry.getValue())); + } + + public static Entry getParsedCustomDisguise(Entity target, + String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException { + Entry entry = getCustomDisguise(disguise); + + return new HashMap.SimpleEntry(entry.getKey(), + DisguiseParser.parseDisguise(Bukkit.getConsoleSender(), target, entry.getValue())); + } + + public static Entry getParsedCustomDisguise(CommandSender invoker, Entity target, + String disguise) throws IllegalAccessException, DisguiseParseException, InvocationTargetException { + Entry entry = getCustomDisguise(disguise); + + return new HashMap.SimpleEntry(entry.getKey(), DisguiseParser.parseDisguise(invoker, target, entry.getValue())); + } + public static Entry getCustomDisguise(String disguise) { for (Entry entry : customDisguises.entrySet()) { String name = entry.getKey().toReadable(); @@ -367,18 +392,6 @@ 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 .parseTestDisguise(Bukkit.getConsoleSender(), "disguise", disguiseArgs, DisguiseParser.getPermissions(Bukkit.getConsoleSender(), "disguise")); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java index 12d80db0..d79f1fae 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java @@ -8,6 +8,7 @@ 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.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandSender; @@ -269,6 +270,17 @@ public class DisguiseParser { return parseDisguise(sender, null, permNode, args, permissions); } + public static Disguise parseDisguise( + String disguise) throws IllegalAccessException, InvocationTargetException, DisguiseParseException { + return parseDisguise(Bukkit.getConsoleSender(), null, disguise); + } + + public static Disguise parseDisguise(CommandSender sender, Entity target, + String disguise) throws IllegalAccessException, InvocationTargetException, DisguiseParseException { + return parseDisguise(sender, target, "disguise", DisguiseUtilities.split(disguise), + new DisguisePermissions(Bukkit.getConsoleSender(), "disguise")); + } + /** * 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