9
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										9
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -56,15 +56,10 @@ | |||||||
| 		<dependency> | 		<dependency> | ||||||
| 			<groupId>com.comphenix.protocol</groupId> | 			<groupId>com.comphenix.protocol</groupId> | ||||||
| 			<artifactId>ProtocolLib</artifactId> | 			<artifactId>ProtocolLib</artifactId> | ||||||
| 			<version>2.5.0</version> | 			<version>2.7.0</version> | ||||||
| 		</dependency> |  | ||||||
| 		<dependency> |  | ||||||
| 			<groupId>org.bukkit</groupId> |  | ||||||
| 			<artifactId>craftbukkit</artifactId> |  | ||||||
| 			<version>1.6.4-R2.1-SNAPSHOT</version> |  | ||||||
| 		</dependency> | 		</dependency> | ||||||
| 	</dependencies> | 	</dependencies> | ||||||
| 	<version>7.7.0</version> | 	<version>7.7.0-SNAPSHOT</version> | ||||||
|  |  | ||||||
| 	<distributionManagement> | 	<distributionManagement> | ||||||
| 		<repository> | 		<repository> | ||||||
|   | |||||||
| @@ -23,6 +23,10 @@ import org.bukkit.permissions.PermissionAttachmentInfo; | |||||||
| import org.bukkit.potion.PotionEffectType; | import org.bukkit.potion.PotionEffectType; | ||||||
|  |  | ||||||
| public abstract class BaseDisguiseCommand implements CommandExecutor { | public abstract class BaseDisguiseCommand implements CommandExecutor { | ||||||
|  |     protected ArrayList<String> getAllowedDisguises(CommandSender sender) { | ||||||
|  |         String permissionNode = "libsdisguises." + getClass().getSimpleName().replace("Command", "").toLowerCase() + "."; | ||||||
|  |         return getAllowedDisguises(sender, permissionNode); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     protected ArrayList<String> getAllowedDisguises(CommandSender sender, String permissionNode) { |     protected ArrayList<String> getAllowedDisguises(CommandSender sender, String permissionNode) { | ||||||
|         ArrayList<String> names = new ArrayList<String>(); |         ArrayList<String> names = new ArrayList<String>(); | ||||||
| @@ -117,8 +121,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { | |||||||
|      * disguise has been feed a proper disguisetype. |      * disguise has been feed a proper disguisetype. | ||||||
|      */ |      */ | ||||||
|     protected Disguise parseDisguise(CommandSender sender, String[] args) throws Exception { |     protected Disguise parseDisguise(CommandSender sender, String[] args) throws Exception { | ||||||
|         String permissionNode = "libsdisguises." + getClass().getSimpleName().replace("Command", "").toLowerCase() + "."; |         ArrayList<String> allowedDisguises = getAllowedDisguises(sender); | ||||||
|         ArrayList<String> allowedDisguises = getAllowedDisguises(sender, permissionNode); |  | ||||||
|         if (allowedDisguises.isEmpty()) { |         if (allowedDisguises.isEmpty()) { | ||||||
|             throw new Exception(ChatColor.RED + "You are forbidden to use this command."); |             throw new Exception(ChatColor.RED + "You are forbidden to use this command."); | ||||||
|         } |         } | ||||||
| @@ -345,7 +348,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { | |||||||
|             for (HashSet<String> perms : optionPermissions) { |             for (HashSet<String> perms : optionPermissions) { | ||||||
|                 if (!perms.containsAll(usedOptions)) { |                 if (!perms.containsAll(usedOptions)) { | ||||||
|                     throw new Exception(ChatColor.RED + "You do not have the permission to use the option " |                     throw new Exception(ChatColor.RED + "You do not have the permission to use the option " | ||||||
|                             + usedOptions.iterator().next()); |                             + usedOptions.toArray(new String[usedOptions.size()])[usedOptions.size() - 1]); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -1,17 +1,15 @@ | |||||||
| package me.libraryaddict.disguise; | package me.libraryaddict.disguise; | ||||||
|  |  | ||||||
| import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||||
|  | import java.lang.reflect.Method; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
|  | import java.util.HashSet; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.events.DisguiseEvent; | import me.libraryaddict.disguise.events.DisguiseEvent; | ||||||
| import me.libraryaddict.disguise.events.UndisguiseEvent; | import me.libraryaddict.disguise.events.UndisguiseEvent; | ||||||
| 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.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity; |  | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer; |  | ||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  |  | ||||||
| @@ -19,6 +17,7 @@ import com.comphenix.protocol.Packets; | |||||||
| import com.comphenix.protocol.ProtocolLibrary; | import com.comphenix.protocol.ProtocolLibrary; | ||||||
| import com.comphenix.protocol.events.PacketContainer; | import com.comphenix.protocol.events.PacketContainer; | ||||||
| import com.comphenix.protocol.reflect.StructureModifier; | import com.comphenix.protocol.reflect.StructureModifier; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedDataWatcher; | ||||||
|  |  | ||||||
| public class DisguiseAPI { | public class DisguiseAPI { | ||||||
|  |  | ||||||
| @@ -48,7 +47,7 @@ public class DisguiseAPI { | |||||||
|             disguise = disguise.clone(); |             disguise = disguise.clone(); | ||||||
|         } |         } | ||||||
|         try { |         try { | ||||||
|             Field field = net.minecraft.server.v1_6_R3.Entity.class.getDeclaredField("entityCount"); |             Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount"); | ||||||
|             field.setAccessible(true); |             field.setAccessible(true); | ||||||
|             int id = field.getInt(null); |             int id = field.getInt(null); | ||||||
|             disguises.put(id, disguise); |             disguises.put(id, disguise); | ||||||
| @@ -166,17 +165,29 @@ public class DisguiseAPI { | |||||||
|      *            the entity to all the watching players, which is where the magic begins |      *            the entity to all the watching players, which is where the magic begins | ||||||
|      */ |      */ | ||||||
|     private static void refreshTrackers(Entity entity) { |     private static void refreshTrackers(Entity entity) { | ||||||
|         EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities |         try { | ||||||
|                 .get(entity.getEntityId()); |             Object world = ReflectionManager.getWorld(entity.getWorld()); | ||||||
|         if (entry != null) { |             Object tracker = world.getClass().getField("tracker").get(world); | ||||||
|             EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]); |             Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker); | ||||||
|             for (EntityPlayer player : players) { |             Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class) | ||||||
|                 if (entity instanceof Player && !player.getBukkitEntity().canSee((Player) entity)) |                     .invoke(trackedEntities, entity.getEntityId()); | ||||||
|  |             if (entityTrackerEntry != null) { | ||||||
|  |                 HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") | ||||||
|  |                         .get(entityTrackerEntry); | ||||||
|  |                 Method getBukkitEntity = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity"); | ||||||
|  |                 Method clear = entityTrackerEntry.getClass().getMethod("clear", ReflectionManager.getNmsClass("EntityPlayer")); | ||||||
|  |                 Method updatePlayer = entityTrackerEntry.getClass().getMethod("updatePlayer", | ||||||
|  |                         ReflectionManager.getNmsClass("EntityPlayer")); | ||||||
|  |                 for (Object player : trackedPlayers) { | ||||||
|  |                     if (entity instanceof Player && !((Player) getBukkitEntity.invoke(player)).canSee((Player) entity)) | ||||||
|                         continue; |                         continue; | ||||||
|                 entry.clear(player); |                     clear.invoke(entityTrackerEntry, player); | ||||||
|                 entry.updatePlayer(player); |                     updatePlayer.invoke(entityTrackerEntry, player); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             ex.printStackTrace(); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private static void removeSelfDisguise(Player player) { |     private static void removeSelfDisguise(Player player) { | ||||||
| @@ -192,18 +203,26 @@ public class DisguiseAPI { | |||||||
|             // Remove the fake entity ID from the disguise bin |             // Remove the fake entity ID from the disguise bin | ||||||
|             selfDisguisesIds.remove(player.getEntityId()); |             selfDisguisesIds.remove(player.getEntityId()); | ||||||
|             // Get the entity tracker |             // Get the entity tracker | ||||||
|             EntityPlayer entityplayer = ((CraftPlayer) player).getHandle(); |             try { | ||||||
|             EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) entityplayer.world).tracker.trackedEntities |                 Object world = ReflectionManager.getWorld(player.getWorld()); | ||||||
|                     .get(player.getEntityId()); |                 Object tracker = world.getClass().getField("tracker").get(world); | ||||||
|  |                 Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker); | ||||||
|  |                 Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class) | ||||||
|  |                         .invoke(trackedEntities, player.getEntityId()); | ||||||
|  |                 if (entityTrackerEntry != null) { | ||||||
|  |                     HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") | ||||||
|  |                             .get(entityTrackerEntry); | ||||||
|                     // If the tracker exists. Remove himself from his tracker |                     // If the tracker exists. Remove himself from his tracker | ||||||
|             if (tracker != null) { |                     trackedPlayers.remove(ReflectionManager.getNmsEntity(player)); | ||||||
|                 tracker.trackedPlayers.remove(entityplayer); |  | ||||||
|                 } |                 } | ||||||
|             // Resend entity metadata else he will be invisible to himself until its resent |             } catch (Exception ex) { | ||||||
|  |                 ex.printStackTrace(); | ||||||
|  |             }// Resend entity metadata else he will be invisible to himself until its resent | ||||||
|             PacketContainer packetMetadata = new PacketContainer(Packets.Server.ENTITY_METADATA); |             PacketContainer packetMetadata = new PacketContainer(Packets.Server.ENTITY_METADATA); | ||||||
|             StructureModifier<Object> mods = packetMetadata.getModifier(); |             StructureModifier<Object> mods = packetMetadata.getModifier(); | ||||||
|             mods.write(0, player.getEntityId()); |             mods.write(0, player.getEntityId()); | ||||||
|             mods.write(1, entityplayer.getDataWatcher().c()); |             packetMetadata.getWatchableCollectionModifier().write(0, | ||||||
|  |                     WrappedDataWatcher.getEntityWatcher(player).getWatchableObjects()); | ||||||
|             try { |             try { | ||||||
|                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetMetadata); |                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetMetadata); | ||||||
|             } catch (Exception ex) { |             } catch (Exception ex) { | ||||||
| @@ -268,7 +287,7 @@ public class DisguiseAPI { | |||||||
|             return; |             return; | ||||||
|         try { |         try { | ||||||
|             // Grab the entity ID the fake disguise will use |             // 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); |             field.setAccessible(true); | ||||||
|             int id = field.getInt(null); |             int id = field.getInt(null); | ||||||
|             // Set the entitycount plus one so we don't have the id being reused |             // 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.File; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||||
| import java.lang.reflect.Method; |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.commands.*; | import me.libraryaddict.disguise.commands.*; | ||||||
| @@ -14,42 +13,19 @@ import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | |||||||
| import me.libraryaddict.disguise.disguisetypes.Values; | import me.libraryaddict.disguise.disguisetypes.Values; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; | ||||||
| import net.minecraft.server.v1_6_R3.ChatMessage; |  | ||||||
| import net.minecraft.server.v1_6_R3.ChunkCoordinates; |  | ||||||
| import net.minecraft.server.v1_6_R3.Entity; |  | ||||||
| import net.minecraft.server.v1_6_R3.EntityHuman; |  | ||||||
| import net.minecraft.server.v1_6_R3.EntityLiving; |  | ||||||
| import net.minecraft.server.v1_6_R3.GenericAttributes; |  | ||||||
| import net.minecraft.server.v1_6_R3.WatchableObject; |  | ||||||
| import net.minecraft.server.v1_6_R3.World; |  | ||||||
|  |  | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.configuration.file.FileConfiguration; | import org.bukkit.configuration.file.FileConfiguration; | ||||||
| import org.bukkit.configuration.file.YamlConfiguration; | import org.bukkit.configuration.file.YamlConfiguration; | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.CraftWorld; |  | ||||||
| import org.bukkit.entity.Ageable; | import org.bukkit.entity.Ageable; | ||||||
|  | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.LivingEntity; | import org.bukkit.entity.LivingEntity; | ||||||
| import org.bukkit.plugin.java.JavaPlugin; | import org.bukkit.plugin.java.JavaPlugin; | ||||||
|  |  | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedDataWatcher; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedWatchableObject; | ||||||
|  |  | ||||||
| public class LibsDisguises extends JavaPlugin { | public class LibsDisguises extends JavaPlugin { | ||||||
|     private class DisguiseHuman extends EntityHuman { |  | ||||||
|  |  | ||||||
|         public DisguiseHuman(World world) { |  | ||||||
|             super(world, "LibsDisguises"); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public boolean a(int arg0, String arg1) { |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public ChunkCoordinates b() { |  | ||||||
|             return null; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         public void sendMessage(ChatMessage arg0) { |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void onEnable() { |     public void onEnable() { | ||||||
| @@ -109,7 +85,6 @@ public class LibsDisguises extends JavaPlugin { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void registerValues() { |     private void registerValues() { | ||||||
|         World world = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle(); |  | ||||||
|         for (DisguiseType disguiseType : DisguiseType.values()) { |         for (DisguiseType disguiseType : DisguiseType.values()) { | ||||||
|             Class watcherClass = null; |             Class watcherClass = null; | ||||||
|             try { |             try { | ||||||
| @@ -196,35 +171,33 @@ public class LibsDisguises extends JavaPlugin { | |||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|             try { |             try { | ||||||
|                 net.minecraft.server.v1_6_R3.Entity entity = null; |                 Object entity = ReflectionManager.createEntityInstance(name); | ||||||
|                 Class entityClass; |                 Entity bukkitEntity = (Entity) ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity") | ||||||
|                 if (disguiseType == DisguiseType.PLAYER) { |                         .invoke(entity); | ||||||
|                     entityClass = EntityHuman.class; |                 int size = 0; | ||||||
|                     entity = new DisguiseHuman(world); |                 for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) { | ||||||
|                 } else { |                     if (field.getType().getName().equals("EnumEntitySize")) { | ||||||
|                     entityClass = Class.forName(Entity.class.getName() + name); |                         Enum a = (Enum) field.get(entity); | ||||||
|                     entity = (net.minecraft.server.v1_6_R3.Entity) entityClass.getConstructor(World.class).newInstance(world); |                         size = a.ordinal(); | ||||||
|  |                         break; | ||||||
|                     } |                     } | ||||||
|                 Values value = new Values(disguiseType, entityClass, entity.at); |  | ||||||
|                 List<WatchableObject> watchers = entity.getDataWatcher().c(); |  | ||||||
|                 for (WatchableObject watch : watchers) |  | ||||||
|                     value.setMetaValue(watch.a(), watch.b()); |  | ||||||
|                 if (entity instanceof EntityLiving) { |  | ||||||
|                     EntityLiving livingEntity = (EntityLiving) entity; |  | ||||||
|                     value.setAttributesValue(GenericAttributes.d.a(), livingEntity.getAttributeInstance(GenericAttributes.d) |  | ||||||
|                             .getValue()); |  | ||||||
|                 } |                 } | ||||||
|  |                 Values value = new Values(disguiseType, entity.getClass(), size); | ||||||
|  |                 WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity); | ||||||
|  |                 List<WrappedWatchableObject> watchers = dataWatcher.getWatchableObjects(); | ||||||
|  |                 for (WrappedWatchableObject watch : watchers) | ||||||
|  |                     value.setMetaValue(watch.getIndex(), watch.getValue()); | ||||||
|                 DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); |                 DisguiseSound sound = DisguiseSound.getType(disguiseType.name()); | ||||||
|                 if (sound != null) { |                 if (sound != null) { | ||||||
|                     Method soundStrength = EntityLiving.class.getDeclaredMethod("ba"); |                     Float soundStrength = ReflectionManager.getSoundModifier(entity); | ||||||
|                     // TODO Update this each update! |                     if (soundStrength != null) { | ||||||
|                     soundStrength.setAccessible(true); |                         sound.setDamageSoundVolume((Float) soundStrength); | ||||||
|                     sound.setDamageSoundVolume((Float) soundStrength.invoke(entity)); |  | ||||||
|                     } |                     } | ||||||
|             } catch (Exception e1) { |                 } | ||||||
|                 System.out.print("[LibsDisguises] Trouble while making values for " + name + ": " + e1.getMessage()); |             } catch (Exception ex) { | ||||||
|  |                 System.out.print("[LibsDisguises] Trouble while making values for " + name + ": " + ex.getMessage()); | ||||||
|                 System.out.print("[LibsDisguises] Please report this to LibsDisguises author"); |                 System.out.print("[LibsDisguises] Please report this to LibsDisguises author"); | ||||||
|                 e1.printStackTrace(); |                 ex.printStackTrace(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,8 +3,7 @@ package me.libraryaddict.disguise; | |||||||
| import java.lang.reflect.Field; | import java.lang.reflect.Field; | ||||||
| import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationTargetException; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Collection; | import java.util.HashSet; | ||||||
| import java.util.HashMap; |  | ||||||
| import java.util.Iterator; | import java.util.Iterator; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Random; | import java.util.Random; | ||||||
| @@ -18,47 +17,22 @@ import me.libraryaddict.disguise.disguisetypes.MobDisguise; | |||||||
| import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.Values; | import me.libraryaddict.disguise.disguisetypes.Values; | ||||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseSound.SoundType; | import me.libraryaddict.disguise.disguisetypes.DisguiseSound.SoundType; | ||||||
| import net.minecraft.server.v1_6_R3.AttributeMapServer; |  | ||||||
| import net.minecraft.server.v1_6_R3.AttributeSnapshot; |  | ||||||
| import net.minecraft.server.v1_6_R3.Block; |  | ||||||
| import net.minecraft.server.v1_6_R3.DataWatcher; |  | ||||||
| import net.minecraft.server.v1_6_R3.EntityHuman; |  | ||||||
| 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.EnumArt; |  | ||||||
| import net.minecraft.server.v1_6_R3.EnumEntitySize; |  | ||||||
| import net.minecraft.server.v1_6_R3.ItemStack; |  | ||||||
| import net.minecraft.server.v1_6_R3.MathHelper; |  | ||||||
| import net.minecraft.server.v1_6_R3.MobEffect; |  | ||||||
| import net.minecraft.server.v1_6_R3.Packet17EntityLocationAction; |  | ||||||
| import net.minecraft.server.v1_6_R3.Packet20NamedEntitySpawn; |  | ||||||
| import net.minecraft.server.v1_6_R3.Packet28EntityVelocity; |  | ||||||
| import net.minecraft.server.v1_6_R3.Packet35EntityHeadRotation; |  | ||||||
| import net.minecraft.server.v1_6_R3.Packet39AttachEntity; |  | ||||||
| import net.minecraft.server.v1_6_R3.Packet40EntityMetadata; |  | ||||||
| import net.minecraft.server.v1_6_R3.Packet41MobEffect; |  | ||||||
| import net.minecraft.server.v1_6_R3.Packet44UpdateAttributes; |  | ||||||
| import net.minecraft.server.v1_6_R3.Packet5EntityEquipment; |  | ||||||
| import net.minecraft.server.v1_6_R3.WatchableObject; |  | ||||||
| import net.minecraft.server.v1_6_R3.World; |  | ||||||
| import net.minecraft.server.v1_6_R3.WorldServer; |  | ||||||
|  |  | ||||||
|  | import org.bukkit.Art; | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.Location; | import org.bukkit.Location; | ||||||
| import org.bukkit.Material; | import org.bukkit.Material; | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity; | import org.bukkit.entity.Ageable; | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.entity.CraftLivingEntity; |  | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer; |  | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack; |  | ||||||
| import org.bukkit.entity.Arrow; | import org.bukkit.entity.Arrow; | ||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.ExperienceOrb; | import org.bukkit.entity.ExperienceOrb; | ||||||
| import org.bukkit.entity.Item; | import org.bukkit.entity.Item; | ||||||
| import org.bukkit.entity.LivingEntity; | import org.bukkit.entity.LivingEntity; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
|  | import org.bukkit.entity.Zombie; | ||||||
|  | import org.bukkit.inventory.ItemStack; | ||||||
| import org.bukkit.plugin.java.JavaPlugin; | import org.bukkit.plugin.java.JavaPlugin; | ||||||
|  | import org.bukkit.potion.PotionEffect; | ||||||
| import org.bukkit.util.Vector; | import org.bukkit.util.Vector; | ||||||
|  |  | ||||||
| import com.comphenix.protocol.Packets; | import com.comphenix.protocol.Packets; | ||||||
| @@ -71,6 +45,8 @@ import com.comphenix.protocol.events.PacketContainer; | |||||||
| import com.comphenix.protocol.events.PacketEvent; | import com.comphenix.protocol.events.PacketEvent; | ||||||
| import com.comphenix.protocol.events.PacketListener; | import com.comphenix.protocol.events.PacketListener; | ||||||
| import com.comphenix.protocol.reflect.StructureModifier; | import com.comphenix.protocol.reflect.StructureModifier; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedDataWatcher; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedWatchableObject; | ||||||
|  |  | ||||||
| public class PacketsManager { | public class PacketsManager { | ||||||
|     private static boolean cancelSound; |     private static boolean cancelSound; | ||||||
| @@ -151,7 +127,7 @@ public class PacketsManager { | |||||||
|     public static PacketContainer[] constructSpawnPackets(Disguise disguise, Entity disguisedEntity) { |     public static PacketContainer[] constructSpawnPackets(Disguise disguise, Entity disguisedEntity) { | ||||||
|         if (disguise.getEntity() == null) |         if (disguise.getEntity() == null) | ||||||
|             disguise.setEntity(disguisedEntity); |             disguise.setEntity(disguisedEntity); | ||||||
|         net.minecraft.server.v1_6_R3.Entity nmsEntity = ((CraftEntity) disguisedEntity).getHandle(); |         // net.minecraft.server.v1_6_R3.Entity nmsEntity = ((CraftEntity) disguisedEntity).getHandle(); | ||||||
|         ArrayList<PacketContainer> packets = new ArrayList<PacketContainer>(); |         ArrayList<PacketContainer> packets = new ArrayList<PacketContainer>(); | ||||||
|         for (int i = 0; i < 5; i++) { |         for (int i = 0; i < 5; i++) { | ||||||
|             int slot = i - 1; |             int slot = i - 1; | ||||||
| @@ -160,14 +136,17 @@ public class PacketsManager { | |||||||
|             org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot); |             org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot); | ||||||
|             if (itemstack != null && itemstack.getTypeId() != 0) { |             if (itemstack != null && itemstack.getTypeId() != 0) { | ||||||
|                 ItemStack item = null; |                 ItemStack item = null; | ||||||
|                 if (nmsEntity instanceof EntityLiving) |                 if (disguisedEntity instanceof LivingEntity) | ||||||
|                     item = ((EntityLiving) nmsEntity).getEquipment(i); |                     if (i != 4) | ||||||
|                 if (item == null) { |                         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); |                     PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_EQUIPMENT); | ||||||
|                     StructureModifier<Object> mods = packet.getModifier(); |                     StructureModifier<Object> mods = packet.getModifier(); | ||||||
|                     mods.write(0, disguisedEntity.getEntityId()); |                     mods.write(0, disguisedEntity.getEntityId()); | ||||||
|                     mods.write(1, i); |                     mods.write(1, i); | ||||||
|                     mods.write(2, CraftItemStack.asNMSCopy(itemstack)); |                     mods.write(2, ReflectionManager.getNmsItem(itemstack)); | ||||||
|                     packets.add(packet); |                     packets.add(packet); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
| @@ -179,7 +158,6 @@ public class PacketsManager { | |||||||
|         Location loc = disguisedEntity.getLocation().clone().add(0, getYModifier(disguisedEntity, disguise.getType()), 0); |         Location loc = disguisedEntity.getLocation().clone().add(0, getYModifier(disguisedEntity, disguise.getType()), 0); | ||||||
|         byte yaw = getYaw(disguise.getType(), DisguiseType.getType(disguise.getEntity().getType()), |         byte yaw = getYaw(disguise.getType(), DisguiseType.getType(disguise.getEntity().getType()), | ||||||
|                 (byte) (int) (loc.getYaw() * 256.0F / 360.0F)); |                 (byte) (int) (loc.getYaw() * 256.0F / 360.0F)); | ||||||
|         EnumEntitySize entitySize = Values.getValues(disguise.getType()).getEntitySize(); |  | ||||||
|  |  | ||||||
|         if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) { |         if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) { | ||||||
|  |  | ||||||
| @@ -201,8 +179,8 @@ public class PacketsManager { | |||||||
|             mods.write(4, ((int) loc.getYaw()) % 4); |             mods.write(4, ((int) loc.getYaw()) % 4); | ||||||
|             int id = ((MiscDisguise) disguise).getData(); |             int id = ((MiscDisguise) disguise).getData(); | ||||||
|             if (id == -1) |             if (id == -1) | ||||||
|                 id = new Random().nextInt(EnumArt.values().length); |                 id = new Random().nextInt(Art.values().length); | ||||||
|             mods.write(5, EnumArt.values()[id % EnumArt.values().length].B); |             mods.write(5, ReflectionManager.getEnumArt(Art.values()[id % Art.values().length])); | ||||||
|  |  | ||||||
|             // Make the teleport packet to make it visible.. |             // Make the teleport packet to make it visible.. | ||||||
|             spawnPackets[1] = new PacketContainer(Packets.Server.ENTITY_TELEPORT); |             spawnPackets[1] = new PacketContainer(Packets.Server.ENTITY_TELEPORT); | ||||||
| @@ -220,22 +198,25 @@ public class PacketsManager { | |||||||
|             StructureModifier<Object> mods = spawnPackets[0].getModifier(); |             StructureModifier<Object> mods = spawnPackets[0].getModifier(); | ||||||
|             mods.write(0, disguisedEntity.getEntityId()); |             mods.write(0, disguisedEntity.getEntityId()); | ||||||
|             mods.write(1, ((PlayerDisguise) disguise).getName()); |             mods.write(1, ((PlayerDisguise) disguise).getName()); | ||||||
|             mods.write(2, (int) Math.floor(loc.getX() * 32)); |             mods.write(2, ((PlayerDisguise) disguise).getName()); | ||||||
|             mods.write(3, (int) Math.floor(loc.getY() * 32)); |             mods.write(3, (int) Math.floor(loc.getX() * 32)); | ||||||
|             mods.write(4, (int) Math.floor(loc.getZ() * 32)); |             mods.write(4, (int) Math.floor(loc.getY() * 32)); | ||||||
|             mods.write(5, yaw); |             mods.write(5, (int) Math.floor(loc.getZ() * 32)); | ||||||
|             mods.write(6, (byte) (int) (loc.getPitch() * 256F / 360F)); |             mods.write(6, yaw); | ||||||
|  |             mods.write(7, (byte) (int) (loc.getPitch() * 256F / 360F)); | ||||||
|             ItemStack item = null; |             ItemStack item = null; | ||||||
|             if (disguisedEntity instanceof Player && ((Player) disguisedEntity).getItemInHand() != null) { |             if (disguisedEntity instanceof Player && ((Player) disguisedEntity).getItemInHand() != null) { | ||||||
|                 item = CraftItemStack.asNMSCopy(((Player) disguisedEntity).getItemInHand()); |                 item = ((Player) disguisedEntity).getItemInHand(); | ||||||
|             } else if (disguisedEntity instanceof LivingEntity) { |             } else if (disguisedEntity instanceof LivingEntity) { | ||||||
|                 item = CraftItemStack.asNMSCopy(((CraftLivingEntity) disguisedEntity).getEquipment().getItemInHand()); |                 item = ((LivingEntity) disguisedEntity).getEquipment().getItemInHand(); | ||||||
|             } |             } | ||||||
|             mods.write(7, (item == null ? 0 : item.id)); |             mods.write(8, (item == null || item.getType() == Material.AIR ? 0 : item.getTypeId())); | ||||||
|             mods.write(8, createDataWatcher(nmsEntity.getDataWatcher(), disguise.getWatcher())); |             spawnPackets[0].getDataWatcherModifier().write(0, | ||||||
|  |                     createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher())); | ||||||
|  |  | ||||||
|         } else if (disguise.getType().isMob()) { |         } else if (disguise.getType().isMob()) { | ||||||
|  |  | ||||||
|  |             Values values = Values.getValues(disguise.getType()); | ||||||
|             Vector vec = disguisedEntity.getVelocity(); |             Vector vec = disguisedEntity.getVelocity(); | ||||||
|             spawnPackets[0] = new PacketContainer(Packets.Server.MOB_SPAWN); |             spawnPackets[0] = new PacketContainer(Packets.Server.MOB_SPAWN); | ||||||
|             StructureModifier<Object> mods = spawnPackets[0].getModifier(); |             StructureModifier<Object> mods = spawnPackets[0].getModifier(); | ||||||
| @@ -257,17 +238,18 @@ public class PacketsManager { | |||||||
|                 d3 = d1; |                 d3 = d1; | ||||||
|             if (d4 > d1) |             if (d4 > d1) | ||||||
|                 d4 = d1; |                 d4 = d1; | ||||||
|             mods.write(2, entitySize.a(loc.getX())); |             mods.write(2, values.getEntitySize(loc.getX())); | ||||||
|             mods.write(3, (int) Math.floor(loc.getY() * 32D)); |             mods.write(3, (int) Math.floor(loc.getY() * 32D)); | ||||||
|             mods.write(4, entitySize.a(loc.getZ())); |             mods.write(4, values.getEntitySize(loc.getZ())); | ||||||
|             mods.write(5, (int) (d2 * 8000.0D)); |             mods.write(5, (int) (d2 * 8000.0D)); | ||||||
|             mods.write(6, (int) (d3 * 8000.0D)); |             mods.write(6, (int) (d3 * 8000.0D)); | ||||||
|             mods.write(7, (int) (d4 * 8000.0D)); |             mods.write(7, (int) (d4 * 8000.0D)); | ||||||
|             mods.write(8, yaw); |             mods.write(8, yaw); | ||||||
|             mods.write(9, (byte) (int) (loc.getPitch() * 256.0F / 360.0F)); |             mods.write(9, (byte) (int) (loc.getPitch() * 256.0F / 360.0F)); | ||||||
|             if (nmsEntity instanceof EntityLiving) |             // if (nmsEntity instanceof EntityLiving) | ||||||
|                 mods.write(10, (byte) (int) (((EntityLiving) nmsEntity).aA * 256.0F / 360.0F)); |             // 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! |             // 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. |             // Probably just the metadata to be sent. But the next meta packet after fixes that anyways. | ||||||
|  |  | ||||||
| @@ -318,7 +300,7 @@ public class PacketsManager { | |||||||
|                 mods.write(5, (int) (d2 * 8000.0D)); |                 mods.write(5, (int) (d2 * 8000.0D)); | ||||||
|                 mods.write(6, (int) (d3 * 8000.0D)); |                 mods.write(6, (int) (d3 * 8000.0D)); | ||||||
|             } |             } | ||||||
|             mods.write(7, (int) MathHelper.floor(loc.getPitch() * 256.0F / 360.0F)); |             mods.write(7, (int) Math.floor(loc.getPitch() * 256.0F / 360.0F)); | ||||||
|             mods.write(8, yaw); |             mods.write(8, yaw); | ||||||
|             mods.write(9, id); |             mods.write(9, id); | ||||||
|             mods.write(10, data); |             mods.write(10, data); | ||||||
| @@ -337,16 +319,13 @@ public class PacketsManager { | |||||||
|     /** |     /** | ||||||
|      * Create a new datawatcher but with the 'correct' values |      * Create a new datawatcher but with the 'correct' values | ||||||
|      */ |      */ | ||||||
|     private static DataWatcher createDataWatcher(DataWatcher watcher, FlagWatcher flagWatcher) { |     private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) { | ||||||
|         DataWatcher newWatcher = new DataWatcher(); |         WrappedDataWatcher newWatcher = new WrappedDataWatcher(); | ||||||
|         try { |         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. |             // Calling c() gets the watchable objects exactly as they are. | ||||||
|             List<WatchableObject> list = watcher.c(); |             List<WrappedWatchableObject> list = watcher.getWatchableObjects(); | ||||||
|             for (WatchableObject watchableObject : flagWatcher.convert(list)) { |             for (WrappedWatchableObject watchableObject : flagWatcher.convert(list)) { | ||||||
|                 c.put(watchableObject.a(), watchableObject); |                 newWatcher.setObject(watchableObject.getIndex(), watchableObject.getValue()); | ||||||
|             } |             } | ||||||
|         } catch (Exception ex) { |         } catch (Exception ex) { | ||||||
|             ex.printStackTrace(); |             ex.printStackTrace(); | ||||||
| @@ -463,13 +442,18 @@ public class PacketsManager { | |||||||
|                                         soundType = SoundType.DEATH; |                                         soundType = SoundType.DEATH; | ||||||
|                                     } else { |                                     } else { | ||||||
|                                         boolean hasInvun = false; |                                         boolean hasInvun = false; | ||||||
|  |                                         Object nmsEntity = ReflectionManager.getNmsEntity(entity); | ||||||
|  |                                         try { | ||||||
|                                             if (entity instanceof LivingEntity) { |                                             if (entity instanceof LivingEntity) { | ||||||
|                                             net.minecraft.server.v1_6_R3.EntityLiving e = ((CraftLivingEntity) entity) |                                                 Class entityClass = ReflectionManager.getNmsClass("Entity"); | ||||||
|                                                     .getHandle(); |                                                 hasInvun = entityClass.getField("noDamageTicks").getInt(nmsEntity) == entityClass | ||||||
|                                             hasInvun = (e.noDamageTicks == e.maxNoDamageTicks); |                                                         .getField("maxNoDamageTicks").getInt(nmsEntity); | ||||||
|                                             } else { |                                             } else { | ||||||
|                                             net.minecraft.server.v1_6_R3.Entity e = ((CraftEntity) entity).getHandle(); |                                                 hasInvun = (Boolean) ReflectionManager.getNmsClass("Entity") | ||||||
|                                             hasInvun = e.isInvulnerable(); |                                                         .getMethod("isInvulnerable").invoke(nmsEntity); | ||||||
|  |                                             } | ||||||
|  |                                         } catch (Exception ex) { | ||||||
|  |                                             ex.printStackTrace(); | ||||||
|                                         } |                                         } | ||||||
|                                         soundType = entitySound.getType(soundName, !hasInvun); |                                         soundType = entitySound.getType(soundName, !hasInvun); | ||||||
|                                     } |                                     } | ||||||
| @@ -493,11 +477,18 @@ public class PacketsManager { | |||||||
|                                     event.setCancelled(true); |                                     event.setCancelled(true); | ||||||
|                                 } else { |                                 } else { | ||||||
|                                     if (sound.equals("step.grass")) { |                                     if (sound.equals("step.grass")) { | ||||||
|                                         World world = ((CraftEntity) disguisedEntity).getHandle().world; |                                         try { | ||||||
|                                         Block b = Block.byId[world.getTypeId(soundLoc.getBlockX(), soundLoc.getBlockY() - 1, |                                             int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(), | ||||||
|                                                 soundLoc.getBlockZ())]; |                                                     soundLoc.getBlockY() - 1, soundLoc.getBlockZ()); | ||||||
|                                         if (b != null) |                                             Class blockClass = ReflectionManager.getNmsClass("Block"); | ||||||
|                                             mods.write(0, b.stepSound.getStepSound()); |                                             Object block = ((Object[]) blockClass.getField("byId").get(null))[typeId]; | ||||||
|  |                                             if (block != null) { | ||||||
|  |                                                 Object step = blockClass.getField("stepSound").get(block); | ||||||
|  |                                                 mods.write(0, step.getClass().getMethod("getStepSound").invoke(step)); | ||||||
|  |                                             } | ||||||
|  |                                         } catch (Exception ex) { | ||||||
|  |                                             ex.printStackTrace(); | ||||||
|  |                                         } | ||||||
|                                         // There is no else statement. Because seriously. This should never be null. Unless |                                         // There is no else statement. Because seriously. This should never be null. Unless | ||||||
|                                         // someone is |                                         // someone is | ||||||
|                                         // sending fake sounds. In which case. Why cancel it. |                                         // sending fake sounds. In which case. Why cancel it. | ||||||
| @@ -514,7 +505,12 @@ public class PacketsManager { | |||||||
|                                             // Here I assume its the default pitch as I can't calculate if its real. |                                             // Here I assume its the default pitch as I can't calculate if its real. | ||||||
|                                             if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity |                                             if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity | ||||||
|                                                     && ((MobDisguise) disguise).doesDisguiseAge()) { |                                                     && ((MobDisguise) disguise).doesDisguiseAge()) { | ||||||
|                                                 boolean baby = ((CraftLivingEntity) disguisedEntity).getHandle().isBaby(); |                                                 boolean baby = false; | ||||||
|  |                                                 if (disguisedEntity instanceof Zombie) { | ||||||
|  |                                                     baby = ((Zombie) disguisedEntity).isBaby(); | ||||||
|  |                                                 } else if (disguisedEntity instanceof Ageable) { | ||||||
|  |                                                     baby = !((Ageable) disguisedEntity).isAdult(); | ||||||
|  |                                                 } | ||||||
|                                                 if (((MobDisguise) disguise).isAdult() == baby) { |                                                 if (((MobDisguise) disguise).isAdult() == baby) { | ||||||
|  |  | ||||||
|                                                     float pitch = (Integer) mods.read(5); |                                                     float pitch = (Integer) mods.read(5); | ||||||
| @@ -552,7 +548,7 @@ public class PacketsManager { | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                 } else if (event.getPacketID() == Packets.Server.ENTITY_STATUS) { |                 } else if (event.getPacketID() == Packets.Server.ENTITY_STATUS) { | ||||||
|                     if ((Byte) mods.read(1) == 2) { |                     if ((Byte) mods.read(1) == 1) { | ||||||
|                         // It made a damage animation |                         // It made a damage animation | ||||||
|                         Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0); |                         Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0); | ||||||
|                         Disguise disguise = DisguiseAPI.getDisguise(entity); |                         Disguise disguise = DisguiseAPI.getDisguise(entity); | ||||||
| @@ -616,7 +612,7 @@ public class PacketsManager { | |||||||
|                 Packets.Server.REL_ENTITY_MOVE_LOOK, Packets.Server.ENTITY_LOOK, Packets.Server.ENTITY_TELEPORT, |                 Packets.Server.REL_ENTITY_MOVE_LOOK, Packets.Server.ENTITY_LOOK, Packets.Server.ENTITY_TELEPORT, | ||||||
|                 Packets.Server.ENTITY_HEAD_ROTATION, Packets.Server.ENTITY_METADATA, Packets.Server.ENTITY_EQUIPMENT, |                 Packets.Server.ENTITY_HEAD_ROTATION, Packets.Server.ENTITY_METADATA, Packets.Server.ENTITY_EQUIPMENT, | ||||||
|                 Packets.Server.ARM_ANIMATION, Packets.Server.ENTITY_LOCATION_ACTION, Packets.Server.MOB_EFFECT, |                 Packets.Server.ARM_ANIMATION, Packets.Server.ENTITY_LOCATION_ACTION, Packets.Server.MOB_EFFECT, | ||||||
|                 Packets.Server.ENTITY_STATUS, Packets.Server.ENTITY_VELOCITY, Packets.Server.UPDATE_ATTRIBUTES) { |                 Packets.Server.ENTITY_VELOCITY, Packets.Server.UPDATE_ATTRIBUTES) { | ||||||
|             @Override |             @Override | ||||||
|             public void onPacketSending(PacketEvent event) { |             public void onPacketSending(PacketEvent event) { | ||||||
|                 StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(event.getPlayer().getWorld()); |                 StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(event.getPlayer().getWorld()); | ||||||
| @@ -639,16 +635,16 @@ public class PacketsManager { | |||||||
|  |  | ||||||
|                         if (event.getPacketID() == Packets.Server.ENTITY_METADATA) { |                         if (event.getPacketID() == Packets.Server.ENTITY_METADATA) { | ||||||
|                             event.setPacket(event.getPacket().deepClone()); |                             event.setPacket(event.getPacket().deepClone()); | ||||||
|                             StructureModifier<Object> mods = event.getPacket().getModifier(); |                             Iterator<WrappedWatchableObject> itel = event.getPacket().getWatchableCollectionModifier().read(0) | ||||||
|                             Iterator<WatchableObject> itel = ((List<WatchableObject>) mods.read(1)).iterator(); |                                     .iterator(); | ||||||
|                             while (itel.hasNext()) { |                             while (itel.hasNext()) { | ||||||
|                                 WatchableObject watch = itel.next(); |                                 WrappedWatchableObject watch = itel.next(); | ||||||
|                                 if (watch.a() == 0) { |                                 if (watch.getIndex() == 0) { | ||||||
|                                     byte b = (Byte) watch.b(); |                                     byte b = (Byte) watch.getValue(); | ||||||
|                                     byte a = (byte) (b | 1 << 5); |                                     byte a = (byte) (b | 1 << 5); | ||||||
|                                     if ((b & 1 << 3) != 0) |                                     if ((b & 1 << 3) != 0) | ||||||
|                                         a = (byte) (a | 1 << 3); |                                         a = (byte) (a | 1 << 3); | ||||||
|                                     watch.a(a); |                                     watch.setValue(a); | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
|                         } else { |                         } else { | ||||||
| @@ -666,12 +662,12 @@ public class PacketsManager { | |||||||
|                                     PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA); |                                     PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA); | ||||||
|                                     StructureModifier<Object> mods = packet.getModifier(); |                                     StructureModifier<Object> mods = packet.getModifier(); | ||||||
|                                     mods.write(0, entity.getEntityId()); |                                     mods.write(0, entity.getEntityId()); | ||||||
|                                     List watchableList = new ArrayList(); |                                     List<WrappedWatchableObject> watchableList = new ArrayList<WrappedWatchableObject>(); | ||||||
|                                     byte b = (byte) (0 | 1 << 5); |                                     byte b = (byte) (0 | 1 << 5); | ||||||
|                                     if (event.getPlayer().isSprinting()) |                                     if (event.getPlayer().isSprinting()) | ||||||
|                                         b = (byte) (b | 1 << 3); |                                         b = (byte) (b | 1 << 3); | ||||||
|                                     watchableList.add(new WatchableObject(0, 0, b)); |                                     watchableList.add(new WrappedWatchableObject(0, b)); | ||||||
|                                     mods.write(1, watchableList); |                                     packet.getWatchableCollectionModifier().write(0, watchableList); | ||||||
|                                     try { |                                     try { | ||||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); |                                         ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); | ||||||
|                                     } catch (Exception ex) { |                                     } catch (Exception ex) { | ||||||
| @@ -681,12 +677,12 @@ public class PacketsManager { | |||||||
|                                 event.setCancelled(true); |                                 event.setCancelled(true); | ||||||
|                                 break; |                                 break; | ||||||
|  |  | ||||||
|                             case Packets.Server.ENTITY_STATUS: |                             /*     case Packets.Server.ENTITY_STATUS: | ||||||
|                                      if (DisguiseAPI.getDisguise(entity).canHearSelfDisguise() |                                      if (DisguiseAPI.getDisguise(entity).canHearSelfDisguise() | ||||||
|                                         && (Byte) event.getPacket().getModifier().read(1) == 2) { |                                              && (Byte) event.getPacket().getModifier().read(1) == 1) { | ||||||
|                                          event.setCancelled(true); |                                          event.setCancelled(true); | ||||||
|                                      } |                                      } | ||||||
|                                 break; |                                      break;*/ | ||||||
|                             default: |                             default: | ||||||
|                                 break; |                                 break; | ||||||
|                             } |                             } | ||||||
| @@ -726,7 +722,7 @@ public class PacketsManager { | |||||||
|                                     if (item != null && item.getType() != Material.AIR) { |                                     if (item != null && item.getType() != Material.AIR) { | ||||||
|                                         event.setPacket(event.getPacket().shallowClone()); |                                         event.setPacket(event.getPacket().shallowClone()); | ||||||
|                                         event.getPacket().getModifier() |                                         event.getPacket().getModifier() | ||||||
|                                                 .write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0))); |                                                 .write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); | ||||||
|                                     } |                                     } | ||||||
|                                 } |                                 } | ||||||
|                                 // Else if its a hotbar slot |                                 // Else if its a hotbar slot | ||||||
| @@ -738,8 +734,9 @@ public class PacketsManager { | |||||||
|                                         org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); |                                         org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); | ||||||
|                                         if (item != null && item.getType() != Material.AIR) { |                                         if (item != null && item.getType() != Material.AIR) { | ||||||
|                                             event.setPacket(event.getPacket().shallowClone()); |                                             event.setPacket(event.getPacket().shallowClone()); | ||||||
|                                             event.getPacket().getModifier() |                                             event.getPacket() | ||||||
|                                                     .write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0))); |                                                     .getModifier() | ||||||
|  |                                                     .write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); | ||||||
|                                         } |                                         } | ||||||
|                                     } |                                     } | ||||||
|                                 } |                                 } | ||||||
| @@ -751,8 +748,8 @@ public class PacketsManager { | |||||||
|                          */ |                          */ | ||||||
|                         case Packets.Server.WINDOW_ITEMS: { |                         case Packets.Server.WINDOW_ITEMS: { | ||||||
|                             event.setPacket(event.getPacket().deepClone()); |                             event.setPacket(event.getPacket().deepClone()); | ||||||
|                             StructureModifier<Object> mods = event.getPacket().getModifier(); |                             StructureModifier<ItemStack[]> mods = event.getPacket().getItemArrayModifier(); | ||||||
|                             ItemStack[] items = (ItemStack[]) mods.read(1); |                             ItemStack[] items = mods.read(0); | ||||||
|                             for (int slot = 0; slot < items.length; slot++) { |                             for (int slot = 0; slot < items.length; slot++) { | ||||||
|                                 if (slot >= 5 && slot <= 8) { |                                 if (slot >= 5 && slot <= 8) { | ||||||
|                                     if (disguise.isHidingArmorFromSelf()) { |                                     if (disguise.isHidingArmorFromSelf()) { | ||||||
| @@ -760,7 +757,7 @@ public class PacketsManager { | |||||||
|                                         int armorSlot = Math.abs((slot - 5) - 3); |                                         int armorSlot = Math.abs((slot - 5) - 3); | ||||||
|                                         org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; |                                         org.bukkit.inventory.ItemStack item = event.getPlayer().getInventory().getArmorContents()[armorSlot]; | ||||||
|                                         if (item != null && item.getType() != Material.AIR) { |                                         if (item != null && item.getType() != Material.AIR) { | ||||||
|                                             items[slot] = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)); |                                             items[slot] = new org.bukkit.inventory.ItemStack(0); | ||||||
|                                         } |                                         } | ||||||
|                                     } |                                     } | ||||||
|                                     // Else if its a hotbar slot |                                     // Else if its a hotbar slot | ||||||
| @@ -771,12 +768,13 @@ public class PacketsManager { | |||||||
|                                         if (slot == currentSlot + 36) { |                                         if (slot == currentSlot + 36) { | ||||||
|                                             org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); |                                             org.bukkit.inventory.ItemStack item = event.getPlayer().getItemInHand(); | ||||||
|                                             if (item != null && item.getType() != Material.AIR) { |                                             if (item != null && item.getType() != Material.AIR) { | ||||||
|                                                 items[slot] = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0)); |                                                 items[slot] = new org.bukkit.inventory.ItemStack(0); | ||||||
|                                             } |                                             } | ||||||
|                                         } |                                         } | ||||||
|                                     } |                                     } | ||||||
|                                 } |                                 } | ||||||
|                             } |                             } | ||||||
|  |                             mods.write(0, items); | ||||||
|                             break; |                             break; | ||||||
|                         } |                         } | ||||||
|                         default: |                         default: | ||||||
| @@ -808,7 +806,7 @@ public class PacketsManager { | |||||||
|                                         StructureModifier<Object> mods = packet.getModifier(); |                                         StructureModifier<Object> mods = packet.getModifier(); | ||||||
|                                         mods.write(0, 0); |                                         mods.write(0, 0); | ||||||
|                                         mods.write(1, slot); |                                         mods.write(1, slot); | ||||||
|                                         mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0))); |                                         mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); | ||||||
|                                         try { |                                         try { | ||||||
|                                             ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, |                                             ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, | ||||||
|                                                     false); |                                                     false); | ||||||
| @@ -827,7 +825,7 @@ public class PacketsManager { | |||||||
|                                             StructureModifier<Object> mods = packet.getModifier(); |                                             StructureModifier<Object> mods = packet.getModifier(); | ||||||
|                                             mods.write(0, 0); |                                             mods.write(0, 0); | ||||||
|                                             mods.write(1, slot); |                                             mods.write(1, slot); | ||||||
|                                             mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0))); |                                             mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); | ||||||
|                                             try { |                                             try { | ||||||
|                                                 ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, |                                                 ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, | ||||||
|                                                         false); |                                                         false); | ||||||
| @@ -854,7 +852,7 @@ public class PacketsManager { | |||||||
|                                     StructureModifier<Object> mods = packet.getModifier(); |                                     StructureModifier<Object> mods = packet.getModifier(); | ||||||
|                                     mods.write(0, 0); |                                     mods.write(0, 0); | ||||||
|                                     mods.write(1, event.getPlayer().getInventory().getHeldItemSlot() + 36); |                                     mods.write(1, event.getPlayer().getInventory().getHeldItemSlot() + 36); | ||||||
|                                     mods.write(2, CraftItemStack.asNMSCopy(currentlyHeld)); |                                     mods.write(2, ReflectionManager.getNmsItem(currentlyHeld)); | ||||||
|                                     try { |                                     try { | ||||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); |                                         ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); | ||||||
|                                     } catch (InvocationTargetException e) { |                                     } catch (InvocationTargetException e) { | ||||||
| @@ -869,7 +867,7 @@ public class PacketsManager { | |||||||
|                                     StructureModifier<Object> mods = packet.getModifier(); |                                     StructureModifier<Object> mods = packet.getModifier(); | ||||||
|                                     mods.write(0, 0); |                                     mods.write(0, 0); | ||||||
|                                     mods.write(1, event.getPacket().getIntegers().read(0) + 36); |                                     mods.write(1, event.getPacket().getIntegers().read(0) + 36); | ||||||
|                                     mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0))); |                                     mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); | ||||||
|                                     try { |                                     try { | ||||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); |                                         ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); | ||||||
|                                     } catch (InvocationTargetException e) { |                                     } catch (InvocationTargetException e) { | ||||||
| @@ -912,7 +910,7 @@ public class PacketsManager { | |||||||
|                                         StructureModifier<Object> mods = packet.getModifier(); |                                         StructureModifier<Object> mods = packet.getModifier(); | ||||||
|                                         mods.write(0, 0); |                                         mods.write(0, 0); | ||||||
|                                         mods.write(1, slot); |                                         mods.write(1, slot); | ||||||
|                                         mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0))); |                                         mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); | ||||||
|                                         try { |                                         try { | ||||||
|                                             ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, |                                             ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, | ||||||
|                                                     false); |                                                     false); | ||||||
| @@ -930,7 +928,7 @@ public class PacketsManager { | |||||||
|                                             StructureModifier<Object> mods = packet.getModifier(); |                                             StructureModifier<Object> mods = packet.getModifier(); | ||||||
|                                             mods.write(0, 0); |                                             mods.write(0, 0); | ||||||
|                                             mods.write(1, slot); |                                             mods.write(1, slot); | ||||||
|                                             mods.write(2, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(0))); |                                             mods.write(2, ReflectionManager.getNmsItem(new org.bukkit.inventory.ItemStack(0))); | ||||||
|                                             try { |                                             try { | ||||||
|                                                 ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, |                                                 ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, | ||||||
|                                                         false); |                                                         false); | ||||||
| @@ -969,10 +967,13 @@ public class PacketsManager { | |||||||
|      * Sends the self disguise to the player |      * Sends the self disguise to the player | ||||||
|      */ |      */ | ||||||
|     public static void sendSelfDisguise(final Player player) { |     public static void sendSelfDisguise(final Player player) { | ||||||
|         EntityPlayer entityplayer = ((CraftPlayer) player).getHandle(); |         try { | ||||||
|         EntityTrackerEntry tracker = (EntityTrackerEntry) ((WorldServer) entityplayer.world).tracker.trackedEntities.get(player |             Object world = ReflectionManager.getWorld(player.getWorld()); | ||||||
|                 .getEntityId()); |             Object tracker = world.getClass().getField("tracker").get(world); | ||||||
|         if (tracker == null) { |             Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker); | ||||||
|  |             Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class) | ||||||
|  |                     .invoke(trackedEntities, player.getEntityId()); | ||||||
|  |             if (entityTrackerEntry == null) { | ||||||
|                 // A check incase the tracker is null. |                 // A check incase the tracker is null. | ||||||
|                 // If it is, then this method will be run again in one tick. Which is when it should be constructed. |                 // If it is, then this method will be run again in one tick. Which is when it should be constructed. | ||||||
|                 // Else its going to run in a infinite loop hue hue hue.. |                 // Else its going to run in a infinite loop hue hue hue.. | ||||||
| @@ -984,81 +985,89 @@ public class PacketsManager { | |||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|             // Add himself to his own entity tracker |             // Add himself to his own entity tracker | ||||||
|         tracker.trackedPlayers.add(entityplayer); |             ((HashSet) entityTrackerEntry.getClass().getField("trackedPlayers").get(entityTrackerEntry)).add(ReflectionManager | ||||||
|  |                     .getNmsEntity(player)); | ||||||
|  |             ProtocolManager manager = ProtocolLibrary.getProtocolManager(); | ||||||
|             // Send the player a packet with himself being spawned |             // Send the player a packet with himself being spawned | ||||||
|         Packet20NamedEntitySpawn packet = new Packet20NamedEntitySpawn((EntityHuman) entityplayer); |             manager.sendServerPacket(player, manager.createPacketConstructor(Packets.Server.NAMED_ENTITY_SPAWN, player) | ||||||
|         entityplayer.playerConnection.sendPacket(packet); |                     .createPacket(player)); | ||||||
|         if (!tracker.tracker.getDataWatcher().d()) { |             manager.sendServerPacket( | ||||||
|             entityplayer.playerConnection.sendPacket(new Packet40EntityMetadata(player.getEntityId(), tracker.tracker |                     player, | ||||||
|                     .getDataWatcher(), true)); |                     manager.createPacketConstructor(Packets.Server.ENTITY_METADATA, player.getEntityId(), | ||||||
|         } |                             WrappedDataWatcher.getEntityWatcher(player), true).createPacket(player.getEntityId(), | ||||||
|         // Send himself some entity attributes |                             WrappedDataWatcher.getEntityWatcher(player), true)); | ||||||
|         if (tracker.tracker instanceof EntityLiving) { |  | ||||||
|             AttributeMapServer attributemapserver = (AttributeMapServer) ((EntityLiving) tracker.tracker).aX(); |  | ||||||
|             Collection collection = attributemapserver.c(); |  | ||||||
|  |  | ||||||
|             if (!collection.isEmpty()) { |  | ||||||
|                 entityplayer.playerConnection.sendPacket(new Packet44UpdateAttributes(player.getEntityId(), collection)); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         // Why do we even have this? |  | ||||||
|         tracker.j = tracker.tracker.motX; |  | ||||||
|         tracker.k = tracker.tracker.motY; |  | ||||||
|         tracker.l = tracker.tracker.motZ; |  | ||||||
|             boolean isMoving = false; |             boolean isMoving = false; | ||||||
|             try { |             try { | ||||||
|             Field field = EntityTrackerEntry.class.getDeclaredField("isMoving"); |                 Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField("isMoving"); | ||||||
|                 field.setAccessible(true); |                 field.setAccessible(true); | ||||||
|             isMoving = field.getBoolean(tracker); |                 isMoving = field.getBoolean(entityTrackerEntry); | ||||||
|             } catch (Exception ex) { |             } catch (Exception ex) { | ||||||
|                 ex.printStackTrace(); |                 ex.printStackTrace(); | ||||||
|             } |             } | ||||||
|             // Send the velocity packets |             // Send the velocity packets | ||||||
|             if (isMoving) { |             if (isMoving) { | ||||||
|             entityplayer.playerConnection.sendPacket(new Packet28EntityVelocity(player.getEntityId(), tracker.tracker.motX, |                 Vector velocity = player.getVelocity(); | ||||||
|                     tracker.tracker.motY, tracker.tracker.motZ)); |                 manager.sendServerPacket( | ||||||
|  |                         player, | ||||||
|  |                         manager.createPacketConstructor(Packets.Server.ENTITY_VELOCITY, player.getEntityId(), velocity.getX(), | ||||||
|  |                                 velocity.getY(), velocity.getZ()).createPacket(player.getEntityId(), velocity.getX(), | ||||||
|  |                                 velocity.getY(), velocity.getZ())); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // Why the hell would he even need this. Meh. |             // Why the hell would he even need this. Meh. | ||||||
|         if (tracker.tracker.vehicle != null && player.getEntityId() > tracker.tracker.vehicle.id) { |             if (player.getVehicle() != null && player.getEntityId() > player.getVehicle().getEntityId()) { | ||||||
|             entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(0, tracker.tracker, tracker.tracker.vehicle)); |                 manager.sendServerPacket(player, | ||||||
|         } else if (tracker.tracker.passenger != null && player.getEntityId() > tracker.tracker.passenger.id) { |                         manager.createPacketConstructor(Packets.Server.ATTACH_ENTITY, 0, player, player.getVehicle()) | ||||||
|             entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(0, tracker.tracker.passenger, tracker.tracker)); |                                 .createPacket(0, player, player.getVehicle())); | ||||||
|         } |             } else if (player.getPassenger() != null && player.getEntityId() > player.getPassenger().getEntityId()) { | ||||||
|  |                 manager.sendServerPacket(player, | ||||||
|         if (tracker.tracker instanceof EntityInsentient && ((EntityInsentient) tracker.tracker).getLeashHolder() != null) { |                         manager.createPacketConstructor(Packets.Server.ATTACH_ENTITY, 0, player.getPassenger(), player) | ||||||
|             entityplayer.playerConnection.sendPacket(new Packet39AttachEntity(1, tracker.tracker, |                                 .createPacket(0, player.getPassenger(), player)); | ||||||
|                     ((EntityInsentient) tracker.tracker).getLeashHolder())); |  | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // Resend the armor |             // Resend the armor | ||||||
|         for (int i = 0; i < 5; ++i) { |             for (int i = 0; i < 5; i++) { | ||||||
|             ItemStack itemstack = ((EntityLiving) tracker.tracker).getEquipment(i); |                 ItemStack item; | ||||||
|  |                 if (i == 0) { | ||||||
|  |                     item = player.getItemInHand(); | ||||||
|  |                 } else { | ||||||
|  |                     item = player.getInventory().getArmorContents()[i - 1]; | ||||||
|  |                 } | ||||||
|  |  | ||||||
|             if (itemstack != null) { |                 if (item != null && item.getType() != Material.AIR) { | ||||||
|                 entityplayer.playerConnection.sendPacket(new Packet5EntityEquipment(player.getEntityId(), i, itemstack)); |                     manager.sendServerPacket(player, | ||||||
|  |                             manager.createPacketConstructor(Packets.Server.ENTITY_EQUIPMENT, player.getEntityId(), i, item) | ||||||
|  |                                     .createPacket(player.getEntityId(), i, item)); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |             Location loc = player.getLocation(); | ||||||
|             // If the disguised is sleeping for w/e reason |             // If the disguised is sleeping for w/e reason | ||||||
|         if (entityplayer.isSleeping()) { |             if (player.isSleeping()) { | ||||||
|             entityplayer.playerConnection |                 manager.sendServerPacket( | ||||||
|                     .sendPacket(new Packet17EntityLocationAction(entityplayer, 0, (int) Math.floor(tracker.tracker.locX), |                         player, | ||||||
|                             (int) Math.floor(tracker.tracker.locY), (int) Math.floor(tracker.tracker.locZ))); |                         manager.createPacketConstructor(Packets.Server.ENTITY_LOCATION_ACTION, player, 0, loc.getBlockX(), | ||||||
|  |                                 loc.getBlockY(), loc.getBlockZ()).createPacket(player, 0, loc.getBlockX(), loc.getBlockY(), | ||||||
|  |                                 loc.getBlockZ())); | ||||||
|             } |             } | ||||||
|  |             // TODO Fix this cos it doesn't move the disguise? | ||||||
|         // CraftBukkit start - Fix for nonsensical head yaw |             byte yaw = (byte) (loc.getYaw() * 256.0F / 360.0F); | ||||||
|         tracker.i = (int) Math.floor(tracker.tracker.getHeadRotation() * 256.0F / 360.0F); // tracker.ao() should be |             byte pitch = (byte) (loc.getPitch() * 256.0F / 360.0F); | ||||||
|         // getHeadRotation |             manager.sendServerPacket( | ||||||
|         tracker.broadcast(new Packet35EntityHeadRotation(player.getEntityId(), (byte) tracker.i)); |                     player, | ||||||
|         // CraftBukkit end |                     manager.createPacketConstructor(Packets.Server.ENTITY_LOOK, player.getEntityId(), yaw, pitch).createPacket( | ||||||
|  |                             player.getEntityId(), yaw, pitch)); | ||||||
|  |  | ||||||
|             // Resend any active potion effects |             // Resend any active potion effects | ||||||
|         Iterator iterator = entityplayer.getEffects().iterator(); |             Iterator iterator = player.getActivePotionEffects().iterator(); | ||||||
|             while (iterator.hasNext()) { |             while (iterator.hasNext()) { | ||||||
|             MobEffect mobeffect = (MobEffect) iterator.next(); |                 PotionEffect potionEffect = (PotionEffect) iterator.next(); | ||||||
|  |                 manager.sendServerPacket(player, | ||||||
|             entityplayer.playerConnection.sendPacket(new Packet41MobEffect(player.getEntityId(), mobeffect)); |                         manager.createPacketConstructor(Packets.Server.MOB_EFFECT, player.getEntityId(), potionEffect) | ||||||
|  |                                 .createPacket(player.getEntityId(), potionEffect)); | ||||||
|  |             } | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             ex.printStackTrace(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -1141,22 +1150,8 @@ public class PacketsManager { | |||||||
|                 case Packets.Server.UPDATE_ATTRIBUTES: |                 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; |                     break; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| @@ -1164,12 +1159,12 @@ public class PacketsManager { | |||||||
|                 case Packets.Server.ENTITY_METADATA: |                 case Packets.Server.ENTITY_METADATA: | ||||||
|  |  | ||||||
|                 { |                 { | ||||||
|                     List<WatchableObject> watchableObjects = disguise.getWatcher().convert( |                     List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert( | ||||||
|                             (List<WatchableObject>) packets[0].getModifier().read(1)); |                             packets[0].getWatchableCollectionModifier().read(0)); | ||||||
|                     packets[0] = new PacketContainer(sentPacket.getID()); |                     packets[0] = new PacketContainer(sentPacket.getID()); | ||||||
|                     StructureModifier<Object> newMods = packets[0].getModifier(); |                     StructureModifier<Object> newMods = packets[0].getModifier(); | ||||||
|                     newMods.write(0, entity.getEntityId()); |                     newMods.write(0, entity.getEntityId()); | ||||||
|                     newMods.write(1, watchableObjects); |                     packets[0].getWatchableCollectionModifier().write(0, watchableObjects); | ||||||
|                     break; |                     break; | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
| @@ -1238,7 +1233,7 @@ public class PacketsManager { | |||||||
|                     if (itemstack != null) { |                     if (itemstack != null) { | ||||||
|                         packets[0] = packets[0].shallowClone(); |                         packets[0] = packets[0].shallowClone(); | ||||||
|                         packets[0].getModifier().write(2, |                         packets[0].getModifier().write(2, | ||||||
|                                 (itemstack.getTypeId() == 0 ? null : CraftItemStack.asNMSCopy(itemstack))); |                                 (itemstack.getTypeId() == 0 ? null : ReflectionManager.getNmsItem(itemstack))); | ||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 } |                 } | ||||||
|   | |||||||
							
								
								
									
										158
									
								
								src/me/libraryaddict/disguise/ReflectionManager.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										158
									
								
								src/me/libraryaddict/disguise/ReflectionManager.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,158 @@ | |||||||
|  | package me.libraryaddict.disguise; | ||||||
|  |  | ||||||
|  | import java.lang.reflect.Field; | ||||||
|  | import java.lang.reflect.Method; | ||||||
|  | import java.lang.reflect.Modifier; | ||||||
|  |  | ||||||
|  | import org.bukkit.Art; | ||||||
|  | import org.bukkit.Bukkit; | ||||||
|  | import org.bukkit.Sound; | ||||||
|  | import org.bukkit.World; | ||||||
|  | import org.bukkit.entity.Entity; | ||||||
|  | import org.bukkit.inventory.ItemStack; | ||||||
|  |  | ||||||
|  | public class ReflectionManager { | ||||||
|  |     private static String bukkitVersion = Bukkit.getServer().getClass().getName().split("\\.")[3]; | ||||||
|  |     private static Class itemClass; | ||||||
|  |     private static Method soundMethod; | ||||||
|  |     static { | ||||||
|  |         for (Method method : getNmsClass("EntityLiving").getDeclaredMethods()) { | ||||||
|  |             try { | ||||||
|  |                 if (method.getReturnType() == float.class && Modifier.isProtected(method.getModifiers()) | ||||||
|  |                         && method.getParameterTypes().length == 0) { | ||||||
|  |                     Object entity = createEntityInstance("Pig"); | ||||||
|  |                     method.setAccessible(true); | ||||||
|  |                     method.invoke(entity); | ||||||
|  |                     Field random = getNmsClass("Entity").getDeclaredField("random"); | ||||||
|  |                     random.setAccessible(true); | ||||||
|  |                     random.set(entity, null); | ||||||
|  |                     method.setAccessible(true); | ||||||
|  |                     try { | ||||||
|  |                         method.invoke(entity); | ||||||
|  |                     } catch (Exception ex) { | ||||||
|  |                         soundMethod = method; | ||||||
|  |                         break; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } catch (Exception ex) { | ||||||
|  |                 ex.printStackTrace(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         try { | ||||||
|  |             itemClass = getCraftClass("inventory.CraftItemStack"); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     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 Object getNmsEntity(Entity entity) { | ||||||
|  |         try { | ||||||
|  |             return getCraftClass("entity.CraftEntity").getMethod("getHandle").invoke(entity); | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             ex.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static String getCraftSound(Sound sound) { | ||||||
|  |         try { | ||||||
|  |             Class c = getCraftClass("CraftSound"); | ||||||
|  |             return (String) c.getMethod("getSound", Sound.class).invoke(null, sound); | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             ex.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static Object createEntityInstance(String entityName) { | ||||||
|  |         try { | ||||||
|  |             Class entityClass = getNmsClass("Entity" + entityName); | ||||||
|  |             Object entityObject; | ||||||
|  |             Object world = getWorld(Bukkit.getWorlds().get(0)); | ||||||
|  |             if (entityName.equals("Player")) { | ||||||
|  |                 Object minecraftServer = getNmsClass("MinecraftServer").getMethod("getServer").invoke(null); | ||||||
|  |                 Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World")) | ||||||
|  |                         .newInstance(world); | ||||||
|  |                 entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("World"), String.class, | ||||||
|  |                         playerinteractmanager.getClass()).newInstance(minecraftServer, world, "LibsDisguises", | ||||||
|  |                         playerinteractmanager); | ||||||
|  |             } else { | ||||||
|  |                 entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world); | ||||||
|  |             } | ||||||
|  |             return entityObject; | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static Class getNmsClass(String className) { | ||||||
|  |         try { | ||||||
|  |             return Class.forName("net.minecraft.server." + bukkitVersion + "." + className); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static Class getCraftClass(String className) { | ||||||
|  |         try { | ||||||
|  |             return Class.forName("org.bukkit.craftbukkit." + bukkitVersion + "." + className); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static Float getSoundModifier(Object entity) { | ||||||
|  |         try { | ||||||
|  |             soundMethod.setAccessible(true); | ||||||
|  |             return (Float) soundMethod.invoke(entity); | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static Object getWorld(World world) { | ||||||
|  |         try { | ||||||
|  |             return getCraftClass("CraftWorld").getMethod("getHandle").invoke(world); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static Object getNmsItem(ItemStack itemstack) { | ||||||
|  |         try { | ||||||
|  |             return itemClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, itemstack); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static ItemStack getBukkitItem(Object nmsItem) { | ||||||
|  |         try { | ||||||
|  |             return (ItemStack) itemClass.getMethod("asBukkitCopy", getNmsClass("ItemStack")).invoke(null, nmsItem); | ||||||
|  |         } catch (Exception e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -18,15 +18,19 @@ public class DisguiseCommand extends BaseDisguiseCommand { | |||||||
|             sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); |             sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|  |         Disguise disguise = null; | ||||||
|         try { |         try { | ||||||
|             Disguise disguise = parseDisguise(sender, args); |             disguise = parseDisguise(sender, args); | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) { | ||||||
|  |                 sender.sendMessage(ex.getMessage()); | ||||||
|  |             } else { | ||||||
|  |                 ex.printStackTrace(); | ||||||
|  |             } | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|         DisguiseAPI.disguiseToAll((Player) sender, disguise); |         DisguiseAPI.disguiseToAll((Player) sender, disguise); | ||||||
|         sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable()); |         sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable()); | ||||||
|         } catch (Exception ex) { |  | ||||||
|             if (ex.getMessage() != null) { |  | ||||||
|                 sender.sendMessage(ex.getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -34,7 +38,7 @@ public class DisguiseCommand extends BaseDisguiseCommand { | |||||||
|      * Send the player the information |      * Send the player the information | ||||||
|      */ |      */ | ||||||
|     protected void sendCommandUsage(CommandSender sender) { |     protected void sendCommandUsage(CommandSender sender) { | ||||||
|         ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguise"); |         ArrayList<String> allowedDisguises = getAllowedDisguises(sender); | ||||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"); |         sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"); | ||||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN |         sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN | ||||||
|                 + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); |                 + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); | ||||||
|   | |||||||
| @@ -23,16 +23,20 @@ public class DisguiseEntityCommand extends BaseDisguiseCommand { | |||||||
|             sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); |             sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|  |         Disguise disguise; | ||||||
|         try { |         try { | ||||||
|             Disguise disguise = parseDisguise(sender, args); |             disguise = parseDisguise(sender, args); | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) { | ||||||
|  |                 sender.sendMessage(ex.getMessage()); | ||||||
|  |             } else { | ||||||
|  |                 ex.printStackTrace(); | ||||||
|  |             } | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|         listener.setSlap(sender.getName(), disguise); |         listener.setSlap(sender.getName(), disguise); | ||||||
|         sender.sendMessage(ChatColor.RED + "Right click a entity in the next 10 seconds to disguise it as a " |         sender.sendMessage(ChatColor.RED + "Right click a entity in the next 10 seconds to disguise it as a " | ||||||
|                 + disguise.getType().toReadable() + "!"); |                 + disguise.getType().toReadable() + "!"); | ||||||
|         } catch (Exception ex) { |  | ||||||
|             if (ex.getMessage() != null) { |  | ||||||
|                 sender.sendMessage(ex.getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -40,7 +44,7 @@ public class DisguiseEntityCommand extends BaseDisguiseCommand { | |||||||
|      * Send the player the information |      * Send the player the information | ||||||
|      */ |      */ | ||||||
|     protected void sendCommandUsage(CommandSender sender) { |     protected void sendCommandUsage(CommandSender sender) { | ||||||
|         ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguiseentity"); |         ArrayList<String> allowedDisguises = getAllowedDisguises(sender); | ||||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then slap a entity to disguise it!"); |         sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then slap a entity to disguise it!"); | ||||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN |         sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN | ||||||
|                 + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); |                 + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); | ||||||
|   | |||||||
| @@ -22,7 +22,7 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { | |||||||
|     @Override |     @Override | ||||||
|     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { |     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||||||
|         for (String node : new String[] { "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" }) { |         for (String node : new String[] { "disguise", "disguiseradius", "disguiseentity", "disguiseplayer" }) { | ||||||
|             ArrayList<String> allowedDisguises = getAllowedDisguises(sender, node); |             ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "libsdisguises." + node + "."); | ||||||
|             if (!allowedDisguises.isEmpty()) { |             if (!allowedDisguises.isEmpty()) { | ||||||
|                 if (args.length == 0) { |                 if (args.length == 0) { | ||||||
|                     sendCommandUsage(sender); |                     sendCommandUsage(sender); | ||||||
| @@ -126,6 +126,7 @@ public class DisguiseHelpCommand extends BaseDisguiseCommand { | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         sender.sendMessage(ChatColor.RED + "You are forbidden from using this command!"); | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { |     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||||||
|         ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguiseplayer"); |         ArrayList<String> allowedDisguises = getAllowedDisguises(sender); | ||||||
|         if (allowedDisguises.isEmpty()) { |         if (allowedDisguises.isEmpty()) { | ||||||
|             sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); |             sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); | ||||||
|             return true; |             return true; | ||||||
| @@ -33,20 +33,24 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand { | |||||||
|             sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'"); |             sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'"); | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|         try { |  | ||||||
|         String[] newArgs = new String[args.length - 1]; |         String[] newArgs = new String[args.length - 1]; | ||||||
|         for (int i = 0; i < newArgs.length; i++) { |         for (int i = 0; i < newArgs.length; i++) { | ||||||
|             newArgs[i] = args[i + 1]; |             newArgs[i] = args[i + 1]; | ||||||
|         } |         } | ||||||
|             Disguise disguise = parseDisguise(sender, newArgs); |         Disguise disguise; | ||||||
|  |         try { | ||||||
|  |             disguise = parseDisguise(sender, newArgs); | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) { | ||||||
|  |                 sender.sendMessage(ex.getMessage()); | ||||||
|  |             } else { | ||||||
|  |                 ex.printStackTrace(); | ||||||
|  |             } | ||||||
|  |             return true; | ||||||
|  |         } | ||||||
|         DisguiseAPI.disguiseToAll(player, disguise); |         DisguiseAPI.disguiseToAll(player, disguise); | ||||||
|         sender.sendMessage(ChatColor.RED + "Successfully disguised " + player.getName() + " as a " |         sender.sendMessage(ChatColor.RED + "Successfully disguised " + player.getName() + " as a " | ||||||
|                 + disguise.getType().toReadable() + "!"); |                 + disguise.getType().toReadable() + "!"); | ||||||
|         } catch (Exception ex) { |  | ||||||
|             if (ex.getMessage() != null) { |  | ||||||
|                 sender.sendMessage(ex.getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -54,7 +58,7 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand { | |||||||
|      * Send the player the information |      * Send the player the information | ||||||
|      */ |      */ | ||||||
|     protected void sendCommandUsage(CommandSender sender) { |     protected void sendCommandUsage(CommandSender sender) { | ||||||
|         ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguiseplayer"); |         ArrayList<String> allowedDisguises = getAllowedDisguises(sender); | ||||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!"); |         sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!"); | ||||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN |         sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN | ||||||
|                 + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); |                 + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); | ||||||
|   | |||||||
| @@ -24,7 +24,7 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand { | |||||||
|             sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); |             sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|         ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguiseplayer"); |         ArrayList<String> allowedDisguises = getAllowedDisguises(sender); | ||||||
|         if (allowedDisguises.isEmpty()) { |         if (allowedDisguises.isEmpty()) { | ||||||
|             sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); |             sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); | ||||||
|             return true; |             return true; | ||||||
| @@ -46,13 +46,21 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand { | |||||||
|             sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); |             sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); | ||||||
|             radius = maxRadius; |             radius = maxRadius; | ||||||
|         } |         } | ||||||
|         try { |  | ||||||
|         String[] newArgs = new String[args.length - 1]; |         String[] newArgs = new String[args.length - 1]; | ||||||
|         for (int i = 0; i < newArgs.length; i++) { |         for (int i = 0; i < newArgs.length; i++) { | ||||||
|             newArgs[i] = args[i + 1]; |             newArgs[i] = args[i + 1]; | ||||||
|         } |         } | ||||||
|             Disguise disguise = parseDisguise(sender, newArgs); |         Disguise disguise; | ||||||
|             // Time to use it! |         try { | ||||||
|  |             disguise = parseDisguise(sender, newArgs); | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             if (ex.getMessage() != null && !ChatColor.getLastColors(ex.getMessage()).equals("")) { | ||||||
|  |                 sender.sendMessage(ex.getMessage()); | ||||||
|  |             } else { | ||||||
|  |                 ex.printStackTrace(); | ||||||
|  |             } | ||||||
|  |             return true; | ||||||
|  |         } // Time to use it! | ||||||
|         int disguisedEntitys = 0; |         int disguisedEntitys = 0; | ||||||
|         for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { |         for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { | ||||||
|             if (entity == sender) |             if (entity == sender) | ||||||
| @@ -61,11 +69,6 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand { | |||||||
|             disguisedEntitys++; |             disguisedEntitys++; | ||||||
|         } |         } | ||||||
|         sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!"); |         sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!"); | ||||||
|         } catch (Exception ex) { |  | ||||||
|             if (ex.getMessage() != null) { |  | ||||||
|                 sender.sendMessage(ex.getMessage()); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -73,7 +76,7 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand { | |||||||
|      * Send the player the information |      * Send the player the information | ||||||
|      */ |      */ | ||||||
|     protected void sendCommandUsage(CommandSender sender) { |     protected void sendCommandUsage(CommandSender sender) { | ||||||
|         ArrayList<String> allowedDisguises = getAllowedDisguises(sender, "disguiseradius"); |         ArrayList<String> allowedDisguises = getAllowedDisguises(sender); | ||||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at 30 blocks!"); |         sender.sendMessage(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at 30 blocks!"); | ||||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN |         sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN | ||||||
|                 + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); |                 + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); | ||||||
|   | |||||||
| @@ -1,25 +1,19 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes; | package me.libraryaddict.disguise.disguisetypes; | ||||||
|  |  | ||||||
|  | import java.lang.reflect.Field; | ||||||
| import java.lang.reflect.InvocationTargetException; | import java.lang.reflect.InvocationTargetException; | ||||||
|  | import java.lang.reflect.Method; | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
|  | import java.util.HashSet; | ||||||
| import java.util.Iterator; | import java.util.Iterator; | ||||||
| import java.util.List; |  | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.DisguiseAPI; | import me.libraryaddict.disguise.DisguiseAPI; | ||||||
| import me.libraryaddict.disguise.PacketsManager; | import me.libraryaddict.disguise.PacketsManager; | ||||||
|  | import me.libraryaddict.disguise.ReflectionManager; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher; | 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.Location; | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity; |  | ||||||
| import org.bukkit.entity.Horse.Variant; | import org.bukkit.entity.Horse.Variant; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| import org.bukkit.plugin.java.JavaPlugin; | import org.bukkit.plugin.java.JavaPlugin; | ||||||
| @@ -182,7 +176,7 @@ public abstract class Disguise { | |||||||
|  |  | ||||||
|             public void run() { |             public void run() { | ||||||
|                 // If entity is no longer valid. Remove it. |                 // If entity is no longer valid. Remove it. | ||||||
|                 if (!((CraftEntity) entity).getHandle().valid) { |                 if (!getEntity().isValid()) { | ||||||
|                     DisguiseAPI.undisguiseToAll(entity); |                     DisguiseAPI.undisguiseToAll(entity); | ||||||
|                 } else { |                 } else { | ||||||
|                     // If the disguise type is tnt, we need to resend the entity packet else it will turn invisible |                     // If the disguise type is tnt, we need to resend the entity packet else it will turn invisible | ||||||
| @@ -190,10 +184,7 @@ public abstract class Disguise { | |||||||
|                         i++; |                         i++; | ||||||
|                         if (i % 40 == 0) { |                         if (i % 40 == 0) { | ||||||
|                             i = 0; |                             i = 0; | ||||||
|                             List<Player> players = new ArrayList<Player>(); |                             ProtocolLibrary.getProtocolManager().updateEntity(getEntity(), getPerverts()); | ||||||
|                             for (EntityPlayer p : getPerverts()) |  | ||||||
|                                 players.add(p.getBukkitEntity()); |  | ||||||
|                             ProtocolLibrary.getProtocolManager().updateEntity(getEntity(), players); |  | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|                     // 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. | ||||||
| @@ -219,16 +210,18 @@ public abstract class Disguise { | |||||||
|                                 mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F)); |                                 mods.write(5, (byte) Math.floor(loc.getPitch() * 256.0F / 360.0F)); | ||||||
|                                 selfLookPacket = lookPacket.shallowClone(); |                                 selfLookPacket = lookPacket.shallowClone(); | ||||||
|                             } |                             } | ||||||
|                             for (EntityPlayer player : getPerverts()) { |                             try { | ||||||
|  |                                 Field ping = ReflectionManager.getNmsClass("EntityPlayer").getField("ping"); | ||||||
|  |                                 for (Player player : getPerverts()) { | ||||||
|                                     PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY); |                                     PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_VELOCITY); | ||||||
|                                     StructureModifier<Object> mods = packet.getModifier(); |                                     StructureModifier<Object> mods = packet.getModifier(); | ||||||
|                                 if (entity == player.getBukkitEntity()) { |                                     if (entity == player) { | ||||||
|                                         if (!viewSelfDisguise()) |                                         if (!viewSelfDisguise()) | ||||||
|                                             continue; |                                             continue; | ||||||
|                                         if (selfLookPacket != null) { |                                         if (selfLookPacket != null) { | ||||||
|                                             try { |                                             try { | ||||||
|                                             ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(), |                                                 ProtocolLibrary.getProtocolManager().sendServerPacket(player, selfLookPacket, | ||||||
|                                                     selfLookPacket, false); |                                                         false); | ||||||
|                                             } catch (InvocationTargetException e) { |                                             } catch (InvocationTargetException e) { | ||||||
|                                                 e.printStackTrace(); |                                                 e.printStackTrace(); | ||||||
|                                             } |                                             } | ||||||
| @@ -237,17 +230,17 @@ public abstract class Disguise { | |||||||
|                                     } else |                                     } else | ||||||
|                                         mods.write(0, entity.getEntityId()); |                                         mods.write(0, entity.getEntityId()); | ||||||
|                                     mods.write(1, (int) (vector.getX() * 8000)); |                                     mods.write(1, (int) (vector.getX() * 8000)); | ||||||
|                                 mods.write(2, (int) (8000 * (vectorY * (double) player.ping * 0.069))); |                                     mods.write( | ||||||
|  |                                             2, | ||||||
|  |                                             (int) (8000 * (vectorY * (double) ping.getInt(ReflectionManager.getNmsEntity(player)) * 0.069))); | ||||||
|                                     mods.write(3, (int) (vector.getZ() * 8000)); |                                     mods.write(3, (int) (vector.getZ() * 8000)); | ||||||
|                                 try { |  | ||||||
|                                     if (lookPacket != null) |                                     if (lookPacket != null) | ||||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(), |                                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, lookPacket, false); | ||||||
|                                                 lookPacket, false); |                                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false); | ||||||
|                                     ProtocolLibrary.getProtocolManager() |  | ||||||
|                                             .sendServerPacket(player.getBukkitEntity(), packet, false); |  | ||||||
|                                 } catch (InvocationTargetException e) { |  | ||||||
|                                     e.printStackTrace(); |  | ||||||
|                                 } |                                 } | ||||||
|  |                             } catch (Exception e) { | ||||||
|  |                                 e.printStackTrace(); | ||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                         // If we need to send more packets because else it still 'sinks' |                         // If we need to send more packets because else it still 'sinks' | ||||||
| @@ -255,10 +248,10 @@ public abstract class Disguise { | |||||||
|                             PacketContainer packet = new PacketContainer(Packets.Server.REL_ENTITY_MOVE); |                             PacketContainer packet = new PacketContainer(Packets.Server.REL_ENTITY_MOVE); | ||||||
|                             StructureModifier<Object> mods = packet.getModifier(); |                             StructureModifier<Object> mods = packet.getModifier(); | ||||||
|                             mods.write(0, entity.getEntityId()); |                             mods.write(0, entity.getEntityId()); | ||||||
|                             for (EntityPlayer player : getPerverts()) { |                             for (Player player : getPerverts()) { | ||||||
|                                 if (DisguiseAPI.isViewDisguises() || entity != player) { |                                 if (DisguiseAPI.isViewDisguises() || entity != player) { | ||||||
|                                     try { |                                     try { | ||||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(player.getBukkitEntity(), packet); |                                         ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||||
|                                     } catch (InvocationTargetException e) { |                                     } catch (InvocationTargetException e) { | ||||||
|                                         e.printStackTrace(); |                                         e.printStackTrace(); | ||||||
|                                     } |                                     } | ||||||
| @@ -281,14 +274,26 @@ public abstract class Disguise { | |||||||
|     /** |     /** | ||||||
|      * Get all EntityPlayers who have this entity in their Entity Tracker |      * Get all EntityPlayers who have this entity in their Entity Tracker | ||||||
|      */ |      */ | ||||||
|     protected EntityPlayer[] getPerverts() { |     protected ArrayList<Player> getPerverts() { | ||||||
|         EntityTrackerEntry entry = (EntityTrackerEntry) ((WorldServer) ((CraftEntity) entity).getHandle().world).tracker.trackedEntities |         ArrayList<Player> players = new ArrayList<Player>(); | ||||||
|                 .get(entity.getEntityId()); |         try { | ||||||
|         if (entry != null) { |             Object world = ReflectionManager.getWorld(getEntity().getWorld()); | ||||||
|             EntityPlayer[] players = (EntityPlayer[]) entry.trackedPlayers.toArray(new EntityPlayer[entry.trackedPlayers.size()]); |             Object tracker = world.getClass().getField("tracker").get(world); | ||||||
|             return players; |             Object trackedEntities = tracker.getClass().getField("trackedEntities").get(tracker); | ||||||
|  |             Object entityTrackerEntry = trackedEntities.getClass().getMethod("get", int.class) | ||||||
|  |                     .invoke(trackedEntities, getEntity().getEntityId()); | ||||||
|  |             if (entityTrackerEntry != null) { | ||||||
|  |                 Method method = ReflectionManager.getNmsClass("Entity").getMethod("getBukkitEntity"); | ||||||
|  |                 HashSet trackedPlayers = (HashSet) entityTrackerEntry.getClass().getField("trackedPlayers") | ||||||
|  |                         .get(entityTrackerEntry); | ||||||
|  |                 for (Object p : trackedPlayers) { | ||||||
|  |                     players.add((Player) method.invoke(p)); | ||||||
|                 } |                 } | ||||||
|         return new EntityPlayer[0]; |             } | ||||||
|  |         } catch (Exception ex) { | ||||||
|  |             ex.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return players; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -342,7 +347,7 @@ public abstract class Disguise { | |||||||
|         // If this disguise has a entity set |         // If this disguise has a entity set | ||||||
|         if (getEntity() != null) { |         if (getEntity() != null) { | ||||||
|             // If the entity is valid |             // If the entity is valid | ||||||
|             if (((CraftEntity) getEntity()).getHandle().valid) { |             if (getEntity().isValid()) { | ||||||
|                 // If this disguise is active |                 // If this disguise is active | ||||||
|                 if (disguises.containsKey(getEntity().getEntityId()) && disguises.get(getEntity().getEntityId()) == this) { |                 if (disguises.containsKey(getEntity().getEntityId()) && disguises.get(getEntity().getEntityId()) == this) { | ||||||
|                     // Now remove the disguise from the current disguises. |                     // Now remove the disguise from the current disguises. | ||||||
| @@ -478,19 +483,19 @@ public abstract class Disguise { | |||||||
|             case 7: |             case 7: | ||||||
|             case 8: |             case 8: | ||||||
|             case 9: |             case 9: | ||||||
|                 baseClass = EntityLiving.class; |                 baseClass = ReflectionManager.getNmsClass("EntityLiving"); | ||||||
|                 break; |                 break; | ||||||
|             case 10: |             case 10: | ||||||
|             case 11: |             case 11: | ||||||
|                 baseClass = EntityInsentient.class; |                 baseClass = ReflectionManager.getNmsClass("EntityInsentient"); | ||||||
|                 break; |                 break; | ||||||
|             case 16: |             case 16: | ||||||
|                 baseClass = EntityAgeable.class; |                 baseClass = ReflectionManager.getNmsClass("EntityAgeable"); | ||||||
|                 break; |                 break; | ||||||
|             default: |             default: | ||||||
|                 break; |                 break; | ||||||
|             } |             } | ||||||
|             Class entityClass = ((CraftEntity) entity).getHandle().getClass(); |             Class entityClass = ReflectionManager.getNmsEntity(getEntity()).getClass(); | ||||||
|             // If they both extend the same base class. They OBVIOUSLY share the same datavalue. Right..? |             // If they both extend the same base class. They OBVIOUSLY share the same datavalue. Right..? | ||||||
|             if (baseClass != null && baseClass.isAssignableFrom(disguiseClass) && baseClass.isAssignableFrom(entityClass)) |             if (baseClass != null && baseClass.isAssignableFrom(disguiseClass) && baseClass.isAssignableFrom(entityClass)) | ||||||
|                 continue; |                 continue; | ||||||
|   | |||||||
| @@ -3,8 +3,9 @@ package me.libraryaddict.disguise.disguisetypes; | |||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.HashSet; | import java.util.HashSet; | ||||||
|  |  | ||||||
|  | import me.libraryaddict.disguise.ReflectionManager; | ||||||
|  |  | ||||||
| import org.bukkit.Sound; | import org.bukkit.Sound; | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.CraftSound; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Only living disguises go in here! |  * Only living disguises go in here! | ||||||
| @@ -103,10 +104,6 @@ public enum DisguiseSound { | |||||||
|         CANCEL, DEATH, HURT, IDLE, STEP; |         CANCEL, DEATH, HURT, IDLE, STEP; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static String getSoundName(Sound sound) { |  | ||||||
|         return CraftSound.getSound(sound); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public static DisguiseSound getType(String name) { |     public static DisguiseSound getType(String name) { | ||||||
|         try { |         try { | ||||||
|             return valueOf(name); |             return valueOf(name); | ||||||
| @@ -128,7 +125,7 @@ public enum DisguiseSound { | |||||||
|             else if (obj instanceof String) |             else if (obj instanceof String) | ||||||
|                 s = (String) obj; |                 s = (String) obj; | ||||||
|             else if (obj instanceof Sound) |             else if (obj instanceof Sound) | ||||||
|                 s = CraftSound.getSound((Sound) obj); |                 s = ReflectionManager.getCraftSound((Sound) obj); | ||||||
|             else |             else | ||||||
|                 throw new RuntimeException("Was given a unknown object " + obj); |                 throw new RuntimeException("Was given a unknown object " + obj); | ||||||
|             switch (i) { |             switch (i) { | ||||||
| @@ -195,7 +192,7 @@ public enum DisguiseSound { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void removeSound(SoundType type, Sound sound) { |     public void removeSound(SoundType type, Sound sound) { | ||||||
|         removeSound(type, CraftSound.getSound(sound)); |         removeSound(type, ReflectionManager.getCraftSound(sound)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void removeSound(SoundType type, String sound) { |     public void removeSound(SoundType type, String sound) { | ||||||
| @@ -211,7 +208,7 @@ public enum DisguiseSound { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSound(SoundType type, Sound sound) { |     public void setSound(SoundType type, Sound sound) { | ||||||
|         setSound(type, CraftSound.getSound(sound)); |         setSound(type, ReflectionManager.getCraftSound(sound)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setSound(SoundType type, String sound) { |     public void setSound(SoundType type, String sound) { | ||||||
|   | |||||||
| @@ -7,7 +7,6 @@ import java.util.HashSet; | |||||||
| import java.util.Iterator; | import java.util.Iterator; | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack; |  | ||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
| import org.bukkit.entity.LivingEntity; | import org.bukkit.entity.LivingEntity; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| @@ -17,13 +16,11 @@ import com.comphenix.protocol.Packets; | |||||||
| import com.comphenix.protocol.ProtocolLibrary; | import com.comphenix.protocol.ProtocolLibrary; | ||||||
| import com.comphenix.protocol.events.PacketContainer; | import com.comphenix.protocol.events.PacketContainer; | ||||||
| import com.comphenix.protocol.reflect.StructureModifier; | import com.comphenix.protocol.reflect.StructureModifier; | ||||||
|  | import com.comphenix.protocol.wrappers.WrappedWatchableObject; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.DisguiseAPI; | import me.libraryaddict.disguise.DisguiseAPI; | ||||||
| import me.libraryaddict.disguise.PacketsManager; | import me.libraryaddict.disguise.PacketsManager; | ||||||
| import net.minecraft.server.v1_6_R3.ChunkCoordinates; | import me.libraryaddict.disguise.ReflectionManager; | ||||||
| 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 class FlagWatcher { | ||||||
|     public enum SlotType { |     public enum SlotType { | ||||||
| @@ -39,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.. |      * This is the entity values I need to add else it could crash them.. | ||||||
|      */ |      */ | ||||||
| @@ -67,7 +54,6 @@ public class FlagWatcher { | |||||||
|         try { |         try { | ||||||
|             cloned = getClass().getConstructor(Disguise.class).newInstance(disguise); |             cloned = getClass().getConstructor(Disguise.class).newInstance(disguise); | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             // TODO Auto-generated catch block |  | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
|         } |         } | ||||||
|         cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone(); |         cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone(); | ||||||
| @@ -75,14 +61,14 @@ public class FlagWatcher { | |||||||
|         return cloned; |         return cloned; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public List<WatchableObject> convert(List<WatchableObject> list) { |     public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list) { | ||||||
|         Iterator<WatchableObject> itel = list.iterator(); |         Iterator<WrappedWatchableObject> itel = list.iterator(); | ||||||
|         List<WatchableObject> newList = new ArrayList<WatchableObject>(); |         List<WrappedWatchableObject> newList = new ArrayList<WrappedWatchableObject>(); | ||||||
|         HashSet<Integer> sentValues = new HashSet<Integer>(); |         HashSet<Integer> sentValues = new HashSet<Integer>(); | ||||||
|         boolean sendAllCustom = false; |         boolean sendAllCustom = false; | ||||||
|         while (itel.hasNext()) { |         while (itel.hasNext()) { | ||||||
|             WatchableObject watch = itel.next(); |             WrappedWatchableObject watch = itel.next(); | ||||||
|             int dataType = watch.a(); |             int dataType = watch.getIndex(); | ||||||
|             sentValues.add(dataType); |             sentValues.add(dataType); | ||||||
|             // Its sending the air metadata. This is the least commonly sent metadata which all entitys still share. |             // 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! |             // I send my custom values if I see this! | ||||||
| @@ -99,15 +85,15 @@ public class FlagWatcher { | |||||||
|                 value = backupEntityValues.get(dataType); |                 value = backupEntityValues.get(dataType); | ||||||
|             } |             } | ||||||
|             if (value != null) { |             if (value != null) { | ||||||
|                 boolean doD = watch.d(); |                 boolean doD = watch.getDirtyState(); | ||||||
|                 watch = new WatchableObject(classTypes.get(value.getClass()), dataType, value); |                 watch = new WrappedWatchableObject(dataType, value); | ||||||
|                 if (!doD) |                 if (!doD) | ||||||
|                     watch.a(false); |                     watch.setDirtyState(doD); | ||||||
|             } else { |             } else { | ||||||
|                 boolean doD = watch.d(); |                 boolean doD = watch.getDirtyState(); | ||||||
|                 watch = new WatchableObject(watch.c(), dataType, watch.b()); |                 watch = new WrappedWatchableObject(dataType, watch.getValue()); | ||||||
|                 if (!doD) |                 if (!doD) | ||||||
|                     watch.a(false); |                     watch.setDirtyState(doD); | ||||||
|             } |             } | ||||||
|             newList.add(watch); |             newList.add(watch); | ||||||
|         } |         } | ||||||
| @@ -119,16 +105,16 @@ public class FlagWatcher { | |||||||
|                 Object obj = entityValues.get(value); |                 Object obj = entityValues.get(value); | ||||||
|                 if (obj == null) |                 if (obj == null) | ||||||
|                     continue; |                     continue; | ||||||
|                 WatchableObject watch = new WatchableObject(classTypes.get(obj.getClass()), value, obj); |                 WrappedWatchableObject watch = new WrappedWatchableObject(value, obj); | ||||||
|                 newList.add(watch); |                 newList.add(watch); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         // Here we check for if there is a health packet that says they died. |         // Here we check for if there is a health packet that says they died. | ||||||
|         if (disguise.viewSelfDisguise() && disguise.getEntity() != null && disguise.getEntity() instanceof Player) { |         if (disguise.viewSelfDisguise() && disguise.getEntity() != null && disguise.getEntity() instanceof Player) { | ||||||
|             for (WatchableObject watch : newList) { |             for (WrappedWatchableObject watch : newList) { | ||||||
|                 // Its a health packet |                 // Its a health packet | ||||||
|                 if (watch.a() == 6) { |                 if (watch.getIndex() == 6) { | ||||||
|                     Object value = watch.b(); |                     Object value = watch.getValue(); | ||||||
|                     if (value != null && value instanceof Float) { |                     if (value != null && value instanceof Float) { | ||||||
|                         float newHealth = (Float) value; |                         float newHealth = (Float) value; | ||||||
|                         if (newHealth > 0 && hasDied) { |                         if (newHealth > 0 && hasDied) { | ||||||
| @@ -209,17 +195,16 @@ public class FlagWatcher { | |||||||
|             return; |             return; | ||||||
|         Entity entity = disguise.getEntity(); |         Entity entity = disguise.getEntity(); | ||||||
|         Object value = entityValues.get(data); |         Object value = entityValues.get(data); | ||||||
|         List<WatchableObject> list = new ArrayList<WatchableObject>(); |         List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>(); | ||||||
|         list.add(new WatchableObject(classTypes.get(value.getClass()), data, value)); |         list.add(new WrappedWatchableObject(data, value)); | ||||||
|         PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA); |         PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA); | ||||||
|         StructureModifier<Object> mods = packet.getModifier(); |         StructureModifier<Object> mods = packet.getModifier(); | ||||||
|         mods.write(0, entity.getEntityId()); |         mods.write(0, entity.getEntityId()); | ||||||
|         mods.write(1, list); |         packet.getWatchableCollectionModifier().write(0, list); | ||||||
|         for (EntityPlayer player : disguise.getPerverts()) { |         for (Player player : disguise.getPerverts()) { | ||||||
|             Player p = player.getBukkitEntity(); |             if (DisguiseAPI.isViewDisguises() || player != entity) { | ||||||
|             if (DisguiseAPI.isViewDisguises() || p != entity) { |  | ||||||
|                 try { |                 try { | ||||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet); |                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||||
|                 } catch (InvocationTargetException e) { |                 } catch (InvocationTargetException e) { | ||||||
|                     e.printStackTrace(); |                     e.printStackTrace(); | ||||||
|                 } |                 } | ||||||
| @@ -266,7 +251,7 @@ public class FlagWatcher { | |||||||
|             // Find the item to replace it with |             // Find the item to replace it with | ||||||
|             if (disguise.getEntity() instanceof LivingEntity) { |             if (disguise.getEntity() instanceof LivingEntity) { | ||||||
|                 EntityEquipment enquipment = ((LivingEntity) disguise.getEntity()).getEquipment(); |                 EntityEquipment enquipment = ((LivingEntity) disguise.getEntity()).getEquipment(); | ||||||
|                 if (slot == 4) { |                 if (slot == 0) { | ||||||
|                     itemStack = enquipment.getItemInHand(); |                     itemStack = enquipment.getItemInHand(); | ||||||
|                 } else { |                 } else { | ||||||
|                     itemStack = enquipment.getArmorContents()[slot]; |                     itemStack = enquipment.getArmorContents()[slot]; | ||||||
| @@ -276,9 +261,9 @@ public class FlagWatcher { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         ItemStack itemToSend = null; |         Object itemToSend = null; | ||||||
|         if (itemStack != null && itemStack.getTypeId() != 0) |         if (itemStack != null && itemStack.getTypeId() != 0) | ||||||
|             itemToSend = CraftItemStack.asNMSCopy(itemStack); |             itemToSend = ReflectionManager.getNmsItem(itemStack); | ||||||
|         items[slot] = itemStack; |         items[slot] = itemStack; | ||||||
|         if (DisguiseAPI.getDisguise(disguise.getEntity()) != disguise) |         if (DisguiseAPI.getDisguise(disguise.getEntity()) != disguise) | ||||||
|             return; |             return; | ||||||
| @@ -290,11 +275,10 @@ public class FlagWatcher { | |||||||
|         mods.write(0, disguise.getEntity().getEntityId()); |         mods.write(0, disguise.getEntity().getEntityId()); | ||||||
|         mods.write(1, slot); |         mods.write(1, slot); | ||||||
|         mods.write(2, itemToSend); |         mods.write(2, itemToSend); | ||||||
|         for (EntityPlayer player : disguise.getPerverts()) { |         for (Player player : disguise.getPerverts()) { | ||||||
|             Player p = player.getBukkitEntity(); |             if (player != disguise.getEntity()) { | ||||||
|             if (p != disguise.getEntity()) { |  | ||||||
|                 try { |                 try { | ||||||
|                     ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet); |                     ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet); | ||||||
|                 } catch (InvocationTargetException e) { |                 } catch (InvocationTargetException e) { | ||||||
|                     e.printStackTrace(); |                     e.printStackTrace(); | ||||||
|                 } |                 } | ||||||
|   | |||||||
| @@ -2,16 +2,10 @@ package me.libraryaddict.disguise.disguisetypes; | |||||||
|  |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
|  |  | ||||||
| import net.minecraft.server.v1_6_R3.EnumEntitySize; |  | ||||||
|  |  | ||||||
| public class Values { | public class Values { | ||||||
|  |  | ||||||
|     private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>(); |     private static HashMap<DisguiseType, Values> values = new HashMap<DisguiseType, Values>(); | ||||||
|  |  | ||||||
|     public static HashMap<String, Double> getAttributesValues(DisguiseType type) { |  | ||||||
|         return getValues(type).getAttributesValues(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public static Class getEntityClass(DisguiseType type) { |     public static Class getEntityClass(DisguiseType type) { | ||||||
|         return getValues(type).getEntityClass(); |         return getValues(type).getEntityClass(); | ||||||
|     } |     } | ||||||
| @@ -47,39 +41,68 @@ public class Values { | |||||||
|         return values.get(type); |         return values.get(type); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private HashMap<String, Double> attributesValues = new HashMap<String, Double>(); |  | ||||||
|  |  | ||||||
|     private Class declared; |     private Class declared; | ||||||
|     private EnumEntitySize enumEntitySize; |     private int enumEntitySize; | ||||||
|  |  | ||||||
|     private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>(); |     private HashMap<Integer, Object> metaValues = new HashMap<Integer, Object>(); | ||||||
|  |  | ||||||
|     public Values(DisguiseType type, Class classType, EnumEntitySize entitySize) { |     public Values(DisguiseType type, Class classType, int entitySize) { | ||||||
|         values.put(type, this); |         values.put(type, this); | ||||||
|         enumEntitySize = entitySize; |         enumEntitySize = entitySize; | ||||||
|         declared = classType; |         declared = classType; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public HashMap<String, Double> getAttributesValues() { |  | ||||||
|         return attributesValues; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public Class getEntityClass() { |     public Class getEntityClass() { | ||||||
|         return declared; |         return declared; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public EnumEntitySize getEntitySize() { |     public int getEntitySize(double paramDouble) { | ||||||
|         return enumEntitySize; |         double d = paramDouble - (((int) Math.floor(paramDouble)) + 0.5D); | ||||||
|  |  | ||||||
|  |         switch (enumEntitySize) { | ||||||
|  |         case 1: | ||||||
|  |             if (d < 0.0D ? d < -0.3125D : d < 0.3125D) { | ||||||
|  |                 return (int) Math.ceil(paramDouble * 32.0D); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return (int) Math.floor(paramDouble * 32.0D); | ||||||
|  |         case 2: | ||||||
|  |             if (d < 0.0D ? d < -0.3125D : d < 0.3125D) { | ||||||
|  |                 return (int) Math.floor(paramDouble * 32.0D); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return (int) Math.ceil(paramDouble * 32.0D); | ||||||
|  |         case 3: | ||||||
|  |             if (d > 0.0D) { | ||||||
|  |                 return (int) Math.floor(paramDouble * 32.0D); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return (int) Math.ceil(paramDouble * 32.0D); | ||||||
|  |         case 4: | ||||||
|  |             if (d < 0.0D ? d < -0.1875D : d < 0.1875D) { | ||||||
|  |                 return (int) Math.ceil(paramDouble * 32.0D); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return (int) Math.floor(paramDouble * 32.0D); | ||||||
|  |         case 5: | ||||||
|  |             if (d < 0.0D ? d < -0.1875D : d < 0.1875D) { | ||||||
|  |                 return (int) Math.floor(paramDouble * 32.0D); | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             return (int) Math.ceil(paramDouble * 32.0D); | ||||||
|  |         case 6: | ||||||
|  |         } | ||||||
|  |         if (d > 0.0D) { | ||||||
|  |             return (int) Math.ceil(paramDouble * 32.0D); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return (int) Math.floor(paramDouble * 32.0D); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public HashMap<Integer, Object> getMetaValues() { |     public HashMap<Integer, Object> getMetaValues() { | ||||||
|         return metaValues; |         return metaValues; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setAttributesValue(String attribute, Double value) { |  | ||||||
|         attributesValues.put(attribute, value); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public void setMetaValue(int no, Object value) { |     public void setMetaValue(int no, Object value) { | ||||||
|         metaValues.put(no, value); |         metaValues.put(no, value); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -7,15 +7,14 @@ public class ArrowWatcher extends FlagWatcher { | |||||||
|  |  | ||||||
|     public ArrowWatcher(Disguise disguise) { |     public ArrowWatcher(Disguise disguise) { | ||||||
|         super(disguise); |         super(disguise); | ||||||
|         setValue(16, (byte) 0); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isMoving() { |     public boolean isCritical() { | ||||||
|         return (Byte) getValue(16, (byte) 0) == 1; |         return (Byte) getValue(16, (byte) 0) == 1; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setMoving(boolean moving) { |     public void setCritical(boolean critical) { | ||||||
|         setValue(16, (byte) (moving ? 1 : 0)); |         setValue(16, (byte) (critical ? 1 : 0)); | ||||||
|         sendData(16); |         sendData(16); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,9 +1,9 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | package me.libraryaddict.disguise.disguisetypes.watchers; | ||||||
|  |  | ||||||
|  | import me.libraryaddict.disguise.ReflectionManager; | ||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||||
|  |  | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack; |  | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
|  |  | ||||||
| public class DroppedItemWatcher extends FlagWatcher { | public class DroppedItemWatcher extends FlagWatcher { | ||||||
| @@ -13,12 +13,11 @@ public class DroppedItemWatcher extends FlagWatcher { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public ItemStack getItemStack() { |     public ItemStack getItemStack() { | ||||||
|         return CraftItemStack.asBukkitCopy((net.minecraft.server.v1_6_R3.ItemStack) getValue(10, |         return ReflectionManager.getBukkitItem(getValue(10, ReflectionManager.getNmsItem(new ItemStack(1)))); | ||||||
|                 CraftItemStack.asNMSCopy(new ItemStack(1)))); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void setItemStack(ItemStack item) { |     public void setItemStack(ItemStack item) { | ||||||
|         setValue(10, CraftItemStack.asNMSCopy(item)); |         setValue(10, ReflectionManager.getNmsItem(item)); | ||||||
|         sendData(10); |         sendData(10); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,9 +1,9 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | package me.libraryaddict.disguise.disguisetypes.watchers; | ||||||
|  |  | ||||||
|  | import me.libraryaddict.disguise.ReflectionManager; | ||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||||
|  |  | ||||||
| import org.bukkit.craftbukkit.v1_6_R3.inventory.CraftItemStack; |  | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
|  |  | ||||||
| public class ItemFrameWatcher extends FlagWatcher { | public class ItemFrameWatcher extends FlagWatcher { | ||||||
| @@ -19,7 +19,7 @@ public class ItemFrameWatcher extends FlagWatcher { | |||||||
|     public ItemStack getItemStack() { |     public ItemStack getItemStack() { | ||||||
|         if (getValue(2, null) == null) |         if (getValue(2, null) == null) | ||||||
|             return new ItemStack(0); |             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) { |     public void setItemRotation(int rotation) { | ||||||
| @@ -30,7 +30,7 @@ public class ItemFrameWatcher extends FlagWatcher { | |||||||
|     public void setItemStack(ItemStack newItem) { |     public void setItemStack(ItemStack newItem) { | ||||||
|         newItem = newItem.clone(); |         newItem = newItem.clone(); | ||||||
|         newItem.setAmount(1); |         newItem.setAmount(1); | ||||||
|         setValue(2, CraftItemStack.asNMSCopy(newItem)); |         setValue(2, ReflectionManager.getNmsItem(newItem)); | ||||||
|         sendData(2); |         sendData(2); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,18 +1,38 @@ | |||||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | package me.libraryaddict.disguise.disguisetypes.watchers; | ||||||
|  |  | ||||||
|  | import java.lang.reflect.Method; | ||||||
| import java.util.HashSet; | import java.util.HashSet; | ||||||
| import java.util.Iterator; | import me.libraryaddict.disguise.ReflectionManager; | ||||||
|  |  | ||||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | 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.PotionEffect; | ||||||
| import org.bukkit.potion.PotionEffectType; | import org.bukkit.potion.PotionEffectType; | ||||||
|  |  | ||||||
| public class LivingWatcher extends FlagWatcher { | 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) { |     public LivingWatcher(Disguise disguise) { | ||||||
|         super(disguise); |         super(disguise); | ||||||
| @@ -22,21 +42,21 @@ public class LivingWatcher extends FlagWatcher { | |||||||
|     public void addPotionEffect(PotionEffect potionEffect) { |     public void addPotionEffect(PotionEffect potionEffect) { | ||||||
|         if (hasPotionEffect(potionEffect.getType())) |         if (hasPotionEffect(potionEffect.getType())) | ||||||
|             removePotionEffect(potionEffect.getType()); |             removePotionEffect(potionEffect.getType()); | ||||||
|         potionEffects.add(new MobEffect(potionEffect.getType().getId(), potionEffect.getDuration(), potionEffect.getAmplifier())); |         potionEffects.add(potionEffect.getType().getId()); | ||||||
|         sendPotionEffects(); |         sendPotionEffects(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void addPotionEffect(PotionEffectType potionEffect) { |     public void addPotionEffect(PotionEffectType potionEffect) { | ||||||
|         if (hasPotionEffect(potionEffect)) |         if (hasPotionEffect(potionEffect)) | ||||||
|             removePotionEffect(potionEffect); |             removePotionEffect(potionEffect); | ||||||
|         potionEffects.add(new MobEffect(potionEffect.getId(), 0, 0)); |         potionEffects.add(potionEffect.getId()); | ||||||
|         sendPotionEffects(); |         sendPotionEffects(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public LivingWatcher clone(Disguise disguise) { |     public LivingWatcher clone(Disguise disguise) { | ||||||
|         LivingWatcher clone = (LivingWatcher) super.clone(disguise); |         LivingWatcher clone = (LivingWatcher) super.clone(disguise); | ||||||
|         clone.potionEffects = (HashSet<MobEffect>) potionEffects.clone(); |         clone.potionEffects = (HashSet<Integer>) potionEffects.clone(); | ||||||
|         return clone; |         return clone; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -57,10 +77,7 @@ public class LivingWatcher extends FlagWatcher { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean hasPotionEffect(PotionEffectType type) { |     public boolean hasPotionEffect(PotionEffectType type) { | ||||||
|         for (MobEffect effect : potionEffects) |         return potionEffects.contains(type.getId()); | ||||||
|             if (effect.getEffectId() == type.getId()) |  | ||||||
|                 return true; |  | ||||||
|         return false; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public boolean isCustomNameVisible() { |     public boolean isCustomNameVisible() { | ||||||
| @@ -68,14 +85,9 @@ public class LivingWatcher extends FlagWatcher { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void removePotionEffect(PotionEffectType type) { |     public void removePotionEffect(PotionEffectType type) { | ||||||
|         Iterator<MobEffect> itel = potionEffects.iterator(); |         if (potionEffects.contains(type.getId())) { | ||||||
|         while (itel.hasNext()) { |             potionEffects.remove(type.getId()); | ||||||
|             MobEffect effect = itel.next(); |  | ||||||
|             if (effect.getEffectId() == type.getId()) { |  | ||||||
|                 itel.remove(); |  | ||||||
|             sendPotionEffects(); |             sendPotionEffects(); | ||||||
|                 return; |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -85,10 +97,40 @@ public class LivingWatcher extends FlagWatcher { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void sendPotionEffects() { |     private void sendPotionEffects() { | ||||||
|         setValue(7, PotionBrewer.a(potionEffects)); |         setValue(7, getPotions()); | ||||||
|         sendData(7); |         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) { |     public void setCustomName(String name) { | ||||||
|         if (name.length() > 64) |         if (name.length() > 64) | ||||||
|             name = name.substring(0, 64); |             name = name.substring(0, 64); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user