From d98333f0f169aa3576d151fd27861049bac29ece Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 5 Jul 2016 17:01:51 +1200 Subject: [PATCH] Fix null, fixed FlagWatchers, fixed typo on EquipmentSlot --- .../disguise/DisguiseListener.java | 3 ++ .../disguise/disguisetypes/Disguise.java | 2 +- .../disguise/disguisetypes/FlagType.java | 18 ++++++---- .../watchers/ArmorStandWatcher.java | 33 +++++++++---------- .../disguise/utilities/DisguiseUtilities.java | 3 ++ .../disguise/utilities/ReflectionManager.java | 2 +- 6 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index 44220d03..92b63c38 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -152,6 +152,9 @@ public class DisguiseListener implements Listener { for (TargetedDisguise disguise : list) { + if (disguise.getEntity() == null) + continue; + if (!disguise.isPlayerDisguise()) continue; diff --git a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java index 4cb273ea..be940ee5 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -53,7 +53,7 @@ public abstract class Disguise private boolean keepDisguisePlayerLogout = DisguiseConfig.isKeepDisguiseOnPlayerLogout(); private boolean modifyBoundingBox = DisguiseConfig.isModifyBoundingBox(); private boolean replaceSounds = DisguiseConfig.isSoundEnabled(); - private BukkitTask task = null; + private BukkitTask task; private Runnable velocityRunnable; private boolean velocitySent = DisguiseConfig.isVelocitySent(); private boolean viewSelfDisguise = DisguiseConfig.isViewDisguises(); diff --git a/src/me/libraryaddict/disguise/disguisetypes/FlagType.java b/src/me/libraryaddict/disguise/disguisetypes/FlagType.java index 42dc104a..7a2baae7 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/FlagType.java +++ b/src/me/libraryaddict/disguise/disguisetypes/FlagType.java @@ -10,7 +10,7 @@ import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.block.BlockFace; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; +import org.bukkit.util.EulerAngle; import com.comphenix.protocol.wrappers.BlockPosition; import com.comphenix.protocol.wrappers.WrappedBlockData; @@ -79,19 +79,23 @@ public class FlagType public static FlagType AREA_EFFECT_RADIUS = new FlagType(AreaEffectCloudWatcher.class, 0, 0F); - public static FlagType ARMORSTAND_BODY = new FlagType(ArmorStandWatcher.class, 2, new Vector()); + public static FlagType ARMORSTAND_BODY = new FlagType(ArmorStandWatcher.class, 2, + new EulerAngle(0, 0, 0)); - public static FlagType ARMORSTAND_HEAD = new FlagType(ArmorStandWatcher.class, 1, new Vector()); + public static FlagType ARMORSTAND_HEAD = new FlagType(ArmorStandWatcher.class, 1, + new EulerAngle(0, 0, 0)); - public static FlagType ARMORSTAND_LEFT_ARM = new FlagType(ArmorStandWatcher.class, 3, new Vector()); + public static FlagType ARMORSTAND_LEFT_ARM = new FlagType(ArmorStandWatcher.class, 3, + new EulerAngle(0, 0, 0)); - public static FlagType ARMORSTAND_LEFT_LEG = new FlagType(ArmorStandWatcher.class, 5, new Vector()); + public static FlagType ARMORSTAND_LEFT_LEG = new FlagType(ArmorStandWatcher.class, 5, + new EulerAngle(0, 0, 0)); public static FlagType ARMORSTAND_META = new FlagType(ArmorStandWatcher.class, 0, (byte) 0); - public static FlagType ARMORSTAND_RIGHT_ARM = new FlagType(ArmorStandWatcher.class, 4, new Vector()); + public static FlagType ARMORSTAND_RIGHT_ARM = new FlagType(ArmorStandWatcher.class, 4, new EulerAngle(0,0,0)); - public static FlagType ARMORSTAND_RIGHT_LEG = new FlagType(ArmorStandWatcher.class, 6, new Vector()); + public static FlagType ARMORSTAND_RIGHT_LEG = new FlagType(ArmorStandWatcher.class, 6, new EulerAngle(0,0,0)); public static FlagType ARROW_CRITICAL = new FlagType(ArrowWatcher.class, 0, (byte) 0); diff --git a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java index 75310a7b..6435c4da 100644 --- a/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java +++ b/src/me/libraryaddict/disguise/disguisetypes/watchers/ArmorStandWatcher.java @@ -1,7 +1,6 @@ package me.libraryaddict.disguise.disguisetypes.watchers; -import org.bukkit.util.Vector; - +import org.bukkit.util.EulerAngle; import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.FlagType; @@ -17,40 +16,40 @@ public class ArmorStandWatcher extends LivingWatcher return (getValue(FlagType.ARMORSTAND_META) & value) != 0; } - public Vector getBody() + public EulerAngle getBody() { return getPose(FlagType.ARMORSTAND_BODY); } - public Vector getHead() + public EulerAngle getHead() { return getPose(FlagType.ARMORSTAND_HEAD); } - public Vector getLeftArm() + public EulerAngle getLeftArm() { return getPose(FlagType.ARMORSTAND_LEFT_ARM); } - public Vector getLeftLeg() + public EulerAngle getLeftLeg() { return getPose(FlagType.ARMORSTAND_LEFT_LEG); } - private Vector getPose(FlagType type) + private EulerAngle getPose(FlagType type) { if (!hasValue(type)) - setValue(type, new Vector()); + setValue(type, new EulerAngle(0, 0, 0)); return getValue(type); } - public Vector getRightArm() + public EulerAngle getRightArm() { return getPose(FlagType.ARMORSTAND_RIGHT_ARM); } - public Vector getRightLeg() + public EulerAngle getRightLeg() { return getPose(FlagType.ARMORSTAND_RIGHT_LEG); } @@ -97,22 +96,22 @@ public class ArmorStandWatcher extends LivingWatcher sendData(FlagType.ARMORSTAND_META); } - public void setBody(Vector vector) + public void setBody(EulerAngle vector) { setPose(FlagType.ARMORSTAND_BODY, vector); } - public void setHead(Vector vector) + public void setHead(EulerAngle vector) { setPose(FlagType.ARMORSTAND_HEAD, vector); } - public void setLeftArm(Vector vector) + public void setLeftArm(EulerAngle vector) { setPose(FlagType.ARMORSTAND_LEFT_ARM, vector); } - public void setLeftLeg(Vector vector) + public void setLeftLeg(EulerAngle vector) { setPose(FlagType.ARMORSTAND_LEFT_LEG, vector); } @@ -135,18 +134,18 @@ public class ArmorStandWatcher extends LivingWatcher sendData(FlagType.ARMORSTAND_META); } - private void setPose(FlagType type, Vector vector) + private void setPose(FlagType type, EulerAngle vector) { setValue(type, vector); sendData(type); } - public void setRightArm(Vector vector) + public void setRightArm(EulerAngle vector) { setPose(FlagType.ARMORSTAND_RIGHT_ARM, vector); } - public void setRightLeg(Vector vector) + public void setRightLeg(EulerAngle vector) { setPose(FlagType.ARMORSTAND_RIGHT_LEG, vector); } diff --git a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 5630ee29..77125abe 100644 --- a/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -606,6 +606,9 @@ public class DisguiseUtilities if (mainThread != Thread.currentThread()) throw new IllegalStateException("Cannot modify disguises on an async thread"); + if (disguise.getEntity() == null) + throw new IllegalStateException("The entity for the disguisetype " + disguise.getType().name() + " is null!"); + List players = new ArrayList<>(); try diff --git a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java index 8c4066c3..9c590349 100644 --- a/src/me/libraryaddict/disguise/utilities/ReflectionManager.java +++ b/src/me/libraryaddict/disguise/utilities/ReflectionManager.java @@ -831,7 +831,7 @@ public class ReflectionManager case "CHEST": return EquipmentSlot.CHEST; case "HEAD": - return EquipmentSlot.HAND; + return EquipmentSlot.HEAD; } } catch (Exception e)