Exemplo n.º 1
0
  public Map<String, ProtectedRegion> getRegions() {
    HashMap<String, ProtectedRegion> ret = new HashMap<String, ProtectedRegion>();
    ret.putAll(this.cRegions);
    ret.putAll(this.pRegions);

    for (Map.Entry<String, ProtectedRegion> entry : ret.entrySet()) {
      ProtectedRegion region = entry.getValue();

      String parentId = region.getParentId();
      if (parentId != null) {
        try {
          region.setParent(ret.get(parentId));
        } catch (CircularInheritanceException ex) {
        }
      } else {
        try {
          region.setParent(null);
        } catch (CircularInheritanceException ex) {
        }
      }

      if (region.getOwners() == null) {
        region.setOwners(new DefaultDomain());
      } else if (region.getMembers() == null) {
        region.setMembers(new DefaultDomain());
      }
    }

    return ret;
  }
Exemplo n.º 2
0
  public static void giveStall(Player player, String zone, String number) {
    WorldGuardPlugin worldGuard = getWorldGuard();
    World world = player.getWorld();

    RegionManager regionManager = worldGuard.getRegionManager(world);
    ProtectedRegion region = regionManager.getRegion("stall_" + zone.toLowerCase() + number);
    DefaultDomain owners = region.getOwners();
    owners.addPlayer(player.getName());
    region.setOwners(owners);
    editPlotSign(player, zone, number, region);
  }
 /**
  * Copy attributes from another region.
  *
  * @param other the other region
  */
 public void copyFrom(ProtectedRegion other) {
   checkNotNull(other);
   setMembers(other.getMembers());
   setOwners(other.getOwners());
   setFlags(other.getFlags());
   setPriority(other.getPriority());
   try {
     setParent(other.getParent());
   } catch (CircularInheritanceException ignore) {
     // This should not be thrown
   }
 }
Exemplo n.º 4
0
  void setUpExitRegion() throws Exception {
    DefaultDomain domain = new DefaultDomain();
    domain.addGroup(BUILDER_GROUP);

    ProtectedRegion region =
        new ProtectedCuboidRegion(
            EXIT_ID, new BlockVector(-1, 0, -1), new BlockVector(-10, 255, -10));

    region.setOwners(domain);
    manager.addRegion(region);

    entryRegion = region;
    // same as above
    entryRegion.setFlag(DefaultFlag.EXIT, StateFlag.State.DENY);
    entryRegion.setFlag(DefaultFlag.EXIT.getRegionGroupFlag(), RegionGroup.NON_OWNERS);
  }
Exemplo n.º 5
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;
    }
  }
  public void onPlayerInteract(PlayerInteractEvent event) {
    if (event.isCancelled()) {
      return;
    }
    Action action = event.getAction();
    if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {
      Block block = event.getClickedBlock();
      Material type = block.getType();
      Player player = event.getPlayer();

      GlobalConfiguration cfg = plugin.getGlobalConfiguration();
      WorldConfiguration wcfg = cfg.getWorldConfig(event.getClickedBlock().getWorld().getName());

      if (wcfg.useRegions && player.getItemInHand().getTypeId() == wcfg.regionWand) {
        Vector pt = toVector(block);

        RegionManager mgr =
            plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());
        ApplicableRegionSet app = mgr.getApplicableRegions(pt);
        List<String> regions = mgr.getApplicableRegionsIDs(pt);

        if (regions.size() > 0) {
          player.sendMessage(
              ChatColor.YELLOW
                  + "Can you build? "
                  + (app.canBuild(BukkitPlayer.wrapPlayer(plugin, player)) ? "Yes" : "No"));

          StringBuilder str = new StringBuilder();
          for (Iterator<String> it = regions.iterator(); it.hasNext(); ) {
            str.append(it.next());
            if (it.hasNext()) {
              str.append(", ");
            }
          }

          player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString());
        } else {
          player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!");
        }
      }

      if (block.getType() == Material.CHEST
          || block.getType() == Material.DISPENSER
          || block.getType() == Material.FURNACE
          || block.getType() == Material.BURNING_FURNACE
          || block.getType() == Material.NOTE_BLOCK) {
        if (wcfg.useRegions) {
          Vector pt = toVector(block);
          LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);
          RegionManager mgr =
              plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName());

          if (!plugin.hasPermission(player, "region.bypass")) {
            ApplicableRegionSet set = mgr.getApplicableRegions(pt);
            if (!set.isStateFlagAllowed(Flags.CHEST_ACCESS) && !set.canBuild(localPlayer)) {
              player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
              event.setCancelled(true);
              return;
            }
          }
        }
      }

      if (wcfg.useRegions && (type == Material.LEVER || type == Material.STONE_BUTTON)) {
        Vector pt = toVector(block);
        RegionManager mgr =
            cfg.getWorldGuardPlugin()
                .getGlobalRegionManager()
                .getRegionManager(player.getWorld().getName());
        ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt);
        LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player);

        if (!applicableRegions.isStateFlagAllowed(Flags.LEVER_AND_BUTTON, localPlayer)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
          event.setCancelled(true);
          return;
        }
      }

      if (wcfg.useRegions && type == Material.CAKE_BLOCK) {

        Vector pt = toVector(block);

        if (!cfg.canBuild(player, pt)) {
          player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");

          byte newData = (byte) (block.getData() - 1);
          newData = newData < 0 ? 0 : newData;

          block.setData(newData);
          player.setHealth(player.getHealth() - 3);

          return;
        }
      }

      if (wcfg.useRegions
          && wcfg.useiConomy
          && cfg.getiConomy() != null
          && (type == Material.SIGN_POST || type == Material.SIGN || type == Material.WALL_SIGN)) {
        BlockState blockstate = block.getState();

        if (((Sign) blockstate).getLine(0).equalsIgnoreCase("[WorldGuard]")
            && ((Sign) blockstate).getLine(1).equalsIgnoreCase("For sale")) {
          String regionId = ((Sign) blockstate).getLine(2);
          // String regionComment = ((Sign)block).getLine(3);

          if (regionId != null && regionId != "") {
            RegionManager mgr =
                cfg.getWorldGuardPlugin()
                    .getGlobalRegionManager()
                    .getRegionManager(player.getWorld().getName());
            ProtectedRegion region = mgr.getRegion(regionId);

            if (region != null) {
              RegionFlagContainer flags = region.getFlags();

              if (flags.getBooleanFlag(Flags.BUYABLE).getValue(false)) {
                if (iConomy.getBank().hasAccount(player.getName())) {
                  Account account = iConomy.getBank().getAccount(player.getName());
                  double balance = account.getBalance();
                  double regionPrice = flags.getDoubleFlag(Flags.PRICE).getValue();

                  if (balance >= regionPrice) {
                    account.subtract(regionPrice);
                    player.sendMessage(
                        ChatColor.YELLOW
                            + "You have bought the region "
                            + regionId
                            + " for "
                            + iConomy.getBank().format(regionPrice));
                    DefaultDomain owners = region.getOwners();
                    owners.addPlayer(player.getName());
                    region.setOwners(owners);
                    flags.getBooleanFlag(Flags.BUYABLE).setValue(false);
                    account.save();
                  } else {
                    player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                  }
                } else {
                  player.sendMessage(ChatColor.YELLOW + "You have not enough money.");
                }
              } else {
                player.sendMessage(ChatColor.RED + "Region: " + regionId + " is not buyable");
              }
            } else {
              player.sendMessage(
                  ChatColor.DARK_RED + "The region " + regionId + " does not exist.");
            }
          } else {
            player.sendMessage(ChatColor.DARK_RED + "No region specified.");
          }
        }
      }

      if (wcfg.getBlacklist() != null) {

        if (!wcfg.getBlacklist()
            .check(
                new BlockInteractBlacklistEvent(
                    BukkitPlayer.wrapPlayer(plugin, player), toVector(block), block.getTypeId()),
                false,
                false)) {
          event.setCancelled(true);
          return;
        }
      }
    }
  }