Arena Regeneration?

Discussion in 'Plugin Development' started by mastertrolable, Aug 17, 2015.

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

    mastertrolable

    Hi am creating a plugin for a server one of my friends have I known a good bit of java to make some advanced plugins and stuff but am a little stuck as I want users to be able to place blocks but at the end of the minigame match want the arena reset back to default so that the blocks the users placed will be gone.

    And was wondering how to do these I have tried looking into the possibility's of the situation like for example
    schematics and world edit but still don't see how this could be done.

    I do know it is possible because other minigames use area regeneration methods such as spleef and other minigames.

    So if you could please help or know of a plugin that could do this please let me know.
     
  2. Create a List<Block> and on BlockPlaceEvent store all the blocks in it. At the end of the game, loop through the list and remove each block (.setType(Material.AIR)). Finally clear the list
     
    Shortninja66 likes this.
  3. Offline

    CraftCreeper6

  4. Offline

    mastertrolable

    Thanks so much

    That didn't help
    Code:
    List<Block> blocks = new ArrayList<Block>();
    
    for(Block block :blocks)
    {
        block.setType(Material.AIR);
    }
        blocks.clear();
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  5. Offline

    nj2miami

    @mastertrolable I suggest against trying to store all of the blocks modified during a game. You will have to ensure so many variables do not happen or you track appropriately so no one can break blocks, no TNT explosions, creeper explosions, water/lava destruction, etc.

    Allowing players to place blocks can still create headaches for moving water and lava and things they could destroy, fire destruction, etc.

    I would suggest (and what I do) is setting the map to not save and then just reload the map when your game is over. In my case, I added an OP command to force save the loaded world so I can make changes to it and save those changes but when the game is running no changes are saved.
     
  6. Offline

    mastertrolable

    How I don't to reload the world since the server is a minigame server and multiple minigamessages will be running at once

    Don't want to reload since multiple minigames will be running at different times

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Aug 17, 2015
  7. Offline

    CraftCreeper6

    @nj2miami
    Wrong, you can add to the block list when an explosion goes off, you can add air to the block list when lava and water spread. I agree, the more blocks you store the more lag occurs when you redo all the blocks but it's the most efficient way.
     
  8. Offline

    drew6017

  9. Offline

    nj2miami

    There is nothing I said that was wrong. You however are grossly wrong by stating tracking blocks is the "most effecient way". There are so many ways a block can be destroyed and if you do not track every event which they can occur in you will lose blocks at some point and degrade the rebuild over time.

    I didn't say you COULDN'T add blocks when an explosion goes off, I said you would have to TRACK all of those events to ensure you capture the blocks lost in those events.

    Also, lava can destroy objects, water can wash away objects, all of which would have to be accounted for to "rebuild" what was destroyed. It is an extremely complex task to ensure your world reverts back to its exact state.

    I stand by my assertion that the simplest and most fail safe way is to "roll back" the world by not allowing the world to save and then reload it when ready.

    To manage multiple games running, you could copy the world and load each copy for each game started then removing the world post game is the simplest way to ensure a 100% success rate. The complexity increases exponentially as you try to allow one plugin to manage multiple games from a programming management standpoint though.

    I am not sure at what level the OP proficiency is at but I am guessing by the question that trying to scope a plugin to manage multiple running games and revert those maps might be a challenge.
     
  10. Offline

    CraftCreeper6

    @nj2miami
    Tracking all the blocks is not at all a complex task, it's just a matter of time. Destroying blocks, placing blocks, explosions, destruction by liquids can all be tracked and added to the BlockList, your argument is partly invalid, I do agree there are efficient ways of doing it better but non are less task heavy than the block list. Reloading the world will require a server restart, re-loading all of the plugins again. Despite how time consuming such a task would be, I still stand by my word. It's the most efficient way.
     
  11. What about hooking into CoreProtect which is designed to backup/save/rollback and much more?
     
    Shortninja66 likes this.
  12. Offline

    CraftCreeper6

    @FisheyLP
    That's another plugin to load!

    EDIT: A large one too!
     
  13. Offline

    nj2miami

    You are WAY off base here. I implement loading/unloading worlds in many of my "arena type" plugins at little to no noticeable effect on server performance. It does NOT require a server restart so I have no idea where you get that from.

    It is so simple and efficient there is really no excuse to monitor block breaking events if the pure intent is to "roll back" the world to a previously saved state. Your argument is not only NOT an argument, it shows your inexperience in Bukkit.

    One line to unload your world ->
    Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(mapname), false)

    Simply reload it:
    Bukkit.getServer().createWorld(new WorldCreator(mapname));

    Make sure no world data is saved:
    Bukkit.getWorld(mapname).setAutoSave(false);

    It is brain dead simple. No need to log all blocks destroyed in the numerous events that will be required to undo.
     
  14. Offline

    CraftCreeper6

    @nj2miami
    You must also manage each player in the arena and extra people in the world to teleport them out before the world unloads otherwise they get kicked, unless you're on a bungee server that isn't supported here.
     
  15. Offline

    AdobeGFX

    Can use schedulers and teleport them out, then in when the world is done unloading, and loading, and wathever..
     
  16. Offline

    CraftCreeper6

    @AdobeGFX
    You would have to track every person just like you'd have to track every block, that's what I mean.
     
  17. Offline

    AdobeGFX

    yea, lel, i just came up with a suggestion tho..
    Btw, does he have multiple arenas in one world??
     
  18. Offline

    CraftCreeper6

    AdobeGFX likes this.
  19. Offline

    AdobeGFX

    What about using World Edit Api???
    Copy and paste. Somehow this should work..
     
  20. Offline

    CraftCreeper6

    @AdobeGFX
    It would work, however, big pastes take up a lot of CPU, leading to server crashes.
     
  21. Online

    timtower Administrator Administrator Moderator

    You could cut it in smaller pieces though, would take more time but would be better for the CPU if done correctly
     
  22. Offline

    CraftCreeper6

    @timtower
    Possibly, with a painstaking method, that would be very efficient.
     
    timtower likes this.
  23. Offline

    Konato_K

    Personally I have found world loading techniques the cleanest, you can just load a world when you need it and drop it away when you need another one.

    Loading worlds it's way faster than restoring a bunch of blocks (or pasting everything with WE), however, it will use more server memory.
     
  24. Offline

    CraftCreeper6

    @Konato_K
    The less memory the better, you would have to restart the server on intervals.
     
  25. Offline

    Konato_K

    @CraftCreeper6 Not if you properly remove the world once it's not needed, and no, the less memory is not always the better, it depends on what's you're situation and what are you looking for.
     
  26. Offline

    CraftCreeper6

    @Konato_K
    For performance and no lag, it's best you keep the memory usage on the down low.
     
    Last edited: Aug 20, 2015
  27. Offline

    mythbusterma

    @CraftCreeper6

    Depends on your usage requirements. In general, Minecraft servers have a lot more excess CPU than they have excess RAM, so algorithms that more heavily favor the CPU over RAM are more suitable to the average server.

    In this case, I agree with CraftCreeper, the best way of doing this is to save all the changes (in whatever form they may occur) and then restore them after the end of the match.

    Also, "lag" is spelled with one 'g.'
     
  28. Offline

    CraftCreeper6

  29. Offline

    nj2miami

    @mythbusterma @CraftCreeper6

    I'm sorry but I have been coding in Bukkit for over 3 years now and in my own experience, tracking blocks to restore them is not a simple task and almost always eventually creates spots where blocks get "missed". If you are perpetually saving / restoring blocks in an area it is almost a certainty that at some point you will find a block missed.

    Like I have said from the beginning, grabbing blocks from all the necessary events to track places when a potential block COULD be destroyed is far more tedious than simply unloading/reloading the world.

    Let's be honest here. No one is here coding for a Mineplex size server so most of the arguments over CPU vs RAM is essentially a moot discussion.

    Most, if not all, who come here with a question are running small private servers or servers which a few CPU cycles here or there will hardly be noticeable. My answers are always geared towards those who are likely seeking the answer.

    There is never a "one answer answers all" answer anyhow but I try to provide efficiency and common sense responses.

    If you really want to attack efficiency, how about his plugin should probably be managing a world per arena match and not place all his active arenas on one map.

    This way he could simply load/unload each map as he needs.

    I will leave it with this. The best grief / rollback plugins monitor upwards of 70 events which destruction CAN happen. The average programmer here probably will use 4-5. There are so many ways blocks can break, it is a daunting task to understand where this can happen.

    Here is a (partial) list from one of the better rollback plugins and what they track:

    Events (open)

    block-break
    block-burn
    block-dispense
    block-fall
    block-place
    block-shift
    block-spread
    block-use
    bucket-fill
    bonemeal-use
    creeper-explode
    crop-trample
    enderman-pickup
    enderman-place
    entity-break
    entity-explode
    fireball
    fire-spread
    hangingitem-break
    hangingitem-place
    lava-break
    lava-bucket
    lava-flow
    lava-ignite
    leaf-decay
    lightning
    mushroom-grow
    sign-change
    tnt-explode
    tnt-prime
    tree-grow
    vehicle-break
    water-break
    water-bucket
    water-flow
    world-edit
     
    Last edited: Aug 20, 2015
  30. Offline

    CraftCreeper6

    @nj2miami
    You are saying that he should be using different worlds, and I agree, he should. However, using multiple worlds (especially if it's a popular network like Mineplex) can be a very inefficient way. Uses a lot of basically everything and causes lag like no tomorrow.

    Despite all the events required to track all of the blocks, it would still be more efficient based on the fact that you can have people editing that world without being kicked out of it and the changes not being saved.

    It can be annoying when a world doesn't save. I've been there.

    In addition, the amount RAM usage required to unload a world and load it again would be bigger than the Titanic. Not to mention the CPU. Lag is a tough subject, however, I still say it's the most efficient way. Nothing is going to change my opinion as far as my knowledge of the Bukkit API goes.
     
Thread Status:
Not open for further replies.

Share This Page