From 061161dad73e81910b16225453dd2e2ca4c35e6d Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 25 Feb 2020 15:20:44 +1300 Subject: [PATCH] Add modifyDisguise to DisguiseParser for api usage, deprecate 'constructDisguise' --- .../libraryaddict/disguise/DisguiseAPI.java | 2 ++ .../utilities/parser/DisguiseParser.java | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java index a2ca5c42..64f4ad8e 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java @@ -87,10 +87,12 @@ public class DisguiseAPI { return disguise.getValue(); } + @Deprecated public static Disguise constructDisguise(Entity entity) { return constructDisguise(entity, true, true, true); } + @Deprecated public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doSneak, boolean doSprint) { DisguiseType disguiseType = DisguiseType.getType(entity); Disguise 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 eaf3ffbc..ee8f927e 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java @@ -9,6 +9,7 @@ import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.TranslateType; +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -508,6 +509,32 @@ public class DisguiseParser { return parseDisguise(sender, null, permNode, args, permissions); } + public static void modifyDisguise(Disguise disguise, Entity target, + String[] params) throws IllegalAccessException, DisguiseParseException, InvocationTargetException { + if (target != null) { + params = DisguiseParser.parsePlaceholders(params, target, target); + } + + DisguiseParser.callMethods(Bukkit.getConsoleSender(), disguise, + new DisguisePermissions(Bukkit.getConsoleSender(), "disguise"), new DisguisePerm(disguise.getType()), + new ArrayList<>(), params, "Disguise"); + } + + public static void modifyDisguise(Disguise disguise, + String[] params) throws IllegalAccessException, InvocationTargetException, DisguiseParseException { + modifyDisguise(disguise, null, params); + } + + public static void modifyDisguise(Disguise disguise, + String params) throws IllegalAccessException, DisguiseParseException, InvocationTargetException { + modifyDisguise(disguise, DisguiseUtilities.split(params)); + } + + public static void modifyDisguise(Disguise disguise, Entity target, + String params) throws IllegalAccessException, InvocationTargetException, DisguiseParseException { + modifyDisguise(disguise, target, DisguiseUtilities.split(params)); + } + public static Disguise parseDisguise( String disguise) throws IllegalAccessException, InvocationTargetException, DisguiseParseException { return parseDisguise(Bukkit.getConsoleSender(), null, disguise);