WorldEdit

WorldEdit

43M Downloads

API for pasting schematics seems to be laggy

JHarris12345 opened this issue ยท 7 comments

commented

WorldEdit Version

7.2.6+4b2d1e7

Platform Version

Paper 1.17.1

Confirmations

  • I am using the most recent Minecraft release.
  • I am using a version of WorldEdit compatible with my Minecraft version.
  • I am using the latest or recommended version of my platform software.
  • I am NOT using a hybrid server, e.g. a server that combines Bukkit and Forge. Examples include Arclight, Mohist, and Cardboard.
  • I am NOT using a fork of WorldEdit, such as FastAsyncWorldEdit (FAWE) or AsyncWorldEdit (AWE)

Bug Description

Hey I am just curious to understand why TPS drops for about 20 seconds when a plugin of mine pastes a worldedit schematic. From the looks of it, it is the bukkit adapter getting the actual chunk that is being edited which is causing lag and this is for a schematic that is only 3 blocks big (used a very small one to just test). So I am unsure why so much lag is being caused for this.

I have 2 sparks:
Idle spark where the schematic was not being pasted (no lag): https://spark.lucko.me/wWJUYo2Ugf
The lag during the schematic being pasted: https://spark.lucko.me/QfB3EhAwJv

My code to paste the schematic is:

` @OverRide
public void paste(File file, Location location, Island island) {
try {
ClipboardFormat format = ClipboardFormats.findByFile(file);
ClipboardReader reader = format.getReader(new FileInputStream(file));
Clipboard clipboard = reader.read();

        World world = IridiumSkyblock.getInstance().adaptedWorld;

        if (location.getWorld().getName().equalsIgnoreCase("skyblock_nether")) world = IridiumSkyblock.getInstance().adaptedNether;
        if (location.getWorld().getName().equalsIgnoreCase("skyblock_world")) world = IridiumSkyblock.getInstance().adaptedWorld;

        try (EditSession editSession = com.sk89q.worldedit.WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1)) {
            editSession.setFastMode(true);
            Operation operation = new ClipboardHolder(clipboard)
                    .createPaste(editSession)
                    .to(BlockVector3.at(location.getX(), location.getY(), location.getZ()))
                    .ignoreAirBlocks(true)
                    .build();
            Operations.complete(operation);
        }
    } catch (Exception e) {
        IridiumSkyblock.getInstance().getLogger().warning("Failed to paste schematic using worldedit");
        IridiumSkyblock.getInstance().getSchematic().paste(file, location, island);
    }
}`

Thanks for your help in advance

Expected Behavior

Hopefully no lag ahah

Reproduction Steps

  1. Use the code I have to paste a schematic

Anything Else?

No response

commented

You should try preparing the schematic in advance, rather than blocking the main thread while loading it. It is safe to load a schematic async, or you could just do it at start up if you know what they are then. I/O is extremely expensive and may be responsible for a slight slow-down. Though it appears from your sparks that WorldEdit is far from the most demanding plugin on your server, even while pasting.

commented

Additionally, please use the discord for support in the future, as this is not an actual bug.

commented

I got banned from the discord like 2 years ago for asking about an update. So if you want to unban me that would be generous thanks. Discord is JHarris#0482

commented

@octylFractal But if I cannot be unbanned, do you mind giving me some support here on how I would go about loading the schem on startup? Because it seems the actual lag is coming from parsing the chunks where it is going to get pasted. I even adapt the world on startup which didnt help either

commented

You don't appear to be banned. So, try joining?

commented

In fact, you're literally in the discord right now?

commented

Sorry completely forgot I recently got unbanned. Sorry about that