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


Java DamageCause.ENTITY_ATTACK屬性代碼示例

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


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

示例1: resolve

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,代碼行數:22,代碼來源:MeleeDamageResolver.java

示例2: onAttack

@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,代碼行數:21,代碼來源:ObsidianMaceWeakness.java

示例3: onAttack

@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,代碼行數:20,代碼來源:StarBattleaxeWither.java

示例4: damage

@Override
public void damage(double amount, Entity source)
{
	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);
	
	EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(source, this, DamageCause.ENTITY_ATTACK, modifiers, modifierFunctions);
	event.setDamage(amount);
	Bukkit.getPluginManager().callEvent(event);
	if (!event.isCancelled())
	{
		setHealth(health - amount);
	}
}
 
開發者ID:seeseemelk,項目名稱:MockBukkit,代碼行數:16,代碼來源:PlayerMock.java

示例5: hitByEntityExplosion

private void hitByEntityExplosion(EntityDamageByEntityEvent event, BPPlayer bpDamager, Player shooter, BPPlayer bpVictim, Player victim)
	{
//		Entity exploded = event.getDamager();
//		if(exploded instanceof Projectile)
//		{
//			if(shooter != null)
//			{
//				CTFProperties damagerProps = (CTFProperties) bpDamager.getGameProperties();
//				if(damagerProps.isEnemy(bpVictim))
//				{
					EntityDamageEvent dmgCause = new EntityDamageByEntityEvent(shooter, victim, DamageCause.ENTITY_ATTACK, event.getDamage());
					victim.setLastDamageCause(dmgCause);
					return;
//				}
//			}
//			
//			event.setCancelled(true);
//		}
	}
 
開發者ID:Limeth,項目名稱:Breakpoint,代碼行數:19,代碼來源:PVPListener.java

示例6: onEntityDamage

@SuppressWarnings("deprecation")
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
    if (event.isCancelled()) {
        return;
    }
    LivingEntity attacker = null;
    Entity defender = event.getEntity();
    if (event.getCause() == DamageCause.ENTITY_ATTACK) {
        EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
        if (e.getDamager() instanceof LivingEntity) {
            attacker = (LivingEntity) e.getDamager();
        }
    }

    if (attacker instanceof Player && defender instanceof LivingEntity && !attacker.equals(defender)) {
        Player player = (Player) attacker;
        if (player.getItemInHand().getType() == Material.getMaterial("ALMURA_WANDINFORMATION")) {
            player.sendMessage(ChatColor.ITALIC + "Entity Information:");
            player.sendMessage(ChatColor.WHITE + "ID: " + ChatColor.RED + event.getEntity().getEntityId());
            player.sendMessage(ChatColor.WHITE + "Type: " + ChatColor.GOLD + event.getEntity().getType());
            player.sendMessage(ChatColor.WHITE + "Type Name: " + ChatColor.GREEN + event.getEntity().getType().getName());
        }
    }
}
 
開發者ID:AlmuraDev,項目名稱:AlmuraForgeBridge,代碼行數:25,代碼來源:EntityListener.java

示例7: IsEnviromentKill

private boolean IsEnviromentKill(DamageCause damageCause)
{
	boolean env = this.model.getConfig().getZombieSpawnCondition().getEnv();

	if(env)
	{
		if(damageCause == DamageCause.ENTITY_ATTACK || damageCause == DamageCause.ENTITY_EXPLOSION)
		{
			return false;
		}

		return true;
	}

	return false;
}
 
開發者ID:DreanorBukkit,項目名稱:ZombieResurrection,代碼行數:16,代碼來源:EntityDeathListener.java

示例8: run

@Override
public boolean run(Player player, String[] args, int power) {
	Entity e = getTarget(player);
	int damage = getConfig().getInt(getName() + ".damage");
	damage *= power;
	if (e == null) {
		Lang.errMsg("spells.punch.fail", player);
		return false;
	}
	EntityDamageEvent event = new EntityDamageEvent(e, DamageCause.ENTITY_ATTACK, (double) damage);
	Bukkit.getPluginManager().callEvent(event);
	if (!event.isCancelled()) {
		LivingEntity c = (LivingEntity) getTarget(player);
		c.damage(damage);
		return true;
	} else {
		return false;
	}
}
 
開發者ID:mcardy,項目名稱:Zephyrus,代碼行數:19,代碼來源:Punch.java

示例9: call

@Override
public void call(Event event) {
	if (event instanceof EntityDamageByEntityEvent) {
		EntityDamageByEntityEvent edbe = (EntityDamageByEntityEvent) event;

		if (edbe.getCause() != DamageCause.ENTITY_ATTACK) {
			return;
		}

		callback(!isInLineOfSight(edbe.getEntity(), 2.0));
	}
}
 
開發者ID:davidm98,項目名稱:Crescent,代碼行數:12,代碼來源:KillauraB.java

示例10: onDamageGet

@EventHandler(priority=EventPriority.MONITOR)
public void onDamageGet(EntityDamageEvent e) {
	if (!e.isCancelled()) {
		if (e instanceof EntityDamageByEntityEvent) {
			if (((EntityDamageByEntityEvent) e).getDamager() instanceof Player && SlimefunStartup.chance(100, 45)) {
				if (SlimefunManager.isItemSimiliar(((Player) ((EntityDamageByEntityEvent) e).getDamager()).getInventory().getItemInMainHand(), SlimefunItem.getItem("BLADE_OF_VAMPIRES"), true)) {
					((Player) ((EntityDamageByEntityEvent) e).getDamager()).playSound(((EntityDamageByEntityEvent) e).getDamager().getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.7F, 0.7F);
					((Player) ((EntityDamageByEntityEvent) e).getDamager()).addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 1));
				}
			}
		}
		if (e.getEntity() instanceof Player) {
			if (!e.isCancelled()) {
				if (e.getCause() == DamageCause.LAVA) Talisman.checkFor(e, SlimefunItem.getByID("LAVA_TALISMAN"));
				if (e.getCause() == DamageCause.DROWNING) Talisman.checkFor(e, SlimefunItem.getByID("WATER_TALISMAN"));
				if (e.getCause() == DamageCause.FALL) Talisman.checkFor(e, SlimefunItem.getByID("ANGEL_TALISMAN"));
				if (e.getCause() == DamageCause.FIRE) Talisman.checkFor(e, SlimefunItem.getByID("FIRE_TALISMAN"));
				if (e.getCause() == DamageCause.ENTITY_ATTACK) Talisman.checkFor(e, SlimefunItem.getByID("WARRIOR_TALISMAN"));
				if (e.getCause() == DamageCause.ENTITY_ATTACK) Talisman.checkFor(e, SlimefunItem.getByID("KNIGHT_TALISMAN"));
				if (e.getCause() == DamageCause.PROJECTILE) {
					if (Talisman.checkFor(e, SlimefunItem.getByID("WHIRLWIND_TALISMAN"))) {
						if (((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) {
							Vector direction = ((Player) e.getEntity()).getEyeLocation().getDirection().multiply(2.0);
							Projectile projectile = (Projectile) e.getEntity().getWorld().spawnEntity(((LivingEntity) e.getEntity()).getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), ((EntityDamageByEntityEvent) e).getDamager().getType());
							projectile.setVelocity(direction);
							((EntityDamageByEntityEvent) e).getDamager().remove();
						}
					}
				}
			}
		}
	}
}
 
開發者ID:StarWishsama,項目名稱:Slimefun4-Chinese-Version,代碼行數:33,代碼來源:TalismanListener.java

示例11: onAttack

@SuppressWarnings("deprecation")
@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 item = player.getItemInHand();
		if(item.getType() == Material.WOOD_SPADE)
		{
			item.setDurability((short)(item.getDurability() - 2));
		}
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:15,代碼來源:FirestrikerClick.java

示例12: onEntityDamage

@EventHandler(priority = EventPriority.LOWEST)
public void onEntityDamage(EntityDamageEvent event)
{
    Entity entity = event.getEntity();
    
    DamageCause cause = event.getCause();
    if(cause == DamageCause.ENTITY_ATTACK || cause == DamageCause.PROJECTILE)
    {
        EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent)event;
        Entity attacker = event2.getDamager();
        
        if(attacker != null && attacker.getType() == EntityType.PLAYER) return;
        
        if(attacker instanceof Projectile)
        {
            ProjectileSource source = ((Projectile)attacker).getShooter();
            if(source != null && source instanceof Player) return;
        }
    }
    
    if(entity instanceof Animals || entity instanceof WaterMob || entity.getType() == EntityType.VILLAGER || entity.getCustomName() != null)
    {
        Flag flag = this.GetFlagInstanceAtLocation(entity.getLocation(), null);
        if(flag == null) return;
        event.setCancelled(true);
    }
}
 
開發者ID:BigScary,項目名稱:GriefPreventionFlags,代碼行數:27,代碼來源:FlagDef_NoMobDamage.java

示例13: hitByFireball

private void hitByFireball(EntityDamageByEntityEvent event, Player damager, Player victim)
{
	double dmg = event.getDamage() * 1.5;
	event.setDamage(dmg);
	EntityDamageEvent dmgCause = new EntityDamageByEntityEvent(damager, victim, DamageCause.ENTITY_ATTACK, dmg);
	victim.setLastDamageCause(dmgCause);
}
 
開發者ID:Limeth,項目名稱:Breakpoint,代碼行數:7,代碼來源:PVPListener.java

示例14: toBukkit

public static DamageCause toBukkit(cn.nukkit.event.entity.EntityDamageEvent.DamageCause nukkit) {
	// TODO Direct mapping via DamageCause.valueOf?
	switch (nukkit) {
		case CONTACT:
			return DamageCause.CONTACT;
		case ENTITY_ATTACK:
			return DamageCause.ENTITY_ATTACK;
		case PROJECTILE:
			return DamageCause.PROJECTILE;
		case SUFFOCATION:
			return DamageCause.SUFFOCATION;
		case FALL:
			return DamageCause.FALL;
		case FIRE:
			return DamageCause.FIRE;
		case FIRE_TICK:
			return DamageCause.FIRE_TICK;
		case LAVA:
			return DamageCause.LAVA;
		case DROWNING:
			return DamageCause.DROWNING;
		case BLOCK_EXPLOSION:
			return DamageCause.BLOCK_EXPLOSION;
		case ENTITY_EXPLOSION:
			return DamageCause.ENTITY_EXPLOSION;
		case VOID:
			return DamageCause.VOID;
		case SUICIDE:
			return DamageCause.SUICIDE;
		case MAGIC:
			return DamageCause.MAGIC;
		case LIGHTNING:
			return DamageCause.LIGHTNING;
		case CUSTOM:
		default:
			return DamageCause.CUSTOM;
	}
}
 
開發者ID:rutgerkok,項目名稱:Pokkit,代碼行數:38,代碼來源:PokkitDamageCause.java

示例15: onEntityDamage

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityDamage(EntityDamageEvent event) {
    Entity entity = event.getEntity();
    World world = entity.getWorld();
    PluginConfig worldConfig = plugin.getConfig(world);

    if (event.getCause() == DamageCause.ENTITY_ATTACK && plugin.isActive(world) && plugin.isFeatureEnabled(world, Feature.SWORD_DAMAGE)) {
        if (entity instanceof Creature) {
            Creature creature = (Creature) entity;
            String creatureName = creature.getType().name().toUpperCase();
            LivingEntity target = creature.getTarget();

            if (target instanceof Player) {
                Player player = (Player) target;
                ItemStack item = player.getItemInHand();
                String itemName = item.getType().name().toUpperCase();

                if (worldConfig.getStringList(Config.FEATURE_SWORD_DAMAGE_MOBS).contains(creatureName) && itemName.endsWith("_SWORD") && this.random.nextInt(100) <= worldConfig.getInt(Config.FEATURE_SWORD_DAMAGE_CHANCE)) {
                    short damage = item.getDurability();
                    short remove = (short) (item.getType().getMaxDurability() / 50);

                    item.setDurability((short) ((damage > remove) ? damage - remove : 1));
                }
            }
        }
    }
}
 
開發者ID:Samistine,項目名稱:BloodMoon,代碼行數:27,代碼來源:SwordDamageListener.java


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