Regenerating blocks

Discussion in 'Plugin Development' started by bananashavings, Apr 24, 2014.

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

    bananashavings

    Hi, basically what I want this plugin to do is that when there is an explosion, it regenerates each of those blocks one at a time every 1 second. This is a snippet of my code so far but its not working. Please check it out :p

    Code:java
    1. @EventHandler
    2. public void regenBlocks(final EntityExplodeEvent event) {
    3.  
    4. final List<Block> explodedBlocks = event.blockList();
    5.  
    6. getServer().getScheduler().scheduleSyncRepeatingTask(this,
    7. new Runnable() {
    8. public void run() {
    9. if (explodedBlocks.size() > 0) {
    10.  
    11.  
    12. Random random = new Random();
    13. int regenBlock = random.nextInt(explodedBlocks
    14. .size());
    15.  
    16. final Block block = explodedBlocks.get(regenBlock);
    17. Bukkit.broadcastMessage(block.getType().toString());
    18.  
    19. explodedBlocks.get(regenBlock).setType(
    20. block.getType());
    21. explodedBlocks.remove(regenBlock);
    22. } else {
    23. if (explodedBlocks.size() >= 0)
    24. getServer().getScheduler().cancelAllTasks();
    25. else
    26. return;
    27. }
    28. }
    29. }, 0, 20);
    30.  
    31. }
     
  2. Offline

    xTigerRebornx

    bananashavings You are setting the blocks type to the type it already has, which does nothing. You'd need to store both the Block and its Material.
     
  3. Offline

    bananashavings

    Thanks for replying. Are you able to post any code?
     
  4. Offline

    xTigerRebornx

    bananashavings I don't like to spoonfeed people code, but I have suggestions. Either make your own class for handling it (like an object that takes in the parameters of Block and Material) and store it in a list, or use a Map/HashMap to store both the Block and Material.
     
  5. Offline

    bananashavings

    xTigerRebornx Its not that im lazy, im just unexperienced so any code would help. Im sorry if this frustrates you but I really appreciate help
     
  6. Offline

    PatoTheBest

    Look up Block State.
     
  7. Offline

    bananashavings

    PatoTheBest Could you please help me with code if possible
     
  8. Offline

    PatoTheBest

    Code:
    List<BlockState> states = new ArrayList<>();
    
    // Listener
    states.add(event.getBlock().getState());
    
    // Rollback
    for (BlockState state : states) {
        state.update(true);
        states.remove(state);
    }
    
     
Thread Status:
Not open for further replies.

Share This Page