-
-
Notifications
You must be signed in to change notification settings - Fork 102
/
ChunkLoadScriptEvent.java
89 lines (75 loc) · 2.89 KB
/
ChunkLoadScriptEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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();
}
}