Solved Getting player's WorldGuard region using their location

Discussion in 'Plugin Development' started by plisov, Mar 28, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    plisov

    I was wondering how I could get the region a player is standing in using their location. For example, a player visits another person's skyblock island. The owner of that skyblock sets their island to private. The players that are not in the members list of the region will get kicked to spawn.
    1. How do I get the region a player is standing in
    2. How do I get the owner and member list of that region
    3. How do I check if the player(s) currently in that region are in the member/owner list of that region

    I have been trying to mess around with this but have gotten no where. I tried researching a bit on this topic but all the threads I've found were already setting the region's name.
     
  2. Online

    timtower Administrator Administrator Moderator

    @plisov Link to plugin you want to hook into?
     
  3. Offline

    plisov

    What do you mean? I'm not trying to hook into any plugin besides WorldGuard.
     
  4. Online

    timtower Administrator Administrator Moderator

    Didn't see the title when I said that, you are the one building his own skyblock plugin right? ( would explain the worldguard a bit )
    https://worldguard.enginehub.org/en/latest/developer/regions/
    I would highly recommend using math for island placement and region naming though.
    Then it will be faster to find the correct region based on player location.
     
  5. Offline

    plisov

    Yes I would be the one building the skyblock. However it could be vise versa. I was thinking of doing something like that where I add 400 or so to X and Z instead of randomly putting the island randomly. However isn't there a method of getting the region that the player is in currently? Like when you type /region info it shows all the region names? Except I don't need the region's name, I need the owner and member lists.
     
  6. Online

    timtower Administrator Administrator Moderator

    @plisov There probably is (or at least a looped method)
    But how often do you want to check it?
    Having 1000 islands with 100 players will make a nasty loop.
     
  7. Offline

    plisov

    Every time the island owner clicks their private button and the boolean is switched to false, it'll run.
     
  8. Online

    timtower Administrator Administrator Moderator

    @plisov So this isn't a playermoveevent thing? That will drastically decrease the amount of work.
    Get the region the button is in.
    Will probably require looping through all regions in the world. Unless the RegionManager has a method to get all regions in a location.
    From there you can get the owners and members with simple method calls I believe.
     
  9. Offline

    plisov

    Well that's the problem. I don't know how to get the region the player's in. I've tried so many things. I think you meant player and not button. I have a inRegion method currently but I don't know how to get the region name to work with WorldGuard methods. It says I need to change my method from boolean to string.
    Code:
        public static boolean inRegion(Location loc)
        {
            WorldGuardPlugin guard = getWorldGuard();
            com.sk89q.worldedit.Vector v = BukkitUtil.toVector(loc);
            RegionManager manager = guard.getRegionManager(loc.getWorld());
            ApplicableRegionSet set = manager.getApplicableRegions(v);
            return set.size() > 0;
        }
    
        protected boolean isInRegion(Location loc, boolean b)
        {
            if (getWorldGuard() != null)
            {
                Vector v = new Vector(loc.getX(), loc.getBlockY(), loc.getZ());
    
                return getWorldGuard().getRegionManager(loc.getWorld()).getApplicableRegionsIDs(v).contains(b);
            }
     
  10. Online

    timtower Administrator Administrator Moderator

    @plisov I assume that the button is in the same region so I mean button.
    First, get the region as variable.
    You do that by setting a variable to null, loop through the applicableRegions, find the first one (assuming they don't overlap), setting the variable to the region.
    If the var is null: no region found, return.

    If there is a region found: loop through all players (nearby or just all of them)
    See if they are in the found region.
    Handle based on ownership.
     
  11. Offline

    plisov

    Thanks, I'll try this later when I get home. By button I meant a GUI item. :p
     
  12. Online

    timtower Administrator Administrator Moderator

    I thought an actual button in the world :p
    Then it should be a player indeed :p
     
  13. Offline

    plisov

    Haha. So for the looping through the applicableRegions, could I use any of the two methods I posted on one of my previous posts?
     
  14. Online

    timtower Administrator Administrator Moderator

    @plisov For getting the regions you need: parts, for looping: that code isn't looping through anything.
     
  15. Offline

    plisov

    I'm having trouble starting the loop (creating it). Would the variable look like this?
    Code:
    Variable region = null;
    Would this be a for loop? How do I get the first region?

    Code:
                    WorldGuardPlugin guard = getWorldGuard();
                    RegionManager manager = guard.getRegionManager(player.getLocation().getWorld());
                 
                    if(!manager.getApplicableRegions(player.getLocation()).isOwnerOfAll((LocalPlayer) player)) {
                     
                    } else {
                        return;
                    }
    ^ That would be getting the player clicking the GUI item and not the players on the island. (Which is not what I need ;( )
     
  16. Online

    timtower Administrator Administrator Moderator

    @plisov Well, looping requires a loop.
    You only have an if statement.
    You don't get the region to begin.
     
Thread Status:
Not open for further replies.

Share This Page