Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrote "on chunk unloads" event in new ScriptEvent format.
- Loading branch information
Showing
3 changed files
with
94 additions
and
91 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
90 changes: 0 additions & 90 deletions
90
src/main/java/net/aufdemrand/denizen/events/core/ChunkUnloadSmartEvent.java
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
src/main/java/net/aufdemrand/denizen/events/scriptevents/ChunkUnloadScriptEvent.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,93 @@ | ||
package net.aufdemrand.denizen.events.scriptevents; | ||
|
||
import net.aufdemrand.denizen.objects.dChunk; | ||
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.ChunkUnloadEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class ChunkUnloadScriptEvent extends ScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// chunk unloads (in <world>) | ||
// | ||
// @Warning This event will fire *extremely* rapidly and often! | ||
// | ||
// @Cancellable true | ||
// | ||
// @Triggers when a chunk is unloaded | ||
// | ||
// @Context | ||
// <context.chunk> returns the loading chunk. | ||
// | ||
// --> | ||
|
||
public ChunkUnloadScriptEvent() { | ||
instance = this; | ||
} | ||
public static ChunkUnloadScriptEvent instance; | ||
public dChunk chunk; | ||
public dWorld world; // Deprecated in favor of context.chunk.world | ||
public ChunkUnloadEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
return lower.startsWith("chunk unloads"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
return lower.equals("chunk unloads") | ||
|| lower.equals("chunk unloads in " + dWorld.mirrorBukkitWorld(event.getWorld()).getName().toLowerCase()); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "ChunkUnloads"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
ChunkUnloadEvent.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("chunk", chunk); | ||
context.put("world", world); // Deprecated in favor of context.chunk.world | ||
return context; | ||
} | ||
|
||
@EventHandler | ||
public void onChunkUnload(ChunkUnloadEvent event) { | ||
chunk = new dChunk(event.getChunk()); | ||
world = new dWorld(event.getWorld()); // Deprecated in favor of context.chunk.world | ||
cancelled = event.isCancelled(); | ||
this.event = event; | ||
fire(); | ||
event.setCancelled(cancelled); | ||
} | ||
} |