Fixed some equals() issues
This commit is contained in:
parent
2146beba9d
commit
9d5de9c0e7
8 changed files with 94 additions and 92 deletions
|
@ -6,7 +6,6 @@ import lombok.Setter;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Getter @Setter @NoArgsConstructor
|
@Getter @Setter @NoArgsConstructor
|
||||||
|
@ -26,15 +25,20 @@ public class Floor {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
Floor floor = (Floor) o;
|
Floor floor = (Floor) o;
|
||||||
return y == floor.y &&
|
if (world == null) {
|
||||||
Objects.equals(world, floor.world) &&
|
if (floor.getWorld() != null) return false;
|
||||||
Objects.equals(doorBlocks, floor.doorBlocks) &&
|
} else if (!world.equals(floor.getWorld())) return false;
|
||||||
Objects.equals(whitelist, floor.whitelist);
|
|
||||||
|
return y == floor.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
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
|
@Override
|
||||||
|
|
|
@ -45,38 +45,6 @@ public class Lift {
|
||||||
this.realistic = realistic;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Lift{" +
|
return "Lift{" +
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
||||||
@Getter @Setter private boolean active = false;
|
@Getter @Setter private boolean active = false;
|
||||||
|
|
||||||
//Only used for chests
|
//Only used for chests
|
||||||
public Map<String, Object>[] serializedItemStacks = null;
|
public Map[] serializedItemStacks = null;
|
||||||
|
|
||||||
/* Floor based liftblock, no material */
|
/* Floor based liftblock, no material */
|
||||||
public LiftBlock(String world, int x, int y, int z, String floor) {
|
public LiftBlock(String world, int x, int y, int z, String floor) {
|
||||||
|
@ -147,27 +147,29 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (!(o instanceof LiftBlock)) {
|
||||||
LiftBlock liftBlock = (LiftBlock) o;
|
if (!(o instanceof LiftSign)) return false;
|
||||||
return x == liftBlock.x &&
|
LiftSign other = (LiftSign) o;
|
||||||
y == liftBlock.y &&
|
return world.equals(other.getWorld()) &&
|
||||||
z == liftBlock.z &&
|
x == other.getX() &&
|
||||||
data == liftBlock.data &&
|
y == other.getY() &&
|
||||||
active == liftBlock.active &&
|
z == other.getZ();
|
||||||
Objects.equals(world, liftBlock.world) &&
|
}
|
||||||
mat == liftBlock.mat &&
|
LiftBlock other = (LiftBlock) o;
|
||||||
face == liftBlock.face &&
|
return world.equals(other.world) &&
|
||||||
Objects.equals(bisected, liftBlock.bisected) &&
|
x == other.x &&
|
||||||
Arrays.equals(signLines, liftBlock.signLines) &&
|
y == other.y &&
|
||||||
Objects.equals(floor, liftBlock.floor) &&
|
z == other.z;
|
||||||
Arrays.equals(serializedItemStacks, liftBlock.serializedItemStacks);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = Objects.hash(world, x, y, z, mat, data, face, bisected, floor, active);
|
final int prime = 31;
|
||||||
result = 31 * result + Arrays.hashCode(signLines);
|
int result = 1;
|
||||||
result = 31 * result + Arrays.hashCode(serializedItemStacks);
|
result = prime * result + ((world == null) ? 0 : world.hashCode());
|
||||||
|
result = prime * result + x;
|
||||||
|
result = prime * result + y;
|
||||||
|
result = prime * result + z;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,15 +39,19 @@ public class LiftRope {
|
||||||
minY == liftRope.minY &&
|
minY == liftRope.minY &&
|
||||||
maxY == liftRope.maxY &&
|
maxY == liftRope.maxY &&
|
||||||
z == liftRope.z &&
|
z == liftRope.z &&
|
||||||
currently == liftRope.currently &&
|
|
||||||
type == liftRope.type &&
|
|
||||||
face == liftRope.face &&
|
|
||||||
Objects.equals(world, liftRope.world);
|
Objects.equals(world, liftRope.world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
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
|
@Override
|
||||||
|
|
|
@ -28,20 +28,31 @@ public class LiftSign {
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (!(o instanceof LiftSign)) {
|
||||||
LiftSign liftSign = (LiftSign) o;
|
if (!(o instanceof LiftBlock))
|
||||||
return x == liftSign.x &&
|
return false;
|
||||||
z == liftSign.z &&
|
LiftBlock other = (LiftBlock) o;
|
||||||
y == liftSign.y &&
|
return world.equals(other.getWorld()) &&
|
||||||
type == liftSign.type &&
|
x == other.getX() &&
|
||||||
state == liftSign.state &&
|
y == other.getY() &&
|
||||||
Objects.equals(world, liftSign.world) &&
|
z == other.getZ();
|
||||||
Objects.equals(oldText, liftSign.oldText);
|
}
|
||||||
|
LiftSign other = (LiftSign) o;
|
||||||
|
return world.equals(other.world) &&
|
||||||
|
x == other.x &&
|
||||||
|
y == other.y &&
|
||||||
|
z == other.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
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
|
@Override
|
||||||
|
|
|
@ -7,7 +7,6 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Getter @NoArgsConstructor
|
@Getter @NoArgsConstructor
|
||||||
|
@ -49,20 +48,33 @@ public class V10Entity {
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null) return false;
|
||||||
V10Entity v10Entity = (V10Entity) o;
|
UUID uuid;
|
||||||
return locX == v10Entity.locX &&
|
if (o instanceof V10Entity) {
|
||||||
locY == v10Entity.locY &&
|
Entity ent = Bukkit.getEntity(((V10Entity) o).getEntityUUID());
|
||||||
locZ == v10Entity.locZ &&
|
if (ent == null || ent.isDead()) {
|
||||||
y == v10Entity.y &&
|
Entity e = Bukkit.getEntity(entityUUID);
|
||||||
step == v10Entity.step &&
|
return e == null || e.isDead();
|
||||||
Objects.equals(entityUUID, v10Entity.entityUUID) &&
|
}
|
||||||
Objects.equals(world, v10Entity.world);
|
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
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(entityUUID, world, locX, locY, locZ, y, step);
|
return 31 + ((entityUUID == null) ? 0 : entityUUID.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -169,7 +169,6 @@ public class MoveLift implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean wc = false;
|
|
||||||
for (LiftBlock lib : lift.getBlocks().descendingSet()) {
|
for (LiftBlock lib : lift.getBlocks().descendingSet()) {
|
||||||
world = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift");
|
world = Objects.requireNonNull(Bukkit.getWorld(lib.getWorld()), "World is null at MoveLift");
|
||||||
block = world.getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
block = world.getBlockAt(lib.getX(), lib.getY(), lib.getZ());
|
||||||
|
|
|
@ -2,8 +2,6 @@ package nl.SBDeveloper.V10Lift.Utils;
|
||||||
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.data.Bisected;
|
|
||||||
import org.bukkit.block.data.BlockData;
|
|
||||||
import org.bukkit.block.data.Directional;
|
import org.bukkit.block.data.Directional;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
@ -13,6 +11,7 @@ public class DirectionUtil {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static BlockFace getDirection(@Nonnull Block block) {
|
public static BlockFace getDirection(@Nonnull Block block) {
|
||||||
|
if (!XMaterial.isNewVersion()) return null;
|
||||||
if (block.getBlockData() instanceof Directional) {
|
if (block.getBlockData() instanceof Directional) {
|
||||||
Directional dir = (Directional) block.getBlockData();
|
Directional dir = (Directional) block.getBlockData();
|
||||||
return dir.getFacing();
|
return dir.getFacing();
|
||||||
|
@ -21,8 +20,9 @@ public class DirectionUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDirection(@Nonnull Block block, BlockFace blockFace) {
|
public static void setDirection(@Nonnull Block block, BlockFace blockFace) {
|
||||||
|
if (!XMaterial.isNewVersion()) return;
|
||||||
if (blockFace != null && block.getBlockData() instanceof Directional) {
|
if (blockFace != null && block.getBlockData() instanceof Directional) {
|
||||||
BlockData bd = block.getBlockData();
|
org.bukkit.block.data.BlockData bd = block.getBlockData();
|
||||||
Directional dir = (Directional) bd;
|
Directional dir = (Directional) bd;
|
||||||
dir.setFacing(blockFace);
|
dir.setFacing(blockFace);
|
||||||
block.setBlockData(bd);
|
block.setBlockData(bd);
|
||||||
|
@ -31,25 +31,27 @@ public class DirectionUtil {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String getBisected(@Nonnull Block block) {
|
public static String getBisected(@Nonnull Block block) {
|
||||||
if (block.getBlockData() instanceof Bisected) {
|
if (!XMaterial.isNewVersion()) return null;
|
||||||
Bisected bis = (Bisected) block.getBlockData();
|
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 bis.getHalf().toString();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBisected(@Nonnull Block block, String bisected) {
|
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 {
|
try {
|
||||||
half = Bisected.Half.valueOf(bisected);
|
half = org.bukkit.block.data.Bisected.Half.valueOf(bisected);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockData bd = block.getBlockData();
|
org.bukkit.block.data.BlockData bd = block.getBlockData();
|
||||||
Bisected bis = (Bisected) bd;
|
org.bukkit.block.data.Bisected bis = (org.bukkit.block.data.Bisected) bd;
|
||||||
bis.setHalf(half);
|
bis.setHalf(half);
|
||||||
block.setBlockData(bd);
|
block.setBlockData(bd);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue