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

The following examples show how to use org.bukkit.event.entity.EntityDamageEvent. 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 want to check out the right sidebar which shows the related API usage.
Example 1
@EventHandler
public void onDamage(EntityDamageEvent event) {
    if (event.isCancelled() || !(event.getEntity() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getEntity();

    if (!Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();

    if (gPlayer.isSpectator) {
        return;
    }

    WarpPowder warpPowder = (WarpPowder) game.getFirstActivedSpecialItemOfPlayer(player, WarpPowder.class);
    if (warpPowder != null) {
        warpPowder.cancelTeleport(true, true);
    }
}
 
Example 2
@EventHandler
public void onDamage(EntityDamageEvent event) {
    if (event.isCancelled() || !(event.getEntity() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getEntity();
    if (Main.isPlayerInGame(player)) {
        ItemStack boots = player.getInventory().getBoots();
        if (boots != null) {
            String magnetShoes = APIUtils.unhashFromInvisibleStringStartsWith(boots, MAGNET_SHOES_PREFIX);
            if (magnetShoes != null) {
                int probability = Integer.parseInt(magnetShoes.split(":")[2]);
                int randInt = MiscUtils.randInt(0, 100);
                if (randInt <= probability) {
                    event.setCancelled(true);
                    player.damage(event.getDamage());
                }
            }
        }
    }
}
 
Example 3
@EventHandler
public void onEntityDamageEvent(EntityDamageEvent event) {
    final Entity damagee = event.getEntity();
    if (!(damagee instanceof Player)) return;
    final Player player = (Player) damagee;
    final User user = User.getUser(player);
    final Location damageeLocation = damagee.getLocation();
    final IslandManager islandManager = IridiumSkyblock.getIslandManager();
    final Island island = islandManager.getIslandViaLocation(damageeLocation);
    if (island == null) return;

    //The user is visiting this island, so disable damage
    if (user.islandID != island.getId() && IridiumSkyblock.getConfiguration().disablePvPOnIslands) {
        event.setCancelled(true);
    }

}
 
Example 4
Source Project: PGM   Source File: SpawnMatchModule.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false)
public void teleportObservers(final EntityDamageEvent event) {
  // when an observer begins to take fall damage, teleport them to their spawn
  if (event.getEntity() instanceof Player
      && event.getCause() == EntityDamageEvent.DamageCause.VOID) {
    MatchPlayer player = match.getPlayer(event.getEntity());
    if (player != null && player.isObserving()) {
      Spawn spawn = chooseSpawn(player);
      if (spawn != null) {
        Location location = spawn.getSpawn(player);
        if (location != null) {
          player.getBukkit().teleport(location);
        }
      }
    }
  }
}
 
Example 5
Source Project: AdditionsAPI   Source File: EntityDamage.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent event) {
	if (event.isCancelled())
		return;

	DamageCause cause = event.getCause();
	Entity damagee = event.getEntity();
	EntityType damageeType = damagee.getType();
	// PlayerCustomArmorDamageEvent
	if (damageeType == EntityType.PLAYER) {
		Player player = (Player) damagee;
		PlayerInventory inv = player.getInventory();
		for (ItemStack armor : inv.getArmorContents())
			// TODO: Speed up
			if (armor != null && armor.getType() != Material.AIR && AdditionsAPI.isCustomItem(armor)
					&& new CustomItemStack(armor).getCustomItem() instanceof CustomArmor
					&& new CustomItemStack(armor).getCustomItem()
							.getDurabilityMechanics() instanceof ArmorDurability) {
				CustomArmor cArmor = (CustomArmor) new CustomItemStack(armor).getCustomItem();
				Bukkit.getServer().getPluginManager().callEvent(new PlayerCustomArmorDamageEvent(player, armor,
						cArmor, cause, (float) event.getDamage(), armor.containsEnchantment(Enchantment.THORNS)));
			}
	}
}
 
Example 6
Source Project: Sentinel   Source File: SentinelTrait.java    License: MIT License 6 votes vote down vote up
/**
 * Called when this sentinel gets attacked, to correct the armor handling.
 */
public void whenAttacksAreHappeningToMe(EntityDamageByEntityEvent event) {
    if (event.isCancelled()) {
        return;
    }
    if (!getNPC().isSpawned()) {
        return;
    }
    double armorLevel = getArmor(getLivingEntity());
    if (hitIsBlocked(event.getDamager())) {
        armorLevel = (1.0 - armorLevel) * 0.5 + armorLevel;
    }
    if (!event.isApplicable(EntityDamageEvent.DamageModifier.ARMOR)) {
        event.setDamage(EntityDamageEvent.DamageModifier.BASE, (1.0 - armorLevel) * event.getDamage(EntityDamageEvent.DamageModifier.BASE));
    }
    else {
        event.setDamage(EntityDamageEvent.DamageModifier.ARMOR, -armorLevel * event.getDamage(EntityDamageEvent.DamageModifier.BASE));
    }
    for (EntityDamageEvent.DamageModifier modifier : modifiersToZero) {
        if (event.isApplicable(modifier)) {
            event.setDamage(modifier, 0);
        }
    }
}
 
Example 7
Source Project: Sentinel   Source File: SentinelTrait.java    License: MIT License 6 votes vote down vote up
/**
 * Called when this sentinel gets hurt.
 */
public void whenImHurt(EntityDamageEvent event) {
    if (SentinelPlugin.debugMe) {
        debug("I'm hurt! By " + event.getCause().name() + " for " + event.getFinalDamage() + " hp");
    }
    switch (event.getCause()) {
        case FIRE:
        case FIRE_TICK:
        case LAVA:
        case MELTING:
            if (ticksSinceLastBurn <= 20) {
                event.setDamage(0);
                event.setCancelled(true);
                return;
            }
            ticksSinceLastBurn = 0;
            break;
    }
}
 
Example 8
@EventHandler
public void invulnerabilityKnockback(EntityDamageEvent event) {

    if (EntityTracker.hasPower(this, event.getEntity())) {

        event.getEntity().setVelocity(new Vector(0, 0, 0));

        new BukkitRunnable() {
            @Override
            public void run() {
                event.getEntity().setVelocity(new Vector(0, 0, 0));
            }
        }.runTaskLater(MetadataHandler.PLUGIN, 1);

    }

}
 
Example 9
Source Project: Skript   Source File: ExprAttacked.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
	if (!ScriptLoader.isCurrentEvent(EntityDamageEvent.class, EntityDeathEvent.class, VehicleDamageEvent.class, VehicleDestroyEvent.class)) {
		Skript.error("The expression 'victim' can only be used in a damage or death event", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	final String type = parser.regexes.size() == 0 ? null : parser.regexes.get(0).group();
	if (type == null) {
		this.type = EntityData.fromClass(Entity.class);
	} else {
		final EntityData<?> t = EntityData.parse(type);
		if (t == null) {
			Skript.error("'" + type + "' is not an entity type", ErrorQuality.NOT_AN_EXPRESSION);
			return false;
		}
		this.type = t;
	}
	return true;
}
 
Example 10
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
	if (((event.getCause() == DamageCause.FIRE_TICK) || (event.getCause() == DamageCause.FIRE) || (event.getCause() == DamageCause.DROWNING))) {
		for (Player player : ServerPlatform.get().getMiscUtils().getNearbyPlayers(event.getEntity().getLocation(), 48, 128, 48)) {
			if (player != null) {
				Connection connection = ProtocolSupportAPI.getConnection(player);
				if (
					(connection != null) &&
					(connection.getVersion().getProtocolType() == ProtocolType.PC) &&
					connection.getVersion().isBefore(ProtocolVersion.MINECRAFT_1_12)
				) {
					connection.sendPacket(ServerPlatform.get().getPacketFactory().createEntityStatusPacket(event.getEntity(), 2));
				}
			}
		}
	}
}
 
Example 11
@EventHandler
public void onDamageReceived(EntityDamageEvent event) {
    if(event.getEntity() instanceof LivingEntity){
        if(StackTools.hasValidStackData(event.getEntity())){
            LivingEntity entity = (LivingEntity) event.getEntity();
            if(sm.getCustomConfig().getBoolean("kill-step-damage.enabled")){
                double healthAfter = entity.getHealth() - event.getFinalDamage();
                if(healthAfter <= 0){
                    entity.setMetadata(GlobalValues.LEFTOVER_DAMAGE, new FixedMetadataValue(sm, Math.abs(healthAfter)));
                }
            }

            if(!sm.getCustomConfig().getStringList("multiply-damage-received.cause-blacklist")
                    .contains(event.getCause().toString())) {
                if(event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK){
                    return;
                }
                int stackSize = StackTools.getSize(entity);
                double extraDamage = event.getDamage() + ((event.getDamage() * (stackSize - 1) * 0.25));
                event.setDamage(extraDamage);
            }
        }
    }
}
 
Example 12
Source Project: MineTinker   Source File: ArmorListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void expCalculation(boolean isBlocking, ItemStack tool, EntityDamageEvent event, Player player) {
	//Armor should not get Exp when successfully blocking
	if(isBlocking && !ToolType.SHIELD.contains(tool.getType()) && ToolType.ARMOR.contains(tool.getType())) return;
	//Shield should not get Exp when not successfully blocking when getting attacked
	if(!isBlocking && player.equals(event.getEntity()) && ToolType.SHIELD.contains(tool.getType())) return;
	FileConfiguration config = MineTinker.getPlugin().getConfig();
	int amount = config.getInt("ExpPerEntityHit");

	if (config.getBoolean("EnableDamageExp")) {
		amount = (int) Math.round(event.getDamage());
	}

	if (config.getBoolean("DisableExpFromFalldamage", false)
			&& event.getCause() == EntityDamageEvent.DamageCause.FALL) {
		return;
	}

	modManager.addExp(player, tool, amount);
}
 
Example 13
@EventHandler(ignoreCancelled = true)
public void onTarget(EntityTargetEvent event) {
    if(!(event.getEntity() instanceof ExperienceOrb)) {
        ParticipantState victimState = null;
        if(event.getTarget() instanceof Player) {
            // Don't target allies
            MatchPlayer victim = getVictim(event.getTarget());
            if(victim == null) return;
            victimState = victim.getParticipantState();
        } else if(event.getTarget() != null) {
            // Don't target other mobs owned by allies
            victimState = entityResolver.getOwner(event.getTarget());
        }
        if(victimState == null) return;
        DamageInfo damageInfo = damageResolver.resolveDamage(EntityDamageEvent.DamageCause.ENTITY_ATTACK, event.getTarget(), event.getEntity());
        if(queryHostile(event, victimState, damageInfo).isDenied()) {
            event.setCancelled(true);
        }
    }
}
 
Example 14
Source Project: Skript   Source File: EvtDamage.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
	private static boolean checkDamage(final EntityDamageEvent e) {
		if (!(e.getEntity() instanceof LivingEntity))
			return true;
		final LivingEntity en = (LivingEntity) e.getEntity();
		if (HealthUtils.getHealth(en) <= 0)
			return false;
//		if (en.getNoDamageTicks() <= en.getMaximumNoDamageTicks() / 2) {
//			lastDamages.put(en, e.getDamage());
//			return true;
//		}
//		final Integer lastDamage = lastDamages.get(en);
//		if (lastDamage != null && lastDamage >= e.getDamage())
//			return false;
//		lastDamages.put(en, e.getDamage());
		return true;
	}
 
Example 15
@EventHandler
public void onDamage(EntityDamageEvent event) {
    if (event.isCancelled() || !(event.getEntity() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getEntity();

    if (!Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();

    if (gPlayer.isSpectator) {
        return;
    }

    WarpPowder warpPowder = (WarpPowder) game.getFirstActivedSpecialItemOfPlayer(player, WarpPowder.class);
    if (warpPowder != null) {
        warpPowder.cancelTeleport(true, true);
    }
}
 
Example 16
@EventHandler(priority = EventPriority.HIGH)
public void onDamage(EntityDamageEvent event) {
    Entity entity = event.getEntity();
    if (!(entity instanceof Player)) {
        return;
    }

    Player player = ((Player) entity).getPlayer();

    if (!Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();

    if (gPlayer.isSpectator) {
        return;
    }

    ArrowBlocker arrowBlocker = (ArrowBlocker) game.getFirstActivedSpecialItemOfPlayer(player, ArrowBlocker.class);
    if (arrowBlocker != null && event.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) {
        event.setCancelled(true);
    }
}
 
Example 17
@EventHandler
public void onFallDamage(EntityDamageEvent event) {
    Entity entity = event.getEntity();
    if (event.isCancelled() || !(entity instanceof Player)) {
        return;
    }

    Player player = ((Player) entity).getPlayer();
    if (!Main.isPlayerInGame(player)) {
        return;
    }

    GamePlayer gPlayer = Main.getPlayerGameProfile(player);
    Game game = gPlayer.getGame();
    if (gPlayer.isSpectator) {
        return;
    }

    RescuePlatform rescuePlatform = (RescuePlatform) game.getFirstActivedSpecialItemOfPlayer(player, RescuePlatform.class);
    if (rescuePlatform != null && event.getCause() == EntityDamageEvent.DamageCause.FALL) {
        Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
        if (block != null) {
            if (block.getType() == rescuePlatform.getMaterial()) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 18
Source Project: Skript   Source File: ExprLastDamageCause.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected DamageCause[] get(final Event e, final LivingEntity[] source) {
	return get(source, new Getter<DamageCause, LivingEntity>() {
		@SuppressWarnings("null")
		@Override
		public DamageCause get(final LivingEntity entity) {
			EntityDamageEvent dmgEvt = entity.getLastDamageCause();
			if (dmgEvt == null) return DamageCause.CUSTOM;
			return dmgEvt.getCause();
		}
	});
}
 
Example 19
Source Project: Skript   Source File: ExprFinalDamage.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
protected Double[] get(final Event e) {
	if (!(e instanceof EntityDamageEvent))
		return new Double[0];
	return new Double[] {HealthUtils.getFinalDamage((EntityDamageEvent) e)};
}
 
Example 20
Source Project: PGM   Source File: SpawnMatchModule.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerDamage(final EntityDamageEvent event) {
  MatchPlayer player = getMatch().getPlayer(event.getEntity());
  if (player != null) {
    State state = states.get(player);
    if (state != null) state.onEvent(event);
  }
}
 
Example 21
@EventHandler
public void onPotionLinger(final AreaEffectCloudApplyEvent event) {
    final AreaEffectCloud cloud = event.getEntity();
    if(PotionClassification.classify(cloud) != PotionClassification.HARMFUL) return;

    for(Iterator<LivingEntity> iterator = event.getAffectedEntities().iterator(); iterator.hasNext(); ) {
        final LivingEntity victim = iterator.next();
        final ParticipantState victimState = getMatch().getParticipantState(victim);
        final DamageInfo damageInfo = damageResolver.resolveDamage(EntityDamageEvent.DamageCause.MAGIC, victim, cloud);

        if(victimState != null && queryDamage(event, victimState, damageInfo).isDenied()) {
            iterator.remove();
        }
    }
}
 
Example 22
void onEvent(EntityDamageEvent event) {
  if (event.getFinalDamage() > 0) {
    // Absorbed damage is applied to the shield before any potion effect
    double shieldDamage = -event.getDamage(EntityDamageEvent.DamageModifier.ABSORPTION);
    logger.fine(
        "Absorbing damage with shield: shield=" + shieldHealth + " shieldDamage=" + shieldDamage);
    shieldHealth = Math.max(0, shieldHealth - shieldDamage);

    damage();
  }
}
 
Example 23
Source Project: AnnihilationPro   Source File: InvisibilityListeners.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void playerDamageChecker(final EntityDamageEvent event)
{
	if(event.getEntityType() == EntityType.PLAYER)
	{
		Player player = (Player)event.getEntity();
		AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
		if(p != null)
			checkInvis(player);
	}
}
 
Example 24
Source Project: EchoPet   Source File: PetOwnerListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerDamage(EntityDamageEvent event) {
    if (event.getEntity() instanceof Player) {
        Player p = (Player) event.getEntity();
        if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
            IPet pet = EchoPet.getManager().getPet(p);
            if (pet != null && pet.isOwnerRiding()) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example 25
Source Project: PGM   Source File: Uncarried.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onEvent(EntityDamageEvent event) {
  super.onEvent(event);

  if (event.getEntity() == this.labelEntity) {
    event.setCancelled(true);

    if (event instanceof EntityDamageByEntityEvent
        && ((EntityDamageByEntityEvent) event).getDamager() instanceof Projectile) {
      ((EntityDamageByEntityEvent) event).getDamager().remove();
    }
  }
}
 
Example 26
Source Project: PGM   Source File: DamageMatchModule.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onIgnition(EntityCombustByEntityEvent event) {
  MatchPlayer victim = getVictim(event.getEntity());
  if (victim == null) return;

  processDamageEvent(
      event,
      victim.getParticipantState(),
      tracker()
          .resolveDamage(
              EntityDamageEvent.DamageCause.FIRE, event.getEntity(), event.getCombuster()));
}
 
Example 27
Source Project: BetonQuest   Source File: MenuConvIO.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void entityDamageByEntityEvent(EntityDamageByEntityEvent event) {
    if (event.getDamager() != player) {
        return;
    }

    event.setCancelled(true);

    if (debounce) {
        return;
    }

    if (event.getCause().equals(EntityDamageEvent.DamageCause.ENTITY_ATTACK)) {

        if (controls.containsKey(CONTROL.LEFT_CLICK)) {

            switch (controls.get(CONTROL.LEFT_CLICK)) {
                case CANCEL:
                    if (!conv.isMovementBlock()) {
                        conv.endConversation();
                    }
                    debounce = true;
                    break;
                case SELECT:
                    conv.passPlayerAnswer(selectedOption + 1);
                    debounce = true;
                    break;
            case MOVE:
                break;
            default:
                break;
            }
        }
    }

}
 
Example 28
@Override
public @Nullable ExplosionInfo resolveDamage(
    EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
  switch (damageType) {
    case ENTITY_EXPLOSION:
    case BLOCK_EXPLOSION:
      // Bukkit fires block explosion events with a null damager in rare situations
      return damager == null ? null : new ExplosionInfo(damager);

    default:
      return null;
  }
}
 
Example 29
@Override
public @Nullable PotionInfo resolveDamage(
    EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
  PotionEffectType effect;
  switch (damageType) {
    case POISON:
      effect = PotionEffectType.POISON;
      break;
    case WITHER:
      effect = PotionEffectType.WITHER;
      break;
    case MAGIC:
      effect = null;
      break;
    default:
      return null;
  }

  // If potion is already resolved (i.e. as a splash potion), leave it alone
  if (damager instanceof PotionInfo
      || damager instanceof ProjectileInfo
          && ((ProjectileInfo) damager).getProjectile() instanceof PotionInfo) {
    return null;
  }

  return new GenericPotionInfo(effect);
}
 
Example 30
Source Project: Slimefun4   Source File: TalismanListener.java    License: GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onDamageGet(EntityDamageEvent e) {
    if (e.getEntity() instanceof Player) {
        if (e.getCause() == DamageCause.LAVA) {
            Talisman.checkFor(e, SlimefunItems.TALISMAN_LAVA);
        }

        if (e.getCause() == DamageCause.DROWNING) {
            Talisman.checkFor(e, SlimefunItems.TALISMAN_WATER);
        }

        if (e.getCause() == DamageCause.FALL) {
            Talisman.checkFor(e, SlimefunItems.TALISMAN_ANGEL);
        }

        if (e.getCause() == DamageCause.FIRE) {
            Talisman.checkFor(e, SlimefunItems.TALISMAN_FIRE);
        }

        if (e.getCause() == DamageCause.ENTITY_ATTACK) {
            Talisman.checkFor(e, SlimefunItems.TALISMAN_KNIGHT);
            Talisman.checkFor(e, SlimefunItems.TALISMAN_WARRIOR);
        }

        if (e.getCause() == DamageCause.PROJECTILE && ((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) {
            Projectile projectile = (Projectile) ((EntityDamageByEntityEvent) e).getDamager();

            if (Talisman.checkFor(e, SlimefunItems.TALISMAN_WHIRLWIND)) {
                returnProjectile((Player) e.getEntity(), projectile);
            }
        }
    }
}
 
Example 31
Source Project: AnnihilationPro   Source File: Scout.java    License: MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void fallDamage(EntityDamageEvent event)
{
	if(event.getEntity().getType() == EntityType.PLAYER && event.getCause() == DamageCause.FALL)
	{
		Player p = (Player)event.getEntity();
		AnniPlayer pl = AnniPlayer.getPlayer(p.getUniqueId());
		if(pl != null && pl.getKit().equals(this))
		{
			event.setDamage(event.getDamage()/2);
		}
	}
}
 
Example 32
Source Project: PGM   Source File: CombatLogTracker.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private ImminentDeath(
    EntityDamageEvent.DamageCause cause,
    Location deathLocation,
    @Nullable Block blockDamager,
    boolean damaged) {
  this.cause = cause;
  this.deathLocation = deathLocation;
  this.blockDamager = blockDamager;
  this.alreadyDamaged = damaged;
}
 
Example 33
Source Project: civcraft   Source File: MobListener.java    License: GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityDamage(EntityDamageEvent event) {
	if (!(event.getEntity() instanceof LivingEntity)) {
		return;
	}
	
	if (!MobLib.isMobLibEntity((LivingEntity) event.getEntity())) {
		return;
	}
	
	switch (event.getCause()) {
	case SUFFOCATION:
		Location loc = event.getEntity().getLocation();
		int y = loc.getWorld().getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()).getY()+4;
		loc.setY(y);
		event.getEntity().teleport(loc);
	case CONTACT:
	case FALL:
	case FIRE:
	case FIRE_TICK:
	case LAVA:
	case MELTING:
	case DROWNING:
	case FALLING_BLOCK:
	case BLOCK_EXPLOSION:
	case ENTITY_EXPLOSION:
	case LIGHTNING:
	case MAGIC:
		event.setCancelled(true);
		break;
	default:
		break;
	}
}
 
Example 34
Source Project: CardinalPGM   Source File: TitleRespawn.java    License: MIT License 5 votes vote down vote up
private void killPlayer(final Player player, Player killer, EntityDamageEvent.DamageCause cause) {
    if (deadPlayers.containsKey(player.getUniqueId())) return;
    this.deadPlayers.put(player.getUniqueId(), System.currentTimeMillis());

    CardinalDeathEvent cardinalDeathEvent = new CardinalDeathEvent(player, killer, cause);
    Bukkit.getServer().getPluginManager().callEvent(cardinalDeathEvent);

    dropInventory(player, true);

    PlayerDeathEvent deathEvent = new PlayerDeathEvent(player, new ArrayList<ItemStack>(), player.getExpToLevel(), 0, 0, 0, null);
    deathEvent.setDeathMessage(null);
    Bukkit.getServer().getPluginManager().callEvent(deathEvent);

    if (!isDeadUUID(player.getUniqueId())) return;

    Players.setObserver(player);

    PlayerNameUpdateEvent nameUpdateEvent = new PlayerNameUpdateEvent(player);
    Bukkit.getServer().getPluginManager().callEvent(nameUpdateEvent);

    sendTitle(player);

    player.setGameMode(GameMode.CREATIVE);

    setBlood(player, true);
    playDeathAnimation(player);

    if (!this.spectate) sendArmorStandPacket(player);

    player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 100, 0, true, false), false);
    player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, this.blackout ? Integer.MAX_VALUE : 20, 0, true, false), false);

    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Cardinal.getInstance(), new Runnable() {
        public void run() {
            GameHandler.getGameHandler().getMatch().getModules().getModule(Visibility.class).showOrHide(player);
        }
    }, 15L);
    if (this.auto) hasLeftClicked.add(player.getUniqueId());
}
 
Example 35
Source Project: PGM   Source File: DeathTracker.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/** Must run after {@link tc.oc.pgm.spawns.SpawnMatchModule#onVanillaDeath} */
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerDeath(PlayerDeathEvent event) {
  logger.fine("Wrapping " + event);
  MatchPlayer victim = match.getParticipant(event.getEntity());
  if (victim == null || victim.isDead()) return;

  DamageInfo info = getLastDamage(victim);
  if (info == null) info = new GenericDamageInfo(EntityDamageEvent.DamageCause.CUSTOM);

  match.callEvent(
      new MatchPlayerDeathEvent(event, victim, info, CombatLogTracker.isCombatLog(event)));
}
 
Example 36
Source Project: ArmorStandTools   Source File: MainListener.java    License: MIT License 5 votes vote down vote up
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
    if(event.getEntity() instanceof ArmorStand) {
        ArmorStand as = (ArmorStand) event.getEntity();
        if(ArmorStandGUI.isInUse(as) || as.isInvulnerable()) {
            event.setCancelled(true);
        }
    }
}
 
Example 37
@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 38
private DamageInfo resolveDamage(
    EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
  // Filter out observers immediately
  if (match.getParticipant(victim) == null) return new NullDamageInfo();

  for (DamageResolver resolver : damageResolvers) {
    DamageInfo resolvedInfo = resolver.resolveDamage(damageType, victim, damager);
    if (resolvedInfo != null) {
      return resolvedInfo;
    }
  }

  // This should never happen
  return new NullDamageInfo();
}
 
Example 39
@EventHandler(ignoreCancelled = true)
public void onIgnition(EntityCombustByEntityEvent event) {
    MatchPlayer victim = getVictim(event.getEntity());
    if(victim == null) return;
    processDamageEvent(event, victim.getParticipantState(),
                       damageResolver.resolveDamage(EntityDamageEvent.DamageCause.FIRE, event.getEntity(), event.getCombuster()));
}
 
Example 40
@EventHandler(ignoreCancelled = true)
public void onDamageVehicle(VehicleDamageEvent event) {
    MatchPlayer victim = getVictim(event.getVehicle());
    if(victim == null) return;
    processDamageEvent(event, victim.getParticipantState(),
                       damageResolver.resolveDamage(EntityDamageEvent.DamageCause.CUSTOM, event.getVehicle(), event.getAttacker()));
}