Пример #1
0
  public TownBlockStatus getStatusCache(Player player, WorldCoord worldCoord) {
    if (isTownyAdmin(player)) return TownBlockStatus.ADMIN;

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

    TownyUniverse universe = getTownyUniverse();
    TownBlock townBlock;
    Town town;
    try {
      townBlock = worldCoord.getTownBlock();
      town = townBlock.getTown();
    } catch (NotRegisteredException e) {
      // Unclaimed Zone switch rights
      return TownBlockStatus.UNCLAIMED_ZONE;
    }

    try {
      Resident resident = universe.getResident(player.getName());

      // War Time switch rights
      if (universe.isWarTime())
        try {
          if (!resident.getTown().getNation().isNeutral() && !town.getNation().isNeutral())
            return TownBlockStatus.WARZONE;
        } 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
          // 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 (universe.isAlly(resident.getTown(), town)) return TownBlockStatus.TOWN_ALLY;
        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;
    }
  }