Update for reflection
This commit is contained in:
		
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -56,7 +56,7 @@ | ||||
| 		<dependency> | ||||
| 			<groupId>com.comphenix.protocol</groupId> | ||||
| 			<artifactId>ProtocolLib</artifactId> | ||||
| 			<version>2.5.0</version> | ||||
| 			<version>2.7.0</version> | ||||
| 		</dependency> | ||||
| 		<dependency> | ||||
| 			<groupId>org.bukkit</groupId> | ||||
|   | ||||
| @@ -48,7 +48,7 @@ public class DisguiseAPI { | ||||
|             disguise = disguise.clone(); | ||||
|         } | ||||
|         try { | ||||
|             Field field = net.minecraft.server.v1_6_R3.Entity.class.getDeclaredField("entityCount"); | ||||
|             Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount"); | ||||
|             field.setAccessible(true); | ||||
|             int id = field.getInt(null); | ||||
|             disguises.put(id, disguise); | ||||
| @@ -268,7 +268,7 @@ public class DisguiseAPI { | ||||
|             return; | ||||
|         try { | ||||
|             // Grab the entity ID the fake disguise will use | ||||
|             Field field = net.minecraft.server.v1_6_R3.Entity.class.getDeclaredField("entityCount"); | ||||
|             Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount"); | ||||
|             field.setAccessible(true); | ||||
|             int id = field.getInt(null); | ||||
|             // Set the entitycount plus one so we don't have the id being reused | ||||
|   | ||||
| @@ -3,7 +3,6 @@ package me.libraryaddict.disguise; | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.lang.reflect.Field; | ||||
| import java.lang.reflect.Method; | ||||
| import java.util.List; | ||||
|  | ||||
| import me.libraryaddict.disguise.commands.*; | ||||
| @@ -23,7 +22,6 @@ import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.LivingEntity; | ||||
| import org.bukkit.plugin.java.JavaPlugin; | ||||
|  | ||||
| import com.comphenix.protocol.wrappers.WrappedAttribute; | ||||
| import com.comphenix.protocol.wrappers.WrappedDataWatcher; | ||||
| import com.comphenix.protocol.wrappers.WrappedWatchableObject; | ||||
|  | ||||
| @@ -174,7 +172,8 @@ public class LibsDisguises extends JavaPlugin { | ||||
|             } | ||||
|             try { | ||||
|                 Object entity = ReflectionManager.getEntityInstance(name); | ||||
|                 Entity bukkitEntity = (Entity) entity.getClass().getMethod("getBukkitEntity").invoke(entity); | ||||
|                 Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity") | ||||
|                         .invoke(entity); | ||||
|                 int size = 0; | ||||
|                 for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) { | ||||
|                     if (field.getType().getName().equals("EnumEntitySize")) { | ||||
| @@ -188,11 +187,6 @@ public class LibsDisguises extends JavaPlugin { | ||||
|                 List<WrappedWatchableObject> watchers = dataWatcher.getWatchableObjects(); | ||||
|                 for (WrappedWatchableObject watch : watchers) | ||||
|                     value.setMetaValue(watch.getTypeID(), watch.getValue()); | ||||
|                 WrappedAttribute s; | ||||
|                 if (bukkitEntity instanceof LivingEntity) { | ||||
|                     value.setAttributesValue("generic.movementSpeed", livingEntity.getAttributeInstance(GenericAttributes.d) | ||||
|                             .getValue()); | ||||
|                 } | ||||
|                 DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); | ||||
|                 if (sound != null) { | ||||
|                     Float soundStrength = ReflectionManager.getSoundModifier(entity); | ||||
|   | ||||
| @@ -4,7 +4,6 @@ import java.lang.reflect.Field; | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collection; | ||||
| import java.util.HashMap; | ||||
| import java.util.Iterator; | ||||
| import java.util.List; | ||||
| import java.util.Random; | ||||
| @@ -18,10 +17,13 @@ import me.libraryaddict.disguise.disguisetypes.MobDisguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.Values; | ||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseSound.SoundType; | ||||
| import net.minecraft.server.v1_6_R3.*; | ||||
|  | ||||
| import org.bukkit.Art; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.craftbukkit.v1_6_R3.entity.*; | ||||
| import org.bukkit.entity.Arrow; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.ExperienceOrb; | ||||
| @@ -42,6 +44,8 @@ import com.comphenix.protocol.events.PacketContainer; | ||||
| import com.comphenix.protocol.events.PacketEvent; | ||||
| import com.comphenix.protocol.events.PacketListener; | ||||
| import com.comphenix.protocol.reflect.StructureModifier; | ||||
| import com.comphenix.protocol.wrappers.WrappedDataWatcher; | ||||
| import com.comphenix.protocol.wrappers.WrappedWatchableObject; | ||||
|  | ||||
| public class PacketsManager { | ||||
|     private static boolean cancelSound; | ||||
| @@ -131,9 +135,12 @@ public class PacketsManager { | ||||
|             org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot); | ||||
|             if (itemstack != null && itemstack.getTypeId() != 0) { | ||||
|                 ItemStack item = null; | ||||
|                 if (nmsEntity instanceof EntityLiving) | ||||
|                     item = ((EntityLiving) nmsEntity).getEquipment(i); | ||||
|                 if (item == null) { | ||||
|                 if (disguisedEntity instanceof LivingEntity) | ||||
|                     if (i != 4) | ||||
|                         item = ((LivingEntity) disguisedEntity).getEquipment().getArmorContents()[i]; | ||||
|                     else | ||||
|                         item = ((LivingEntity) disguisedEntity).getEquipment().getItemInHand(); | ||||
|                 if (item == null || item.getType() == Material.AIR) { | ||||
|                     PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_EQUIPMENT); | ||||
|                     StructureModifier<Object> mods = packet.getModifier(); | ||||
|                     mods.write(0, disguisedEntity.getEntityId()); | ||||
| @@ -171,8 +178,8 @@ public class PacketsManager { | ||||
|             mods.write(4, ((int) loc.getYaw()) % 4); | ||||
|             int id = ((MiscDisguise) disguise).getData(); | ||||
|             if (id == -1) | ||||
|                 id = new Random().nextInt(EnumArt.values().length); | ||||
|             mods.write(5, EnumArt.values()[id % EnumArt.values().length].B); | ||||
|                 id = new Random().nextInt(Art.values().length); | ||||
|             mods.write(5, ReflectionManager.getEnumArt(Art.values()[id % Art.values().length])); | ||||
|  | ||||
|             // Make the teleport packet to make it visible.. | ||||
|             spawnPackets[1] = new PacketContainer(Packets.Server.ENTITY_TELEPORT); | ||||
| @@ -202,8 +209,9 @@ public class PacketsManager { | ||||
|             } else if (disguisedEntity instanceof LivingEntity) { | ||||
|                 item = ((LivingEntity) disguisedEntity).getEquipment().getItemInHand(); | ||||
|             } | ||||
|             mods.write(8, (item == null || item.getType() == Material.AIR ? 0 : item.getTypeId()); | ||||
|             mods.write(9, createDataWatcher(nmsEntity.getDataWatcher(), disguise.getWatcher())); | ||||
|             mods.write(8, (item == null || item.getType() == Material.AIR ? 0 : item.getTypeId())); | ||||
|             spawnPackets[0].getDataWatcherModifier().write(0, | ||||
|                     createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher())); | ||||
|  | ||||
|         } else if (disguise.getType().isMob()) { | ||||
|  | ||||
| @@ -239,7 +247,8 @@ public class PacketsManager { | ||||
|             mods.write(9, (byte) (int) (loc.getPitch() * 256.0F / 360.0F)); | ||||
|             if (nmsEntity instanceof EntityLiving) | ||||
|                 mods.write(10, (byte) (int) (((EntityLiving) nmsEntity).aA * 256.0F / 360.0F)); | ||||
|             mods.write(11, createDataWatcher(nmsEntity.getDataWatcher(), disguise.getWatcher())); | ||||
|             spawnPackets[0].getDataWatcherModifier().write(0, | ||||
|                     createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher())); | ||||
|             // Theres a list sometimes written with this. But no problems have appeared! | ||||
|             // Probably just the metadata to be sent. But the next meta packet after fixes that anyways. | ||||
|  | ||||
| @@ -309,16 +318,13 @@ public class PacketsManager { | ||||
|     /** | ||||
|      * Create a new datawatcher but with the 'correct' values | ||||
|      */ | ||||
|     private static DataWatcher createDataWatcher(DataWatcher watcher, FlagWatcher flagWatcher) { | ||||
|         DataWatcher newWatcher = new DataWatcher(); | ||||
|     private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) { | ||||
|         WrappedDataWatcher newWatcher = new WrappedDataWatcher(); | ||||
|         try { | ||||
|             Field map = newWatcher.getClass().getDeclaredField("c"); | ||||
|             map.setAccessible(true); | ||||
|             HashMap c = (HashMap) map.get(newWatcher); | ||||
|             // Calling c() gets the watchable objects exactly as they are. | ||||
|             List<WatchableObject> list = watcher.c(); | ||||
|             for (WatchableObject watchableObject : flagWatcher.convert(list)) { | ||||
|                 c.put(watchableObject.a(), watchableObject); | ||||
|             List<WrappedWatchableObject> list = watcher.getWatchableObjects(); | ||||
|             for (WrappedWatchableObject watchableObject : flagWatcher.convert(list)) { | ||||
|                 newWatcher.setObject(watchableObject.getIndex(), watchableObject.getValue()); | ||||
|             } | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
| @@ -611,16 +617,16 @@ public class PacketsManager { | ||||
|  | ||||
|                         if (event.getPacketID() == Packets.Server.ENTITY_METADATA) { | ||||
|                             event.setPacket(event.getPacket().deepClone()); | ||||
|                             StructureModifier<Object> mods = event.getPacket().getModifier(); | ||||
|                             Iterator<WatchableObject> itel = ((List<WatchableObject>) mods.read(1)).iterator(); | ||||
|                             Iterator<WrappedWatchableObject> itel = event.getPacket().getWatchableCollectionModifier().read(0) | ||||
|                                     .iterator(); | ||||
|                             while (itel.hasNext()) { | ||||
|                                 WatchableObject watch = itel.next(); | ||||
|                                 if (watch.a() == 0) { | ||||
|                                     byte b = (Byte) watch.b(); | ||||
|                                 WrappedWatchableObject watch = itel.next(); | ||||
|                                 if (watch.getTypeID() == 0) { | ||||
|                                     byte b = (Byte) watch.getValue(); | ||||
|                                     byte a = (byte) (b | 1 << 5); | ||||
|                                     if ((b & 1 << 3) != 0) | ||||
|                                         a = (byte) (a | 1 << 3); | ||||
|                                     watch.a(a); | ||||
|                                     watch.setValue(a); | ||||
|                                 } | ||||
|                             } | ||||
|                         } else { | ||||
| @@ -642,7 +648,7 @@ public class PacketsManager { | ||||
|                                     byte b = (byte) (0 | 1 << 5); | ||||
|                                     if (event.getPlayer().isSprinting()) | ||||
|                                         b = (byte) (b | 1 << 3); | ||||
|                                     watchableList.add(new WatchableObject(0, 0, b)); | ||||
|                                     watchableList.add(new WrappedWatchableObject(0, b)); | ||||
|                                     mods.write(1, watchableList); | ||||
|                                     try { | ||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); | ||||
| @@ -710,7 +716,8 @@ public class PacketsManager { | ||||
|                                         org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); | ||||
|                                         if (item != null && item.getType() != Material.AIR) { | ||||
|                                             event.setPacket(event.getPacket().shallowClone()); | ||||
|                                             event.getPacket().getModifier() | ||||
|                                             event.getPacket() | ||||
|                                                     .getModifier() | ||||
|                                                     .write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); | ||||
|                                         } | ||||
|                                     } | ||||
| @@ -723,8 +730,8 @@ public class PacketsManager { | ||||
|                          */ | ||||
|                         case Packets.Server.WINDOW_ITEMS: { | ||||
|                             event.setPacket(event.getPacket().deepClone()); | ||||
|                             StructureModifier<Object> mods = event.getPacket().getModifier(); | ||||
|                             ItemStack[] items = (ItemStack[]) mods.read(1); | ||||
|                             StructureModifier<ItemStack[]> mods = event.getPacket().getItemArrayModifier(); | ||||
|                             ItemStack[] items = mods.read(0); | ||||
|                             for (int slot = 0; slot < items.length; slot++) { | ||||
|                                 if (slot >= 5 && slot <= 8) { | ||||
|                                     if (disguise.isHidingArmorFromSelf()) { | ||||
| @@ -732,7 +739,7 @@ public class PacketsManager { | ||||
|                                         int armorSlot = Math.abs((slot - 5) - 3); | ||||
|                                         org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; | ||||
|                                         if (item != null && item.getType() != Material.AIR) { | ||||
|                                             items[slot] = ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)); | ||||
|                                             items[slot] = new org.bukkit.inventory.ItemStack(0); | ||||
|                                         } | ||||
|                                     } | ||||
|                                     // Else if its a hotbar slot | ||||
| @@ -743,12 +750,13 @@ public class PacketsManager { | ||||
|                                         if (slot == currentSlot + 36) { | ||||
|                                             org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); | ||||
|                                             if (item != null && item.getType() != Material.AIR) { | ||||
|                                                 items[slot] = ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0)); | ||||
|                                                 items[slot] = new org.bukkit.inventory.ItemStack(0); | ||||
|                                             } | ||||
|                                         } | ||||
|                                     } | ||||
|                                 } | ||||
|                             } | ||||
|                             mods.write(0, items); | ||||
|                             break; | ||||
|                         } | ||||
|                         default: | ||||
| @@ -1006,7 +1014,7 @@ public class PacketsManager { | ||||
|  | ||||
|         // Resend the armor | ||||
|         for (int i = 0; i < 5; ++i) { | ||||
|             ItemStack itemstack = ((EntityLiving) tracker.tracker).getEquipment(i); | ||||
|             net.minecraft.server.v1_6_R3.ItemStack itemstack = ((EntityLiving) tracker.tracker).getEquipment(i); | ||||
|  | ||||
|             if (itemstack != null) { | ||||
|                 entityplayer.playerConnection.sendPacket(new Packet5EntityEquipment(player.getEntityId(), i, itemstack)); | ||||
| @@ -1113,22 +1121,8 @@ public class PacketsManager { | ||||
|                 case Packets.Server.UPDATE_ATTRIBUTES: | ||||
|  | ||||
|                 { | ||||
|                     // Grab the values which are 'approved' to be sent for this entity | ||||
|                     HashMap<String, Double> values = Values.getAttributesValues(disguise.getType()); | ||||
|                     Collection collection = new ArrayList<AttributeSnapshot>(); | ||||
|                     for (AttributeSnapshot att : (List<AttributeSnapshot>) sentPacket.getModifier().read(1)) { | ||||
|                         if (values.containsKey(att.a())) { | ||||
|                             collection.add(new AttributeSnapshot(null, att.a(), values.get(att.a()), att.c())); | ||||
|                         } | ||||
|                     } | ||||
|                     if (collection.size() > 0) { | ||||
|                         packets[0] = new PacketContainer(sentPacket.getID()); | ||||
|                         StructureModifier<Object> mods = packets[0].getModifier(); | ||||
|                         mods.write(0, entity.getEntityId()); | ||||
|                         mods.write(1, collection); | ||||
|                     } else { | ||||
|                         packets = new PacketContainer[0]; | ||||
|                     } | ||||
|  | ||||
|                     packets = new PacketContainer[0]; | ||||
|                     break; | ||||
|                 } | ||||
|  | ||||
| @@ -1136,12 +1130,12 @@ public class PacketsManager { | ||||
|                 case Packets.Server.ENTITY_METADATA: | ||||
|  | ||||
|                 { | ||||
|                     List<WatchableObject> watchableObjects = disguise.getWatcher().convert( | ||||
|                             (List<WatchableObject>) packets[0].getModifier().read(1)); | ||||
|                     List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert( | ||||
|                             packets[0].getWatchableCollectionModifier().read(0)); | ||||
|                     packets[0] = new PacketContainer(sentPacket.getID()); | ||||
|                     StructureModifier<Object> newMods = packets[0].getModifier(); | ||||
|                     newMods.write(0, entity.getEntityId()); | ||||
|                     newMods.write(1, watchableObjects); | ||||
|                     packets[0].getWatchableCollectionModifier().write(0, watchableObjects); | ||||
|                     break; | ||||
|                 } | ||||
|  | ||||
|   | ||||
| @@ -1,12 +1,11 @@ | ||||
| package me.libraryaddict.disguise; | ||||
|  | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.lang.reflect.Field; | ||||
| import java.lang.reflect.Method; | ||||
|  | ||||
| import net.minecraft.server.v1_6_R3.World; | ||||
|  | ||||
| import org.bukkit.Art; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack; | ||||
| import org.bukkit.Sound; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
|  | ||||
| public class ReflectionManager { | ||||
| @@ -20,18 +19,44 @@ public class ReflectionManager { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public static String getEnumArt(Art art) { | ||||
|         try { | ||||
|             Class craftArt = Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".CraftArt"); | ||||
|             Object enumArt = craftArt.getMethod("BukkitToNotch", Art.class).invoke(null, art); | ||||
|             for (Field field : enumArt.getClass().getFields()) { | ||||
|                 if (field.getType() == String.class) { | ||||
|                     return (String) field.get(enumArt); | ||||
|                 } | ||||
|             } | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     public static String getCraftSound(Sound sound) { | ||||
|         try { | ||||
|             Class c = Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".CraftSound"); | ||||
|             return (String) c.getMethod("getSound", Sound.class).invoke(null, sound); | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     public static Object getEntityInstance(String entityName) { | ||||
|         try { | ||||
|             Class entityClass = getNmsClass("Entity" + entityName); | ||||
|             Object entityObject; | ||||
|             Object world = getWorld(); | ||||
|             if (entityName.equals("Human")) { | ||||
|                 entityObject = entityClass.getConstructor(world.getClass(), String.class).newInstance(world, "LibsDisguises"); | ||||
|                 entityObject = entityClass.getConstructor(getNmsClass("World"), String.class).newInstance(world, "LibsDisguises"); | ||||
|             } else { | ||||
|                 entityObject = entityClass.getConstructor(world.getClass()).newInstance(world); | ||||
|                 entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world); | ||||
|             } | ||||
|             return entityObject; | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
| @@ -58,7 +83,9 @@ public class ReflectionManager { | ||||
|  | ||||
|     private static Object getWorld() { | ||||
|         try { | ||||
|             return World.class.getMethod("getHandle").invoke(Bukkit.getWorlds().get(0)); | ||||
|             return Class.forName("org.bukkit.craftbukkit." + bukkitVersion + ".CraftWorld").getMethod("getHandle") | ||||
|                     .invoke(Bukkit.getWorlds().get(0)); | ||||
|  | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|   | ||||
| @@ -1,25 +1,25 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes; | ||||
|  | ||||
| import java.lang.reflect.Field; | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.Iterator; | ||||
| import java.util.List; | ||||
|  | ||||
| import me.libraryaddict.disguise.DisguiseAPI; | ||||
| import me.libraryaddict.disguise.PacketsManager; | ||||
| import me.libraryaddict.disguise.ReflectionManager; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; | ||||
| import net.minecraft.server.v1_6_R3.EntityAgeable; | ||||
| import net.minecraft.server.v1_6_R3.EntityInsentient; | ||||
| import net.minecraft.server.v1_6_R3.EntityLiving; | ||||
| import net.minecraft.server.v1_6_R3.EntityPlayer; | ||||
| import net.minecraft.server.v1_6_R3.EntityTrackerEntry; | ||||
| import net.minecraft.server.v1_6_R3.WorldServer; | ||||
|  | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.Horse.Variant; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.plugin.java.JavaPlugin; | ||||
| @@ -190,10 +190,7 @@ public abstract class Disguise { | ||||
|                         i++; | ||||
|                         if (i % 40 == 0) { | ||||
|                             i = 0; | ||||
|                             List<Player> players = new ArrayList<Player>(); | ||||
|                             for (EntityPlayer p : getPerverts()) | ||||
|                                 players.add(p.getBukkitEntity()); | ||||
|                             ProtocolLibrary.getProtocolManager().updateEntity(getEntity(), players); | ||||
|                             ProtocolLibrary.getProtocolManager().updateEntity(getEntity(), getPerverts()); | ||||
|                         } | ||||
|                     } | ||||
|                     // If the vectorY isn't 0. Cos if it is. Then it doesn't want to send any vectors. | ||||
| @@ -219,35 +216,36 @@ public abstract class Disguise { | ||||
|                                 mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F)); | ||||
|                                 selfLookPacket = lookPacket.shallowClone(); | ||||
|                             } | ||||
|                             for (EntityPlayer player : getPerverts()) { | ||||
|                                 PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY); | ||||
|                                 StructureModifier<Object> mods = packet.getModifier(); | ||||
|                                 if (entity == player.getBukkitEntity()) { | ||||
|                                     if (!viewSelfDisguise()) | ||||
|                                         continue; | ||||
|                                     if (selfLookPacket != null) { | ||||
|                                         try { | ||||
|                                             ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(), | ||||
|                                                     selfLookPacket, false); | ||||
|                                         } catch (InvocationTargetException e) { | ||||
|                                             e.printStackTrace(); | ||||
|                             try { | ||||
|                                 Field ping = ReflectionManager.getNmsClass("EntityPlayer").getField("ping"); | ||||
|                                 Field handle = Entity.class.getField("getHandle"); | ||||
|                                 for (Player player : getPerverts()) { | ||||
|                                     PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY); | ||||
|                                     StructureModifier<Object> mods = packet.getModifier(); | ||||
|                                     if (entity == player) { | ||||
|                                         if (!viewSelfDisguise()) | ||||
|                                             continue; | ||||
|                                         if (selfLookPacket != null) { | ||||
|                                             try { | ||||
|                                                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, selfLookPacket, | ||||
|                                                         false); | ||||
|                                             } catch (InvocationTargetException e) { | ||||
|                                                 e.printStackTrace(); | ||||
|                                             } | ||||
|                                         } | ||||
|                                     } | ||||
|                                     mods.write(0, DisguiseAPI.getFakeDisguise(entity.getEntityId())); | ||||
|                                 } else | ||||
|                                     mods.write(0, entity.getEntityId()); | ||||
|                                 mods.write(1, (int) (vector.getX() * 8000)); | ||||
|                                 mods.write(2, (int) (8000 * (vectorY * (double) player.ping * 0.069))); | ||||
|                                 mods.write(3, (int) (vector.getZ() * 8000)); | ||||
|                                 try { | ||||
|                                         mods.write(0, DisguiseAPI.getFakeDisguise(entity.getEntityId())); | ||||
|                                     } else | ||||
|                                         mods.write(0, entity.getEntityId()); | ||||
|                                     mods.write(1, (int) (vector.getX() * 8000)); | ||||
|                                     mods.write(2, (int) (8000 * (vectorY * (double) ping.getInt(handle.get(player)) * 0.069))); | ||||
|                                     mods.write(3, (int) (vector.getZ() * 8000)); | ||||
|                                     if (lookPacket != null) | ||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(), | ||||
|                                                 lookPacket, false); | ||||
|                                     ProtocolLibrary.getProtocolManager() | ||||
|                                             .sendServerPacket(player.getBukkitEntity(), packet, false); | ||||
|                                 } catch (InvocationTargetException e) { | ||||
|                                     e.printStackTrace(); | ||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, lookPacket, false); | ||||
|                                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); | ||||
|  | ||||
|                                 } | ||||
|                             } catch (Exception e) { | ||||
|                                 e.printStackTrace(); | ||||
|                             } | ||||
|                         } | ||||
|                         // If we need to send more packets because else it still 'sinks' | ||||
| @@ -255,10 +253,10 @@ public abstract class Disguise { | ||||
|                             PacketContainer packet = new PacketContainer(Packets.Server.REL_ENTITY_MOVE); | ||||
|                             StructureModifier<Object> mods = packet.getModifier(); | ||||
|                             mods.write(0, entity.getEntityId()); | ||||
|                             for (EntityPlayer player : getPerverts()) { | ||||
|                             for (Player player : getPerverts()) { | ||||
|                                 if (DisguiseAPI.isViewDisguises() || entity != player) { | ||||
|                                     try { | ||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(), packet); | ||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||
|                                     } catch (InvocationTargetException e) { | ||||
|                                         e.printStackTrace(); | ||||
|                                     } | ||||
| @@ -281,14 +279,21 @@ public abstract class Disguise { | ||||
|     /** | ||||
|      * Get all EntityPlayers who have this entity in their Entity Tracker | ||||
|      */ | ||||
|     protected EntityPlayer[] getPerverts() { | ||||
|         EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities | ||||
|                 .get(entity.getEntityId()); | ||||
|         if (entry != null) { | ||||
|             EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]); | ||||
|             return players; | ||||
|     protected ArrayList<Player> getPerverts() { | ||||
|         ArrayList<Player> players = new ArrayList<Player>(); | ||||
|         try { | ||||
|             EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities | ||||
|                     .get(entity.getEntityId()); | ||||
|             if (entry != null) { | ||||
|                 Field field = ReflectionManager.getNmsClass("Entity").getField("getBukkitEntity"); | ||||
|                 for (Object p : entry.trackedPlayers) { | ||||
|                     players.add((Player) field.get(p)); | ||||
|                 } | ||||
|             } | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|         return new EntityPlayer[0]; | ||||
|         return players; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -3,8 +3,9 @@ package me.libraryaddict.disguise.disguisetypes; | ||||
| import java.util.HashMap; | ||||
| import java.util.HashSet; | ||||
|  | ||||
| import me.libraryaddict.disguise.ReflectionManager; | ||||
|  | ||||
| import org.bukkit.Sound; | ||||
| import org.bukkit.craftbukkit.v1_6_R3.CraftSound; | ||||
|  | ||||
| /** | ||||
|  * Only living disguises go in here! | ||||
| @@ -103,10 +104,6 @@ public enum DisguiseSound { | ||||
|         CANCEL, DEATH, HURT, IDLE, STEP; | ||||
|     } | ||||
|  | ||||
|     public static String getSoundName(Sound sound) { | ||||
|         return CraftSound.getSound(sound); | ||||
|     } | ||||
|  | ||||
|     public static DisguiseSound getType(String name) { | ||||
|         try { | ||||
|             return valueOf(name); | ||||
| @@ -128,7 +125,7 @@ public enum DisguiseSound { | ||||
|             else if (obj instanceof String) | ||||
|                 s = (String) obj; | ||||
|             else if (obj instanceof Sound) | ||||
|                 s = CraftSound.getSound((Sound) obj); | ||||
|                 s = ReflectionManager.getCraftSound((Sound) obj); | ||||
|             else | ||||
|                 throw new RuntimeException("Was given a unknown object " + obj); | ||||
|             switch (i) { | ||||
| @@ -195,7 +192,7 @@ public enum DisguiseSound { | ||||
|     } | ||||
|  | ||||
|     public void removeSound(SoundType type, Sound sound) { | ||||
|         removeSound(type, CraftSound.getSound(sound)); | ||||
|         removeSound(type, ReflectionManager.getCraftSound(sound)); | ||||
|     } | ||||
|  | ||||
|     public void removeSound(SoundType type, String sound) { | ||||
| @@ -211,7 +208,7 @@ public enum DisguiseSound { | ||||
|     } | ||||
|  | ||||
|     public void setSound(SoundType type, Sound sound) { | ||||
|         setSound(type, CraftSound.getSound(sound)); | ||||
|         setSound(type, ReflectionManager.getCraftSound(sound)); | ||||
|     } | ||||
|  | ||||
|     public void setSound(SoundType type, String sound) { | ||||
|   | ||||
| @@ -7,7 +7,6 @@ import java.util.HashSet; | ||||
| import java.util.Iterator; | ||||
| import java.util.List; | ||||
|  | ||||
| import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.LivingEntity; | ||||
| import org.bukkit.entity.Player; | ||||
| @@ -17,14 +16,11 @@ import com.comphenix.protocol.Packets; | ||||
| import com.comphenix.protocol.ProtocolLibrary; | ||||
| import com.comphenix.protocol.events.PacketContainer; | ||||
| import com.comphenix.protocol.reflect.StructureModifier; | ||||
| import com.comphenix.protocol.wrappers.WrappedWatchableObject; | ||||
|  | ||||
| import me.libraryaddict.disguise.DisguiseAPI; | ||||
| import me.libraryaddict.disguise.PacketsManager; | ||||
| import me.libraryaddict.disguise.ReflectionManager; | ||||
| import net.minecraft.server.v1_6_R3.ChunkCoordinates; | ||||
| import net.minecraft.server.v1_6_R3.EntityPlayer; | ||||
| import net.minecraft.server.v1_6_R3.ItemStack; | ||||
| import net.minecraft.server.v1_6_R3.WatchableObject; | ||||
|  | ||||
| public class FlagWatcher { | ||||
|     public enum SlotType { | ||||
| @@ -40,16 +36,6 @@ public class FlagWatcher { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static HashMap<Class, Integer> classTypes = new HashMap<Class, Integer>(); | ||||
|     static { | ||||
|         classTypes.put(Byte.class, 0); | ||||
|         classTypes.put(Short.class, 1); | ||||
|         classTypes.put(Integer.class, 2); | ||||
|         classTypes.put(Float.class, 3); | ||||
|         classTypes.put(String.class, 4); | ||||
|         classTypes.put(ItemStack.class, 5); | ||||
|         classTypes.put(ChunkCoordinates.class, 6); | ||||
|     } | ||||
|     /** | ||||
|      * This is the entity values I need to add else it could crash them.. | ||||
|      */ | ||||
| @@ -68,7 +54,6 @@ public class FlagWatcher { | ||||
|         try { | ||||
|             cloned = getClass().getConstructor(Disguise.class).newInstance(disguise); | ||||
|         } catch (Exception e) { | ||||
|             // TODO Auto-generated catch block | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone(); | ||||
| @@ -76,14 +61,14 @@ public class FlagWatcher { | ||||
|         return cloned; | ||||
|     } | ||||
|  | ||||
|     public List<WatchableObject> convert(List<WatchableObject> list) { | ||||
|         Iterator<WatchableObject> itel = list.iterator(); | ||||
|         List<WatchableObject> newList = new ArrayList<WatchableObject>(); | ||||
|     public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) { | ||||
|         Iterator<WrappedWatchableObject> itel = list.iterator(); | ||||
|         List<WrappedWatchableObject> newList = new ArrayList<WrappedWatchableObject>(); | ||||
|         HashSet<Integer> sentValues = new HashSet<Integer>(); | ||||
|         boolean sendAllCustom = false; | ||||
|         while (itel.hasNext()) { | ||||
|             WatchableObject watch = itel.next(); | ||||
|             int dataType = watch.a(); | ||||
|             WrappedWatchableObject watch = itel.next(); | ||||
|             int dataType = watch.getTypeID(); | ||||
|             sentValues.add(dataType); | ||||
|             // Its sending the air metadata. This is the least commonly sent metadata which all entitys still share. | ||||
|             // I send my custom values if I see this! | ||||
| @@ -100,15 +85,15 @@ public class FlagWatcher { | ||||
|                 value = backupEntityValues.get(dataType); | ||||
|             } | ||||
|             if (value != null) { | ||||
|                 boolean doD = watch.d(); | ||||
|                 watch = new WatchableObject(classTypes.get(value.getClass()), dataType, value); | ||||
|                 boolean doD = watch.getDirtyState(); | ||||
|                 watch = new WrappedWatchableObject(dataType, value); | ||||
|                 if (!doD) | ||||
|                     watch.a(false); | ||||
|                     watch.setDirtyState(doD); | ||||
|             } else { | ||||
|                 boolean doD = watch.d(); | ||||
|                 watch = new WatchableObject(watch.c(), dataType, watch.b()); | ||||
|                 boolean doD = watch.getDirtyState(); | ||||
|                 watch = new WrappedWatchableObject(dataType, watch.getValue()); | ||||
|                 if (!doD) | ||||
|                     watch.a(false); | ||||
|                     watch.setDirtyState(doD); | ||||
|             } | ||||
|             newList.add(watch); | ||||
|         } | ||||
| @@ -120,16 +105,16 @@ public class FlagWatcher { | ||||
|                 Object obj = entityValues.get(value); | ||||
|                 if (obj == null) | ||||
|                     continue; | ||||
|                 WatchableObject watch = new WatchableObject(classTypes.get(obj.getClass()), value, obj); | ||||
|                 WrappedWatchableObject watch = new WrappedWatchableObject(value, obj); | ||||
|                 newList.add(watch); | ||||
|             } | ||||
|         } | ||||
|         // Here we check for if there is a health packet that says they died. | ||||
|         if (disguise.viewSelfDisguise() && disguise.getEntity() != null && disguise.getEntity() instanceof Player) { | ||||
|             for (WatchableObject watch : newList) { | ||||
|             for (WrappedWatchableObject watch : newList) { | ||||
|                 // Its a health packet | ||||
|                 if (watch.a() == 6) { | ||||
|                     Object value = watch.b(); | ||||
|                 if (watch.getTypeID() == 6) { | ||||
|                     Object value = watch.getValue(); | ||||
|                     if (value != null && value instanceof Float) { | ||||
|                         float newHealth = (Float) value; | ||||
|                         if (newHealth > 0 && hasDied) { | ||||
| @@ -210,17 +195,16 @@ public class FlagWatcher { | ||||
|             return; | ||||
|         Entity entity = disguise.getEntity(); | ||||
|         Object value = entityValues.get(data); | ||||
|         List<WatchableObject> list = new ArrayList<WatchableObject>(); | ||||
|         list.add(new WatchableObject(classTypes.get(value.getClass()), data, value)); | ||||
|         List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>(); | ||||
|         list.add(new WrappedWatchableObject(data, value)); | ||||
|         PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA); | ||||
|         StructureModifier<Object> mods = packet.getModifier(); | ||||
|         mods.write(0, entity.getEntityId()); | ||||
|         mods.write(1, list); | ||||
|         for (EntityPlayer player : disguise.getPerverts()) { | ||||
|             Player p = player.getBukkitEntity(); | ||||
|             if (DisguiseAPI.isViewDisguises() || p != entity) { | ||||
|         packet.getWatchableCollectionModifier().write(0, list); | ||||
|         for (Player player : disguise.getPerverts()) { | ||||
|             if (DisguiseAPI.isViewDisguises() || player != entity) { | ||||
|                 try { | ||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet); | ||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||
|                 } catch (InvocationTargetException e) { | ||||
|                     e.printStackTrace(); | ||||
|                 } | ||||
| @@ -277,7 +261,7 @@ public class FlagWatcher { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         ItemStack itemToSend = null; | ||||
|         Object itemToSend = null; | ||||
|         if (itemStack != null && itemStack.getTypeId() != 0) | ||||
|             itemToSend = ReflectionManager.getNmsItem(itemStack); | ||||
|         items[slot] = itemStack; | ||||
| @@ -291,11 +275,10 @@ public class FlagWatcher { | ||||
|         mods.write(0, disguise.getEntity().getEntityId()); | ||||
|         mods.write(1, slot); | ||||
|         mods.write(2, itemToSend); | ||||
|         for (EntityPlayer player : disguise.getPerverts()) { | ||||
|             Player p = player.getBukkitEntity(); | ||||
|             if (p != disguise.getEntity()) { | ||||
|         for (Player player : disguise.getPerverts()) { | ||||
|             if (player != disguise.getEntity()) { | ||||
|                 try { | ||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet); | ||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||
|                 } catch (InvocationTargetException e) { | ||||
|                     e.printStackTrace(); | ||||
|                 } | ||||
|   | ||||
| @@ -2,15 +2,13 @@ package me.libraryaddict.disguise.disguisetypes; | ||||
|  | ||||
| import java.util.HashMap; | ||||
|  | ||||
| import net.minecraft.server.v1_6_R3.EnumEntitySize; | ||||
|  | ||||
| public class Values { | ||||
|  | ||||
|     private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>(); | ||||
|  | ||||
|     public static HashMap<String, Double> getAttributesValues(DisguiseType type) { | ||||
|    /* public static HashMap<String, Double> getAttributesValues(DisguiseType type) { | ||||
|         return getValues(type).getAttributesValues(); | ||||
|     } | ||||
|     }*/ | ||||
|  | ||||
|     public static Class getEntityClass(DisguiseType type) { | ||||
|         return getValues(type).getEntityClass(); | ||||
| @@ -47,7 +45,7 @@ public class Values { | ||||
|         return values.get(type); | ||||
|     } | ||||
|  | ||||
|     private HashMap<String, Double> attributesValues = new HashMap<String, Double>(); | ||||
|   //  private HashMap<String, Double> attributesValues = new HashMap<String, Double>(); | ||||
|  | ||||
|     private Class declared; | ||||
|     private int enumEntitySize; | ||||
| @@ -60,9 +58,9 @@ public class Values { | ||||
|         declared = classType; | ||||
|     } | ||||
|  | ||||
|     public HashMap<String, Double> getAttributesValues() { | ||||
|     /*public HashMap<String, Double> getAttributesValues() { | ||||
|         return attributesValues; | ||||
|     } | ||||
|     }*/ | ||||
|  | ||||
|     public Class getEntityClass() { | ||||
|         return declared; | ||||
| @@ -115,9 +113,9 @@ public class Values { | ||||
|         return metaValues; | ||||
|     } | ||||
|  | ||||
|     public void setAttributesValue(String attribute, Double value) { | ||||
|     /*public void setAttributesValue(String attribute, Double value) { | ||||
|         attributesValues.put(attribute, value); | ||||
|     } | ||||
|     }*/ | ||||
|  | ||||
|     public void setMetaValue(int no, Object value) { | ||||
|         metaValues.put(no, value); | ||||
|   | ||||
| @@ -4,7 +4,6 @@ import me.libraryaddict.disguise.ReflectionManager; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||
|  | ||||
| import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
|  | ||||
| public class DroppedItemWatcher extends FlagWatcher { | ||||
| @@ -14,8 +13,7 @@ public class DroppedItemWatcher extends FlagWatcher { | ||||
|     } | ||||
|  | ||||
|     public ItemStack getItemStack() { | ||||
|         return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R3.ItemStack) getValue(10, | ||||
|                 ReflectionManager.getNmsItem(new ItemStack(1)))); | ||||
|         return ReflectionManager.getBukkitItem(getValue(10, ReflectionManager.getNmsItem(new ItemStack(1)))); | ||||
|     } | ||||
|  | ||||
|     public void setItemStack(ItemStack item) { | ||||
|   | ||||
| @@ -4,7 +4,6 @@ import me.libraryaddict.disguise.ReflectionManager; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||
|  | ||||
| import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
|  | ||||
| public class ItemFrameWatcher extends FlagWatcher { | ||||
| @@ -20,7 +19,7 @@ public class ItemFrameWatcher extends FlagWatcher { | ||||
|     public ItemStack getItemStack() { | ||||
|         if (getValue(2, null) == null) | ||||
|             return new ItemStack(0); | ||||
|         return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R3.ItemStack) getValue(2, null)); | ||||
|         return ReflectionManager.getBukkitItem(getValue(2, null)); | ||||
|     } | ||||
|  | ||||
|     public void setItemRotation(int rotation) { | ||||
|   | ||||
| @@ -1,18 +1,38 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | ||||
|  | ||||
| import java.lang.reflect.Method; | ||||
| import java.util.HashSet; | ||||
| import java.util.Iterator; | ||||
|  | ||||
| import me.libraryaddict.disguise.ReflectionManager; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||
| import net.minecraft.server.v1_6_R3.MobEffect; | ||||
| import net.minecraft.server.v1_6_R3.PotionBrewer; | ||||
|  | ||||
| import org.bukkit.potion.PotionEffect; | ||||
| import org.bukkit.potion.PotionEffectType; | ||||
|  | ||||
| public class LivingWatcher extends FlagWatcher { | ||||
|     private HashSet<MobEffect> potionEffects = new HashSet<MobEffect>(); | ||||
|     private HashSet<Integer> potionEffects = new HashSet<Integer>(); | ||||
|     static Object[] list; | ||||
|     static Method potionNo; | ||||
|     static { | ||||
|         try { | ||||
|             Class mobEffectList = ReflectionManager.getNmsClass("MobEffectList"); | ||||
|             list = (Object[]) mobEffectList.getField("byId").get(null); | ||||
|             for (Object obj : list) { | ||||
|                 if (obj != null) { | ||||
|                     for (Method field : obj.getClass().getMethods()) { | ||||
|                         if (field.getReturnType() == int.class) { | ||||
|                             if ((Integer) field.invoke(obj) > 10000) { | ||||
|                                 potionNo = field; | ||||
|                                 break; | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public LivingWatcher(Disguise disguise) { | ||||
|         super(disguise); | ||||
| @@ -22,21 +42,21 @@ public class LivingWatcher extends FlagWatcher { | ||||
|     public void addPotionEffect(PotionEffect potionEffect) { | ||||
|         if (hasPotionEffect(potionEffect.getType())) | ||||
|             removePotionEffect(potionEffect.getType()); | ||||
|         potionEffects.add(new MobEffect(potionEffect.getType().getId(), potionEffect.getDuration(), potionEffect.getAmplifier())); | ||||
|         potionEffects.add(potionEffect.getType().getId()); | ||||
|         sendPotionEffects(); | ||||
|     } | ||||
|  | ||||
|     public void addPotionEffect(PotionEffectType potionEffect) { | ||||
|         if (hasPotionEffect(potionEffect)) | ||||
|             removePotionEffect(potionEffect); | ||||
|         potionEffects.add(new MobEffect(potionEffect.getId(), 0, 0)); | ||||
|         potionEffects.add(potionEffect.getId()); | ||||
|         sendPotionEffects(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public LivingWatcher clone(Disguise disguise) { | ||||
|         LivingWatcher clone = (LivingWatcher) super.clone(disguise); | ||||
|         clone.potionEffects = (HashSet<MobEffect>) potionEffects.clone(); | ||||
|         clone.potionEffects = (HashSet<Integer>) potionEffects.clone(); | ||||
|         return clone; | ||||
|     } | ||||
|  | ||||
| @@ -57,10 +77,7 @@ public class LivingWatcher extends FlagWatcher { | ||||
|     } | ||||
|  | ||||
|     public boolean hasPotionEffect(PotionEffectType type) { | ||||
|         for (MobEffect effect : potionEffects) | ||||
|             if (effect.getEffectId() == type.getId()) | ||||
|                 return true; | ||||
|         return false; | ||||
|         return potionEffects.contains(type.getId()); | ||||
|     } | ||||
|  | ||||
|     public boolean isCustomNameVisible() { | ||||
| @@ -68,14 +85,9 @@ public class LivingWatcher extends FlagWatcher { | ||||
|     } | ||||
|  | ||||
|     public void removePotionEffect(PotionEffectType type) { | ||||
|         Iterator<MobEffect> itel = potionEffects.iterator(); | ||||
|         while (itel.hasNext()) { | ||||
|             MobEffect effect = itel.next(); | ||||
|             if (effect.getEffectId() == type.getId()) { | ||||
|                 itel.remove(); | ||||
|                 sendPotionEffects(); | ||||
|                 return; | ||||
|             } | ||||
|         if (potionEffects.contains(type.getId())) { | ||||
|             potionEffects.remove(type.getId()); | ||||
|             sendPotionEffects(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -85,10 +97,40 @@ public class LivingWatcher extends FlagWatcher { | ||||
|     } | ||||
|  | ||||
|     private void sendPotionEffects() { | ||||
|         setValue(7, PotionBrewer.a(potionEffects)); | ||||
|         setValue(7, getPotions()); | ||||
|         sendData(7); | ||||
|     } | ||||
|  | ||||
|     private int getPotions() { | ||||
|         int m = 3694022; | ||||
|  | ||||
|         if (potionEffects.isEmpty()) { | ||||
|             return m; | ||||
|         } | ||||
|  | ||||
|         float f1 = 0.0F; | ||||
|         float f2 = 0.0F; | ||||
|         float f3 = 0.0F; | ||||
|         float f4 = 0.0F; | ||||
|         try { | ||||
|             for (int localMobEffect : potionEffects) { | ||||
|                 int n = (Integer) potionNo.invoke(list[localMobEffect]); | ||||
|                 f1 += (n >> 16 & 0xFF) / 255.0F; | ||||
|                 f2 += (n >> 8 & 0xFF) / 255.0F; | ||||
|                 f3 += (n >> 0 & 0xFF) / 255.0F; | ||||
|                 f4 += 1.0F; | ||||
|             } | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|  | ||||
|         f1 = f1 / f4 * 255.0F; | ||||
|         f2 = f2 / f4 * 255.0F; | ||||
|         f3 = f3 / f4 * 255.0F; | ||||
|  | ||||
|         return (int) f1 << 16 | (int) f2 << 8 | (int) f3; | ||||
|     } | ||||
|  | ||||
|     public void setCustomName(String name) { | ||||
|         if (name.length() > 64) | ||||
|             name = name.substring(0, 64); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user