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.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
|
||||
|
|
|
@ -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{" +
|
||||
|
|
|
@ -31,7 +31,7 @@ public class LiftBlock implements Comparable<LiftBlock> {
|
|||
@Getter @Setter private boolean active = false;
|
||||
|
||||
//Only used for chests
|
||||
public Map<String, Object>[] 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<LiftBlock> {
|
|||
@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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue