예제 #1
0
 public boolean isEnemy(Town a, Town b) {
   try {
     if (a == b) return false;
     if (a.getNation() == b.getNation()) return false;
     if (a.getNation().hasEnemy(b.getNation())) return true;
   } catch (NotRegisteredException e) {
     return false;
   }
   return false;
 }
예제 #2
0
  public void adminSet(String[] split) throws TownyException {

    if (split.length == 0) {
      sender.sendMessage(ChatTools.formatTitle("/townyadmin set"));
      // TODO: player.sendMessage(ChatTools.formatCommand("",
      // "/townyadmin set", "king [nation] [king]", ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              "",
              "/townyadmin set",
              "mayor [town] " + TownySettings.getLangString("town_help_2"),
              ""));
      sender.sendMessage(ChatTools.formatCommand("", "/townyadmin set", "mayor [town] npc", ""));
      // player.sendMessage(ChatTools.formatCommand("", "/townyadmin set",
      // "debugmode [on/off]", ""));
      // player.sendMessage(ChatTools.formatCommand("", "/townyadmin set",
      // "devmode [on/off]", ""));

      return;
    }

    if (!TownyUniverse.getPermissionSource()
        .testPermission(
            player, PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_SET.getNode(split[0].toLowerCase())))
      throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

    if (split[0].equalsIgnoreCase("mayor")) {
      if (split.length < 3) {

        sender.sendMessage(ChatTools.formatTitle("/townyadmin set mayor"));
        sender.sendMessage(
            ChatTools.formatCommand(
                "Eg",
                "/townyadmin set mayor",
                "[town] " + TownySettings.getLangString("town_help_2"),
                ""));
        sender.sendMessage(
            ChatTools.formatCommand("Eg", "/townyadmin set mayor", "[town] npc", ""));

      } else
        try {
          Resident newMayor = null;
          Town town = TownyUniverse.getDataSource().getTown(split[1]);

          if (split[2].equalsIgnoreCase("npc")) {
            String name = nextNpcName();
            TownyUniverse.getDataSource().newResident(name);

            newMayor = TownyUniverse.getDataSource().getResident(name);

            newMayor.setRegistered(System.currentTimeMillis());
            newMayor.setLastOnline(0);
            newMayor.setNPC(true);

            TownyUniverse.getDataSource().saveResident(newMayor);
            TownyUniverse.getDataSource().saveResidentList();

            // set for no upkeep as an NPC mayor is assigned
            town.setHasUpkeep(false);

          } else {
            newMayor = TownyUniverse.getDataSource().getResident(split[2]);

            // set upkeep again
            town.setHasUpkeep(true);
          }

          if (!town.hasResident(newMayor)) TownCommand.townAddResident(town, newMayor);
          // Delete the resident if the old mayor was an NPC.
          Resident oldMayor = town.getMayor();

          town.setMayor(newMayor);

          if (oldMayor.isNPC()) {
            try {
              town.removeResident(oldMayor);
              TownyUniverse.getDataSource().removeResident(oldMayor);

              TownyUniverse.getDataSource().removeResidentList(oldMayor);

            } catch (EmptyTownException e) {
              // Should never reach here as we are setting a new
              // mayor before removing the old one.
              e.printStackTrace();
            }
          }
          TownyUniverse.getDataSource().saveTown(town);
          String[] msg = TownySettings.getNewMayorMsg(newMayor.getName());
          TownyMessaging.sendTownMessage(town, msg);
          // TownyMessaging.sendMessage(player, msg);
        } catch (TownyException e) {
          TownyMessaging.sendErrorMsg(getSender(), e.getMessage());
        }

    } else if (split[0].equalsIgnoreCase("capital")) {

      if (split.length < 2) {

        sender.sendMessage(ChatTools.formatTitle("/townyadmin set capital"));
        sender.sendMessage(ChatTools.formatCommand("Eg", "/ta set capital", "[town name]", ""));

      } else {

        try {
          Town newCapital = TownyUniverse.getDataSource().getTown(split[1]);
          Nation nation = newCapital.getNation();

          nation.setCapital(newCapital);
          plugin.resetCache();

          TownyMessaging.sendNationMessage(
              nation,
              TownySettings.getNewKingMsg(newCapital.getMayor().getName(), nation.getName()));

          TownyUniverse.getDataSource().saveNation(nation);
          TownyUniverse.getDataSource().saveNationList();

        } catch (TownyException e) {
          TownyMessaging.sendErrorMsg(player, e.getMessage());
        }
      }

    } else {
      TownyMessaging.sendErrorMsg(
          getSender(),
          String.format(TownySettings.getLangString("msg_err_invalid_property"), "administrative"));
      return;
    }
  }
예제 #3
0
  public TownBlockStatus getStatusCache(Player player, WorldCoord worldCoord) {
    // if (isTownyAdmin(player))
    //        return TownBlockStatus.ADMIN;

    if (!worldCoord.getWorld().isUsingTowny()) return TownBlockStatus.OFF_WORLD;

    // TownyUniverse universe = plugin.getTownyUniverse();
    TownBlock townBlock;
    Town town;
    try {
      townBlock = worldCoord.getTownBlock();
      town = townBlock.getTown();

      if (townBlock.isLocked()) {
        // Push the TownBlock location to the queue for a snapshot (if it's not already in the
        // queue).
        if (town.getWorld().isUsingPlotManagementRevert()
            && (TownySettings.getPlotManagementSpeed() > 0)) {
          TownyRegenAPI.addWorldCoord(townBlock.getWorldCoord());
          return TownBlockStatus.LOCKED;
        }
        townBlock.setLocked(false);
      }

    } catch (NotRegisteredException e) {
      // Unclaimed Zone switch rights
      return TownBlockStatus.UNCLAIMED_ZONE;
    }

    Resident resident;
    try {
      resident = TownyUniverse.getDataSource().getResident(player.getName());
    } catch (TownyException e) {
      System.out.print("Failed to fetch resident: " + player.getName());
      return TownBlockStatus.NOT_REGISTERED;
    }

    try {
      // War Time switch rights
      if (isWarTime()) {
        if (TownySettings.isAllowWarBlockGriefing()) {
          try {
            if (!resident.getTown().getNation().isNeutral() && !town.getNation().isNeutral())
              return TownBlockStatus.WARZONE;
          } catch (NotRegisteredException e) {

          }
        }
        // If this town is not in a nation and we are set to non neutral status during war.
        if (!TownySettings.isWarTimeTownsNeutral() && !town.hasNation())
          return TownBlockStatus.WARZONE;
      }

      // Town Owner Override
      try {
        if (townBlock.getTown().isMayor(resident) || townBlock.getTown().hasAssistant(resident))
          return TownBlockStatus.TOWN_OWNER;
      } catch (NotRegisteredException e) {
      }

      // Resident Plot switch rights
      try {
        Resident owner = townBlock.getResident();
        if (resident == owner) return TownBlockStatus.PLOT_OWNER;
        else if (owner.hasFriend(resident)) return TownBlockStatus.PLOT_FRIEND;
        else if (resident.hasTown() && isAlly(owner.getTown(), resident.getTown()))
          return TownBlockStatus.PLOT_ALLY;
        else
          // Exit out and use town permissions
          throw new TownyException();
      } catch (NotRegisteredException x) {
      } catch (TownyException x) {
      }

      // Town resident destroy rights
      if (!resident.hasTown()) throw new TownyException();

      if (resident.getTown() != town) {
        // Allied destroy rights
        if (isAlly(town, resident.getTown())) return TownBlockStatus.TOWN_ALLY;
        else if (isEnemy(resident.getTown(), town)) {
          if (townBlock.isWarZone()) return TownBlockStatus.WARZONE;
          else return TownBlockStatus.ENEMY;
        } else return TownBlockStatus.OUTSIDER;
      } else if (resident.isMayor() || resident.getTown().hasAssistant(resident))
        return TownBlockStatus.TOWN_OWNER;
      else return TownBlockStatus.TOWN_RESIDENT;
    } catch (TownyException e) {
      // Outsider destroy rights
      return TownBlockStatus.OUTSIDER;
    }
  }