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

The following are top voted examples for showing how to use org.bukkit.event.entity.EntityDamageEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Crescent   File: AntiDamageA.java   Source Code and License 6 votes vote down vote up
@Override
public void call(Event event) {
	if (event instanceof EntityDamageEvent) {
		final EntityDamageEvent ede = (EntityDamageEvent) event;
		final DamageCause cause = ede.getCause();

		if (cause == DamageCause.FIRE || cause == DamageCause.CONTACT) {
			final Player player = profile.getPlayer();

			if (cause == DamageCause.FIRE && player.getFoodLevel() < 20) {
				// The AntiFire cheat only works when the hunger bar is
				// full.
				return;
			}

			final double previousHealth = player.getHealth();

			// Check a little later.
			Bukkit.getScheduler().runTaskLater(Crescent.getInstance(), () -> {
				if (player.getHealth() > previousHealth - ede.getDamage()) {
					callback(true);
				}
			}, 2L);
		}
	}
}
 
Example 2
Project: PA   File: PlayerEvents.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onDamage(EntityDamageEvent e){
    if(!(e.getEntity() instanceof Player)) return;
    Player p = (Player) e.getEntity();

    if (plugin.getGm().isInLobby()) e.setCancelled(true);

    switch (e.getCause()) {
        case LAVA:
            e.setCancelled(true);
            p.teleport(plugin.getAm().getRandomSpawn());
            //RageGames.getPlayer(p).resetPlayer();
            p.setHealth(20d);
            p.setFireTicks(0);
            break;
        case FALL:
            e.setCancelled(true);
            break;
    }
}
 
Example 3
Project: MockBukkit   File: PlayerMock.java   Source Code and License 6 votes vote down vote up
@Override
public void damage(double amount)
{
	Map<DamageModifier, Double> modifiers = new EnumMap<>(DamageModifier.class);
	modifiers.put(DamageModifier.BASE, 1.0);
	Map<DamageModifier, Function<Double, Double>> modifierFunctions = new EnumMap<>(DamageModifier.class);
	modifierFunctions.put(DamageModifier.BASE, damage -> damage);
	
	EntityDamageEvent event = new EntityDamageEvent(this, DamageCause.CUSTOM, modifiers, modifierFunctions);
	event.setDamage(amount);
	Bukkit.getPluginManager().callEvent(event);
	if (!event.isCancelled())
	{
		setHealth(health - amount);
	}
}
 
Example 4
Project: Warzone   File: DamageAPI.java   Source Code and License 6 votes vote down vote up
/**
 * Inflicts the given damage on an entity.
 *
 * This method will call the appropriate damage method and fire an {@link EntityDamageEvent}.
 *
 * @param entity Entity to inflict damage upon
 * @param damage Amount of half-hearts of damage to inflict
 * @param info {@link DamageInfo} object that details the type of damage
 * @return the final {@link Damage} object (never null)
 *
 * @throws NullPointerException if entity or info is null
 * throws IllegalArgumentExcpetion if hearts is less than zero
 */
public static @Nonnull
Damage inflictDamage(@Nonnull LivingEntity entity, int damage, @Nonnull DamageInfo info) {
    Preconditions.checkNotNull(entity, "living entity");
    Preconditions.checkArgument(damage >= 0, "damage must be greater than or equal to zero");
    Preconditions.checkNotNull(info, "damage info");

    DamageAPIHelper helper = DamageAPIHelper.get();

    EntityDamageEvent event = new EntityDamageEvent(entity, DamageCause.CUSTOM, damage);
    helper.setEventDamageInfo(event, info);

    Bukkit.getPluginManager().callEvent(event);

    if(event.isCancelled()) {
        return null;
    }

    entity.damage(event.getDamage());

    helper.setEventDamageInfo(event, null);

    return helper.getOurEvent(event).toDamageObject();
}
 
Example 5
Project: Warzone   File: SimpleGravityKillTracker.java   Source Code and License 6 votes vote down vote up
/**
 * Get the Fall that caused the given damage to the given player,
 * or null if the damage was not caused by a Fall.
 */
public Fall getCausingFall(Player victim, EntityDamageEvent.DamageCause damageCause) {
    Fall fall = this.falls.get(victim);

    if (fall == null || !fall.isFalling) {
        return null;
    }

    // Do an extra check to see if the fall should be cancelled
    this.checkFallCancelled(fall);
    if (!this.falls.containsKey(victim)) {
        return null;
    }

    switch (damageCause) {
        case VOID:
        case FALL:
        case LAVA:
        case SUICIDE:
            return fall;
        case FIRE_TICK:
            return fall.isInLava ? fall : null;
        default:
            return null;
    }
}
 
Example 6
Project: Warzone   File: ProjectileDamageResolver.java   Source Code and License 6 votes vote down vote up
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    if(damageEvent instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) damageEvent;

        if(event.getDamager() instanceof Projectile) {
            Projectile projectile = (Projectile) event.getDamager();
            Location launchLocation = this.projectileDistanceTracker.getLaunchLocation(projectile);
            Double projectileDistance = null;

            if(launchLocation != null) projectileDistance = event.getEntity().getLocation().distance(launchLocation);

            if(projectile.getShooter() instanceof LivingEntity) {
                return new ProjectileDamageInfo(projectile, (LivingEntity) projectile.getShooter(), projectileDistance);
            }
        }
    }
    return null;
}
 
Example 7
Project: Warzone   File: DispensedProjectileDamageResolver.java   Source Code and License 6 votes vote down vote up
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    if(damageEvent instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) damageEvent;

        if(event.getDamager() instanceof Projectile) {
            Projectile projectile = (Projectile) event.getDamager();
            Location launchLocation = this.projectileDistanceTracker.getLaunchLocation(projectile);
            Double projectileDistance = null;
            OfflinePlayer dispenserOwner = dispenserTracker.getOwner(projectile);


            if(launchLocation != null) projectileDistance = event.getEntity().getLocation().distance(launchLocation);

            if(projectile.getShooter() instanceof LivingEntity) {
                return new DispensedProjectileDamageInfo(projectile, (LivingEntity) projectile.getShooter(), projectileDistance, dispenserOwner);
            }
        }
    }
    return null;
}
 
Example 8
Project: Warzone   File: AnvilDamageResolver.java   Source Code and License 6 votes vote down vote up
public DamageInfo resolve(LivingEntity entity, Lifetime lifetime, EntityDamageEvent damageEvent) {
    if(damageEvent instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) damageEvent;

        if(event.getDamager() instanceof FallingBlock) {
            FallingBlock anvil = (FallingBlock) event.getDamager();
            OfflinePlayer offlineOwner = this.anvilTracker.getOwner(anvil);
            Player onlineOwner = null;

            if(offlineOwner != null) onlineOwner = offlineOwner.getPlayer();

            return new AnvilDamageInfo(anvil, onlineOwner, offlineOwner);
        }
    }

    return null;
}
 
Example 9
Project: Kineticraft   File: Parties.java   Source Code and License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true) // Prevent players from being damaged in the party world unless in a game.
public void onPlayerDamage(EntityDamageEvent evt) {
    if (!isParty(evt.getEntity()))
        return;

    if (!(evt.getEntity() instanceof LivingEntity))
        evt.setCancelled(true); // Default to no damage, if the entity isn't alive.

    if (!(evt.getEntity() instanceof Player))
        return; // If the damaged isn't a player, ignore this next bit that may uncancel it.
    Player p = (Player) evt.getEntity();
    evt.setCancelled(!checkParty(p, PartyGame::allowDamage));
    if (evt instanceof EntityDamageByEntityEvent) { // Handle combat differently.
        EntityDamageByEntityEvent dmg = (EntityDamageByEntityEvent) evt;
        boolean isMob = evt.getEntity() instanceof Creature;
        boolean isPlayer = dmg.getEntity() instanceof Player && dmg.getDamager() instanceof Player;
        evt.setCancelled((!checkParty(p, PartyGame::allowMobCombat) && isMob) || (!checkParty(p, PartyGame::allowPlayerCombat) && isPlayer));
    }
}
 
Example 10
Project: SurvivalPlus   File: Chairs.java   Source Code and License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onHit(EntityDamageEvent event)
{
	if(event.isCancelled()) return;
	Entity hitTarget = event.getEntity();
	if(hitTarget != null && hitTarget instanceof ArmorStand && hitTarget.getCustomName() == "Chair")
		// Chair entity is immune to damage.
		event.setCancelled(true);
	else if(hitTarget != null && hitTarget instanceof Player && hitTarget.getVehicle() != null)
	{
		// Let players stand up if receiving damage.
		Entity vehicle = hitTarget.getVehicle();
		if(vehicle != null && vehicle instanceof ArmorStand && vehicle.getCustomName() == "Chair")
			vehicle.remove();
	}
}
 
Example 11
Project: Arcadia-Spigot   File: DamageListener.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
    if(event.getCause() == EntityDamageEvent.DamageCause.CUSTOM) return;
    if(Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().getGameState() != GameState.INGAME) {
        event.setCancelled(true);
    } else {
        if(!Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().getCurrentGame().allowPVP) event.setCancelled(true);
    }
    if(!event.isCancelled() && event.getEntity() instanceof Player) {
        Player player = (Player) event.getEntity();
        if((player.getHealth()-event.getDamage()) <= 0) {
            event.setDamage(0);
            if(Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().isAlive(player)) {
                Arcadia.getPlugin(Arcadia.class).getAPI().getGameManager().setAlive(player, false);
            }
        }
    }
}
 
Example 12
Project: ProjectAres   File: PlayerStaminaState.java   Source Code and License 6 votes vote down vote up
void onEvent(EntityDamageEvent event) {
    if(event.getEntity() == player.getBukkit()) {
        // Player took damage
        mutateStamina(options.mutators.injury);

    } else if(event.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK &&
              event instanceof EntityDamageByEntityEvent &&
              ((EntityDamageByEntityEvent) event).getDamager() == player.getBukkit()) {

        // Player is damager and attack is melee
        swinging = false;

        for(StaminaSymptom symptom : getActiveSymptoms()) {
            symptom.onAttack(event);
        }

        mutateStamina(options.mutators.meleeHit);
    }
}
 
Example 13
Project: PA   File: PlayerEvents.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onDeath(PlayerDeathEvent e) {
    Player pl = e.getEntity();
    Player p = e.getEntity().getKiller();

    if (pl.getLastDamageCause().getCause() == EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) {
        //Para los logros
    }

    death = true;
    plugin.getServer().getScheduler().runTaskLater(plugin, () -> death = false, 20 * 5);

    if (manager.isInPvP(p)) {
        manager.removeCooldown(p);
        manager.removeCooldown(pl);

        p.sendMessage(Utils.colorize(PAData.SURVIVAL.getPrefix() + ChatColor.DARK_GREEN + " Ya no estás en pvp, puedes desconectarte."));
        pl.sendMessage(Utils.colorize(PAData.SURVIVAL.getPrefix() + ChatColor.DARK_GREEN + " Ya no estás en pvp, puedes desconectarte."));
    }
    pl.sendMessage(ChatColor.GREEN + "");
}
 
Example 14
Project: ProjectAres   File: BloodMatchModule.java   Source Code and License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event) {
    if(event.getEntity() instanceof Player) {
        Player victim = (Player) event.getEntity();
        Location location = victim.getBoundingBox().center().toLocation(match.getWorld());
        if(event.getDamage() > 0 && location.getY() >= 0 && !victim.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
            EntityUtils.entities(match.getWorld(), Player.class)
                 .filter(player -> settings.getManager(player).getValue(Settings.BLOOD, Boolean.class, false))
                 .forEach(player -> {
                     if(event instanceof EntityDamageByEntityEvent) {
                         player.playEffect(location, Effect.STEP_SOUND, Material.REDSTONE_WIRE);
                     } else {
                         player.playEffect(location, Effect.STEP_SOUND, Material.LAVA);
                     }
                 });
        }
    }
}
 
Example 15
Project: ProjectAres   File: DamageMatchModule.java   Source Code and License 6 votes vote down vote up
@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 16
Project: SamaGamesCore   File: CooldownModule.java   Source Code and License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
    if (api.getGameManager().isLegacyPvP()) {
        Entity attacker = event.getDamager();
        if (attacker instanceof Player) {
            Player player = (Player) attacker;
            ItemStack inHand = player.getInventory().getItemInMainHand();
            if (inHand != null) {
                double baseDamage = event.getDamage(EntityDamageEvent.DamageModifier.BASE);
                double currentDamage = this.getCurrentDamage(inHand.getType());
                if (currentDamage != 0.0D) {
                    double damageFactor = baseDamage / currentDamage;
                    double legacyDamage = this.getLegacyDamage(inHand.getType()) * damageFactor;
                    event.setDamage(EntityDamageEvent.DamageModifier.BASE, legacyDamage);
                }
            }
        }
    }
}
 
Example 17
Project: WebSandboxMC   File: WebPlayerBridge.java   Source Code and License 6 votes vote down vote up
public void notifyDied(String username, EntityDamageEvent.DamageCause cause) {
    webSocketServerThread.log(Level.INFO, "web user "+username+"'s entity died from "+cause);

    Channel channel = name2channel.get(username);
    if (channel != null) {
        String message = "T,You died from "+(cause == null ? "unknown causes" : cause);

        if (!dieDisconnect) {
            message += ", but remain connected to the server as a ghost";
        }

        webSocketServerThread.sendLine(channel, message);

        if (dieDisconnect) {
            channel.close();
            clientDisconnected(channel);
        }
    }
}
 
Example 18
Project: ProjectAres   File: PotionDamageResolver.java   Source Code and License 6 votes vote down vote up
@Override
public @Nullable PotionInfo resolveDamage(EntityDamageEvent.DamageCause damageType, Entity victim, @Nullable PhysicalInfo damager) {
    // 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;
    }

    final PotionEffectType effect;
    switch(damageType) {
        case POISON: effect = PotionEffectType.POISON; break;
        case WITHER: effect = PotionEffectType.WITHER; break;
        case MAGIC: effect = PotionEffectType.HARM; break;
        default: return null;
    }

    return new GenericPotionInfo(effect);
}
 
Example 19
Project: Hub   File: PlayerListener.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onEntityDamage(EntityDamageEvent event)
{
    event.setCancelled(true);

    if (event.getEntity().getType() != EntityType.PLAYER)
        return;

    if (event.getCause() == EntityDamageEvent.DamageCause.VOID)
    {
        if (this.hub.getParkourManager().getPlayerParkour(event.getEntity().getUniqueId()) != null)
            this.hub.getParkourManager().getPlayerParkour(event.getEntity().getUniqueId()).failPlayer((Player) event.getEntity());
        else
            event.getEntity().teleport(this.hub.getPlayerManager().getSpawn());
    }
}
 
Example 20
Project: HCFCore   File: VoidGlitchFixListener.java   Source Code and License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPlayerDamage(EntityDamageEvent event) {
    if (event.getCause() == EntityDamageEvent.DamageCause.VOID) {
        Entity entity = event.getEntity();
        if (entity instanceof Player) {
            // Allow players to die by VOID in the END
            if (entity.getWorld().getEnvironment() == World.Environment.THE_END) {
                return;
            }

            Location destination = BukkitUtils.getHighestLocation(entity.getLocation());
            if (destination == null)
                return;

            if (entity.teleport(destination, PlayerTeleportEvent.TeleportCause.PLUGIN)) {
                event.setCancelled(true);
                ((Player) entity).sendMessage(ChatColor.YELLOW + "You were saved from the void.");
            }
        }
    }
}
 
Example 21
Project: mczone   File: DamageEvents.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
	if (event instanceof EntityDamageByEntityEvent)
		return;
	
	if (event.getEntity() instanceof Player == false)
		return;

	Player t = (Player) event.getEntity();
	
	if (!damages.containsKey(t.getName()))
		damages.put(t.getName(), new ArrayList<PlayerDamageEvent>());
	
	PlayerDamageEvent callMe = new PlayerDamageEvent(t, event.getCause());
	Bukkit.getPluginManager().callEvent(callMe);
	event.setCancelled(callMe.isCancelled());
	
	if (event.isCancelled() == false)
		damages.get(t.getName()).add(callMe);
}
 
Example 22
Project: mczone   File: KitEvents.java   Source Code and License 6 votes vote down vote up
@EventHandler
public void Stomper(EntityDamageEvent e) {
	if (e.getEntity() instanceof Player) {
		Player p = (Player) e.getEntity();
		if (Kit.getKit(p).getName().equalsIgnoreCase("stomper")) {
			if (e.getCause() == DamageCause.FALL) {
				List<Entity> nearbyEntities = e.getEntity()
						.getNearbyEntities(5, 5, 5);
				for (Entity target : nearbyEntities) {
					if (target instanceof Player) {
						Player t = (Player) target;
						if (Team.getTeam(p) == Team.getTeam(t))
							continue;
						if (t.isSneaking())
							t.damage(e.getDamage() / 2, e.getEntity());
						else
							t.damage(e.getDamage(), e.getEntity());
					}
				}
				e.setDamage(0);
			}
		}
	}
}
 
Example 23
Project: Crescent   File: DetectionListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
	if (!(event.getEntity() instanceof Player)) {
		return;
	}

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

	getCheckVersion(player, CheckType.ANTIDAMAGE, "A").call(event);
}
 
Example 24
Project: SurvivalAPI   File: SuperheroesPlusModule.java   Source Code and License 5 votes vote down vote up
/**
 * Cancel fall damages
 *
 * @param event Event instance
 */
@EventHandler
public void onDamage(EntityDamageEvent event)
{
    if (event.getEntityType() == EntityType.PLAYER && event.getCause() == EntityDamageEvent.DamageCause.FALL)
    {
        event.setCancelled(true);
        event.setDamage(0);
    }
}
 
Example 25
Project: CloudNet   File: MobSelector.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void entityDamage(EntityDamageEvent e)
{
    MobImpl mob = CollectionWrapper.filter(mobs.values(), new Acceptable<MobImpl>() {
        @Override
        public boolean isAccepted(MobImpl value)
        {
            return e.getEntity().getEntityId() == value.getEntity().getEntityId();
        }
    });
    if (mob != null)
    {
        e.setCancelled(true);
    }
}
 
Example 26
Project: kaosEssentials   File: Core.java   Source Code and License 5 votes vote down vote up
@EventHandler(priority=EventPriority.LOWEST)
public void customDeathNonPlayerFallback(EntityDamageEvent e){
	if(e.getCause().equals(DamageCause.FALL)) return;
	if(e.getEntity() instanceof Player){
		Player p = (Player) e.getEntity();
		if(e.getCause().equals(DamageCause.ENTITY_ATTACK)){
			// no need to do anything here, this part is controlled in the customDeath method
		}else{
			if(e.getFinalDamage() >= p.getHealth()){
				e.setCancelled(true);
				Bukkit.getServer().broadcastMessage(ChatColor.GRAY + p.getName() + " died");
				// Set statistics
				//p.setStatistic(Statistic.DEATHS, p.getStatistic(Statistic.DEATHS) + 1);
				// Reset health, so they dont die
				p.setHealth(p.getMaxHealth());
				// Inventory clearing
				p.getInventory().clear();
				ItemStack air = new ItemStack(Material.AIR);
				p.getInventory().setHelmet(air);
				p.getInventory().setChestplate(air);
				p.getInventory().setLeggings(air);
				p.getInventory().setBoots(air);
				// Clear potion effects
				for(PotionEffect pe : p.getActivePotionEffects()){
					p.removePotionEffect(pe.getType());
				}
				// Stop infinite kill glitch
				p.setGameMode(GameMode.SPECTATOR);
				p.setGameMode(GameMode.ADVENTURE);
				// send them to the SPAWN of the world
				p.teleport(p.getWorld().getSpawnLocation());
				p.setFireTicks(0);
			}
		}
	}
}
 
Example 27
Project: Warzone   File: BlitzModule.java   Source Code and License 5 votes vote down vote up
public void createDeath(EntityDamageEvent event) {
    if (!(event.getEntity() instanceof Player)) return;
    if (TGM.get().getApiManager().isStatsDisabled()) {
        return;
    }

    Player player = (Player) event.getEntity();
    List<ItemStack> drops = Arrays.asList(player.getInventory().getContents());

    TGM.get().getGrave().getPlayerListener().onEntityDeath(new EntityDeathEvent(player, drops, player.getTotalExperience()));

}
 
Example 28
Project: Warzone   File: GravityDamageResolver.java   Source Code and License 5 votes vote down vote up
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    if(!(entity instanceof Player)) return null;
    Player victim = (Player) entity;
    Fall fall = this.tracker.getCausingFall(victim, damageEvent.getCause());
    if(fall != null) {
        return new GravityDamageInfo(fall.attacker, fall.cause, fall.from);
    } else {
        return null;
    }
}
 
Example 29
Project: Warzone   File: LavaDamageResolver.java   Source Code and License 5 votes vote down vote up
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    if(damageEvent.getCause() == DamageCause.LAVA) {
        return new SimpleLavaDamageInfo(null);
    }

    return null;
}
 
Example 30
Project: VoxelGamesLibv2   File: VoidTeleportFeature.java   Source Code and License 5 votes vote down vote up
@GameEvent
public void onVoidDamage(@Nonnull EntityDamageEvent event) {
    if (event.getEntityType() != EntityType.PLAYER)
        return;

    if (event.getCause().equals(EntityDamageEvent.DamageCause.VOID)) {
        Player player = (Player) event.getEntity();

        player.teleport(getPhase().getFeature(SpawnFeature.class).getSpawn(player.getUniqueId()));

        event.setCancelled(true);
    }
}
 
Example 31
Project: Warzone   File: VoidDamageResolver.java   Source Code and License 5 votes vote down vote up
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    if(damageEvent.getCause() == DamageCause.VOID) {
        return new SimpleVoidDamageInfo(null);
    }

    return null;
}
 
Example 32
Project: HCFCore   File: StuckTimer.java   Source Code and License 5 votes vote down vote up
@EventHandler(ignoreCancelled=true, priority=EventPriority.MONITOR)
public void onPlayerDamage(EntityDamageEvent event)
{
    Entity entity = event.getEntity();
    if ((entity instanceof Player))
    {
        Player player = (Player)entity;
        if (getRemaining(player) > 0L)
        {
            player.sendMessage(ChatColor.RED + "You were damaged, " + getDisplayName() + ChatColor.RED + " timer ended.");
            clearCooldown(player);
        }
    }
}
 
Example 33
Project: OMGPI   File: OMGDamageEvent.java   Source Code and License 5 votes vote down vote up
public OMGDamageEvent(EntityDamageEvent e, OMGPlayer damaged, Entity damager, OMGDamageCause reason, float damage) {
    super(e);
    cancel = false;
    this.damaged = damaged;
    this.damager = damager;
    this.reason = reason;
    this.damage = damage;
    OMGPI.g.event_player_damage(this);
}
 
Example 34
Project: SurvivalAPI   File: PyroTechnicsModule.java   Source Code and License 5 votes vote down vote up
/**
 * Fire player on damage
 * @param event Event
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onDamage(EntityDamageEvent event)
{
    if (((SurvivalGame) SamaGamesAPI.get().getGameManager().getGame()).isDamagesActivated()
            && event.getEntityType() == EntityType.PLAYER
            && event.getCause() != EntityDamageEvent.DamageCause.FIRE
            && event.getCause() != EntityDamageEvent.DamageCause.FIRE_TICK
            && event.getDamage() > 0
            && !event.isCancelled())
        event.getEntity().setFireTicks((int) this.moduleConfiguration.get("fire-time") * 20);
}
 
Example 35
Project: Arcadia-Spigot   File: Freeze.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
    if(event.getEntity().getUniqueId() == entity.getUniqueId())
        event.setCancelled(true);
    if(event.getEntity().getUniqueId() == player.getUniqueId())
        event.setCancelled(true);
}
 
Example 36
Project: bskyblock   File: VisitorGuard.java   Source Code and License 5 votes vote down vote up
/**
 * Prevents visitors from getting damage if invinciblevisitors option is set to TRUE
 * @param e
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onVisitorReceiveDamage(EntityDamageEvent e){
    if(!Settings.invincibleVisitor) return;
    if(!(e.getEntity() instanceof Player)) return;

    Player p = (Player) e.getEntity();
    if (!Util.inWorld(p) || plugin.getIslands().locationIsOnIsland(p, p.getLocation())) return;

    if (Settings.invincibleVisitorOptions.contains(e.getCause())) e.setCancelled(true);

    else if(e.getCause().equals(DamageCause.VOID)) {
        if(plugin.getPlayers().hasIsland(p.getUniqueId())) {
            Location safePlace = plugin.getIslands().getSafeHomeLocation(p.getUniqueId(), 1);
            if (safePlace != null) {
                p.teleport(safePlace);
                // Set their fall distance to zero otherwise they crash onto their island and die
                p.setFallDistance(0);
                e.setCancelled(true);
                return;
            } 
        }
        // No island, or no safe spot on island
        if (plugin.getIslands().getSpawn() != null) {
            p.teleport(plugin.getIslands().getSpawnPoint());
            // Set their fall distance to zero otherwise they crash onto their island and die
            p.setFallDistance(0);
            e.setCancelled(true);
            return;
        }
        // No island spawn, try regular spawn
        if (!p.performCommand("spawn")) {
            // If this command doesn't work, let them die otherwise they may get trapped in the void forever
            return;
        }
        // Set their fall distance to zero otherwise they crash onto their island and die
        p.setFallDistance(0);
        e.setCancelled(true);
    }
}
 
Example 37
Project: Absorption   File: PlayerListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onEntityDamage(EntityDamageEvent e) {
	if(e.getEntity() instanceof ArmorStand || e.getEntity() instanceof Item)
		e.setCancelled(true);
	
	if(e.getEntity() instanceof Player) {
		e.setCancelled(true);
		if(e.getCause() == DamageCause.FALL) {
			GamePlayer player = Absorption.getPlayer((Player) e.getEntity());
			
			if(player == null) return;
			player.damage((int) e.getDamage()); 
		}
	}
}
 
Example 38
Project: Slimefun4-Chinese-Version   File: DamageListener.java   Source Code and License 5 votes vote down vote up
public void onArrowHit(EntityDamageEvent e)
{
    if((e.getEntity() instanceof Player) && e.getCause() == org.bukkit.event.entity.EntityDamageEvent.DamageCause.FALL && Variables.damage.containsKey(e.getEntity().getUniqueId()))
    {
        e.setCancelled(true);
        Variables.damage.remove(e.getEntity().getUniqueId());
    }
}
 
Example 39
Project: SuperiorCraft   File: DamageIndicator.java   Source Code and License 5 votes vote down vote up
@EventHandler
   public void onEntityDamageEvent(EntityDamageEvent e) {
	if (!(e.getEntity() instanceof ArmorStand) && e.getEntityType() != EntityType.ARMOR_STAND && e.getEntityType() != EntityType.DROPPED_ITEM) {
		Hologram h = new Hologram(ChatColor.RED + "-" + Double.toString(e.getDamage()) + " \u2764", e.getEntity().getLocation());
		h.getHologram().addScoreboardTag("dindicator");
		h.setKillTimer(2);
	}
	if (e.getEntity() instanceof Player) {
		Player player = (Player) e.getEntity();
		player.sendMessage(ChatColor.GRAY + "[DamageIndicator] " + e.getCause().name() + " did " + new DecimalFormat("#0.0").format(((double) Math.round(e.getDamage())) / 2) + ChatColor.RED + " \u2764");
	}
}
 
Example 40
Project: BlockBall   File: GameListener.java   Source Code and License 5 votes vote down vote up
@EventHandler
public void onPlayerDamageEvent(EntityDamageEvent event) {
    if (event.getEntity() instanceof Player) {
        Game game;
        if ((game = this.controller.getGameFromPlayer((Player) event.getEntity())) != null) {
            if (!game.getArena().getTeamMeta().isDamageEnabled())
                event.setCancelled(true);
        } else if ((game = this.controller.isInGameLobby((Player) event.getEntity())) != null) {
            if (!game.getArena().getTeamMeta().isDamageEnabled())
                event.setCancelled(true);
        }
    }
}