From bcd5b9bbf2da476c62321d5fdc18d718780670e2 Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Wed, 7 Feb 2024 19:41:30 +0100 Subject: [PATCH] Implement equals for all ServerWorld implementations --- .../core/world/mca/PackedIntArrayAccess.java | 2 ++ .../bluemap/fabric/FabricWorld.java | 16 ++++++++++++++ .../bluemap/fabric/FabricWorld.java | 16 ++++++++++++++ .../bluemap/fabric/FabricWorld.java | 16 ++++++++++++++ .../bluemap/fabric/FabricWorld.java | 16 ++++++++++++++ .../bluemap/fabric/FabricWorld.java | 16 ++++++++++++++ .../bluemap/fabric/FabricWorld.java | 16 ++++++++++++++ .../bluecolored/bluemap/forge/ForgeWorld.java | 16 ++++++++++++++ .../bluecolored/bluemap/forge/ForgeWorld.java | 16 ++++++++++++++ .../bluecolored/bluemap/forge/ForgeWorld.java | 16 ++++++++++++++ .../bluecolored/bluemap/forge/ForgeWorld.java | 16 ++++++++++++++ .../bluecolored/bluemap/forge/ForgeWorld.java | 16 ++++++++++++++ .../bluemap/bukkit/BukkitWorld.java | 21 +++++++++++++++++-- .../bluemap/bukkit/BukkitWorld.java | 16 ++++++++++++++ .../bluemap/sponge/SpongeWorld.java | 16 ++++++++++++++ 15 files changed, 229 insertions(+), 2 deletions(-) diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/PackedIntArrayAccess.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/PackedIntArrayAccess.java index b56432dc..e32aedfa 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/PackedIntArrayAccess.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/world/mca/PackedIntArrayAccess.java @@ -4,6 +4,7 @@ public class PackedIntArrayAccess { // magic constants for fast division private static final int[] DIVISION_MAGIC = new int[]{ + // -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 + // }; private final int bitsPerElement; diff --git a/implementations/fabric-1.15.2/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java b/implementations/fabric-1.15.2/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java index a8f3aab1..349c0cb7 100644 --- a/implementations/fabric-1.15.2/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java +++ b/implementations/fabric-1.15.2/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java @@ -91,4 +91,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/fabric-1.16.2/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java b/implementations/fabric-1.16.2/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java index 31ec0381..73b20f9c 100644 --- a/implementations/fabric-1.16.2/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java +++ b/implementations/fabric-1.16.2/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java @@ -91,4 +91,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/fabric-1.17/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java b/implementations/fabric-1.17/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java index 31ec0381..73b20f9c 100644 --- a/implementations/fabric-1.17/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java +++ b/implementations/fabric-1.17/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java @@ -91,4 +91,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/fabric-1.18/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java b/implementations/fabric-1.18/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java index 31ec0381..73b20f9c 100644 --- a/implementations/fabric-1.18/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java +++ b/implementations/fabric-1.18/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java @@ -91,4 +91,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/fabric-1.19.4/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java b/implementations/fabric-1.19.4/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java index 31ec0381..73b20f9c 100644 --- a/implementations/fabric-1.19.4/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java +++ b/implementations/fabric-1.19.4/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java @@ -91,4 +91,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/fabric-1.20/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java b/implementations/fabric-1.20/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java index 31ec0381..73b20f9c 100644 --- a/implementations/fabric-1.20/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java +++ b/implementations/fabric-1.20/src/main/java/de/bluecolored/bluemap/fabric/FabricWorld.java @@ -91,4 +91,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/forge-1.17.1/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java b/implementations/forge-1.17.1/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java index da750184..0474e297 100644 --- a/implementations/forge-1.17.1/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java +++ b/implementations/forge-1.17.1/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java @@ -92,4 +92,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/forge-1.18.1/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java b/implementations/forge-1.18.1/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java index da750184..0474e297 100644 --- a/implementations/forge-1.18.1/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java +++ b/implementations/forge-1.18.1/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java @@ -92,4 +92,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/forge-1.19.4/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java b/implementations/forge-1.19.4/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java index da750184..0474e297 100644 --- a/implementations/forge-1.19.4/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java +++ b/implementations/forge-1.19.4/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java @@ -92,4 +92,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/forge-1.20/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java b/implementations/forge-1.20/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java index da750184..0474e297 100644 --- a/implementations/forge-1.20/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java +++ b/implementations/forge-1.20/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java @@ -92,4 +92,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/neoforge-1.20.2/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java b/implementations/neoforge-1.20.2/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java index da750184..0474e297 100644 --- a/implementations/neoforge-1.20.2/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java +++ b/implementations/neoforge-1.20.2/src/main/java/de/bluecolored/bluemap/forge/ForgeWorld.java @@ -92,4 +92,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java b/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java index e155d9eb..db7954ee 100644 --- a/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java +++ b/implementations/paper/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java @@ -29,17 +29,18 @@ 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 delegate; + private final WeakReference 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 Key getDimension() { 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; + } + } diff --git a/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java b/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java index 1a2e52cb..04021343 100644 --- a/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java +++ b/implementations/spigot/src/main/java/de/bluecolored/bluemap/bukkit/BukkitWorld.java @@ -97,4 +97,20 @@ public Key getDimension() { 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; + } + } diff --git a/implementations/sponge/src/main/java/de/bluecolored/bluemap/sponge/SpongeWorld.java b/implementations/sponge/src/main/java/de/bluecolored/bluemap/sponge/SpongeWorld.java index bf5138c5..bf30ebbf 100644 --- a/implementations/sponge/src/main/java/de/bluecolored/bluemap/sponge/SpongeWorld.java +++ b/implementations/sponge/src/main/java/de/bluecolored/bluemap/sponge/SpongeWorld.java @@ -84,4 +84,20 @@ public Key getDimension() { 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; + } + }