WorldGuard get regions at player location

Discussion in 'Plugin Development' started by Sorroko, Feb 19, 2012.

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

    Sorroko

    ok so my problem is getting the regions, my code so far is:
    Code:java
    1.  
    2. if (event.getFrom().getBlockX() != event.getTo().getBlockX() ||
    3. event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
    4.  
    5. Location loc = p.getLocation();
    6. Vector vec = new Vector(loc.getX(), loc.getY(), loc.getZ());
    7. Map<String, ProtectedRegion>regionlist = ((WorldGuardPlugin) plugin.getServer().getPluginManager().getPlugin("WorldGuard")).getRegionManager(loc.getWorld()).getRegions();
    8.  
    9. List<String> regions = new ArrayList<String>();
    10. for (String key : regionlist.keySet()) {
    11. ProtectedRegion pr = regionlist.get(key);
    12. if (pr.contains(vec)) {
    13. regions.add(key);
    14. }
    15. }
    16.  
    17. if (regions.contains("rpgzone")) {
    18. event.setCancelled(true);
    19. }
    20.  
    21. }
    22.  

    And the error I get is this:
    Code:
    Could not pass event org.bukkit.event.player.PlayerMoveEvent to RPGWorld
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.java:1026)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:61)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:460)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:191)
    at net.minecraft.server.Packet10Flying.handle(SourceFile:126)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:100)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:78)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:537)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:435)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor147.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.java:1024)
    ... 10 more
    Caused by: java.lang.NullPointerException
    at me.ryan7745.RPGWorld.RPGListener.PlayerMove(RPGListener.java:34)
    ... 14 more
    
    Any ideas? I am completely stuck nothing seems to work with worldguard.
     
  2. Offline

    hatstand

    This is how I do a similar check:
    Code:java
    1. public WorldGuardPlugin getWorldGuard() {
    2. Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
    3.  
    4. if ((plugin == null) || (!(plugin instanceof WorldGuardPlugin))) {
    5. return null;
    6. }
    7.  
    8. return (WorldGuardPlugin)plugin;
    9. }

    That gives me the instance of WorldGuard

    and this is the check:
    Code:java
    1. protected boolean isInRegion(Location loc, String region)
    2. {
    3. if (getWorldGuard() != null)
    4. {
    5. Vector v = new Vector(loc.getX(), loc.getBlockY(), loc.getZ());
    6.  
    7. return getWorldGuard().getRegionManager(loc.getWorld()).getApplicableRegionsIDs(v).contains(region);
    8. }
    9.  
    10. return false;
    11. }


    The vector used there is sk89q's implementation (com.sk89q.worldedit.Vector), and the location can be obtained from the player. You can remove the region argument, change the return type to a list, and return the list instead (Remove the .contains(region) and change getApplicableRegionsIDs to getApplicableRegions if you want a list of region objects and not strings)
     
Thread Status:
Not open for further replies.

Share This Page