Added MVWorldDeleteEvent.

This commit is contained in:
main() 2011-12-19 20:48:14 +01:00
parent 251b66a8d0
commit 2721419324
2 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,61 @@
package com.onarandombox.MultiverseCore.event;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
/**
* Called when a world is about to be deleted by Multiverse.
*/
public class MVWorldDeleteEvent extends Event implements Cancellable {
private boolean cancelled = false;
private final MultiverseWorld world;
private final boolean removeFromConfig;
public MVWorldDeleteEvent(MultiverseWorld world, boolean removeFromConfig) {
super("MVWorldDeleteEvent");
if (world == null)
throw new IllegalArgumentException("world can't be null!");
this.world = world;
this.removeFromConfig = removeFromConfig;
}
/**
* {@inheritDoc}
*/
@Override
public boolean isCancelled() {
return cancelled;
}
/**
* {@inheritDoc}
*/
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
/**
* Gets the world that's about to be deleted.
*
* @return That {@link MultiverseWorld}.
*/
public MultiverseWorld getWorld() {
return world;
}
/**
* Is the world about to be removed from the config?
*
* @return True if yes, false if no.
*/
public boolean removeWorldFromConfig() {
return removeFromConfig;
}
}

View File

@ -11,6 +11,8 @@ import com.onarandombox.MultiverseCore.MVWorld;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVWorldManager;
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
@ -258,6 +260,15 @@ public class WorldManager implements MVWorldManager {
// We can only delete loaded worlds
return false;
}
// call the event!
MVWorldDeleteEvent mvwde = new MVWorldDeleteEvent(getMVWorld(name), removeFromConfig);
this.plugin.getServer().getPluginManager().callEvent(mvwde);
if (mvwde.isCancelled()) {
this.plugin.log(Level.FINE, "Tried to delete a world, but the event was cancelled!");
return false;
}
if (removeFromConfig) {
if (!removeWorldFromConfig(name)) {
return false;