Java Code Examples for org.bukkit.event.entity.EntityDamageByEntityEvent#getDamager()

The following examples show how to use org.bukkit.event.entity.EntityDamageByEntityEvent#getDamager() . 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 File: IslandGuard.java    From askyblock with 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
Source File: PlayerDamageListener.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
private void handleArrow(EntityDamageByEntityEvent event){

		PlayersManager pm = GameManager.getGameManager().getPlayersManager();
		
		if(event.getEntity() instanceof Player && event.getDamager() instanceof Arrow){
			Projectile arrow = (Projectile) event.getDamager();
			final Player shot = (Player) event.getEntity();
			if(arrow.getShooter() instanceof Player){
				
				if(!GameManager.getGameManager().getPvp()){
					event.setCancelled(true);
					return;
				}

				UhcPlayer uhcDamager = pm.getUhcPlayer((Player) arrow.getShooter());
				UhcPlayer uhcDamaged = pm.getUhcPlayer(shot);

				if(!friendlyFire && uhcDamager.getState().equals(PlayerState.PLAYING) && uhcDamager.isInTeamWith(uhcDamaged)){
					uhcDamager.sendMessage(Lang.PLAYERS_FF_OFF);
					event.setCancelled(true);
				}
			}
		}
	}
 
Example 3
Source File: Pyro.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true)
public void damageListener(final EntityDamageByEntityEvent event)
{
	Entity one = event.getDamager();
	if(one.getType() == EntityType.PLAYER && event.getEntity().getType() == EntityType.PLAYER)
	{
		Player damager = (Player)one;
		AnniPlayer d = AnniPlayer.getPlayer(damager.getUniqueId());
		if(d != null && d.getKit().equals(this))
		{
			if(rand.nextInt(100) < 37)
				event.getEntity().setFireTicks(40);
		}
	}
}
 
Example 4
Source File: EntityListener.java    From Guilds with MIT License 5 votes vote down vote up
/**
 * Guild / Ally damage handlers
 *
 * @param event handles when damage is done between two players that might be in the same guild or are allies
 */
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
    if (!(event.getEntity() instanceof Player) || !(event.getDamager() instanceof Player)) return;
    Player player = (Player) event.getEntity();
    Player damager = (Player) event.getDamager();

    // Make sure that they aren't in a claim that turns off pvpv
    if (settingsManager.getProperty(GuildSettings.RESPECT_WG_PVP_FLAG)) {
        event.setCancelled(ClaimUtils.checkPvpDisabled(player));
        return;
    }

    // Check if they are the same guild
    if (guildHandler.isSameGuild(player, damager)) {
        event.setCancelled(!settingsManager.getProperty(GuildSettings.GUILD_DAMAGE));
        return;
    }

    // Get the challenge object
    GuildChallenge challenge = challengeHandler.getChallenge(player);

    // Check if they are in a challenge
    if (challenge != null) {
        // Check if the challenge has started
        if (challenge.isStarted()) {
            // Cancel the rest of the checks in case they are battling allies
            return;
        }
    }

    if (guildHandler.isAlly(player, damager)) {
        event.setCancelled(!settingsManager.getProperty(GuildSettings.ALLY_DAMAGE));
    }
}
 
Example 5
Source File: SwitcherooListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerDamage(EntityDamageByEntityEvent e){
    if (!(e.getEntity() instanceof Player)){
        return;
    }

    Player player = ((Player) e.getEntity()).getPlayer();

    if (!(e.getDamager() instanceof Arrow)){
        return;
    }

    Arrow arrow = (Arrow) e.getDamager();

    if (!(arrow.getShooter() instanceof  Player)){
        return;
    }

    Player shooter = ((Player) arrow.getShooter()).getPlayer();

    if (player.equals(shooter)){
        return;
    }

    arrow.remove();

    Location playerLoc = player.getLocation();
    Location shooterLoc = shooter.getLocation();

    player.teleport(shooterLoc);
    shooter.teleport(playerLoc);

    player.sendMessage(Lang.SCENARIO_SWITCHEROO_SWITCH.replace("%player%", shooter.getName()));
    shooter.sendMessage(Lang.SCENARIO_SWITCHEROO_SWITCH.replace("%player%", player.getName()));
}
 
Example 6
Source File: GriefEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onEntityDamage(EntityDamageByEntityEvent event) {
    if ((!killAnimalsEnabled && !killMonstersEnabled)
            || !plugin.getWorldManager().isSkyAssociatedWorld(event.getDamager().getWorld())) {
        return;
    }
    if (!(event.getEntity() instanceof Creature)) {
        return;
    }
    if (event.getDamager() instanceof Player
            && !plugin.playerIsOnIsland((Player)event.getDamager())) {
        if (event.getDamager().hasPermission("usb.mod.bypassprotection")) {
            return;
        }
        cancelMobDamage(event);
    } else if (event.getDamager() instanceof Projectile) {
        ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter();
        if (!(shooter instanceof Player)) {
            return;
        }
        Player player = (Player) shooter;
        if (player.hasPermission("usb.mod.bypassprotection") || plugin.playerIsOnIsland(player)) {
            return;
        }
        cancelMobDamage(event);
    }
}
 
Example 7
Source File: LoveAtFirstSightListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler (priority = EventPriority.LOW)
public void onPlayerDamage(EntityDamageByEntityEvent e){
    if (e.getEntityType() != EntityType.PLAYER || !(e.getDamager() instanceof Player)){
        return;
    }

    PlayersManager pm = getPlayersManager();
    UhcPlayer uhcDamaged = pm.getUhcPlayer((Player) e.getEntity());
    UhcPlayer uhcDamager = pm.getUhcPlayer((Player) e.getDamager());

    if (getGameManager().getGameState() != GameState.PLAYING){
        return;
    }

    if (uhcDamaged.getTeam().isFull() || uhcDamager.getTeam().isFull()){
        return; // One of the teams is full so no team can be made
    }

    if (!uhcDamaged.getTeam().isSolo() && !uhcDamager.getTeam().isSolo()){
        return; // Neither of the players are solo so a team can't be created
    }

    if (getTeamManager().getPlayingUhcTeams().size() <= 2){
        return; // Only 2 teams left, don't team them up but let them first.
    }

    boolean result;
    if (uhcDamaged.getTeam().isSolo()){
        // add to damager team
        result = addPlayerToTeam(uhcDamaged, uhcDamager.getTeam());
    }else{
        // add damager to damaged
        result = addPlayerToTeam(uhcDamager, uhcDamaged.getTeam());
    }

    if (result){
        e.setCancelled(true);
    }
}
 
Example 8
Source File: KnockbackPlayerFacet.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@TargetedEventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMelee(EntityDamageByEntityEvent event) {
    if(knockback.isPresent() &&
       victim.equals(event.getEntity()) &&
       event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK &&
       event.getDamager() instanceof LivingEntity &&
       victim.getNoDamageTicks() <= 0) {

        applyImpulses((LivingEntity) event.getDamager());
    }
}
 
Example 9
Source File: ObserverModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onEntityAttack(EntityDamageByEntityEvent event) {
    if (event.getDamager() instanceof Player) {
        if (testObserverOrDead((Player) event.getDamager())) {
            event.setCancelled(true);
        }
    }
}
 
Example 10
Source File: Revulsion.java    From ce with 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.CONFUSION,
					duration * level, //This value is counted in ticks, 1/20 of a second
					0));
}
 
Example 11
Source File: Deepwounds.java    From ce with 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 12
Source File: ExhibitionListener.java    From NyaaUtils with MIT License 5 votes vote down vote up
@EventHandler(priority = HIGHEST, ignoreCancelled = true)
public void onPlayerHitItemFrame(EntityDamageByEntityEvent ev) {
    if (!(ev.getEntity() instanceof ItemFrame)) return;
    ItemFrame f = (ItemFrame) ev.getEntity();
    if (f.getItem() == null || f.getItem().getType() == Material.AIR) return;
    if (ExhibitionFrame.fromItemFrame(f).isSet()) {
        ev.setCancelled(true);
        if (ev.getDamager() instanceof Player) {
            ev.getDamager().sendMessage(I18n.format("user.exhibition.frame_protected"));
        }
    }
}
 
Example 13
Source File: ArmorStandListener.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Listener used to generate the ArmorStandDamageEvent.
 *
 * @param evt The initial EntityDamageByEntityEvent event
 *            used to generate the ArmorStandDamageEvent
 */
@EventHandler
public void onArmorStandDamage(EntityDamageByEntityEvent evt) {
    if (evt.getEntity().getType().equals(EntityType.ARMOR_STAND)
            && evt.getDamager().getType().equals(EntityType.PLAYER)) {
        ArmorStandDamageEvent event =
                new ArmorStandDamageEvent((Player) evt.getDamager(), evt.getEntity());
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            evt.setCancelled(true);
            return;
        }
    }
}
 
Example 14
Source File: FriendlyFire.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onEntityDamageEvent(EntityDamageByEntityEvent event) {
    if (!enabled) return;
    if (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() == event.getEntity()){
        event.setCancelled(true);
    }
}
 
Example 15
Source File: Rage.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if (event.getDamager() instanceof Player) {
        ItemStack item = ((Player) event.getDamager()).getItemInHand();
        if (item != null) {
            if (item.containsEnchantment(Enchantment.DAMAGE_ALL) && item.getEnchantmentLevel(Enchantment.DAMAGE_ALL) > 1) {
                event.setDamage(1000);
            }
        }
    } else if (event.getDamager() instanceof Arrow) {
        if (event.getDamager().hasMetadata("rage")) {
            event.setDamage(1000);
        }
    }
}
 
Example 16
Source File: FriendlyFireRefundMatchModule.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@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 17
Source File: BukkitImageListener.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if(!(event.getDamager() instanceof Player)) return;
    handleInteract(event, (Player) event.getDamager(), event.getEntity(), false);
}
 
Example 18
Source File: RocketGizmo.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler
public void entityDamage(final EntityDamageEvent event) {
    if(!(event instanceof EntityDamageByEntityEvent)) return;
    EntityDamageByEntityEvent realEvent = (EntityDamageByEntityEvent) event;
    if(!(realEvent.getDamager() instanceof Player) || !(realEvent.getEntity() instanceof Player)) return;

    final Player damager = (Player) realEvent.getDamager();
    final Player victim = (Player) realEvent.getEntity();

    if(victim.hasPermission(GizmoConfig.EXEMPT_PERMISSION)) return;

    if(!(Gizmos.gizmoMap.get(damager) instanceof RocketGizmo)) return;
    if(damager.getItemInHand().getType() != this.getIcon()) return;

    boolean cancel = false;
    for(Rocket rocket : this.rockets) {
        if(rocket.getObserver().equals(damager) && rocket.getVictim().equals(victim)) {
            cancel = true;
            break;
        }
    }
    if(cancel) return;

    List<Firework> fireworks = Lists.newArrayList();
    for(int i = 0; i < GizmoConfig.FIREWORK_COUNT; i++) {
        Firework firework = RocketUtils.getRandomFirework(victim.getLocation());
        firework.setVelocity(firework.getVelocity().multiply(new Vector(1, GizmoConfig.ROCKET_VELOCITY_MOD, 1)));
        fireworks.add(firework);
    }

    this.rockets.add(new Rocket(damager, victim, fireworks));

    RocketUtils.fakeDelta(damager, victim, new Vector(0, 3, 0));
    RocketUtils.takeOff(damager, victim.getLocation());

    Integer count = rocketedCount.get(damager);
    if(count == null) count = 0;

    count++;
    rocketedCount.put(damager, count);

    if(count % 10 == 0) {
        RaindropUtil.giveRaindrops(
            Users.playerId(damager), 1, null,
            new TranslatableComponent("gizmo.rocket.raindropsResult", new Component(String.valueOf(count), net.md_5.bungee.api.ChatColor.GOLD))
        );
    }

    event.setCancelled(true);
}
 
Example 19
Source File: ModifyBowProjectileMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void fixEntityDamage(EntityDamageByEntityEvent event) {
  Entity projectile = event.getDamager();
  if (projectile.hasMetadata("customProjectile")) {

    // If the custom projectile replaced an arrow, recreate some effects specific to arrows
    if (projectile.hasMetadata("damage")) {
      boolean critical = projectile.getMetadata("critical").get(0).asBoolean();
      int knockback = projectile.getMetadata("knockback").get(0).asInt();
      double damage = projectile.getMetadata("damage").get(0).asDouble();
      double speed = projectile.getVelocity().length();

      // Reproduce the damage calculation from nms.EntityArrow with the addition of our modifier
      int finalDamage = (int) Math.ceil(speed * damage * this.velocityMod);
      if (critical) {
        finalDamage += match.getRandom().nextInt(finalDamage / 2 + 2);
      }
      event.setDamage(finalDamage);

      // Flame arrows - target burns for 5 seconds always
      if (projectile.getFireTicks() > 0) {
        event.getEntity().setFireTicks(100);
      }

      // Reproduce the knockback calculation for punch bows
      if (knockback > 0) {
        Vector projectileVelocity = projectile.getVelocity();
        double horizontalSpeed =
            Math.sqrt(
                projectileVelocity.getX() * projectileVelocity.getX()
                    + projectileVelocity.getZ() * projectileVelocity.getZ());
        Vector velocity = event.getEntity().getVelocity();
        velocity.setX(
            velocity.getX() + projectileVelocity.getX() * knockback * 0.6 / horizontalSpeed);
        velocity.setY(velocity.getY() + 0.1);
        velocity.setZ(
            velocity.getZ() + projectileVelocity.getZ() * knockback * 0.6 / horizontalSpeed);
        event.getEntity().setVelocity(velocity);
      }

      // If the projectile is not an arrow, play an impact sound.
      if (event.getEntity() instanceof Player
          && (projectile instanceof Projectile && !(projectile instanceof Arrow))) {
        Projectile customProjectile = (Projectile) projectile;
        if (customProjectile.getShooter() instanceof Player) {
          Player bukkitShooter = (Player) customProjectile.getShooter();
          MatchPlayer shooter = match.getPlayer(bukkitShooter);
          if (shooter != null && event.getEntity() != null) {
            shooter.playSound(PROJECTILE_SOUND);
          }
        }
      }
    }

    // Apply any potion effects attached to the projectile
    if (event.getEntity() instanceof LivingEntity) {
      for (PotionEffect potionEffect : this.potionEffects) {
        ((LivingEntity) event.getEntity()).addPotionEffect(potionEffect);
      }
    }
  }
}
 
Example 20
Source File: TreasureGoblin.java    From EliteMobs with GNU General Public License v3.0 3 votes vote down vote up
@EventHandler
public void onHit(EntityDamageByEntityEvent event) {

    if (!(event.getDamager().getType().equals(EntityType.ZOMBIE) ||
            event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Zombie))
        return;

    if (ThreadLocalRandom.current().nextDouble() > 0.5) return;

    LivingEntity livingEntity;

    if (event.getDamager() instanceof Projectile)
        livingEntity = (LivingEntity) ((Projectile) event.getDamager()).getShooter();
    else
        livingEntity = (LivingEntity) event.getDamager();

    EliteMobEntity eliteMobEntity = getTreasureGoblin((Zombie) livingEntity);
    if (eliteMobEntity == null) return;

    if (!PowerCooldown.isInCooldown(eliteMobEntity, radialGoldExplosionCooldown)) {

        PowerCooldown.startCooldownTimer(eliteMobEntity, radialGoldExplosionCooldown,
                20 * ConfigValues.eventsConfig.getInt(EventsConfig.TREASURE_GOBLIN_RADIAL_EXPLOSION));
        radialGoldExplosionInitializer((Zombie) event.getDamager());

    } else if (!PowerCooldown.isInCooldown(eliteMobEntity, goldShotgunCooldown)) {

        PowerCooldown.startCooldownTimer(eliteMobEntity, goldShotgunCooldown,
                20 * ConfigValues.eventsConfig.getInt(EventsConfig.TREASURE_GOBLIN_GOLD_SHOTGUN_INTERVAL));
        goldShotgunInitializer((Zombie) event.getDamager(), livingEntity.getLocation());

    }

}