Search in sources :

Example 1 with IEntityControllerPet

use of simplepets.brainsynder.api.entity.IEntityControllerPet in project SimplePets by brainsynder-Dev.

the class PetOwner method removePet.

/**
 * Removes the players current pet, if the player does not have a pet method will do nothing.
 */
public void removePet() {
    if (hasPet()) {
        PetRemoveEvent removeEvent = new PetRemoveEvent((Pet) pet);
        Bukkit.getServer().getPluginManager().callEvent(removeEvent);
        if (removeEvent.isCancelled()) {
            play(player.getEyeLocation(), ParticleMaker.Particle.VILLAGER_ANGRY, 0.5F, 0.5F, 0.5F);
            SoundMaker.BLOCK_ANVIL_LAND.playSound(player.getLocation(), 0.5F, 0.5F);
            return;
        }
        if (pet.getEntity().getEntity().getPassenger() instanceof Player) {
            pet.getEntity().getEntity().eject();
        }
        if (PetCore.get().getConfiguration().getBoolean("ShowParticles")) {
            play(pet.getEntity().getEntity().getLocation(), ParticleMaker.Particle.LAVA, 1.0F, 1.0F, 1.0F);
        }
        if (pet.getEntity() instanceof IEntityControllerPet) {
            ((IEntityControllerPet) pet.getEntity()).remove();
        } else {
            pet.getEntity().getEntity().remove();
        }
        this.pet = null;
    }
}
Also used : Player(org.bukkit.entity.Player) PetRemoveEvent(simplepets.brainsynder.api.event.pet.PetRemoveEvent) IEntityControllerPet(simplepets.brainsynder.api.entity.IEntityControllerPet)

Example 2 with IEntityControllerPet

use of simplepets.brainsynder.api.entity.IEntityControllerPet in project SimplePets by brainsynder-Dev.

the class Pet method setVehicle.

public void setVehicle(boolean value, boolean byEvent) {
    if (!byEvent) {
        if (type.canMount(owner)) {
            if (ent instanceof IHorseAbstract) {
                IHorseAbstract horse = (IHorseAbstract) ent;
                if (!horse.isSaddled())
                    horse.setSaddled(true);
            }
            if (getPet().getPassenger() != null) {
                PetVehicleEvent event = new PetVehicleEvent(this, PetVehicleEvent.Type.DISMOUNT);
                Bukkit.getServer().getPluginManager().callEvent(event);
                if (event.isCancelled())
                    return;
                if (ent instanceof IEntityControllerPet) {
                    ((IEntityControllerPet) ent).getDisplayEntity().eject();
                } else {
                    ent.getEntity().eject();
                }
                value = false;
            } else if (isVehicle()) {
                value = false;
            }
            if (value && (vehicle != value)) {
                if (isHat) {
                    PetHatEvent event = new PetHatEvent(this, PetHatEvent.Type.REMOVE);
                    Bukkit.getServer().getPluginManager().callEvent(event);
                    if (event.isCancelled())
                        return;
                    instance.getUtilities().removePassenger(owner, ent.getEntity());
                    setHat(false);
                }
                PetVehicleEvent event = new PetVehicleEvent(this, PetVehicleEvent.Type.MOUNT);
                Bukkit.getServer().getPluginManager().callEvent(event);
                if (event.isCancelled())
                    return;
                value = true;
                if (owner.getLocation().getBlock() != null) {
                    List<Material> blocks = Utilities.getBlacklistedMaterials();
                    if (!blocks.contains(owner.getLocation().getBlock().getType()) && !blocks.contains(owner.getEyeLocation().getBlock().getType())) {
                        getPet().teleport(owner);
                    }
                } else {
                    getPet().teleport(owner);
                }
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        if (ent instanceof IEntityControllerPet) {
                            ((IEntityControllerPet) ent).getDisplayEntity().setPassenger(owner);
                        } else {
                            ent.getEntity().setPassenger(owner);
                        }
                    }
                }.runTaskLater(PetCore.get(), 2L);
            }
        }
    }
    vehicle = value;
}
Also used : PetHatEvent(simplepets.brainsynder.api.event.pet.PetHatEvent) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Material(org.bukkit.Material) IHorseAbstract(simplepets.brainsynder.api.entity.misc.IHorseAbstract) PetVehicleEvent(simplepets.brainsynder.api.event.pet.PetVehicleEvent) IEntityControllerPet(simplepets.brainsynder.api.entity.IEntityControllerPet)

Example 3 with IEntityControllerPet

use of simplepets.brainsynder.api.entity.IEntityControllerPet 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 4 with IEntityControllerPet

use of simplepets.brainsynder.api.entity.IEntityControllerPet 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 5 with IEntityControllerPet

use of simplepets.brainsynder.api.entity.IEntityControllerPet 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)

Aggregations

IEntityControllerPet (simplepets.brainsynder.api.entity.IEntityControllerPet)15 IEntityPet (simplepets.brainsynder.api.entity.IEntityPet)10 ArmorStand (org.bukkit.entity.ArmorStand)6 Shulker (org.bukkit.entity.Shulker)6 EulerAngle (org.bukkit.util.EulerAngle)6 SimplePetsException (simplepets.brainsynder.errors.SimplePetsException)6 ArmorStandDefault (simplepets.brainsynder.pet.types.ArmorStandDefault)6 ShulkerDefault (simplepets.brainsynder.pet.types.ShulkerDefault)6 Map (java.util.Map)3 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)2 CraftEntity (org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity)2 CraftEntity (org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity)2 Player (org.bukkit.entity.Player)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 PetHatEvent (simplepets.brainsynder.api.event.pet.PetHatEvent)2 EntityControllerPet (simplepets.brainsynder.nms.v1_11_R1.entities.list.EntityControllerPet)2 World (net.minecraft.server.v1_11_R1.World)1 World (net.minecraft.server.v1_12_R1.World)1 World (net.minecraft.server.v1_13_R1.World)1 World (net.minecraft.server.v1_13_R2.World)1