Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converted "world unloads" to ScriptEvent
- Loading branch information
Showing
3 changed files
with
92 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/net/aufdemrand/denizen/events/world/WorldUnloadsScriptEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package net.aufdemrand.denizen.events.world; | ||
|
||
|
||
import net.aufdemrand.denizen.objects.dWorld; | ||
import net.aufdemrand.denizen.utilities.DenizenAPI; | ||
import net.aufdemrand.denizencore.events.ScriptEvent; | ||
import net.aufdemrand.denizencore.objects.dObject; | ||
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer; | ||
import net.aufdemrand.denizencore.utilities.CoreUtilities; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.world.WorldUnloadEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class WorldUnloadsScriptEvent extends ScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// world unloads | ||
// <world> unloads | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a world is unloaded. | ||
// | ||
// @Context | ||
// <context.world> returns the dWorld that was unloaded. | ||
// | ||
// --> | ||
|
||
public WorldUnloadsScriptEvent() { | ||
instance = this; | ||
} | ||
|
||
public static WorldUnloadsScriptEvent instance; | ||
public dWorld world; | ||
public WorldUnloadEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
return CoreUtilities.getXthArg(1,CoreUtilities.toLowerCase(s)).equals("unloads"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String wCheck = CoreUtilities.getXthArg(0,CoreUtilities.toLowerCase(s)); | ||
if (!wCheck.equals("world") && !wCheck.equals(CoreUtilities.toLowerCase(world.getName()))) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "WorldUnloads"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
WorldUnloadEvent.getHandlerList().unregister(this); | ||
} | ||
|
||
@Override | ||
public boolean applyDetermination(ScriptContainer container, String determination) { | ||
return super.applyDetermination(container, determination); | ||
} | ||
|
||
@Override | ||
public HashMap<String, dObject> getContext() { | ||
HashMap<String, dObject> context = super.getContext(); | ||
context.put("world", world); | ||
return context; | ||
} | ||
|
||
@EventHandler | ||
public void onWorldUnloads(WorldUnloadEvent event) { | ||
world = new dWorld(event.getWorld()); | ||
cancelled = event.isCancelled(); | ||
this.event = event; | ||
fire(); | ||
event.setCancelled(cancelled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters