Let location serialization throw exceptions if a given world does not exist anymore.
This commit is contained in:
parent
384c2b819d
commit
ed9aa2fa09
@ -5,8 +5,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
|
||||||
import org.bukkit.WorldCreator;
|
|
||||||
|
|
||||||
import de.craftinc.gates.Plugin;
|
import de.craftinc.gates.Plugin;
|
||||||
|
|
||||||
@ -22,15 +20,12 @@ public class LocationSerializer
|
|||||||
protected static String zKey = "z";
|
protected static String zKey = "z";
|
||||||
|
|
||||||
|
|
||||||
protected static World getWorld(String name)
|
protected static World getWorld(String name) throws Exception
|
||||||
{
|
{
|
||||||
World world = Plugin.instance.getServer().getWorld(name);
|
World world = Plugin.instance.getServer().getWorld(name);
|
||||||
|
|
||||||
// TODO: Creating a world silently in the background is not a good thing I think. No one expects a Gate
|
|
||||||
// Plugin to do that. It would be better to handle gates which point to non-existing worlds safely (not
|
|
||||||
// teleporting at all)
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
world = Plugin.instance.getServer().createWorld(new WorldCreator(name).environment(Environment.NORMAL));
|
throw new Exception("World '" + name + "' does not exists anymore! Cannot get instance!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return world;
|
return world;
|
||||||
@ -50,7 +45,7 @@ public class LocationSerializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static Location deserializeLocation(Map<String, Object> map)
|
public static Location deserializeLocation(Map<String, Object> map) throws Exception
|
||||||
{
|
{
|
||||||
World w = getWorld((String)map.get(worldKey));
|
World w = getWorld((String)map.get(worldKey));
|
||||||
double x = (Double) map.get(xKey);
|
double x = (Double) map.get(xKey);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user