use of org.bukkit.projectiles.ProjectileSource in project Sentinel by mcmonkey4eva.
the class SentinelTrait method whenAttacksAreHappening.
@EventHandler(priority = EventPriority.LOWEST)
public void whenAttacksAreHappening(EntityDamageByEntityEvent event) {
if (!npc.isSpawned()) {
return;
}
if (event.isCancelled()) {
return;
}
if (event.getEntity().getUniqueId().equals(getLivingEntity().getUniqueId())) {
if (!event.isApplicable(EntityDamageEvent.DamageModifier.ARMOR)) {
event.setDamage(EntityDamageEvent.DamageModifier.BASE, (1.0 - getArmor(getLivingEntity())) * event.getDamage(EntityDamageEvent.DamageModifier.BASE));
} else {
event.setDamage(EntityDamageEvent.DamageModifier.ARMOR, -getArmor(getLivingEntity()) * event.getDamage(EntityDamageEvent.DamageModifier.BASE));
}
return;
}
if (event.getDamager().getUniqueId().equals(getLivingEntity().getUniqueId())) {
if (SentinelPlugin.instance.getConfig().getBoolean("random.enforce damage", false)) {
if (canEnforce) {
canEnforce = false;
whenAttacksHappened(event);
if (!event.isCancelled()) {
((LivingEntity) event.getEntity()).damage(event.getFinalDamage());
}
if (SentinelPlugin.debugMe) {
SentinelPlugin.instance.getLogger().info("Sentinel: enforce damage value to " + event.getFinalDamage());
}
} else {
if (SentinelPlugin.debugMe) {
SentinelPlugin.instance.getLogger().info("Sentinel: refuse damage enforcement");
}
}
event.setDamage(0);
event.setCancelled(true);
return;
}
event.setDamage(EntityDamageEvent.DamageModifier.BASE, getDamage());
}
if (event.getDamager() instanceof Projectile) {
ProjectileSource source = ((Projectile) event.getDamager()).getShooter();
if (source instanceof LivingEntity && ((LivingEntity) source).getUniqueId().equals(getLivingEntity().getUniqueId())) {
if (SentinelPlugin.instance.getConfig().getBoolean("random.enforce damage", false)) {
if (canEnforce) {
canEnforce = false;
whenAttacksHappened(event);
if (!event.isCancelled()) {
((LivingEntity) event.getEntity()).damage(getDamage());
}
if (SentinelPlugin.debugMe) {
SentinelPlugin.instance.getLogger().info("Sentinel: enforce damage value to " + getDamage());
}
} else {
if (SentinelPlugin.debugMe) {
SentinelPlugin.instance.getLogger().info("Sentinel: refuse damage enforcement");
}
}
event.setDamage(0);
event.setCancelled(true);
return;
}
double dam = getDamage();
double modder = event.getDamage(EntityDamageEvent.DamageModifier.BASE);
double rel = modder == 0.0 ? 1.0 : dam / modder;
event.setDamage(EntityDamageEvent.DamageModifier.BASE, dam);
for (EntityDamageEvent.DamageModifier mod : EntityDamageEvent.DamageModifier.values()) {
if (mod != EntityDamageEvent.DamageModifier.BASE && event.isApplicable(mod)) {
event.setDamage(mod, event.getDamage(mod) * rel);
if (SentinelPlugin.debugMe) {
SentinelPlugin.instance.getLogger().info("Sentinel: Set damage for " + mod + " to " + event.getDamage(mod));
}
}
}
}
}
}
use of org.bukkit.projectiles.ProjectileSource in project MyPet by xXKeyleXx.
the class MyPetEntityListener method onMyPetDamageMonitor.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMyPetDamageMonitor(final EntityDamageByEntityEvent event) {
if (event.getEntity() == null) {
// catch invalid events (i.e. EnchantmentAPI)
return;
}
Entity target = event.getEntity();
if (WorldGroup.getGroupByWorld(target.getWorld()).isDisabled()) {
return;
}
if (target instanceof LivingEntity) {
Entity source = event.getDamager();
if (Configuration.LevelSystem.Experience.DAMAGE_WEIGHTED_EXPERIENCE_DISTRIBUTION && !(target instanceof Player) && !(target instanceof MyPetBukkitEntity)) {
LivingEntity livingSource = null;
if (source instanceof Projectile) {
Projectile projectile = (Projectile) source;
if (projectile.getShooter() instanceof LivingEntity) {
livingSource = (LivingEntity) projectile.getShooter();
}
} else if (source instanceof LivingEntity) {
livingSource = (LivingEntity) source;
}
if (livingSource != null) {
MyPetExperience.addDamageToEntity(livingSource, (LivingEntity) target, event.getDamage());
}
}
if (source instanceof Projectile) {
ProjectileSource projectileSource = ((Projectile) source).getShooter();
if (projectileSource instanceof Entity) {
source = (Entity) projectileSource;
}
}
if (source instanceof MyPetBukkitEntity) {
MyPet myPet = ((MyPetBukkitEntity) source).getMyPet();
if (myPet.getStatus() != PetState.Here) {
return;
}
// fix influence of other plugins for this event and throw damage event
MyPetDamageEvent petDamageEvent = new MyPetDamageEvent(myPet, target, event.getOriginalDamage(EntityDamageEvent.DamageModifier.BASE));
Bukkit.getPluginManager().callEvent(petDamageEvent);
if (petDamageEvent.isCancelled()) {
event.setCancelled(true);
return;
} else {
event.setDamage(petDamageEvent.getDamage());
}
if (!isSkillActive) {
for (Skill skill : myPet.getSkills().all()) {
if (skill instanceof OnHitSkill) {
OnHitSkill onHitSkill = (OnHitSkill) skill;
if (onHitSkill.trigger()) {
MyPetOnHitSkillEvent skillEvent = new MyPetOnHitSkillEvent(myPet, onHitSkill, (LivingEntity) target);
Bukkit.getPluginManager().callEvent(skillEvent);
if (!skillEvent.isCancelled()) {
isSkillActive = true;
onHitSkill.apply((LivingEntity) target);
isSkillActive = false;
}
}
}
}
}
}
}
}
use of org.bukkit.projectiles.ProjectileSource in project InfernalMobs by NyaaCat.
the class EventListener method onEntityAttack.
@EventHandler(priority = EventPriority.HIGH)
public void onEntityAttack(final EntityDamageByEntityEvent event) {
// todo unexpected fireball damage
boolean isDirectAttack = true;
Entity trueVictim = event.getEntity();
Entity trueAttacker = event.getDamager();
if (trueAttacker instanceof Projectile) {
isDirectAttack = false;
ProjectileSource src = ((Projectile) trueAttacker).getShooter();
if (src instanceof Entity) {
trueAttacker = (Entity) src;
} else {
return;
}
}
if (!(trueAttacker instanceof LivingEntity))
return;
if (!(trueVictim instanceof LivingEntity))
return;
if (plugin.mobManager.mobMap.containsKey(trueVictim.getUniqueId())) {
// something attacked infernal mob
if (!(trueAttacker instanceof Player))
return;
Mob mob = plugin.mobManager.mobMap.get(trueVictim.getUniqueId());
mob.lastDamageCause = event;
GameMode gameMode = ((Player) trueAttacker).getGameMode();
if (gameMode != GameMode.CREATIVE && gameMode != GameMode.SPECTATOR) {
for (EnumAbilities ab : mob.abilityList) {
ab.onPlayerAttack((LivingEntity) trueVictim, mob, (Player) trueAttacker, isDirectAttack, event);
}
}
if (ConfigReader.isEnhanceEnabled()) {
double resistedDamage = ConfigReader.getLevelConfig().calcResistedDamage(event.getDamage(), mob.getMobLevel());
event.setDamage(resistedDamage);
}
}
if ((plugin.mobManager.mobMap.containsKey(trueAttacker.getUniqueId()))) {
// infernal mob attacked something
EntityDamageEvent.DamageCause cause = event.getCause();
double originDamage = event.getDamage();
Mob mob = plugin.mobManager.mobMap.get(trueAttacker.getUniqueId());
if (isValidDamageCause(cause, mob)) {
if ((trueVictim instanceof Player)) {
GameMode gameMode = ((Player) trueVictim).getGameMode();
if (gameMode == GameMode.CREATIVE || gameMode == GameMode.SPECTATOR)
return;
for (EnumAbilities ab : mob.abilityList) {
ab.onAttackPlayer((LivingEntity) trueAttacker, mob, (Player) trueVictim, isDirectAttack, event);
}
}
double extraDamage = event.getDamage() - originDamage;
if (ConfigReader.isEnhanceEnabled()) {
LevelConfig levelConfig = ConfigReader.getLevelConfig();
double damage = levelConfig.getDamage(originDamage, mob.getMobLevel());
damage += extraDamage;
event.setDamage(damage);
}
}
}
}
use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.
the class GlowFishingHook method reelIn.
/**
* Removes this fishing hook. Drops loot and xp if a player is fishing.
*/
public void reelIn() {
if (location.getBlock().getType() == Material.WATER) {
ProjectileSource shooter = getShooter();
if (shooter instanceof Player) {
PlayerFishEvent fishEvent = new PlayerFishEvent((Player) shooter, this, null, CAUGHT_FISH);
fishEvent.setExpToDrop(ThreadLocalRandom.current().nextInt(1, 7));
fishEvent = EventFactory.getInstance().callEvent(fishEvent);
if (!fishEvent.isCancelled()) {
// TODO: Item should "fly" towards player
world.dropItemNaturally(((Player) getShooter()).getLocation(), getRewardItem());
((Player) getShooter()).giveExp(fishEvent.getExpToDrop());
}
}
}
remove();
}
use of org.bukkit.projectiles.ProjectileSource in project Glowstone by GlowstoneMC.
the class GlowEnderPearl method collide.
/**
* Process teleportation when collide with an entity.
*
* @param entity the eneity that the ender pearl collides with
*/
@Override
public void collide(LivingEntity entity) {
ProjectileSource source = getShooter();
// the entity receives fake damage.
if (source instanceof Entity) {
entity.damage(0, (Entity) source, EntityDamageEvent.DamageCause.PROJECTILE);
} else {
entity.damage(0, EntityDamageEvent.DamageCause.PROJECTILE);
}
collide(entity.getLocation().getBlock());
}
Aggregations