-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
TickScriptEvent.java
70 lines (58 loc) · 1.77 KB
/
TickScriptEvent.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
package com.denizenscript.denizencore.events.core;
import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
public class TickScriptEvent extends ScriptEvent {
// <--[event]
// @Events
// tick
//
// @Switch every:<count> to only run the event every *count* times (like "every:5" for every 5 ticks).
//
// @Group Core
//
// @Warning This event fires very rapidly and is usually not the most ideal way to handle things. Generally, prefer <@link event delta time>.
//
// @Triggers every single tick.
//
// @Context
// <context.tick> how many ticks have passed since the server started.
//
// -->
public static TickScriptEvent instance;
public TickScriptEvent() {
instance = this;
registerCouldMatcher("tick");
registerSwitches("every");
}
public long ticks = 0;
@Override
public ObjectTag getContext(String name) {
if (name.equals("tick")) {
return new ElementTag(ticks);
}
return super.getContext(name);
}
@Override
public boolean matches(ScriptPath path) {
String countString = path.switches.get("every");
int count = countString == null ? 1 : Integer.parseInt(countString);
if (ticks % count != 0) {
return false;
}
return super.matches(path);
}
@Override
public String getName() {
return "Tick";
}
public boolean enabled = false;
@Override
public void init() {
enabled = true;
}
@Override
public void destroy() {
enabled = false;
}
}