Fixed falling block disguise, fixed velocity when flying
This commit is contained in:
		| @@ -112,15 +112,7 @@ public abstract class Disguise { | |||||||
|         final boolean alwaysSendVelocity; |         final boolean alwaysSendVelocity; | ||||||
|  |  | ||||||
|         switch (getType()) { |         switch (getType()) { | ||||||
|             case EGG: |  | ||||||
|             case ENDER_PEARL: |  | ||||||
|             case BAT: |  | ||||||
|             case EXPERIENCE_ORB: |             case EXPERIENCE_ORB: | ||||||
|             case FIREBALL: |  | ||||||
|             case SMALL_FIREBALL: |  | ||||||
|             case SNOWBALL: |  | ||||||
|             case SPLASH_POTION: |  | ||||||
|             case THROWN_EXP_BOTTLE: |  | ||||||
|             case WITHER_SKULL: |             case WITHER_SKULL: | ||||||
|             case FIREWORK: |             case FIREWORK: | ||||||
|                 alwaysSendVelocity = true; |                 alwaysSendVelocity = true; | ||||||
| @@ -130,55 +122,21 @@ public abstract class Disguise { | |||||||
|                 break; |                 break; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         double velocitySpeed = 0.0005; |         final Double vectorY; | ||||||
|  |  | ||||||
|         switch (getType()) { |         switch (getType()) { | ||||||
|             case FIREWORK: |             case FIREWORK: | ||||||
|                 velocitySpeed = -0.040; |  | ||||||
|                 break; |  | ||||||
|             case WITHER_SKULL: |             case WITHER_SKULL: | ||||||
|                 velocitySpeed = 0.000001D; |                 vectorY = 0.000001D; | ||||||
|                 break; |  | ||||||
|             case ARROW: |  | ||||||
|             case TIPPED_ARROW: |  | ||||||
|             case SPECTRAL_ARROW: |  | ||||||
|             case BOAT: |  | ||||||
|             case ENDER_CRYSTAL: |  | ||||||
|             case ENDER_DRAGON: |  | ||||||
|             case GHAST: |  | ||||||
|             case ITEM_FRAME: |  | ||||||
|             case MINECART: |  | ||||||
|             case MINECART_CHEST: |  | ||||||
|             case MINECART_COMMAND: |  | ||||||
|             case MINECART_FURNACE: |  | ||||||
|             case MINECART_HOPPER: |  | ||||||
|             case MINECART_MOB_SPAWNER: |  | ||||||
|             case MINECART_TNT: |  | ||||||
|             case PAINTING: |  | ||||||
|             case PLAYER: |  | ||||||
|             case SQUID: |  | ||||||
|                 velocitySpeed = 0; |  | ||||||
|                 break; |  | ||||||
|             case DROPPED_ITEM: |  | ||||||
|             case PRIMED_TNT: |  | ||||||
|             case WITHER: |  | ||||||
|             case FALLING_BLOCK: |  | ||||||
|                 velocitySpeed = 0.04; |  | ||||||
|                 break; |                 break; | ||||||
|             case EXPERIENCE_ORB: |             case EXPERIENCE_ORB: | ||||||
|                 velocitySpeed = 0.0221; |                 vectorY = 0.0221; | ||||||
|                 break; |  | ||||||
|             case SPIDER: |  | ||||||
|             case BAT: |  | ||||||
|             case CAVE_SPIDER: |  | ||||||
|                 velocitySpeed = 0.004; |  | ||||||
|                 break; |                 break; | ||||||
|             default: |             default: | ||||||
|  |                 vectorY = null; | ||||||
|                 break; |                 break; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         final double vectorY = velocitySpeed; |  | ||||||
|  |  | ||||||
|         final TargetedDisguise disguise = (TargetedDisguise) this; |         final TargetedDisguise disguise = (TargetedDisguise) this; | ||||||
|  |  | ||||||
|         // A scheduler to clean up any unused disguises. |         // A scheduler to clean up any unused disguises. | ||||||
| @@ -190,9 +148,9 @@ public abstract class Disguise { | |||||||
|             @Override |             @Override | ||||||
|             public void run() { |             public void run() { | ||||||
|                 // If entity is no longer valid. Remove it. |                 // If entity is no longer valid. Remove it. | ||||||
|                 if (getEntity() instanceof Player && !((Player) getEntity()).isOnline()) |                 if (getEntity() instanceof Player && !((Player) getEntity()).isOnline()) { | ||||||
|                     removeDisguise(); |                     removeDisguise(); | ||||||
|                 else if (!getEntity().isValid()) { |                 } else if (!getEntity().isValid()) { | ||||||
|                     // If it has been dead for 30+ ticks |                     // If it has been dead for 30+ ticks | ||||||
|                     // This is to ensure that this disguise isn't removed while clients think its the real entity |                     // This is to ensure that this disguise isn't removed while clients think its the real entity | ||||||
|                     // The delay is because if it sends the destroy entity packets straight away, then it means no |                     // The delay is because if it sends the destroy entity packets straight away, then it means no | ||||||
| @@ -251,7 +209,7 @@ public abstract class Disguise { | |||||||
|  |  | ||||||
|                     // If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors. |                     // If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors. | ||||||
|                     // If this disguise has velocity sending enabled and the entity is flying. |                     // If this disguise has velocity sending enabled and the entity is flying. | ||||||
|                     if (isVelocitySent() && vectorY != 0 && (alwaysSendVelocity || !getEntity().isOnGround())) { |                     if (isVelocitySent() && vectorY != null && (alwaysSendVelocity || !getEntity().isOnGround())) { | ||||||
|                         Vector vector = getEntity().getVelocity(); |                         Vector vector = getEntity().getVelocity(); | ||||||
|  |  | ||||||
|                         // If the entity doesn't have velocity changes already - You know. I really can't wrap my |                         // If the entity doesn't have velocity changes already - You know. I really can't wrap my | ||||||
|   | |||||||
| @@ -60,7 +60,7 @@ public enum DisguiseType { | |||||||
|  |  | ||||||
|     EXPERIENCE_ORB, |     EXPERIENCE_ORB, | ||||||
|  |  | ||||||
|     FALLING_BLOCK(70, 1), |     FALLING_BLOCK(70), | ||||||
|  |  | ||||||
|     FIREBALL(63), |     FIREBALL(63), | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,22 +19,26 @@ public class MiscDisguise extends TargetedDisguise { | |||||||
|         this(disguiseType, -1, disguiseType.getDefaultData()); |         this(disguiseType, -1, disguiseType.getDefaultData()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public MiscDisguise(Material material, int data) { |     public MiscDisguise(DisguiseType disguiseType, Material material, int data) { | ||||||
|         super(DisguiseType.DROPPED_ITEM); |         this(disguiseType, new ItemStack(material, 1, (short) data)); | ||||||
|  |  | ||||||
|         apply(0, 0, new ItemStack(material, 1, (short) data)); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public MiscDisguise(ItemStack itemStack) { |     public MiscDisguise(DisguiseType disguiseType, ItemStack itemStack) { | ||||||
|         super(DisguiseType.DROPPED_ITEM); |         super(disguiseType); | ||||||
|  |  | ||||||
|         apply(0, 0, itemStack); |         if (disguiseType != DisguiseType.FALLING_BLOCK && disguiseType != DisguiseType.DROPPED_ITEM) { | ||||||
| } |             throw new IllegalArgumentException( | ||||||
|  |                     "This constructor requires a DROPPED_ITEM or FALLING_BLOCK disguise type!"); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         apply(0, itemStack); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     public MiscDisguise(DisguiseType disguiseType, int id) { |     public MiscDisguise(DisguiseType disguiseType, int id) { | ||||||
|         this(disguiseType, id, disguiseType.getDefaultData()); |         this(disguiseType, id, disguiseType.getDefaultData()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Deprecated | ||||||
|     public MiscDisguise(DisguiseType disguiseType, int id, int data) { |     public MiscDisguise(DisguiseType disguiseType, int id, int data) { | ||||||
|         super(disguiseType); |         super(disguiseType); | ||||||
|  |  | ||||||
| @@ -45,10 +49,10 @@ public class MiscDisguise extends TargetedDisguise { | |||||||
|                             " instead"); |                             " instead"); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         apply(id, data, new ItemStack(Material.STONE)); |         apply(id, new ItemStack(Material.STONE)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void apply(int id, int data, ItemStack itemStack) { |     private void apply(int id, ItemStack itemStack) { | ||||||
|         createDisguise(); |         createDisguise(); | ||||||
|  |  | ||||||
|         this.id = getType().getTypeId(); |         this.id = getType().getTypeId(); | ||||||
|   | |||||||
| @@ -18,6 +18,7 @@ import me.libraryaddict.disguise.DisguiseAPI; | |||||||
| import me.libraryaddict.disguise.DisguiseConfig; | import me.libraryaddict.disguise.DisguiseConfig; | ||||||
| import me.libraryaddict.disguise.LibsDisguises; | import me.libraryaddict.disguise.LibsDisguises; | ||||||
| import me.libraryaddict.disguise.disguisetypes.*; | import me.libraryaddict.disguise.disguisetypes.*; | ||||||
|  | import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; | ||||||
| import me.libraryaddict.disguise.utilities.packetlisteners.*; | import me.libraryaddict.disguise.utilities.packetlisteners.*; | ||||||
| @@ -432,7 +433,9 @@ public class PacketsManager { | |||||||
|             int data = ((MiscDisguise) disguise).getData(); |             int data = ((MiscDisguise) disguise).getData(); | ||||||
|  |  | ||||||
|             if (disguise.getType() == DisguiseType.FALLING_BLOCK) { |             if (disguise.getType() == DisguiseType.FALLING_BLOCK) { | ||||||
|                 data = ReflectionManager.getCombinedId(((MiscDisguise) disguise).getId(), data); |                 ItemStack block = ((FallingBlockWatcher) disguise.getWatcher()).getBlock(); | ||||||
|  |  | ||||||
|  |                 data = ReflectionManager.getCombinedIdByItemStack(block); | ||||||
|             } else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) { |             } else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) { | ||||||
|                 // If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners |                 // If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners | ||||||
|                 // entity id |                 // entity id | ||||||
| @@ -448,6 +451,16 @@ public class PacketsManager { | |||||||
|                     .createPacket(nmsEntity, objectId, data); |                     .createPacket(nmsEntity, objectId, data); | ||||||
|             packets.addPacket(spawnEntity); |             packets.addPacket(spawnEntity); | ||||||
|  |  | ||||||
|  |             // If it's not the same type, then highly likely they have different velocity settings which we'd want to | ||||||
|  |             // cancel | ||||||
|  |             if (DisguiseType.getType(disguisedEntity) != disguise.getType()) { | ||||||
|  |                 StructureModifier<Integer> ints = spawnEntity.getIntegers(); | ||||||
|  |  | ||||||
|  |                 ints.write(1, 0); | ||||||
|  |                 ints.write(2, 0); | ||||||
|  |                 ints.write(3, 0); | ||||||
|  |             } | ||||||
|  |  | ||||||
|             spawnEntity.getModifier().write(8, pitch); |             spawnEntity.getModifier().write(8, pitch); | ||||||
|             spawnEntity.getModifier().write(9, yaw); |             spawnEntity.getModifier().write(9, yaw); | ||||||
|  |  | ||||||
| @@ -1089,7 +1102,8 @@ public class PacketsManager { | |||||||
|  |  | ||||||
|             // If the entity is sending velocity and its a falling block |             // If the entity is sending velocity and its a falling block | ||||||
|             else if (sentPacket.getType() == Server.ENTITY_VELOCITY) { |             else if (sentPacket.getType() == Server.ENTITY_VELOCITY) { | ||||||
|                 if (disguise.getType() == DisguiseType.FALLING_BLOCK) { |                 // If the disguise is a misc and the disguised is not the same type | ||||||
|  |                 if (disguise.getType().isMisc() && DisguiseType.getType(entity) != disguise.getType()) { | ||||||
|                     packets.clear(); |                     packets.clear(); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -833,33 +833,13 @@ public class ReflectionManager { | |||||||
|             return ((Double) value).floatValue(); |             return ((Double) value).floatValue(); | ||||||
|         } else if (value instanceof NbtWrapper) { |         } else if (value instanceof NbtWrapper) { | ||||||
|             return ((NbtWrapper) value).getHandle(); |             return ((NbtWrapper) value).getHandle(); | ||||||
|         } else if (value instanceof Particle) { |         } else if (value instanceof WrappedParticle) { | ||||||
|             return getParticleType((Particle) value); |             return ((WrappedParticle) value).getHandle(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return value; |         return value; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private static Object getParticleType(Particle particle) { |  | ||||||
|         try { |  | ||||||
|             Class craftParticle = getCraftClass("CraftParticle"); |  | ||||||
|             Field mcKeyField = craftParticle.getDeclaredField("minecraftKey"); |  | ||||||
|             mcKeyField.setAccessible(true); |  | ||||||
|             Object mcKey = mcKeyField.get(Enum.valueOf(craftParticle, particle.name())); |  | ||||||
|  |  | ||||||
|             Class typesClass = getNmsClass("IRegistry"); |  | ||||||
|  |  | ||||||
|             Object registry = typesClass.getField("PARTICLE_TYPE").get(null); |  | ||||||
|  |  | ||||||
|             return registry.getClass().getMethod("get", mcKey.getClass()).invoke(registry, mcKey); |  | ||||||
|         } |  | ||||||
|         catch (Exception e) { |  | ||||||
|             e.printStackTrace(); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return null; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public static String getMinecraftVersion() { |     public static String getMinecraftVersion() { | ||||||
|         String version = Bukkit.getVersion(); |         String version = Bukkit.getVersion(); | ||||||
|         version = version.substring(version.lastIndexOf(" ") + 1, version.length() - 1); |         version = version.substring(version.lastIndexOf(" ") + 1, version.length() - 1); | ||||||
| @@ -979,10 +959,6 @@ public class ReflectionManager { | |||||||
|         return new WrappedWatchableObject(watcherItem); |         return new WrappedWatchableObject(watcherItem); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static int getCombinedId(int id, int data) { |  | ||||||
|         return id + (data << 12); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public static int getCombinedIdByItemStack(ItemStack itemStack) { |     public static int getCombinedIdByItemStack(ItemStack itemStack) { | ||||||
|         try { |         try { | ||||||
|             Object nmsItem = getNmsItem(itemStack); |             Object nmsItem = getNmsItem(itemStack); | ||||||
| @@ -991,7 +967,9 @@ public class ReflectionManager { | |||||||
|  |  | ||||||
|             Object nmsBlock = getNmsMethod(blockClass, "asBlock", getNmsClass("Item")).invoke(null, item); |             Object nmsBlock = getNmsMethod(blockClass, "asBlock", getNmsClass("Item")).invoke(null, item); | ||||||
|  |  | ||||||
|             return (int) getNmsMethod(blockClass, "getBlockData").invoke(nmsBlock); |             Object iBlockData = getNmsMethod(blockClass, "getBlockData").invoke(nmsBlock); | ||||||
|  |  | ||||||
|  |             return (int) getNmsMethod("Block", "getCombinedId", getNmsClass("IBlockData")).invoke(null, iBlockData); | ||||||
|         } |         } | ||||||
|         catch (Exception ex) { |         catch (Exception ex) { | ||||||
|             ex.printStackTrace(); |             ex.printStackTrace(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user