-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
PlayerReceivesMessageScriptEvent.java
111 lines (96 loc) · 3.32 KB
/
PlayerReceivesMessageScriptEvent.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
106
107
108
109
110
111
package net.aufdemrand.denizen.events.player;
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.events.BukkitScriptEvent;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
public class PlayerReceivesMessageScriptEvent extends BukkitScriptEvent {
// <--[event]
// @Events
// player receives message
//
// @Regex ^on player receives message$
//
// @Cancellable true
//
// @Warning Using this will forcibly sync the chat thread.
//
// @Triggers when a player receives any chat message from the server.
//
// @Context
// <context.message> returns an Element of the message.
// <context.raw_json> returns an Element of the raw JSON used for the message.
// <context.system_message> returns true if the message is a system message (not player chat).
//
// @Determine
// "MESSAGE:" + Element to change the message.
// "RAW_JSON:" + Element to change the JSON used for the message.
//
// -->
public PlayerReceivesMessageScriptEvent() {
instance = this;
}
public static PlayerReceivesMessageScriptEvent instance;
public Element message;
public Element rawJson;
public Element system;
public dPlayer player;
public boolean messageModified;
public boolean rawJsonModified;
public boolean loaded;
@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
return CoreUtilities.toLowerCase(s).startsWith("player receives message");
}
@Override
public boolean matches(ScriptContainer scriptContainer, ScriptPath path) {
return true;
}
@Override
public String getName() {
return "PlayerReceivesMessage";
}
@Override
public void init() {
loaded = true;
}
@Override
public void destroy() {
loaded = false;
}
@Override
public boolean applyDetermination(ScriptContainer container, String determination) {
String lower = CoreUtilities.toLowerCase(determination);
if (lower.startsWith("message:")) {
message = new Element(determination.substring("message:".length()));
messageModified = true;
return true;
}
if (lower.startsWith("raw_json:")) {
rawJson = new Element(determination.substring("raw_json:".length()));
rawJsonModified = true;
return true;
}
return super.applyDetermination(container, determination);
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(player, null);
}
@Override
public dObject getContext(String name) {
if (name.equals("message")) {
return message;
}
if (name.equals("raw_json")) {
return rawJson;
}
if (name.equals("system_message")) {
return system;
}
return super.getContext(name);
}
}