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;
}
}
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;
}
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) {
}
}
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();
}
}
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);
}
}
Aggregations