Dan_Ender

SimpleMapReset

Mar 12th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package ru.Dan_Ender.SimpleMapReset;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.event.EventHandler;
  8. import org.bukkit.event.Listener;
  9. import org.bukkit.event.block.BlockBreakEvent;
  10. import org.bukkit.event.block.BlockPlaceEvent;
  11.  
  12. @SuppressWarnings("deprecation")
  13. public class SimpleMapReset implements Listener {
  14.    
  15.     private static final HashMap<Location,MaterialData> recordedBlocks = new HashMap<>();
  16.    
  17.    
  18.     @EventHandler
  19.     public void onBlockBreak(BlockBreakEvent e) {
  20.         recordedBlocks.put(e.getBlock().getLocation(), new MaterialData(e.getBlock().getType(), e.getBlock().getData()));
  21.     }
  22.    
  23.     @EventHandler
  24.     public void onBlockPlace(BlockPlaceEvent e) {
  25.         recordedBlocks.put(e.getBlock().getLocation(), new MaterialData(e.getBlockReplacedState().getType(), e.getBlockReplacedState().getRawData()));
  26.     }
  27.    
  28.     public static void resetMap() {
  29.         for (Location location:recordedBlocks.keySet()) {
  30.             MaterialData materialData = recordedBlocks.remove(location);
  31.             location.getBlock().setType(materialData.getMaterial());
  32.             location.getBlock().setData(materialData.getData());
  33.         }
  34.     }
  35.    
  36.     private final class MaterialData {
  37.        
  38.         private Material material;
  39.         private Byte data;
  40.        
  41.         public MaterialData(Material material, byte data) {
  42.             this.material = material;
  43.             this.data = data;
  44.         }
  45.        
  46.         public Material getMaterial() {
  47.             return material;
  48.         }
  49.        
  50.         public byte getData() {
  51.             return data;
  52.         }
  53.        
  54.     }
  55.    
  56. }
Advertisement
Add Comment
Please, Sign In to add comment