Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.Dan_Ender.utils;
- import java.util.ArrayList;
- import java.util.HashMap;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.entity.Player;
- import ru.Dan_Ender.config.LWEConfig;
- import ru.Dan_Ender.events.LWEEventListener;
- public class Buffer {
- private final LWEConfig cfg = LWEEventListener.cfg;
- ArrayList<HashMap<Location,String[]>> undo = new ArrayList<>();
- ArrayList<HashMap<Location,String[]>> redo = new ArrayList<>();
- Player p;
- int current = -1;
- HashMap<Location,String[]> last;
- public Buffer(Player p) {
- this.p = p;
- }
- public void add(HashMap<Location,String[]> rg) {
- if (undo.size()==30) {
- undo.remove(0);
- undo.set(29, rg);
- current = undo.size()-1;
- } else {
- undo.add(rg);
- current = undo.size()-1;
- }
- }
- @SuppressWarnings("deprecation")
- public void undo() {
- if (current==-1 || undo.isEmpty()) {
- p.sendMessage(c(cfg.getNothingLeftToUndoMsg()));
- return;
- }
- HashMap<Location,String[]> rg = undo.get(current);
- for (Location loc:rg.keySet()) {
- String[] id = rg.get(loc);
- World w = loc.getWorld();
- Block block = w.getBlockAt(loc);
- block.setType(Material.getMaterial(id[0]));
- block.setData(Byte.parseByte(id[1]));
- }
- p.sendMessage(c(cfg.getUndoMsg()));
- current = current-1;
- }
- @Deprecated
- public void redo() {
- if (current<=redo.size()-1 || redo.isEmpty()) {
- p.sendMessage(ChatColor.RED+"Нечего возвращать.");
- return;
- }
- HashMap<Location,String[]> rg = redo.get(current+1);
- for (Location loc:rg.keySet()) {
- String[] id = rg.get(loc);
- World w = loc.getWorld();
- Block block = w.getBlockAt(loc);
- block.setType(Material.getMaterial(id[0]));
- block.setData(Byte.parseByte(id[1]));
- }
- p.sendMessage(ChatColor.LIGHT_PURPLE+"Успешно возвращено.");
- }
- public int getBufferSize() {
- return undo.size();
- }
- private String c(String s) {
- return ChatColor.translateAlternateColorCodes('&', s);
- }
- }
Add Comment
Please, Sign In to add comment