コード例 #1
0
ファイル: PainSpell.java プロジェクト: Meatzombie/MagicSpells
 private boolean causePain(Player player, LivingEntity target, float power) {
   if (target.isDead()) return false;
   double dam = damage * power;
   if (target instanceof Player && checkPlugins && player != null) {
     // handle the event myself so I can detect cancellation properly
     EntityDamageByEntityEvent event =
         new EntityDamageByEntityEvent(player, target, damageType, dam);
     Bukkit.getServer().getPluginManager().callEvent(event);
     if (event.isCancelled()) {
       return false;
     }
     dam = event.getDamage();
     target.setLastDamageCause(event);
   }
   if (ignoreArmor) {
     double health = target.getHealth();
     if (health > target.getMaxHealth()) health = target.getMaxHealth();
     health = health - dam;
     if (health < 0) health = 0;
     if (health > target.getMaxHealth()) health = target.getMaxHealth();
     if (health == 0 && player != null) {
       MagicSpells.getVolatileCodeHandler().setKiller(target, player);
     }
     target.setHealth(health);
     target.playEffect(EntityEffect.HURT);
   } else {
     target.damage(dam, player);
   }
   if (player != null) {
     playSpellEffects(player, target);
   } else {
     playSpellEffects(EffectPosition.TARGET, target);
   }
   return true;
 }
コード例 #2
0
 @EventHandler
 private void entityDamageByEntityEvent(EntityDamageByEntityEvent event) {
   if (event.isCancelled()
       || !(event.getDamager() instanceof Player)
       || !(event.getEntity() instanceof Player)
       || !(RandomPackage.getEnabledEnchantsConfig()
           .getString("Unique.Curse")
           .equalsIgnoreCase("true"))) {
     return;
   } else {
     Player damager = (Player) event.getDamager();
     Player victim = (Player) event.getEntity();
     if (victim.getInventory().getChestplate() == null
         || !(victim.getInventory().getChestplate().hasItemMeta())
         || !(victim.getInventory().getChestplate().getItemMeta().hasLore())) {
       return;
     } else {
       Bukkit.getScheduler()
           .scheduleSyncDelayedTask(
               RandomPackage.getPlugin(),
               new Runnable() {
                 public void run() {
                   if (event.isCancelled()) {
                     return;
                   } else {
                     Random random = new Random();
                     int chance = 8;
                     int duration = 60;
                     for (int i = 1; i <= 3; i++) {
                       chance = chance + 2;
                       duration = duration + 40;
                       if (victim
                               .getInventory()
                               .getChestplate()
                               .getItemMeta()
                               .getLore()
                               .contains(
                                   ChatColor.translateAlternateColorCodes(
                                       '&',
                                       RandomPackage.getPlugin()
                                           .getConfig()
                                           .getString(
                                               "Enchantments.Unique.Curse.Curse"
                                                   + i
                                                   + ".ItemLore")))
                           && random.nextInt(100) <= chance) {
                         damager.addPotionEffect(
                             new PotionEffect(PotionEffectType.SLOW, duration, 4));
                         return;
                       }
                     }
                     return;
                   }
                 }
               },
               1);
       return;
     }
   }
 }
コード例 #3
0
  /**
   * Monitor EntityDamageByEntity events.
   *
   * @param event The event to monitor
   */
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if (event instanceof FakeEntityDamageByEntityEvent) {
      return;
    }

    Entity defender = event.getEntity();
    Entity attacker = event.getDamager();

    if (attacker instanceof Player && defender instanceof Player) {
      if (!defender.getWorld().getPVP()) {
        return;
      }

      if (Party.getInstance().inSameParty((Player) defender, (Player) attacker)) {
        event.setCancelled(true);
        return;
      }
    }

    /* Check for invincibility */
    if (defender instanceof LivingEntity) {
      LivingEntity livingDefender = (LivingEntity) defender;

      if (!m.isInvincible(livingDefender, event)) {
        // Make sure event isn't cancelled before trying to proc?
        if (!event.isCancelled()) Combat.combatChecks(event, plugin);
      }
    }
  }
コード例 #4
0
  @EventHandler(priority = EventPriority.LOWEST)
  public void entityDamageByEntity(EntityDamageByEntityEvent e) {
    if (e.isCancelled()) return;
    if (!Minegusta.getServer().containsWorld(e.getEntity().getWorld())) return;

    ElfPower arrow = ElfPower.arrowDamage(e);
    DwarfPower axe = DwarfPower.axeBoost(e);
    EnderbornPower bleed = EnderbornPower.bleedBoost(e);
    EnderbornPower pearl = EnderbornPower.enderPearlDamage(e);

    if (arrow.isBowDamage()
        && arrow.isPlayer()
        && arrow.arrowIsFiredByElf()
        && arrow.victimIsLiving()
        && arrow.canPVP()) {
      arrow.applyBowDamage();
    }

    if (axe.isPlayer() && axe.isDwarf() && axe.hasAxe() && axe.canPVP()) {
      axe.applyAxeBoost();
    }

    if (bleed.isPlayer() && bleed.damagerIsEndeborn() && bleed.victimIsLiving() && bleed.canPVP()) {
      bleed.applyBleedBoost();
    }

    if (pearl.isPearl() && pearl.isPlayer() && pearl.entityIsEnderBorn()) {
      pearl.cancelPearlDamage();
    }
  }
コード例 #5
0
  @Test
  public void testWhenCreaturesIsAttackedByNonPlayerEventIsPassed() {
    EntityDamageByEntityEvent event =
        new EntityDamageByEntityEvent(mock(Creeper.class), mockCreature, null, 10.0);

    systemUnderTest.onEntityDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
コード例 #6
0
  @Test
  public void testAdminCanDamageCreaturesWhenInChunk() {
    playerIsAdmin();

    EntityDamageByEntityEvent event =
        new EntityDamageByEntityEvent(mockPlayer, mockCreature, null, 10.0);

    systemUnderTest.onEntityDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
コード例 #7
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    if (event.isCancelled()) return;

    final Entity target = event.getEntity();

    Player attacker = null;
    if (event.getDamager() instanceof Player) {
      attacker = (Player) event.getDamager();
    } else if (event.getDamager() instanceof Projectile) {
      if (((Projectile) event.getDamager()).getShooter() instanceof Player)
        attacker = (Player) ((Projectile) event.getDamager()).getShooter();
    }

    if (target != null && attacker != null) {
      plugin.debug("Attacker: " + attacker + ", Target: " + target + "");

      if (attacker.getWorld() != plugin.getIslandWorld()) return;
      if (attacker.isOp()) return;
      if (attacker.hasPermission("islandworld.bypass.damage")) return;

      if (target instanceof Player) {
        if (!Config.FLAG_PVP) event.setCancelled(true);
      } else {
        if (target instanceof ItemFrame) {
          if (!plugin.canBuildOnLocation(attacker, target.getLocation())) event.setCancelled(true);
        } else if (target instanceof Monster || target instanceof WaterMob) {
          if (plugin.canBuildOnLocation(attacker, target.getLocation())
              || plugin.getConfig().getBoolean("flags.kill-monster", false)) {
          } else {
            event.setCancelled(true);
          }
        } else if (target instanceof Animals || target instanceof NPC) {
          if (plugin.canBuildOnLocation(attacker, target.getLocation())
              || plugin.getConfig().getBoolean("flags.kill-animals", false)) {
          } else {
            event.setCancelled(true);
          }
        }
      }
    }
    plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled());
  }
コード例 #8
0
  @Test
  public void testWhenMonstersAreAttackedByUntrustedPlayersTheyStillGetHurt() {
    playerIsUntrusted();

    EntityDamageByEntityEvent event =
        new EntityDamageByEntityEvent(mockPlayer, mock(Monster.class), null, 10.0);

    systemUnderTest.onEntityDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
コード例 #9
0
  @Override
  public void spellEvent(EntityDamageByEntityEvent event, Player target) {
    Player player = (Player) event.getDamager();
    SuperNPlayer snplayer = SuperNManager.get(player);
    Material itemMaterial = player.getItemInHand().getType();

    boolean cancelled = false;

    if (player.getItemInHand() == null) {
      return;
    }

    if (itemMaterial != null) {
      if (SNConfigHandler.priestSpellMaterials.contains(itemMaterial)) {
        if (itemMaterial.equals(SNConfigHandler.priestSpellMaterials.get(0))) {
          banish(player, target);
          cancelled = true;
        } else if (itemMaterial.equals(SNConfigHandler.priestSpellMaterials.get(1))) {
          exorcise(player, target);
          cancelled = true;
        } else if (itemMaterial.equals(SNConfigHandler.priestSpellMaterials.get(2))) {
          cancelled = cure(player, target, itemMaterial);
        } else if (itemMaterial.equals(SNConfigHandler.priestSpellMaterials.get(3))) {
          cancelled = heal(player, target);
        } else if (itemMaterial.equals(SNConfigHandler.priestSpellMaterials.get(4))) {
          drainPower(player, target);
          cancelled = true;
        }
        if (!event.isCancelled()) {
          event.setCancelled(cancelled);
        }
      } else if (itemMaterial
          .toString()
          .equalsIgnoreCase(SNConfigHandler.priestSpellGuardianAngel)) {
        cancelled = guardianAngel(player, target);
        if (!event.isCancelled()) {
          event.setCancelled(cancelled);
        }
      } else if (itemMaterial.equals(Material.BOWL)) {
        remoteDonations(player);
      }
    }
  }
コード例 #10
0
 @EventHandler(priority = EventPriority.MONITOR)
 public void BlazeBlood(EntityDamageByEntityEvent e) {
   if (e.isCancelled()) return;
   if (e.getEntity() instanceof Blaze) {
     int blood = plugin.getConfig().getInt("Mobs.Blaze");
     e.getEntity()
         .getLocation()
         .getWorld()
         .playEffect(e.getEntity().getLocation().add(0, 1, 0), Effect.STEP_SOUND, blood);
   }
 }
コード例 #11
0
  @Test
  public void testTrustedPlayerCanDamageCreaturesWithProjectilesWhenInChunk() {
    playerIsTrusted();
    playerThrewProjectile();

    EntityDamageByEntityEvent event =
        new EntityDamageByEntityEvent(mockProjectile, mockCreature, null, 10.0);

    systemUnderTest.onEntityDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
コード例 #12
0
  @Test
  public void testUntrustedPlayerCannotDamageCreaturesWhenInChunk() {
    playerIsUntrusted();

    EntityDamageByEntityEvent event =
        new EntityDamageByEntityEvent(mockPlayer, mockCreature, null, 10.0);

    systemUnderTest.onEntityDamage(event);
    Assert.assertTrue(event.isCancelled());
    verify(mockPlayer)
        .sendMessage("§eYou do not have APlayer's permission to hurt creatures here.");
  }
コード例 #13
0
  @Test
  public void testWhenCreaturesIsAttackedByNonPlayerWithProjectileEventIsPassed() {
    Skeleton mockSkeleton = mock(Skeleton.class);
    Projectile mockAttacker = mock(Projectile.class);
    when(mockAttacker.getShooter()).thenReturn(mockSkeleton);

    EntityDamageByEntityEvent event =
        new EntityDamageByEntityEvent(mockAttacker, mockCreature, null, 10.0);

    systemUnderTest.onEntityDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
コード例 #14
0
  /**
   * Entity damaged by another entity event. Cancels the event and sends damager a message if either
   * damager or attacked player have not enabled PvP
   *
   * @param event event being handled
   */
  @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
  public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent event) {
    if (event.getEntity() instanceof Player) {
      final Player attackedPlayer = (Player) event.getEntity();
      final Player attacker;

      if (event.getDamager() instanceof Player) {
        attacker = (Player) event.getDamager();
      } else if (event.getDamager() instanceof Projectile) {
        if (((Projectile) event.getDamager()).getShooter() instanceof Player) {
          attacker = (Player) ((Projectile) event.getDamager()).getShooter();
        } else {
          return;
        }
      } else {
        return;
      }

      final World world = attacker.getWorld();
      final Localisation localisation = plugin.getLocalisation();
      if (PVPConfigUtils.getPlayerStatus(attacker, world, plugin)) {
        if (PVPConfigUtils.getPlayerStatus(attackedPlayer, world, plugin)) {
          LastPVPActionTimeConfigUtils.update(attacker, world, plugin);
          if (DebugConfigUtils.getDebugEnabled(plugin)) {
            attacker.sendMessage(
                localisation.get(
                    LocalisationEntry.DEBUG_ATTACKED_PLAYER,
                    new Object[] {attackedPlayer.getDisplayName(), event.getDamage()}));
            attackedPlayer.sendMessage(
                localisation.get(
                    LocalisationEntry.DEBUG_ATTACKED_BY_PLAYER,
                    new Object[] {attacker.getDisplayName(), event.getDamage()}));
          }
        } else {
          event.setCancelled(true);
          attacker.sendMessage(
              localisation.get(
                  LocalisationEntry.MSG_ATTACK_CANCELLED_PLAYER_DOES_NOT_HAVE_PVP_ENABLED,
                  new Object[] {attackedPlayer.getDisplayName()}));
        }
      } else {
        event.setCancelled(true);
        attacker.sendMessage(
            localisation.get(LocalisationEntry.MSG_ATTACK_CANCELLED_PVP_NOT_ENABLED));
      }

      // Stop arrows bouncing back, possibly hitting you.
      if ((event.isCancelled()) && (event.getDamager() instanceof Projectile)) {
        ((Projectile) event.getDamager()).setBounce(false);
      }
    }
  }
コード例 #15
0
ファイル: Entity.java プロジェクト: dested/CraftbukkitMaps
  public void a(EntityWeatherStorm entityweatherstorm) {
    // CraftBukkit start
    int damage = 5;
    EntityDamageByEntityEvent event =
        new EntityDamageByEntityEvent(
            entityweatherstorm.getBukkitEntity(), getBukkitEntity(), DamageCause.LIGHTNING, damage);
    Bukkit.getServer().getPluginManager().callEvent(event);
    damage = event.getDamage();

    if (event.isCancelled()) {
      return;
    }

    this.a(damage);
    // CraftBukkit end

    ++this.fireTicks;
    if (this.fireTicks == 0) {
      this.fireTicks = 300;
    }
  }
コード例 #16
0
ファイル: Damage.java プロジェクト: frostythedev/COD-Warfare
 @SuppressWarnings("deprecation")
 public static void damage(LivingEntity damager, LivingEntity damagee, double damage) {
   if (damager instanceof Player) {
     Player p = (Player) damager;
     if (!(p.isOnline())) return;
   }
   EntityDamageByEntityEvent event =
       new EntityDamageByEntityEvent(damager, damagee, DamageCause.ENTITY_ATTACK, damage);
   Bukkit.getServer().getPluginManager().callEvent(event);
   if (event.isCancelled()) return;
   if (event.getDamage() != damage) damage = event.getDamage();
   if (damage <= 1) {
     damagee.damage(1, damager);
   } else if (damage >= damagee.getHealth()) {
     damagee.setHealth(1);
     damagee.damage(200, damager);
   } else {
     double damageChanged = damage - 1;
     damagee.damage(damageChanged);
     damagee.damage(3, damager);
   }
 }
コード例 #17
0
    @EventHandler(priority = EventPriority.HIGHEST)
    public void onEntityDamage(EntityDamageByEntityEvent event) {
      if (!(event.getDamager() instanceof Projectile)) return;

      Projectile projectile = (Projectile) event.getDamager();
      ProjectileInfo info = projectiles.get(projectile);
      if (info == null || event.isCancelled()) return;

      if (!(event.getEntity() instanceof LivingEntity)) {
        return;
      }

      projectileHitEntity(projectile, (LivingEntity) event.getEntity(), info);

      if (cancelDamage) {
        event.setCancelled(true);
      }

      if (info.monitor != null) {
        info.monitor.stop();
      }
    }
コード例 #18
0
ファイル: Events.java プロジェクト: Elenw/RPG-Items-2
 private double playerHit(EntityDamageByEntityEvent e, double damage) {
   Player p = (Player) e.getEntity();
   if (e.isCancelled() || !WorldGuard.canPvP(p.getLocation())) return damage;
   String locale = Locale.getPlayerLocale(p);
   ItemStack[] armour = p.getInventory().getArmorContents();
   for (int i = 0; i < armour.length; i++) {
     ItemStack pArmour = armour[i];
     RPGItem pRItem = ItemManager.toRPGItem(pArmour);
     if (pRItem == null) continue;
     if (!WorldGuard.canPvP(p.getLocation()) && !pRItem.ignoreWorldGuard) return damage;
     if (pRItem.getHasPermission() == true && p.hasPermission(pRItem.getPermission()) == false) {
       damage = 0;
       e.setCancelled(true);
       p.sendMessage(
           ChatColor.RED
               + String.format(Locale.get("message.error.permission", Locale.getPlayerLocale(p))));
     }
     if (pRItem.getArmour() > 0) {
       damage -= Math.round(((double) damage) * (((double) pRItem.getArmour()) / 100d));
     }
     RPGMetadata meta = RPGItem.getMetadata(pArmour);
     if (pRItem.getMaxDurability() != -1) {
       int durability =
           meta.containsKey(RPGMetadata.DURABILITY)
               ? ((Number) meta.get(RPGMetadata.DURABILITY)).intValue()
               : pRItem.getMaxDurability();
       durability--;
       if (durability <= 0) {
         armour[i] = null;
       }
       meta.put(RPGMetadata.DURABILITY, Integer.valueOf(durability));
     }
     RPGItem.updateItem(pArmour, locale, meta);
   }
   p.getInventory().setArmorContents(armour);
   p.updateInventory();
   return damage;
 }
コード例 #19
0
 @EventHandler
 public void onEntityDamage(EntityDamageByEntityEvent event) {
   if (event.isCancelled()) return;
   Entity damager = event.getDamager();
   if (event.getDamager() instanceof Projectile && ((Projectile) damager).getShooter() != null)
     damager = ((Projectile) damager).getShooter();
   if (isChameleon(event.getEntity()) && breakDisguiseOnAttacked) {
     Player p = (Player) event.getEntity();
     if (DisguiseAPI.isDisguised(p)) {
       DisguiseAPI.undisguiseToAll(p);
       p.sendMessage(chameleonDisguiseBroken);
     }
   }
   if (isChameleon(damager)) {
     Player p = (Player) damager;
     if (event.getEntity() instanceof Player && DisguiseAPI.isDisguised(p)) {
       if (breakDisguiseOnAttackPlayer) {
         DisguiseAPI.undisguiseToAll(p);
         p.sendMessage(chameleonBreakDisguise);
       }
     } else disguise(event.getEntity(), p);
   }
 }
コード例 #20
0
  @EventHandler(priority = EventPriority.LOWEST)
  public void onEntityDamage(EntityDamageByEntityEvent event) {
    if (damage <= 0 || event.isCancelled() || !(event.getEntity() instanceof LivingEntity)) return;

    if (!(event.getDamager() instanceof Snowball)
        || event.getDamager().getFallDistance() != identifier) return;

    LivingEntity entity = (LivingEntity) event.getEntity();

    if (validTargetList.canTarget(entity)) {
      float power = 1;
      SpellTargetEvent e =
          new SpellTargetEvent(
              this, (Player) ((Snowball) event.getDamager()).getShooter(), entity, power);
      Bukkit.getPluginManager().callEvent(e);
      if (e.isCancelled()) {
        event.setCancelled(true);
      } else {
        event.setDamage(damage * e.getPower());
      }
    } else {
      event.setCancelled(true);
    }
  }
コード例 #21
0
ファイル: Bleed.java プロジェクト: GRANTSWIM4/MGRacesRedone
  public boolean bleed() {
    if (target == null || damager == null || target.isDead()) return false;
    if (damager instanceof Player && !Bukkit.getOfflinePlayer(damager.getUniqueId()).isOnline()) {
      return false;
    }

    EntityDamageByEntityEvent e =
        new EntityDamageByEntityEvent(damager, target, EntityDamageEvent.DamageCause.CUSTOM, 1);

    Bukkit.getPluginManager().callEvent(e);

    if (WGUtil.canGetDamage(target) && !e.isCancelled()) {
      target.damage(e.getDamage());
      target.setLastDamageCause(e);
      if (target instanceof Player) {
        target.sendMessage(ChatColor.DARK_RED + "You are bleeding..");
      }
    }
    EffectUtil.playParticle(target, Effect.CRIT);

    duration--;

    return duration > 0;
  }
コード例 #22
0
ファイル: CombatTag.java プロジェクト: CodeMyAss/Hardcore-2.0
  @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
  public void onDamage(EntityDamageByEntityEvent e) {
    if (e.isCancelled()) {
      System.out.println("Event is cancelled. Ignoring...");
      return;
    }
    if (e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
      final Player damaged = (Player) e.getEntity();
      final Player damager = (Player) e.getDamager();
      if (!inCombat.containsKey(damaged.getName())) {
        damaged.sendMessage(ChatColor.RED + "You are now in combat!");
        final Scoreboard scoreboard = damaged.getScoreboard();
        Objective objective =
            scoreboard.getObjective("timers") == null
                ? scoreboard.registerNewObjective("timers", "dummy")
                : scoreboard.getObjective("timers");
        objective.setDisplayName("§6Timers");
        objective.setDisplaySlot(DisplaySlot.SIDEBAR);
        final Score combatTag = objective.getScore("§aCombat Tag");
        combatTag.setScore(60);
        // damaged.setScoreboard(scoreboard);
        inCombatTag.put(
            damaged.getName(),
            new BukkitRunnable() {
              @Override
              public void run() {
                if (inCombat.get(damaged.getName()) != null) {
                  if (inCombat.get(damaged.getName()) > 0) {
                    inCombat.put(damaged.getName(), inCombat.get(damaged.getName()) - 1);
                    combatTag.setScore(inCombat.get(damaged.getName()));
                  } else {
                    inCombat.remove(damaged.getName());
                    damaged.sendMessage(ChatColor.GREEN + "You are no longer in combat.");
                    scoreboard.resetScores("§aCombat Tag");
                    this.cancel();
                    inCombatTag.remove(damager.getName());
                  }
                }
              }
            });
        inCombatTag
            .get(damaged.getName())
            .runTaskTimerAsynchronously(Hardcore.getPlugin(Hardcore.class), 20L, 20L);
      }
      if (!inCombat.containsKey(damager.getName())) {
        damager.sendMessage(ChatColor.RED + "You are now in combat!");
        final Scoreboard scoreboard2 = damager.getScoreboard();
        Objective objective2 =
            scoreboard2.getObjective("timers") == null
                ? scoreboard2.registerNewObjective("timers", "dummy")
                : scoreboard2.getObjective("timers");
        objective2.setDisplayName("§6Timers");
        objective2.setDisplaySlot(DisplaySlot.SIDEBAR);
        final Score combatTag2 = objective2.getScore("§aCombat Tag");
        combatTag2.setScore(60);
        //    damager.setScoreboard(scoreboard2);
        inCombatTag.put(
            damager.getName(),
            new BukkitRunnable() {
              @Override
              public void run() {
                if (inCombat.get(damager.getName()) != null) {
                  if (inCombat.get(damager.getName()) > 0) {
                    inCombat.put(damager.getName(), inCombat.get(damager.getName()) - 1);
                    combatTag2.setScore(inCombat.get(damager.getName()));

                  } else {
                    inCombat.remove(damager.getName());
                    damager.sendMessage(ChatColor.GREEN + "You are no longer in combat.");
                    scoreboard2.resetScores("§aCombat Tag");
                    this.cancel();
                    inCombatTag.remove(damager.getName());
                  }
                }
              }
            });
        inCombatTag
            .get(damager.getName())
            .runTaskTimerAsynchronously(Hardcore.getPlugin(Hardcore.class), 20L, 20L);
      }
      inCombat.put(damaged.getName(), 60);
      inCombat.put(damager.getName(), 60);
    }

    if (e.getEntity() instanceof Player && e.getDamager() instanceof Projectile) {
      final Player damaged = (Player) e.getEntity();
      Projectile projectile = (Projectile) e.getDamager();

      if (projectile.getShooter() instanceof Player) {
        final Player damager = (Player) projectile.getShooter();

        if (damager.equals(damaged)) {
          return;
        }

        if (!inCombat.containsKey(damaged.getName())) {
          damaged.sendMessage(ChatColor.RED + "You are now in combat!");
          final Scoreboard scoreboard = damaged.getScoreboard();
          Objective objective =
              scoreboard.getObjective("ct") == null
                  ? scoreboard.registerNewObjective("ct", "dummy")
                  : scoreboard.getObjective("ct");
          objective.setDisplayName("§6Timers");
          objective.setDisplaySlot(DisplaySlot.SIDEBAR);
          final Score combatTag = objective.getScore("§aCombat Tag");
          combatTag.setScore(60);
          // damaged.setScoreboard(scoreboard);
          inCombatTag.put(
              damaged.getName(),
              new BukkitRunnable() {
                @Override
                public void run() {
                  if (inCombat.get(damaged.getName()) != null) {
                    if (inCombat.get(damaged.getName()) > 0) {
                      inCombat.put(damaged.getName(), inCombat.get(damaged.getName()) - 1);
                      combatTag.setScore(inCombat.get(damaged.getName()));
                    } else {
                      inCombat.remove(damaged.getName());
                      damaged.sendMessage(ChatColor.GREEN + "You are no longer in combat.");
                      scoreboard.resetScores("§aCombat Tag");
                      this.cancel();
                      inCombatTag.remove(damager.getName());
                    }
                  }
                }
              });
          inCombatTag
              .get(damaged.getName())
              .runTaskTimerAsynchronously(Hardcore.getPlugin(Hardcore.class), 20L, 20L);
        }
        if (!inCombat.containsKey(damager.getName())) {
          damager.sendMessage(ChatColor.RED + "You are now in combat!");
          final Scoreboard scoreboard2 = damager.getScoreboard();
          Objective objective2 =
              scoreboard2.getObjective("ct") == null
                  ? scoreboard2.registerNewObjective("ct", "dummy")
                  : scoreboard2.getObjective("ct");
          objective2.setDisplayName("§6Timers");
          objective2.setDisplaySlot(DisplaySlot.SIDEBAR);
          final Score combatTag2 = objective2.getScore("§aCombat Tag");
          combatTag2.setScore(60);
          //    damager.setScoreboard(scoreboard2);
          inCombatTag.put(
              damager.getName(),
              new BukkitRunnable() {
                @Override
                public void run() {
                  if (inCombat.get(damager.getName()) != null) {
                    if (inCombat.get(damager.getName()) > 0) {
                      inCombat.put(damager.getName(), inCombat.get(damager.getName()) - 1);
                      combatTag2.setScore(inCombat.get(damager.getName()));

                    } else {
                      inCombat.remove(damager.getName());
                      damager.sendMessage(ChatColor.GREEN + "You are no longer in combat.");
                      scoreboard2.resetScores("§aCombat Tag");
                      this.cancel();
                      inCombatTag.remove(damager.getName());
                    }
                  }
                }
              });
          inCombatTag
              .get(damager.getName())
              .runTaskTimerAsynchronously(Hardcore.getPlugin(Hardcore.class), 20L, 20L);
        }
        inCombat.put(damaged.getName(), 60);
        inCombat.put(damager.getName(), 60);
      }
    }
  }
コード例 #23
0
ファイル: EntityArrow.java プロジェクト: MDAWG25/backup
  public void w_() {
    super.w_();
    if (this.lastPitch == 0.0F && this.lastYaw == 0.0F) {
      float f = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ);

      this.lastYaw =
          this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D);
      this.lastPitch =
          this.pitch = (float) (Math.atan2(this.motY, (double) f) * 180.0D / 3.1415927410125732D);
    }

    int i = this.world.getTypeId(this.e, this.f, this.g);

    if (i > 0) {
      Block.byId[i].updateShape(this.world, this.e, this.f, this.g);
      AxisAlignedBB axisalignedbb = Block.byId[i].e(this.world, this.e, this.f, this.g);

      if (axisalignedbb != null && axisalignedbb.a(Vec3D.create(this.locX, this.locY, this.locZ))) {
        this.inGround = true;
      }
    }

    if (this.shake > 0) {
      --this.shake;
    }

    if (this.inGround) {
      i = this.world.getTypeId(this.e, this.f, this.g);
      int j = this.world.getData(this.e, this.f, this.g);

      if (i == this.h && j == this.i) {
        ++this.k;
        if (this.k == 1200) {
          this.die();
        }
      } else {
        this.inGround = false;
        this.motX *= (double) (this.random.nextFloat() * 0.2F);
        this.motY *= (double) (this.random.nextFloat() * 0.2F);
        this.motZ *= (double) (this.random.nextFloat() * 0.2F);
        this.k = 0;
        this.l = 0;
      }
    } else {
      ++this.l;
      Vec3D vec3d = Vec3D.create(this.locX, this.locY, this.locZ);
      Vec3D vec3d1 =
          Vec3D.create(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
      MovingObjectPosition movingobjectposition = this.world.rayTrace(vec3d, vec3d1, false, true);

      vec3d = Vec3D.create(this.locX, this.locY, this.locZ);
      vec3d1 = Vec3D.create(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
      if (movingobjectposition != null) {
        vec3d1 =
            Vec3D.create(
                movingobjectposition.f.a, movingobjectposition.f.b, movingobjectposition.f.c);
      }

      Entity entity = null;
      List list =
          this.world.b(
              (Entity) this,
              this.boundingBox.a(this.motX, this.motY, this.motZ).b(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;

      int k;
      float f1;

      for (k = 0; k < list.size(); ++k) {
        Entity entity1 = (Entity) list.get(k);

        if (entity1.e_() && (entity1 != this.shooter || this.l >= 5)) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 =
              entity1.boundingBox.b((double) f1, (double) f1, (double) f1);
          MovingObjectPosition movingobjectposition1 = axisalignedbb1.a(vec3d, vec3d1);

          if (movingobjectposition1 != null) {
            double d1 = vec3d.b(movingobjectposition1.f);

            if (d1 < d0 || d0 == 0.0D) {
              entity = entity1;
              d0 = d1;
            }
          }
        }
      }

      if (entity != null) {
        movingobjectposition = new MovingObjectPosition(entity);
      }

      float f2;

      if (movingobjectposition != null) {
        // CraftBukkit start
        ProjectileHitEvent phe = new ProjectileHitEvent((Projectile) this.getBukkitEntity());
        this.world.getServer().getPluginManager().callEvent(phe);
        // CraftBukkit end
        if (movingobjectposition.entity != null) {
          f2 = MathHelper.a(this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
          int l = (int) Math.ceil((double) f2 * 2.0D);

          if (this.d) {
            l += this.random.nextInt(l / 2 + 2);
          }

          DamageSource damagesource = null;

          if (this.shooter == null) {
            damagesource = DamageSource.arrow(this, this);
          } else {
            damagesource = DamageSource.arrow(this, this.shooter);
          }

          // CraftBukkit start
          boolean stick;
          if (entity instanceof EntityLiving) {

            org.bukkit.entity.Entity damagee = movingobjectposition.entity.getBukkitEntity();
            Projectile projectile = (Projectile) this.getBukkitEntity();

            EntityDamageByEntityEvent event =
                new EntityDamageByEntityEvent(
                    projectile, damagee, EntityDamageEvent.DamageCause.PROJECTILE, l);
            Bukkit.getPluginManager().callEvent(event);

            if (event.isCancelled()) {
              stick = !projectile.doesBounce();
            } else {
              // this function returns if the arrow should stick in or not, i.e. !bounce
              stick = movingobjectposition.entity.damageEntity(damagesource, event.getDamage());
            }
          } else {
            stick = movingobjectposition.entity.damageEntity(damagesource, l);
          }
          if (stick) {
            // CraftBukkit end
            if (movingobjectposition.entity instanceof EntityLiving) {
              ++((EntityLiving) movingobjectposition.entity).aH;
            }

            this.world.makeSound(
                this, "random.bowhit", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
            this.die();
          } else {
            this.motX *= -0.10000000149011612D;
            this.motY *= -0.10000000149011612D;
            this.motZ *= -0.10000000149011612D;
            this.yaw += 180.0F;
            this.lastYaw += 180.0F;
            this.l = 0;
          }
        } else {
          this.e = movingobjectposition.b;
          this.f = movingobjectposition.c;
          this.g = movingobjectposition.d;
          this.h = this.world.getTypeId(this.e, this.f, this.g);
          this.i = this.world.getData(this.e, this.f, this.g);
          this.motX = (double) ((float) (movingobjectposition.f.a - this.locX));
          this.motY = (double) ((float) (movingobjectposition.f.b - this.locY));
          this.motZ = (double) ((float) (movingobjectposition.f.c - this.locZ));
          f2 = MathHelper.a(this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
          this.locX -= this.motX / (double) f2 * 0.05000000074505806D;
          this.locY -= this.motY / (double) f2 * 0.05000000074505806D;
          this.locZ -= this.motZ / (double) f2 * 0.05000000074505806D;
          this.world.makeSound(
              this, "random.bowhit", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
          this.inGround = true;
          this.shake = 7;
          this.d = false;
        }
      }

      if (this.d) {
        for (k = 0; k < 4; ++k) {
          this.world.a(
              "crit",
              this.locX + this.motX * (double) k / 4.0D,
              this.locY + this.motY * (double) k / 4.0D,
              this.locZ + this.motZ * (double) k / 4.0D,
              -this.motX,
              -this.motY + 0.2D,
              -this.motZ);
        }
      }

      this.locX += this.motX;
      this.locY += this.motY;
      this.locZ += this.motZ;
      f2 = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ);
      this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D);

      for (this.pitch = (float) (Math.atan2(this.motY, (double) f2) * 180.0D / 3.1415927410125732D);
          this.pitch - this.lastPitch < -180.0F;
          this.lastPitch -= 360.0F) {;
      }

      while (this.pitch - this.lastPitch >= 180.0F) {
        this.lastPitch += 360.0F;
      }

      while (this.yaw - this.lastYaw < -180.0F) {
        this.lastYaw -= 360.0F;
      }

      while (this.yaw - this.lastYaw >= 180.0F) {
        this.lastYaw += 360.0F;
      }

      this.pitch = this.lastPitch + (this.pitch - this.lastPitch) * 0.2F;
      this.yaw = this.lastYaw + (this.yaw - this.lastYaw) * 0.2F;
      float f3 = 0.99F;

      f1 = 0.05F;
      if (this.az()) {
        for (int i1 = 0; i1 < 4; ++i1) {
          float f4 = 0.25F;

          this.world.a(
              "bubble",
              this.locX - this.motX * (double) f4,
              this.locY - this.motY * (double) f4,
              this.locZ - this.motZ * (double) f4,
              this.motX,
              this.motY,
              this.motZ);
        }

        f3 = 0.8F;
      }

      this.motX *= (double) f3;
      this.motY *= (double) f3;
      this.motZ *= (double) f3;
      this.motY -= (double) f1;
      this.setPosition(this.locX, this.locY, this.locZ);
    }
  }
コード例 #24
0
ファイル: Explosion.java プロジェクト: mousesrc/CraftBukkit
  public void a() {
    // CraftBukkit start
    if (this.size < 0.1F) {
      return;
    }
    // CraftBukkit end

    float f = this.size;
    HashSet hashset = new HashSet();

    int i;
    int j;
    int k;
    double d0;
    double d1;
    double d2;

    for (i = 0; i < this.i; ++i) {
      for (j = 0; j < this.i; ++j) {
        for (k = 0; k < this.i; ++k) {
          if (i == 0 || i == this.i - 1 || j == 0 || j == this.i - 1 || k == 0 || k == this.i - 1) {
            double d3 = (double) ((float) i / ((float) this.i - 1.0F) * 2.0F - 1.0F);
            double d4 = (double) ((float) j / ((float) this.i - 1.0F) * 2.0F - 1.0F);
            double d5 = (double) ((float) k / ((float) this.i - 1.0F) * 2.0F - 1.0F);
            double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5);

            d3 /= d6;
            d4 /= d6;
            d5 /= d6;
            float f1 = this.size * (0.7F + this.world.random.nextFloat() * 0.6F);

            d0 = this.posX;
            d1 = this.posY;
            d2 = this.posZ;

            for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) {
              int l = MathHelper.floor(d0);
              int i1 = MathHelper.floor(d1);
              int j1 = MathHelper.floor(d2);
              int k1 = this.world.getTypeId(l, i1, j1);

              if (k1 > 0) {
                Block block = Block.byId[k1];
                float f3 =
                    this.source != null
                        ? this.source.a(this, this.world, l, i1, j1, block)
                        : block.a(this.source);

                f1 -= (f3 + 0.3F) * f2;
              }

              if (f1 > 0.0F
                  && (this.source == null || this.source.a(this, this.world, l, i1, j1, k1, f1))
                  && i1 < 256
                  && i1 >= 0) { // CraftBukkit - don't wrap explosions
                hashset.add(new ChunkPosition(l, i1, j1));
              }

              d0 += d3 * (double) f2;
              d1 += d4 * (double) f2;
              d2 += d5 * (double) f2;
            }
          }
        }
      }
    }

    this.blocks.addAll(hashset);
    this.size *= 2.0F;
    i = MathHelper.floor(this.posX - (double) this.size - 1.0D);
    j = MathHelper.floor(this.posX + (double) this.size + 1.0D);
    k = MathHelper.floor(this.posY - (double) this.size - 1.0D);
    int l1 = MathHelper.floor(this.posY + (double) this.size + 1.0D);
    int i2 = MathHelper.floor(this.posZ - (double) this.size - 1.0D);
    int j2 = MathHelper.floor(this.posZ + (double) this.size + 1.0D);
    List list =
        this.world.getEntities(
            this.source,
            AxisAlignedBB.a()
                .a((double) i, (double) k, (double) i2, (double) j, (double) l1, (double) j2));
    Vec3D vec3d = this.world.getVec3DPool().create(this.posX, this.posY, this.posZ);

    for (int k2 = 0; k2 < list.size(); ++k2) {
      Entity entity = (Entity) list.get(k2);
      double d7 = entity.f(this.posX, this.posY, this.posZ) / (double) this.size;

      if (d7 <= 1.0D) {
        d0 = entity.locX - this.posX;
        d1 = entity.locY + (double) entity.getHeadHeight() - this.posY;
        d2 = entity.locZ - this.posZ;
        double d8 = (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);

        if (d8 != 0.0D) {
          d0 /= d8;
          d1 /= d8;
          d2 /= d8;
          double d9 = (double) this.world.a(vec3d, entity.boundingBox);
          double d10 = (1.0D - d7) * d9;

          // CraftBukkit start - Explosion damage hook
          org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
          float damageDone =
              (float) ((int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D));

          if (damagee == null) {
            // nothing was hurt
          } else if (this.source == null) { // Block explosion (without an entity source; bed etc.)
            EntityDamageByBlockEvent event =
                new EntityDamageByBlockEvent(
                    null, damagee, EntityDamageEvent.DamageCause.BLOCK_EXPLOSION, damageDone);
            Bukkit.getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
              damagee.setLastDamageCause(event);
              entity.damageEntity(DamageSource.explosion(this), (float) event.getDamage());
              double d11 = EnchantmentProtection.a(entity, d10);

              entity.motX += d0 * d11;
              entity.motY += d1 * d11;
              entity.motZ += d2 * d11;
              if (entity instanceof EntityHuman) {
                this.l.put(
                    (EntityHuman) entity,
                    this.world.getVec3DPool().create(d0 * d10, d1 * d10, d2 * d10));
              }
            }
          } else {
            final org.bukkit.entity.Entity damager = this.source.getBukkitEntity();
            final EntityDamageEvent.DamageCause damageCause;

            if (damager instanceof org.bukkit.entity.TNTPrimed) {
              damageCause = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;
            } else {
              damageCause = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION;
            }

            EntityDamageByEntityEvent event =
                new EntityDamageByEntityEvent(damager, damagee, damageCause, damageDone);
            Bukkit.getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
              entity.getBukkitEntity().setLastDamageCause(event);
              entity.damageEntity(DamageSource.explosion(this), (float) event.getDamage());

              entity.motX += d0 * d10;
              entity.motY += d1 * d10;
              entity.motZ += d2 * d10;
              if (entity instanceof EntityHuman) {
                this.l.put(
                    (EntityHuman) entity,
                    this.world.getVec3DPool().create(d0 * d10, d1 * d10, d2 * d10));
              }
            }
          }
          // CraftBukkit end
        }
      }
    }

    this.size = f;
  }
コード例 #25
0
  /**
   * parsing of damage: Entity vs Entity
   *
   * @param event the triggering event
   */
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {

    if (event.isCancelled()) {
      return;
    }

    Entity p1 = event.getDamager();
    Entity p2 = event.getEntity();

    db.i(
        "onEntityDamageByEntity: cause: "
            + event.getCause().name()
            + " : "
            + event.getDamager().toString()
            + " => "
            + event.getEntity().toString());

    if (p1 instanceof Projectile) {
      db.i("parsing projectile");
      p1 = ((Projectile) p1).getShooter();
      db.i("=> " + String.valueOf(p1));
    }

    if (event.getEntity() instanceof Wolf) {
      Wolf wolf = (Wolf) event.getEntity();
      if (wolf.getOwner() != null) {
        try {
          p1 = (Entity) wolf.getOwner();
        } catch (Exception e) {
          // wolf belongs to dead player or whatnot
        }
      }
    }

    if ((p1 != null && p2 != null) && p1 instanceof Player && p2 instanceof Player) {
      if (PVPArena.instance.getConfig().getBoolean("onlyPVPinArena")) {
        event.setCancelled(true); // cancel events for regular no PVP
        // servers
      }
    }

    if ((p2 == null) || (!(p2 instanceof Player))) {
      return;
    }

    Arena arena = Arenas.getArenaByPlayer((Player) p2);
    if (arena == null) {
      // defender no arena player => out
      return;
    }

    db.i("onEntityDamageByEntity: fighting player");

    if ((p1 == null) || (!(p1 instanceof Player))) {
      // attacker no player => out!
      return;
    }

    db.i("both entities are players");
    Player attacker = (Player) p1;
    Player defender = (Player) p2;

    if (attacker.equals(defender)) {
      // player attacking himself. ignore!
      return;
    }

    boolean defTeam = false;
    boolean attTeam = false;
    ArenaPlayer apDefender = ArenaPlayer.parsePlayer(defender);
    ArenaPlayer apAttacker = ArenaPlayer.parsePlayer(attacker);

    for (ArenaTeam team : arena.getTeams()) {
      defTeam = defTeam ? true : team.getTeamMembers().contains(apDefender);
      attTeam = attTeam ? true : team.getTeamMembers().contains(apAttacker);
    }

    if (!defTeam || !attTeam || arena.REALEND_ID != -1) {
      event.setCancelled(true);
      return;
    }

    db.i("both players part of the arena");

    if (PVPArena.instance.getConfig().getBoolean("onlyPVPinArena")) {
      event.setCancelled(false); // uncancel events for regular no PVP
      // servers
    }

    if ((!arena.cfg.getBoolean("game.teamKill", false))
        && (Teams.getTeam(arena, apAttacker)).equals(Teams.getTeam(arena, apDefender))) {
      // no team fights!
      db.i("team hit, cancel!");
      event.setCancelled(true);
      return;
    }

    if (!arena.fightInProgress) {
      // fight not started, cancel!
      event.setCancelled(true);
      return;
    }

    if (arena.cfg.getBoolean("game.weaponDamage")) {
      if (Inventories.receivesDamage(attacker.getItemInHand())) {
        attacker.getItemInHand().setDurability((short) 0);
      }
    }

    // TODO NOT LAGGING

    if (arena.cfg.getInt("protection.spawn") > 0) {
      if (Spawns.isNearSpawn(arena, defender, arena.cfg.getInt("protection.spawn"))) {
        // spawn protection!
        db.i("spawn protection! damage cancelled!");
        event.setCancelled(true);
        return;
      }
    }

    // here it comes, process the damage!

    db.i("processing damage!");

    PVPArena.instance.getAmm().onEntityDamageByEntity(arena, attacker, defender, event);

    Statistics.damage(arena, attacker, defender, event.getDamage());
  }
コード例 #26
0
ファイル: Explosion.java プロジェクト: tahg/CraftPail
  public void a() {
    float f = this.size;
    byte b0 = 16;

    int i;
    int j;
    int k;
    double d0;
    double d1;
    double d2;

    for (i = 0; i < b0; ++i) {
      for (j = 0; j < b0; ++j) {
        for (k = 0; k < b0; ++k) {
          if (i == 0 || i == b0 - 1 || j == 0 || j == b0 - 1 || k == 0 || k == b0 - 1) {
            double d3 = (double) ((float) i / ((float) b0 - 1.0F) * 2.0F - 1.0F);
            double d4 = (double) ((float) j / ((float) b0 - 1.0F) * 2.0F - 1.0F);
            double d5 = (double) ((float) k / ((float) b0 - 1.0F) * 2.0F - 1.0F);
            double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5);

            d3 /= d6;
            d4 /= d6;
            d5 /= d6;
            float f1 = this.size * (0.7F + this.world.random.nextFloat() * 0.6F);

            d0 = this.posX;
            d1 = this.posY;
            d2 = this.posZ;

            for (float f2 = 0.3F; f1 > 0.0F; f1 -= f2 * 0.75F) {
              int l = MathHelper.floor(d0);
              int i1 = MathHelper.floor(d1);
              int j1 = MathHelper.floor(d2);
              int k1 = this.world.getTypeId(l, i1, j1);

              if (k1 > 0) {
                f1 -= (Block.byId[k1].a(this.source) + 0.3F) * f2;
              }

              if (f1 > 0.0F) {
                this.g.add(new ChunkPosition(l, i1, j1));
              }

              d0 += d3 * (double) f2;
              d1 += d4 * (double) f2;
              d2 += d5 * (double) f2;
            }
          }
        }
      }
    }

    this.size *= 2.0F;
    i = MathHelper.floor(this.posX - (double) this.size - 1.0D);
    j = MathHelper.floor(this.posX + (double) this.size + 1.0D);
    k = MathHelper.floor(this.posY - (double) this.size - 1.0D);
    int l1 = MathHelper.floor(this.posY + (double) this.size + 1.0D);
    int i2 = MathHelper.floor(this.posZ - (double) this.size - 1.0D);
    int j2 = MathHelper.floor(this.posZ + (double) this.size + 1.0D);
    List list =
        this.world.b(
            this.source,
            AxisAlignedBB.b(
                (double) i, (double) k, (double) i2, (double) j, (double) l1, (double) j2));
    Vec3D vec3d = Vec3D.create(this.posX, this.posY, this.posZ);

    for (int k2 = 0; k2 < list.size(); ++k2) {
      Entity entity = (Entity) list.get(k2);
      double d7 = entity.e(this.posX, this.posY, this.posZ) / (double) this.size;

      if (d7 <= 1.0D) {
        d0 = entity.locX - this.posX;
        d1 = entity.locY - this.posY;
        d2 = entity.locZ - this.posZ;
        double d8 = (double) MathHelper.a(d0 * d0 + d1 * d1 + d2 * d2);

        d0 /= d8;
        d1 /= d8;
        d2 /= d8;
        double d9 = (double) this.world.a(vec3d, entity.boundingBox);
        double d10 = (1.0D - d7) * d9;

        // CraftBukkit start - explosion damage hook
        CraftServer server = ((WorldServer) this.world).getServer();
        org.bukkit.entity.Entity damagee = (entity == null) ? null : entity.getBukkitEntity();
        DamageCause damageType;
        int damageDone = (int) ((d10 * d10 + d10) / 2.0D * 8.0D * (double) this.size + 1.0D);

        if (damagee == null) {
          // nothing was hurt
        } else if (this.source == null) { // Block explosion
          // TODO: get the x/y/z of the tnt block?
          // does this even get called ever? @see EntityTNTPrimed - not BlockTNT or whatever
          damageType = EntityDamageEvent.DamageCause.BLOCK_EXPLOSION;

          EntityDamageByBlockEvent event =
              new EntityDamageByBlockEvent(null, damagee, damageType, damageDone);
          server.getPluginManager().callEvent(event);

          if (!event.isCancelled()) {
            entity.damageEntity(this.source, event.getDamage());
            entity.motX += d0 * d10;
            entity.motY += d1 * d10;
            entity.motZ += d2 * d10;
          }
        } else {
          org.bukkit.entity.Entity damager = this.source.getBukkitEntity();
          damageType = EntityDamageEvent.DamageCause.ENTITY_EXPLOSION;

          EntityDamageByEntityEvent event =
              new EntityDamageByEntityEvent(damager, damagee, damageType, damageDone);
          server.getPluginManager().callEvent(event);

          if (!event.isCancelled()) {
            entity.damageEntity(this.source, event.getDamage());

            entity.motX += d0 * d10;
            entity.motY += d1 * d10;
            entity.motZ += d2 * d10;
          }
        }
        // CraftBukkit end
      }
    }

    this.size = f;
    ArrayList arraylist = new ArrayList();

    arraylist.addAll(this.g);
    if (this.a) {
      for (int l2 = arraylist.size() - 1; l2 >= 0; --l2) {
        ChunkPosition chunkposition = (ChunkPosition) arraylist.get(l2);
        int i3 = chunkposition.x;
        int j3 = chunkposition.y;
        int k3 = chunkposition.z;
        int l3 = this.world.getTypeId(i3, j3, k3);
        int i4 = this.world.getTypeId(i3, j3 - 1, k3);

        if (l3 == 0 && Block.o[i4] && this.h.nextInt(3) == 0) {
          this.world.setTypeId(i3, j3, k3, Block.FIRE.id);
        }
      }
    }
  }
コード例 #27
0
 public void onEntityDamagedByEntity(EntityDamageByEntityEvent event) {
   Entity att = event.getDamager();
   Entity def = event.getEntity();
   if (((att instanceof PlayerEvent) && (def instanceof PlayerEvent))
       || ((att instanceof Player) && (def instanceof Player))) {
     Player attacker = ((PlayerEvent) att).getPlayer();
     Player defender = ((PlayerEvent) def).getPlayer();
     int amount = event.getDamage();
     if (SafePVPListener1.accepted) {
       if (SafePVPListener1.finished) {
         if (!event.isCancelled()) {
           event.setCancelled(true);
         }
       } else {
         if (SafePVPListener1.sparList.contains(attacker.getName().toLowerCase())
             && SafePVPListener1.sparList.contains(defender.getName().toLowerCase())) {
           if (defender.getHealth() - amount <= 0) {
             plugin
                 .getServer()
                 .broadcastMessage(
                     SafePVPListener1.spar
                         + attacker.getName()
                         + " has won the spar between "
                         + defender.getName()
                         + "! Congratulations!");
             SafePVPListener1.finished = true;
             SafePVPListener1.inProgress = false;
             SafePVPListener1.accepted = false;
             SafePVPListener1.valid = false;
             SafePVPListener1.waiting = false;
             SafePVPListener1.sparList.remove(attacker.getName().toLowerCase());
             SafePVPListener1.sparList.remove(defender.getName().toLowerCase());
           }
         }
       }
     }
     if (SafePVPListener1.iAccepted) {
       if (SafePVPListener1.iFinished) {
         if (!event.isCancelled()) {
           event.setCancelled(true);
         }
       } else {
         if (SafePVPListener1.iSparList.contains(attacker.getName().toLowerCase())
             && SafePVPListener1.iSparList.contains(defender.getName().toLowerCase())) {
           if (defender.getHealth() - amount <= 0) {
             plugin
                 .getServer()
                 .broadcastMessage(
                     SafePVPListener1.duel
                         + attacker.getName()
                         + " has won the iSpar between "
                         + defender.getName()
                         + "!");
             //  plugin.getServer().broadcastMessage(SafePVPListener1.duel + attacker.getName() + "
             // has been credited " + SafePVPListener1.iWin + " " + SafePVPListener1.currency +
             // "!");
             //	int balance = Hooked.getInt("iBalance", new Object[] { "balance",
             // attacker.getName() });
             //	int newBalance = (balance+iWin);
             //	Hooked.silent("iBalance", new Object[] { "set", attacker.getName(), newBalance });
             SafePVPListener1.iFinished = true;
             SafePVPListener1.iInProgress = false;
             SafePVPListener1.iAccepted = false;
             SafePVPListener1.iValid = false;
             SafePVPListener1.iWaiting = false;
             SafePVPListener1.iSparList.remove(attacker.getName().toLowerCase());
             SafePVPListener1.iSparList.remove(defender.getName().toLowerCase());
           }
         }
       }
     }
     if (SafePVPListener1.sparList.contains(defender.getName().toLowerCase())
         && SafePVPListener1.accepted) {
       attacker.sendMessage(
           SafePVPListener1.spar
               + ChatColor.DARK_AQUA
               + defender.getName()
               + ChatColor.WHITE
               + " is participating in a spar and you aren't their partner.");
     }
     if (SafePVPListener1.sparList.contains(attacker.getName().toLowerCase())
         && SafePVPListener1.accepted) {
       attacker.sendMessage(
           SafePVPListener1.spar
               + "You are sparring and "
               + ChatColor.DARK_AQUA
               + defender.getName()
               + ChatColor.WHITE
               + " isn't your partner.");
     }
     if (SafePVPListener1.iSparList.contains(defender.getName().toLowerCase())
         && SafePVPListener1.iAccepted) {
       attacker.sendMessage(
           SafePVPListener1.duel
               + ChatColor.DARK_AQUA
               + defender.getName()
               + ChatColor.WHITE
               + " is participating in an iSpar and you aren't their partner.");
     }
     if (SafePVPListener1.iSparList.contains(attacker.getName().toLowerCase())
         && SafePVPListener1.iAccepted) {
       attacker.sendMessage(
           SafePVPListener1.duel
               + "You are iSparring and "
               + ChatColor.DARK_AQUA
               + defender.getName()
               + ChatColor.WHITE
               + " isn't your partner.");
     }
     if (SafePVPListener1.noPvp.contains(defender.getName())) {
       if (SafePVPListener1.yesMsg.contains(defender.getName())) {
         defender.sendMessage(
             SafePVPListener1.prefix
                 + "The no PVP list protects you from "
                 + ChatColor.DARK_AQUA
                 + attacker.getName()
                 + ChatColor.WHITE
                 + ".");
       }
       if (SafePVPListener1.yesMsg.contains(attacker.getName())) {
         attacker.sendMessage(
             SafePVPListener1.prefix
                 + ChatColor.DARK_AQUA
                 + defender.getName()
                 + ChatColor.WHITE
                 + " is on the no PVP list. You can't damage them.");
       }
     }
     if (SafePVPListener1.noPvp.contains(attacker.getName())) {
       if (SafePVPListener1.yesMsg.contains(defender.getName())) {
         defender.sendMessage(
             SafePVPListener1.prefix
                 + ChatColor.DARK_AQUA
                 + attacker.getName()
                 + ChatColor.WHITE
                 + " is on the no PVP list. You can't be damaged.");
       }
       if (SafePVPListener1.yesMsg.contains(attacker.getName())) {
         attacker.sendMessage(
             SafePVPListener1.prefix + "You are on the no PVP list. You can not damage!");
       }
     }
     if (!SafePVPListener1.noPvp.contains(attacker.getName())
         && !SafePVPListener1.yesPvp.contains(attacker.getName())) {
       if (SafePVPListener1.yesMsg.contains(attacker.getName())) {
         attacker.sendMessage(SafePVPListener1.prefix + "Type /pvp on to battle!");
       }
     }
     if (!SafePVPListener1.noPvp.contains(defender.getName())
         && !SafePVPListener1.yesPvp.contains(defender.getName())) {
       if (SafePVPListener1.yesMsg.contains(attacker.getName())) {
         attacker.sendMessage(
             SafePVPListener1.prefix
                 + ChatColor.DARK_AQUA
                 + defender.getName()
                 + ChatColor.WHITE
                 + " hasn't enabled PVP yet!");
       }
       if (SafePVPListener1.yesMsg.contains(defender.getName())) {
         defender.sendMessage(
             SafePVPListener1.prefix + "Type /pvp on to battle or /pvp off to stay safe.");
       }
     }
     if (SafePVPListener1.yesPvp.contains(attacker.getName())
         && (SafePVPListener1.yesPvp.contains(defender.getName()))) {
       if (defender.getHealth() - amount <= 0) {
         plugin
             .getServer()
             .broadcastMessage(
                 SafePVPListener1.prefix
                     + ChatColor.RED
                     + attacker.getName()
                     + " has just killed "
                     + defender.getName()
                     + ".");
       }
     }
   }
 }
コード例 #28
0
ファイル: BlizzardSpell.java プロジェクト: ZammieWins/Wayward
 @Override
 public boolean use(Player player) {
   BlockIterator iterator = new BlockIterator(player, 8);
   long delay = 0L;
   int i = 0;
   while (iterator.hasNext()) {
     Block block = iterator.next();
     setShard(block.getRelative(BlockFace.UP, 2).getRelative(BlockFace.DOWN, i), delay);
     float yaw = player.getLocation().getYaw();
     yaw = (yaw + 90) % 360;
     int left = (int) Math.floor((yaw - 90) / 90);
     int right = (int) Math.floor((yaw + 90) / 90);
     BlockFace leftBlockFace = BlockFace.UP;
     switch (left) {
       case 0:
         leftBlockFace = BlockFace.NORTH;
         break;
       case 1:
         leftBlockFace = BlockFace.WEST;
         break;
       case 2:
         leftBlockFace = BlockFace.SOUTH;
         break;
       case 3:
         leftBlockFace = BlockFace.EAST;
         break;
     }
     BlockFace rightBlockFace = BlockFace.UP;
     switch (right) {
       case 0:
         rightBlockFace = BlockFace.NORTH;
         break;
       case 1:
         rightBlockFace = BlockFace.WEST;
         break;
       case 2:
         rightBlockFace = BlockFace.SOUTH;
         break;
       case 3:
         rightBlockFace = BlockFace.EAST;
         break;
     }
     setShard(block.getRelative(leftBlockFace, 2).getRelative(BlockFace.DOWN, i), delay);
     setShard(block.getRelative(rightBlockFace, 2).getRelative(BlockFace.DOWN, i), delay);
     delay += 5L;
     i++;
   }
   Set<LivingEntity> invulnerableEntities = new HashSet<>();
   RegisteredServiceProvider<CharacterPlugin> characterPluginProvider =
       Bukkit.getServer().getServicesManager().getRegistration(CharacterPlugin.class);
   if (characterPluginProvider != null) {
     CharacterPlugin characterPlugin = characterPluginProvider.getProvider();
     Party party = characterPlugin.getParty(characterPlugin.getActiveCharacter(player));
     if (party != null) {
       for (Character member : party.getMembers()) {
         OfflinePlayer memberPlayer = member.getPlayer();
         if (memberPlayer.isOnline()) invulnerableEntities.add(memberPlayer.getPlayer());
       }
     }
   }
   for (LivingEntity entity : player.getWorld().getLivingEntities()) {
     if (entity.getLocation().distanceSquared(player.getLocation()) <= 64) {
       if (!invulnerableEntities.contains(entity)) {
         EntityDamageByEntityEvent event =
             new EntityDamageByEntityEvent(
                 player, entity, EntityDamageEvent.DamageCause.MAGIC, entity.getHealth() / 2D);
         plugin.getServer().getPluginManager().callEvent(event);
         if (!event.isCancelled()) {
           if (event.getEntity() instanceof LivingEntity) {
             ((LivingEntity) event.getEntity()).damage(event.getDamage(), event.getDamager());
             event.getEntity().setLastDamageCause(event);
           }
         }
       }
     }
   }
   return true;
 }
コード例 #29
0
  @EventHandler(ignoreCancelled = true)
  public void onEntityDamageEntity(EntityDamageByEntityEvent e) {
    if (e.getEntity() instanceof Player) { // Hit player
      Player damaged = (Player) e.getEntity();
      if (e.getDamager() instanceof Player) { // Player
        Player damager = (Player) e.getDamager();
        if (cancelBothIngame(damaged, damager)) {
          e.setCancelled(true);
          return;
        }
        if (checkForShadowBlade(damager)) {
          e.setCancelled(true);
          return;
        }
        if (pl.ingameList.get(damager).getAttackType() == 2) {
          if (damager.getItemInHand().getType().equals(Material.IRON_SWORD)
              || damager.getItemInHand().getType().equals(Material.DIAMOND_SWORD)
              || damager.getItemInHand().getType().equals(Material.GOLD_SWORD)) {
            e.setCancelled(true);
            return;
          }
        }
        if (!e.isCancelled()) {
          checkTeleport(damager);
        }
      } else if (e.getDamager() instanceof Projectile) { // Arrow
        Projectile proj = (Projectile) e.getDamager();
        if (proj.getShooter() instanceof Player) {
          Player shooter = (Player) proj.getShooter();
          if (cancelBothIngame(damaged, shooter)) {
            e.setCancelled(true);
            return;
          }
          if (pl.ingameList.get(shooter).getAttackType() == 1) {
            e.setCancelled(true);
            return;
          }
          if (checkForShadowBlade(shooter)) {
            e.setCancelled(true);
            return;
          }

          checkTeleport(shooter);
          if (!e.isCancelled()) {
            if (!checkIngame(damaged)
                && checkIngame(shooter)) { // spectator wont get hurt, and the arrow wont stop
              proj.setBounce(false);
              Vector vel = proj.getVelocity();
              damaged.teleport(damaged.getLocation().add(0, 3, 0));
              damaged.setFlying(true);
              Arrow newArrow = shooter.launchProjectile(Arrow.class);
              newArrow.setShooter(shooter);
              newArrow.setVelocity(vel);
              e.setCancelled(true);
              proj.remove();
            } else if (checkIngame(damaged) && checkIngame(shooter)) {
              // e.setCancelled(true);
              // damaged.damage(e.getDamage());
              checkTarrasque(damaged);
              checkTeleport(damaged);
              checkTeleport(shooter);
              pl.breakEffect(damaged.getLocation(), 3, 11);
            }
          }
        }
      }
    } else { // Hit a non-player
      if (e.getDamager() instanceof Player) { // Player
        Player damager = (Player) e.getDamager();
        if (checkSpectator(damager)) {
          e.setCancelled(true);
          return;
        }
        if (checkForShadowBlade(damager)) {
          e.setCancelled(true);
          return;
        }
        if (pl.ingameList.get(damager).getAttackType() == 2) {
          if (damager.getItemInHand().getType().equals(Material.IRON_SWORD)
              || damager.getItemInHand().getType().equals(Material.DIAMOND_SWORD)
              || damager.getItemInHand().getType().equals(Material.GOLD_SWORD)) {
            e.setCancelled(true);
            return;
          }
        }
        checkTeleport(damager);
      } else if (e.getDamager() instanceof Projectile) { // Arrow
        Projectile proj = (Projectile) e.getDamager();
        if (proj.getShooter() instanceof Player) {
          Player shooter = (Player) proj.getShooter();
          if (!checkIngame(shooter)) {
            if (checkSpectator(shooter)) {
              e.setCancelled(true);
              return;
            }
          } else {
            if (pl.ingameList.get(shooter).getAttackType() == 1) {
              e.setCancelled(true);
              return;
            }
            if (checkForShadowBlade(shooter)) {
              e.setCancelled(true);
              return;
            }
            checkTeleport(shooter);
          }
        }
      }
      if (!e.isCancelled()) {
        pl.breakEffect(e.getEntity().getLocation(), 2, 55);
      }
    }
  }