Best way to go about reloading a map for a minigame?

Discussion in 'Plugin Development' started by MayoDwarf, Jan 1, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    MayoDwarf

    I had a few ideas in my head. I just want your thoughts and ideas on how you would do this, as perhaps they may be easier and better for the future. The concept is: This is for a minigame. When the game is over, it will recreate the map without having to stop the server and restart it. Thanks - Jared
     
  2. Offline

    Wizehh

  3. Offline

    NoLiver92

    MayoDwarf how big is the arena? if its small you can use schematics and paste it over the old map. or if its a whole world then you can copy a saved world, unload the first one and load in the second world.
     
  4. Offline

    MayoDwarf

    It's a whole world. Will update post in a minute with that information. How would we do these? Thanks. :)
     
  5. Offline

    Bart

    Keep an untouched copy of the map.

    When you start the game, copy the map over to a new world and load it. Unload when game stops and only delete when the server is stopping. Make it restart every X number of games
     
  6. Offline

    caseif

    I have a minigame plugin which uses entire worlds as arenas, so what I have it do is recreate the world with the prefix "TTT_", then just delete that and recreate it again upon the end of each round. It's surprisingly fast, though it's probably not the best way of doing it. An alternative would be to store every block modified to memory, though this could be problematic if you expect a large quantity of blocks to be modified. To avoid keeping them in memory, you could simply write them to disk in real time using a YAML file. You would just have to remember to store the block's ID, data, and state properly with this approach.

    EDIT: To append to what Bart said, you wouldn't need to wait for a restart to reset the world. You would just need to unload it manually; then you could easily delete it and replace it. However, I found the need to reference Multiverse's API due to it having issues with this approach. You would need to also manually unload the world from MV before deleting if it's enabled, lest you be riddled with countless pointless exceptions.
     
  7. Offline

    MayoDwarf

  8. Offline

    reider45

    Well this is what i did for my minigame, and it worked just fine :)

    Make sure to use /save-off or something like that

    Code:java
    1. if(Bukkit.getServer().unloadWorld("worldname",false))
    2. {
    3. new File("serverfolder/worldname").delete();
    4. Bukkit.broadcastMessage(ChatColor.GREEN + "World Rolledback...");
    5. new WorldCreator("worldname").createWorld();
    6. }


    Good luck :)
     
  9. Offline

    Garris0n

    Copy-pasting world files.
     
  10. Offline

    MayoDwarf

    ShadyPotato The problem with storing the blocks destroyed to memory is the blocks destroyed by TNT and also water and lava I don't think would be counted or called for to save as a block (May be wrong).
     
  11. Offline

    Bart

    The only reason that you would avoid deleting it at runtime is because it (just as copying the world does) causes a bit of lag. For my server, at least, it's not an issue and we restart every 50 games to delete maps.
     
  12. Offline

    MayoDwarf

    reider45 Would the .createWorld() work for a world copied and pasted by code to be loaded up or no?

    Bart This shouldn't be an issue for a server that hosts 8GB of ram I hope.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  13. Offline

    Bart

    Don't double post. We're on a 128GB dedicated server, it isn't but it is something that you can avoid for the sake of a restart every now and again. Besides, you will probably want the servers to restart every 30-50 games just to clear up some memory
     
  14. Offline

    MayoDwarf

    Hmm true true. So what do you think the best way is going about this? Bart
     
  15. Offline

    Bart

    I have this setup:

    /plugins/MyPluginName/arenas/[arena name]/world

    Start:
    -> Copy the world folder to "current_" and then append a number on the end that increases for every time a new game starts.
    -> Load "current_[number]"
    -> Start game, teleport people in etc

    Stop:
    -> Teleport everyone out
    -> Unload current_[number]
    -> Increment the number variable
    -> Once number reaches X amount, restart the server (stop and get something else to start it up again)


    Then onEnable:
    -> Loop through all folders, check if they begin with current_ and delete accordingly
     
  16. Offline

    MayoDwarf

    Hmm this may be a great new way, but can logging the blocks and putting them in their spots work too? The only problem I would find with this is the fact of the water and lava not being counted and also TNT destroying blocks that won't get counted because they don't get called in block break event right? Bart
     
  17. Offline

    Bart

    You would have to store all of that data in memory. It's way easier to do what I said than have to accomodate for all of the things you mentioned: TNT, Water destroying blocks, Endermen, Ender dragons, withers etc

    EDIT: Oh I forgot to mention, in the /plugins/MyPluginName/[arena name], I have a config.yml file as well that has information about that particular arena.
     
  18. Offline

    RawCode

    On my server minigame worlds feature custom world generator that able to generate endless array of required arena.

    This allow players to visit minigame world and play without operator interaction.
     
  19. Offline

    Forseth11

    MayoDwarf If it is a whole world I made my own type of reset that I use for my SkyWars plugin. What you do is turn all saving off. And make a method to refresh the non-saved world when it needs to be reset.
     
  20. Offline

    Foorack

    MayoDwarf You COULD use (if you know what it is and how to use it) a bungee-network with 2 servers. A hub server and 1 mingame server. When the user writes /minigame join you teleport them to the minigame server and the game starts.
    When the game is finished you teleport everyone back to where they where before or a specific position (your choise) and restart the minigame server, that also deletes the "used" world and copy's the new one.. Example startup script of the minigame server: (Windows, just ask if you need a linux version of it..)
    Code:
    @echo off
    cls
    :: start section
    xcopy /e /i "GameWorldBACKUP\*.*" "GameWorld"
     
    :: minecraft section
    java -Xmx4096M -Xms2048M -jar craftbukkit.jar
     
    :: end section
    rmdir /s /q "GameWorld"
    start.bat
    That's at least how I do it and it works fine for me :p

    (And yes, it have to be more complicated than it has to).. ^_^
    ~Foorack
     
  21. Offline

    reider45


    Not sure what you mean, care to expand on it?
     
  22. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page