当前位置: 首页>>代码示例>>Java>>正文


Java DamageCause类代码示例

本文整理汇总了Java中org.bukkit.event.entity.EntityDamageEvent.DamageCause的典型用法代码示例。如果您正苦于以下问题:Java DamageCause类的具体用法?Java DamageCause怎么用?Java DamageCause使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DamageCause类属于org.bukkit.event.entity.EntityDamageEvent包,在下文中一共展示了DamageCause类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: EntityDamageByEntityListener

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler
public void EntityDamageByEntityListener(EntityDamageByEntityEvent e) {
	if (!GameManager.getGameSituation()) {
		e.setCancelled(true);
	}
	if (e.getDamager() instanceof Player) {
		if (e.getEntity() instanceof Player) {
			Player damager = (Player) e.getDamager();
			Player victim = (Player) e.getEntity();
			if (SettingsManager.shotinfo) {
				if (e.getCause() == DamageCause.PROJECTILE) {
					if(victim.getLocation().distance(damager.getLocation()) < 20) {
						Bukkit.broadcastMessage(SettingsManager.niceshot.replace("%s", victim.getName()).replace("%s", damager.getName()).replace("%d", String.valueOf(victim.getLocation().distance(damager.getLocation()))));
					}
				}
			}
		}
	}
}
 
开发者ID:masste,项目名称:McPlayUHC,代码行数:20,代码来源:EntityDamageByEntityListener.java

示例2: call

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的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: inflictDamage

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的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

示例4: resolve

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的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

示例5: callEntityDamageEvent

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
private static EntityDamageEvent callEntityDamageEvent(Entity damager, Entity damagee, DamageCause cause, Map<DamageModifier, Double> modifiers, Map<DamageModifier, Function<? super Double, Double>> modifierFunctions) {
    EntityDamageEvent event;
    if (damager != null) {
        event = new EntityDamageByEntityEvent(damager.getBukkitEntity(), damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
    } else {
        event = new EntityDamageEvent(damagee.getBukkitEntity(), cause, modifiers, modifierFunctions);
    }

    callEvent(event);

    if (!event.isCancelled()) {
        event.getEntity().setLastDamageCause(event);
    }

    return event;
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:17,代码来源:CraftEventFactory.java

示例6: onItemDamage

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler
public void onItemDamage(EntityDamageEvent event) {
    if (event.getEntityType() == EntityType.DROPPED_ITEM && (event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.FIRE_TICK || event.getCause() == DamageCause.FIRE)) {
        Vector v = Vector.getRandom().normalize();
        v = v.setX(v.getX() - 0.5f);
        v = v.setZ(v.getZ() - 0.5f);
        v = v.multiply(0.35);
        if (v.getX() > 0 && v.getX() < 0.10)
            v.setX(0.10);
        if (v.getZ() > 0 && v.getZ() < 0.10)
            v.setZ(0.10);
        if (v.getX() < 0 && v.getX() > -0.10)
            v.setX(-0.10);
        if (v.getZ() < 0 && v.getZ() > -0.10)
            v.setZ(-0.10);
        v.setY(0.3);
        event.getEntity().setVelocity(v);
        event.setCancelled(true);
        RScheduler.schedule(plugin, () -> {
            event.getEntity().setFireTicks(0);
        }, RTicks.seconds(1));
    }
    if (event.getEntityType() == EntityType.ARMOR_STAND && (event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.FIRE_TICK || event.getCause() == DamageCause.FIRE)) {
        event.setCancelled(true);
    }
}
 
开发者ID:edasaki,项目名称:ZentrelaRPG,代码行数:27,代码来源:EnvironmentManager.java

示例7: parse

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
public static DisableDamageModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException {
    SetMultimap<DamageCause, PlayerRelation> causes = HashMultimap.create();
    for(Element damageCauseElement : doc.getRootElement().getChildren("disabledamage")) {
        for(Element damageEl : damageCauseElement.getChildren("damage")) {
            DamageCause cause = XMLUtils.parseEnum(damageEl, DamageCause.class, "damage type");
            for(PlayerRelation damagerType : PlayerRelation.values()) {
                // Legacy syntax used "other" instead of "neutral"
                String attrName = damagerType.name().toLowerCase();
                Node attr = damagerType == PlayerRelation.NEUTRAL ? Node.fromAttr(damageEl, attrName, "other")
                                                                  : Node.fromAttr(damageEl, attrName);
                if(XMLUtils.parseBoolean(attr, true)) {
                    causes.put(cause, damagerType);

                    // Bukkit 1.7.10 changed TNT from BLOCK_EXPLOSION to ENTITY_EXPLOSION,
                    // so we include them both to keep old maps working.
                    if(cause == DamageCause.BLOCK_EXPLOSION) {
                        causes.put(DamageCause.ENTITY_EXPLOSION, damagerType);
                    }
                }
            }
        }
    }
    return new DisableDamageModule(causes);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:25,代码来源:DisableDamageModule.java

示例8: onAttack

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
	{
		Player player = (Player)event.getDamager();
		ItemStack mainItem = player.getInventory().getItemInMainHand();
		LivingEntity enemy = (LivingEntity)event.getEntity();
		
		if(mainItem.getType() == Material.GOLD_SPADE)
		{
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 100, 0, false));
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 100, 0, false));
			player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 48, 2, true));
			Location particleLoc = player.getLocation();
			particleLoc.setY(particleLoc.getY() + 2);
               ParticleEffect.HEART.display(0.5f, 0, 0.5f, 1, 2, particleLoc, 64);
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:22,代码来源:ObsidianMaceWeakness.java

示例9: onAttack

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST)
public void onAttack(EntityDamageByEntityEvent event)
{
	if(event.isCancelled()) return;
	if(event.getDamager() instanceof Player && event.getEntity() instanceof LivingEntity && event.getCause() == DamageCause.ENTITY_ATTACK)
	{
		Player player = (Player)event.getDamager();
		ItemStack mainItem = player.getInventory().getItemInMainHand();
		LivingEntity enemy = (LivingEntity)event.getEntity();

		Random rand = new Random();
		
		if(mainItem.getType() == Material.GOLD_AXE)
		{
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 480, 2, false));
			enemy.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 480, 0, false));
           	enemy.getLocation().getWorld().playSound(enemy.getLocation(), Sound.ENTITY_WITHER_SPAWN, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
		}
	}
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:21,代码来源:StarBattleaxeWither.java

示例10: onEntityDamage

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler
public void onEntityDamage(EntityDamageEvent e) {
	Entity ent = e.getEntity();
	 if(ent instanceof Player) {
		 if (!hasIgnorePermission((Player) ent)) {
			 if (inLobbyWorld((Player) ent) && SkyWarsReloaded.getCfg().LobbyFallDamageDisabled()) {
					if (e.getCause().equals(DamageCause.FALL)) {
						e.setCancelled(true);
					}
			 }
			 if (inLobbyWorld((Player) ent) && SkyWarsReloaded.getCfg().damageDisabled()) {
					if (!e.getCause().equals(DamageCause.VOID)) {
						e.setCancelled(true);
					}
			 }
		 }
	 }
}
 
开发者ID:smessie,项目名称:SkyWarsReloaded,代码行数:19,代码来源:LobbyListener.java

示例11: damage

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的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

示例12: Stomper

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@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);
			}
		}
	}
}
 
开发者ID:thekeenant,项目名称:mczone,代码行数:25,代码来源:KitEvents.java

示例13: onPlayerDamage

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的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

示例14: onCancell

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
@EventHandler
public void onCancell(EntityDamageEvent event){
Entity e = event.getEntity();
if(!(e instanceof Player)){
	return;
}
Player p = (Player)e;
Arena a = new ArenaManager().getArena(p);

if(a==null){
	event.setCancelled(true);
	return;
}
if(a.isEnd()){
	event.setCancelled(true);
	
}
if(a.fallMode()==true){
	if(event.getCause() == DamageCause.FALL||event.getCause() == DamageCause.VOID){
	event.setCancelled(true);
	}
}
}
 
开发者ID:SpikyBite,项目名称:BiteSkywars,代码行数:24,代码来源:PlayerListener.java

示例15: onAthenaDeath

import org.bukkit.event.entity.EntityDamageEvent.DamageCause; //导入依赖的package包/类
/**
 * Suppress regular death messages, replacing them with custom ones local to the player's Match
 */
@EventHandler
public void onAthenaDeath(AthenaDeathEvent event) {
    DamageCause cause = event.getPlayer().getLastDamageCause().getCause();
    if (event.isPvP()) {
        switch (cause) {
            case FALL:
                handleGroundFall(event);
                break;
            case PROJECTILE:
                handleProjectile(event);
                break;
            case VOID:
                handleVoid(event);
                break;
            default:
                broadcast(event, event.getDeathEvent().getDeathMessage());
        }
    } else {
        broadcast(event, event.getDeathEvent().getDeathMessage());
    }
    event.getDeathEvent().setDeathMessage(null); //disable vanilla death broadcast
}
 
开发者ID:redwallhp,项目名称:AthenaGM,代码行数:26,代码来源:DeathMessageModule.java


注:本文中的org.bukkit.event.entity.EntityDamageEvent.DamageCause类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。