Minecraft – How to make persistent variables in WorldEdit CraftScripting

minecraft-java-editionminecraft-worldedit

When experimenting in Minecraft I usually create a large flat area to work on using WorldEdit.

However, this usually results in a crash or big freeze.

I'm going to make a script that can take a large clear-out job and split it into lots of smaller ones and give the game time to recover. It doesn't look too hard to make this, but if I have to re-type the command and the arguments each time its going to be a hassle.

I need a variable that can persist past the execution of the script so I can do a "/next" type thing to go to the next job.

I've had a look through the api reference, but I can't see anything regarding preferences or settings or something I can use.

Best Answer

I suggest you don't even use world edit, Making a bukkit plugin from scratch is very easy and very fun.

Bukkit's API has very usful block-editing tools, this peice of code here will place a block of stone(b.setTypeId(1);) above every player's head whenever they move.

    public void onPlayerMove(PlayerMoveEvent evt) {

    Location loc = evt.getPlayer().getLocation();

    World w = loc.getWorld();

    loc.setY(loc.getY()-1);
    Block b = w.getBlockAt(loc);
    if(!b.isEmpty())
    {
    b.setTypeId(1);
    }}

And as for the anti-crashing, just make the plugin run on a separate thread from the main server, this way if your plugin "crashes" the server won't respond any diffrently until the plugin has finished calculating and will finish at quicker speed.