- Cleaned up code
- Future proofed code via reflection again (DamageSource in PacketsManager)
This commit is contained in:
		| @@ -9,7 +9,7 @@ println 'Compiling LibsDisguises via Gradle ver. ' + gradle.gradleVersion | ||||
| sourceCompatibility = '1.7' | ||||
| ext.spigotVersion = '1.8.8-R0.1-SNAPSHOT' | ||||
|  | ||||
| ext.disguisesVersion = '8.6.7' | ||||
| ext.disguisesVersion = '8.6.8' | ||||
|  | ||||
| [compileJava, compileTestJava]*.options*.encoding = 'UTF-8' | ||||
|  | ||||
|   | ||||
| @@ -1,12 +1,5 @@ | ||||
| package me.libraryaddict.disguise; | ||||
|  | ||||
| import java.lang.reflect.Field; | ||||
| import java.lang.reflect.Method; | ||||
| import java.util.Arrays; | ||||
| import java.util.Collection; | ||||
| import java.util.List; | ||||
| import java.util.UUID; | ||||
|  | ||||
| import me.libraryaddict.disguise.disguisetypes.AnimalColor; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||
| @@ -20,7 +13,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||
| import me.libraryaddict.disguise.utilities.ReflectionManager; | ||||
|  | ||||
| import org.bukkit.DyeColor; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.entity.Entity; | ||||
| @@ -33,6 +25,13 @@ import org.bukkit.inventory.HorseInventory; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| import org.bukkit.potion.PotionEffect; | ||||
|  | ||||
| import java.lang.reflect.Field; | ||||
| import java.lang.reflect.Method; | ||||
| import java.util.Arrays; | ||||
| import java.util.Collection; | ||||
| import java.util.List; | ||||
| import java.util.UUID; | ||||
|  | ||||
| public class DisguiseAPI { | ||||
|  | ||||
|     public static Disguise constructDisguise(Entity entity) { | ||||
| @@ -47,7 +46,7 @@ public class DisguiseAPI { | ||||
|         } else if (disguiseType.isMob()) { | ||||
|             disguise = new MobDisguise(disguiseType); | ||||
|         } else { | ||||
|             disguise = new PlayerDisguise(((Player) entity).getName()); | ||||
|             disguise = new PlayerDisguise(entity.getName()); | ||||
|         } | ||||
|         FlagWatcher watcher = disguise.getWatcher(); | ||||
|         if (entity instanceof LivingEntity) { | ||||
| @@ -105,14 +104,14 @@ public class DisguiseAPI { | ||||
|                                             if (!(toCast.isInstance(value))) { | ||||
|                                                 if (toCast == float.class) { | ||||
|                                                     if (value instanceof Float) { | ||||
|                                                         value = ((Float) value); | ||||
|                                                         value = value; | ||||
|                                                     } else { | ||||
|                                                         double d = (Double) value; | ||||
|                                                         value = (float) d; | ||||
|                                                     } | ||||
|                                                 } else if (toCast == double.class) { | ||||
|                                                     if (value instanceof Double) { | ||||
|                                                         value = ((Double) value); | ||||
|                                                         value = value; | ||||
|                                                     } else { | ||||
|                                                         float d = (Float) value; | ||||
|                                                         value = (double) d; | ||||
|   | ||||
| @@ -1,21 +1,20 @@ | ||||
| package me.libraryaddict.disguise.commands; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
|  | ||||
| import me.libraryaddict.disguise.DisguiseAPI; | ||||
| import me.libraryaddict.disguise.DisguiseConfig; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; | ||||
| import me.libraryaddict.disguise.utilities.BaseDisguiseCommand; | ||||
|  | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.bukkit.ChatColor; | ||||
| import org.bukkit.command.Command; | ||||
| import org.bukkit.command.CommandSender; | ||||
| import org.bukkit.entity.Player; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
|  | ||||
| public class DisguiseCommand extends BaseDisguiseCommand { | ||||
|  | ||||
|     @Override | ||||
| @@ -38,9 +37,9 @@ public class DisguiseCommand extends BaseDisguiseCommand { | ||||
|         } | ||||
|         if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { | ||||
|             if (disguise.getWatcher() instanceof LivingWatcher) { | ||||
|                 ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) sender).getDisplayName()); | ||||
|                 disguise.getWatcher().setCustomName(((Player) sender).getDisplayName()); | ||||
|                 if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { | ||||
|                     ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); | ||||
|                     disguise.getWatcher().setCustomNameVisible(true); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -1,8 +1,5 @@ | ||||
| package me.libraryaddict.disguise.commands; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
|  | ||||
| import me.libraryaddict.disguise.DisguiseAPI; | ||||
| import me.libraryaddict.disguise.DisguiseConfig; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| @@ -16,6 +13,9 @@ import org.bukkit.command.Command; | ||||
| import org.bukkit.command.CommandSender; | ||||
| import org.bukkit.entity.Player; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
|  | ||||
| public class DisguisePlayerCommand extends BaseDisguiseCommand { | ||||
|  | ||||
|     @Override | ||||
| @@ -59,9 +59,9 @@ public class DisguisePlayerCommand extends BaseDisguiseCommand { | ||||
|         } | ||||
|         if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { | ||||
|             if (disguise.getWatcher() instanceof LivingWatcher) { | ||||
|                 ((LivingWatcher) disguise.getWatcher()).setCustomName(player.getDisplayName()); | ||||
|                 disguise.getWatcher().setCustomName(player.getDisplayName()); | ||||
|                 if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { | ||||
|                     ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); | ||||
|                     disguise.getWatcher().setCustomNameVisible(true); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -1,9 +1,5 @@ | ||||
| package me.libraryaddict.disguise.commands; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collections; | ||||
| import java.util.HashMap; | ||||
|  | ||||
| import me.libraryaddict.disguise.DisguiseAPI; | ||||
| import me.libraryaddict.disguise.DisguiseConfig; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| @@ -20,6 +16,10 @@ import org.bukkit.entity.EntityType; | ||||
| import org.bukkit.entity.LivingEntity; | ||||
| import org.bukkit.entity.Player; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collections; | ||||
| import java.util.HashMap; | ||||
|  | ||||
| public class DisguiseRadiusCommand extends BaseDisguiseCommand { | ||||
|  | ||||
|     private int maxRadius = 30; | ||||
| @@ -124,9 +124,9 @@ public class DisguiseRadiusCommand extends BaseDisguiseCommand { | ||||
|                 disguise = disguise.clone(); | ||||
|                 if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) { | ||||
|                     if (disguise.getWatcher() instanceof LivingWatcher) { | ||||
|                         ((LivingWatcher) disguise.getWatcher()).setCustomName(((Player) entity).getDisplayName()); | ||||
|                         disguise.getWatcher().setCustomName(((Player) entity).getDisplayName()); | ||||
|                         if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) { | ||||
|                             ((LivingWatcher) disguise.getWatcher()).setCustomNameVisible(true); | ||||
|                             disguise.getWatcher().setCustomNameVisible(true); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|   | ||||
| @@ -16,7 +16,7 @@ public enum AnimalColor { | ||||
|  | ||||
|     private int value; | ||||
|  | ||||
|     private AnimalColor(int newValue) { | ||||
|     AnimalColor(int newValue) { | ||||
|         value = newValue; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,7 +1,5 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes; | ||||
|  | ||||
| import java.lang.reflect.Method; | ||||
|  | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.EntityType; | ||||
| @@ -10,6 +8,8 @@ import org.bukkit.entity.Horse; | ||||
| import org.bukkit.entity.Skeleton; | ||||
| import org.bukkit.entity.Zombie; | ||||
|  | ||||
| import java.lang.reflect.Method; | ||||
|  | ||||
| public enum DisguiseType { | ||||
|  | ||||
|     ARMOR_STAND(78), | ||||
| @@ -195,7 +195,7 @@ public enum DisguiseType { | ||||
|     private EntityType entityType; | ||||
|     private Class<? extends FlagWatcher> watcherClass; | ||||
|  | ||||
|     private DisguiseType(int... ints) { | ||||
|     DisguiseType(int... ints) { | ||||
|         for (int i = 0; i < ints.length; i++) { | ||||
|             int value = ints[i]; | ||||
|             switch (i) { | ||||
|   | ||||
| @@ -1,27 +1,25 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes; | ||||
|  | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.HashSet; | ||||
| import java.util.List; | ||||
|  | ||||
| import org.bukkit.entity.LivingEntity; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.inventory.EntityEquipment; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
|  | ||||
| import com.comphenix.protocol.PacketType; | ||||
| import com.comphenix.protocol.ProtocolLibrary; | ||||
| import com.comphenix.protocol.events.PacketContainer; | ||||
| import com.comphenix.protocol.reflect.StructureModifier; | ||||
| import com.comphenix.protocol.wrappers.WrappedDataWatcher; | ||||
| import com.comphenix.protocol.wrappers.WrappedWatchableObject; | ||||
|  | ||||
| import me.libraryaddict.disguise.DisguiseAPI; | ||||
| import me.libraryaddict.disguise.DisguiseConfig; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||
| import me.libraryaddict.disguise.utilities.ReflectionManager; | ||||
| import org.bukkit.entity.LivingEntity; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.inventory.EntityEquipment; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
|  | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashMap; | ||||
| import java.util.HashSet; | ||||
| import java.util.List; | ||||
|  | ||||
| public class FlagWatcher { | ||||
|  | ||||
| @@ -31,7 +29,7 @@ public class FlagWatcher { | ||||
|         // The ints is for bukkit. Not nms slots. | ||||
|         private int slotNo = 0; | ||||
|  | ||||
|         private SlotType(int no) { | ||||
|         SlotType(int no) { | ||||
|             slotNo = no; | ||||
|         } | ||||
|  | ||||
| @@ -217,7 +215,7 @@ public class FlagWatcher { | ||||
|     } | ||||
|  | ||||
|     public boolean isCustomNameVisible() { | ||||
|         return (Byte) getValue(3, (byte) 0) == 1; | ||||
|         return (byte) getValue(3, (byte) 0) == 1; | ||||
|     } | ||||
|  | ||||
|     public boolean isEntityAnimationsAdded() { | ||||
|   | ||||
| @@ -15,7 +15,7 @@ public enum RabbitType { | ||||
|  | ||||
|     private int type; | ||||
|  | ||||
|     private RabbitType(int type) { | ||||
|     RabbitType(int type) { | ||||
|         this.type = type; | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -1,19 +1,18 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes; | ||||
|  | ||||
| import me.libraryaddict.disguise.DisguiseAPI; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||
| import org.bukkit.entity.Player; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
|  | ||||
| import me.libraryaddict.disguise.DisguiseAPI; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||
| import me.libraryaddict.disguise.utilities.ReflectionManager; | ||||
| import org.bukkit.entity.Player; | ||||
|  | ||||
| public abstract class TargetedDisguise extends Disguise { | ||||
|  | ||||
|     public enum TargetType { | ||||
|  | ||||
|         HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS, SHOW_TO_EVERYONE_BUT_THESE_PLAYERS; | ||||
|         HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS, SHOW_TO_EVERYONE_BUT_THESE_PLAYERS | ||||
|     } | ||||
|  | ||||
|     private List<String> disguiseViewers = new ArrayList<>(); | ||||
|   | ||||
| @@ -1,9 +1,8 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | ||||
|  | ||||
| import org.bukkit.inventory.ItemStack; | ||||
|  | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
|  | ||||
| public class MinecartWatcher extends FlagWatcher { | ||||
|  | ||||
| @@ -37,7 +36,7 @@ public class MinecartWatcher extends FlagWatcher { | ||||
|     public void setBlockInCart(ItemStack item) { | ||||
|         int id = item.getTypeId(); | ||||
|         int data = item.getDurability(); | ||||
|         setValue(20, (int) (id & 0xffff | data << 16)); | ||||
|         setValue(20, id & 0xffff | data << 16); | ||||
|         setValue(22, (byte) 1); | ||||
|         sendData(20, 22); | ||||
|     } | ||||
|   | ||||
| @@ -1,10 +1,10 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes.watchers; | ||||
|  | ||||
| import java.util.Random; | ||||
|  | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.RabbitType; | ||||
|  | ||||
| import java.util.Random; | ||||
|  | ||||
| public class RabbitWatcher extends AgeableWatcher { | ||||
|  | ||||
|     public RabbitWatcher(Disguise disguise) { | ||||
| @@ -13,7 +13,7 @@ public class RabbitWatcher extends AgeableWatcher { | ||||
|     } | ||||
|  | ||||
|     public RabbitType getType() { | ||||
|         return RabbitType.getType((Integer) getValue(18, (int) 0)); | ||||
|         return RabbitType.getType((Integer) getValue(18, 0)); | ||||
|     } | ||||
|  | ||||
|     public void setType(RabbitType type) { | ||||
|   | ||||
| @@ -1,16 +1,5 @@ | ||||
| package me.libraryaddict.disguise.utilities; | ||||
|  | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.lang.reflect.Method; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| import java.util.Collections; | ||||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.Map.Entry; | ||||
| import java.util.UUID; | ||||
| import me.libraryaddict.disguise.DisguiseConfig; | ||||
|  | ||||
| import me.libraryaddict.disguise.disguisetypes.AnimalColor; | ||||
| import me.libraryaddict.disguise.disguisetypes.Disguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||
| @@ -19,7 +8,6 @@ import me.libraryaddict.disguise.disguisetypes.MiscDisguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.MobDisguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | ||||
| import me.libraryaddict.disguise.disguisetypes.RabbitType; | ||||
|  | ||||
| import org.bukkit.ChatColor; | ||||
| import org.bukkit.Material; | ||||
| import org.bukkit.block.BlockFace; | ||||
| @@ -32,6 +20,14 @@ import org.bukkit.inventory.ItemStack; | ||||
| import org.bukkit.permissions.PermissionAttachmentInfo; | ||||
| import org.bukkit.potion.PotionEffectType; | ||||
|  | ||||
| import java.lang.reflect.InvocationTargetException; | ||||
| import java.lang.reflect.Method; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Arrays; | ||||
| import java.util.Collections; | ||||
| import java.util.HashMap; | ||||
| import java.util.Map.Entry; | ||||
|  | ||||
| public abstract class BaseDisguiseCommand implements CommandExecutor { | ||||
|  | ||||
|     public class DisguiseParseException extends Exception { | ||||
| @@ -506,7 +502,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { | ||||
|                         if (int.class == param) { | ||||
|                             // Parse to integer | ||||
|                             if (isNumeric(valueString)) { | ||||
|                                 value = (int) Integer.parseInt(valueString); | ||||
|                                 value = Integer.parseInt(valueString); | ||||
|                             } else { | ||||
|                                 throw parseToException("number", valueString, methodName); | ||||
|                             } | ||||
| @@ -515,7 +511,7 @@ public abstract class BaseDisguiseCommand implements CommandExecutor { | ||||
|                             if (isDouble(valueString)) { | ||||
|                                 float obj = Float.parseFloat(valueString); | ||||
|                                 if (param == float.class) { | ||||
|                                     value = (float) obj; | ||||
|                                     value = obj; | ||||
|                                 } else if (param == double.class) { | ||||
|                                     value = (double) obj; | ||||
|                                 } | ||||
|   | ||||
| @@ -1,12 +1,10 @@ | ||||
| package me.libraryaddict.disguise.utilities; | ||||
|  | ||||
| import org.bukkit.Sound; | ||||
|  | ||||
| import java.util.HashMap; | ||||
| import java.util.HashSet; | ||||
|  | ||||
| import me.libraryaddict.disguise.utilities.ReflectionManager.LibVersion; | ||||
|  | ||||
| import org.bukkit.Sound; | ||||
|  | ||||
| /** | ||||
|  * Only living disguises go in here! | ||||
|  */ | ||||
| @@ -74,7 +72,7 @@ public enum DisguiseSound { | ||||
|  | ||||
|     public enum SoundType { | ||||
|  | ||||
|         CANCEL, DEATH, HURT, IDLE, STEP; | ||||
|         CANCEL, DEATH, HURT, IDLE, STEP | ||||
|     } | ||||
|  | ||||
|     public static DisguiseSound getType(String name) { | ||||
| @@ -89,7 +87,7 @@ public enum DisguiseSound { | ||||
|     private float damageSoundVolume = 1F; | ||||
|     private HashMap<SoundType, String> disguiseSounds = new HashMap<>(); | ||||
|  | ||||
|     private DisguiseSound(Object... sounds) { | ||||
|     DisguiseSound(Object... sounds) { | ||||
|         for (int i = 0; i < sounds.length; i++) { | ||||
|             Object obj = sounds[i]; | ||||
|             String s; | ||||
|   | ||||
| @@ -4,6 +4,6 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||
|  | ||||
| public interface LibsProfileLookup { | ||||
|  | ||||
|     public void onLookup(WrappedGameProfile gameProfile); | ||||
|     void onLookup(WrappedGameProfile gameProfile); | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -28,7 +28,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher; | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType; | ||||
| import net.minecraft.server.v1_8_R3.DamageSource; | ||||
| import org.bukkit.Art; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| @@ -55,9 +54,9 @@ import java.util.Random; | ||||
| import java.util.UUID; | ||||
|  | ||||
| public class PacketsManager { | ||||
|  | ||||
|     /** | ||||
|      * This is a fix for the stupidity that is "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard" | ||||
|      * This is a fix for the stupidity that is | ||||
|      * "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard" | ||||
|      */ | ||||
|     private static boolean cancelSound; | ||||
|     private static PacketListener clientInteractEntityListener; | ||||
| @@ -78,9 +77,8 @@ public class PacketsManager { | ||||
|                 PacketType.Play.Client.USE_ENTITY) { | ||||
|             @Override | ||||
|             public void onPacketReceiving(PacketEvent event) { | ||||
|                 if (event.isCancelled()) { | ||||
|                 if (event.isCancelled()) | ||||
|                     return; | ||||
|                 } | ||||
|                 try { | ||||
|                     Player observer = event.getPlayer(); | ||||
|                     StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld()); | ||||
| @@ -105,7 +103,7 @@ public class PacketsManager { | ||||
|                         } | ||||
|                     } | ||||
|                 } catch (Exception e) { | ||||
|                     e.printStackTrace(System.out); | ||||
|                     e.printStackTrace(); | ||||
|                 } | ||||
|             } | ||||
|         }; | ||||
| @@ -116,26 +114,19 @@ public class PacketsManager { | ||||
|  | ||||
|     /** | ||||
|      * Construct the packets I need to spawn in the disguise | ||||
|      * | ||||
|      * @param player | ||||
|      * @param disguise | ||||
|      * @param disguisedEntity | ||||
|      * @return | ||||
|      */ | ||||
|     public static PacketContainer[][] constructSpawnPackets(final Player player, Disguise disguise, Entity disguisedEntity) { | ||||
|         if (disguise.getEntity() == null) { | ||||
|         if (disguise.getEntity() == null) | ||||
|             disguise.setEntity(disguisedEntity); | ||||
|         } | ||||
|         Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity); | ||||
|         ArrayList<PacketContainer> packets = new ArrayList<>(); | ||||
|         ArrayList<PacketContainer> packets = new ArrayList<PacketContainer>(); | ||||
|         // This sends the armor packets so that the player isn't naked. | ||||
|         // Please note it only sends the packets that wouldn't be sent normally | ||||
|         if (DisguiseConfig.isEquipmentPacketsEnabled()) { | ||||
|             for (int nmsSlot = 0; nmsSlot < 5; nmsSlot++) { | ||||
|                 int armorSlot = nmsSlot - 1; | ||||
|                 if (armorSlot < 0) { | ||||
|                 if (armorSlot < 0) | ||||
|                     armorSlot = 4; | ||||
|                 } | ||||
|                 ItemStack itemstack = disguise.getWatcher().getItemStack(armorSlot); | ||||
|                 if (itemstack != null && itemstack.getTypeId() != 0) { | ||||
|                     ItemStack item = null; | ||||
| @@ -160,7 +151,7 @@ public class PacketsManager { | ||||
|         if (DisguiseConfig.isMiscDisguisesForLivingEnabled()) { | ||||
|             if (disguise.getWatcher() instanceof LivingWatcher) { | ||||
|                 PacketContainer packet = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES); | ||||
|                 List<WrappedAttribute> attributes = new ArrayList<>(); | ||||
|                 List<WrappedAttribute> attributes = new ArrayList<WrappedAttribute>(); | ||||
|                 Builder builder = WrappedAttribute.newBuilder().attributeKey("generic.maxHealth"); | ||||
|                 if (((LivingWatcher) disguise.getWatcher()).isMaxHealthSet()) { | ||||
|                     builder.baseValue(((LivingWatcher) disguise.getWatcher()).getMaxHealth()); | ||||
| @@ -219,6 +210,7 @@ public class PacketsManager { | ||||
|             mods.write(5, pitch); | ||||
|  | ||||
|         } else if (disguise.getType().isPlayer()) { | ||||
|  | ||||
|             spawnPackets[0] = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN); | ||||
|             StructureModifier<String> stringMods = spawnPackets[0].getStrings(); | ||||
|             WrappedGameProfile gameProfile; | ||||
| @@ -270,12 +262,11 @@ public class PacketsManager { | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             ArrayList<PacketContainer> newPackets = new ArrayList<>(); | ||||
|             ArrayList<PacketContainer> newPackets = new ArrayList<PacketContainer>(); | ||||
|             newPackets.add(null); | ||||
|             for (PacketContainer spawnPacket : spawnPackets) { | ||||
|                 if (spawnPacket != null) { | ||||
|                     // Get rid of empty packet '1' if it exists. | ||||
|                     newPackets.add(spawnPacket); | ||||
|             for (int i = 0; i < spawnPackets.length; i++) { | ||||
|                 if (spawnPackets[i] != null) { // Get rid of empty packet '1' if it exists. | ||||
|                     newPackets.add(spawnPackets[i]); | ||||
|                 } | ||||
|             } | ||||
|             spawnPackets = newPackets.toArray(new PacketContainer[newPackets.size()]); | ||||
| @@ -287,9 +278,10 @@ public class PacketsManager { | ||||
|             spawnPackets[0].getModifier().write(1, playerList); | ||||
|             PacketContainer delayedPacket = spawnPackets[0].shallowClone(); | ||||
|             delayedPacket.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4)); | ||||
|             delayedPackets = new PacketContainer[]{delayedPacket}; | ||||
|             delayedPackets = new PacketContainer[] { delayedPacket }; | ||||
|  | ||||
|         } else if (disguise.getType().isMob() || disguise.getType() == DisguiseType.ARMOR_STAND) { | ||||
|  | ||||
|             DisguiseValues values = DisguiseValues.getDisguiseValues(disguise.getType()); | ||||
|             Vector vec = disguisedEntity.getVelocity(); | ||||
|             spawnPackets[0] = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_LIVING); | ||||
| @@ -300,24 +292,18 @@ public class PacketsManager { | ||||
|             double d2 = vec.getX(); | ||||
|             double d3 = vec.getY(); | ||||
|             double d4 = vec.getZ(); | ||||
|             if (d2 < -d1) { | ||||
|             if (d2 < -d1) | ||||
|                 d2 = -d1; | ||||
|             } | ||||
|             if (d3 < -d1) { | ||||
|             if (d3 < -d1) | ||||
|                 d3 = -d1; | ||||
|             } | ||||
|             if (d4 < -d1) { | ||||
|             if (d4 < -d1) | ||||
|                 d4 = -d1; | ||||
|             } | ||||
|             if (d2 > d1) { | ||||
|             if (d2 > d1) | ||||
|                 d2 = d1; | ||||
|             } | ||||
|             if (d3 > d1) { | ||||
|             if (d3 > d1) | ||||
|                 d3 = d1; | ||||
|             } | ||||
|             if (d4 > d1) { | ||||
|             if (d4 > d1) | ||||
|                 d4 = d1; | ||||
|             } | ||||
|             mods.write(2, values.getEntitySize(loc.getX())); | ||||
|             mods.write(3, (int) Math.floor(loc.getY() * 32D)); | ||||
|             mods.write(4, values.getEntitySize(loc.getZ())); | ||||
| @@ -328,12 +314,13 @@ public class PacketsManager { | ||||
|             mods.write(9, pitch); | ||||
|             spawnPackets[0].getDataWatcherModifier().write(0, | ||||
|                     createDataWatcher(player, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher())); | ||||
|  | ||||
|         } else if (disguise.getType().isMisc()) { | ||||
|             MiscDisguise msc = (MiscDisguise) disguise; | ||||
|  | ||||
|             int id = disguise.getType().getEntityId(); | ||||
|             int data = msc.getData(); | ||||
|             int data = ((MiscDisguise) disguise).getData(); | ||||
|             if (disguise.getType() == DisguiseType.FALLING_BLOCK) { | ||||
|                 data = msc.getId() + (msc.getData() << 12); | ||||
|                 data = (((MiscDisguise) disguise).getId() | data << 16); | ||||
|             } else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) { | ||||
|                 // If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id | ||||
|                 data = disguisedEntity.getEntityId(); | ||||
| @@ -366,7 +353,7 @@ public class PacketsManager { | ||||
|             mods.write(0, disguisedEntity.getEntityId()); | ||||
|             mods.write(1, yaw); | ||||
|         } | ||||
|         return new PacketContainer[][]{spawnPackets, delayedPackets}; | ||||
|         return new PacketContainer[][] { spawnPackets, delayedPackets }; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| @@ -382,7 +369,7 @@ public class PacketsManager { | ||||
|                 newWatcher.setObject(watchableObject.getIndex(), watchableObject.getValue()); | ||||
|             } | ||||
|         } catch (Exception ex) { | ||||
|             ex.printStackTrace(System.out); | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|         return newWatcher; | ||||
|     } | ||||
| @@ -487,9 +474,8 @@ public class PacketsManager { | ||||
|         } | ||||
|         switch (disguise.getType()) { | ||||
|             case BAT: | ||||
|                 if (entity instanceof LivingEntity) { | ||||
|                 if (entity instanceof LivingEntity) | ||||
|                     return yMod + ((LivingEntity) entity).getEyeHeight(); | ||||
|                 } | ||||
|             case MINECART: | ||||
|             case MINECART_COMMAND: | ||||
|             case MINECART_CHEST: | ||||
| @@ -536,8 +522,6 @@ public class PacketsManager { | ||||
|  | ||||
|     /** | ||||
|      * Creates the packet listeners | ||||
|      * | ||||
|      * @param plugin | ||||
|      */ | ||||
|     public static void init(LibsDisguises plugin) { | ||||
|         libsDisguises = plugin; | ||||
| @@ -563,7 +547,8 @@ public class PacketsManager { | ||||
|                     DisguiseSound entitySound = null; | ||||
|                     Disguise disguise = null; | ||||
|                     Entity[] entities = soundLoc.getChunk().getEntities(); | ||||
|                     for (Entity entity : entities) { | ||||
|                     for (int i = 0; i < entities.length; i++) { | ||||
|                         Entity entity = entities[i]; | ||||
|                         Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity); | ||||
|                         if (entityDisguise != null) { | ||||
|                             Location loc = entity.getLocation(); | ||||
| @@ -583,7 +568,7 @@ public class PacketsManager { | ||||
|                                                 obj = null; | ||||
|                                             } | ||||
|                                         } catch (Exception e) { | ||||
|                                             e.printStackTrace(System.out); | ||||
|                                             e.printStackTrace(); | ||||
|                                         } | ||||
|                                     } | ||||
|                                     if (obj == null) { | ||||
| @@ -595,11 +580,12 @@ public class PacketsManager { | ||||
|                                                         nmsEntity) == ReflectionManager.getNmsField("EntityLiving", | ||||
|                                                         "maxNoDamageTicks").getInt(nmsEntity); | ||||
|                                             } else { | ||||
|                                                 hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", DamageSource.class) | ||||
|                                                         .invoke(nmsEntity, DamageSource.GENERIC); | ||||
|                                                 Class clazz = ReflectionManager.getNmsClass("DamageSource"); | ||||
|                                                 hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", clazz) | ||||
|                                                         .invoke(nmsEntity, ReflectionManager.getNmsField(clazz, "GENERIC")); | ||||
|                                             } | ||||
|                                         } catch (Exception ex) { | ||||
|                                             ex.printStackTrace(System.out); | ||||
|                                             ex.printStackTrace(); | ||||
|                                         } | ||||
|                                         soundType = entitySound.getType(soundName, !hasInvun); | ||||
|                                     } | ||||
| @@ -617,9 +603,8 @@ public class PacketsManager { | ||||
|                             if (disguise.isSoundsReplaced()) { | ||||
|                                 String sound = null; | ||||
|                                 DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name()); | ||||
|                                 if (dSound != null) { | ||||
|                                 if (dSound != null) | ||||
|                                     sound = dSound.getSound(soundType); | ||||
|                                 } | ||||
|  | ||||
|                                 if (sound == null) { | ||||
|                                     event.setCancelled(true); | ||||
| @@ -637,7 +622,7 @@ public class PacketsManager { | ||||
|                                                         .invoke(step)); | ||||
|                                             } | ||||
|                                         } catch (Exception ex) { | ||||
|                                             ex.printStackTrace(System.out); | ||||
|                                             ex.printStackTrace(); | ||||
|                                         } | ||||
|                                         // There is no else statement. Because seriously. This should never be null. Unless | ||||
|                                         // someone is | ||||
| @@ -665,9 +650,8 @@ public class PacketsManager { | ||||
|                                                     float pitch = (Integer) mods.read(5); | ||||
|                                                     if (baby) { | ||||
|                                                         // If the pitch is not the expected | ||||
|                                                         if (pitch > 97 || pitch < 111) { | ||||
|                                                         if (pitch > 97 || pitch < 111) | ||||
|                                                             return; | ||||
|                                                         } | ||||
|                                                         pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; | ||||
|                                                         // Min = 1.5 | ||||
|                                                         // Cap = 97.5 | ||||
| @@ -675,9 +659,8 @@ public class PacketsManager { | ||||
|                                                         // Cap = 110.5 | ||||
|                                                     } else { | ||||
|                                                         // If the pitch is not the expected | ||||
|                                                         if (pitch >= 63 || pitch <= 76) { | ||||
|                                                         if (pitch >= 63 || pitch <= 76) | ||||
|                                                             return; | ||||
|                                                         } | ||||
|                                                         pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; | ||||
|                                                         // Min = 1 | ||||
|                                                         // Cap = 63 | ||||
| @@ -685,12 +668,10 @@ public class PacketsManager { | ||||
|                                                         // Cap = 75.6 | ||||
|                                                     } | ||||
|                                                     pitch *= 63; | ||||
|                                                     if (pitch < 0) { | ||||
|                                                     if (pitch < 0) | ||||
|                                                         pitch = 0; | ||||
|                                                     } | ||||
|                                                     if (pitch > 255) { | ||||
|                                                     if (pitch > 255) | ||||
|                                                         pitch = 255; | ||||
|                                                     } | ||||
|                                                     mods.write(5, (int) pitch); | ||||
|                                                 } | ||||
|                                             } | ||||
| @@ -708,9 +689,8 @@ public class PacketsManager { | ||||
|                         if (disguise != null && !disguise.getType().isPlayer() | ||||
|                                 && (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) { | ||||
|                             DisguiseSound disSound = DisguiseSound.getType(entity.getType().name()); | ||||
|                             if (disSound == null) { | ||||
|                             if (disSound == null) | ||||
|                                 return; | ||||
|                             } | ||||
|                             SoundType soundType = null; | ||||
|                             Object obj = null; | ||||
|                             if (entity instanceof LivingEntity) { | ||||
| @@ -722,7 +702,7 @@ public class PacketsManager { | ||||
|                                         obj = null; | ||||
|                                     } | ||||
|                                 } catch (Exception e) { | ||||
|                                     e.printStackTrace(System.out); | ||||
|                                     e.printStackTrace(); | ||||
|                                 } | ||||
|                             } | ||||
|                             if (obj == null) { | ||||
| @@ -732,9 +712,8 @@ public class PacketsManager { | ||||
|                                     || (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) { | ||||
|                                 if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) { | ||||
|                                     cancelSound = !cancelSound; | ||||
|                                     if (cancelSound) { | ||||
|                                     if (cancelSound) | ||||
|                                         return; | ||||
|                                     } | ||||
|                                 } | ||||
|                                 disSound = DisguiseSound.getType(disguise.getType().name()); | ||||
|                                 if (disSound != null) { | ||||
| @@ -751,24 +730,20 @@ public class PacketsManager { | ||||
|                                         float pitch; | ||||
|                                         if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) { | ||||
|                                             pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; | ||||
|                                         } else { | ||||
|                                         } else | ||||
|                                             pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; | ||||
|                                         } | ||||
|                                         if (disguise.getType() == DisguiseType.BAT) { | ||||
|                                         if (disguise.getType() == DisguiseType.BAT) | ||||
|                                             pitch *= 95F; | ||||
|                                         } | ||||
|                                         pitch *= 63; | ||||
|                                         if (pitch < 0) { | ||||
|                                         if (pitch < 0) | ||||
|                                             pitch = 0; | ||||
|                                         } | ||||
|                                         if (pitch > 255) { | ||||
|                                         if (pitch > 255) | ||||
|                                             pitch = 255; | ||||
|                                         } | ||||
|                                         mods.write(5, (int) pitch); | ||||
|                                         try { | ||||
|                                             ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); | ||||
|                                         } catch (InvocationTargetException e) { | ||||
|                                             e.printStackTrace(System.out); | ||||
|                                             e.printStackTrace(); | ||||
|                                         } | ||||
|                                     } | ||||
|                                 } | ||||
| @@ -788,9 +763,8 @@ public class PacketsManager { | ||||
|                 PacketType.Play.Server.UPDATE_ATTRIBUTES, PacketType.Play.Server.ENTITY_STATUS) { | ||||
|             @Override | ||||
|             public void onPacketSending(PacketEvent event) { | ||||
|                 if (event.isCancelled()) { | ||||
|                 if (event.isCancelled()) | ||||
|                     return; | ||||
|                 } | ||||
|                 final Player observer = event.getPlayer(); | ||||
|                 if (event.getPacket().getIntegers().read(0) == observer.getEntityId()) { | ||||
|                     if (DisguiseAPI.isSelfDisguised(observer)) { | ||||
| @@ -799,7 +773,7 @@ public class PacketsManager { | ||||
|                         PacketContainer[] packets = transformed == null ? null : transformed[0]; | ||||
|                         final PacketContainer[] delayedPackets = transformed == null ? null : transformed[1]; | ||||
|                         if (packets == null) { | ||||
|                             packets = new PacketContainer[]{event.getPacket()}; | ||||
|                             packets = new PacketContainer[] { event.getPacket() }; | ||||
|                         } | ||||
|                         for (PacketContainer packet : packets) { | ||||
|                             if (packet.getType() != PacketType.Play.Server.PLAYER_INFO) { | ||||
| @@ -811,19 +785,18 @@ public class PacketsManager { | ||||
|                             try { | ||||
|                                 ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); | ||||
|                             } catch (InvocationTargetException e) { | ||||
|                                 e.printStackTrace(System.out); | ||||
|                                 e.printStackTrace(); | ||||
|                             } | ||||
|                         } | ||||
|                         if (delayedPackets != null && delayedPackets.length > 0) { | ||||
|                             Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { | ||||
|                                 @Override | ||||
|                                 public void run() { | ||||
|                                     try { | ||||
|                                         for (PacketContainer packet : delayedPackets) { | ||||
|                                             ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); | ||||
|                                         } | ||||
|                                     } catch (InvocationTargetException e) { | ||||
|                                         e.printStackTrace(System.out); | ||||
|                                         e.printStackTrace(); | ||||
|                                     } | ||||
|                                 } | ||||
|                             }, 2); | ||||
| @@ -834,9 +807,8 @@ public class PacketsManager { | ||||
|                                 if (watch.getIndex() == 0) { | ||||
|                                     byte b = (Byte) watch.getValue(); | ||||
|                                     byte a = (byte) (b | 1 << 5); | ||||
|                                     if ((b & 1 << 3) != 0) { | ||||
|                                     if ((b & 1 << 3) != 0) | ||||
|                                         a = (byte) (a | 1 << 3); | ||||
|                                     } | ||||
|                                     watch.setValue(a); | ||||
|                                 } | ||||
|                             } | ||||
| @@ -845,17 +817,16 @@ public class PacketsManager { | ||||
|                             PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); | ||||
|                             StructureModifier<Object> mods = packet.getModifier(); | ||||
|                             mods.write(0, observer.getEntityId()); | ||||
|                             List<WrappedWatchableObject> watchableList = new ArrayList<>(); | ||||
|                             List<WrappedWatchableObject> watchableList = new ArrayList<WrappedWatchableObject>(); | ||||
|                             byte b = (byte) 1 << 5; | ||||
|                             if (observer.isSprinting()) { | ||||
|                             if (observer.isSprinting()) | ||||
|                                 b = (byte) (b | 1 << 3); | ||||
|                             } | ||||
|                             watchableList.add(new WrappedWatchableObject(0, b)); | ||||
|                             packet.getWatchableCollectionModifier().write(0, watchableList); | ||||
|                             try { | ||||
|                                 ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); | ||||
|                             } catch (InvocationTargetException e) { | ||||
|                                 e.printStackTrace(System.out); | ||||
|                                 e.printStackTrace(); | ||||
|                             } | ||||
|                         } else if (event.getPacketType() == PacketType.Play.Server.ANIMATION) { | ||||
|                             if (event.getPacket().getIntegers().read(1) != 2) { | ||||
| @@ -888,9 +859,8 @@ public class PacketsManager { | ||||
|                 PacketType.Play.Client.SET_CREATIVE_SLOT, PacketType.Play.Client.WINDOW_CLICK) { | ||||
|             @Override | ||||
|             public void onPacketReceiving(final PacketEvent event) { | ||||
|                 if (event.isCancelled()) { | ||||
|                 if (event.isCancelled()) | ||||
|                     return; | ||||
|                 } | ||||
|                 if (!(event.getPlayer() instanceof com.comphenix.net.sf.cglib.proxy.Factory) | ||||
|                         && event.getPlayer().getVehicle() == null) { | ||||
|                     Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer(), event.getPlayer()); | ||||
| @@ -914,7 +884,7 @@ public class PacketsManager { | ||||
|                                             ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, | ||||
|                                                     false); | ||||
|                                         } catch (InvocationTargetException e) { | ||||
|                                             e.printStackTrace(System.out); | ||||
|                                             e.printStackTrace(); | ||||
|                                         } | ||||
|                                     } | ||||
|                                 } | ||||
| @@ -933,13 +903,14 @@ public class PacketsManager { | ||||
|                                                 ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, | ||||
|                                                         false); | ||||
|                                             } catch (InvocationTargetException e) { | ||||
|                                                 e.printStackTrace(System.out); | ||||
|                                                 e.printStackTrace(); | ||||
|                                             } | ||||
|                                         } | ||||
|                                     } | ||||
|                                 } | ||||
|                             } | ||||
|                         } // If the player switched item, aka he moved from slot 1 to slot 2 | ||||
|                         } | ||||
|                         // If the player switched item, aka he moved from slot 1 to slot 2 | ||||
|                         else if (event.getPacketType() == PacketType.Play.Client.HELD_ITEM_SLOT) { | ||||
|                             if (disguise.isHidingHeldItemFromSelf()) { | ||||
|                                 // From logging, it seems that both bukkit and nms uses the same thing for the slot switching. | ||||
| @@ -957,7 +928,7 @@ public class PacketsManager { | ||||
|                                     try { | ||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); | ||||
|                                     } catch (InvocationTargetException e) { | ||||
|                                         e.printStackTrace(System.out); | ||||
|                                         e.printStackTrace(); | ||||
|                                     } | ||||
|                                 } | ||||
|                                 org.bukkit.inventory.ItemStack newHeld = event.getPlayer().getInventory() | ||||
| @@ -972,7 +943,7 @@ public class PacketsManager { | ||||
|                                     try { | ||||
|                                         ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); | ||||
|                                     } catch (InvocationTargetException e) { | ||||
|                                         e.printStackTrace(System.out); | ||||
|                                         e.printStackTrace(); | ||||
|                                     } | ||||
|                                 } | ||||
|                             } | ||||
| @@ -986,7 +957,6 @@ public class PacketsManager { | ||||
|                                     // Rather than predict the clients actions | ||||
|                                     // Lets just update the entire inventory.. | ||||
|                                     Bukkit.getScheduler().runTask(libsDisguises, new Runnable() { | ||||
|                                         @Override | ||||
|                                         public void run() { | ||||
|                                             event.getPlayer().updateInventory(); | ||||
|                                         } | ||||
| @@ -1014,7 +984,7 @@ public class PacketsManager { | ||||
|                                             ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, | ||||
|                                                     false); | ||||
|                                         } catch (InvocationTargetException e) { | ||||
|                                             e.printStackTrace(System.out); | ||||
|                                             e.printStackTrace(); | ||||
|                                         } | ||||
|                                     } | ||||
|                                     // Else if its a hotbar slot | ||||
| @@ -1032,7 +1002,7 @@ public class PacketsManager { | ||||
|                                                 ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, | ||||
|                                                         false); | ||||
|                                             } catch (InvocationTargetException e) { | ||||
|                                                 e.printStackTrace(System.out); | ||||
|                                                 e.printStackTrace(); | ||||
|                                             } | ||||
|                                         } | ||||
|                                     } | ||||
| @@ -1174,7 +1144,7 @@ public class PacketsManager { | ||||
|             if (mainListener != null) { | ||||
|                 ProtocolLibrary.getProtocolManager().removePacketListener(mainListener); | ||||
|             } | ||||
|             List<PacketType> packetsToListen = new ArrayList<>(); | ||||
|             List<PacketType> packetsToListen = new ArrayList<PacketType>(); | ||||
|             // Add spawn packets | ||||
|             { | ||||
|                 packetsToListen.add(PacketType.Play.Server.NAMED_ENTITY_SPAWN); | ||||
| @@ -1220,9 +1190,8 @@ public class PacketsManager { | ||||
|             mainListener = new PacketAdapter(libsDisguises, ListenerPriority.HIGH, packetsToListen) { | ||||
|                 @Override | ||||
|                 public void onPacketSending(PacketEvent event) { | ||||
|                     if (event.isCancelled()) { | ||||
|                     if (event.isCancelled()) | ||||
|                         return; | ||||
|                     } | ||||
|                     final Player observer = event.getPlayer(); | ||||
|                     // First get the entity, the one sending this packet | ||||
|                     StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(observer.getWorld()); | ||||
| @@ -1230,9 +1199,8 @@ public class PacketsManager { | ||||
|                             .read((PacketType.Play.Server.COLLECT == event.getPacketType() ? 1 : 0)); | ||||
|                     // If the entity is the same as the sender. Don't disguise! | ||||
|                     // Prevents problems and there is no advantage to be gained. | ||||
|                     if (entity == observer) { | ||||
|                     if (entity == observer) | ||||
|                         return; | ||||
|                     } | ||||
|                     PacketContainer[][] packets = transformPacket(event.getPacket(), event.getPlayer(), entity); | ||||
|                     if (packets != null) { | ||||
|                         event.setCancelled(true); | ||||
| @@ -1243,20 +1211,19 @@ public class PacketsManager { | ||||
|                             final PacketContainer[] delayed = packets[1]; | ||||
|                             if (delayed.length > 0) { | ||||
|                                 Bukkit.getScheduler().scheduleSyncDelayedTask(libsDisguises, new Runnable() { | ||||
|                                     @Override | ||||
|                                     public void run() { | ||||
|                                         try { | ||||
|                                             for (PacketContainer packet : delayed) { | ||||
|                                                 ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); | ||||
|                                             } | ||||
|                                         } catch (InvocationTargetException e) { | ||||
|                                             e.printStackTrace(System.out); | ||||
|                                             e.printStackTrace(); | ||||
|                                         } | ||||
|                                     } | ||||
|                                 }, 2); | ||||
|                             } | ||||
|                         } catch (InvocationTargetException ex) { | ||||
|                             ex.printStackTrace(System.out); | ||||
|                             ex.printStackTrace(); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
| @@ -1292,12 +1259,8 @@ public class PacketsManager { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if its not transformed | ||||
|      * | ||||
|      * @param sentPacket | ||||
|      * @param observer | ||||
|      * @param entity | ||||
|      * @return | ||||
|      * Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if its not | ||||
|      * transformed | ||||
|      */ | ||||
|     public static PacketContainer[][] transformPacket(PacketContainer sentPacket, Player observer, Entity entity) { | ||||
|         PacketContainer[] packets = null; | ||||
| @@ -1306,14 +1269,14 @@ public class PacketsManager { | ||||
|             Disguise disguise = DisguiseAPI.getDisguise(observer, entity); | ||||
|             // If disguised. | ||||
|             if (disguise != null) { | ||||
|                 packets = new PacketContainer[]{sentPacket}; | ||||
|                 packets = new PacketContainer[] { sentPacket }; | ||||
|  | ||||
|                 // This packet sends attributes | ||||
|                 if (sentPacket.getType() == PacketType.Play.Server.UPDATE_ATTRIBUTES) { | ||||
|                     if (disguise.isMiscDisguise()) { | ||||
|                         packets = new PacketContainer[0]; | ||||
|                     } else { | ||||
|                         List<WrappedAttribute> attributes = new ArrayList<>(); | ||||
|                         List<WrappedAttribute> attributes = new ArrayList<WrappedAttribute>(); | ||||
|                         for (WrappedAttribute attribute : sentPacket.getAttributeCollectionModifier().read(0)) { | ||||
|                             if (attribute.getAttributeKey().equals("generic.maxHealth")) { | ||||
|                                 packets[0] = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES); | ||||
| @@ -1341,7 +1304,9 @@ public class PacketsManager { | ||||
|                             packets = new PacketContainer[0]; | ||||
|                         } | ||||
|                     } | ||||
|                 } // Else if the packet is sending entity metadata | ||||
|                 } | ||||
|  | ||||
|                 // Else if the packet is sending entity metadata | ||||
|                 else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_METADATA) { | ||||
|                     if (DisguiseConfig.isMetadataPacketsEnabled()) { | ||||
|                         List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert( | ||||
| @@ -1354,7 +1319,9 @@ public class PacketsManager { | ||||
|                     } else { | ||||
|                         packets = new PacketContainer[0]; | ||||
|                     } | ||||
|                 } // Else if the packet is spawning.. | ||||
|                 } | ||||
|  | ||||
|                 // Else if the packet is spawning.. | ||||
|                 else if (sentPacket.getType() == PacketType.Play.Server.NAMED_ENTITY_SPAWN | ||||
|                         || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_LIVING | ||||
|                         || sentPacket.getType() == PacketType.Play.Server.SPAWN_ENTITY_EXPERIENCE_ORB | ||||
| @@ -1363,7 +1330,9 @@ public class PacketsManager { | ||||
|                     PacketContainer[][] spawnPackets = constructSpawnPackets(observer, disguise, entity); | ||||
|                     packets = spawnPackets[0]; | ||||
|                     delayedPackets = spawnPackets[1]; | ||||
|                 } // Else if the disguise is attempting to send players a forbidden packet | ||||
|                 } | ||||
|  | ||||
|                 // Else if the disguise is attempting to send players a forbidden packet | ||||
|                 else if (sentPacket.getType() == PacketType.Play.Server.ANIMATION) { | ||||
|                     if (disguise.getType().isMisc() | ||||
|                             || (packets[0].getIntegers().read(1) == 2 && (!disguise.getType() | ||||
| @@ -1371,7 +1340,9 @@ public class PacketsManager { | ||||
|                             .getWatcher()).isSleeping())))) { | ||||
|                         packets = new PacketContainer[0]; | ||||
|                     } | ||||
|                 } else if (sentPacket.getType() == PacketType.Play.Server.COLLECT) { | ||||
|                 } | ||||
|  | ||||
|                 else if (sentPacket.getType() == PacketType.Play.Server.COLLECT) { | ||||
|                     if (disguise.getType().isMisc()) { | ||||
|                         packets = new PacketContainer[0]; | ||||
|                     } else if (DisguiseConfig.isBedPacketsEnabled() && disguise.getType().isPlayer() | ||||
| @@ -1380,9 +1351,11 @@ public class PacketsManager { | ||||
|                         StructureModifier<Integer> mods = newPacket.getIntegers(); | ||||
|                         mods.write(0, disguise.getEntity().getEntityId()); | ||||
|                         mods.write(1, 3); | ||||
|                         packets = new PacketContainer[]{newPacket, sentPacket}; | ||||
|                         packets = new PacketContainer[] { newPacket, sentPacket }; | ||||
|                     } | ||||
|                 } // Else if the disguise is moving. | ||||
|                 } | ||||
|  | ||||
|                 // Else if the disguise is moving. | ||||
|                 else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_MOVE_LOOK | ||||
|                         || sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK | ||||
|                         || sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT | ||||
| @@ -1435,11 +1408,12 @@ public class PacketsManager { | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                 } else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT) { | ||||
|                 } | ||||
|  | ||||
|                 else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT) { | ||||
|                     int slot = (Integer) packets[0].getModifier().read(1) - 1; | ||||
|                     if (slot < 0) { | ||||
|                     if (slot < 0) | ||||
|                         slot = 4; | ||||
|                     } | ||||
|                     org.bukkit.inventory.ItemStack itemstack = disguise.getWatcher().getItemStack(slot); | ||||
|                     if (itemstack != null) { | ||||
|                         packets[0] = packets[0].shallowClone(); | ||||
| @@ -1450,7 +1424,7 @@ public class PacketsManager { | ||||
|                         ItemStack heldItem = packets[0].getItemModifier().read(0); | ||||
|                         if (heldItem != null && heldItem.getType() != Material.AIR) { | ||||
|                             // Convert the datawatcher | ||||
|                             List<WrappedWatchableObject> list = new ArrayList<>(); | ||||
|                             List<WrappedWatchableObject> list = new ArrayList<WrappedWatchableObject>(); | ||||
|                             if (DisguiseConfig.isMetadataPacketsEnabled()) { | ||||
|                                 list.add(new WrappedWatchableObject(0, WrappedDataWatcher.getEntityWatcher(entity).getByte(0))); | ||||
|                                 list = disguise.getWatcher().convert(list); | ||||
| @@ -1474,20 +1448,26 @@ public class PacketsManager { | ||||
|                             } | ||||
|                             // Send the unblock before the itemstack change so that the 2nd metadata packet works. Why? Scheduler | ||||
|                             // delay. | ||||
|                             packets = new PacketContainer[]{packetUnblock, packets[0], packetBlock}; | ||||
|                             packets = new PacketContainer[] { packetUnblock, packets[0], packetBlock }; | ||||
|                             // Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset | ||||
|                             // it. | ||||
|                         } | ||||
|                     } | ||||
|                 } else if (sentPacket.getType() == PacketType.Play.Server.BED) { | ||||
|                 } | ||||
|  | ||||
|                 else if (sentPacket.getType() == PacketType.Play.Server.BED) { | ||||
|                     if (!disguise.getType().isPlayer()) { | ||||
|                         packets = new PacketContainer[0]; | ||||
|                     } | ||||
|                 } else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_STATUS) { | ||||
|                 } | ||||
|  | ||||
|                 else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_STATUS) { | ||||
|                     if (packets[0].getBytes().read(0) == (byte) 3) { | ||||
|                         packets = new PacketContainer[0]; | ||||
|                     } | ||||
|                 } else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_HEAD_ROTATION) { | ||||
|                 } | ||||
|  | ||||
|                 else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_HEAD_ROTATION) { | ||||
|                     if (disguise.getType().isPlayer() && entity.getType() != EntityType.PLAYER) { | ||||
|                         Location loc = entity.getLocation(); | ||||
|                         byte pitch = getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), | ||||
| @@ -1501,16 +1481,18 @@ public class PacketsManager { | ||||
|                         look.getIntegers().write(0, entity.getEntityId()); | ||||
|                         look.getBytes().write(3, yaw); | ||||
|                         look.getBytes().write(4, pitch); | ||||
|                         packets = new PacketContainer[]{look, rotation}; | ||||
|                         packets = new PacketContainer[] { look, rotation }; | ||||
|                     } | ||||
|                 } else { | ||||
|                 } | ||||
|  | ||||
|                 else { | ||||
|                     packets = null; | ||||
|                 } | ||||
|  | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(System.out); | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         return packets == null ? null : new PacketContainer[][]{packets, delayedPackets}; | ||||
|         return packets == null ? null : new PacketContainer[][] { packets, delayedPackets }; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,5 +1,17 @@ | ||||
| package me.libraryaddict.disguise.utilities; | ||||
|  | ||||
| import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||
| import com.google.common.collect.ImmutableMap; | ||||
| import org.bukkit.Art; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Sound; | ||||
| import org.bukkit.World; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
| import org.bukkit.potion.PotionEffect; | ||||
|  | ||||
| import java.io.BufferedReader; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| @@ -14,20 +26,6 @@ import java.util.UUID; | ||||
| import java.util.regex.Matcher; | ||||
| import java.util.regex.Pattern; | ||||
|  | ||||
| import com.google.common.collect.ImmutableMap; | ||||
|  | ||||
| import org.bukkit.Art; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Sound; | ||||
| import org.bukkit.World; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.inventory.ItemStack; | ||||
|  | ||||
| import com.comphenix.protocol.wrappers.WrappedGameProfile; | ||||
| import org.bukkit.potion.PotionEffect; | ||||
|  | ||||
| public class ReflectionManager { | ||||
|  | ||||
|     public enum LibVersion { | ||||
| @@ -202,19 +200,23 @@ public class ReflectionManager { | ||||
|             Class<?> entityClass = getNmsClass("Entity" + entityName); | ||||
|             Object entityObject; | ||||
|             Object world = getWorld(Bukkit.getWorlds().get(0)); | ||||
|             if (entityName.equals("Player")) { | ||||
|                 Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null); | ||||
|                 Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World")) | ||||
|                         .newInstance(world); | ||||
|                 WrappedGameProfile gameProfile = getGameProfile(null, "LibsDisguises"); | ||||
|                 entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), | ||||
|                         gameProfile.getHandleType(), playerinteractmanager.getClass()).newInstance(minecraftServer, world, | ||||
|                                 gameProfile.getHandle(), playerinteractmanager); | ||||
|             } else if (entityName.equals("EnderPearl")) { | ||||
|                 entityObject = entityClass.getConstructor(getNmsClass("World"), getNmsClass("EntityLiving")) | ||||
|                         .newInstance(world, createEntityInstance("Cow")); | ||||
|             } else { | ||||
|                 entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world); | ||||
|             switch (entityName) { | ||||
|                 case "Player": | ||||
|                     Object minecraftServer = getNmsMethod("MinecraftServer", "getServer").invoke(null); | ||||
|                     Object playerinteractmanager = getNmsClass("PlayerInteractManager").getConstructor(getNmsClass("World")) | ||||
|                             .newInstance(world); | ||||
|                     WrappedGameProfile gameProfile = getGameProfile(null, "LibsDisguises"); | ||||
|                     entityObject = entityClass.getConstructor(getNmsClass("MinecraftServer"), getNmsClass("WorldServer"), | ||||
|                             gameProfile.getHandleType(), playerinteractmanager.getClass()).newInstance(minecraftServer, world, | ||||
|                             gameProfile.getHandle(), playerinteractmanager); | ||||
|                     break; | ||||
|                 case "EnderPearl": | ||||
|                     entityObject = entityClass.getConstructor(getNmsClass("World"), getNmsClass("EntityLiving")) | ||||
|                             .newInstance(world, createEntityInstance("Cow")); | ||||
|                     break; | ||||
|                 default: | ||||
|                     entityObject = entityClass.getConstructor(getNmsClass("World")).newInstance(world); | ||||
|                     break; | ||||
|             } | ||||
|             return entityObject; | ||||
|         } catch (Exception e) { | ||||
| @@ -397,6 +399,7 @@ public class ReflectionManager { | ||||
|     } | ||||
|  | ||||
|     public static WrappedGameProfile getGameProfileWithThisSkin(UUID uuid, String playerName, WrappedGameProfile profileWithSkin) { | ||||
|  | ||||
|         try { | ||||
|             WrappedGameProfile gameProfile = new WrappedGameProfile(uuid != null ? uuid : UUID.randomUUID(), playerName); | ||||
|             gameProfile.getProperties().putAll(profileWithSkin.getProperties()); | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| name: LibsDisguises | ||||
| main: me.libraryaddict.disguise.LibsDisguises | ||||
| version: 8.6.7 | ||||
| version: 8.6.8 | ||||
| author: libraryaddict | ||||
| authors: [Byteflux, Navid K.] | ||||
| depend: [ProtocolLib] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user