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 loads" event in new ScriptEvent format.
- Loading branch information
Showing
3 changed files
with
90 additions
and
88 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
87 changes: 0 additions & 87 deletions
87
src/main/java/net/aufdemrand/denizen/events/core/ChunkLoadSmartEvent.java
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
src/main/java/net/aufdemrand/denizen/events/scriptevents/ChunkLoadScriptEvent.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,89 @@ | ||
package net.aufdemrand.denizen.events.scriptevents; | ||
|
||
import net.aufdemrand.denizen.objects.dChunk; | ||
import net.aufdemrand.denizen.objects.dWorld; // Deprecated in favor of context.chunk.world | ||
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.ChunkLoadEvent; | ||
|
||
import java.util.HashMap; | ||
|
||
public class ChunkLoadScriptEvent extends ScriptEvent implements Listener { | ||
|
||
// <--[event] | ||
// @Events | ||
// chunk loads for the first time (in <world>) | ||
// | ||
// @Warning This event will fire *extremely* rapidly and often! | ||
// | ||
// @Triggers when a new chunk is loaded | ||
// | ||
// @Context | ||
// <context.chunk> returns the loading chunk. | ||
// | ||
// --> | ||
|
||
public ChunkLoadScriptEvent() { | ||
instance = this; | ||
} | ||
public static ChunkLoadScriptEvent instance; | ||
public dChunk chunk; | ||
public dWorld world; // Deprecated in favor of context.chunk.world | ||
public ChunkLoadEvent event; | ||
|
||
@Override | ||
public boolean couldMatch(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
return lower.startsWith("chunk loads"); | ||
} | ||
|
||
@Override | ||
public boolean matches(ScriptContainer scriptContainer, String s) { | ||
String lower = CoreUtilities.toLowerCase(s); | ||
return lower.equals("chunk loads for the first time") | ||
|| lower.equals("chunk loads for the first time in " + dWorld.mirrorBukkitWorld(event.getWorld()).getName().toLowerCase()); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "ChunkLoads"; | ||
} | ||
|
||
@Override | ||
public void init() { | ||
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance()); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
ChunkLoadEvent.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 onChunkLoad(ChunkLoadEvent event) { | ||
chunk = new dChunk(event.getChunk()); | ||
world = new dWorld(event.getWorld()); // Deprecated in favor of context.chunk.world | ||
this.event = event; | ||
fire(); | ||
} | ||
} |