Beispiel #1
0
  /**
   * Is PvP disabled in this TownBlock? Checks the world if the TownBlock is null.
   *
   * @param townBlock
   * @return true if PvP is disallowed
   */
  public static boolean preventPvP(TownyWorld world, TownBlock townBlock) {

    if (townBlock != null) {
      try {

        /*
         * Check the attackers TownBlock and it's Town for their PvP
         * status
         */
        if (townBlock.getTown().isAdminDisabledPVP()) return true;

        if (!townBlock.getTown().isPVP() && !townBlock.getPermissions().pvp && !world.isForcePVP())
          return true;

      } catch (NotRegisteredException ex) {
        /*
         * Failed to fetch the town data
         * so check world PvP
         */
        if (!isWorldPvP(world)) return true;
      }

    } else {

      /*
       * Attacker isn't in a TownBlock so check the world PvP
       */
      if (!isWorldPvP(world)) return true;
    }
    return false;
  }
Beispiel #2
0
 public void remove(Town town) {
   for (TownBlock townBlock : town.getTownBlocks()) remove(townBlock.getWorldCoord());
   warringTowns.remove(town);
   try {
     if (!townsLeft(town.getNation())) eliminate(town.getNation());
   } catch (NotRegisteredException e) {
   }
 }
Beispiel #3
0
 public void add(Town town) {
   TownyMessaging.sendTownMessage(town, TownySettings.getJoinWarMsg(town));
   townScores.put(town, 0);
   warringTowns.add(town);
   for (TownBlock townBlock : town.getTownBlocks())
     if (town.isHomeBlock(townBlock))
       warZone.put(townBlock.getWorldCoord(), TownySettings.getWarzoneHomeBlockHealth());
     else warZone.put(townBlock.getWorldCoord(), TownySettings.getWarzoneTownBlockHealth());
 }
Beispiel #4
0
  public void remove(Town attacker, Town town) throws NotRegisteredException {
    townScored(attacker, TownySettings.getWarPointsForTown());

    for (TownBlock townBlock : town.getTownBlocks()) remove(townBlock.getWorldCoord());
    warringTowns.remove(town);
    try {
      if (!townsLeft(town.getNation())) eliminate(town.getNation());
    } catch (NotRegisteredException e) {
    }
  }
Beispiel #5
0
 public void remove(Town attacker, TownBlock townBlock) throws NotRegisteredException {
   townScored(attacker, TownySettings.getWarPointsForTownBlock());
   townBlock.getTown().addBonusBlocks(-1);
   attacker.addBonusBlocks(1);
   try {
     if (!townBlock
         .getTown()
         .payTo(TownySettings.getWartimeTownBlockLossPrice(), attacker, "War - TownBlock Loss")) {
       remove(townBlock.getTown());
       TownyMessaging.sendTownMessage(
           townBlock.getTown(), "Your town ran out of funds to support yourself in war.");
     } else
       TownyMessaging.sendTownMessage(
           townBlock.getTown(),
           "Your town lost "
               + TownySettings.getWartimeTownBlockLossPrice()
               + " "
               + TownyEconomyObject.getEconomyCurrency()
               + ".");
   } catch (EconomyException e) {
   }
   if (townBlock.getTown().isHomeBlock(townBlock)) remove(townBlock.getTown());
   else remove(townBlock.getWorldCoord());
   TownyUniverse.getDataSource().saveTown(townBlock.getTown());
   TownyUniverse.getDataSource().saveTown(attacker);
 }
Beispiel #6
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;
  }
Beispiel #7
0
 public void damage(Town attacker, TownBlock townBlock) throws NotRegisteredException {
   WorldCoord worldCoord = townBlock.getWorldCoord();
   int hp = warZone.get(worldCoord) - 1;
   if (hp > 0) {
     warZone.put(worldCoord, hp);
     // if (hp % 10 == 0) {
     universe.sendMessageTo(
         townBlock.getTown(),
         Colors.Gray
             + "["
             + townBlock.getTown().getName()
             + "]("
             + townBlock.getCoord().toString()
             + ") HP: "
             + hp,
         "");
     universe.sendMessageTo(
         attacker,
         Colors.Gray
             + "["
             + townBlock.getTown().getName()
             + "]("
             + townBlock.getCoord().toString()
             + ") HP: "
             + hp,
         "");
     // }
   } else remove(attacker, townBlock);
 }
Beispiel #8
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;
  }
Beispiel #9
0
 public int countActiveWarBlocks(Town town) {
   int n = 0;
   for (TownBlock townBlock : town.getTownBlocks())
     if (warZone.containsKey(townBlock.getWorldCoord())) n++;
   return n;
 }
Beispiel #10
0
 public void remove(TownBlock townBlock) throws NotRegisteredException {
   if (townBlock.getTown().isHomeBlock(townBlock)) remove(townBlock.getTown());
   else remove(townBlock.getWorldCoord());
 }