World Guard API Frustrating NPE

Discussion in 'Plugin Development' started by Weasel_Squeezer, Apr 2, 2013.

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

    Weasel_Squeezer

    ok so this error has been one that I have not been able to figure out for days. It should be easy to figure out because it is just a null pointer exception, but I just cannot figure it out. So i am also wondering if it is possibly a fault with worldguard.
    Here is the Error:

    Code:
    2013-04-02 04:02:45 [WARNING] [FarmControl] Task #53 for FarmControl v2.1 generated an exception
    java.lang.NullPointerException
        at com.sk89q.worldguard.protection.managers.RegionManager.getRegion(RegionManager.java:111)
        at me.Weasel_Squeezer.FarmControl.FarmControl.getRegion(FarmControl.java:756)
        at me.Weasel_Squeezer.FarmControl.FarmControl$1.run(FarmControl.java:416)
        at org.bukkit.craftbukkit.v1_5_R1.scheduler.CraftTask.run(CraftTask.java:53)
        at org.bukkit.craftbukkit.v1_5_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:344)
        at net.minecraft.server.v1_5_R1.MinecraftServer.r(MinecraftServer.java:512)
        at net.minecraft.server.v1_5_R1.DedicatedServer.r(DedicatedServer.java:225)
        at net.minecraft.server.v1_5_R1.MinecraftServer.q(MinecraftServer.java:476)
        at net.minecraft.server.v1_5_R1.MinecraftServer.run(MinecraftServer.java:409)
        at net.minecraft.server.v1_5_R1.ThreadServerApplication.run(SourceFile:573)
    So pretty much I have a scheduled task which will regrow a tree within a certain worldguard region. It works about 98% of the time, but that 2% is a problem, because when I get this error, it just keeps looping through spitting out the same error non stop. But whats weird is that it doesn't just throw an error, it actually regenerates the tree how it should, but it keeps doing it every time the error is thrown, so I end up getting animated trees from repeated tree regrowth.

    Here is my WorldGuard API calls:

    Code:java
    1. public ProtectedRegion getRegion(Location loc, String regionID) {
    2. RegionManager rm = getWGRegionManager(loc);
    3. if (rm == null) {
    4. return null;
    5. }
    6. //This is line 756 in the code
    7. ProtectedRegion region = rm.getRegion(regionID);
    8. return region;
    9. }
    10.  
    11. public RegionManager getWGRegionManager(Location loc) {
    12. WorldGuardPlugin wg = getWorldGuard();
    13. if (wg == null) {
    14. return null;
    15. }
    16. return wg.getRegionManager(loc.getWorld());
    17. }
    18.  
    19. public WorldGuardPlugin getWorldGuard() {
    20. Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
    21. // WorldGuard may not be loaded
    22. if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
    23. return null;
    24. }
    25. return (WorldGuardPlugin) plugin;
    26. }


    Here is where I call getRegion:

    Code:java
    1. int treeData = block.getData() % 4;
    2. //This is line 416 in the code
    3. ProtectedRegion region = getRegion(location, treeRegrowLink.get(location));
    4. //it procedes this null check, resets the region, and regenerates a tree, but it does not stop when the location is added to regeneratedTrees which it should.
    5. if (region != null) {
    6. resetRegion(region.getMaximumPoint(), region.getMinimumPoint());
    7. if (treeData == 0) {
    8. block.setTypeId(0);
    9. regrowTree(location, region, TreeType.TREE);
    10. regeneratedTrees.add(serializedLocation);
    11. }
    12. //....


    Any clues as to what is happening here? thanks!
     
  2. Offline

    raGan.

    Actual error is on line 111 in worldguard's RegionManager. Try to update.
     
  3. Offline

    Weasel_Squeezer

    hmmm. here is the getRegion method in WG:

    Code:java
    1. public ProtectedRegion getRegion(String id)
    2. {
    3. if (id.startsWith("#")) {
    4. int index;
    5. try {
    6. index = Integer.parseInt(id.substring(1)) - 1;
    7. } catch (NumberFormatException e) {
    8. return null;
    9. }
    10. for (ProtectedRegion region : getRegions().values()) {
    11. if (index == 0) {
    12. return region;
    13. }
    14. index--;
    15. }
    16. return null;
    17. }
    18.  
    19. return getRegionExact(id);
    20. }


    line 111 is: if (id.startsWith("#"))
    so that must mean that id is null. So my script is not returning an id when I call:
    treeRegrowLink.get(location)
    treeRegrowLink is a property file. I wonder why it would fail to get a property. it gives no errors from retrieving data from the file. this is weird.
     
  4. Offline

    raGan.

    Do a simple null check then, or find out why it is happening.
     
Thread Status:
Not open for further replies.

Share This Page