From f24b35a2df502974baedfc4fae9e29c6cf3c20e7 Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Sun, 2 Feb 2020 12:57:28 +0100 Subject: [PATCH] Testing things with blockstate --- .../V10Lift/API/Objects/Floor.java | 9 ++- .../SBDeveloper/V10Lift/API/Objects/Lift.java | 55 ++++++------- .../V10Lift/API/Objects/LiftBlock.java | 66 ++++++++++------ .../V10Lift/API/Objects/LiftSign.java | 2 +- .../V10Lift/API/Runnables/MoveLift.java | 30 ++++++-- .../SBDeveloper/V10Lift/API/V10LiftAPI.java | 77 ++++++++++++++++--- .../Listeners/PlayerInteractListener.java | 23 +++++- 7 files changed, 185 insertions(+), 77 deletions(-) diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java index ae0238f..d2e3541 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Floor.java @@ -4,14 +4,15 @@ import lombok.Getter; import lombok.Setter; import java.util.ArrayList; +import java.util.HashSet; import java.util.UUID; @Getter @Setter public class Floor { - private String world; - private int y; - private ArrayList doorBlocks; - private ArrayList whitelist; + private final String world; + private final int y; + private final ArrayList doorBlocks = new ArrayList<>(); + private final HashSet whitelist = new HashSet<>(); public Floor(int y, String world) { this.y = y; 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 b6413fd..48680ff 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/Lift.java @@ -9,46 +9,37 @@ 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 TreeSet blocks; - @Getter private LinkedHashMap floors; - @Getter private ArrayList signs; - @Getter private ArrayList inputs; - @Getter private ArrayList offlineInputs; - @Getter @Setter private LinkedHashMap queue; - @Getter private ArrayList ropes; - @Getter private ArrayList toMove; + @Getter private final HashSet owners; + @Getter @Setter private ArrayList whitelist; + @Getter private final TreeSet blocks = new TreeSet<>(); + @Getter private final LinkedHashMap floors = new LinkedHashMap<>(); + @Getter private final HashSet signs = new HashSet<>(); + @Getter private final HashSet inputs = new HashSet<>(); + @Getter private HashSet offlineInputs = new HashSet<>(); + @Getter @Setter private LinkedHashMap queue = null; + @Getter private final HashSet ropes = new HashSet<>(); + @Getter private final ArrayList toMove = new ArrayList<>(); @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; + @Getter @Setter private boolean offline = false; + @Getter @Setter private boolean sound = true; + @Getter @Setter private boolean defective = false; + @Getter @Setter private String signText = null; + @Getter @Setter private int counter = 0; + @Getter @Setter private Floor doorOpen = null; + @Getter @Setter private DoorCloser doorCloser = null; - public Lift(ArrayList owners, int speed, boolean realistic) { + public Lift(HashSet owners, int speed, boolean realistic) { this.owners = owners; this.speed = speed; this.realistic = realistic; - this.blocks = new TreeSet<>(); - this.signs = new ArrayList<>(); - this.whitelist = new ArrayList<>(); - this.floors = new LinkedHashMap<>(); - this.inputs = new ArrayList<>(); - 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) { - new Lift(new ArrayList<>(Collections.singletonList(owner)), speed, realistic); + HashSet hs = new HashSet<>(); + hs.add(owner); + this.owners = hs; + this.speed = speed; + this.realistic = 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 e1e8cd6..3f053c6 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java @@ -10,53 +10,75 @@ import java.util.Map; public class LiftBlock implements Comparable { @Getter @Setter private String world; - @Getter @Setter private int x; + @Getter private final int x; @Getter @Setter private int y; - @Getter @Setter private int z; + @Getter private final int z; //Only used for cabine blocks, because those need caching! - @Getter @Setter private Material mat; - @Getter @Setter private String[] signLines; + @Getter private final Material mat; + @Getter private final byte data; + @Getter private final String[] signLines; //Only used for inputs! - @Getter @Setter private String floor; + @Getter private final String floor; @Getter @Setter private boolean active = false; //Only used for chests public Map[] serializedItemStacks = null; - /** - * Add lift block with material - * - * @param world Worldname - * @param x x-pos - * @param y y-pos - * @param z z-pos - * @param mat the material - */ - public LiftBlock(String world, int x, int y, int z, Material mat) { - this.world = world; - this.x = x; - this.y = y; - this.z = z; - this.mat = mat; - } - public LiftBlock(String world, int x, int y, int z, String floor) { this.world = world; this.x = x; this.y = y; this.z = z; + this.mat = null; + this.data = 0; + this.signLines = null; this.floor = floor; } + public LiftBlock(String world, int x, int y, int z, Material mat) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + this.mat = mat; + this.data = 0; + this.signLines = null; + this.floor = null; + } + + public LiftBlock(String world, int x, int y, int z, Material mat, byte data) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + this.mat = mat; + this.data = data; + this.signLines = null; + this.floor = null; + } + public LiftBlock(String world, int x, int y, int z, Material mat, String[] signLines) { this.world = world; this.x = x; this.y = y; this.z = z; this.mat = mat; + this.data = 0; this.signLines = signLines; + this.floor = null; + } + + public LiftBlock(String world, int x, int y, int z, Material mat, byte data, String[] signLines) { + this.world = world; + this.x = x; + this.y = y; + this.z = z; + this.mat = mat; + this.data = data; + this.signLines = signLines; + this.floor = null; } @Override diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java index 76c776b..9807eb6 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java @@ -9,7 +9,7 @@ public class LiftSign { private int x; private int z; private int y; - private String oldText; + private String oldText = null; private final byte type; private byte state; diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java b/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java index a2f3579..f92790e 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java @@ -3,6 +3,7 @@ package nl.SBDeveloper.V10Lift.API.Runnables; import nl.SBDeveloper.V10Lift.API.Objects.*; import nl.SBDeveloper.V10Lift.Managers.DataManager; import nl.SBDeveloper.V10Lift.Utils.LocationSerializer; +import nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.Utils.XSound; import nl.SBDeveloper.V10Lift.V10LiftPlugin; import org.bukkit.*; @@ -124,7 +125,6 @@ public class MoveLift implements Runnable { down = true; } - String tmpw = lift.getWorldName(); if (up) { if (!V10LiftPlugin.getAPI().closeDoor(liftName)) return; @@ -183,7 +183,12 @@ public class MoveLift implements Runnable { block.setType(Material.AIR); lib.setY(lib.getY() + 1); block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()); - block.setType(lib.getMat()); + BlockState state = block.getState(); + state.setType(lb.getMat()); + if (!XMaterial.isNewVersion()) { + state.setRawData(lb.getData()); + } + state.update(true); lb = lift.getBlocks().first(); for (Entity ent : Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()).getChunk().getEntities()) { v10ent = new V10Entity(ent, null, 0); @@ -218,7 +223,12 @@ public class MoveLift implements Runnable { } for (LiftBlock lib : tb) { block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()); - block.setType(lib.getMat(), true); + BlockState state = block.getState(); + state.setType(lb.getMat()); + if (!XMaterial.isNewVersion()) { + state.setRawData(lb.getData()); + } + state.update(true); lift.getBlocks().add(lib); if (lib.getSignLines() != null) { bs = block.getState(); @@ -298,7 +308,12 @@ public class MoveLift implements Runnable { lib.setY(lib.getY() - 1); y = lib.getY(); block = world.getBlockAt(lib.getX(), lib.getY(), lib.getZ()); - block.setType(lib.getMat(), true); + BlockState state = block.getState(); + state.setType(lb.getMat()); + if (!XMaterial.isNewVersion()) { + state.setRawData(lb.getData()); + } + state.update(true); } veiter = lift.getToMove().iterator(); while (veiter.hasNext()) { @@ -313,7 +328,12 @@ public class MoveLift implements Runnable { } for (LiftBlock lib : tb) { block = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift").getBlockAt(lib.getX(), lib.getY(), lib.getZ()); - block.setType(lib.getMat(), true); + BlockState state = block.getState(); + state.setType(lb.getMat()); + if (!XMaterial.isNewVersion()) { + state.setRawData(lb.getData()); + } + state.update(true); lift.getBlocks().add(lib); if (lib.getSignLines() != null) { bs = block.getState(); diff --git a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java index 4511b26..a5cd983 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/API/V10LiftAPI.java @@ -7,6 +7,7 @@ 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 nl.SBDeveloper.V10Lift.Utils.XMaterial; import nl.SBDeveloper.V10Lift.V10LiftPlugin; import org.bukkit.*; import org.bukkit.block.Block; @@ -48,6 +49,7 @@ public class V10LiftAPI { /* Private API methods */ private void sortFloors(@Nonnull Lift lift) { + Bukkit.getLogger().info("[V10Lift] Sorting floors for lift..."); ArrayList> as = new ArrayList<>(lift.getFloors().entrySet()); as.sort(Comparator.comparingInt(o -> o.getValue().getY())); Iterator> iter = as.iterator(); @@ -60,6 +62,7 @@ public class V10LiftAPI { } private void startLift(String liftName) { + Bukkit.getLogger().info("[V10Lift] Starting lift " + liftName); if (!DataManager.containsMovingTask(liftName)) { Lift lift = DataManager.getLift(liftName); DataManager.addMovingTask(liftName, Bukkit.getScheduler().scheduleSyncRepeatingTask(V10LiftPlugin.getInstance(), new MoveLift(liftName, lift.getSpeed()), lift.getSpeed(), lift.getSpeed())); @@ -76,6 +79,7 @@ public class V10LiftAPI { * @return true if created, false if null or already exists */ public boolean createLift(Player p, String liftName) { + Bukkit.getLogger().info("[V10Lift] Creating lift " + liftName); if (p == null || liftName == null || DataManager.containsLift(liftName)) return false; //TODO Add defaults to config @@ -90,6 +94,7 @@ public class V10LiftAPI { * @return true if removed, false if null or doesn't exists */ public boolean removeLift(String liftName) { + Bukkit.getLogger().info("[V10Lift] Removing lift " + liftName); if (liftName == null || !DataManager.containsLift(liftName)) return false; //TODO Remove lift from all data maps @@ -107,6 +112,7 @@ public class V10LiftAPI { * @param newName The new name of the lift */ public void renameLift(String liftName, String newName) { + Bukkit.getLogger().info("[V10Lift] Renaming lift " + liftName); if (liftName == null || newName == null || !DataManager.containsLift(liftName)) return; Lift lift = DataManager.getLift(liftName); @@ -145,13 +151,24 @@ public class V10LiftAPI { * @return 0 if added, -1 if null or doesn't exists, -2 if forbidden, -3 if already added */ public int addBlockToLift(Set blocks, @Nonnull Block block) { + Bukkit.getLogger().info("[V10Lift] Adding Block to lift..."); Material type = block.getType(); LiftBlock lb; if (type.toString().contains("SIGN")) { //SIGN - lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines()); + if (XMaterial.isNewVersion()) { + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines()); + } else { + Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines()); + } } else { - lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type); + if (XMaterial.isNewVersion()) { + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type); + } else { + Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData()); + } } return addBlockToLift(blocks, lb); } @@ -164,7 +181,8 @@ public class V10LiftAPI { * @param block The LiftBlock * @return 0 if added, -1 if null or doesn't exists, -2 if forbidden, -3 if already added */ - public int addBlockToLift(Set blocks, @Nonnull LiftBlock block) { + public int addBlockToLift(@Nonnull Set blocks, @Nonnull LiftBlock block) { + Bukkit.getLogger().info("[V10Lift] Adding Block to lift 2..."); if (getFBM().isForbidden(block.getMat())) return -2; if (blocks.contains(block)) return -3; blocks.add(block); @@ -186,9 +204,19 @@ public class V10LiftAPI { LiftBlock lb; if (type.toString().contains("SIGN")) { //SIGN - lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines()); + if (XMaterial.isNewVersion()) { + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines()); + } else { + Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines()); + } } else { - lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type); + if (XMaterial.isNewVersion()) { + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type); + } else { + Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData()); + } } if (!lift.getBlocks().contains(lb)) return -2; lift.getBlocks().remove(lb); @@ -204,6 +232,7 @@ public class V10LiftAPI { * @return 0 if added, 1 if removed, -1 if null or doesn't exists, -2 if not added */ public int switchBlockAtLift(String liftName, Block block) { + Bukkit.getLogger().info("[V10Lift] Switching block at lift..."); if (liftName == null || block == null || !DataManager.containsLift(liftName)) return -1; return switchBlockAtLift(DataManager.getLift(liftName).getBlocks(), block); } @@ -217,15 +246,26 @@ public class V10LiftAPI { * @return 0 if added, 1 if removed, -1 if null or doesn't exists, -2 if not added */ public int switchBlockAtLift(TreeSet blocks, Block block) { + Bukkit.getLogger().info("[V10Lift] Switching block at lift 2..."); if (blocks == null || block == null) return -1; Material type = block.getType(); if (getFBM().isForbidden(type)) return -2; LiftBlock lb; if (type.toString().contains("SIGN")) { //SIGN - lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines()); + if (XMaterial.isNewVersion()) { + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, ((Sign) block.getState()).getLines()); + } else { + Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData(), ((Sign) block.getState()).getLines()); + } } else { - lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type); + if (XMaterial.isNewVersion()) { + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type); + } else { + Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), type, block.getState().getRawData()); + } } if (blocks.contains(lb)) { blocks.remove(lb); @@ -242,6 +282,7 @@ public class V10LiftAPI { * @param liftName The name of the lift */ public void sortLiftBlocks(String liftName) { + Bukkit.getLogger().info("[V10Lift] Sorting blocks at lift..."); if (liftName != null && DataManager.containsLift(liftName)) { Lift lift = DataManager.getLift(liftName); if (lift.getWorldName() == null) lift.setWorldName(lift.getBlocks().first().getWorld()); @@ -308,6 +349,7 @@ public class V10LiftAPI { * @return true/false */ public boolean openDoor(Lift lift, String liftName, Floor f) { + Bukkit.getLogger().info("[V10Lift] Opening door..."); if (lift == null || liftName == null || f == null) return false; if (lift.getDoorOpen() != null && !closeDoor(liftName)) return false; @@ -335,6 +377,7 @@ public class V10LiftAPI { * @return true if door was closed, false if else. */ public boolean closeDoor(String liftName) { + Bukkit.getLogger().info("[V10Lift] Closing door..."); if (liftName == null || !DataManager.containsLift(liftName)) return false; Lift lift = DataManager.getLift(liftName); @@ -361,7 +404,12 @@ public class V10LiftAPI { 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); + BlockState state = block.getState(); + state.setType(lb.getMat()); + if (!XMaterial.isNewVersion()) { + state.setRawData(lb.getData()); + } + state.update(true); } lift.setDoorOpen(null); if (lift.getDoorCloser() != null) lift.getDoorCloser().stop(); @@ -377,6 +425,7 @@ public class V10LiftAPI { * @return true if open, false if else */ public boolean hasDoorOpen(String liftName) { + Bukkit.getLogger().info("[V10Lift] Opening door..."); return (liftName != null && DataManager.containsLift(liftName)) && DataManager.getLift(liftName).getDoorOpen() != null; } @@ -389,6 +438,7 @@ public class V10LiftAPI { * @return 0 if added, -1 if null or doesn't exists, -2 if height is to high, -3 if floor already exists */ public int addFloor(String liftName, String floorName, Floor floor) { + Bukkit.getLogger().info("[V10Lift] Adding door to " + floorName); if (liftName == null || floorName == null || floor == null || !DataManager.containsLift(liftName) || floor.getWorld() == null) return -1; if (floor.getY() > Objects.requireNonNull(Bukkit.getServer().getWorld(floor.getWorld()), "World is null at addNewFloor!").getMaxHeight()) return -2; if (floorName.length() > 13) floorName = floorName.substring(0, 13).trim(); @@ -408,6 +458,7 @@ public class V10LiftAPI { * @return true if removed, false if null or doesn't exists */ public boolean removeFloor(String liftName, String floorName) { + Bukkit.getLogger().info("[V10Lift] Removing floor at " + liftName); if (liftName == null || floorName == null || !DataManager.containsLift(liftName)) return false; Lift lift = DataManager.getLift(liftName); if (!lift.getFloors().containsKey(floorName)) return false; @@ -426,6 +477,7 @@ public class V10LiftAPI { * @return 0 if renamed, -1 if null or doesn't exists, -2 if floor doesn't exists, -3 if floor already exists */ public int renameFloor(String liftName, String oldName, String newName) { + Bukkit.getLogger().info("[V10Lift] Renaming floor at " + liftName); if (liftName == null || oldName == null || newName == null || !DataManager.containsLift(liftName)) return -1; Lift lift = DataManager.getLift(liftName); if (!lift.getFloors().containsKey(oldName)) return -2; @@ -469,6 +521,7 @@ public class V10LiftAPI { * @return 0 if set, -1 if null or doesn't exists, -2 if same state, -3 if no signs, -4 if wrong sign */ public int setDefective(String liftName, boolean state) { + Bukkit.getLogger().info("[V10Lift] Set defective"); if (liftName == null || !DataManager.containsLift(liftName)) return -1; Lift lift = DataManager.getLift(liftName); boolean oldState = lift.isDefective(); @@ -556,8 +609,8 @@ public class V10LiftAPI { * @param floorName The name of the floor * @return list with UUIDs of the players */ - public ArrayList getWhitelist(String liftName, String floorName) { - ArrayList ret = new ArrayList<>(); + public HashSet getWhitelist(String liftName, String floorName) { + HashSet ret = new HashSet<>(); if (liftName != null && floorName != null && DataManager.containsLift(liftName)) { Lift lift = DataManager.getLift(liftName); if (lift.getFloors().containsKey(floorName)) { @@ -757,6 +810,7 @@ public class V10LiftAPI { * @return 0 if added, -1 if null or doesn't exists, -2 if not same mat, -3 if already a rope, -4 if forbidden material */ public int addRope(String lift, World world, int x, int minY, int maxY, int z) { + Bukkit.getLogger().info("[V10Lift] Adding rope to " + lift); if (lift == null || !DataManager.containsLift(lift) || world == null) return -1; boolean change = minY > maxY; @@ -783,6 +837,7 @@ public class V10LiftAPI { * @return true/false */ public boolean removeRope(String lift, Block block) { + Bukkit.getLogger().info("[V10Lift] Removing rope from " + lift); if (lift == null || block == null || !DataManager.containsLift(lift) || !containsRope(lift, block)) return false; String world = block.getWorld().getName(); @@ -845,6 +900,7 @@ public class V10LiftAPI { * @return true/false */ public boolean addToQueue(String lift, int y, @Nonnull World world, String floorName) { + Bukkit.getLogger().info("[V10Lift] Adding to queue: " + lift); return addToQueue(lift, new Floor(y, world.getName()), floorName); } @@ -858,6 +914,7 @@ public class V10LiftAPI { * @return true/false */ public boolean addToQueue(String lift, Floor floor, String floorName) { + Bukkit.getLogger().info("[V10Lift] Adding to queue: " + lift); if (lift == null || floor == null || !DataManager.containsLift(lift)) return false; Lift l = DataManager.getLift(lift); diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java b/src/main/java/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java index d73ad96..28f3700 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java @@ -22,7 +22,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; -import javax.xml.crypto.Data; import java.util.Iterator; import java.util.Map; @@ -34,9 +33,12 @@ public class PlayerInteractListener implements Listener { Block block = e.getClickedBlock(); if (block == null) return; Material button = block.getType(); + + Bukkit.getLogger().severe("Button pressed! " + action + " || " + e.getHand() + " || " + button); + if (action == Action.RIGHT_CLICK_BLOCK && e.getHand() != EquipmentSlot.OFF_HAND - && (button.toString().contains("BUTTON") || button == XMaterial.LEVER.parseMaterial())) { + && (button.toString().contains("_BUTTON") || button == XMaterial.LEVER.parseMaterial())) { String world = block.getWorld().getName(); int x = block.getX(); int y = block.getY(); @@ -50,6 +52,15 @@ public class PlayerInteractListener implements Listener { return; } } + + if (lift.isOffline()) return; + + for (LiftBlock lb : lift.getInputs()) { + if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) { + V10LiftPlugin.getAPI().addToQueue(entry.getKey(), lift.getFloors().get(lb.getFloor()), lb.getFloor()); + return; + } + } } } } @@ -208,7 +219,13 @@ public class PlayerInteractListener implements Listener { p.sendMessage(ChatColor.RED + "The material " + e.getClickedBlock().getType().toString() + " is currently not supported!"); return; } - LiftBlock lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), block.getType()); + LiftBlock lb; + if (XMaterial.isNewVersion()) { + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), block.getType()); + } else { + Bukkit.getLogger().info("Using deprecated method! " + block.getState().getRawData()); + lb = new LiftBlock(block.getWorld().getName(), block.getX(), block.getY(), block.getZ(), block.getType(), block.getState().getRawData()); + } Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId())); Floor floor = lift.getFloors().get(DataManager.getDoorEditPlayer(p.getUniqueId())); if (floor.getDoorBlocks().contains(lb)) {