0

I am making a dungeon generator in Minecraft spigot and I am trying to implement a copy paste method using the World Edit API. i cant see much on the documentation and i believe chatGPT is giving outdated information, as follows:

public void cloneWithWorldEdit(Location fromMin, Location fromMax, Location to) throws WorldEditException {
    WorldEditPlugin worldEdit = (WorldEditPlugin)       Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
    com.sk89q.worldedit.world.World world = BukkitAdapter.adapt(fromMin.getWorld());

    // Define the source region
    Region sourceRegion = new CuboidRegion(BukkitAdapter.asBlockVector(fromMin), BukkitAdapter.asBlockVector(fromMax));

    // Define the destination
    BlockVector3 toVector = BukkitAdapter.asBlockVector(to);

    // Create an edit session
    try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1)) {
        ForwardExtentCopy copy = new ForwardExtentCopy(editSession, sourceRegion, editSession, toVector);
        // Perform the operation
        Operations.completeLegacy(copy);
        // Remember to commit changes of the edit session
        editSession.flushSession();
    }
}

Let me know if this is close or if there is a much easier way of doing this. i eventually want to run more complex world edit functions but for now i just want to copy/paste

0 Answers0