mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 03:55:27 +01:00
use Location's World
This commit is contained in:
parent
3afca50930
commit
6882660286
@ -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
|
||||
|
@ -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<World> 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>(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);
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user