Worldguard checking if player's in a region?

Discussion in 'Spigot Plugin Development' started by NaJated, May 22, 2015.

  1. Hey all, it basically says it in the title, I want to launch a firework or whatever when a player goes in a region. thanks :->
     
  2. Just my guess but in the player move event:

    Code (Text):

    Player p = //however you get the player
    for(ProtectedRegion r : WGBukkit.getRegionManager(p.getWorld()).getApplicableRegions(p.getLocation())) {
                       //Check if region is the correct one through r.getId() if by name
                       //Do the firework thing
                    }
     
     
  3. Could I start a runnable on the onEnable then loop through all the players on the server, checking what region a player is in then do something if they are in that region?
     
  4. You probably shouldnt do that, you could however listen to it with the "PlayerMoveEvent".
    Note** You should make it only listen for when they move through blocks because that event is called when the player looks around aswell
     
  5. CB 1.4.7-R1.0 Feb 01, 2013 wot

    Does that code check if they are in a region?
     
  6. It will list what regions they are in: your job to see if it's the region you are looking for.
     
  7. Thanks :). I tried this:

    Code (Java):
        public void launchEnterLeaveTownListener() {
            Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.getInstance(), new BukkitRunnable() {
                public void run() {
                    for (Player p : Bukkit.getOnlinePlayers()) {
                        for(ProtectedRegion r : WGBukkit.getRegionManager(p.getWorld()).getApplicableRegions(p.getLocation())) {
                            if (r.getId().equalsIgnoreCase("Meido")) {
                                p.sendMessage(ChatColor.AQUA + "Lol");
                            }
                        }
                    }
                }
            }, 10 * 20, 5 * 20);
        }[/CODE=java]
     
  8. I've been using it for a while, works on 1.7.10, but would need to be updated to work with WG6. It may not be the best solution, but it works.
     
  9. Hm, I think I'll just try to use the Worldguard API, thanks though :D. Any comments on the code I posted just above? :D <3
     
  10. It might be better to use the player move event, check if they moved a block, and then see if they're in a region.
     

Share This Page