Solved Restore world to original state

Discussion in 'Spigot Plugin Development' started by gamerpig, Jun 30, 2021.

  1. Hello Spigot Community!
    I have a question on how to restore a world before any blocks has been broken or placed. I'm making a mini game where people have to do multiple tasks, one of them being breaking down trees. I want the players to break the trees and then be able to restore the forest before anything was broken. Hope that isn't to confusing...
  2. coreprotect?
  3. would I have to use their api?
  4. This video should be helpful:
    • Agree Agree x 1
  5. The only problem with this video is that its very fast pase and doesn't explain in depth
    I will still be open to any more replies
  6. If you are integrating that function into your own plugin, I think using CoreProtect API is a good idea, since there is really no point in reinventing the wheel. The detailed tutorial can be found here CoreProtect - API [v6] - Minerealm Community Forums. But if you want a quick answer, CoreProtect API has this method

    Code (Text):
    List<String[]> performRollback(int time, List<String> restrict_users, List<String> exclude_users, List<Object> restrict_blocks, List<Object> exclude_blocks, List<Integer> action_list, int radius, Location radius_location)
    which allows you to basically perform the same thing has a "/co rollback" in game. By calling this method you would be able to restore your map to certain prior timestamp. So you just need to log in your plugin data file when your game started, so later you would know which point in time to restore to. You can add CoreProtect dependency in your pom.xml as follows. Also don't forget to make sure that CoreProtect is in the dependency list of your plugin.yml

    Code (Text):

  7. I was thinking more of replacing all
    Thanks I'll try it out!
  8. Set up some kind of world template your servers use and copy on boot/don't save the world. This is probably the simplest and cleanest approach to what you're looking for.
  9. what do you mean by template?
  10. Can you not unload and reload it?
    Auto save disabled
  11. how would i do that
  12. I think it probably means having a "fresh" folder with the original world somewhere in your server root dir, and then when you want to restore you can just either use some other API (such as Multiverse) to re-import the fresh world.
    • Like Like x 1
  13. Can't show you the code atm, try googling it, you should find it
  14. ok, thanks
    • Like Like x 1
  15. I am currently using multiverse so this seems pretty easy to implement.
  16. so I looked into the multiverse-core API documentation and it talks nothing about importing world. Do you know how to do it?
  17. Yeah I browsed through their Javadocs and indeed there does not seem to have a direct equivalent to 'mv import' in game. However I did see this
    Code (Text):
    cloneWorld(String oldName, String newName)
    , which seems to suggest that you can make your template world named like "minigame-template" and keep cloning that when you want a refresh (ofc call the deleteWorld() on the old world first)
  18. ok thank you! I would say this thread is Solved!
    • Like Like x 1