Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 13 additions & 16 deletions Essentials/src/main/java/com/earth2me/essentials/Jails.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import com.earth2me.essentials.config.ConfigurateUtil;
import com.earth2me.essentials.config.EssentialsConfiguration;
import com.earth2me.essentials.config.entities.LazyLocation;
import net.ess3.api.IEssentials;
import net.ess3.api.IUser;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -44,7 +43,7 @@ public class Jails implements net.ess3.api.IJails {
private static transient boolean enabled = false;
private final IEssentials ess;
private final EssentialsConfiguration config;
private final Map<String, Location> jails = new HashMap<>();
private final Map<String, LazyLocation> jails = new HashMap<>();

public Jails(final IEssentials ess) {
this.ess = ess;
Expand All @@ -60,17 +59,11 @@ public void reloadConfig() {
final CommentedConfigurationNode jailsNode = config.getSection("jails");
for (final Map.Entry<String, CommentedConfigurationNode> entry : ConfigurateUtil.getMap(jailsNode).entrySet()) {
final CommentedConfigurationNode jailNode = entry.getValue();
final String worldName = jailNode.node("world").getString();
if (worldName == null || worldName.isEmpty()) {
final String worldId = jailNode.node("world").getString();
if (worldId == null || worldId.isEmpty()) {
continue;
}

final World world = Bukkit.getWorld(worldName);
if (world == null) {
LOGGER.log(Level.WARNING, "Invalid world name, " + worldName + ", for jail name " + entry.getKey());
continue;
}
jails.put(entry.getKey().toLowerCase(Locale.ENGLISH), new Location(world, jailNode.node("x").getDouble(), jailNode.node("y").getDouble(),
jails.put(entry.getKey().toLowerCase(Locale.ENGLISH), new LazyLocation(worldId, jailNode.node("x").getDouble(), jailNode.node("y").getDouble(),
jailNode.node("z").getDouble(), jailNode.node("yaw").getFloat(), jailNode.node("pitch").getFloat()));
}
checkRegister();
Expand Down Expand Up @@ -119,7 +112,11 @@ public Location getJail(String jailName) throws Exception {
if (!jails.containsKey(jailName)) {
throw new Exception(tl("jailNotExist"));
}
return jails.get(jailName);
final Location location = jails.get(jailName).location();
if (location == null) {
throw new Exception(tl("jailWorldNotExist"));
}
return location;
}
}

Expand Down Expand Up @@ -160,7 +157,7 @@ public void sendToJail(final IUser user, String jail) throws Exception {
synchronized (jails) {
if (jails.containsKey(jail)) {
if (user.getBase().isOnline()) {
user.getTeleport().now(jails.get(jail), false, TeleportCause.COMMAND);
user.getTeleport().now(getJail(jail), false, TeleportCause.COMMAND);
}
user.setJail(jail);
}
Expand All @@ -177,7 +174,7 @@ public void sendToJail(final IUser user, final String jailName, final Completabl
synchronized (jails) {
if (jails.containsKey(jail)) {
if (user.getBase().isOnline()) {
user.getAsyncTeleport().now(jails.get(jail), false, TeleportCause.COMMAND, future);
user.getAsyncTeleport().now(getJail(jail), false, TeleportCause.COMMAND, future);
future.thenAccept(success -> user.setJail(jail));
return;
}
Expand All @@ -190,7 +187,7 @@ public void sendToJail(final IUser user, final String jailName, final Completabl
public void setJail(String jailName, final Location loc) throws Exception {
jailName = jailName.toLowerCase(Locale.ENGLISH);
synchronized (jails) {
jails.put(jailName, loc);
jails.put(jailName, LazyLocation.fromLocation(loc));
config.setProperty("jails." + jailName, loc);
config.save();
}
Expand Down
1 change: 1 addition & 0 deletions Essentials/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ jailReleased=\u00a76Player \u00a7c{0}\u00a76 unjailed.
jailReleasedPlayerNotify=\u00a76You have been released\!
jailSentenceExtended=\u00a76Jail time extended to \u00a7c{0}\u00a76.
jailSet=\u00a76Jail\u00a7c {0} \u00a76has been set.
jailWorldNotExist=\u00a74That jail's world does not exist.
jumpEasterDisable=\u00a76Flying wizard mode disabled.
jumpEasterEnable=\u00a76Flying wizard mode enabled.
jailsCommandDescription=List all jails.
Expand Down