From daacbe2eb486866e2af39c4acef25583ec2ab104 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Fri, 31 Jan 2020 11:42:52 +0100 Subject: [PATCH] Added a lot of things!! --- .../SBDeveloper/V10Lift/API/Objects/Lift.java | 16 +- .../V10Lift/API/Objects/LiftBlock.java | 22 +-- .../V10Lift/API/Objects/LiftRope.java | 30 ++- .../V10Lift/API/Objects/V10Entity.java | 33 ++++ .../V10Lift/API/Runnables/DoorCloser.java | 28 +++ .../V10Lift/API/Runnables/MoveLift.java | 179 ++++++++++++++++++ .../SBDeveloper/V10Lift/API/V10LiftAPI.java | 107 ++++++++++- .../Managers/AntiCopyBlockManager.java | 65 +++++++ .../V10Lift/Managers/DataManager.java | 23 +++ 9 files changed, 472 insertions(+), 31 deletions(-) create mode 100644 src/main/java/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java create mode 100644 src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/DoorCloser.java create mode 100644 src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java create mode 100644 src/main/java/nl/SBDeveloper/V10Lift/Managers/AntiCopyBlockManager.java diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java index b7e2c81..50f8e9a 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java @@ -2,36 +2,38 @@ package nl.SBDeveloper.V10Lift.API.Objects; import lombok.Getter; import lombok.Setter; +import nl.SBDeveloper.V10Lift.API.Runnables.DoorCloser; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.UUID; +import java.util.*; public class Lift { @Getter @Setter private String worldName; @Getter @Setter private int y; @Getter private ArrayList owners; @Getter private ArrayList whitelist; - @Getter private ArrayList blocks; + @Getter private TreeSet blocks; @Getter private LinkedHashMap floors; @Getter private ArrayList signs; @Getter private ArrayList inputs; @Getter private ArrayList offlineInputs; @Getter private LinkedHashMap queue; @Getter private ArrayList ropes; + @Getter private ArrayList toMove; @Getter @Setter private int speed; @Getter @Setter private boolean realistic; @Getter @Setter private boolean offline; @Getter @Setter private boolean sound; @Getter @Setter private boolean defective; @Getter @Setter private String signText; + @Getter @Setter private int counter; + @Getter @Setter private Floor doorOpen; + @Getter @Setter private DoorCloser doorCloser; public Lift(ArrayList owners, int speed, boolean realistic) { this.owners = owners; this.speed = speed; this.realistic = realistic; - this.blocks = new ArrayList<>(); + this.blocks = new TreeSet<>(); this.signs = new ArrayList<>(); this.whitelist = new ArrayList<>(); this.floors = new LinkedHashMap<>(); @@ -39,9 +41,11 @@ public class Lift { this.offlineInputs = new ArrayList<>(); this.queue = new LinkedHashMap<>(); this.ropes = new ArrayList<>(); + this.toMove = new ArrayList<>(); this.offline = false; this.sound = true; this.defective = false; + this.counter = 0; } public Lift(UUID owner, int speed, boolean realistic) { diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java index f065f5c..99b8e80 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java @@ -3,29 +3,27 @@ package nl.SBDeveloper.V10Lift.API.Objects; import lombok.Getter; import lombok.Setter; import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; import javax.annotation.Nonnull; -import java.util.LinkedHashMap; +import java.util.Map; -@Getter @Setter public class LiftBlock implements Comparable { - private String world; - private int x; - private int y; - private int z; + @Getter @Setter private String world; + @Getter @Setter private int x; + @Getter @Setter private int y; + @Getter @Setter private int z; //Only used for cabine blocks, because those need caching! - private Material mat; - private String[] signLines; + @Getter @Setter private Material mat; + @Getter @Setter private String[] signLines; //Only used for inputs! - private String floor; - private boolean active = false; + @Getter @Setter private String floor; + @Getter @Setter private boolean active = false; //Only used for chests - private LinkedHashMap chestContent = new LinkedHashMap<>(); + public Map[] serializedItemStacks = null; /** * Add lift block with material diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java index 0ae0811..a8fdc99 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java @@ -1,14 +1,30 @@ package nl.SBDeveloper.V10Lift.API.Objects; -import lombok.AllArgsConstructor; +import javafx.scene.paint.Material; import lombok.Getter; import lombok.Setter; -@Getter @Setter @AllArgsConstructor +@Getter @Setter public class LiftRope { - private String world; - private int x; - private int z; - private int minY; - private int maxY; + private final Material type; + private final String startWorld; + private final String endWorld; + private final int x; + private final int minY; + private final int maxY; + private final int z; + private String currentWorld; + private int currently; + + public LiftRope(Material type, String startWorld, String endWorld, int x, int minY, int maxY, int z) { + this.type = type; + this.startWorld = startWorld; + this.endWorld = endWorld; + this.x = x; + this.minY = minY; + this.maxY = maxY; + this.z = z; + this.currently = minY; + this.currentWorld = endWorld; + } } diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java new file mode 100644 index 0000000..02be88f --- /dev/null +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java @@ -0,0 +1,33 @@ +package nl.SBDeveloper.V10Lift.API.Objects; + +import lombok.Getter; +import lombok.Setter; +import org.bukkit.Location; +import org.bukkit.entity.Entity; + +@Getter +public class V10Entity { + private final Entity e; + private final Location loc; + private final int y; + @Setter private short step; + + public V10Entity(Entity e, Location loc, int y) { + this.e = e; + this.loc = loc; + this.y = y; + this.step = 0; + } + + public void moveUp() { + if (e == null || e.isDead()) return; + loc.setY(y + step); + e.teleport(loc); + } + + public void moveDown() { + if (e == null || e.isDead()) return; + loc.setY(y - step); + e.teleport(loc); + } +} diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/DoorCloser.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/DoorCloser.java new file mode 100644 index 0000000..682bfe8 --- /dev/null +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/DoorCloser.java @@ -0,0 +1,28 @@ +package nl.SBDeveloper.V10Lift.API.Runnables; + +import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.V10LiftPlugin; +import org.bukkit.Bukkit; + +public class DoorCloser implements Runnable { + private final String liftName; + private int pid; + + public DoorCloser(String liftName) { + this.liftName = liftName; + } + + @Override + public void run() { + if (V10LiftPlugin.getAPI().closeDoor(liftName)) stop(); + } + + public void setPid(int pid) { + this.pid = pid; + } + + public void stop() { + Bukkit.getScheduler().cancelTask(pid); + if (DataManager.containsLift(liftName)) DataManager.getLift(liftName).setDoorCloser(null); + } +} diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java new file mode 100644 index 0000000..90af85b --- /dev/null +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java @@ -0,0 +1,179 @@ +package nl.SBDeveloper.V10Lift.API.Runnables; + +import nl.SBDeveloper.V10Lift.API.Objects.Floor; +import nl.SBDeveloper.V10Lift.API.Objects.Lift; +import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock; +import nl.SBDeveloper.V10Lift.API.Objects.LiftRope; +import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.V10LiftPlugin; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.block.Chest; +import org.bukkit.entity.Item; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import java.util.*; + +public class MoveLift implements Runnable { + + private final String liftName; + private final long speed; + private final int ft; + + public MoveLift(String liftName, long speed) { + this.liftName = liftName; + this.speed = speed; + + if (speed > 32L) { + ft = 1; + } else if (speed > 16L) { + ft = 2; + } else if (speed > 8L) { + ft = 4; + } else if (speed > 4L) { + ft = 8; + } else if (speed > 2L) { + ft = 16; + } else if (speed > 1L) { + ft = 32; + } else { + ft = 64; + } + } + + @Override + public void run() { + Lift lift = DataManager.getLift(liftName); + if (lift == null) { + stopMe(); + return; + } + + if (lift.getQueue().isEmpty() || lift.isOffline()) { + stopMe(); + return; + } + + if (DataManager.containsEditLift(liftName)) return; + + if (lift.getCounter() > 0) { + lift.setCounter(lift.getCounter() - 1); + return; + } + + LiftBlock lb = lift.getBlocks().first(); + World w = Bukkit.getWorld(lb.getWorld()); + if (w == null) { + lift.setCounter(ft); + return; + } + + Location loc = new Location(w, lb.getX(), lb.getY(), lb.getZ()); + if (!loc.getChunk().isLoaded()) { + lift.setCounter(ft); + return; + } + + //TODO Add defaults to config (chanceOfDefect) + double changeOfDefect = 0.0D; + if (changeOfDefect > 0.0D) { + int y = new Random().nextInt(100); + double chance; + if (y < 100) { + long co = new Random().nextLong(); + if (co < 0) co = -co; + chance = Double.parseDouble(y + "." + co); + } else { + chance = y; + } + + if (chance < changeOfDefect) { + V10LiftPlugin.getAPI().setDefective(liftName, true); + return; + } + } + + ArrayList tb = new ArrayList<>(); + + Iterator> quiter = lift.getQueue().entrySet().iterator(); + Map.Entry floor = quiter.next(); + Floor to = floor.getValue(); + String fl = floor.getKey(); + boolean up = false; + boolean down = false; + + if (lift.getY() < to.getY()) { + up = true; + } else if (lift.getY() > to.getY()) { + down = true; + } + + String tmpw = lift.getWorldName(); + if (up) { + if (!V10LiftPlugin.getAPI().closeDoor(liftName)) return; + + //MOVE ROPES + for (LiftRope rope : lift.getRopes()) { + if (rope.getCurrentWorld().equals(rope.getStartWorld()) && rope.getCurrently() > rope.getMaxY()) { + Bukkit.getLogger().info("[V10Lift] Lift " + liftName + " reaches the upper rope end but won't stop!!"); + V10LiftPlugin.getAPI().setDefective(liftName, true); + lift.getToMove().clear(); + quiter.remove(); + return; + } + Block block = Objects.requireNonNull(Bukkit.getWorld(rope.getCurrentWorld()), "World is null at MoveLift").getBlockAt(rope.getX(), rope.getCurrently(), rope.getZ()); + block.setType(Material.AIR); + rope.setCurrently(rope.getCurrently() + 1); + } + + Iterator iter = lift.getBlocks().iterator(); + while (iter.hasNext()) { + LiftBlock lblock = iter.next(); + if (V10LiftPlugin.getAPI().getACBM().isAntiCopy(lblock.getMat())) { + tb.add(lblock); + iter.remove(); + Block block = Objects.requireNonNull(Bukkit.getWorld(lblock.getWorld()), "World is null at MoveLift").getBlockAt(lblock.getX(), lblock.getY(), lblock.getZ()); + block.setType(Material.AIR); + lblock.setY(lblock.getY() + 1); + } + } + + boolean wc = false; + for (LiftBlock lib : lift.getBlocks().descendingSet()) { + Block block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()); + if (lib.getMat() == Material.CHEST || lib.getMat() == Material.TRAPPED_CHEST && lib.serializedItemStacks == null) { + Chest c = (Chest) block.getState(); + Inventory inv = c.getInventory(); + ItemStack[] isa = inv.getContents(); + boolean by = false; + lib.serializedItemStacks = new Map[isa.length]; + for (int i = 0; i < isa.length; i++) { + ItemStack is = isa[i]; + if (is != null) { + by = true; + lib.serializedItemStacks[i] = is.serialize(); + } + } + if (by) { + inv.clear(); + c.update(); + } else { + lib.serializedItemStacks = null; + } + } + + block.setType(Material.AIR); + lib.setY(lib.getY() + 1); + Block b = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()); + b.setType(lib.getMat()); + lb = lift.getBlocks().first(); + } + } + } + + private void stopMe() { + Bukkit.getServer().getScheduler().cancelTask(DataManager.getMovingTask(liftName)); + DataManager.removeMovingTask(liftName); + } +} diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java index 3bdb470..f59f608 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java @@ -4,16 +4,17 @@ import nl.SBDeveloper.V10Lift.API.Objects.Floor; import nl.SBDeveloper.V10Lift.API.Objects.Lift; import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock; import nl.SBDeveloper.V10Lift.API.Objects.LiftSign; +import nl.SBDeveloper.V10Lift.API.Runnables.DoorCloser; +import nl.SBDeveloper.V10Lift.Managers.AntiCopyBlockManager; import nl.SBDeveloper.V10Lift.Managers.DataManager; import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager; import nl.SBDeveloper.V10Lift.Utils.LocationSerializer; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.World; +import nl.SBDeveloper.V10Lift.V10LiftPlugin; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.Sign; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import javax.annotation.Nonnull; @@ -22,15 +23,21 @@ import java.util.*; public class V10LiftAPI { /* Load managers... */ private static ForbiddenBlockManager fbm; + private static AntiCopyBlockManager acbm; public V10LiftAPI() { fbm = new ForbiddenBlockManager(); + acbm = new AntiCopyBlockManager(); } - public static ForbiddenBlockManager getFBM() { + public ForbiddenBlockManager getFBM() { return fbm; } + public AntiCopyBlockManager getACBM() { + return acbm; + } + /* Private API methods */ private void sortFloors(@Nonnull Lift lift) { ArrayList> as = new ArrayList<>(lift.getFloors().entrySet()); @@ -180,7 +187,7 @@ public class V10LiftAPI { public void sortLiftBlocks(String liftName) { if (liftName != null && DataManager.containsLift(liftName)) { Lift lift = DataManager.getLift(liftName); - if (lift.getWorldName() == null) lift.setWorldName(lift.getBlocks().get(0).getWorld()); + if (lift.getWorldName() == null) lift.setWorldName(lift.getBlocks().first().getWorld()); World world = Bukkit.getWorld(lift.getWorldName()); if (world == null) return; lift.setY(world.getMaxHeight()); @@ -193,6 +200,94 @@ public class V10LiftAPI { } } + public boolean openDoor(String liftName) { + if (liftName == null || !DataManager.containsLift(liftName)) return false; + + Lift lift = DataManager.getLift(liftName); + + if (lift.getQueue() != null) return false; + + Floor f = null; + for (Floor fl : lift.getFloors().values()) { + if (fl.getY() == lift.getY() && fl.getWorld().equals(lift.getWorldName())) { + f = fl; + break; + } + } + + if (f == null) return false; + + if (lift.getDoorOpen() != null && !closeDoor(liftName)) return false; + + for (LiftBlock lb : f.getDoorBlocks()) { + Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at openDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ()); + block.setType(Material.AIR); + } + + lift.setDoorOpen(f); + + if (lift.isRealistic()) { + lift.setDoorCloser(new DoorCloser(liftName)); + //TODO Add defaults (doorclosetime) to config + long doorCloseTime = 5 * 20; + int pid = Bukkit.getScheduler().scheduleSyncRepeatingTask(V10LiftPlugin.getInstance(), lift.getDoorCloser(), doorCloseTime, doorCloseTime); + lift.getDoorCloser().setPid(pid); + } + return true; + } + + /** + * Close a lift door + * + * @param liftName The name of the lift + * @return true if door was closed, false if else. + */ + public boolean closeDoor(String liftName) { + if (liftName == null || !DataManager.containsLift(liftName)) return false; + + Lift lift = DataManager.getLift(liftName); + + boolean blocked = false; + if (lift.getDoorOpen() == null) { + return true; + } + + if (lift.isRealistic()) { + for (LiftBlock lb : lift.getDoorOpen().getDoorBlocks()) { + Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at closeDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ()); + for (Entity ent : block.getChunk().getEntities()) { + Location loc = ent.getLocation(); + if (loc.getBlockX() == lb.getX() && loc.getBlockY() == lb.getY() && loc.getBlockZ() == lb.getZ()) { + blocked = true; + break; + } + } + if (blocked) break; + } + } + + if (!blocked) { + for (LiftBlock lb : lift.getDoorOpen().getDoorBlocks()) { + Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at closeDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ()); + block.setType(lb.getMat(), true); + } + lift.setDoorOpen(null); + if (lift.getDoorCloser() != null) lift.getDoorCloser().stop(); + } + + return !blocked; + } + + /** + * To check if a lift has an open door. + * + * @param liftName The name of the lift + * @return true if open, false if else + */ + public boolean hasDoorOpen(String liftName) { + return (liftName != null && DataManager.containsLift(liftName)) && DataManager.getLift(liftName).getDoorOpen() != null; + } + /** * Adds a new floor to a lift * diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Managers/AntiCopyBlockManager.java b/src/main/java/nl/SBDeveloper/V10Lift/Managers/AntiCopyBlockManager.java new file mode 100644 index 0000000..e362f02 --- /dev/null +++ b/src/main/java/nl/SBDeveloper/V10Lift/Managers/AntiCopyBlockManager.java @@ -0,0 +1,65 @@ +package nl.SBDeveloper.V10Lift.Managers; + +import nl.SBDeveloper.V10Lift.Utils.XMaterial; +import org.bukkit.Material; + +import java.util.ArrayList; + +public class AntiCopyBlockManager { + private ArrayList antiCopy = new ArrayList<>(); + + public AntiCopyBlockManager() { + //TODO Add more anti copy materials + antiCopy.add(XMaterial.REDSTONE_TORCH); + antiCopy.add(XMaterial.REDSTONE_WALL_TORCH); + antiCopy.add(XMaterial.REPEATER); + antiCopy.add(XMaterial.COMPARATOR); + antiCopy.add(XMaterial.REDSTONE_WIRE); + antiCopy.add(XMaterial.ACACIA_BUTTON); + antiCopy.add(XMaterial.BIRCH_BUTTON); + antiCopy.add(XMaterial.DARK_OAK_BUTTON); + antiCopy.add(XMaterial.JUNGLE_BUTTON); + antiCopy.add(XMaterial.OAK_BUTTON); + antiCopy.add(XMaterial.SPRUCE_BUTTON); + antiCopy.add(XMaterial.STONE_BUTTON); + antiCopy.add(XMaterial.TORCH); + antiCopy.add(XMaterial.ACACIA_TRAPDOOR); + antiCopy.add(XMaterial.BIRCH_TRAPDOOR); + antiCopy.add(XMaterial.DARK_OAK_TRAPDOOR); + antiCopy.add(XMaterial.JUNGLE_TRAPDOOR); + antiCopy.add(XMaterial.OAK_TRAPDOOR); + antiCopy.add(XMaterial.SPRUCE_TRAPDOOR); + antiCopy.add(XMaterial.IRON_TRAPDOOR); + antiCopy.add(XMaterial.ACACIA_PRESSURE_PLATE); + antiCopy.add(XMaterial.BIRCH_PRESSURE_PLATE); + antiCopy.add(XMaterial.DARK_OAK_PRESSURE_PLATE); + antiCopy.add(XMaterial.JUNGLE_PRESSURE_PLATE); + antiCopy.add(XMaterial.OAK_PRESSURE_PLATE); + antiCopy.add(XMaterial.SPRUCE_PRESSURE_PLATE); + antiCopy.add(XMaterial.STONE_PRESSURE_PLATE); + antiCopy.add(XMaterial.HEAVY_WEIGHTED_PRESSURE_PLATE); + antiCopy.add(XMaterial.LIGHT_WEIGHTED_PRESSURE_PLATE); + antiCopy.add(XMaterial.ACACIA_SIGN); + antiCopy.add(XMaterial.BIRCH_SIGN); + antiCopy.add(XMaterial.DARK_OAK_SIGN); + antiCopy.add(XMaterial.JUNGLE_SIGN); + antiCopy.add(XMaterial.OAK_SIGN); + antiCopy.add(XMaterial.SPRUCE_SIGN); + antiCopy.add(XMaterial.ACACIA_WALL_SIGN); + antiCopy.add(XMaterial.BIRCH_WALL_SIGN); + antiCopy.add(XMaterial.DARK_OAK_WALL_SIGN); + antiCopy.add(XMaterial.JUNGLE_WALL_SIGN); + antiCopy.add(XMaterial.OAK_WALL_SIGN); + antiCopy.add(XMaterial.SPRUCE_WALL_SIGN); + antiCopy.add(XMaterial.RAIL); + antiCopy.add(XMaterial.POWERED_RAIL); + antiCopy.add(XMaterial.DETECTOR_RAIL); + antiCopy.add(XMaterial.ACTIVATOR_RAIL); + antiCopy.add(XMaterial.LADDER); + } + + public boolean isAntiCopy(Material mat) { + XMaterial xmat = XMaterial.matchXMaterial(mat); + return antiCopy.contains(xmat); + } +} diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java b/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java index 4a14da1..98b0f3b 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/Managers/DataManager.java @@ -4,6 +4,7 @@ import nl.SBDeveloper.V10Lift.API.Objects.Lift; import org.bukkit.block.Block; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.UUID; @@ -21,6 +22,7 @@ public class DataManager { private static ArrayList ropeRemoves = new ArrayList<>(); private static ArrayList doorEdits = new ArrayList<>(); private static ArrayList whoisReq = new ArrayList<>(); + private static HashMap movingTasks = new HashMap<>(); /* HashMap methods */ @@ -97,6 +99,10 @@ public class DataManager { return editors.containsKey(player); } + public static boolean containsEditLift(String liftName) { + return editors.containsValue(liftName); + } + public static void addEditPlayer(UUID player, String liftName) { editors.put(player, liftName); } @@ -109,6 +115,23 @@ public class DataManager { return editors.get(player); } + // // + public static void addMovingTask(String liftName, int taskid) { + movingTasks.put(liftName, taskid); + } + + public static void removeMovingTask(String liftName) { + movingTasks.remove(liftName); + } + + public static boolean containsMovingTask(String liftName) { + return movingTasks.containsKey(liftName); + } + + public static int getMovingTask(String liftName) { + return movingTasks.get(liftName); + } + /* ArrayList methods */ // //