Help with worldedit editsession

Discussion in 'Programming Help' started by Robotnik, Apr 23, 2016.

  1. Robotnik

    Robotnik New Member

    Hi, I keep getting a nullpointerexception error, and I dont know what can be causing it except for editsession. However, I dont seen anything about it which could be null.

    Code (Text):

                           File worldPath = new File(datafolder + "/Schematics/" + world.getName());
                           worldPath.mkdir();
                           File[] directoryListing = worldPath.listFiles();
         
                           for (File child : directoryListing) {  
                               Boolean pasteair = data.getBoolean("pasteair", true);
                               Chunk chunk = event.getChunk();
     
                                World world = chunk.getWorld();
     
                                Integer PastePosX = chunk.getX();
                                Integer PastePosZ = chunk.getZ();
                                Integer PastePosY = world.getHighestBlockYAt(PastePosX, PastePosZ);
                           

                                com.sk89q.worldedit.Vector pasteposition = new com.sk89q.worldedit.Vector(0,0,0);
                           

                                EditSession editsession = new EditSession( new BukkitWorld(world), 5000000);
                           
                                //load schematic into clipboard. child is a file
                                CuboidClipboard cuboidClipboard = SchematicFormat.MCEDIT.load(child);
                           
                           
                                //nullpointerexception happens here. Checked pasteposition and pasteair, and they seem solid.
                                //the only one which could be causing it is editsession
                                cuboidClipboard.paste(editsession, pasteposition, pasteair); //line 133
    Last edited: Apr 23, 2016
  2. wizjany

    wizjany Administrator Developer

    would be nice if you posted the exception too.
    unless the exception is directly that line, which would imply that cuboidClipboard was the null pointer. but i'm pretty sure the method you're using to load will throw an exception before it returns a null.
  3. Robotnik

    Robotnik New Member

    Forgot all about posting that

    Code (Text):
    [13:27:08] [Server thread/ERROR]: Could not pass event ChunkPopulateEvent to TESTPLUGIN v0.2
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-944aa20-8d16fc0]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-944aa20-8d16fc0]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.Chunk.a(Chunk.java:952) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.Chunk.loadNearby(Chunk.java:901) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.ChunkProviderServer.originalGetChunkAt(ChunkProviderServer.java:205) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:139) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:118) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.ChunkProviderServer.getOrCreateChunkFast(ChunkProviderServer.java:76) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.World.getChunkAt(World.java:324) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.World.getChunkAtWorldCoords(World.java:320) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.World.getType(World.java:743) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.World.isEmpty(World.java:261) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.World.c(World.java:249) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.WorldProvider.canSpawn(SourceFile:84) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.WorldServer.canSpawn(WorldServer.java:200) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.WorldServer.b(WorldServer.java:962) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.WorldServer.a(WorldServer.java:884) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.MinecraftServer.a(MinecraftServer.java:271) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.DedicatedServer.init(DedicatedServer.java:269) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:527) [spigot.jar:git-Spigot-944aa20-8d16fc0]
        at java.lang.Thread.run(Unknown Source) [?:1.7.0_79]
    Caused by: java.lang.NullPointerException
        at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:213) ~[spigot.jar:git-Spigot-944aa20-8d16fc0]
        at com.sk89q.worldedit.bukkit.WorldEditPlugin.getInstance(WorldEditPlugin.java:459) ~[?:?]
        at com.sk89q.worldedit.bukkit.BukkitWorld.getBlock(BukkitWorld.java:400) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.getBlock(AbstractDelegateExtent.java:68) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.getBlock(AbstractDelegateExtent.java:68) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.getBlock(AbstractDelegateExtent.java:68) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.getBlock(AbstractDelegateExtent.java:68) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.getBlock(AbstractDelegateExtent.java:68) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.getBlock(AbstractDelegateExtent.java:68) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.getBlock(AbstractDelegateExtent.java:68) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.getBlock(AbstractDelegateExtent.java:68) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.getBlock(AbstractDelegateExtent.java:68) ~[?:?]
        at com.sk89q.worldedit.extent.ChangeSetExtent.setBlock(ChangeSetExtent.java:62) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.setBlock(AbstractDelegateExtent.java:78) ~[?:?]
        at com.sk89q.worldedit.extent.MaskingExtent.setBlock(MaskingExtent.java:69) ~[?:?]
        at com.sk89q.worldedit.extent.AbstractDelegateExtent.setBlock(AbstractDelegateExtent.java:78) ~[?:?]
        at com.sk89q.worldedit.extent.validation.BlockChangeLimiter.setBlock(BlockChangeLimiter.java:87) ~[?:?]
        at com.sk89q.worldedit.EditSession.setBlock(EditSession.java:503) ~[?:?]
        at com.sk89q.worldedit.EditSession.setBlock(EditSession.java:546) ~[?:?]
        at com.sk89q.worldedit.CuboidClipboard.place(CuboidClipboard.java:439) ~[?:?]
        at com.sk89q.worldedit.CuboidClipboard.paste(CuboidClipboard.java:407) ~[?:?]
        at com.sk89q.worldedit.CuboidClipboard.paste(CuboidClipboard.java:389) ~[?:?]
        at testplugin.ChunkListenser.onChunkPopulate(ChunkListenser.java:133) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_79]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-944aa20-8d16fc0]
        ... 22 more
  4. wizjany

    wizjany Administrator Developer

    it would appear that you're doing things before worldedit is loaded.
    you should depend/softdepend your plugin on worldedit to ensure it loads first.
  5. Robotnik

    Robotnik New Member

    Thats the odd thing, I already do have it as a depend in my plugin.yml

    Code (Text):
    name: TESTPLUGIN
    main: testplugin.testplugin
    version: 0.2
    author: Robotnikman
    load: startup
    description: puts schematics in new chunks
    website:
    commands:
    permissions:
    depend: [WorldEdit]
  6. wizjany

    wizjany Administrator Developer

    possibly has something to do with load: startup then?
    i am not sure how bukkit/spigot does plugin loading priorities.
  7. PseudoKnight

    PseudoKnight Well-Known Member

    No, you're right. Depend means it will load WorldEdit first.
  8. wizjany

    wizjany Administrator Developer