/
MythicKeysKeyPressScriptEvent.java
78 lines (68 loc) · 2.28 KB
/
MythicKeysKeyPressScriptEvent.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
package com.denizenscript.depenizen.bukkit.events.mythickeys;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import eu.asangarin.mythickeys.api.MythicKeyPressEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class MythicKeysKeyPressScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// mythickeys key pressed
//
// @Location true
//
// @Switch id:<id> to only process the event if the key ID matches the given text matcher.
//
// @Triggers When a key is pressed by a client running MythicKeys, if that key is in the MythicKeys config.
//
// @Context
// <context.id> Returns the ID of the key that was pressed according to the MythicKeys config, as a namespaced key.
//
// @Player Always.
//
// @Plugin Depenizen, MythicKeys
//
// @Group Depenizen
//
// -->
public MythicKeysKeyPressScriptEvent() {
instance = this;
registerCouldMatcher("mythickeys key pressed");
registerSwitches("id");
}
public static MythicKeysKeyPressScriptEvent instance;
public MythicKeyPressEvent event;
@Override
public boolean matches(ScriptPath path) {
if (!runGenericSwitchCheck(path, "id", String.valueOf(event.getId()))) {
return false;
}
if (!runInCheck(path, event.getPlayer().getLocation())) {
return false;
}
return super.matches(path);
}
@Override
public String getName() {
return "MythicKeysKeyPressed";
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(event.getPlayer());
}
@Override
public ObjectTag getContext(String name) {
switch (name) {
case "id": return new ElementTag(event.getId().toString());
}
return super.getContext(name);
}
@EventHandler
public void onKeyPress(MythicKeyPressEvent event) {
this.event = event;
fire(event);
}
}