Search in sources :

Example 1 with EntityShulkerPet

use of simplepets.brainsynder.nms.v1_12_R1.entities.impossamobs.EntityShulkerPet in project SimplePets by brainsynder-Dev.

the class EntityPet method glowHandler.

private void glowHandler(boolean glow) {
    try {
        if (this instanceof IEntityControllerPet) {
            org.bukkit.entity.Entity ent = ((IEntityControllerPet) this).getVisibleEntity().getEntity();
            Entity handle = ((CraftEntity) ent).getHandle();
            if (handle instanceof EntityArmorStandPet) {
                EntityArmorStandPet pet = (EntityArmorStandPet) handle;
                DataWatcher toCloneDataWatcher = pet.getDataWatcher();
                DataWatcher newDataWatcher = new DataWatcher(pet);
                Map<Integer, DataWatcher.Item<?>> currentMap = (Map<Integer, DataWatcher.Item<?>>) FieldUtils.readDeclaredField(toCloneDataWatcher, "d", true);
                Map<Integer, DataWatcher.Item<?>> newMap = Maps.newHashMap();
                for (Integer integer : currentMap.keySet()) {
                    newMap.put(integer, currentMap.get(integer).d());
                }
                DataWatcher.Item item = newMap.get(0);
                byte initialBitMask = (Byte) item.b();
                byte bitMaskIndex = (byte) 6;
                isGlowing = glow;
                if (glow) {
                    item.a((byte) (initialBitMask | 1 << bitMaskIndex));
                } else {
                    item.a((byte) (initialBitMask & ~(1 << bitMaskIndex)));
                }
                FieldUtils.writeDeclaredField(newDataWatcher, "d", newMap, true);
                PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(pet.getId(), newDataWatcher, true);
                ((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(metadataPacket);
            } else if (handle instanceof EntityShulkerPet) {
                EntityShulkerPet pet = (EntityShulkerPet) handle;
                DataWatcher toCloneDataWatcher = pet.getDataWatcher();
                DataWatcher newDataWatcher = new DataWatcher(pet);
                Map<Integer, DataWatcher.Item<?>> currentMap = (Map<Integer, DataWatcher.Item<?>>) FieldUtils.readDeclaredField(toCloneDataWatcher, "d", true);
                Map<Integer, DataWatcher.Item<?>> newMap = Maps.newHashMap();
                for (Integer integer : currentMap.keySet()) {
                    newMap.put(integer, currentMap.get(integer).d());
                }
                DataWatcher.Item item = newMap.get(0);
                byte initialBitMask = (Byte) item.b();
                byte bitMaskIndex = (byte) 6;
                isGlowing = glow;
                if (glow) {
                    item.a((byte) (initialBitMask | 1 << bitMaskIndex));
                } else {
                    item.a((byte) (initialBitMask & ~(1 << bitMaskIndex)));
                }
                FieldUtils.writeDeclaredField(newDataWatcher, "d", newMap, true);
                PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(pet.getId(), newDataWatcher, true);
                ((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(metadataPacket);
            } else {
                EntityPet pet = this;
                DataWatcher toCloneDataWatcher = pet.getDataWatcher();
                DataWatcher newDataWatcher = new DataWatcher(pet);
                Map<Integer, DataWatcher.Item<?>> currentMap = (Map<Integer, DataWatcher.Item<?>>) FieldUtils.readDeclaredField(toCloneDataWatcher, "d", true);
                Map<Integer, DataWatcher.Item<?>> newMap = Maps.newHashMap();
                for (Integer integer : currentMap.keySet()) {
                    newMap.put(integer, currentMap.get(integer).d());
                }
                DataWatcher.Item item = newMap.get(0);
                byte initialBitMask = (Byte) item.b();
                byte bitMaskIndex = (byte) 6;
                isGlowing = glow;
                if (glow) {
                    item.a((byte) (initialBitMask | 1 << bitMaskIndex));
                } else {
                    item.a((byte) (initialBitMask & ~(1 << bitMaskIndex)));
                }
                FieldUtils.writeDeclaredField(newDataWatcher, "d", newMap, true);
                PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(pet.getId(), newDataWatcher, true);
                ((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(metadataPacket);
            }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) IEntityControllerPet(simplepets.brainsynder.api.entity.IEntityControllerPet) IEntityPet(simplepets.brainsynder.api.entity.IEntityPet) EntityArmorStandPet(simplepets.brainsynder.nms.v1_13_R2.entities.impossamobs.EntityArmorStandPet) EntityShulkerPet(simplepets.brainsynder.nms.v1_13_R2.entities.impossamobs.EntityShulkerPet) Map(java.util.Map)

Example 2 with EntityShulkerPet

use of simplepets.brainsynder.nms.v1_12_R1.entities.impossamobs.EntityShulkerPet in project SimplePets by brainsynder-Dev.

the class EntityPet method glowHandler.

private void glowHandler(boolean glow) {
    try {
        if (this instanceof IEntityControllerPet) {
            org.bukkit.entity.Entity ent = ((IEntityControllerPet) this).getVisibleEntity().getEntity();
            Entity handle = ((CraftEntity) ent).getHandle();
            if (handle instanceof EntityArmorStandPet) {
                EntityArmorStandPet pet = (EntityArmorStandPet) handle;
                DataWatcher toCloneDataWatcher = pet.getDataWatcher();
                DataWatcher newDataWatcher = new DataWatcher(pet);
                Map<Integer, DataWatcher.Item<?>> currentMap = (Map<Integer, DataWatcher.Item<?>>) FieldUtils.readDeclaredField(toCloneDataWatcher, "d", true);
                Map<Integer, DataWatcher.Item<?>> newMap = Maps.newHashMap();
                for (Integer integer : currentMap.keySet()) {
                    newMap.put(integer, currentMap.get(integer).d());
                }
                DataWatcher.Item item = newMap.get(0);
                byte initialBitMask = (Byte) item.b();
                byte bitMaskIndex = (byte) 6;
                isGlowing = glow;
                if (glow) {
                    item.a((byte) (initialBitMask | 1 << bitMaskIndex));
                } else {
                    item.a((byte) (initialBitMask & ~(1 << bitMaskIndex)));
                }
                FieldUtils.writeDeclaredField(newDataWatcher, "d", newMap, true);
                PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(pet.getId(), newDataWatcher, true);
                ((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(metadataPacket);
            } else if (handle instanceof EntityShulkerPet) {
                EntityShulkerPet pet = (EntityShulkerPet) handle;
                DataWatcher toCloneDataWatcher = pet.getDataWatcher();
                DataWatcher newDataWatcher = new DataWatcher(pet);
                Map<Integer, DataWatcher.Item<?>> currentMap = (Map<Integer, DataWatcher.Item<?>>) FieldUtils.readDeclaredField(toCloneDataWatcher, "d", true);
                Map<Integer, DataWatcher.Item<?>> newMap = Maps.newHashMap();
                for (Integer integer : currentMap.keySet()) {
                    newMap.put(integer, currentMap.get(integer).d());
                }
                DataWatcher.Item item = newMap.get(0);
                byte initialBitMask = (Byte) item.b();
                byte bitMaskIndex = (byte) 6;
                isGlowing = glow;
                if (glow) {
                    item.a((byte) (initialBitMask | 1 << bitMaskIndex));
                } else {
                    item.a((byte) (initialBitMask & ~(1 << bitMaskIndex)));
                }
                FieldUtils.writeDeclaredField(newDataWatcher, "d", newMap, true);
                PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(pet.getId(), newDataWatcher, true);
                ((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(metadataPacket);
            } else {
                EntityPet pet = this;
                DataWatcher toCloneDataWatcher = pet.getDataWatcher();
                DataWatcher newDataWatcher = new DataWatcher(pet);
                Map<Integer, DataWatcher.Item<?>> currentMap = (Map<Integer, DataWatcher.Item<?>>) FieldUtils.readDeclaredField(toCloneDataWatcher, "d", true);
                Map<Integer, DataWatcher.Item<?>> newMap = Maps.newHashMap();
                for (Integer integer : currentMap.keySet()) {
                    newMap.put(integer, currentMap.get(integer).d());
                }
                DataWatcher.Item item = newMap.get(0);
                byte initialBitMask = (Byte) item.b();
                byte bitMaskIndex = (byte) 6;
                isGlowing = glow;
                if (glow) {
                    item.a((byte) (initialBitMask | 1 << bitMaskIndex));
                } else {
                    item.a((byte) (initialBitMask & ~(1 << bitMaskIndex)));
                }
                FieldUtils.writeDeclaredField(newDataWatcher, "d", newMap, true);
                PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(pet.getId(), newDataWatcher, true);
                ((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(metadataPacket);
            }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) IEntityControllerPet(simplepets.brainsynder.api.entity.IEntityControllerPet) IEntityPet(simplepets.brainsynder.api.entity.IEntityPet) EntityArmorStandPet(simplepets.brainsynder.nms.v1_12_R1.entities.impossamobs.EntityArmorStandPet) EntityShulkerPet(simplepets.brainsynder.nms.v1_12_R1.entities.impossamobs.EntityShulkerPet) Map(java.util.Map)

Example 3 with EntityShulkerPet

use of simplepets.brainsynder.nms.v1_12_R1.entities.impossamobs.EntityShulkerPet in project SimplePets by brainsynder-Dev.

the class EntityPet method glowHandler.

private void glowHandler(boolean glow) {
    try {
        if (this instanceof IEntityControllerPet) {
            org.bukkit.entity.Entity ent = ((IEntityControllerPet) this).getVisibleEntity().getEntity();
            Entity handle = ((CraftEntity) ent).getHandle();
            if (handle instanceof EntityArmorStandPet) {
                EntityArmorStandPet pet = (EntityArmorStandPet) handle;
                DataWatcher toCloneDataWatcher = pet.getDataWatcher();
                DataWatcher newDataWatcher = new DataWatcher(pet);
                Map<Integer, DataWatcher.Item<?>> currentMap = (Map<Integer, DataWatcher.Item<?>>) FieldUtils.readDeclaredField(toCloneDataWatcher, "d", true);
                Map<Integer, DataWatcher.Item<?>> newMap = Maps.newHashMap();
                for (Integer integer : currentMap.keySet()) {
                    newMap.put(integer, currentMap.get(integer).d());
                }
                DataWatcher.Item item = newMap.get(0);
                byte initialBitMask = (Byte) item.b();
                byte bitMaskIndex = (byte) 6;
                isGlowing = glow;
                if (glow) {
                    item.a((byte) (initialBitMask | 1 << bitMaskIndex));
                } else {
                    item.a((byte) (initialBitMask & ~(1 << bitMaskIndex)));
                }
                FieldUtils.writeDeclaredField(newDataWatcher, "d", newMap, true);
                PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(pet.getId(), newDataWatcher, true);
                ((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(metadataPacket);
            } else if (handle instanceof EntityShulkerPet) {
                EntityShulkerPet pet = (EntityShulkerPet) handle;
                DataWatcher toCloneDataWatcher = pet.getDataWatcher();
                DataWatcher newDataWatcher = new DataWatcher(pet);
                Map<Integer, DataWatcher.Item<?>> currentMap = (Map<Integer, DataWatcher.Item<?>>) FieldUtils.readDeclaredField(toCloneDataWatcher, "d", true);
                Map<Integer, DataWatcher.Item<?>> newMap = Maps.newHashMap();
                for (Integer integer : currentMap.keySet()) {
                    newMap.put(integer, currentMap.get(integer).d());
                }
                DataWatcher.Item item = newMap.get(0);
                byte initialBitMask = (Byte) item.b();
                byte bitMaskIndex = (byte) 6;
                isGlowing = glow;
                if (glow) {
                    item.a((byte) (initialBitMask | 1 << bitMaskIndex));
                } else {
                    item.a((byte) (initialBitMask & ~(1 << bitMaskIndex)));
                }
                FieldUtils.writeDeclaredField(newDataWatcher, "d", newMap, true);
                PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(pet.getId(), newDataWatcher, true);
                ((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(metadataPacket);
            } else {
                EntityPet pet = this;
                DataWatcher toCloneDataWatcher = pet.getDataWatcher();
                DataWatcher newDataWatcher = new DataWatcher(pet);
                Map<Integer, DataWatcher.Item<?>> currentMap = (Map<Integer, DataWatcher.Item<?>>) FieldUtils.readDeclaredField(toCloneDataWatcher, "d", true);
                Map<Integer, DataWatcher.Item<?>> newMap = Maps.newHashMap();
                for (Integer integer : currentMap.keySet()) {
                    newMap.put(integer, currentMap.get(integer).d());
                }
                DataWatcher.Item item = newMap.get(0);
                byte initialBitMask = (Byte) item.b();
                byte bitMaskIndex = (byte) 6;
                isGlowing = glow;
                if (glow) {
                    item.a((byte) (initialBitMask | 1 << bitMaskIndex));
                } else {
                    item.a((byte) (initialBitMask & ~(1 << bitMaskIndex)));
                }
                FieldUtils.writeDeclaredField(newDataWatcher, "d", newMap, true);
                PacketPlayOutEntityMetadata metadataPacket = new PacketPlayOutEntityMetadata(pet.getId(), newDataWatcher, true);
                ((CraftPlayer) getOwner()).getHandle().playerConnection.sendPacket(metadataPacket);
            }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer) IEntityControllerPet(simplepets.brainsynder.api.entity.IEntityControllerPet) IEntityPet(simplepets.brainsynder.api.entity.IEntityPet) EntityArmorStandPet(simplepets.brainsynder.nms.v1_13_R1.entities.impossamobs.EntityArmorStandPet) EntityShulkerPet(simplepets.brainsynder.nms.v1_13_R1.entities.impossamobs.EntityShulkerPet) Map(java.util.Map)

Aggregations

Map (java.util.Map)3 IEntityControllerPet (simplepets.brainsynder.api.entity.IEntityControllerPet)3 IEntityPet (simplepets.brainsynder.api.entity.IEntityPet)3 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)1 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)1 CraftEntity (org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity)1 CraftPlayer (org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer)1 CraftEntity (org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity)1 CraftPlayer (org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer)1 EntityArmorStandPet (simplepets.brainsynder.nms.v1_12_R1.entities.impossamobs.EntityArmorStandPet)1 EntityShulkerPet (simplepets.brainsynder.nms.v1_12_R1.entities.impossamobs.EntityShulkerPet)1 EntityArmorStandPet (simplepets.brainsynder.nms.v1_13_R1.entities.impossamobs.EntityArmorStandPet)1 EntityShulkerPet (simplepets.brainsynder.nms.v1_13_R1.entities.impossamobs.EntityShulkerPet)1 EntityArmorStandPet (simplepets.brainsynder.nms.v1_13_R2.entities.impossamobs.EntityArmorStandPet)1 EntityShulkerPet (simplepets.brainsynder.nms.v1_13_R2.entities.impossamobs.EntityShulkerPet)1