Ejemplo n.º 1
0
  @Command(
      name = "unclaim",
      permission = "mytown.cmd.assistant.unclaim",
      parentName = "mytown.cmd",
      syntax = "/town unclaim")
  public static CommandResponse unclaimCommand(ICommandSender sender, List<String> args) {
    EntityPlayer player = (EntityPlayer) sender;
    Resident res = MyTownUniverse.instance.getOrMakeResident(sender);
    TownBlock block = getBlockAtResident(res);
    Town town = getTownFromResident(res);

    if (town != block.getTown())
      throw new MyTownCommandException("mytown.cmd.err.unclaim.notInTown");
    if (block.isPointIn(town.getSpawn().getDim(), town.getSpawn().getX(), town.getSpawn().getZ()))
      throw new MyTownCommandException("mytown.cmd.err.unclaim.spawnPoint");
    if (!checkNearby(block.getDim(), block.getX(), block.getZ(), town)
        && town.townBlocksContainer.size() <= 1) {
      throw new MyTownCommandException("mytown.cmd.err.unclaim.lastClaim");
    }

    getDatasource().deleteBlock(block);
    res.sendMessage(
        getLocal()
            .getLocalization(
                "mytown.notification.block.removed",
                block.getX() << 4,
                block.getZ() << 4,
                block.getX() << 4 + 15,
                block.getZ() << 4 + 15,
                town.getName()));
    makeBankRefund(player, town, block.getPricePaid());
    return CommandResponse.DONE;
  }
Ejemplo n.º 2
0
  // Temporary here, might integrate in the methods
  protected static boolean checkNearby(int dim, int x, int z, Town town) {
    int[] dx = {1, 0, -1, 0};
    int[] dz = {0, 1, 0, -1};

    for (int i = 0; i < 4; i++) {
      TownBlock block = getUniverse().blocks.get(dim, x + dx[i], z + dz[i]);
      if (block != null && block.getTown() == town) {
        return true;
      }
    }
    return false;
  }
Ejemplo n.º 3
0
  public static boolean hasPermission(
      Resident res, FlagType<Boolean> flagType, int dim, Volume volume) {
    boolean inWild = false;

    for (int townBlockX = volume.getMinX() >> 4;
        townBlockX <= volume.getMaxX() >> 4;
        townBlockX++) {
      for (int townBlockZ = volume.getMinZ() >> 4;
          townBlockZ <= volume.getMaxZ() >> 4;
          townBlockZ++) {
        TownBlock townBlock = MyTownUniverse.instance.blocks.get(dim, townBlockX, townBlockZ);

        if (townBlock == null) {
          inWild = true;
          continue;
        }

        Town town = townBlock.getTown();
        Volume rangeBox = volume.intersect(townBlock.toVolume());

        // If the range volume intersects the TownBlock, check Town/Plot permissions
        if (rangeBox != null) {
          int totalIntersectArea = 0;

          // Check every plot in the current TownBlock and sum all plot areas
          for (Plot plot : townBlock.plotsContainer) {
            Volume plotIntersection = volume.intersect(plot.toVolume());
            if (plotIntersection != null) {
              if (!plot.hasPermission(res, flagType)) {
                return false;
              }
              totalIntersectArea += plotIntersection.getVolumeAmount();
            }
          }

          // If plot area sum is not equal to range area, check town permission
          if (totalIntersectArea != rangeBox.getVolumeAmount()) {
            if (!town.hasPermission(res, flagType)) {
              return false;
            }
          }
        }
      }
    }

    if (inWild) {
      return Wild.instance.hasPermission(res, flagType);
    }

    return true;
  }
Ejemplo n.º 4
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;
    }
  }