use of org.bukkit.projectiles.ProjectileSource in project Denizen-For-Bukkit by DenizenScript.
the class HealthTrait method onDamage.
// <--[action]
// @Actions
// death
// death by entity
// death by <entity>
// death by block
// death by <cause>
//
// @Triggers when the NPC dies. (Requires Health Trait)
//
// @Context
// <context.killer> returns the entity that killed the NPC (if any)
// <context.shooter> returns the shooter of the killing projectile (if any)
//
// -->
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(EntityDamageEvent event) {
// Check if the event pertains to this NPC
if (event.getEntity() != npc.getEntity() || dying) {
return;
}
// Make sure this is a killing blow
if (this.getHealth() - event.getFinalDamage() > 0) {
return;
}
dying = true;
player = null;
// Save entityId for EntityDeath event
entityId = npc.getEntity().getEntityId();
String deathCause = CoreUtilities.toLowerCase(event.getCause().toString()).replace('_', ' ');
Map<String, dObject> context = new HashMap<String, dObject>();
context.put("damage", new Element(event.getDamage()));
context.put("death_cause", new Element(deathCause));
// Check if the entity has been killed by another entity
if (event instanceof EntityDamageByEntityEvent) {
Entity killerEntity = ((EntityDamageByEntityEvent) event).getDamager();
context.put("killer", new dEntity(killerEntity));
// that player to the action's ScriptEntry
if (killerEntity instanceof Player) {
player = dPlayer.mirrorBukkitPlayer((Player) killerEntity);
} else // account as well
if (killerEntity instanceof Projectile) {
ProjectileSource shooter = ((Projectile) killerEntity).getShooter();
if (shooter != null && shooter instanceof LivingEntity) {
context.put("shooter", new dEntity((LivingEntity) shooter));
if (shooter instanceof Player) {
player = dPlayer.mirrorBukkitPlayer((Player) shooter);
}
DenizenAPI.getDenizenNPC(npc).action("death by " + ((LivingEntity) shooter).getType().toString(), player, context);
}
// TODO: Handle other shooter source thingy types
}
DenizenAPI.getDenizenNPC(npc).action("death by entity", player, context);
DenizenAPI.getDenizenNPC(npc).action("death by " + killerEntity.getType().toString(), player, context);
} else // If not, check if the entity has been killed by a block
if (event instanceof EntityDamageByBlockEvent) {
DenizenAPI.getDenizenNPC(npc).action("death by block", player, context);
// TODO:
// The line of code below should work, but a Bukkit bug makes the damager
// return null. Uncomment it once the bug is fixed.
// DenizenAPI.getDenizenNPC(npc).action("death by " +
// ((EntityDamageByBlockEvent) event).getDamager().getType().name(), null);
}
DenizenAPI.getDenizenNPC(npc).action("death", player, context);
DenizenAPI.getDenizenNPC(npc).action("death by " + deathCause, player, context);
// NPC's entity still exists before proceeding
if (npc.getEntity() == null) {
return;
}
loc = dLocation.valueOf(// TODO: debug option?
TagManager.tag(// TODO: debug option?
respawnLocation, new BukkitTagContext(null, DenizenAPI.getDenizenNPC(npc), false, null, true, null)));
if (loc == null) {
loc = npc.getEntity().getLocation();
}
if (animatedeath) {
// Cancel navigation to keep the NPC from damaging players
// while the death animation is being carried out.
npc.getNavigator().cancelNavigation();
// Reset health now to avoid the death from happening instantly
//setHealth();
// Play animation (TODO)
// playDeathAnimation(npc.getEntity());
}
die();
if (respawn && (Duration.valueOf(respawnDelay).getTicks() > 0)) {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() {
public void run() {
if (CitizensAPI.getNPCRegistry().getById(npc.getId()) == null || npc.isSpawned()) {
return;
} else {
npc.spawn(loc);
}
}
}, (Duration.valueOf(respawnDelay).getTicks()));
}
}
use of org.bukkit.projectiles.ProjectileSource 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(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);
}
}
use of org.bukkit.projectiles.ProjectileSource in project MagicPlugin by elBukkit.
the class ProjectileAction method start.
@Override
public SpellResult start(CastContext context) {
MageController controller = context.getController();
Mage mage = context.getMage();
// Modify with wand power
// Turned some of this off for now
// int count = this.count * mage.getRadiusMultiplier();
// int speed = this.speed * damageMultiplier;
int size = (int) (mage.getRadiusMultiplier() * this.size);
double damageMultiplier = mage.getDamageMultiplier("projectile");
double damage = damageMultiplier * this.damage;
float radiusMultiplier = mage.getRadiusMultiplier();
float spread = this.spread;
if (radiusMultiplier > 1) {
spread = spread / radiusMultiplier;
}
Random random = context.getRandom();
Class<?> projectileType = NMSUtils.getBukkitClass("net.minecraft.server.Entity" + projectileTypeName);
if (!CompatibilityUtils.isValidProjectileClass(projectileType)) {
controller.getLogger().warning("Bad projectile class: " + projectileTypeName);
return SpellResult.FAIL;
}
// Prepare parameters
Location location = sourceLocation.getLocation(context);
Vector direction = location.getDirection();
if (startDistance > 0) {
location = location.clone().add(direction.clone().multiply(startDistance));
}
// Spawn projectiles
LivingEntity shootingEntity = context.getLivingEntity();
ProjectileSource source = null;
if (shootingEntity != null) {
source = shootingEntity;
}
for (int i = 0; i < count; i++) {
try {
// Spawn a new projectile
Projectile projectile = CompatibilityUtils.spawnProjectile(projectileType, location, direction, source, speed, spread, i > 0 ? spread : 0, random);
if (projectile == null) {
return SpellResult.FAIL;
}
if (shootingEntity != null) {
projectile.setShooter(shootingEntity);
}
if (projectile instanceof Fireball) {
Fireball fireball = (Fireball) projectile;
fireball.setIsIncendiary(useFire);
fireball.setYield(size);
}
if (projectile instanceof Arrow) {
Arrow arrow = (Arrow) projectile;
if (useFire) {
arrow.setFireTicks(300);
}
if (damage > 0) {
CompatibilityUtils.setDamage(projectile, damage);
}
if (tickIncrease > 0) {
CompatibilityUtils.decreaseLifespan(projectile, tickIncrease);
}
if (pickupStatus != null && !pickupStatus.isEmpty()) {
CompatibilityUtils.setPickupStatus(arrow, pickupStatus);
}
}
if (!breakBlocks) {
projectile.setMetadata("cancel_explosion", new FixedMetadataValue(controller.getPlugin(), true));
}
track(context, projectile);
} catch (Exception ex) {
ex.printStackTrace();
}
}
return checkTracking(context);
}
use of org.bukkit.projectiles.ProjectileSource in project MassiveCore by MassiveCraft.
the class MUtil method getLiableDamager.
public static Entity getLiableDamager(EntityDamageEvent event) {
if (!(event instanceof EntityDamageByEntityEvent))
return null;
EntityDamageByEntityEvent edbeEvent = (EntityDamageByEntityEvent) event;
Entity ret = edbeEvent.getDamager();
if (ret instanceof Projectile) {
Projectile projectile = (Projectile) ret;
ProjectileSource projectileSource = projectile.getShooter();
if (projectileSource instanceof Entity)
ret = (Entity) projectileSource;
}
Entity cloudBasedDamager = IntegrationLiabilityAreaEffectCloud.get().getLiableDamager(edbeEvent);
if (cloudBasedDamager != null)
ret = cloudBasedDamager;
return ret;
}
use of org.bukkit.projectiles.ProjectileSource in project RedProtect by FabioZumbi12.
the class RPEntityListener method onPotionSplash.
@EventHandler
public void onPotionSplash(PotionSplashEvent event) {
RedProtect.get().logger.debug("RPEntityListener - Is PotionSplashEvent");
if (event.isCancelled()) {
return;
}
ProjectileSource thrower = event.getPotion().getShooter();
for (PotionEffect e : event.getPotion().getEffects()) {
PotionEffectType t = e.getType();
if (!t.equals(PotionEffectType.BLINDNESS) && !t.equals(PotionEffectType.CONFUSION) && !t.equals(PotionEffectType.HARM) && !t.equals(PotionEffectType.HUNGER) && !t.equals(PotionEffectType.POISON) && !t.equals(PotionEffectType.SLOW) && !t.equals(PotionEffectType.SLOW_DIGGING) && !t.equals(PotionEffectType.WEAKNESS) && !t.equals(PotionEffectType.WITHER)) {
return;
}
}
Player shooter;
if (thrower instanceof Player) {
shooter = (Player) thrower;
} else {
return;
}
for (Entity e2 : event.getAffectedEntities()) {
Region r = RedProtect.get().rm.getTopRegion(e2.getLocation());
if (event.getEntity() instanceof Player) {
if (r != null && r.flagExists("pvp") && !r.canPVP((Player) event.getEntity(), shooter)) {
event.setCancelled(true);
return;
}
} else {
if (r != null && !r.canInteractPassives(shooter)) {
event.setCancelled(true);
return;
}
}
}
}
Aggregations