diff --git a/Essentials/src/main/java/com/earth2me/essentials/RandomTeleport.java b/Essentials/src/main/java/com/earth2me/essentials/RandomTeleport.java index d830a1bf2..8c2533860 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/RandomTeleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/RandomTeleport.java @@ -40,7 +40,7 @@ public class RandomTeleport implements IConf { public Location getCenter() { try { - final Location center = config.getLocation("center"); + final Location center = config.getLocation("center").location(); if (center != null) { return center; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Warps.java b/Essentials/src/main/java/com/earth2me/essentials/Warps.java index f1f671fc0..c4dd46c85 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Warps.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Warps.java @@ -54,7 +54,12 @@ public class Warps implements IConf, net.ess3.api.IWarps { if (conf == null) { throw new WarpNotFoundException(); } - return conf.getLocation(null); + + final Location loc = conf.getLocation(null).location(); + if (loc == null) { + throw new WarpNotFoundException(); + } + return loc; } @Override diff --git a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java index c2d96f18e..3b87bd25b 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java +++ b/Essentials/src/main/java/com/earth2me/essentials/config/EssentialsConfiguration.java @@ -103,26 +103,26 @@ public class EssentialsConfiguration { setInternal(path, location); } - public Location getLocation(final String path) throws InvalidWorldException { + public LazyLocation getLocation(final String path) throws InvalidWorldException { final CommentedConfigurationNode node = path == null ? getRootNode() : getSection(path); if (node == null) { return null; } try { - return node.get(Location.class); + return node.get(LazyLocation.class); } catch (SerializationException e) { return null; } } - public Map getLocationSectionMap(final String path) { + public Map getLocationSectionMap(final String path) { final CommentedConfigurationNode node = getSection(path); - final Map result = new HashMap<>(); + final Map result = new HashMap<>(); for (final Map.Entry entry : ConfigurateUtil.getMap(node).entrySet()) { final CommentedConfigurationNode jailNode = entry.getValue(); try { - result.put(entry.getKey().toLowerCase(Locale.ENGLISH), jailNode.get(Location.class)); + result.put(entry.getKey().toLowerCase(Locale.ENGLISH), jailNode.get(LazyLocation.class)); } catch (SerializationException e) { LOGGER.log(Level.WARNING, "Error serializing key " + entry.getKey(), e); } diff --git a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/Commandspawn.java index 8794b3491..02781551d 100644 --- a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/Commandspawn.java +++ b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/Commandspawn.java @@ -69,6 +69,9 @@ public class Commandspawn extends EssentialsCommand { private void respawn(final CommandSource sender, final User teleportOwner, final User teleportee, final Trade charge, final String commandLabel, final CompletableFuture future) throws Exception { final Location spawn = ((SpawnStorage) this.module).getSpawn(teleportee.getGroup()); + if (spawn == null) { + return; + } sender.sendMessage(tl("teleporting", spawn.getWorld().getName(), spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ())); future.exceptionally(e -> { showError(sender.getSender(), e, commandLabel); diff --git a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java index fbe672f8a..e72522a85 100644 --- a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java +++ b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/EssentialsSpawnPlayerListener.java @@ -85,6 +85,9 @@ class EssentialsSpawnPlayerListener implements Listener { if (ess.getSettings().isUserInSpawnOnJoinGroup(user) && !user.isAuthorized("essentials.spawn-on-join.exempt")) { ess.scheduleSyncDelayedTask(() -> { final Location spawn = spawns.getSpawn(user.getGroup()); + if (spawn == null) { + return; + } final CompletableFuture future = new CompletableFuture<>(); future.exceptionally(e -> { ess.showError(user.getSource(), e, "spawn-on-join"); diff --git a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/SpawnStorage.java b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/SpawnStorage.java index 1f7bc14a2..c8d2e7308 100644 --- a/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/SpawnStorage.java +++ b/EssentialsSpawn/src/main/java/com/earth2me/essentials/spawn/SpawnStorage.java @@ -3,6 +3,7 @@ package com.earth2me.essentials.spawn; import com.earth2me.essentials.IConf; import com.earth2me.essentials.IEssentialsModule; import com.earth2me.essentials.config.EssentialsConfiguration; +import com.earth2me.essentials.config.entities.LazyLocation; import net.ess3.api.IEssentials; import org.bukkit.Location; import org.bukkit.World; @@ -15,7 +16,7 @@ import java.util.Map; public class SpawnStorage implements IEssentialsModule, IConf { private final IEssentials ess; private final EssentialsConfiguration config; - private final Map spawns = new HashMap<>(); + private final Map spawns = new HashMap<>(); SpawnStorage(final IEssentials ess) { this.ess = ess; @@ -36,7 +37,7 @@ public class SpawnStorage implements IEssentialsModule, IConf { void setSpawn(final Location loc, String group) { group = group.toLowerCase(Locale.ENGLISH); synchronized (spawns) { - spawns.put(group, loc); + spawns.put(group, LazyLocation.fromLocation(loc)); config.setProperty("spawns." + group, loc); config.save(); } @@ -52,7 +53,7 @@ public class SpawnStorage implements IEssentialsModule, IConf { if (!spawns.containsKey(group)) { return getWorldSpawn(); } - return spawns.get(group); + return spawns.get(group).location(); } }