-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
ScriptGeneratesErrorScriptEvent.java
105 lines (93 loc) · 3.2 KB
/
ScriptGeneratesErrorScriptEvent.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.denizenscript.denizencore.events.core;
import com.denizenscript.denizencore.DenizenCore;
import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.QueueTag;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.scripts.queues.ScriptQueue;
public class ScriptGeneratesErrorScriptEvent extends ScriptEvent {
// <--[event]
// @Events
// script generates error
//
// @Regex ^on script generates error$
//
// @Group Core
//
// @Cancellable true
//
// @Warning Abusing this event can cause significant failures in the Denizen debug system. Use only with extreme caution.
//
// @Triggers when a script generates an error.
//
// @Context
// <context.message> returns the error message.
// <context.queue> returns the queue that caused the error, if any.
// <context.script> returns the script that caused the error, if any.
// <context.line> returns the line number within the script file that caused the error, if any.
//
// -->
public static ScriptGeneratesErrorScriptEvent instance;
public ScriptGeneratesErrorScriptEvent() {
instance = this;
}
public ScriptQueue queue;
public String message;
public int line;
public ScriptTag script;
public static boolean cancelledTracker = false;
@Override
public ScriptEntryData getScriptEntryData() {
if (queue != null && queue.getLastEntryExecuted() != null) {
return queue.getLastEntryExecuted().entryData;
}
return DenizenCore.implementation.getEmptyScriptEntryData();
}
@Override
public ObjectTag getContext(String name) {
switch (name) {
case "message":
return new ElementTag(message);
case "script":
return script;
case "line":
if (line != -1) {
return new ElementTag(line);
}
break;
case "queue":
if (queue != null) {
return new QueueTag(queue);
}
break;
}
return super.getContext(name);
}
@Override
public boolean couldMatch(ScriptPath path) {
if (!path.eventLower.startsWith("script generates error")) {
return false;
}
return true;
}
@Override
public void cancellationChanged() {
cancelledTracker = cancelled;
super.cancellationChanged();
}
@Override
public String getName() {
return "ScriptGeneratesError";
}
public boolean handle(String message, ScriptQueue queue, ScriptTag script, int line) {
this.queue = queue;
this.message = message;
this.line = line;
this.script = script;
cancelledTracker = false;
fire();
return cancelledTracker;
}
}