Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.Dan_Ender.SimpleMapReset;
- import java.util.HashMap;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.block.BlockPlaceEvent;
- @SuppressWarnings("deprecation")
- public class SimpleMapReset implements Listener {
- private static final HashMap<Location,MaterialData> recordedBlocks = new HashMap<>();
- @EventHandler
- public void onBlockBreak(BlockBreakEvent e) {
- recordedBlocks.put(e.getBlock().getLocation(), new MaterialData(e.getBlock().getType(), e.getBlock().getData()));
- }
- @EventHandler
- public void onBlockPlace(BlockPlaceEvent e) {
- recordedBlocks.put(e.getBlock().getLocation(), new MaterialData(e.getBlockReplacedState().getType(), e.getBlockReplacedState().getRawData()));
- }
- public static void resetMap() {
- for (Location location:recordedBlocks.keySet()) {
- MaterialData materialData = recordedBlocks.remove(location);
- location.getBlock().setType(materialData.getMaterial());
- location.getBlock().setData(materialData.getData());
- }
- }
- private final class MaterialData {
- private Material material;
- private Byte data;
- public MaterialData(Material material, byte data) {
- this.material = material;
- this.data = data;
- }
- public Material getMaterial() {
- return material;
- }
- public byte getData() {
- return data;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment