From 69f34946339338bd2dba322b25227e3e473a7afc Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 8 Aug 2021 03:02:25 +1200 Subject: [PATCH] Enderman can't hold non-blocks, fixes #606 --- .../disguise/commands/DisguiseBaseCommand.java | 6 ++++++ .../disguise/disguisetypes/watchers/EndermanWatcher.java | 9 +++++++-- .../disguise/utilities/params/ParamInfoManager.java | 6 ++++++ .../disguise/utilities/params/ParamInfoTypes.java | 3 +-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index bb239fe0..10590f6c 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -17,6 +17,7 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.params.ParamInfo; import me.libraryaddict.disguise.utilities.params.ParamInfoManager; +import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemStack; import me.libraryaddict.disguise.utilities.parser.DisguiseParser; import me.libraryaddict.disguise.utilities.parser.DisguisePerm; import me.libraryaddict.disguise.utilities.parser.DisguisePermissions; @@ -181,6 +182,11 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { if (info != null && !info.isParam(boolean.class)) { addMethods = false; } + + // Enderman can't hold non-blocks + if (disguisePerm.getType() == DisguiseType.ENDERMAN && prevArg.equalsIgnoreCase("setItemInMainHand")) { + info = ParamInfoManager.getParamInfoItemBlock(); + } } // If the previous argument is a method diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java index ce911836..75311ce7 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/EndermanWatcher.java @@ -32,12 +32,17 @@ public class EndermanWatcher extends InsentientWatcher { } public void setItemInMainHand(Material type) { + if (!type.isBlock()) { + return; + } + Optional optional; - if (type == null) + if (type == null) { optional = Optional.empty(); - else + } else { optional = Optional.of(WrappedBlockData.createData(type)); + } setData(MetaIndex.ENDERMAN_ITEM, optional); sendData(MetaIndex.ENDERMAN_ITEM); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java index 4728927e..c9004eb7 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoManager.java @@ -3,6 +3,7 @@ package me.libraryaddict.disguise.utilities.params; import lombok.Getter; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; +import me.libraryaddict.disguise.disguisetypes.watchers.EndermanWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemBlock; @@ -50,6 +51,11 @@ public class ParamInfoManager { return getParamInfoSoundGroup(); } + // Enderman can't hold non-blocks + if (method.getWatcherClass() == EndermanWatcher.class && method.getName().equalsIgnoreCase("setItemInMainHand")) { + return getParamInfoItemBlock(); + } + if (method.getWatcherClass() == FallingBlockWatcher.class && (method.getParam() == Material.class || method.getParam() == ItemStack.class)) { return getParamInfoItemBlock(); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoTypes.java b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoTypes.java index 60bd429d..fe0190d3 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoTypes.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/ParamInfoTypes.java @@ -31,8 +31,7 @@ import java.util.*; */ public class ParamInfoTypes { public ParamInfoItemBlock getParamInfoBlock() { - return new ParamInfoItemBlock(ItemStack.class, "ItemStack", "ItemStack (Material,Amount?,Glow?)", - "An ItemStack compromised of Material,Amount,Glow. Only requires Material", getMaterials()); + return new ParamInfoItemBlock(ItemStack.class, "ItemStack", "ItemStack (Material)", "An ItemStack compromised of Material", getMaterials()); } public ParamInfoSoundGroup getParamInfoSoundGroup() {