use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.
the class GlowEnderPearl method collide.
/**
* Process teleportation when collide with a block.
*
* @param block the block that the ender pearl collides with
*/
@Override
public void collide(Block block) {
ProjectileSource source = getShooter();
if (source instanceof Entity) {
Location destination = getLocation();
Entity entity = (Entity) source;
Location entityLocation = entity.getLocation();
// Add 0.3 to Y value. Otherwise the eneity will get stuck inside a block.
destination.add(0, 0.3, 0);
// Renew the pitch and yaw value right before teleportation.
destination.setPitch(entityLocation.getPitch());
destination.setYaw(entityLocation.getYaw());
entity.teleport(destination, PlayerTeleportEvent.TeleportCause.ENDER_PEARL);
// Give fall damage to the eneity that threw this ender pearl.
if (source instanceof LivingEntity) {
((LivingEntity) entity).damage(ENDER_PEARL_DAMAGE, EntityDamageEvent.DamageCause.FALL);
}
}
// Spawn endermite for 5% chance.
ThreadLocalRandom random = ThreadLocalRandom.current();
if (random.nextInt(100) < 5) {
getWorld().spawn(location, GlowEndermite.class, CreatureSpawnEvent.SpawnReason.ENDER_PEARL);
}
remove();
}
use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.
the class GlowEgg method randomHatchSpawning.
/**
* Handle spawning entities when the egg breaks.
*
* @param location The location the egg breaks
*/
private void randomHatchSpawning(Location location) {
ThreadLocalRandom random = ThreadLocalRandom.current();
// There is a 1/8 chance for egg to hatch and spawn at least 1 entity
boolean hatching = random.nextInt(8) == 0;
// ...and if the egg is hatching, there is now
// 1/32 chance to spawn 3 more entities.
byte amount;
if (hatching) {
amount = (byte) ((random.nextInt(32) == 0) ? 4 : 1);
} else {
amount = 0;
}
EntityType hatchingType = EntityType.CHICKEN;
final ProjectileSource shooter = getShooter();
if (shooter instanceof GlowPlayer) {
PlayerEggThrowEvent event = EventFactory.getInstance().callEvent(new PlayerEggThrowEvent((GlowPlayer) shooter, this, hatching, amount, hatchingType));
amount = event.getNumHatches();
hatching = event.isHatching();
hatchingType = event.getHatchingType();
}
if (hatching) {
for (int i = 0; i < amount; i++) {
GlowEntity entity = (GlowEntity) location.getWorld().spawnEntity(location.clone().add(0, 0.3, 0), hatchingType);
if (entity instanceof GlowAgeable) {
((GlowAgeable) entity).setBaby();
}
}
}
}
use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.
the class GlowFireball method explode.
private void explode() {
ProjectileSource source = getShooter();
world.createExplosion(source instanceof Entity ? (Entity) source : this, location.getX(), location.getY(), location.getZ(), yield, incendiary, true);
remove();
}
use of org.bukkit.projectiles.ProjectileSource in project modules-extra by CubeEngine.
the class ListenerVehicle method onVehicleDestroy.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVehicleDestroy(final VehicleDestroyEvent event) {
Entity causer;
if (event.getAttacker() != null) {
if (event.getAttacker() instanceof Player) {
causer = event.getAttacker();
} else if (event.getAttacker() instanceof Projectile) {
ProjectileSource shooter = ((Projectile) event.getAttacker()).getShooter();
if (shooter instanceof Player) {
causer = (Player) shooter;
} else if (shooter instanceof Entity) {
causer = (Entity) shooter;
} else {
// TODO other ProjectileSources
return;
}
} else {
causer = event.getAttacker();
}
} else if (event.getVehicle().getPassenger() instanceof Player) {
causer = event.getVehicle().getPassenger();
} else {
// TODO why?
return;
}
if (causer instanceof Player) {
VehicleBreak action = this.newAction(VehicleBreak.class, event.getVehicle().getWorld());
if (action != null) {
action.setLocation(event.getVehicle().getLocation());
action.setVehicle(event.getVehicle());
action.setPlayer((Player) causer);
this.logAction(action);
}
} else {
// TODO EntityVehicleBreak
}
}
use of org.bukkit.projectiles.ProjectileSource in project modules-extra by CubeEngine.
the class ListenerBlockIgnite method onIgnite.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIgnite(BlockIgniteEvent event) {
BlockState oldState = event.getBlock().getState();
ActionBlock action;
switch(event.getCause()) {
case FIREBALL:
action = this.newAction(IgniteFireball.class, oldState.getWorld());
if (action != null) {
ProjectileSource shooter = ((Fireball) event.getIgnitingEntity()).getShooter();
if (shooter instanceof Entity) {
((IgniteFireball) action).setShooter((Entity) shooter);
if (shooter instanceof Ghast) {
LivingEntity target = BukkitUtils.getTarget((Ghast) shooter);
if (target instanceof Player) {
((IgniteFireball) action).setPlayer((Player) target);
}
} else if (shooter instanceof Player) {
((IgniteFireball) action).setPlayer((Player) shooter);
}
}
}
break;
case LAVA:
action = this.newAction(IgniteLava.class, oldState.getWorld());
if (action != null) {
((IgniteLava) action).setSource(event.getIgnitingBlock().getLocation());
}
break;
case LIGHTNING:
action = this.newAction(IgniteLightning.class, oldState.getWorld());
break;
case FLINT_AND_STEEL:
action = this.newAction(IgniteLighter.class, oldState.getWorld());
if (action != null && event.getPlayer() != null) {
((IgniteLighter) action).setPlayer(event.getPlayer());
}
break;
case ENDER_CRYSTAL:
case EXPLOSION:
action = this.newAction(IgniteOther.class, oldState.getWorld());
break;
case SPREAD:
return;
default:
this.module.getLog().warn("Unknown IgniteCause! {}", event.getCause().name());
return;
}
if (action != null) {
action.setOldBlock(oldState);
action.setNewBlock(FIRE);
action.setLocation(oldState.getLocation());
this.logAction(action);
}
}
Aggregations