Solved Log and rollback blocks

Discussion in 'Plugin Development' started by PatoTheBest, Apr 10, 2014.

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

    PatoTheBest

    Hello Guys,
    I was wondering how can I log and then rollback blocks? I know I can log them with the block break event but how do I actually save them and rollback them?

    Kind Regards,
    -Pato
     
  2. Offline

    amhokies

    Save the necessary block data into a database.
     
  3. Offline

    xTrollxDudex

    PatoTheBest
    Save block state. Update block states when you want to rollback.
     
  4. Offline

    PatoTheBest

    I don't know how to save them or which hashmap or what. Can anyone provide me a piece of code?
     
  5. Offline

    Zethariel

    PatoTheBest You see, that's the whole point of plugin development. To figure such stuff out.

    What you have to do:
    1. Capture the event
    2. Log the BlockState or whatever you need into a flatfile/SQL/YML whatever
    3. Create a command that would iterate upon the changes in reversed chronological order

    That being said, logging plugins can be really complex, with different types of logging, rollbacks that can happen in an area, according to block type, dates etc. It might be a bit much.
     
  6. Offline

    PatoTheBest

    Zethariel
    I have this code and I want to log all the blocks and then rollback when the game finishes.
    Code:java
    1. @EventHandler
    2. public void Break(BlockBreakEvent event){
    3. Player player = event.getPlayer();
    4. if (ArenaManager.getManager().isInGame(player)){
    5. //code
    6. }
    7. }


    Bunp

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

    xTrollxDudex

    PatoTheBest
    PHP:
    List<BlockStatestates = new ArrayList<>();

    // Listener
    states.add(event.getBlock().getState());

    // Rollback
    for (BlockState state states) {
        
    state.update(true);
    }
     
  8. Offline

    PatoTheBest

    xTrollxDudex
    Oh, I didn't know there was a BlockState class. Thanks, will try it out.
     
  9. Offline

    blablubbabc

    Note that block states might not properly restore tile entity data (like sign text or check content) if the block changes it's type in the meantime. At least that was an issue the last time I wanted to use them to temporary store and restore blocks which get removed by explosions.
     
  10. Offline

    PatoTheBest

    Yep, creating a thread for that
     
  11. Offline

    Garris0n

    They won't? I'd think they would, they store the data in them...

    @OP For what you're doing I would recommend copying world files for arenas instead of rolling back blocks, it's a lot "safer". But do what you like, I suppose.
     
  12. Offline

    PatoTheBest

    They don't, check my other thread http://forums.bukkit.org/threads/itemstack-broken.256802/
    I tried to temp. save the data but it is wired.
     
  13. Offline

    blablubbabc

    They store the data but they don't properly restore it if the block type changed in the meantime (for example for type 'chest' to 'air'). The update method set the block back to type 'chest' but fails to restore it's conent. See this ticket about it: https://bukkit.atlassian.net/browse/BUKKIT-3522
     
Thread Status:
Not open for further replies.

Share This Page