Пример #1
0
  public void regionPrice(Player player, String[] args) {
    Selection sel = worldEdit.getSelection(player);

    if (sel == null) {
      player.sendMessage(ChatColor.RED + "Select a region with a wooden axe first.");
      return;
    }

    ProtectedRegion region = null;
    String id = "icp__tempregion";

    if (sel instanceof Polygonal2DSelection) {
      Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
      int minY = polySel.getNativeMinimumPoint().getBlockY();
      int maxY = polySel.getNativeMaximumPoint().getBlockY();
      region = new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY);
    } else if (sel instanceof CuboidSelection) {
      BlockVector min = sel.getNativeMinimumPoint().toBlockVector();
      BlockVector max = sel.getNativeMaximumPoint().toBlockVector();
      region = new ProtectedCuboidRegion(id, min, max);
    } else {
      player.sendMessage(
          ChatColor.RED
              + "(shouldn't happen) Something went wrong. The type of region selected is unsupported!");
      return;
    }

    double cost = (int) Math.ceil(econ.getCost(region.volume()));

    player.sendMessage(ChatColor.AQUA + "That region will cost you $" + cost + ".");
  }
Пример #2
0
  public void setRegion(Player sender, String[] args) {
    if (args.length != 2) {
      sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help");
      return;
    }

    LocalPlayer wgPlayer = plugin.wrapPlayer(sender);

    String id = "icp_" + sender.getName() + "_" + args[1];

    if (!ProtectedRegion.isValidId(id)) {
      sender.sendMessage(ChatColor.RED + "Invalid region name specified!");
      return;
    }

    Selection sel = worldEdit.getSelection(sender);

    if (sel == null) {
      sender.sendMessage(ChatColor.RED + "Select a region with a wooden axe first.");
      return;
    }

    RegionManager mgr = plugin.getGlobalRegionManager().get(sel.getWorld());

    if (mgr.hasRegion(id)) {
      sender.sendMessage(
          ChatColor.RED + "That region name is already taken. Please choose a new name.");
      return;
    }

    int regionCount = mgr.getRegionCountOfPlayer(wgPlayer);

    if (regionCount > Economy.maxDonatorAllowedRegions
        && !sender.isOp()
        && sender.hasPermission("iceprotect.freeprotect")) {
      sender.sendMessage(
          ChatColor.RED
              + "You have reached the maximum allowed regions per user ("
              + Economy.maxDonatorAllowedRegions
              + ").");
      sender.sendMessage(ChatColor.RED + "Please contact an admin.");
      return;
    }

    ProtectedRegion region = null;

    if (sel instanceof Polygonal2DSelection) {
      Polygonal2DSelection polySel = (Polygonal2DSelection) sel;
      int minY = polySel.getNativeMinimumPoint().getBlockY();
      int maxY = polySel.getNativeMaximumPoint().getBlockY();
      region = new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY);
    } else if (sel instanceof CuboidSelection) {
      BlockVector min = sel.getNativeMinimumPoint().toBlockVector();
      BlockVector max = sel.getNativeMaximumPoint().toBlockVector();
      region = new ProtectedCuboidRegion(id, min, max);
    } else {
      sender.sendMessage(
          ChatColor.RED
              + "(shouldn't happen) Something went wrong. The type of region selected is unsupported!");
      return;
    }

    String[] names = new String[1];
    names[0] = sender.getName();
    region.setOwners(RegionUtil.parseDomainString(names, 0));

    ApplicableRegionSet regions = mgr.getApplicableRegions(region);

    if (!regions.isOwnerOfAll(wgPlayer)) {
      sender.sendMessage(ChatColor.RED + "That region overlaps with another one not owned by you!");
      return;
    }

    double cost = (int) Math.ceil(econ.getCost(region.volume()));

    if (cost > Economy.maxDonatorAllowedCost && sender.hasPermission("iceprotect.freeprotect")) {
      sender.sendMessage(
          ChatColor.RED + "You have exceeded the maximum allowed price for this region!");
      sender.sendMessage(
          ChatColor.RED
              + "Cost: "
              + ChatColor.GRAY
              + "$"
              + cost
              + ChatColor.RED
              + ", "
              + ChatColor.GRAY
              + "$"
              + Economy.maxDonatorAllowedCost
              + " allowed.");
      return;
    }

    if (!sender.hasPermission("iceprotect.freeprotect") && !econ.chargePlayer(sender, cost)) {
      sender.sendMessage(ChatColor.RED + "You don't have enough money! $" + cost + " needed.");
      return;
    }

    mgr.addRegion(region);

    try {
      mgr.save();
      sender.sendMessage(
          ChatColor.YELLOW
              + "Region saved as "
              + args[1]
              + ". "
              + (sender.hasPermission("iceprotect.freeprotect") ? "" : "Cost: $" + cost + "."));
    } catch (IOException e) {
      sender.sendMessage(
          ChatColor.RED + "(shouldn't happen) Failed to write regions file: " + e.getMessage());
      e.printStackTrace();
      return;
    }
  }
Пример #3
0
  protected static void claim(String regionname, CommandSender sender) throws CommandException {
    Player player = WGExtender.getInstance().getWorldGuard().checkPlayer(sender);
    LocalPlayer localPlayer = WGExtender.getInstance().getWorldGuard().wrapPlayer(player);
    RegionPermissionModel permModel = getPermissionModel(sender);

    if (!permModel.mayClaim()) {
      throw new CommandPermissionsException();
    }

    String id = checkRegionId(regionname, false);

    RegionManager manager =
        checkRegionManager(WGExtender.getInstance().getWorldGuard(), player.getWorld());

    checkRegionDoesNotExist(manager, id, false);
    ProtectedRegion region = checkRegionFromSelection(player, id);

    WorldConfiguration wcfg =
        WGExtender.getInstance().getWorldGuard().getGlobalStateManager().get(player.getWorld());

    if (!permModel.mayClaimRegionsUnbounded()) {
      int maxRegionCount = wcfg.getMaxRegionCount(player);
      if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(localPlayer) >= maxRegionCount) {
        throw new CommandException(
            "У вас слишком много регионов, удалите один из них перед тем как заприватить новый.");
      }
    }

    ProtectedRegion existing = manager.getRegion(id);

    if (existing != null) {
      if (!existing.getOwners().contains(localPlayer)) {
        throw new CommandException("Регион уже существует, и вы им не владеете.");
      }
    }

    ApplicableRegionSet regions = manager.getApplicableRegions(region);

    if (regions.size() > 0) {
      if (!regions.isOwnerOfAll(localPlayer)) {
        throw new CommandException("Это регион перекрывает чужой регион.");
      }
    } else {
      if (wcfg.claimOnlyInsideExistingRegions) {
        throw new CommandException("Вы можете приватить только внутри своих регионов.");
      }
    }

    if (wcfg.maxClaimVolume >= Integer.MAX_VALUE) {
      throw new CommandException(
          "The maximum claim volume get in the configuration is higher than is supported. "
              + "Currently, it must be "
              + Integer.MAX_VALUE
              + " or smaller. Please contact a server administrator.");
    }

    if (!permModel.mayClaimRegionsUnbounded()) {
      if (region instanceof ProtectedPolygonalRegion) {
        throw new CommandException("Полигональные регионы не поддерживаются.");
      }

      if (region.volume() > wcfg.maxClaimVolume) {
        player.sendMessage(ChatColor.RED + "Размер региона слишком большой.");
        player.sendMessage(
            ChatColor.RED
                + "Максимальный размер: "
                + wcfg.maxClaimVolume
                + ", ваш размер: "
                + region.volume());
        return;
      }
    }

    RegionAdder task = new RegionAdder(WGExtender.getInstance().getWorldGuard(), manager, region);
    task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY);
    task.setOwnersInput(new String[] {player.getName()});
    try {
      task.call();
      sender.sendMessage(ChatColor.YELLOW + "Вы заприватили регион " + id);
    } catch (Exception e) {
      sender.sendMessage(ChatColor.YELLOW + "Произошла ошибка при привате региона " + id);
      e.printStackTrace();
    }
  }