use of org.bukkit.entity.Projectile in project Jobs by GamingMesh.
the class JobsPaymentListener method onEntityDeath.
@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event) {
// Entity that died must be living
if (!(event.getEntity() instanceof LivingEntity))
return;
LivingEntity lVictim = (LivingEntity) event.getEntity();
// mob spawner, no payment or experience
if (lVictim.hasMetadata(mobSpawnerMetadata)) {
lVictim.removeMetadata(mobSpawnerMetadata, plugin);
return;
}
// make sure plugin is enabled
if (!plugin.isEnabled())
return;
if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
org.bukkit.entity.Player pDamager = null;
if (e.getDamager() instanceof org.bukkit.entity.Player) {
pDamager = (org.bukkit.entity.Player) e.getDamager();
} else if (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof org.bukkit.entity.Player) {
pDamager = (org.bukkit.entity.Player) ((Projectile) e.getDamager()).getShooter();
} else if (e.getDamager() instanceof Tameable) {
Tameable t = (Tameable) e.getDamager();
if (t.isTamed() && t.getOwner() instanceof org.bukkit.entity.Player) {
pDamager = (org.bukkit.entity.Player) t.getOwner();
}
}
if (pDamager != null) {
// check if in creative
if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
return;
if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
return;
// restricted area multiplier
double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(pDamager);
// pay
JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);
Jobs.action(jDamager, new EntityActionInfo(lVictim.getType(), ActionType.KILL), multiplier);
}
}
}
use of org.bukkit.entity.Projectile in project EliteMobs by MagmaGuy.
the class FrostCone method createSnowball.
private static Snowball createSnowball(EliteEntity eliteEntity, Location location) {
Projectile snowball = EliteProjectile.create(EntityType.SNOWBALL, eliteEntity.getLivingEntity(), getShotVector(eliteEntity, location), false);
ProjectileTagger.tagProjectileWithCustomDamage(snowball, 2);
snowball.getPersistentDataContainer().set(frostConeSnowballKey, PersistentDataType.STRING, "true");
Bukkit.getScheduler().runTaskLater(MetadataHandler.PLUGIN, snowball::remove, 20L * 3);
return (Snowball) snowball;
}
use of org.bukkit.entity.Projectile in project EliteMobs by MagmaGuy.
the class PlayerDamagedByEliteMobHandler method secondaryEnchantmentDamageReduction.
private double secondaryEnchantmentDamageReduction(Player player, EntityDamageByEntityEvent event) {
double totalReductionLevel = 0;
for (ItemStack itemStack : player.getInventory().getArmorContents()) {
if (itemStack == null || itemStack.getItemMeta() == null)
continue;
if (event.getDamager() instanceof Projectile)
totalReductionLevel += ItemTagger.getEnchantment(itemStack.getItemMeta(), Enchantment.PROTECTION_ENVIRONMENTAL.getKey());
}
totalReductionLevel = totalReductionLevel / 4 / 10;
return totalReductionLevel;
}
use of org.bukkit.entity.Projectile in project EliteMobs by MagmaGuy.
the class EliteProjectile method create.
public static Projectile create(EntityType entityType, Entity shooter, Entity victim, Vector shotVector, boolean gravity) {
Location projectileLocation = generateLocation(shooter, victim);
Projectile projectile = (Projectile) projectileLocation.getWorld().spawnEntity(projectileLocation, entityType);
projectile.setShooter((ProjectileSource) shooter);
projectile.setVelocity(shotVector);
projectile.setGravity(gravity);
EntityTracker.registerProjectileEntity(projectile);
return projectile;
}
use of org.bukkit.entity.Projectile in project Glowstone by GlowstoneMC.
the class GlowEntity method pulsePhysics.
protected void pulsePhysics() {
// The pending location and the block at that location
Location pendingLocation = location.clone().add(velocity);
Block pendingBlock = pendingLocation.getBlock();
if (pendingBlock.getType().isSolid()) {
Location pendingLocationX = location.clone().add(velocity.getX(), 0, 0);
if (pendingLocationX.getBlock().getType().isSolid()) {
velocity.setX(0);
}
Location pendingLocationY = location.clone().add(0, velocity.getY(), 0);
if (pendingLocationY.getBlock().getType().isSolid()) {
velocity.setY(0);
}
Location pendingLocationZ = location.clone().add(0, 0, velocity.getZ());
if (pendingLocationZ.getBlock().getType().isSolid()) {
velocity.setZ(0);
}
if (this instanceof Projectile) {
EventFactory.getInstance().callEvent(new ProjectileHitEvent((Projectile) this, pendingBlock));
}
collide(pendingBlock);
} else {
if (hasFriction()) {
// apply friction and gravity
if (location.getBlock().getType() == Material.WATER) {
velocity.multiply(liquidDrag);
velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
} else if (location.getBlock().getType() == Material.LAVA) {
velocity.multiply(liquidDrag - 0.3);
velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
} else {
if (applyDragBeforeAccel) {
velocity.setY(airDrag * velocity.getY() + getGravityAccel().getY());
} else {
velocity.setY(airDrag * (velocity.getY() + getGravityAccel().getY()));
}
if (isOnGround()) {
velocity.setX(velocity.getX() * slipMultiplier);
velocity.setY(0);
velocity.setZ(velocity.getZ() * slipMultiplier);
} else {
velocity.setX(velocity.getX() * airDrag);
velocity.setZ(velocity.getZ() * airDrag);
}
}
} else if (hasGravity() && !isOnGround()) {
switch(location.getBlock().getType()) {
case WATER:
case LAVA:
velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
break;
default:
velocity.setY(velocity.getY() + getGravityAccel().getY() / 4);
}
}
setRawLocation(pendingLocation);
}
}
Aggregations