From 6882660286da0dd8ee3b1cbf9ff0d30101b56fac Mon Sep 17 00:00:00 2001 From: Kermina Awad Date: Thu, 9 Jul 2020 09:48:40 -0400 Subject: [PATCH] use Location's World --- .../onarandombox/MultiverseCore/MVWorld.java | 3 +- .../configuration/SpawnLocation.java | 54 +++---------------- .../MultiverseCore/TestWorldProperties.java | 8 +-- 3 files changed, 11 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index d8f64e97..485a75ae 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -28,7 +28,6 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldType; -import org.bukkit.command.CommandSender; import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; @@ -346,7 +345,7 @@ public class MVWorld implements MultiverseWorld { @SerializableAs("MVNullLocation (It's a bug if you see this in your config file)") public static final class NullLocation extends SpawnLocation { public NullLocation() { - super(0, -1, 0); + super(null, 0, -1, 0); } @Override diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/SpawnLocation.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/SpawnLocation.java index a09391c1..170dc802 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/SpawnLocation.java +++ b/src/main/java/com/onarandombox/MultiverseCore/configuration/SpawnLocation.java @@ -1,14 +1,10 @@ package com.onarandombox.MultiverseCore.configuration; -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; -import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.block.Block; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.SerializableAs; @@ -18,54 +14,16 @@ import org.bukkit.configuration.serialization.SerializableAs; */ @SerializableAs("MVSpawnLocation") public class SpawnLocation extends Location implements ConfigurationSerializable { - private Reference worldRef; - - public SpawnLocation(double x, double y, double z) { - super(null, x, y, z); + public SpawnLocation(World world, double x, double y, double z) { + super(world, x, y, z); } - public SpawnLocation(double x, double y, double z, float yaw, float pitch) { - super(null, x, y, z, yaw, pitch); + public SpawnLocation(World world, double x, double y, double z, float yaw, float pitch) { + super(world, x, y, z, yaw, pitch); } public SpawnLocation(Location loc) { - this(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); - } - - /** - * {@inheritDoc} - */ - @Override - public World getWorld() { - return (this.worldRef != null) ? this.worldRef.get() : null; - } - - /** - * {@inheritDoc} - */ - @Override - public void setWorld(World world) { - this.worldRef = new WeakReference(world); - } - - /** - * {@inheritDoc} - */ - @Override - public Chunk getChunk() { - if ((this.worldRef != null) && (this.worldRef.get() != null)) - return this.worldRef.get().getChunkAt(this); - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public Block getBlock() { - if ((this.worldRef != null) && (this.worldRef.get() != null)) - return this.worldRef.get().getBlockAt(this); - return null; + super(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); } /** @@ -93,6 +51,6 @@ public class SpawnLocation extends Location implements ConfigurationSerializable double z = ((Number) args.get("z")).doubleValue(); float pitch = ((Number) args.get("pitch")).floatValue(); float yaw = ((Number) args.get("yaw")).floatValue(); - return new SpawnLocation(x, y, z, yaw, pitch); + return new SpawnLocation(null, x, y, z, yaw, pitch); } } diff --git a/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java b/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java index c415b3db..bf7fb03e 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java +++ b/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java @@ -166,7 +166,7 @@ public class TestWorldProperties { assertTrue(mvWorld.isKeepingSpawnInMemory()); assertTrue(mvWorld.getBedRespawn()); assertTrue(mvWorld.getAutoLoad()); - assertEquals(new SpawnLocation(0, 64, 0), mvWorld.getSpawnLocation()); + assertEquals(new SpawnLocation(core.getServer().getWorld("world"), 0, 64, 0), mvWorld.getSpawnLocation()); /* ****************************************** * * Call some events and verify behavior @@ -258,7 +258,7 @@ public class TestWorldProperties { mvWorld.setAutoLoad(false); assertEquals(false, mvWorld.getAutoLoad()); mvWorld.setSpawnLocation(new Location(mvWorld.getCBWorld(), 1, 1, 1)); - assertEquals(new SpawnLocation(1, 1, 1), mvWorld.getSpawnLocation()); + assertEquals(new SpawnLocation(core.getServer().getWorld("world"), 1, 1, 1), mvWorld.getSpawnLocation()); /* ****************************************** * @@ -297,7 +297,7 @@ public class TestWorldProperties { core.getPlayerListener().playerJoin(playerJoinEvent); verify(mockPlayer, never()).teleport(any(Location.class)); core.getPlayerListener().playerJoin(playerNewJoinEvent); - verify(mockNewPlayer).teleport(new SpawnLocation(1, 1, 1)); + verify(mockNewPlayer).teleport(new SpawnLocation(core.getServer().getWorld("world"), 1, 1, 1)); // call player respawn events core.getPlayerListener().playerRespawn(playerRespawnBed); @@ -347,7 +347,7 @@ public class TestWorldProperties { assertEquals(false, mvWorld.isKeepingSpawnInMemory()); assertEquals(false, mvWorld.getBedRespawn()); assertEquals(false, mvWorld.getAutoLoad()); - assertEquals(new SpawnLocation(1, 1, 1), mvWorld.getSpawnLocation()); + assertEquals(new SpawnLocation(core.getServer().getWorld("world"), 1, 1, 1), mvWorld.getSpawnLocation()); } public void createEvents(MultiverseWorld mvWorld) {