'Copy large regions with Spigot
I'm currently working on a training plugin, where every player would get his own region, to learn bridge for example. So when a player joins, the plugin should automatically generate a new area for this player and delete it when he leaves.
I've created a SetupCommand where you have to set the start and end of the region that should be copied.
Now the only thing to do is copy the region and teleport the player to it, however, I couldn't find any good ways to do that. The only solution I found so far is to loop through all blocks and copy them one by one. But I can imagine that this is not the best solution and would cause lag, not only server-side but also client-side.
Are there better ways to clone a region than that? I've read you should use Schematics but they weren't going into detail.
Solution 1:[1]
If you are experienced with java and feel comfortable about your skills you can try to get the blocks in the list as List and save it as base64 into your database or whatelse. You can parse it everytime back into a list of blocks and replace it. I would rather recommend you to make a custom block class with implements Serializeable
and then add some values like Location
, Material
and BlockData
to it.
Solution 2:[2]
Use FAWE or WorldEdit to copy/paste sections
If you use Block#setType, performance will be very slow, so if you don't want to use the API, you should use NMS, but using NMS is not a good practice.
Disadvantages of NMS: Most nms methods are obfuscated. In one version the method is called f(), in the next version maybe c().
How to copy/paste with FAWE: https://www.spigotmc.org/threads/how-to-paste-a-schematic-with-fawe.402950/
How to copy/paste with worldedit: https://www.spigotmc.org/threads/worldedit-api-schematic-copy-save-load-and-paste.498476/
In conclusion, it is recommended to use the API
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Levi Heßmann |
Solution 2 | NullPointerException |