Search in sources :

Example 76 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project SimplePets by brainsynder-Dev.

the class EntityPet method glowHandler.

private void glowHandler(boolean glow) {
    try {
        Entity pet = this;
        if (this instanceof IEntityControllerPet) {
            org.bukkit.entity.Entity ent = ((IEntityControllerPet) this).getVisibleEntity().getEntity();
            pet = ((CraftEntity) ent).getHandle();
        }
        handleInvisible(glow, pet);
    } catch (IllegalAccessException ignored) {
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) IEntityControllerPet(simplepets.brainsynder.api.entity.IEntityControllerPet)

Example 77 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project SimplePets by brainsynder-Dev.

the class EntityControllerPet method reloadLocation.

@Override
public void reloadLocation() {
    if (displayEntity.getPassenger() != null) {
        net.minecraft.server.v1_14_R1.Entity displayEntity = ((CraftEntity) this.displayEntity).getHandle();
        Location loc;
        if (this.displayRider != null) {
            if (this.displayRider.getType().equals(EntityType.SHULKER)) {
                loc = getBukkitEntity().getLocation().clone().subtract(0, 0.735, 0);
            } else {
                loc = getBukkitEntity().getLocation().clone();
            }
        } else {
            loc = getBukkitEntity().getLocation().clone();
        }
        displayEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
        loc.getWorld().getNearbyEntities(loc, 100, 100, 100).forEach(entity -> {
            if (entity instanceof Player) {
                Player player = (Player) entity;
                PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(displayEntity);
                ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
            }
        });
        return;
    }
    net.minecraft.server.v1_14_R1.Entity displayEntity = ((CraftEntity) this.displayEntity).getHandle();
    Location loc;
    if (this.displayRider != null) {
        if (this.displayRider.getType().equals(EntityType.SHULKER)) {
            loc = getBukkitEntity().getLocation().clone().add(0, 0.75, 0);
        } else {
            loc = getBukkitEntity().getLocation().clone();
        }
    } else {
        loc = getBukkitEntity().getLocation().clone();
    }
    displayEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    loc.getWorld().getNearbyEntities(loc, 100, 100, 100).forEach(entity -> {
        if (entity instanceof Player) {
            Player player = (Player) entity;
            PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(displayEntity);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    });
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) net.minecraft.server.v1_14_R1(net.minecraft.server.v1_14_R1) CraftEntity(org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) Location(org.bukkit.Location)

Example 78 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity 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 79 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project SimplePets by brainsynder-Dev.

the class SpawnUtil method spawn.

public IEntityPet spawn(Location l, IPet pet, String className) {
    try {
        World mcWorld = ((CraftWorld) l.getWorld()).getHandle();
        EntityTypes<?> types = EntityUtils.getType((className.equals("EntityControllerPet")) ? EntityWrapper.ZOMBIE : pet.getEntityType());
        EntityPet customEntity = (EntityPet) petMap.get(className).getDeclaredConstructor(EntityTypes.class, World.class, IPet.class).newInstance(types, mcWorld, pet);
        customEntity.setInvisible(false);
        customEntity.setLocation(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch());
        mcWorld.addEntity(customEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        if (customEntity instanceof IEntityControllerPet) {
            if (pet.getPetType() instanceof ArmorStandDefault) {
                ArmorStand stand = EntityArmorStandPet.spawn(l, ((EntityControllerPet) customEntity));
                stand.setGravity(false);
                stand.setArms(true);
                stand.setCollidable(false);
                stand.setLeftLegPose(new EulerAngle(0.0D, 0.0D, 0.0D));
                stand.setRightLegPose(new EulerAngle(0.0D, 0.0D, 0.0D));
                stand.setLeftArmPose(new EulerAngle(0.0D, 0.0D, 0.0D));
                stand.setRightArmPose(new EulerAngle(0.0D, 0.0D, 0.0D));
                ((IEntityControllerPet) customEntity).setDisplayEntity(stand);
            } else if (pet.getPetType() instanceof ShulkerDefault) {
                ArmorStand stand = EntityGhostStandPet.spawn(l, pet);
                stand.setGravity(false);
                stand.setCollidable(false);
                stand.setSmall(true);
                Shulker shulker = EntityShulkerPet.spawn(l, (EntityControllerPet) customEntity);
                shulker.setAI(false);
                shulker.setCollidable(false);
                ((CraftEntity) stand).getHandle().passengers.add(0, ((CraftEntity) shulker).getHandle());
                ((IEntityControllerPet) customEntity).setDisplayEntity(stand);
            }
        }
        return customEntity;
    } catch (Exception e) {
        e.printStackTrace();
        throw new SimplePetsException("Could not summon the " + pet.getPetType().getConfigName() + " Pet", e);
    }
}
Also used : ShulkerDefault(simplepets.brainsynder.pet.types.ShulkerDefault) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) CraftWorld(org.bukkit.craftbukkit.v1_13_R2.CraftWorld) World(net.minecraft.server.v1_13_R2.World) Shulker(org.bukkit.entity.Shulker) SimplePetsException(simplepets.brainsynder.errors.SimplePetsException) IEntityControllerPet(simplepets.brainsynder.api.entity.IEntityControllerPet) IEntityPet(simplepets.brainsynder.api.entity.IEntityPet) EntityControllerPet(simplepets.brainsynder.nms.v1_13_R2.entities.list.EntityControllerPet) IEntityControllerPet(simplepets.brainsynder.api.entity.IEntityControllerPet) ArmorStand(org.bukkit.entity.ArmorStand) ArmorStandDefault(simplepets.brainsynder.pet.types.ArmorStandDefault) SimplePetsException(simplepets.brainsynder.errors.SimplePetsException) EulerAngle(org.bukkit.util.EulerAngle) CraftWorld(org.bukkit.craftbukkit.v1_13_R2.CraftWorld)

Example 80 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project SimplePets by brainsynder-Dev.

the class EntityControllerPet method reloadLocation.

@Override
public void reloadLocation() {
    if (displayEntity.getPassenger() != null) {
        net.minecraft.server.v1_13_R2.Entity displayEntity = ((CraftEntity) this.displayEntity).getHandle();
        Location loc;
        if (this.displayRider != null) {
            if (this.displayRider.getType().equals(EntityType.SHULKER)) {
                loc = getBukkitEntity().getLocation().clone().subtract(0, 0.735, 0);
            } else {
                loc = getBukkitEntity().getLocation().clone();
            }
        } else {
            loc = getBukkitEntity().getLocation().clone();
        }
        displayEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
        loc.getWorld().getNearbyEntities(loc, 100, 100, 100).forEach(entity -> {
            if (entity instanceof Player) {
                Player player = (Player) entity;
                PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(displayEntity);
                ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
            }
        });
        return;
    }
    net.minecraft.server.v1_13_R2.Entity displayEntity = ((CraftEntity) this.displayEntity).getHandle();
    Location loc;
    if (this.displayRider != null) {
        if (this.displayRider.getType().equals(EntityType.SHULKER)) {
            loc = getBukkitEntity().getLocation().clone().add(0, 0.75, 0);
        } else {
            loc = getBukkitEntity().getLocation().clone();
        }
    } else {
        loc = getBukkitEntity().getLocation().clone();
    }
    displayEntity.setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    loc.getWorld().getNearbyEntities(loc, 100, 100, 100).forEach(entity -> {
        if (entity instanceof Player) {
            Player player = (Player) entity;
            PacketPlayOutEntityTeleport packet = new PacketPlayOutEntityTeleport(displayEntity);
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
        }
    });
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) Player(org.bukkit.entity.Player) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) net.minecraft.server.v1_13_R2(net.minecraft.server.v1_13_R2) CraftPlayer(org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)40 Entity (org.bukkit.entity.Entity)38 LivingEntity (org.bukkit.entity.LivingEntity)33 Entity (net.minecraft.world.entity.Entity)25 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)25 CraftEntity (org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)24 Iterator (java.util.Iterator)21 List (java.util.List)21 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)21 UUID (java.util.UUID)20 CraftEntity (org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity)20 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)17 Player (org.bukkit.entity.Player)16 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)14 Vector (org.bukkit.util.Vector)14 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)12 Vec3 (net.minecraft.world.phys.Vec3)12 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)11 EntityDamageSource (net.minecraft.world.damagesource.EntityDamageSource)11 EnteredStateTracker (com.elmakers.mine.bukkit.utility.EnteredStateTracker)10