Regeneration map

Discussion in 'Plugin Development' started by deret123, Dec 30, 2015.

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

    deret123

    Hi, I've a problem with my plugin, it's a rush plugin but I don't see how to regenerate the map at the end of a game, I tried to erase the map and copy the content of other map in but without sucess, if someone have a solution...
    Thx to your answers.
     
  2. Offline

    Zombie_Striker

  3. Offline

    deret123

    How can I do that ?
    Sorry if my question is stupid but I learned the Bukkit Api 1 week ago
     
  4. Offline

    Xerox262

  5. Offline

    deret123

    Can you help me to do that please ? ^^
     
  6. Offline

    deret123

    I've just to copy and paste this code (and modify values of world and place the map in plugin folder) ?

    I think it will be more easy for me to use a method to save blocs of the map at the start of the plugin and copy at the end

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

    deret123

  8. Offline

    Zombie_Striker

    @deret123
    You misspelled "Bump".
    • Create a HashMap. Keys will be the location, The value will be any data about the block (Block Type/ Block data/ block meta)
    • When saving the map, Save the location of each block to the hashmap, with the data as the keys.
    • When loading the map, loop through all the keys in the hashmap, and set the block at each location with the data.
     
  9. Offline

    deret123

    Which command can I use ?
     
  10. Offline

    Zombie_Striker

    @deret123
    Please tag me if you want me to respond.

    What do you mean "which command"? Looking back, no one has ever mention anything about commands.
     
  11. Offline

    deret123

    @Zombie_Striker Sorry I'm expressing badly, I wanted to say how can I do that with the code ?
     
  12. Offline

    Zombie_Striker

  13. Offline

    deret123

    @Zombie_Striker

    This solution don't work, my server crash at more than 1000 blocks...
     
  14. Offline

    Zombie_Striker

    @deret123
    Well, yeah. You're overloading your server. May we see your code? Most likely you not add any breaking method if it goes on for too long.
     
  15. Offline

    deret123

    @Zombie_Striker

    I found other code in youtube but don't work with blockPlaceEvent
    Code:
        @SuppressWarnings("deprecation")
        public static void restore() {
            int blocks = 0;
            for (String b : CHANGES) {
                String[] blockdata = b.split(":");
              
                int id = Integer.parseInt(blockdata[0]);
                byte data = Byte.parseByte(blockdata[1]);
                World world =Bukkit.getWorld(blockdata[2]);
                int x = Integer.parseInt(blockdata[3]);
                int y = Integer.parseInt(blockdata[4]);
                int z = Integer.parseInt(blockdata[5]);
              
                world.getBlockAt(x, y, z).setTypeId(id);
                world.getBlockAt(x, y, z).setData(data);
                blocks++;
            }
          
            System.out.println("Map régénéré : "+blocks+" blocs régénérés");
        }
      
    
      
      
      
        private static List<String> CHANGES = new LinkedList<String>();
      
      
        @EventHandler
        public void onBreakEvent (BlockBreakEvent e) {
            Block b = e.getBlock();
            @SuppressWarnings("deprecation")
            String block = b.getTypeId() + ":" + b.getData() + ":" + b.getWorld().getName() + ":" + b.getX() + ":" + b.getY() + ":" + b.getZ();
          
            CHANGES.add(block);
            plugin.getConfig().set("mapregen", block);
          
        }
      
        @EventHandler
        public void onPlaceEvent (BlockPlaceEvent e) {
            Block b = e.getBlock();
            @SuppressWarnings("deprecation")
            String block = b.getTypeId() + ":" + b.getData() + ":" + b.getWorld().getName() + ":" + b.getX() + ":" + b.getY() + ":" + b.getZ();
          
            CHANGES.add(block);
        }
      
      
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onEntityExplode(EntityExplodeEvent e) {
          
            for (int i = 0; i<e.blockList().size(); i++) {
                Block b = e.blockList().get(i);
                String block = b.getTypeId() + ":" + b.getData() + ":" + b.getWorld().getName() + ":" + b.getX() + ":" + b.getY() + ":" + b.getZ();
              
                CHANGES.add(block);
            }
          
        }
    
     
    Last edited by a moderator: Jan 2, 2016
  16. Offline

    Zombie_Striker

    This is expected from youtube tutorials.
    This method has been deprecated for a reason. Minecraft is trying to move away from IDS. Try instead Material.toString().

    As for your actual problem. What do you mean "Don't work"? Does the event not get triggered? Did you debug?
     
  17. Offline

    deret123

    @Zombie_Striker

    When I reload the server only the broken blocks respawn but placed blocks don't disappear
     
  18. Offline

    Zombie_Striker

    What gets added to the array? Are you sure the ID provided is air?
     
  19. Offline

    deret123

    @Zombie_Striker
    This code will not work because on place block and destroy the block will be replaced...

    Or if it's possible find thing to see the order of blocks added in the loop for just set the 1st of the list. I would say add new blockdata in the array and compare for the same coords the 1st block which was modified
     
    Last edited: Jan 2, 2016
  20. Offline

    Zombie_Striker

    @deret123
    What if you create another array called "remove", and all blocks that should be removed would go into that array. Since you would always want to set the removed blocks to air, all you need to save is:
    Code:
    @EventHandler
        public void onPlaceEvent (BlockPlaceEvent e) {
            Block b = e.getBlock();
            @SuppressWarnings("deprecation")
            String block = b.getWorld().getName() + ":" + b.getX() + ":" + b.getY() + ":" + b.getZ();
         
            REMOVES.add(block);
        }
    And add this to the restore method
    Code:
            for (String b : REMOVES) {
                String[] blockdata = b.split(":");
    
                World world =Bukkit.getWorld(blockdata[0]);
                int x = Integer.parseInt(blockdata[1]);
                int y = Integer.parseInt(blockdata[2]);
                int z = Integer.parseInt(blockdata[3]);
             
                world.getBlockAt(x, y, z).setTypeId(0);
                blocks++;
            }
     
  21. Offline

    deret123

    @Zombie_Striker
    Don't work if I place and break the block, after reload I've the block placed
    I think I've to use the order of events (place or break) to restore only the first block which was modified
     
    Last edited: Jan 2, 2016
Thread Status:
Not open for further replies.

Share This Page