Skip to content

Commit 7fec711

Browse files
authored
Fix ability to delete warps in unloaded worlds (EssentialsX#4590)
Fixes EssentialsX#4584.
1 parent 6c279b1 commit 7fec711

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

Essentials/src/main/java/com/earth2me/essentials/Warps.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public boolean isEmpty() {
3838
return warpPoints.isEmpty();
3939
}
4040

41+
@Override
42+
public boolean isWarp(String name) {
43+
return warpPoints.containsKey(new StringIgnoreCase(name));
44+
}
45+
4146
@Override
4247
public Collection<String> getList() {
4348
final List<String> keys = new ArrayList<>();

Essentials/src/main/java/com/earth2me/essentials/api/IWarps.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public interface IWarps extends IConf {
2626
*/
2727
Location getWarp(String warp) throws WarpNotFoundException, net.ess3.api.InvalidWorldException;
2828

29+
/**
30+
* Checks if the provided name is a warp.
31+
*
32+
* @param name The warp name.
33+
* @return true if a warp by that name exists.
34+
*/
35+
boolean isWarp(String name);
36+
2937
/**
3038
* Gets a list of warps
3139
*

Essentials/src/main/java/com/earth2me/essentials/commands/Commanddelwarp.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ public void run(final Server server, final CommandSource sender, final String co
2323
throw new NotEnoughArgumentsException();
2424
}
2525
//Check if warp exists before calling the event
26-
final Location location = ess.getWarps().getWarp(args[0]);
27-
if (location != null) {
26+
if (ess.getWarps().isWarp(args[0])) {
27+
Location location;
28+
try {
29+
location = ess.getWarps().getWarp(args[0]);
30+
} catch (Exception ignored) {
31+
// World is unloaded/deleted
32+
location = null;
33+
}
2834
final WarpModifyEvent event = new WarpModifyEvent(sender.getUser(this.ess), args[0], location, null, WarpModifyEvent.WarpModifyCause.DELETE);
2935
Bukkit.getServer().getPluginManager().callEvent(event);
3036
if (event.isCancelled()) {

Essentials/src/main/java/net/essentialsx/api/v2/events/WarpModifyEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class WarpModifyEvent extends Event implements Cancellable {
2323
/**
2424
* @param user the {@link IUser} who is modifing the warp.
2525
* @param warpName the name of the warp that's being altered.
26-
* @param oldLocation the old location before being modified. Null if {@link WarpModifyCause#CREATE}.
26+
* @param oldLocation the old location before being modified. Null if {@link WarpModifyCause#CREATE} or if the previous location's world is not loaded.
2727
* @param newLocation the new location after being modified. Null if {@link WarpModifyCause#DELETE}.
2828
* @param cause the cause of change.
2929
*/
@@ -58,7 +58,7 @@ public String getWarpName() {
5858
}
5959

6060
/**
61-
* Gets the current location of the warp or null if it's being created.
61+
* Gets the current location of the warp or null if it's being created or if the previous location's world is not loaded.
6262
* @return The warps new location or null.
6363
*/
6464
public Location getOldLocation() {

0 commit comments

Comments
 (0)