當前位置: 首頁>>代碼示例>>Java>>正文


Java EntityDamageEvent類代碼示例

本文整理匯總了Java中org.bukkit.event.entity.EntityDamageEvent的典型用法代碼示例。如果您正苦於以下問題:Java EntityDamageEvent類的具體用法?Java EntityDamageEvent怎麽用?Java EntityDamageEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EntityDamageEvent類屬於org.bukkit.event.entity包,在下文中一共展示了EntityDamageEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: call

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
@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);
		}
	}
}
 
開發者ID:davidm98,項目名稱:Crescent,代碼行數:27,代碼來源:AntiDamageA.java

示例2: onDamage

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
@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;
    }
}
 
開發者ID:cadox8,項目名稱:PA,代碼行數:21,代碼來源:PlayerEvents.java

示例3: damage

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
@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);
	}
}
 
開發者ID:seeseemelk,項目名稱:MockBukkit,代碼行數:17,代碼來源:PlayerMock.java

示例4: inflictDamage

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:37,代碼來源:DamageAPI.java

示例5: getCausingFall

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
/**
 * 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;
    }
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:30,代碼來源:SimpleGravityKillTracker.java

示例6: resolve

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
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;
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:20,代碼來源:ProjectileDamageResolver.java

示例7: resolve

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
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;
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:22,代碼來源:DispensedProjectileDamageResolver.java

示例8: resolve

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
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;
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:18,代碼來源:AnvilDamageResolver.java

示例9: onPlayerDamage

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
@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));
    }
}
 
開發者ID:Kneesnap,項目名稱:Kineticraft,代碼行數:20,代碼來源:Parties.java

示例10: onHit

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
@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();
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:17,代碼來源:Chairs.java

示例11: onEntityDamage

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
@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);
            }
        }
    }
}
 
開發者ID:ArcadiaPlugins,項目名稱:Arcadia-Spigot,代碼行數:19,代碼來源:DamageListener.java

示例12: onEvent

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
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);
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:20,代碼來源:PlayerStaminaState.java

示例13: onDeath

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
@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 + "");
}
 
開發者ID:cadox8,項目名稱:PA,代碼行數:22,代碼來源:PlayerEvents.java

示例14: onEntityDamage

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
@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);
                     }
                 });
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:19,代碼來源:BloodMatchModule.java

示例15: onTarget

import org.bukkit.event.entity.EntityDamageEvent; //導入依賴的package包/類
@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);
        }
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:21,代碼來源:DamageMatchModule.java


注:本文中的org.bukkit.event.entity.EntityDamageEvent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。