From 7a0f10768709abdb5eb2f236123dece3a50aa408 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 24 Mar 2020 11:54:26 +1300 Subject: [PATCH] Fix ItemStack serializer being unable to serialize some items Fix PlayerDisguise using code I forgot to use, instead of real code --- .../disguise/disguisetypes/Disguise.java | 16 ---------------- .../disguise/disguisetypes/PlayerDisguise.java | 2 +- .../params/types/custom/ParamInfoItemStack.java | 5 +++++ .../utilities/reflection/ReflectionManager.java | 12 ++++++++++++ 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index 0ab9b31a..8bd8972d 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -62,7 +62,6 @@ public abstract class Disguise { private boolean playerHiddenFromTab = DisguiseConfig.isHideDisguisedPlayers(); private boolean replaceSounds = DisguiseConfig.isSoundEnabled(); private boolean mobsIgnoreDisguise; - private boolean showName; private transient BukkitTask task; private Runnable velocityRunnable; private boolean velocitySent = DisguiseConfig.isVelocitySent(); @@ -666,21 +665,6 @@ public abstract class Disguise { setViewSelfDisguise(selfDisguiseVisible); } - /** - * Returns true if the entity's name is showing through the disguise - * - * @return - */ - public boolean isShowName() { - return showName; - } - - public Disguise setShowName(boolean showName) { - this.showName = showName; - - return this; - } - public boolean isSoundsReplaced() { return replaceSounds; } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java index 199193c4..b02897f0 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java @@ -199,7 +199,7 @@ public class PlayerDisguise extends TargetedDisguise { name = name.substring(0, 16); } - if (isDisguiseInUse() && isShowName()) { + if (isDisguiseInUse() && isNameVisible()) { if (stopDisguise()) { playerName = name; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoItemStack.java b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoItemStack.java index 94c50396..4952bda0 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoItemStack.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoItemStack.java @@ -64,6 +64,11 @@ public class ParamInfoItemStack extends ParamInfoEnum { return name; } + // If its not a CraftItemStack + if (item.getClass().getSimpleName().equals("ItemStack") && item.hasItemMeta()) { + item = ReflectionManager.getCraftItem(item); + } + String itemName = ReflectionManager.getItemName(item.getType()); ArrayList mcArray = new ArrayList<>(); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index 1a424918..835fff85 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -18,6 +18,7 @@ import org.apache.commons.lang.StringUtils; import org.bukkit.*; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.entity.*; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -361,6 +362,17 @@ public class ReflectionManager { return null; } + public static ItemStack getCraftItem(ItemStack bukkitItem) { + try { + return (ItemStack) craftItemClass.getMethod("asCraftMirror", ItemStack.class).invoke(null, bukkitItem); + } + catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + public static NmsVersion getVersion() { if (version == null) { getBukkitVersion();