Temporary patch for sounds not working
Replaced some code with Craftbukkit versions
This commit is contained in:
		| @@ -1,9 +1,7 @@ | |||||||
| package me.libraryaddict.disguise.utilities; | package me.libraryaddict.disguise.utilities; | ||||||
|  |  | ||||||
| import com.comphenix.protocol.wrappers.MinecraftKey; |  | ||||||
| import org.bukkit.Sound; | import org.bukkit.Sound; | ||||||
|  |  | ||||||
| import java.lang.reflect.Field; |  | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.HashSet; | import java.util.HashSet; | ||||||
|  |  | ||||||
| @@ -125,22 +123,6 @@ public enum DisguiseSound { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Necessary for 1.9 |  | ||||||
|      * @return |  | ||||||
|      */ |  | ||||||
|     public static String convertSoundEffectToString(Object soundEffect) { |  | ||||||
|         try { |  | ||||||
|             Field f_getMinecraftKey = ReflectionManager.getNmsField("SoundEffect", "b"); |  | ||||||
|             f_getMinecraftKey.setAccessible(true); |  | ||||||
|             MinecraftKey key = MinecraftKey.fromHandle(f_getMinecraftKey.get(soundEffect)); |  | ||||||
|             return key.getKey(); |  | ||||||
|         } catch (IllegalAccessException e) { |  | ||||||
|             e.printStackTrace(); |  | ||||||
|         } |  | ||||||
|         return null; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public float getDamageAndIdleSoundVolume() { |     public float getDamageAndIdleSoundVolume() { | ||||||
|         return damageSoundVolume; |         return damageSoundVolume; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -22,18 +22,15 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; | |||||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.MiscDisguise; | import me.libraryaddict.disguise.disguisetypes.MiscDisguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.MobDisguise; |  | ||||||
| import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.SheepWatcher; | ||||||
| import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; | import me.libraryaddict.disguise.disguisetypes.watchers.WolfWatcher; | ||||||
| import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType; |  | ||||||
| import org.bukkit.Art; | 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.entity.Ageable; |  | ||||||
| import org.bukkit.entity.Arrow; | import org.bukkit.entity.Arrow; | ||||||
| import org.bukkit.entity.Damageable; | import org.bukkit.entity.Damageable; | ||||||
| import org.bukkit.entity.Entity; | import org.bukkit.entity.Entity; | ||||||
| @@ -42,7 +39,6 @@ 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.EquipmentSlot; | import org.bukkit.inventory.EquipmentSlot; | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
| import org.bukkit.metadata.FixedMetadataValue; | import org.bukkit.metadata.FixedMetadataValue; | ||||||
| @@ -51,7 +47,6 @@ import java.lang.reflect.InvocationTargetException; | |||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Random; |  | ||||||
| import java.util.UUID; | import java.util.UUID; | ||||||
|  |  | ||||||
| public class PacketsManager { | public class PacketsManager { | ||||||
| @@ -325,6 +320,7 @@ public class PacketsManager { | |||||||
|      * Create a new datawatcher but with the 'correct' values |      * Create a new datawatcher but with the 'correct' values | ||||||
|      */ |      */ | ||||||
|     private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) { |     private static WrappedDataWatcher createDataWatcher(WrappedDataWatcher watcher, FlagWatcher flagWatcher) { | ||||||
|  |         //TODO: Specify a serializer... | ||||||
|         WrappedDataWatcher newWatcher = new WrappedDataWatcher(); |         WrappedDataWatcher newWatcher = new WrappedDataWatcher(); | ||||||
|         try { |         try { | ||||||
|             List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? |             List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? | ||||||
| @@ -495,226 +491,227 @@ public class PacketsManager { | |||||||
|                 Server.ENTITY_STATUS) { |                 Server.ENTITY_STATUS) { | ||||||
|             @Override |             @Override | ||||||
|             public void onPacketSending(PacketEvent event) { |             public void onPacketSending(PacketEvent event) { | ||||||
|                 if (event.isCancelled()) { |                 //TODO: Fix this later once ProtocolLib's deepClone for NamedSoundEffect and EntityStatus is fixed | ||||||
|                     return; | //                if (event.isCancelled()) { | ||||||
|                 } | //                    return; | ||||||
|                 event.setPacket(event.getPacket().deepClone()); | //                } | ||||||
|                 StructureModifier<Object> mods = event.getPacket().getModifier(); | //                event.setPacket(event.getPacket().deepClone()); | ||||||
|                 Player observer = event.getPlayer(); | //                StructureModifier<Object> mods = event.getPacket().getModifier(); | ||||||
|                 if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) { | //                Player observer = event.getPlayer(); | ||||||
|                     if (event.isAsync()) { | //                if (event.getPacketType() == Server.NAMED_SOUND_EFFECT) { | ||||||
|                         return; | ////                    if (event.isAsync()) { | ||||||
|                     } | ////                        return; | ||||||
|                     Object soundEffect = mods.read(0); | ////                    } | ||||||
|                     SoundType soundType = null; | ////                    Object soundEffect = mods.read(0); | ||||||
|                     Location soundLoc = new Location(observer.getWorld(), ((Integer) mods.read(1)) / 8D, | ////                    SoundType soundType = null; | ||||||
|                             ((Integer) mods.read(2)) / 8D, ((Integer) mods.read(3)) / 8D); | ////                    Location soundLoc = new Location(observer.getWorld(), ((Integer) mods.read(2)) / 8D, | ||||||
|                     Entity disguisedEntity = null; | ////                            ((Integer) mods.read(3)) / 8D, ((Integer) mods.read(4)) / 8D); | ||||||
|                     DisguiseSound entitySound = null; | ////                    Entity disguisedEntity = null; | ||||||
|                     Disguise disguise = null; | ////                    DisguiseSound entitySound = null; | ||||||
|                     Entity[] entities = soundLoc.getChunk().getEntities(); | ////                    Disguise disguise = null; | ||||||
|                     for (Entity entity : entities) { | ////                    Entity[] entities = soundLoc.getChunk().getEntities(); | ||||||
|                         Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity); | ////                    for (Entity entity : entities) { | ||||||
|                         if (entityDisguise != null) { | ////                        Disguise entityDisguise = DisguiseAPI.getDisguise(observer, entity); | ||||||
|                             Location loc = entity.getLocation(); | ////                        if (entityDisguise != null) { | ||||||
|                             loc = new Location(observer.getWorld(), ((int) (loc.getX() * 8)) / 8D, ((int) (loc.getY() * 8)) / 8D, | ////                            Location loc = entity.getLocation(); | ||||||
|                                     ((int) (loc.getZ() * 8)) / 8D); | ////                            loc = new Location(observer.getWorld(), ((int) (loc.getX() * 8)) / 8D, ((int) (loc.getY() * 8)) / 8D, | ||||||
|                             if (loc.equals(soundLoc)) { | ////                                    ((int) (loc.getZ() * 8)) / 8D); | ||||||
|                                 entitySound = DisguiseSound.getType(entity.getType().name()); | ////                            if (loc.equals(soundLoc)) { | ||||||
|                                 if (entitySound != null) { | ////                                entitySound = DisguiseSound.getType(entity.getType().name()); | ||||||
|                                     Object obj = null; | ////                                if (entitySound != null) { | ||||||
|                                     if (entity instanceof LivingEntity) { | ////                                    Object obj = null; | ||||||
|                                         try { | ////                                    if (entity instanceof LivingEntity) { | ||||||
|                                             // Use reflection so that this works for either int or double methods | ////                                        try { | ||||||
|                                             obj = LivingEntity.class.getMethod("getHealth").invoke(entity); | ////                                            // Use reflection so that this works for either int or double methods | ||||||
|                                             if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) { | ////                                            obj = LivingEntity.class.getMethod("getHealth").invoke(entity); | ||||||
|                                                 soundType = SoundType.DEATH; | ////                                            if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) { | ||||||
|                                             } else { | ////                                                soundType = SoundType.DEATH; | ||||||
|                                                 obj = null; | ////                                            } else { | ||||||
|                                             } | ////                                                obj = null; | ||||||
|                                         } catch (Exception e) { | ////                                            } | ||||||
|                                             e.printStackTrace(); | ////                                        } catch (Exception e) { | ||||||
|                                         } | ////                                            e.printStackTrace(); | ||||||
|                                     } | ////                                        } | ||||||
|                                     if (obj == null) { | ////                                    } | ||||||
|                                         boolean hasInvun = false; | ////                                    if (obj == null) { | ||||||
|                                         Object nmsEntity = ReflectionManager.getNmsEntity(entity); | ////                                        boolean hasInvun = false; | ||||||
|                                         try { | ////                                        Object nmsEntity = ReflectionManager.getNmsEntity(entity); | ||||||
|                                             if (entity instanceof LivingEntity) { | ////                                        try { | ||||||
|                                                 hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks").getInt( | ////                                            if (entity instanceof LivingEntity) { | ||||||
|                                                         nmsEntity) == ReflectionManager.getNmsField("EntityLiving", | ////                                                hasInvun = ReflectionManager.getNmsField("Entity", "noDamageTicks").getInt( | ||||||
|                                                         "maxNoDamageTicks").getInt(nmsEntity); | ////                                                        nmsEntity) == ReflectionManager.getNmsField("EntityLiving", | ||||||
|                                             } else { | ////                                                        "maxNoDamageTicks").getInt(nmsEntity); | ||||||
|                                                 Class clazz = ReflectionManager.getNmsClass("DamageSource"); | ////                                            } else { | ||||||
|                                                 hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", clazz) | ////                                                Class clazz = ReflectionManager.getNmsClass("DamageSource"); | ||||||
|                                                         .invoke(nmsEntity, ReflectionManager.getNmsField(clazz, "GENERIC")); | ////                                                hasInvun = (Boolean) ReflectionManager.getNmsMethod("Entity", "isInvulnerable", clazz) | ||||||
|                                             } | ////                                                        .invoke(nmsEntity, ReflectionManager.getNmsField(clazz, "GENERIC")); | ||||||
|                                         } catch (Exception ex) { | ////                                            } | ||||||
|                                             ex.printStackTrace(); | ////                                        } catch (Exception ex) { | ||||||
|                                         } | ////                                            ex.printStackTrace(); | ||||||
|                                         soundType = entitySound.getType(DisguiseSound.convertSoundEffectToString(soundEffect), !hasInvun); | ////                                        } | ||||||
|                                     } | ////                                        soundType = entitySound.getType(ReflectionManager.convertSoundEffectToString(soundEffect), !hasInvun); | ||||||
|                                     if (soundType != null) { | ////                                    } | ||||||
|                                         disguise = entityDisguise; | ////                                    if (soundType != null) { | ||||||
|                                         disguisedEntity = entity; | ////                                        disguise = entityDisguise; | ||||||
|                                         break; | ////                                        disguisedEntity = entity; | ||||||
|                                     } | ////                                        break; | ||||||
|                                 } | ////                                    } | ||||||
|                             } | ////                                } | ||||||
|                         } | ////                            } | ||||||
|                     } | ////                        } | ||||||
|                     if (disguise != null) { | ////                    } | ||||||
|                         if (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != event.getPlayer()) { | ////                    if (disguise != null) { | ||||||
|                             if (disguise.isSoundsReplaced()) { | ////                        if (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != event.getPlayer()) { | ||||||
|                                 String sound = null; | ////                            if (disguise.isSoundsReplaced()) { | ||||||
|                                 DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name()); | ////                                String sound = null; | ||||||
|                                 if (dSound != null) | ////                                DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name()); | ||||||
|                                     sound = dSound.getSound(soundType); | ////                                if (dSound != null) | ||||||
|  | ////                                    sound = dSound.getSound(soundType); | ||||||
|                                 if (sound == null) { | //// | ||||||
|                                     event.setCancelled(true); | ////                                if (sound == null) { | ||||||
|                                 } else { | ////                                    event.setCancelled(true); | ||||||
|                                     if (sound.equals("step.grass")) { | ////                                } else { | ||||||
|                                         try { | ////                                    if (sound.equals("step.grass")) { | ||||||
|                                             int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(), | ////                                        try { | ||||||
|                                                     soundLoc.getBlockY() - 1, soundLoc.getBlockZ()); | ////                                            int typeId = soundLoc.getWorld().getBlockTypeIdAt(soundLoc.getBlockX(), | ||||||
|                                             Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "a", int.class) | ////                                                    soundLoc.getBlockY() - 1, soundLoc.getBlockZ()); | ||||||
|                                                     .invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), | ////                                            Object block = ReflectionManager.getNmsMethod("RegistryMaterials", "a", int.class) | ||||||
|                                                             typeId); | ////                                                    .invoke(ReflectionManager.getNmsField("Block", "REGISTRY").get(null), | ||||||
|                                             if (block != null) { | ////                                                            typeId); | ||||||
|                                                 Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block); | ////                                            if (block != null) { | ||||||
|                                                 mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound").invoke(step)); | ////                                                Object step = ReflectionManager.getNmsField("Block", "stepSound").get(block); | ||||||
|                                             } | ////                                                mods.write(0, ReflectionManager.getNmsMethod(step.getClass(), "getStepSound").invoke(step)); | ||||||
|                                         } catch (Exception ex) { | ////                                            } | ||||||
|                                             ex.printStackTrace(); | ////                                        } catch (Exception ex) { | ||||||
|                                         } | ////                                            ex.printStackTrace(); | ||||||
|                                         // There is no else statement. Because seriously. This should never be null. Unless | ////                                        } | ||||||
|                                         // someone is | ////                                        // There is no else statement. Because seriously. This should never be null. Unless | ||||||
|                                         // sending fake sounds. In which case. Why cancel it. | ////                                        // someone is | ||||||
|                                     } else { | ////                                        // sending fake sounds. In which case. Why cancel it. | ||||||
|                                         mods.write(0, sound); | ////                                    } else { | ||||||
|                                         // Time to change the pitch and volume | ////                                        mods.write(0, ReflectionManager.getCraftSoundEffect(sound)); | ||||||
|                                         if (soundType == SoundType.HURT || soundType == SoundType.DEATH | ////                                        // Time to change the pitch and volume | ||||||
|                                                 || soundType == SoundType.IDLE) { | ////                                        if (soundType == SoundType.HURT || soundType == SoundType.DEATH | ||||||
|                                             // If the volume is the default | ////                                                || soundType == SoundType.IDLE) { | ||||||
|                                             if (mods.read(4).equals(entitySound.getDamageAndIdleSoundVolume())) { | ////                                            // If the volume is the default | ||||||
|                                                 mods.write(4, dSound.getDamageAndIdleSoundVolume()); | ////                                            if (mods.read(5).equals(entitySound.getDamageAndIdleSoundVolume())) { | ||||||
|                                             } | ////                                                mods.write(5, dSound.getDamageAndIdleSoundVolume()); | ||||||
|                                             // Here I assume its the default pitch as I can't calculate if its real. | ////                                            } | ||||||
|                                             if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity | ////                                            // Here I assume its the default pitch as I can't calculate if its real. | ||||||
|                                                     && ((MobDisguise) disguise).doesDisguiseAge()) { | ////                                            if (disguise instanceof MobDisguise && disguisedEntity instanceof LivingEntity | ||||||
|                                                 boolean baby = false; | ////                                                    && ((MobDisguise) disguise).doesDisguiseAge()) { | ||||||
|                                                 if (disguisedEntity instanceof Zombie) { | ////                                                boolean baby = false; | ||||||
|                                                     baby = ((Zombie) disguisedEntity).isBaby(); | ////                                                if (disguisedEntity instanceof Zombie) { | ||||||
|                                                 } else if (disguisedEntity instanceof Ageable) { | ////                                                    baby = ((Zombie) disguisedEntity).isBaby(); | ||||||
|                                                     baby = !((Ageable) disguisedEntity).isAdult(); | ////                                                } 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); | //// | ||||||
|                                                     if (baby) { | ////                                                    float pitch = (Integer) mods.read(5); | ||||||
|                                                         // If the pitch is not the expected | ////                                                    if (baby) { | ||||||
|                                                         if (pitch > 97 || pitch < 111) | ////                                                        // If the pitch is not the expected | ||||||
|                                                             return; | ////                                                        if (pitch > 97 || pitch < 111) | ||||||
|                                                         pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; | ////                                                            return; | ||||||
|                                                         // Min = 1.5 | ////                                                        pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; | ||||||
|                                                         // Cap = 97.5 | ////                                                        // Min = 1.5 | ||||||
|                                                         // Max = 1.7 | ////                                                        // Cap = 97.5 | ||||||
|                                                         // Cap = 110.5 | ////                                                        // Max = 1.7 | ||||||
|                                                     } else { | ////                                                        // Cap = 110.5 | ||||||
|                                                         // If the pitch is not the expected | ////                                                    } else { | ||||||
|                                                         if (pitch >= 63 || pitch <= 76) | ////                                                        // If the pitch is not the expected | ||||||
|                                                             return; | ////                                                        if (pitch >= 63 || pitch <= 76) | ||||||
|                                                         pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; | ////                                                            return; | ||||||
|                                                         // Min = 1 | ////                                                        pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; | ||||||
|                                                         // Cap = 63 | ////                                                        // Min = 1 | ||||||
|                                                         // Max = 1.2 | ////                                                        // Cap = 63 | ||||||
|                                                         // Cap = 75.6 | ////                                                        // Max = 1.2 | ||||||
|                                                     } | ////                                                        // Cap = 75.6 | ||||||
|                                                     pitch *= 63; | ////                                                    } | ||||||
|                                                     if (pitch < 0) | ////                                                    pitch *= 63; | ||||||
|                                                         pitch = 0; | ////                                                    if (pitch < 0) | ||||||
|                                                     if (pitch > 255) | ////                                                        pitch = 0; | ||||||
|                                                         pitch = 255; | ////                                                    if (pitch > 255) | ||||||
|                                                     mods.write(5, (int) pitch); | ////                                                        pitch = 255; | ||||||
|                                                 } | ////                                                    mods.write(6, (int) pitch); | ||||||
|                                             } | ////                                                } | ||||||
|                                         } | ////                                            } | ||||||
|                                     } | ////                                        } | ||||||
|                                 } | ////                                    } | ||||||
|                             } | ////                                } | ||||||
|                         } | ////                            } | ||||||
|                     } | ////                        } | ||||||
|                 } else if (event.getPacketType() == Server.ENTITY_STATUS) { | ////                    } | ||||||
|                     if ((byte) mods.read(1) == 2) { | //                } else if (event.getPacketType() == Server.ENTITY_STATUS) { | ||||||
|                         // It made a damage animation | //                    if ((byte) mods.read(1) == 2) { | ||||||
|                         Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0); | //                        // It made a damage animation | ||||||
|                         Disguise disguise = DisguiseAPI.getDisguise(observer, entity); | //                        Entity entity = event.getPacket().getEntityModifier(observer.getWorld()).read(0); | ||||||
|                         if (disguise != null && !disguise.getType().isPlayer() | //                        Disguise disguise = DisguiseAPI.getDisguise(observer, entity); | ||||||
|                                 && (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) { | //                        if (disguise != null && !disguise.getType().isPlayer() | ||||||
|                             DisguiseSound disSound = DisguiseSound.getType(entity.getType().name()); | //                                && (disguise.isSelfDisguiseSoundsReplaced() || entity != event.getPlayer())) { | ||||||
|                             if (disSound == null) | //                            DisguiseSound disSound = DisguiseSound.getType(entity.getType().name()); | ||||||
|                                 return; | //                            if (disSound == null) | ||||||
|                             SoundType soundType = null; | //                                return; | ||||||
|                             Object obj = null; | //                            SoundType soundType = null; | ||||||
|                             if (entity instanceof LivingEntity) { | //                            Object obj = null; | ||||||
|                                 try { | //                            if (entity instanceof LivingEntity) { | ||||||
|                                     obj = LivingEntity.class.getMethod("getHealth").invoke(entity); | //                                try { | ||||||
|                                     if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) { | //                                    obj = LivingEntity.class.getMethod("getHealth").invoke(entity); | ||||||
|                                         soundType = SoundType.DEATH; | //                                    if (obj instanceof Double ? (Double) obj == 0 : (Integer) obj == 0) { | ||||||
|                                     } else { | //                                        soundType = SoundType.DEATH; | ||||||
|                                         obj = null; | //                                    } else { | ||||||
|                                     } | //                                        obj = null; | ||||||
|                                 } catch (Exception e) { | //                                    } | ||||||
|                                     e.printStackTrace(); | //                                } catch (Exception e) { | ||||||
|                                 } | //                                    e.printStackTrace(); | ||||||
|                             } | //                                } | ||||||
|                             if (obj == null) { | //                            } | ||||||
|                                 soundType = SoundType.HURT; | //                            if (obj == null) { | ||||||
|                             } | //                                soundType = SoundType.HURT; | ||||||
|                             if (disSound.getSound(soundType) == null | //                            } | ||||||
|                                     || (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) { | //                            if (disSound.getSound(soundType) == null | ||||||
|                                 if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) { | //                                    || (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer())) { | ||||||
|                                     cancelSound = !cancelSound; | //                                if (disguise.isSelfDisguiseSoundsReplaced() && entity == event.getPlayer()) { | ||||||
|                                     if (cancelSound) | //                                    cancelSound = !cancelSound; | ||||||
|                                         return; | //                                    if (cancelSound) | ||||||
|                                 } | //                                        return; | ||||||
|                                 disSound = DisguiseSound.getType(disguise.getType().name()); | //                                } | ||||||
|                                 if (disSound != null) { | //                                disSound = DisguiseSound.getType(disguise.getType().name()); | ||||||
|                                     String sound = disSound.getSound(soundType); | //                                if (disSound != null) { | ||||||
|                                     if (sound != null) { | //                                    String sound = disSound.getSound(soundType); | ||||||
|                                         Location loc = entity.getLocation(); | //                                    if (sound != null) { | ||||||
|                                         PacketContainer packet = new PacketContainer(Server.NAMED_SOUND_EFFECT); | //                                        Location loc = entity.getLocation(); | ||||||
|                                         mods = packet.getModifier(); | //                                        PacketContainer packet = new PacketContainer(Server.NAMED_SOUND_EFFECT); | ||||||
|                                         mods.write(0, sound); | //                                        mods = packet.getModifier(); | ||||||
|                                         mods.write(1, (int) (loc.getX() * 8D)); | //                                        mods.write(0, sound); | ||||||
|                                         mods.write(2, (int) (loc.getY() * 8D)); | //                                        mods.write(1, (int) (loc.getX() * 8D)); | ||||||
|                                         mods.write(3, (int) (loc.getZ() * 8D)); | //                                        mods.write(2, (int) (loc.getY() * 8D)); | ||||||
|                                         mods.write(4, disSound.getDamageAndIdleSoundVolume()); | //                                        mods.write(3, (int) (loc.getZ() * 8D)); | ||||||
|                                         float pitch; | //                                        mods.write(4, disSound.getDamageAndIdleSoundVolume()); | ||||||
|                                         if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) { | //                                        float pitch; | ||||||
|                                             pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; | //                                        if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) { | ||||||
|                                         } else | //                                            pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F; | ||||||
|                                             pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; | //                                        } else | ||||||
|                                         if (disguise.getType() == DisguiseType.BAT) | //                                            pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F; | ||||||
|                                             pitch *= 95F; | //                                        if (disguise.getType() == DisguiseType.BAT) | ||||||
|                                         pitch *= 63; | //                                            pitch *= 95F; | ||||||
|                                         if (pitch < 0) | //                                        pitch *= 63; | ||||||
|                                             pitch = 0; | //                                        if (pitch < 0) | ||||||
|                                         if (pitch > 255) | //                                            pitch = 0; | ||||||
|                                             pitch = 255; | //                                        if (pitch > 255) | ||||||
|                                         mods.write(5, (int) pitch); | //                                            pitch = 255; | ||||||
|                                         try { | //                                        mods.write(5, (int) pitch); | ||||||
|                                             ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); | //                                        try { | ||||||
|                                         } catch (InvocationTargetException e) { | //                                            ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); | ||||||
|                                             e.printStackTrace(); | //                                        } catch (InvocationTargetException e) { | ||||||
|                                         } | //                                            e.printStackTrace(); | ||||||
|                                     } | //                                        } | ||||||
|                                 } | //                                    } | ||||||
|                             } | //                                } | ||||||
|                         } | //                            } | ||||||
|                     } | //                        } | ||||||
|                 } | //                    } | ||||||
|  | //                } | ||||||
|             } |             } | ||||||
|         }; |         }; | ||||||
|         viewDisguisesListener = new PacketAdapter(libsDisguises, ListenerPriority.HIGH, |         viewDisguisesListener = new PacketAdapter(libsDisguises, ListenerPriority.HIGH, | ||||||
| @@ -1322,16 +1319,14 @@ public class PacketsManager { | |||||||
|                         || sentPacket.getType() == Server.ENTITY_LOOK |                         || sentPacket.getType() == Server.ENTITY_LOOK | ||||||
|                         || sentPacket.getType() == Server.ENTITY_TELEPORT |                         || sentPacket.getType() == Server.ENTITY_TELEPORT | ||||||
|                         || sentPacket.getType() == Server.REL_ENTITY_MOVE) { |                         || sentPacket.getType() == Server.REL_ENTITY_MOVE) { | ||||||
|                     if (disguise.getType() == DisguiseType.RABBIT |                     if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == Server.REL_ENTITY_MOVE || sentPacket.getType() == Server.ENTITY_MOVE_LOOK)) { | ||||||
|                             && (sentPacket.getType() == Server.REL_ENTITY_MOVE || sentPacket.getType() == Server.ENTITY_MOVE_LOOK)) { |  | ||||||
|                         if (entity.getMetadata("LibsRabbitHop").isEmpty() |                         if (entity.getMetadata("LibsRabbitHop").isEmpty() | ||||||
|                                 || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() < 100 |                                 || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() < 100 | ||||||
|                                 || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) { |                                 || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) { | ||||||
|                             if (entity.getMetadata("LibsRabbitHop").isEmpty() |                             if (entity.getMetadata("LibsRabbitHop").isEmpty() | ||||||
|                                     || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) { |                                     || System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong() > 500) { | ||||||
|                                 entity.removeMetadata("LibsRabbitHop", libsDisguises); |                                 entity.removeMetadata("LibsRabbitHop", libsDisguises); | ||||||
|                                 entity.setMetadata("LibsRabbitHop", |                                 entity.setMetadata("LibsRabbitHop", new FixedMetadataValue(libsDisguises, System.currentTimeMillis())); | ||||||
|                                         new FixedMetadataValue(libsDisguises, System.currentTimeMillis())); |  | ||||||
|                             } |                             } | ||||||
|                             packets = Arrays.copyOf(packets, packets.length + 1); |                             packets = Arrays.copyOf(packets, packets.length + 1); | ||||||
|                             packets[1] = new PacketContainer(Server.ENTITY_STATUS); |                             packets[1] = new PacketContainer(Server.ENTITY_STATUS); | ||||||
| @@ -1340,16 +1335,17 @@ public class PacketsManager { | |||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     if (sentPacket.getType() == Server.ENTITY_LOOK |                     if (sentPacket.getType() == Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL) { | ||||||
|                             && disguise.getType() == DisguiseType.WITHER_SKULL) { |  | ||||||
|                         packets = new PacketContainer[0]; |                         packets = new PacketContainer[0]; | ||||||
|                     } else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) { |                     } else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) { | ||||||
|  |  | ||||||
|                         packets[0] = sentPacket.shallowClone(); |                         packets[0] = sentPacket.shallowClone(); | ||||||
|                         StructureModifier<Byte> bytes = packets[0].getBytes(); |                         StructureModifier<Byte> bytes = packets[0].getBytes(); | ||||||
|                         byte yawValue = bytes.read(1); |                         byte yawValue = bytes.read(1); | ||||||
|                         bytes.write(1, getYaw(disguise.getType(), entity.getType(), yawValue)); |                         bytes.write(1, getYaw(disguise.getType(), entity.getType(), yawValue)); | ||||||
|                         byte pitchValue = bytes.read(0); |                         byte pitchValue = bytes.read(0); | ||||||
|                         bytes.write(0, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue)); |                         bytes.write(0, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue)); | ||||||
|  |  | ||||||
|                         if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) { |                         if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) { | ||||||
|                             StructureModifier<Double> doubles = packets[0].getDoubles(); |                             StructureModifier<Double> doubles = packets[0].getDoubles(); | ||||||
|                             Location loc = entity.getLocation(); |                             Location loc = entity.getLocation(); | ||||||
|   | |||||||
| @@ -1,5 +1,6 @@ | |||||||
| package me.libraryaddict.disguise.utilities; | package me.libraryaddict.disguise.utilities; | ||||||
|  |  | ||||||
|  | import com.comphenix.protocol.wrappers.MinecraftKey; | ||||||
| import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; | import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry; | ||||||
| import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; | import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer; | ||||||
| import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; | import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject; | ||||||
| @@ -569,6 +570,32 @@ public class ReflectionManager { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Necessary for 1.9 | ||||||
|  |      * @return | ||||||
|  |      */ | ||||||
|  |     public static String convertSoundEffectToString(Object soundEffect) { | ||||||
|  |         try { | ||||||
|  |             Field f_getMinecraftKey = getNmsField("SoundEffect", "b"); | ||||||
|  |             f_getMinecraftKey.setAccessible(true); | ||||||
|  |             MinecraftKey key = MinecraftKey.fromHandle(f_getMinecraftKey.get(soundEffect)); | ||||||
|  |             return key.getKey(); | ||||||
|  |         } catch (IllegalAccessException e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static Object getCraftSoundEffect(String sound) { | ||||||
|  |         Method nmsMethod = getNmsMethod("CraftSound", "getSoundEffect"); | ||||||
|  |         try { | ||||||
|  |             return nmsMethod.invoke(null, sound); | ||||||
|  |         } catch (IllegalAccessException | InvocationTargetException e) { | ||||||
|  |             e.printStackTrace(); | ||||||
|  |         } | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * This creates a DataWatcherItem usable with WrappedWatchableObject |      * This creates a DataWatcherItem usable with WrappedWatchableObject | ||||||
|      * @param id |      * @param id | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user