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


Java EntityDamageEvent.getCause方法代碼示例

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


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

示例1: onDamageWhenPlayerNotLoaded

import org.bukkit.event.entity.EntityDamageEvent; //導入方法依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
public void onDamageWhenPlayerNotLoaded(EntityDamageEvent event) {
    if (event.getEntityType() != EntityType.PLAYER) {
        return;
    }

    Player player = (Player) event.getEntity();
    if (InventoryManager.playerIsLoaded(player)) {
        return;
    }

    if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
        PlayerLoader.setDamageForPlayer(player, event.getFinalDamage());
    }

    event.setCancelled(true);
}
 
開發者ID:EndlessCodeGroup,項目名稱:RPGInventory,代碼行數:18,代碼來源:PlayerListener.java

示例2: 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

示例3: onEntityDamage

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

示例4: resolve

import org.bukkit.event.entity.EntityDamageEvent; //導入方法依賴的package包/類
public @Nonnull
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    DamageInfo info = null;

    for(ResolverEntry entry : this.resolvers) {
        DamageInfo resolvedInfo = entry.resolver.resolve(entity, lifetime, damageEvent);
        if(resolvedInfo != null) {
            info = resolvedInfo;
        }
    }

    if(info == null) {
        info = new BukkitDamageInfo(damageEvent.getCause());
    }

    return info;
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:18,代碼來源:SimpleResolverManager.java

示例5: onPlayerDamage

import org.bukkit.event.entity.EntityDamageEvent; //導入方法依賴的package包/類
@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.");
            }
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:22,代碼來源:VoidGlitchFixListener.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 && damageEvent.getCause() == DamageCause.ENTITY_ATTACK) {
        EntityDamageByEntityEvent entityEvent = (EntityDamageByEntityEvent) damageEvent;

        if(entityEvent.getDamager() instanceof LivingEntity) {
            LivingEntity attacker = (LivingEntity) entityEvent.getDamager();

            Material weaponMaterial;
            ItemStack held = attacker.getEquipment().getItemInMainHand();
            if(held != null) {
                weaponMaterial = held.getType();
            } else {
                weaponMaterial = Material.AIR;
            }

            return new SimpleMeleeDamageInfo(attacker, weaponMaterial);
        }
    }

    return null;
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:23,代碼來源:MeleeDamageResolver.java

示例7: 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

示例8: 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

示例9: onPlayerDamage

import org.bukkit.event.entity.EntityDamageEvent; //導入方法依賴的package包/類
@EventHandler
public void onPlayerDamage(EntityDamageEvent event) {
	if (!(event.getEntity() instanceof Player))
		return;
	event.setCancelled(true);
	
	if (event.getCause()==DamageCause.VOID) {
		Location l = event.getEntity().getWorld().getSpawnLocation();
		l.setX(14.5);
		l.setY(10.5);
		l.setZ(-795.5);
		l.setPitch(0.5F);
		l.setYaw(90 * RandomUtil.between(1, 4));
		event.getEntity().teleport(l);
	}
}
 
開發者ID:thekeenant,項目名稱:mczone,代碼行數:17,代碼來源:Events.java

示例10: onDamage

import org.bukkit.event.entity.EntityDamageEvent; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.LOWEST)
public void onDamage(EntityDamageEvent evt) { // Teleport a player out if they lose.
    if (evt.getCause() == EntityDamageEvent.DamageCause.LAVA && evt.getEntity() instanceof Player) {
        evt.getEntity().playEffect(EntityEffect.HURT);
        removePlayer((Player) evt.getEntity());
        Bukkit.getScheduler().runTask(Core.getInstance(), () -> evt.getEntity().setFireTicks(0)); // Must run a tick late.
    }
}
 
開發者ID:Kneesnap,項目名稱:Kineticraft,代碼行數:9,代碼來源:Splef.java

示例11: resolve

import org.bukkit.event.entity.EntityDamageEvent; //導入方法依賴的package包/類
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    if(damageEvent.getCause() == DamageCause.LAVA) {
        return new SimpleLavaDamageInfo(null);
    }

    return null;
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:9,代碼來源:LavaDamageResolver.java

示例12: resolve

import org.bukkit.event.entity.EntityDamageEvent; //導入方法依賴的package包/類
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
    if(damageEvent.getCause() == DamageCause.FALL) {
        float fallDistance = Math.max(0, entity.getFallDistance());

        return new SimpleFallDamageInfo(null, fallDistance);
    }

    return null;
}
 
開發者ID:WarzoneMC,項目名稱:Warzone,代碼行數:11,代碼來源:FallDamageResolver.java

示例13: onEntityDamage

import org.bukkit.event.entity.EntityDamageEvent; //導入方法依賴的package包/類
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
	if (event.getEntity() instanceof Player) {
		Gamer g = Gamer.get((Player) event.getEntity());
		if (g.getVariable("spectator") != null)
			return;
		
		Kit kit = (Kit) g.getVariable("kit");
		if (kit.getName().equals("scout") && event.getCause() == DamageCause.FALL) {
			event.setDamage(0);
		}
	}
}
 
開發者ID:thekeenant,項目名稱:mczone,代碼行數:14,代碼來源:KitEvents.java

示例14: onEntityDamageEvent

import org.bukkit.event.entity.EntityDamageEvent; //導入方法依賴的package包/類
@EventHandler
public void onEntityDamageEvent(EntityDamageEvent event) {
    if (event.getCause() == DamageCause.VOID && event.getEntity() instanceof Player) {
        if (lastVoid.containsKey(((Player) event.getEntity()).getName()) && System.currentTimeMillis() - lastVoid.get(((Player) event.getEntity()).getName()) < 5000)
            return;
        ((Player) event.getEntity()).sendMessage(ChatColor.RED + "Woah! Careful there, pal!");
        event.getEntity().setFallDistance(0);
        event.getEntity().teleport(event.getEntity().getWorld().getSpawnLocation());
        event.getEntity().setFallDistance(0);
    } else if (event.getCause() == DamageCause.VOID && MobManager.spawnedMobs.get(event.getEntity().getUniqueId()) != null) {
        MobData md = MobManager.spawnedMobs.get(event.getEntity().getUniqueId());
        event.getEntity().teleport(md.ai.originalLoc);
    }
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:15,代碼來源:EnvironmentManager.java

示例15: onEntityDamage

import org.bukkit.event.entity.EntityDamageEvent; //導入方法依賴的package包/類
/**
 * Set Potion Effect SLOWNESS I when player takes fall damage
 * @param event Entity Damage Event
 */
@EventHandler
public void onEntityDamage(EntityDamageEvent event)
{
    if (event.getEntity() instanceof Player && event.getCause() == EntityDamageEvent.DamageCause.FALL && !event.isCancelled())
        ((Player) event.getEntity()).addPotionEffect(PotionEffectType.SLOW.createEffect((int) this.moduleConfiguration.get("penalty-time") * 20, 1));
}
 
開發者ID:SamaGames,項目名稱:SurvivalAPI,代碼行數:11,代碼來源:CrippleModule.java


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