use of org.bukkit.craftbukkit.v1_6_R3.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) {
}
}
use of org.bukkit.craftbukkit.v1_6_R3.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);
}
});
}
use of org.bukkit.craftbukkit.v1_6_R3.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();
}
}
use of org.bukkit.craftbukkit.v1_6_R3.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);
}
}
use of org.bukkit.craftbukkit.v1_6_R3.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);
}
});
}
Aggregations