use of org.bukkit.entity.Projectile in project Glowstone by GlowstoneMC.
the class GlowArmorStand method damage.
@Override
public void damage(double amount, Entity source, @NotNull DamageCause cause) {
if (getNoDamageTicks() > 0 || health <= 0 || !canTakeDamage(cause)) {
return;
}
if (source instanceof Projectile && !(source instanceof Arrow)) {
return;
}
EntityDamageEvent event = EventFactory.getInstance().onEntityDamage(source == null ? new EntityDamageEvent(this, cause, amount) : new EntityDamageByEntityEvent(source, this, cause, amount));
if (event.isCancelled()) {
return;
}
boolean drop = false;
if (source instanceof GlowPlayer || source instanceof Arrow && ((Projectile) source).getShooter() instanceof GlowPlayer) {
GlowPlayer damager = (GlowPlayer) (source instanceof GlowPlayer ? source : ((Arrow) source).getShooter());
if (damager.getGameMode() == GameMode.ADVENTURE) {
return;
} else if (damager.getGameMode() == GameMode.CREATIVE) {
// Instantly kill the entity
amount = 2;
} else {
// Needs two hits
amount = 1;
drop = true;
}
}
setLastDamage(amount);
setHealth(health - amount, drop);
}
use of org.bukkit.entity.Projectile in project Glowstone by GlowstoneMC.
the class ProjectileDispenseBehavior method dispenseStack.
@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
GlowWorld world = block.getWorld();
Vector position = BlockDispenser.getDispensePosition(block);
BlockFace face = BlockDispenser.getFacing(block);
Projectile entity = projectileCreator.apply(new Location(world, position.getX(), position.getY(), position.getZ()), stack);
entity.setShooter(new GlowDispenser(block));
entity.setVelocity(new Vector(face.getModX(), face.getModY() + 0.1f, face.getModZ()).multiply(6));
stack.setAmount(stack.getAmount() - 1);
if (stack.getAmount() < 1) {
return null;
}
return stack;
}
use of org.bukkit.entity.Projectile in project Denizen-For-Bukkit by DenizenScript.
the class NPCTagBase method onHit.
// <--[action]
// @Actions
// hit
// hit on <entity>
//
// @Triggers when the NPC hits an enemy.
//
// @Context
// None
//
// -->
// <--[action]
// @Actions
// kill
// kill of <entity>
//
// @Triggers when the NPC kills an enemy.
//
// @Context
// None
//
// -->
@EventHandler(priority = EventPriority.MONITOR)
public void onHit(EntityDamageByEntityEvent event) {
NPC citizen = CitizensAPI.getNPCRegistry().getNPC(event.getEntity());
if (citizen == null) {
if (event.getDamager() instanceof Projectile) {
if (((Projectile) event.getDamager()).getShooter() instanceof Entity) {
citizen = CitizensAPI.getNPCRegistry().getNPC((Entity) ((Projectile) event.getDamager()).getShooter());
}
}
}
if (citizen == null || !citizen.hasTrait(AssignmentTrait.class)) {
return;
}
NPCTag npc = new NPCTag(citizen);
PlayerTag player = null;
if (event.getEntity() instanceof Player) {
player = PlayerTag.mirrorBukkitPlayer((Player) event.getEntity());
}
// TODO: Context containing the entity hit
npc.action("hit", player);
npc.action("hit on " + event.getEntityType().name(), player);
if (event.getEntity() instanceof LivingEntity) {
if (((LivingEntity) event.getEntity()).getHealth() - event.getFinalDamage() <= 0) {
npc.action("kill", player);
npc.action("kill of " + event.getEntityType().name(), player);
}
}
}
use of org.bukkit.entity.Projectile in project Prism-Bukkit by prism.
the class DeathUtils method getCauseNiceName.
/**
* Returns the name of what caused an entity to die.
*
* @return String
*/
public static String getCauseNiceName(Entity entity) {
EntityDamageEvent e = entity.getLastDamageCause();
if (e == null) {
return "unknown";
}
// Determine the root cause
DamageCause damageCause = e.getCause();
Entity killer = null;
// If was damaged by an entity
if (entity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) entity.getLastDamageCause();
// Arrow?
if (entityDamageByEntityEvent.getDamager() instanceof Arrow) {
Projectile arrow = (Arrow) entityDamageByEntityEvent.getDamager();
ProjectileSource source = arrow.getShooter();
if (source instanceof Player) {
killer = ((Player) source);
}
} else {
killer = entityDamageByEntityEvent.getDamager();
}
}
if (entity instanceof Player) {
Player player = (Player) entity;
// yourself with instant damage it doesn't show as suicide.
if (killer instanceof Player) {
// Themself
if (killer.getName().equals(player.getName())) {
return "suicide";
}
// translate bukkit events to nicer names
if ((damageCause.equals(DamageCause.ENTITY_ATTACK) || damageCause.equals(DamageCause.PROJECTILE))) {
return "pvp";
}
}
}
// Causes of death for either entities or players
if (damageCause.equals(DamageCause.ENTITY_ATTACK)) {
return "mob";
} else if (damageCause.equals(DamageCause.PROJECTILE)) {
return "skeleton";
} else if (damageCause.equals(DamageCause.ENTITY_EXPLOSION)) {
return "creeper";
} else if (damageCause.equals(DamageCause.CONTACT)) {
return "cactus";
} else if (damageCause.equals(DamageCause.BLOCK_EXPLOSION)) {
return "tnt";
} else if (damageCause.equals(DamageCause.FIRE) || damageCause.equals(DamageCause.FIRE_TICK)) {
return "fire";
} else if (damageCause.equals(DamageCause.MAGIC)) {
return "potion";
}
return damageCause.name().toLowerCase();
}
use of org.bukkit.entity.Projectile in project acidisland by tastybento.
the class IslandGuard1_9 method EndCrystalDamage.
/**
* Handle end crystal damage by visitors
* @param e - event
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void EndCrystalDamage(final EntityDamageByEntityEvent e) {
if (e.getEntity() == null || !IslandGuard.inWorld(e.getEntity())) {
return;
}
if (!(e.getEntity() instanceof EnderCrystal)) {
return;
}
Player p = null;
if (e.getDamager() instanceof Player) {
p = (Player) e.getDamager();
} else if (e.getDamager() instanceof Projectile) {
// Get the shooter
Projectile projectile = (Projectile) e.getDamager();
ProjectileSource shooter = projectile.getShooter();
if (shooter instanceof Player) {
p = (Player) shooter;
}
}
if (p != null) {
if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) {
return;
}
// Check if on island
if (plugin.getGrid().playerIsOnIsland(p)) {
return;
}
// Check island
Island island = plugin.getGrid().getIslandAt(e.getEntity().getLocation());
if (island == null && Settings.defaultWorldSettings.get(SettingsFlag.BREAK_BLOCKS)) {
return;
}
if (island != null && island.getIgsFlag(SettingsFlag.BREAK_BLOCKS)) {
return;
}
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).islandProtected);
e.setCancelled(true);
}
}
Aggregations