Implement equals for all ServerWorld implementations

This commit is contained in:
Lukas Rieger (Blue) 2024-02-07 19:41:30 +01:00
parent e68aacfd5d
commit bcd5b9bbf2
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
15 changed files with 229 additions and 2 deletions

View File

@ -4,6 +4,7 @@ public class PackedIntArrayAccess {
// magic constants for fast division
private static final int[] DIVISION_MAGIC = new int[]{
// <editor-fold defaultstate="collapsed" desc="Division-Magic Constants">
-1, -1, 0,
Integer.MIN_VALUE, 0, 0,
1431655765, 1431655765, 0,
@ -68,6 +69,7 @@ public class PackedIntArrayAccess {
69273666, 69273666, 0,
68174084, 68174084, 0,
Integer.MIN_VALUE, 0, 5
// </editor-fold>
};
private final int bitsPerElement;

View File

@ -91,4 +91,20 @@ public class FabricWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FabricWorld that = (FabricWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -91,4 +91,20 @@ public class FabricWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FabricWorld that = (FabricWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -91,4 +91,20 @@ public class FabricWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FabricWorld that = (FabricWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -91,4 +91,20 @@ public class FabricWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FabricWorld that = (FabricWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -91,4 +91,20 @@ public class FabricWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FabricWorld that = (FabricWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -91,4 +91,20 @@ public class FabricWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FabricWorld that = (FabricWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -92,4 +92,20 @@ public class ForgeWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ForgeWorld that = (ForgeWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -92,4 +92,20 @@ public class ForgeWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ForgeWorld that = (ForgeWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -92,4 +92,20 @@ public class ForgeWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ForgeWorld that = (ForgeWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -92,4 +92,20 @@ public class ForgeWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ForgeWorld that = (ForgeWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -92,4 +92,20 @@ public class ForgeWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ForgeWorld that = (ForgeWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -29,17 +29,18 @@ import de.bluecolored.bluemap.core.util.Key;
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
import org.bukkit.World;
import java.lang.ref.WeakReference;
import java.nio.file.Files;
import java.nio.file.Path;
public class BukkitWorld implements ServerWorld {
//private final WeakReference<World> delegate;
private final WeakReference<World> delegate;
private final Path worldFolder;
private final Key dimension;
public BukkitWorld(World delegate) {
//this.delegate = new WeakReference<>(delegate);
this.delegate = new WeakReference<>(delegate);
Path worldFolder = delegate.getWorldFolder().toPath();
var id = delegate.key();
@ -79,4 +80,20 @@ public class BukkitWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BukkitWorld that = (BukkitWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -97,4 +97,20 @@ public class BukkitWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BukkitWorld that = (BukkitWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}

View File

@ -84,4 +84,20 @@ public class SpongeWorld implements ServerWorld {
return dimension;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SpongeWorld that = (SpongeWorld) o;
var world = delegate.get();
return world != null && world.equals(that.delegate.get());
}
@Override
public int hashCode() {
var world = delegate.get();
return world != null ? world.hashCode() : 0;
}
}