本文整理匯總了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;
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
// }
}
示例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());
}
}
}
示例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;
}
示例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;
}
}
示例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));
}
}
示例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();
}
}
}
}
}
}
}
示例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));
}
}
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例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));
}
}
}
}
}