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.
Please read this: https://bukkit.org/threads/how-to-make-a-plugin-development-thread.395844/ As for your actual problem, save all the blocks in your map, and when you want to reset the map, load all the blocks from that save.
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.
@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.
@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.
@deret123 I posted how to do what you wanted in the previous post. These are all the links needed in order to fully understand what you're going to be doing: //How a hashmap works. http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html //How a for loop works http://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html //How to create a class that will store all the block's data. http://docs.oracle.com/javase/tutorial/java/javaOO/classes.html
@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.
@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); } }
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?
@Zombie_Striker When I reload the server only the broken blocks respawn but placed blocks don't disappear
@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
@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++; }
@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