Пример #1
0
  /**
   * Return true if both attacker and defender are in Arena Plots.
   *
   * @param attacker
   * @param defender
   * @return true if both players in an Arena plot.
   */
  public static boolean isPvPPlot(Player attacker, Player defender) {

    if ((attacker != null) && (defender != null)) {
      TownBlock attackerTB, defenderTB;
      try {
        attackerTB =
            new WorldCoord(attacker.getWorld().getName(), Coord.parseCoord(attacker))
                .getTownBlock();
        defenderTB =
            new WorldCoord(defender.getWorld().getName(), Coord.parseCoord(defender))
                .getTownBlock();

        if (defenderTB.getType().equals(TownBlockType.ARENA)
            && attackerTB.getType().equals(TownBlockType.ARENA)) return true;

      } catch (NotRegisteredException e) {
        // Not a Town owned Plot
      }
    }
    return false;
  }
Пример #2
0
  /**
   * Should we be preventing friendly fire?
   *
   * @param attacker
   * @param defender
   * @return true if we should cancel damage.
   */
  public static boolean preventFriendlyFire(Player attacker, Player defender) {

    /*
     * Don't block potion use (self damaging) on ourselves.
     */
    if (attacker == defender) return false;

    if ((attacker != null) && (defender != null))
      if (!TownySettings.getFriendlyFire()
          && CombatUtil.isAlly(attacker.getName(), defender.getName())) {
        try {
          TownBlock townBlock =
              new WorldCoord(defender.getWorld().getName(), Coord.parseCoord(defender))
                  .getTownBlock();
          if (!townBlock.getType().equals(TownBlockType.ARENA)) return true;
        } catch (TownyException x) {
          // World or TownBlock failure
          // But we are configured to prevent friendly fire in the
          // wilderness too.
          return true;
        }
      }
    return false;
  }