Fix remaining uses of Location over LazyLocation (#4206)

This commit is contained in:
Josh Roy 2021-06-07 18:23:13 -04:00 committed by GitHub
parent 300daea4f9
commit 3d09ea386b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 10 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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<String, Location> getLocationSectionMap(final String path) {
public Map<String, LazyLocation> getLocationSectionMap(final String path) {
final CommentedConfigurationNode node = getSection(path);
final Map<String, Location> result = new HashMap<>();
final Map<String, LazyLocation> result = new HashMap<>();
for (final Map.Entry<String, CommentedConfigurationNode> 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);
}

View File

@ -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<Boolean> 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);

View File

@ -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<Boolean> future = new CompletableFuture<>();
future.exceptionally(e -> {
ess.showError(user.getSource(), e, "spawn-on-join");

View File

@ -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<String, Location> spawns = new HashMap<>();
private final Map<String, LazyLocation> 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();
}
}