@EventHandler
 public static void onPlayerMove(PlayerMoveEvent e) {
   Player player = e.getPlayer();
   Location locTo = e.getTo();
   Location locFrom = e.getFrom();
   if (PBMethods.WGSupportEnabled) {
     if (PBMethods.getWorldGuard() != null) {
       ApplicableRegionSet set =
           WGBukkit.getRegionManager(locTo.getWorld()).getApplicableRegions(locTo);
       for (ProtectedRegion region : set) {
         if (region != null) {
           // Checks if the player can enter the field during a Probending Match
           if (region.getId().equalsIgnoreCase(PBMethods.ProbendingField)) {
             if (PBMethods.matchStarted) {
               String teamName = PBMethods.getPlayerTeam(player.getUniqueId());
               if (teamName != null) {
                 if (!PBMethods.playingTeams.contains(teamName.toLowerCase())) {
                   player.sendMessage(Strings.Prefix + Strings.CantEnterField);
                   player.teleport(locFrom);
                   e.setCancelled(true);
                 }
               }
               if (teamName == null) {
                 player.sendMessage(Strings.Prefix + Strings.CantEnterField);
                 player.teleport(locFrom);
                 e.setCancelled(true);
               }
             }
           }
         }
       }
     }
   }
 }
Example #2
0
  public void deleteRegion(Player player, String[] args) {
    if (args.length != 2) {
      player.sendMessage(ChatColor.RED + "Wrong usage. /pr help");
      return;
    }

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

    World world = player.getWorld();
    LocalPlayer localPlayer = plugin.wrapPlayer(player);

    RegionManager mgr = plugin.getGlobalRegionManager().get(world);
    ProtectedRegion region = mgr.getRegion(id);

    if (region == null) {
      player.sendMessage(ChatColor.RED + "Could not find a region by that name.");
      return;
    }

    if (region.isOwner(localPlayer)) {
      mgr.removeRegion(id);

      player.sendMessage(ChatColor.YELLOW + "Region " + args[1] + " removed.");

      try {
        mgr.save();
      } catch (IOException e) {
        player.sendMessage(
            ChatColor.RED + "(shouldn't happen) Failed to write regions file: " + e.getMessage());
      }
    }
  }
Example #3
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 + ".");
  }
  /** Returns whether this region has the same ID as another region. */
  @Override
  public boolean equals(Object obj) {
    if (!(obj instanceof ProtectedRegion)) {
      return false;
    }

    ProtectedRegion other = (ProtectedRegion) obj;
    return other.getId().equals(getId());
  }
  @Override
  public int compareTo(ProtectedRegion other) {
    if (getPriority() > other.getPriority()) {
      return -1;
    } else if (getPriority() < other.getPriority()) {
      return 1;
    }

    return getId().compareTo(other.getId());
  }
Example #6
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
   }
 }
  @Override
  public int getRegionCountOfPlayer(LocalPlayer player) {
    int count = 0;

    for (ProtectedRegion region : regions.values()) {
      if (region.getOwners().contains(player)) {
        count++;
      }
    }

    return count;
  }
Example #9
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;
  }
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length != 0) {
      plugin.sendMessageWarning(
          sender,
          ChatColor.translateAlternateColorCodes(
              '&', plugin.languageGetConfig().getString("buyland.general.parameters")));
      plugin.sendMessageInfo(sender, "Usage: /buyland list");
    } else {
      // See if the person requesting the information is a player
      if (sender instanceof Player) {
        Player player = (Player) sender;
        String playerName = player.getName();

        // See if the player has permission to this command
        if (player.hasPermission("buyland.list") || player.hasPermission("buyland.all")) {
          // State who the list is for
          plugin.sendMessageInfo(sender, "You own regions: ");

          // Loop through all the worlds
          for (World world : Bukkit.getWorlds()) {
            // get the list of regions for the selected world
            Map<String, ProtectedRegion> regionMap = WGBukkit.getRegionManager(world).getRegions();
            // Loop through all the regions
            for (ProtectedRegion region : regionMap.values()) {
              // see if the person is an owner of the region
              if (region.isOwner(playerName)) {
                // see if the region is buyable
                if (region.getFlag(DefaultFlag.BUYABLE) == null) {
                  // if it is null, it is not purchased by anyone.
                } else {
                  // See if the region was purchased.
                  if (region.getFlag(DefaultFlag.BUYABLE) == false) {
                    // list this as owned by the player in question
                    plugin.sendMessageInfo(
                        sender, " " + world.getName() + ": " + region.getId(), false);
                  }
                }
              }
            }
          }
        }
      } else {
        plugin.sendMessageInfo(sender, "Currently not available at console.");
      }
    }

    // command was utilized.
    return true;
  }
Example #11
0
  public void allowUser(Player player, String[] args) {
    if (args.length != 3) {
      player.sendMessage(ChatColor.RED + "Wrong usage. /pr help");
      return;
    }

    String id = "icp_" + player.getName() + "_" + args[2];

    World world = player.getWorld();
    LocalPlayer localPlayer = plugin.wrapPlayer(player);

    RegionManager mgr = plugin.getGlobalRegionManager().get(world);
    ProtectedRegion region = mgr.getRegion(id);

    if (region == null) {
      player.sendMessage(ChatColor.RED + "Could not find a region by that name.");
      return;
    }

    if (region.isOwner(localPlayer)) {
      region.getMembers().addPlayer(args[1]);
      player.sendMessage(
          ChatColor.GREEN
              + "Allowed "
              + ChatColor.RED
              + args[1]
              + ChatColor.GREEN
              + " to region "
              + ChatColor.RED
              + args[2]
              + ChatColor.GREEN
              + ".");

      Player targetPlayer = Bukkit.getServer().getPlayerExact(args[1]);
      if (targetPlayer != null) {
        targetPlayer.sendMessage(
            ChatColor.GREEN
                + player.getName()
                + " has added you as a member in the "
                + ChatColor.RED
                + args[2]
                + ChatColor.GREEN
                + " region.");
      }

    } else {
      player.sendMessage(ChatColor.RED + "(shouldn't happen) You don't own the region " + args[2]);
    }
  }
Example #12
0
  public static void enter(Player player, ProtectedRegion region) {
    String name = WordUtils.capitalize(region.getId());

    Title title = new Title("§3" + name, null, 1, 5, 1);

    title.send(player);
  }
  /**
   * Return a list of regions from the given list of regions that intersect with this region.
   *
   * @param regions a list of regions to source from
   * @return the elements of {@code regions} that intersect with this region
   */
  public List<ProtectedRegion> getIntersectingRegions(Collection<ProtectedRegion> regions) {
    checkNotNull(regions, "regions");

    List<ProtectedRegion> intersecting = Lists.newArrayList();
    Area thisArea = toArea();

    for (ProtectedRegion region : regions) {
      if (!region.isPhysicalArea()) continue;

      if (intersects(region, thisArea)) {
        intersecting.add(region);
      }
    }

    return intersecting;
  }
  /**
   * Checks whether a player is a member of the region or any of its parents.
   *
   * @param player player to check
   * @return whether an member
   */
  public boolean isMemberOnly(LocalPlayer player) {
    if (members.contains(player)) {
      return true;
    }

    ProtectedRegion curParent = getParent();
    while (curParent != null) {
      if (curParent.getMembers().contains(player)) {
        return true;
      }

      curParent = curParent.getParent();
    }

    return false;
  }
Example #15
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);
  }
 // main
 public static String getXYZSafeZone(Location l, String world) {
   String r = "";
   // ResultSet rs =
   // tekkitrestrict.db.query("SELECT * FROM `tr_safezones` WHERE `world` = '"+world+"'");
   /*
    * if(tekkitrestrict.config.getBoolean("UseSafeZones")){ //determine if
    * the player is in the 3D cube. for(int i=0;i<zones.size();i++){
    * safeZone rs = zones.get(i); if(world.equals(rs.world)){ int x1 =
    * rs.x1; int y1 = rs.y1; int z1 = rs.z1; int x2 = rs.x2; int y2 =
    * rs.y2; int z2 = rs.z2; double x = l.getX(); double y= l.getY();
    * double z = l.getZ(); boolean it = x >= x1 && x < x2 + 1 && y >= y1 &&
    * y < y2 + 1 && z >= z1 && z < z2 + 1; if(it){ return rs.name; } } } }
    */
   if (tekkitrestrict.config.getBoolean("UseSafeZones")) {
     for (int i = 0; i < zones.size(); i++) {
       TRSafeZone a = zones.get(i);
       if (a.mode == 0) {
         // do nothing... (for now)
       } else if (a.mode == 1) { // WorldGuard!
         // determine whether in WG region or not...
         // com.sk89q.worldguard.protection.regions.ProtectedRegion
         Plugin plugin =
             tekkitrestrict.getInstance().getServer().getPluginManager().getPlugin("WorldGuard");
         try {
           // WorldGuard may not be loaded
           if (plugin != null
               && (plugin instanceof com.sk89q.worldguard.bukkit.WorldGuardPlugin)) {
             com.sk89q.worldguard.bukkit.WorldGuardPlugin WGB =
                 (com.sk89q.worldguard.bukkit.WorldGuardPlugin) plugin;
             com.sk89q.worldguard.protection.regions.ProtectedRegion PR =
                 WGB.getRegionManager(tekkitrestrict.getInstance().getServer().getWorld(a.world))
                     .getRegion(a.name);
             if (PR.contains(l.getBlockX(), l.getBlockY(), l.getBlockZ())) {
               return a.name;
             }
           }
         } catch (Exception E) {
           // E.printStackTrace();
         }
       }
     }
     return r;
   } else {
     return "";
   }
 }
Example #17
0
  void setUpEntryRegion() {
    DefaultDomain domain = new DefaultDomain();
    domain.addGroup(VIP_GROUP);

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

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

    entryRegion = region;
    // this is the way it's supposed to work
    // whatever the group flag is set to is the group that the flag APPLIES to
    // in this case, non members (esskay) should be DENIED entry
    entryRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.DENY);
    entryRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.NON_MEMBERS);
  }
  /**
   * Checks if the bounding box of a region intersects with with the bounding box of this region.
   *
   * @param region the region to check
   * @return whether the given region intersects
   */
  protected boolean intersectsBoundingBox(ProtectedRegion region) {
    BlockVector rMaxPoint = region.getMaximumPoint();
    BlockVector min = getMinimumPoint();

    if (rMaxPoint.getBlockX() < min.getBlockX()) return false;
    if (rMaxPoint.getBlockY() < min.getBlockY()) return false;
    if (rMaxPoint.getBlockZ() < min.getBlockZ()) return false;

    BlockVector rMinPoint = region.getMinimumPoint();
    BlockVector max = getMaximumPoint();

    if (rMinPoint.getBlockX() > max.getBlockX()) return false;
    if (rMinPoint.getBlockY() > max.getBlockY()) return false;
    if (rMinPoint.getBlockZ() > max.getBlockZ()) return false;

    return true;
  }
  @Override
  public void untakeRegion(String world, String region) {
    final ProtectedRegion protectedRegion =
        SimpleRegionMarket.wgManager.getProtectedRegion(Bukkit.getWorld(world), region);

    // Clear Members
    protectedRegion.setMembers(new DefaultDomain());

    checkUntakeActions(protectedRegion, world);

    Utils.setEntry(this, world, region, "taken", false);
    Utils.removeEntry(this, world, region, "owner");
    Utils.removeEntry(this, world, region, "expiredate");
    Utils.setEntry(this, world, region, "hidden", false);

    tokenManager.updateSigns(this, world, region);
  }
Example #20
0
  public static void editPlotSign(
      Player player, String zone, String number, ProtectedRegion region) {
    String line1 = "######";
    String line2 = zone + " Zone - " + number;
    String line3 = player.getName();
    String line4 = "######";

    World world = player.getWorld();

    BlockVector max = region.getMaximumPoint();
    BlockVector min = region.getMinimumPoint();

    int minx = Math.min(max.getBlockX() + 1, min.getBlockX() - 1),
        miny = Math.min(max.getBlockY() + 1, min.getBlockY() - 1),
        minz = Math.min(max.getBlockZ(), min.getBlockZ()),
        maxx = Math.max(max.getBlockX() + 1, min.getBlockX() - 1),
        maxy = Math.max(max.getBlockY() + 1, min.getBlockY() - 1),
        maxz = Math.max(max.getBlockZ(), min.getBlockZ());
    int a = 0;
    for (int x = minx; x <= maxx; x++) {
      for (int y = miny; y <= maxy; y++) {
        for (int z = minz; z <= maxz; z++) {
          a++;
          Block b = world.getBlockAt(x, y, z);
          if (b.getType().equals(Material.SIGN_POST)
              || b.getType().equals(Material.WALL_SIGN)
              || b.getType().equals(Material.SIGN)) {
            Sign sign = (Sign) b.getState();
            if (sign.getLine(0).contains("#")) {
              sign.setLine(0, line1);
              sign.setLine(1, line2);
              sign.setLine(2, line3);
              sign.setLine(3, line4);
              sign.update(true);

              player.sendMessage("yes");
            } else {
              player.sendMessage("no");
            }
            break;
          }
        }
      }
    }
    player.sendMessage("Number: " + a);
  }
  @Override
  public void removeRegion(String id) {
    ProtectedRegion region = regions.get(id.toLowerCase());
    regions.remove(id.toLowerCase());

    if (region != null) {
      List<String> removeRegions = new ArrayList<String>();
      for (ProtectedRegion curRegion : regions.values()) {
        if (curRegion.getParent() == region) {
          removeRegions.add(curRegion.getId().toLowerCase());
        }
      }

      for (String remId : removeRegions) {
        removeRegion(remId);
      }
    }
  }
  /**
   * Checks whether a player is an owner of region or any of its parents.
   *
   * @param player player to check
   * @return whether an owner
   */
  public boolean isOwner(LocalPlayer player) {
    checkNotNull(player);

    if (owners.contains(player)) {
      return true;
    }

    ProtectedRegion curParent = getParent();
    while (curParent != null) {
      if (curParent.getOwners().contains(player)) {
        return true;
      }

      curParent = curParent.getParent();
    }

    return false;
  }
 /**
  * Test whether the given region intersects with this area.
  *
  * @param region the region to test
  * @param thisArea an area object for this region
  * @return true if the two regions intersect
  */
 protected boolean intersects(ProtectedRegion region, Area thisArea) {
   if (intersectsBoundingBox(region)) {
     Area testArea = region.toArea();
     testArea.intersect(thisArea);
     return !testArea.isEmpty();
   } else {
     return false;
   }
 }
  /**
   * Checks whether a player is an owner of region or any of its parents.
   *
   * @param playerName player name to check
   * @return whether an owner
   * @deprecated Names are deprecated
   */
  @Deprecated
  public boolean isOwner(String playerName) {
    checkNotNull(playerName);

    if (owners.contains(playerName)) {
      return true;
    }

    ProtectedRegion curParent = getParent();
    while (curParent != null) {
      if (curParent.getOwners().contains(playerName)) {
        return true;
      }

      curParent = curParent.getParent();
    }

    return false;
  }
  private static String checkRegionId(String id, boolean allowGlobal) throws CommandException {
    if (!ProtectedRegion.isValidId(id)) {
      throw new CommandException("Имя региона '" + id + "' содержит запрещённые символы.");
    }

    if (!allowGlobal && id.equalsIgnoreCase("__global__")) {
      throw new CommandException("Нельзя заприватить __global__.");
    }

    return id;
  }
  /**
   * Set the curParent. This checks to make sure that it will not result in circular inheritance.
   *
   * @param parent the curParent to setFlag
   * @throws CircularInheritanceException
   */
  public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
    if (parent == null) {
      this.parent = null;
      return;
    }

    if (parent == this) {
      throw new CircularInheritanceException();
    }

    ProtectedRegion p = parent.getParent();
    while (p != null) {
      if (p == this) {
        throw new CircularInheritanceException();
      }
      p = p.getParent();
    }

    this.parent = parent;
  }
  @Override
  public boolean overlapsUnownedRegion(ProtectedRegion checkRegion, LocalPlayer player) {
    List<ProtectedRegion> appRegions = new ArrayList<ProtectedRegion>();

    for (ProtectedRegion other : regions.values()) {
      if (other.getOwners().contains(player)) {
        continue;
      }

      appRegions.add(other);
    }

    List<ProtectedRegion> intersectRegions;
    try {
      intersectRegions = checkRegion.getIntersectingRegions(appRegions);
    } catch (UnsupportedIntersectionException e) {
      intersectRegions = new ArrayList<ProtectedRegion>();
    }

    return intersectRegions.size() > 0;
  }
Example #28
0
  public JSONContainer(Map<String, ProtectedRegion> regions) {

    this.cRegions = new HashMap<String, ProtectedCuboidRegion>();
    this.pRegions = new HashMap<String, ProtectedPolygonalRegion>();

    for (Map.Entry<String, ProtectedRegion> entry : regions.entrySet()) {
      String id = entry.getKey();
      ProtectedRegion region = entry.getValue();
      region.setParentId();

      if (region instanceof ProtectedCuboidRegion) {
        cRegions.put(id, (ProtectedCuboidRegion) region);
      } else if (region instanceof ProtectedPolygonalRegion) {
        pRegions.put(id, (ProtectedPolygonalRegion) region);
      } else {
        logger.info(
            "regions of type '"
                + region.getClass().toString()
                + "' are not supported for saving, yet.");
      }
    }
  }
 @EventHandler
 public void onPlayerBreakBlock(BlockBreakEvent e) {
   Player player = e.getPlayer();
   Location loc = player.getLocation();
   if (PBMethods.WGSupportEnabled) {
     if (PBMethods.getWorldGuard() != null) {
       ApplicableRegionSet set =
           WGBukkit.getRegionManager(loc.getWorld()).getApplicableRegions(loc);
       for (ProtectedRegion region : set) {
         if (region != null) {
           if (region.getId().equalsIgnoreCase(PBMethods.ProbendingField)) {
             if (PBMethods.buildDisabled) {
               if (!player.hasPermission("probending.worldguard.buildonfield")) {
                 e.setCancelled(true);
               }
             }
           }
         }
       }
     }
   }
 }
  @Override
  public ApplicableRegionSet getApplicableRegions(Vector pt) {
    TreeSet<ProtectedRegion> appRegions = new TreeSet<ProtectedRegion>();

    for (ProtectedRegion region : regions.values()) {
      if (region.contains(pt)) {
        appRegions.add(region);

        ProtectedRegion parent = region.getParent();

        while (parent != null) {
          if (!appRegions.contains(parent)) {
            appRegions.add(parent);
          }

          parent = parent.getParent();
        }
      }
    }

    return new ApplicableRegionSet(appRegions, regions.get("__global__"));
  }