Closed UltraGameCoder closed 6 years ago
You can do this by starting a job from the blocksplacer. You also need to use the blocksplacer to track if your job has finished. Please check the IBlocksPlacer for further information.
@SBPrime I can't seem to figure it out. May you want to look at my code and tell me how you would implement it in the load function?
public void loadIsland() throws FileNotFoundException, IOException, MaxChangedBlocksException {
String schematicName = getPlayer().getUniqueId().toString();
AtomicBoolean isNew = new AtomicBoolean(false);
File file = PlayerStatsManager.getManager().getPlayerIsland(schematicName, isNew);
org.bukkit.util.Vector originVector = center.toVector();
Vector to;
if (isNew.get()) {
to = new Vector(originVector.getBlockX() - 21,60,originVector.getBlockZ() -21);//to = new Vector(originVector.getBlockX(),originVector.getBlockY(),originVector.getBlockZ());
Vector borderCenter = new Vector(to.getX(),to.getY()+2,to.getZ());
generateBorder(borderCenter,21);
}else {
to = new Vector(originVector.getBlockX() - 21,60,originVector.getBlockZ() -21);
}
World weWorld = new BukkitWorld(center.getWorld());
WorldData worldData = weWorld.getWorldData();
FileInputStream input = new FileInputStream(file);
ClipboardReader reader = ClipboardFormat.SCHEMATIC.getReader(input);
Clipboard clipboard = reader.read(worldData);
input.close();
Extent source = clipboard;
Extent destination = WorldEdit.getInstance().getEditSessionFactory().getEditSession(weWorld, -1);
ForwardExtentCopy copy = new ForwardExtentCopy(source, clipboard.getRegion(), clipboard.getOrigin(), destination, to);
copy.setSourceMask(new ExistingBlockMask(clipboard));
Operations.completeLegacy(copy);
}
I've wanted to return some kind of object/id to check from if the schematic paste is finished.
To listen for jobs take a look at: addListener and addStateChangedListener. The first listener needs to be added once when you enable the plugin, the second one needs to be added and removed when you get an event from the IBlockPlacer.
Thank you! first I didn't know all the things you've meant but no I've figured it out. Thanks for helping!
Your welcome.
I can't find a way to check if my schematic paste is finished. I want to teleport the player to the schematic when it's finished placing all the blocks. Is there currently a way I can achieve this? (I also need to call some other functions beside the player teleportation )