diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Floor.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Floor.java index dbef7e6..ce073a1 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Floor.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Floor.java @@ -6,7 +6,6 @@ import lombok.Setter; import java.util.ArrayList; import java.util.HashSet; -import java.util.Objects; import java.util.UUID; @Getter @Setter @NoArgsConstructor @@ -26,15 +25,20 @@ public class Floor { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Floor floor = (Floor) o; - return y == floor.y && - Objects.equals(world, floor.world) && - Objects.equals(doorBlocks, floor.doorBlocks) && - Objects.equals(whitelist, floor.whitelist); + if (world == null) { + if (floor.getWorld() != null) return false; + } else if (!world.equals(floor.getWorld())) return false; + + return y == floor.getY(); } @Override public int hashCode() { - return Objects.hash(world, y, doorBlocks, whitelist); + final int prime = 31; + int result = 1; + result = prime * result + ((world == null) ? 0 : world.hashCode()); + result = prime * result + y; + return result; } @Override diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Lift.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Lift.java index 39d35af..d42eeb9 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Lift.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/Lift.java @@ -45,38 +45,6 @@ public class Lift { this.realistic = realistic; } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Lift lift = (Lift) o; - return y == lift.y && - speed == lift.speed && - realistic == lift.realistic && - offline == lift.offline && - sound == lift.sound && - defective == lift.defective && - counter == lift.counter && - Objects.equals(worldName, lift.worldName) && - Objects.equals(owners, lift.owners) && - Objects.equals(blocks, lift.blocks) && - Objects.equals(floors, lift.floors) && - Objects.equals(signs, lift.signs) && - Objects.equals(inputs, lift.inputs) && - Objects.equals(offlineInputs, lift.offlineInputs) && - Objects.equals(queue, lift.queue) && - Objects.equals(ropes, lift.ropes) && - Objects.equals(toMove, lift.toMove) && - Objects.equals(signText, lift.signText) && - Objects.equals(doorOpen, lift.doorOpen) && - Objects.equals(doorCloser, lift.doorCloser); - } - - @Override - public int hashCode() { - return Objects.hash(worldName, y, owners, blocks, floors, signs, inputs, offlineInputs, queue, ropes, toMove, speed, realistic, offline, sound, defective, signText, counter, doorOpen, doorCloser); - } - @Override public String toString() { return "Lift{" + diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java index c7fa45d..806c8b4 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftBlock.java @@ -31,7 +31,7 @@ public class LiftBlock implements Comparable { @Getter @Setter private boolean active = false; //Only used for chests - public Map[] serializedItemStacks = null; + public Map[] serializedItemStacks = null; /* Floor based liftblock, no material */ public LiftBlock(String world, int x, int y, int z, String floor) { @@ -147,27 +147,29 @@ public class LiftBlock implements Comparable { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - LiftBlock liftBlock = (LiftBlock) o; - return x == liftBlock.x && - y == liftBlock.y && - z == liftBlock.z && - data == liftBlock.data && - active == liftBlock.active && - Objects.equals(world, liftBlock.world) && - mat == liftBlock.mat && - face == liftBlock.face && - Objects.equals(bisected, liftBlock.bisected) && - Arrays.equals(signLines, liftBlock.signLines) && - Objects.equals(floor, liftBlock.floor) && - Arrays.equals(serializedItemStacks, liftBlock.serializedItemStacks); + if (!(o instanceof LiftBlock)) { + if (!(o instanceof LiftSign)) return false; + LiftSign other = (LiftSign) o; + return world.equals(other.getWorld()) && + x == other.getX() && + y == other.getY() && + z == other.getZ(); + } + LiftBlock other = (LiftBlock) o; + return world.equals(other.world) && + x == other.x && + y == other.y && + z == other.z; } @Override public int hashCode() { - int result = Objects.hash(world, x, y, z, mat, data, face, bisected, floor, active); - result = 31 * result + Arrays.hashCode(signLines); - result = 31 * result + Arrays.hashCode(serializedItemStacks); + final int prime = 31; + int result = 1; + result = prime * result + ((world == null) ? 0 : world.hashCode()); + result = prime * result + x; + result = prime * result + y; + result = prime * result + z; return result; } diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java index c4f076f..8d6ec05 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftRope.java @@ -39,15 +39,19 @@ public class LiftRope { minY == liftRope.minY && maxY == liftRope.maxY && z == liftRope.z && - currently == liftRope.currently && - type == liftRope.type && - face == liftRope.face && Objects.equals(world, liftRope.world); } @Override public int hashCode() { - return Objects.hash(type, face, world, x, minY, maxY, z, currently); + final int prime = 31; + int result = 1; + result = prime * result + world.hashCode(); + result = prime * result + x; + result = prime * result + minY; + result = prime * result + maxY; + result = prime * result + z; + return result; } @Override diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java index f3e268f..b6a26c4 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/LiftSign.java @@ -28,20 +28,31 @@ public class LiftSign { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - LiftSign liftSign = (LiftSign) o; - return x == liftSign.x && - z == liftSign.z && - y == liftSign.y && - type == liftSign.type && - state == liftSign.state && - Objects.equals(world, liftSign.world) && - Objects.equals(oldText, liftSign.oldText); + if (!(o instanceof LiftSign)) { + if (!(o instanceof LiftBlock)) + return false; + LiftBlock other = (LiftBlock) o; + return world.equals(other.getWorld()) && + x == other.getX() && + y == other.getY() && + z == other.getZ(); + } + LiftSign other = (LiftSign) o; + return world.equals(other.world) && + x == other.x && + y == other.y && + z == other.z; } @Override public int hashCode() { - return Objects.hash(world, x, z, y, oldText, type, state); + final int prime = 31; + int result = 1; + result = prime * result + ((world == null) ? 0 : world.hashCode()); + result = prime * result + x; + result = prime * result + y; + result = prime * result + z; + return result; } @Override diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java index 90daf2b..b1e5e01 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Objects/V10Entity.java @@ -7,7 +7,6 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; -import java.util.Objects; import java.util.UUID; @Getter @NoArgsConstructor @@ -49,20 +48,33 @@ public class V10Entity { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - V10Entity v10Entity = (V10Entity) o; - return locX == v10Entity.locX && - locY == v10Entity.locY && - locZ == v10Entity.locZ && - y == v10Entity.y && - step == v10Entity.step && - Objects.equals(entityUUID, v10Entity.entityUUID) && - Objects.equals(world, v10Entity.world); + if (o == null) return false; + UUID uuid; + if (o instanceof V10Entity) { + Entity ent = Bukkit.getEntity(((V10Entity) o).getEntityUUID()); + if (ent == null || ent.isDead()) { + Entity e = Bukkit.getEntity(entityUUID); + return e == null || e.isDead(); + } + uuid = ent.getUniqueId(); + } else if (o instanceof Entity) { + Entity ent = (Entity) o; + if (ent.isDead()) { + Entity e = Bukkit.getEntity(entityUUID); + return e == null || e.isDead(); + } + uuid = ((Entity) o).getUniqueId(); + } else + return false; + Entity e = Bukkit.getEntity(entityUUID); + if (e == null || e.isDead()) + return false; + return uuid == e.getUniqueId(); } @Override public int hashCode() { - return Objects.hash(entityUUID, world, locX, locY, locZ, y, step); + return 31 + ((entityUUID == null) ? 0 : entityUUID.hashCode()); } @Override diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java index 62d0f23..cb69c22 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/API/Runnables/MoveLift.java @@ -169,7 +169,6 @@ public class MoveLift implements Runnable { } } - boolean wc = false; for (LiftBlock lib : lift.getBlocks().descendingSet()) { world = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift"); block = world.getBlockAt(lib.getX(), lib.getY(), lib.getZ()); diff --git a/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/DirectionUtil.java b/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/DirectionUtil.java index ab42110..231e03c 100644 --- a/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/DirectionUtil.java +++ b/src/main/lombok/nl/SBDeveloper/V10Lift/Utils/DirectionUtil.java @@ -2,8 +2,6 @@ package nl.SBDeveloper.V10Lift.Utils; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import org.bukkit.block.data.Bisected; -import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Directional; import javax.annotation.Nonnull; @@ -13,6 +11,7 @@ public class DirectionUtil { @Nullable public static BlockFace getDirection(@Nonnull Block block) { + if (!XMaterial.isNewVersion()) return null; if (block.getBlockData() instanceof Directional) { Directional dir = (Directional) block.getBlockData(); return dir.getFacing(); @@ -21,8 +20,9 @@ public class DirectionUtil { } public static void setDirection(@Nonnull Block block, BlockFace blockFace) { + if (!XMaterial.isNewVersion()) return; if (blockFace != null && block.getBlockData() instanceof Directional) { - BlockData bd = block.getBlockData(); + org.bukkit.block.data.BlockData bd = block.getBlockData(); Directional dir = (Directional) bd; dir.setFacing(blockFace); block.setBlockData(bd); @@ -31,25 +31,27 @@ public class DirectionUtil { @Nullable public static String getBisected(@Nonnull Block block) { - if (block.getBlockData() instanceof Bisected) { - Bisected bis = (Bisected) block.getBlockData(); + if (!XMaterial.isNewVersion()) return null; + if (block.getBlockData() instanceof org.bukkit.block.data.Bisected) { + org.bukkit.block.data.Bisected bis = (org.bukkit.block.data.Bisected) block.getBlockData(); return bis.getHalf().toString(); } return null; } public static void setBisected(@Nonnull Block block, String bisected) { - if (bisected != null && block.getBlockData() instanceof Bisected) { + if (!XMaterial.isNewVersion()) return; + if (bisected != null && block.getBlockData() instanceof org.bukkit.block.data.Bisected) { - Bisected.Half half; + org.bukkit.block.data.Bisected.Half half; try { - half = Bisected.Half.valueOf(bisected); + half = org.bukkit.block.data.Bisected.Half.valueOf(bisected); } catch (IllegalArgumentException e) { return; } - BlockData bd = block.getBlockData(); - Bisected bis = (Bisected) bd; + org.bukkit.block.data.BlockData bd = block.getBlockData(); + org.bukkit.block.data.Bisected bis = (org.bukkit.block.data.Bisected) bd; bis.setHalf(half); block.setBlockData(bd); }