use of org.bukkit.craftbukkit.v1_13_R1.CraftWorld in project Village_Defense by Plajer.
the class ArenaInitializer1_11_R1 method spawnWolf.
public void spawnWolf(Location location, Player player) {
net.minecraft.server.v1_11_R1.World McWorld = ((CraftWorld) location.getWorld()).getHandle();
WorkingWolf wolf = new WorkingWolf(location.getWorld());
wolf.setPosition(location.getX(), location.getY(), location.getZ());
McWorld.addEntity(wolf, CreatureSpawnEvent.SpawnReason.CUSTOM);
wolf.setCustomName(ChatManager.colorMessage("In-Game.Spawned-Wolf-Name").replaceAll("%player%", player.getName()));
wolf.setCustomNameVisible(true);
wolf.setInvisible(false);
((Wolf) wolf.getBukkitEntity()).setOwner(player);
CreatureUtils.applyMetadata(wolf.getBukkitEntity(), this);
this.addWolf((Wolf) wolf.getBukkitEntity());
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftWorld in project MagicPlugin by elBukkit.
the class CompatibilityUtils method spawnProjectile.
@Override
public Projectile spawnProjectile(Class<?> projectileType, Location location, Vector direction, ProjectileSource source, float speed, float spread, float spreadLocations, Random random) {
Constructor<? extends Object> constructor = null;
ServerLevel nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
Projectile projectile = null;
try {
Object entityType = null;
constructor = projectileType.getConstructor(net.minecraft.world.entity.EntityType.class, net.minecraft.world.level.Level.class);
entityType = projectileEntityTypes.get(projectileType.getSimpleName());
if (entityType == null) {
throw new Exception("Failed to find entity type for projectile class " + projectileType.getName());
}
Object nmsProjectile = null;
try {
nmsProjectile = constructor.newInstance(entityType, nmsWorld);
} catch (Exception ex) {
nmsProjectile = null;
platform.getLogger().log(Level.WARNING, "Error spawning projectile of class " + projectileType.getName(), ex);
}
if (nmsProjectile == null || !(nmsProjectile instanceof net.minecraft.world.entity.Entity)) {
throw new Exception("Failed to spawn projectile of class " + projectileType.getName());
}
// Velocity must be set manually- EntityFireball.setDirection applies a crazy-wide gaussian distribution!
if (nmsProjectile instanceof AbstractHurtingProjectile) {
AbstractHurtingProjectile fireballIsh = (AbstractHurtingProjectile) nmsProjectile;
// Taken from EntityArrow
double spreadWeight = Math.min(0.4f, spread * 0.007499999832361937D);
double dx = speed * (direction.getX() + (random.nextGaussian() * spreadWeight));
double dy = speed * (direction.getY() + (random.nextGaussian() * spreadWeight));
double dz = speed * (direction.getZ() + (random.nextGaussian() * spreadWeight));
fireballIsh.xPower = dx * 0.1D;
fireballIsh.yPower = dy * 0.1D;
fireballIsh.zPower = dz * 0.1D;
}
net.minecraft.world.entity.Entity nmsEntity = ((net.minecraft.world.entity.Entity) nmsProjectile);
Vector modifiedLocation = location.toVector().clone();
if (Fireball.class.isAssignableFrom(projectileType) && spreadLocations > 0) {
modifiedLocation.setX(modifiedLocation.getX() + direction.getX() + (random.nextGaussian() * spread / 5));
modifiedLocation.setY(modifiedLocation.getY() + direction.getY() + (random.nextGaussian() * spread / 5));
modifiedLocation.setZ(modifiedLocation.getZ() + direction.getZ() + (random.nextGaussian() * spread / 5));
}
nmsEntity.moveTo(modifiedLocation.getX(), modifiedLocation.getY(), modifiedLocation.getZ(), location.getYaw(), location.getPitch());
if (nmsEntity instanceof net.minecraft.world.entity.projectile.Projectile) {
net.minecraft.world.entity.projectile.Projectile nms = (net.minecraft.world.entity.projectile.Projectile) nmsEntity;
nms.shoot(direction.getX(), direction.getY(), direction.getZ(), speed, spread);
}
Entity entity = nmsEntity.getBukkitEntity();
if (entity == null || !(entity instanceof Projectile)) {
throw new Exception("Got invalid bukkit entity from projectile of class " + projectileType.getName());
}
projectile = (Projectile) entity;
if (source != null) {
projectile.setShooter(source);
nmsEntity.projectileSource = source;
}
nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.DEFAULT);
} catch (Throwable ex) {
ex.printStackTrace();
return null;
}
return projectile;
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftWorld in project MagicPlugin by elBukkit.
the class CompatibilityUtils method spawnFireworkEffect.
@Override
public Entity spawnFireworkEffect(Material fireworkMaterial, Server server, Location location, FireworkEffect effect, int power, Vector direction, Integer expectedLifespan, Integer ticksFlown, boolean silent) {
Entity entity = null;
try {
if (fireworkMaterial == null) {
return null;
}
ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
ItemStack itemStack = new ItemStack(fireworkMaterial);
FireworkMeta meta = (FireworkMeta) itemStack.getItemMeta();
meta.addEffect(effect);
meta.setPower(power);
itemStack.setItemMeta(meta);
Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(itemStack));
final FireworkRocketEntity fireworkHandle = new FireworkRocketEntity(level, location.getX(), location.getY(), location.getZ(), (net.minecraft.world.item.ItemStack) item);
fireworkHandle.setSilent(silent);
if (direction != null) {
fireworkHandle.setDeltaMovement(new Vec3(direction.getX(), direction.getY(), direction.getZ()));
}
if (ticksFlown != null) {
ReflectionUtils.setPrivateNeedsFixing(platform.getLogger(), fireworkHandle, FireworkRocketEntity.class, "life", "e", ticksFlown);
}
if (expectedLifespan != null) {
fireworkHandle.lifetime = expectedLifespan;
}
if (direction == null) {
ClientboundAddEntityPacket fireworkPacket = new ClientboundAddEntityPacket(fireworkHandle, CompatibilityConstants.FIREWORK_TYPE);
int fireworkId = fireworkHandle.getId();
SynchedEntityData watcher = fireworkHandle.getEntityData();
ClientboundSetEntityDataPacket metadataPacket = new ClientboundSetEntityDataPacket(fireworkId, watcher, true);
ClientboundEntityEventPacket statusPacket = new ClientboundEntityEventPacket(fireworkHandle, (byte) 17);
ClientboundRemoveEntityPacket destroyPacket = new ClientboundRemoveEntityPacket(fireworkId);
Collection<? extends Player> players = server.getOnlinePlayers();
sendPacket(server, location, players, fireworkPacket);
sendPacket(server, location, players, metadataPacket);
sendPacket(server, location, players, statusPacket);
sendPacket(server, location, players, destroyPacket);
return null;
}
level.addEntity(fireworkHandle, CreatureSpawnEvent.SpawnReason.CUSTOM);
entity = fireworkHandle.getBukkitEntity();
} catch (Exception ex) {
ex.printStackTrace();
}
return entity;
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftWorld in project MagicPlugin by elBukkit.
the class CompatibilityUtils method applyPhysics.
@Override
public boolean applyPhysics(Block block) {
ServerLevel nmsWorld = ((CraftWorld) block.getWorld()).getHandle();
BlockPos blockLocation = new BlockPos(block.getX(), block.getY(), block.getZ());
net.minecraft.world.level.block.state.BlockState blockState = nmsWorld.getBlockState(blockLocation);
clearItems(block.getLocation());
platform.getDeprecatedUtils().setTypeAndData(block, Material.AIR, (byte) 0, false);
return nmsWorld.setBlock(blockLocation, blockState, 3);
}
use of org.bukkit.craftbukkit.v1_13_R1.CraftWorld in project MagicPlugin by elBukkit.
the class CompatibilityUtils method createItemFrame.
@Override
public ItemFrame createItemFrame(Location location, BlockFace facing, Rotation rotation, ItemStack item) {
ItemFrame newItemFrame = null;
ServerLevel level = ((CraftWorld) location.getWorld()).getHandle();
Direction directionEnum = null;
try {
directionEnum = Direction.valueOf(facing.name());
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
BlockPos blockLocation = new BlockPos(location.getX(), location.getY(), location.getZ());
net.minecraft.world.entity.decoration.ItemFrame newEntity = new net.minecraft.world.entity.decoration.ItemFrame(level, blockLocation, directionEnum);
Entity bukkitEntity = newEntity.getBukkitEntity();
if (bukkitEntity != null && bukkitEntity instanceof ItemFrame) {
newItemFrame = (ItemFrame) bukkitEntity;
newItemFrame.setItem(platform.getItemUtils().getCopy(item));
newItemFrame.setRotation(rotation);
}
return newItemFrame;
}
Aggregations