Fix ability to delete warps in unloaded worlds (#4590)

Fixes #4584.
This commit is contained in:
Josh Roy 2021-10-24 10:05:10 -04:00 committed by GitHub
parent edd15132fd
commit 494e82e581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 4 deletions

View File

@ -38,6 +38,11 @@ public class Warps implements IConf, net.ess3.api.IWarps {
return warpPoints.isEmpty();
}
@Override
public boolean isWarp(String name) {
return warpPoints.containsKey(new StringIgnoreCase(name));
}
@Override
public Collection<String> getList() {
final List<String> keys = new ArrayList<>();

View File

@ -26,6 +26,14 @@ public interface IWarps extends IConf {
*/
Location getWarp(String warp) throws WarpNotFoundException, net.ess3.api.InvalidWorldException;
/**
* Checks if the provided name is a warp.
*
* @param name The warp name.
* @return true if a warp by that name exists.
*/
boolean isWarp(String name);
/**
* Gets a list of warps
*

View File

@ -23,8 +23,14 @@ public class Commanddelwarp extends EssentialsCommand {
throw new NotEnoughArgumentsException();
}
//Check if warp exists before calling the event
final Location location = ess.getWarps().getWarp(args[0]);
if (location != null) {
if (ess.getWarps().isWarp(args[0])) {
Location location;
try {
location = ess.getWarps().getWarp(args[0]);
} catch (Exception ignored) {
// World is unloaded/deleted
location = null;
}
final WarpModifyEvent event = new WarpModifyEvent(sender.getUser(this.ess), args[0], location, null, WarpModifyEvent.WarpModifyCause.DELETE);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {

View File

@ -23,7 +23,7 @@ public class WarpModifyEvent extends Event implements Cancellable {
/**
* @param user the {@link IUser} who is modifing the warp.
* @param warpName the name of the warp that's being altered.
* @param oldLocation the old location before being modified. Null if {@link WarpModifyCause#CREATE}.
* @param oldLocation the old location before being modified. Null if {@link WarpModifyCause#CREATE} or if the previous location's world is not loaded.
* @param newLocation the new location after being modified. Null if {@link WarpModifyCause#DELETE}.
* @param cause the cause of change.
*/
@ -58,7 +58,7 @@ public class WarpModifyEvent extends Event implements Cancellable {
}
/**
* Gets the current location of the warp or null if it's being created.
* Gets the current location of the warp or null if it's being created or if the previous location's world is not loaded.
* @return The warps new location or null.
*/
public Location getOldLocation() {