WorldGuard API Region problem

Discussion in 'Spigot Plugin Development' started by RandomPanda30, May 19, 2016.

  1. I'm currently working on a plugin that basically allows a player to build in a certain place in the server whilst having WorldGuard stop the player from building on the rest of the server.

    However, I'm having problems overriding WorldGuard and stopping the "you don't have permission for this area" message

    I've tired setting the eventcancelled to false and such. Any suggestions?
  2. Try updating the source or use an java-decompiler to view what it contains
  3. At the moment, I have found this:

    Code (Text):
        @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
        public void onBlockBreak(BlockBreakEvent event) {
            Player player = event.getPlayer();
            Block target = event.getBlock();
            WorldConfiguration wcfg = getWorldConfig(player);

            if (!wcfg.itemDurability) {
                ItemStack held = player.getItemInHand();
                if (held.getType() != Material.AIR && !(ItemType.usesDamageValue(held.getTypeId())|| BlockType.usesData(held.getTypeId()))) {
                    held.setDurability((short) 0);
    Not completely sure about the ignoreCancelled part...Will that have something to do with it?
  4. What?
    Yeah the ignoredCancelled part means that your method won't even be called if the event has been canceled before it reaches your handler. This means if world guard is cancelling a block break even your handler is just going to be skipped.
  5. Brilliant, could see something like that was coming. Any way around this? The WorldGuard API won't really support just a one time allowance to build
  6. You can remove the ignoreCanceled part. Now if you want to preform a check you can still call BlockBreakEvent #isCanceled() to check if something has canceled it. Then if you want to cancel it yourself (or uncancel it) you can simply invoke BlockBreakEvent #setCanceled(boolean)

    So in you event handler you would want some logic like the following
    Code (Text):
    if (eventIsCanceled && playerShouldBypassTheCancel) {
  7. Create a region where you want that player to be building and add the player as member there. Why do you need a plugin for this?
  8. And you recommend putting this on either the LOWEST or HIGHEST priority? Or would that not affected it at all
    Basically I have a plugin to select a bunch of locations from inside a house and save them. Easy enough, but the houses are normally complex and complicated so I've have to make the plugin select all the air blocks inside the house which is fine. However, we have a global flag on WorldGuard denying build to stop the players from building sooo yeah, see where I'm coming from?
  9. The lower the priority the earlier the handler is called in the chain. The last handler has the final say, hence it is of the highest priority because handlers with this priority don't want other handlers changing the result after them. If I remember correctly world guard is on low or lowest (don't quote me on that, it just seems like something I remember when I check a while back) and so as long as you are after it (the standard priority should do but you can go on high if you'd like to play it safe). You want to make a decision based on if world guard canceled the event and then in some cases you need to change the result and therefore you must run your handler after world guard.
  10. Brilliant! Amazing I've managed to get the event sorted out just fine. However, I have the "You don't have permission for this area" message coming up now. Any solutions to this?...I really don't want to be messing with WorldGuard so any kind of work around or something will be pretty damn good
  11. Thats why regions in worldguard have a priority you can set.
  12. Guess I'm biting the bullet then. Am I right in thinking WorldGuard has support for advanced selections and not just cuboid selection?
  13. Okay so please do forgive and correct me if I'm wrong but I have a list of complex locations, will WorldGuard API still be able to handle this?
  14. As I already said, it supports polygons. So yeah.
  15. Right, got the WorldGuard API cracked and such apart from I need to set a region so it's build-able now. However, it seems adding a member still doesn't allow one to build.

    Code (Text):
     RegionContainer container = HouseShop.getWorldGuard().getRegionContainer();
                                RegionManager regions = container.get(player.getWorld());
                                ProtectedRegion pr = regions.getRegion("spawn");

                                ApplicableRegionSet set = HouseShop.getWorldGuard().getRegionManager(player.getWorld()).

                                DefaultDomain members = pr.getMembers();

                                members.getPlayers().forEach(s -> {
                                    Bukkit.broadcastMessage(ChatColor.GOLD + s);


                                members.getPlayers().forEach(s -> {
                                    Bukkit.broadcastMessage(ChatColor.RED + s);

                                pr.setFlag(DefaultFlag.BUILD, StateFlag.State.ALLOW);
    Still not allowing building, any other options here?
    • Like Like x 1
  16. what is the regions priority compared to the one that prohibits building?
  17. Okay so ignore this, I've cannot seem to find how to create a new Polygon region in the API. The site is still down as well