Solved Behavior of this code

Discussion in 'Plugin Development' started by Caedus, Apr 15, 2017.

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



    the following code works mostly as it should, as in it pastes the schematic into the bukkit world immediately.

    package me.caedus.procbuild;
    import java.util.ArrayList;
    import java.util.List;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import net.minecraft.server.v1_8_R3.NBTCompressedStreamTools;
    import net.minecraft.server.v1_8_R3.NBTTagCompound;
    public class Schematic{
        Location loc;
         @SuppressWarnings({ "deprecation", "unused" })
        public void pasteSchematic(File f, Location ll, ProcBuild plugin){ 
           loc = ll;
           FileInputStream fis = new FileInputStream(f);
           NBTTagCompound nbt = NBTCompressedStreamTools.a(fis);
           short width = nbt.getShort("Width");
           short height = nbt.getShort("Height");
           short length = nbt.getShort("Length");
           byte[] blocks = nbt.getByteArray("Blocks");
           byte[] data = nbt.getByteArray("Data");
           List<Location> locations = new ArrayList<Location>();
           for(int x = 0; x < width; ++x){
            for(int y = 0; y < height; ++y){
             for(int z = 0; z < length; ++z){
                 int index = y * width * length + z * width + x;
                 final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ());
                 int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted
                 plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
                    public void run() {
                      final Block block = l.getBlock();
                    }}, 1L);
          catch(Exception e){e.printStackTrace();}
    However, it literally pastes the whole building in one go and I would THINK it should paste it in block by block. Clearly I am wrong, can someone explain where my logic is flawed and what I should be doing to have it paste in block by block? If I set the delay on the task to 40L it just waits two seconds to paste the whole building in btw.

  2. Offline


    The issue is that you are not increasing the delay for the task. Every time it loops There should be at least a +1 delay for Each task.
    Caedus likes this.
  3. Offline


  4. Offline


    If your problem has been solved, mark this thread as solved.
Thread Status:
Not open for further replies.

Share This Page