Java Code Examples for org.bukkit.event.entity.EntityDamageByEntityEvent

The following examples show how to use org.bukkit.event.entity.EntityDamageByEntityEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: askyblock   Source File: IslandGuard.java    License: GNU General Public License v2.0 7 votes vote down vote up
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onItemFrameDamage(final EntityDamageByEntityEvent e) {
    // Check world
    if (!inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) {
        return;
    }
    if (e.getDamager() instanceof Projectile) {
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Projectile damage to itemframe");
        // Find out who fired the arrow
        Projectile p = (Projectile) e.getDamager();
        if (DEBUG)
            plugin.getLogger().info("DEBUG: Shooter is " + p.getShooter().toString());
        if (p.getShooter() instanceof Skeleton || p.getShooter() instanceof Golem) {
            if (DEBUG)
                plugin.getLogger().info("DEBUG: Shooter is mob");
            if (!Settings.allowMobDamageToItemFrames) {
                if (DEBUG)
                    plugin.getLogger().info("DEBUG: Damage not allowed, cancelling");
                e.setCancelled(true);
            }
        }
    }
}
 
Example 2
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onDamage(final EntityDamageEvent event) {
  cancelUnlessInteracting(event, event.getEntity());
  if (event instanceof EntityDamageByEntityEvent) {
    EntityDamageByEntityEvent entityEvent = (EntityDamageByEntityEvent) event;
    if (cancelUnlessInteracting(event, entityEvent.getDamager())) {
      MatchPlayer player = match.getPlayer(entityEvent.getDamager());
      if (player == null) return;

      match.callEvent(
          new ObserverInteractEvent(
              player,
              ClickType.LEFT,
              null,
              event.getEntity(),
              player.getInventory().getItemInHand()));
    }
  }
}
 
Example 3
@EventHandler
public void onProjectileHurtEvent(EntityDamageByEntityEvent event) {
  if (!(event.getEntity() instanceof LivingEntity)) return;
  LivingEntity damagedEntity = (LivingEntity) event.getEntity();

  ProjectileDefinition projectileDefinition =
      ProjectileMatchModule.getProjectileDefinition(event.getDamager());

  if (projectileDefinition != null) {
    if (!projectileDefinition.potion.isEmpty()) {
      damagedEntity.addPotionEffects(projectileDefinition.potion);
    }

    if (projectileDefinition.damage != null) {
      event.setDamage(projectileDefinition.damage);
    }
  }
}
 
Example 4
Source Project: civcraft   Source File: Attack.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onAttack(EntityDamageByEntityEvent event, ItemStack inHand) {
	AttributeUtil attrs = new AttributeUtil(inHand);
	double dmg = this.getDouble("value");
			
	double extraAtt = 0.0;
	for (LoreEnhancement enh : attrs.getEnhancements()) {
		if (enh instanceof LoreEnhancementAttack) {
			extraAtt +=  ((LoreEnhancementAttack)enh).getExtraAttack(attrs);
		}
	}
	dmg += extraAtt;
	
	if (event.getDamager() instanceof Player) {
		Resident resident = CivGlobal.getResident(((Player)event.getDamager()));
		if (!resident.hasTechForItem(inHand)) {
			dmg = dmg / 2;
		}
	}
	
	if (dmg < 0.5) {
		dmg = 0.5;
	}
	
	event.setDamage(dmg);
}
 
Example 5
Source Project: ce   Source File: CEventHandler.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void handleBows(Player toCheck, EntityDamageByEntityEvent e) {
    if (e.getDamager().hasMetadata("ce.bow.item")) {
        Tools.getItemByOriginalname(e.getDamager().getMetadata("ce.bow.item").get(0).asString()).effect(e, toCheck);
        e.getDamager().removeMetadata("ce.bow.item", Main.plugin);
    }

    if (e.getDamager().hasMetadata("ce.bow.enchantment")) {
        String[] enchantments = e.getDamager().getMetadata("ce.bow.enchantment").get(0).asString().split(" ; ");
        for (String ench : enchantments) {
            String[] enchantment = ench.split(" : ");
            CEnchantment ce = EnchantManager.getInternalEnchantment(enchantment[0]);
            ce.effect(e, toCheck.getItemInHand(), Integer.parseInt(enchantment[1]));
        }
        e.getDamager().removeMetadata("ce.bow.enchantment", Main.plugin);
    }
}
 
Example 6
Source Project: ce   Source File: BountyHunter.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, final int level) {
	if(e instanceof EntityDamageByEntityEvent) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	Entity target = event.getEntity();
	
	if(!(target instanceof Player))
		return;
	
	Player p = (Player) ((Projectile) event.getDamager()).getShooter();
	
	Material bountyDrop = getBounty();
	
	for(int i = 10; i>0; i--) {
		p.getWorld().playEffect(p.getLocation(), Effect.COLOURED_DUST, 10);
		p.getWorld().playEffect(target.getLocation(), Effect.COLOURED_DUST, 10);
	}
	
	p.getInventory().addItem(new ItemStack(bountyDrop, Tools.random.nextInt(MaximumBounty+level)+1));
	p.sendMessage(ChatColor.GOLD + "You have collected a bounty on " + target.getName() + "!");
	this.generateCooldown(p, Cooldown);
	
	}
}
 
Example 7
Source Project: CombatLogX   Source File: NoEntryListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST)
public void onCancelPVP(EntityDamageByEntityEvent e) {
    if(!e.isCancelled()) return;
    if(this.expansion.getNoEntryHandler().getNoEntryMode() != NoEntryMode.VULNERABLE) return;

    Entity entity = e.getEntity();
    if(!(entity instanceof Player)) return;

    ICombatLogX plugin = this.expansion.getPlugin();
    ICombatManager manager = plugin.getCombatManager();

    Player player = (Player) entity;
    if(!manager.isInCombat(player)) return;

    LivingEntity enemy = manager.getEnemy(player);
    if(enemy == null) return;

    e.setCancelled(false);
    this.expansion.sendNoEntryMessage(player, enemy);
}
 
Example 8
Source Project: ce   Source File: HealingShovel.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean effect(Event event, Player player) {
    EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
    if (e.getDamager() == player && e.getEntity() instanceof Player) {
        Player damaged = (Player) e.getEntity();
        e.setDamage(0);
        EffectManager.playSound(damaged.getLocation(), "ENTITY_GENERIC_DRINK", 0.5f, 1f);
        EffectManager.playSound(damaged.getLocation(), "BLOCK_ANVIL_LAND", 0.5f, 2f);
        short currentDur = player.getItemInHand().getDurability();

        if (((Damageable) damaged).getHealth() + Heal <= ((Damageable) damaged).getMaxHealth()) {
            damaged.setHealth(((Damageable) damaged).getHealth() + Heal);
        } else {
            damaged.setHealth(((Damageable) damaged).getMaxHealth());
        }

        if (currentDur + Heal < player.getItemInHand().getType().getMaxDurability()) {
            player.getItemInHand().setDurability((short) (currentDur + Heal));
        } else {
            player.setItemInHand(new ItemStack(Material.AIR, 1));
            EffectManager.playSound(player.getLocation(), "ENTITY_ITEM_BREAK", 0.1f, 0.3f);
        }
        return true;
    }
    return false;
}
 
Example 9
Source Project: AnnihilationPro   Source File: Areas.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST,ignoreCancelled = true)
public void checkBreaks(EntityDamageByEntityEvent e)
{
	if(e.getDamager().getType() == EntityType.PLAYER && e.getEntity().getType() == EntityType.PLAYER)
	{
		Area a = this.getArea(new Loc(e.getDamager().getLocation(),false));
		if(a != null && !a.getAllowPVP())
		{
			e.setCancelled(true);
			return;
		}
		a = this.getArea(new Loc(e.getEntity().getLocation(),false));
		if(a != null && !a.getAllowPVP())
		{
			e.setCancelled(true);
			return;
		}
	}
}
 
Example 10
Source Project: BedwarsRel   Source File: EntityListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent ede) {
  List<EntityType> canDamageTypes = new ArrayList<EntityType>();
  canDamageTypes.add(EntityType.PLAYER);

  if (BedwarsRel.getInstance().getServer().getPluginManager().isPluginEnabled("AntiAura")
      || BedwarsRel.getInstance().getServer().getPluginManager().isPluginEnabled("AAC")) {
    canDamageTypes.add(EntityType.SQUID);
  }

  if (canDamageTypes.contains(ede.getEntityType())) {
    return;
  }

  Game game =
      BedwarsRel.getInstance().getGameManager().getGameByLocation(ede.getEntity().getLocation());
  if (game == null) {
    return;
  }

  if (game.getState() == GameState.STOPPED) {
    return;
  }

  ede.setCancelled(true);
}
 
Example 11
@EventHandler (priority = EventPriority.HIGHEST)
public void onDamage(EntityDamageByEntityEvent event){

    if (event.isCancelled()) return;
    if (!event.getEntity().getType().equals(EntityType.ENDERMAN)) return;
    EntityType entityType = EntityFinder.getRealDamager(event).getType();
    if (entityType == null) return;
    if (!entityType.equals(EntityType.PLAYER)) return;

    EliteMobEntity eliteMobEntity = EntityTracker.getEliteMobEntity(event.getEntity());
    if (eliteMobEntity == null) return;

    Block block = EntityFinder.getRealDamager(event).getLocation().getBlock().getLocation().add(new Vector(0, 2, 0)).getBlock();
    if (block.getType().equals(Material.AIR) || block.getType().equals(Material.WATER)) return;

    eliteMobEntity.setHasSpecialLoot(false);
    AntiExploitMessage.sendWarning((LivingEntity) event.getEntity());

}
 
Example 12
@EventHandler(priority = EventPriority.NORMAL)
public void onHit(EntityDamageByEntityEvent event) {
  final Entity damager = event.getDamager();
  if (!event.isCancelled()
      || event.getCause() != EntityDamageEvent.DamageCause.PROJECTILE
      || !(damager instanceof Projectile)
      || !damager.hasMetadata(METADATA_KEY)) return;

  final Player shooter = (Player) ((Projectile) damager).getShooter();
  if (match.getParticipant(shooter) == null) return;

  damager.remove();
  shooter.getInventory().addItem(new ItemStack(Material.ARROW));
}
 
Example 13
Source Project: CardinalPGM   Source File: Projectiles.java    License: MIT License 5 votes vote down vote up
@EventHandler
public void onEntityHitByProjectile(EntityDamageByEntityEvent event) {
    if (event.isCancelled()) return;
    if (event.getCause().equals(DamageCause.PROJECTILE)) {
        ProjectileSource source = ((Projectile) event.getDamager()).getShooter();
        if (source instanceof Player) {
            ((Player) source).playSound(((Player) source).getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.2F, 0.5F);
        }
        if (event.getDamager().getType().equals(projectile) && event.getDamager().hasMetadata("custom")) {
            Entity arrow = event.getEntity().getWorld().spawnEntity(event.getDamager().getLocation(), EntityType.ARROW);
            ((Projectile) arrow).setShooter(source);
            arrow.setVelocity(event.getDamager().getVelocity());
            event.getDamager().remove();
            if (event.getEntity() instanceof LivingEntity) {
                for (PotionEffect effect : potionEffects) {
                    ((LivingEntity) event.getEntity()).addPotionEffect(effect);
                }
                final Entity entity = event.getEntity();
                Bukkit.getServer().getScheduler().runTaskLater(GameHandler.getGameHandler().getPlugin(), new Runnable() {
                    @Override
                    public void run() {
                        ((LivingEntity) entity).setArrowsStuck(((LivingEntity) entity).getArrowsStuck() - 1);
                    }
                }, 0);
            }
        }
    }
}
 
Example 14
Source Project: uSkyBlock   Source File: GriefEvents.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onWitherSkullExplosion(EntityDamageByEntityEvent e) {
    if (!witherEnabled
            || !(e.getEntity() instanceof WitherSkull)
            || !plugin.getWorldManager().isSkyAssociatedWorld(e.getEntity().getWorld())) {
        return;
    }
    // Find owner
    ProjectileSource shooter = ((WitherSkull) e.getEntity()).getShooter();
    if (shooter instanceof Wither) {
        handleWitherRampage(e, (Wither) shooter, e.getDamager().getLocation());
    }
}
 
Example 15
@EventHandler
public void onArrowHitEntity(EntityDamageByEntityEvent e) {
    if (!isEnabled()) {
        return;
    }

    if (e.getDamager() instanceof Arrow) {
        handleGrapplingHook((Arrow) e.getDamager());
    }
}
 
Example 16
Source Project: ce   Source File: Frozen.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	LivingEntity target = (LivingEntity) event.getDamager();
	target.addPotionEffect(
			new PotionEffect(
					PotionEffectType.SLOW, 
					duration * level,
					strength + level));
}
 
Example 17
/**
 * Event constructor (used for the Armor-Effects as the Player and the Entity are the same)
 *
 * @param player     The Player
 * @param tool  The ItemStack (MUST be a MineTinker-Tool)
 * @param event The BlockBreakEvent from which it was called
 */
public MTEntityDamageByEntityEvent(@NotNull Player player, @NotNull ItemStack tool, @NotNull EntityDamageByEntityEvent event) {
	this.player = player;
	this.tool = tool;
	this.entity = event.getEntity();
	this.event = event;
	this.isBlocking = false;
}
 
Example 18
Source Project: TabooLib   Source File: Servers.java    License: MIT License 5 votes vote down vote up
public static Player getAttackerInDamageEvent(EntityDamageByEntityEvent e) {
    if (e.getDamager() instanceof Player) {
        return (Player) e.getDamager();
    } else if (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof Player) {
        return (Player) ((Projectile) e.getDamager()).getShooter();
    } else {
        return null;
    }
}
 
Example 19
Source Project: ce   Source File: Thunderingblow.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	Player damager = (Player) event.getDamager();
	Random random = new Random();
	int i = level;
	while(i != 0) {
		if(random.nextInt(100) < chance) {
			damager.getWorld().strikeLightning(
					event.getEntity().getLocation());
		}
		--i;
	}
}
 
Example 20
Source Project: EliteMobs   Source File: AttackWither.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {

    EliteMobEntity eliteMobEntity = EventValidator.getEventEliteMob(this, event);
    if (eliteMobEntity == null) return;
    Player player = EntityFinder.findPlayer(event);
    if (PowerCooldown.isInCooldown(eliteMobEntity, cooldownList)) return;
    player.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 50, 1));
    PowerCooldown.startCooldownTimer(eliteMobEntity, cooldownList, 10 * 20);

}
 
Example 21
Source Project: ce   Source File: Poisoned.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	LivingEntity target = (LivingEntity) event.getDamager();
		target.addPotionEffect(
			new PotionEffect(
					PotionEffectType.POISON, 
					duration * level, //This value is counted in ticks, 1/20 of a second
					strength + level));
}
 
Example 22
Source Project: Modern-LWC   Source File: LWCPlayerListener.java    License: MIT License 5 votes vote down vote up
@EventHandler
public void itemFrameItemRemoval(EntityDamageByEntityEvent e) {
    if (e.isCancelled())
        return;
    Entity entity = e.getEntity();
    if (plugin.getLWC().isProtectable(e.getEntity().getType())) {
        int A = 50000 + entity.getUniqueId().hashCode();
        LWC lwc = LWC.getInstance();
        Protection protection = lwc.getPhysicalDatabase().loadProtection(entity.getWorld().getName(), A, A, A);
        if (!(entity instanceof Player)) {
            if (e.getDamager() instanceof Projectile) {
                if (protection != null) {
                    e.setCancelled(true);
                }
                if ((((entity instanceof StorageMinecart)) || ((entity instanceof HopperMinecart)))
                        && (protection != null)) {
                    e.setCancelled(true);
                }
            }
            if (e.getDamager() instanceof Player) {
                Player p = (Player) e.getDamager();
                if (protection != null && !lwc.canAccessProtection(p, protection)) {
                    e.setCancelled(true);
                }
                if (p.hasPermission("lwc.lockentity." + e.getEntityType())
                        || p.hasPermission("lwc.lockentity.all")) {
                    if (onPlayerEntityInteract(p, entity, e.isCancelled())) {
                        e.setCancelled(true);
                    }
                }
                if ((((entity instanceof StorageMinecart)) || ((entity instanceof HopperMinecart)))
                        && (protection != null)) {
                    e.setCancelled(true);
                }
            }
        }
    }
}
 
Example 23
Source Project: helper   Source File: CitizensNpcFactory.java    License: MIT License 5 votes vote down vote up
private void init() {
    // create npc registry
    this.npcRegistry = CitizensAPI.createNamedNPCRegistry("helper", new MemoryNPCDataStore());

    // ensure our trait is registered
    registerTrait();

    // handle click events
    Events.merge(NPCClickEvent.class, NPCRightClickEvent.class, NPCLeftClickEvent.class)
            .handler(e -> handleClick(e.getNPC(), e.getClicker())).bindWith(this.registry);

    // don't let players move npcs
    Events.subscribe(PlayerFishEvent.class)
            .filter(e -> e.getCaught() != null)
            .filter(e -> e.getCaught().hasMetadata("NPC"))
            .handler(e -> e.setCancelled(true))
            .bindWith(this.registry);

    /* Events.subscribe(ProjectileCollideEvent.class)
            .filter(e -> e.getCollidedWith() != null)
            .filter(e -> e.getCollidedWith().hasMetadata("NPC"))
            .handler(e -> e.setCancelled(true))
            .bindWith(this.registry); */

    Events.subscribe(EntityDamageByEntityEvent.class)
            .filter(e -> e.getEntity().hasMetadata("NPC"))
            .handler(e -> e.setCancelled(true))
            .bindWith(this.registry);

    // update npcs every 10 ticks
    Schedulers.sync().runRepeating(this::tickNpcs, 10L, 10L).bindWith(this.registry);
}
 
Example 24
Source Project: Sentinel   Source File: SentinelTrait.java    License: MIT License 5 votes vote down vote up
/**
 * Called when this sentinel attacks something, to correct damage handling.
 */
public void whenAttacksAreHappeningFromMe(EntityDamageByEntityEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (!npc.isSpawned()) {
        return;
    }
    if (SentinelPlugin.instance.alternateDamage) {
        if (canEnforce) {
            canEnforce = false;
            whenAttacksHappened(event);
            if (!event.isCancelled()) {
                ((LivingEntity) event.getEntity()).damage(event.getFinalDamage());
                if (event.getEntity() instanceof LivingEntity) {
                    weaponHelper.knockback((LivingEntity) event.getEntity());
                }
            }
            if (SentinelPlugin.debugMe) {
                debug("enforce damage value to " + event.getFinalDamage());
            }
        }
        else {
            if (SentinelPlugin.debugMe) {
                debug("refuse damage enforcement");
            }
        }
        event.setDamage(0);
        event.setCancelled(true);
        return;
    }
    event.setDamage(EntityDamageEvent.DamageModifier.BASE, getDamage(false));
}
 
Example 25
Source Project: ce   Source File: Deepwounds.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	final Player damaged = (Player) event.getEntity();
	final Player damager = (Player) event.getDamager();
	if(!getHasCooldown(damager) && !damaged.hasMetadata("ce.bleed")) {

	Random random = new Random();
	if(random.nextInt(100) < rand) {
		generateCooldown(damager, 140);
		Tools.applyBleed(damaged, duration*level);
	}
	}
}
 
Example 26
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = false)
   public void onEntityDamage(final EntityDamageByEntityEvent e) {	
	if (SkyWarsReloaded.getCfg().protectLobby() && Util.get().isSpawnWorld(e.getEntity().getWorld())) {
		e.setCancelled(true);
   		if (e.getEntity() instanceof Player || e.getDamager() instanceof Player) {
       		if (((Player)e.getDamager()).hasPermission("sw.alterlobby")) {
       			e.setCancelled(false);
       		}
   		}
	}
}
 
Example 27
Source Project: AnnihilationPro   Source File: Assassin.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void damageHandler(EntityDamageByEntityEvent event) 
{
	if(event.getDamager().getType() == EntityType.PLAYER)
	{
		Player player = (Player)event.getDamager();
		AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
		if(p != null && p.getKit().equals(this) && p.getData("Cur") != null)
			endLeap(player,p);
	}
}
 
Example 28
Source Project: ce   Source File: Aerial.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void effect(Event e, ItemStack item, int level) {
	EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) e;
	Player player = (Player) event.getDamager();
	if(player.getVelocity().getY() == -0.0784000015258789) //Constant velocity for not moving in y direction (Gravity)
		return;
	
	event.setDamage(event.getDamage() * (1 + DamageIncreasePercentage * level));

	EffectManager.playSound(player.getLocation(), "ENTITY_BAT_TAKEOFF", 0.1f, 0.1f);
}
 
Example 29
@EventHandler
public void onDamageByPlayer(EntityDamageByEntityEvent event) {
    if (!(EntityFinder.getRealDamager(event) instanceof Player)) return;
    EliteMobEntity eliteMobEntity = EntityTracker.getEliteMobEntity(event.getEntity());
    if (eliteMobEntity == null) return;

    eliteMobEntity.setHasVisualEffectObfuscated(false);
    eliteMobEntity.getLivingEntity().setCustomNameVisible(true);
}
 
Example 30
default DamageInfo resolveDamage(EntityDamageEvent damageEvent) {
    if(damageEvent instanceof EntityDamageByEntityEvent) {
        return resolveDamage((EntityDamageByEntityEvent) damageEvent);
    } else if(damageEvent instanceof EntityDamageByBlockEvent) {
        return resolveDamage((EntityDamageByBlockEvent) damageEvent);
    } else {
        return resolveDamage(damageEvent.getCause(), damageEvent.getEntity());
    }
}