-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
BungeeProxyServerCommandScriptEvent.java
111 lines (95 loc) · 3.34 KB
/
BungeeProxyServerCommandScriptEvent.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 com.denizenscript.depenizen.bukkit.events.bungee;
import com.denizenscript.denizen.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.depenizen.bukkit.bungee.BungeeBridge;
public class BungeeProxyServerCommandScriptEvent extends BukkitScriptEvent {
// <--[event]
// @Events
// proxy server command
// proxy server (<command>) command
//
// @Regex ^on proxy server( [^\s]+)? command$
//
// @Triggers when a player runs a command on the bungee proxy server.
//
// @Cancellable true
//
// @Context
// <context.sender> returns the name of the command sender.
// <context.command> returns the command executed.
//
// @Determine
// "COMMAND:" + Element to change the command that will be ran.
//
// -->
public BungeeProxyServerCommandScriptEvent() {
instance = this;
}
public static BungeeProxyServerCommandScriptEvent instance;
public String sender;
public String command;
@Override
public boolean couldMatch(ScriptPath path) {
if (!path.eventLower.startsWith("proxy server ")) {
return false;
}
if (!path.eventArgLowerAt(2).equals("command") && !path.eventArgLowerAt(3).equals("command")) {
return false;
}
return true;
}
public String commandName() {
return CoreUtilities.toLowerCase(command.substring(1, command.contains(" ") ? command.indexOf(' ') : command.length()));
}
@Override
public boolean matches(ScriptPath path) {
if (!path.eventArgLowerAt(2).equals("command") && !path.eventArgLowerAt(2).equals(commandName())) {
return false;
}
return true;
}
@Override
public void init() {
BungeeBridge.instance.controlsProxyCommand = true;
BungeeBridge.instance.checkBroadcastProxyCommand();
}
@Override
public void destroy() {
BungeeBridge.instance.controlsProxyCommand = false;
BungeeBridge.instance.checkBroadcastProxyCommand();
}
@Override
public String getName() {
return "BungeeProxyServerCommand";
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(null, null);
}
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag) {
String determination = determinationObj.toString();
String determinationLow = CoreUtilities.toLowerCase(determination);
if (determinationLow.startsWith("command:")) {
command = determination.substring("command:".length());
return true;
}
}
return super.applyDetermination(path, determinationObj);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("sender")) {
return new ElementTag(sender);
}
else if (name.equals("command")) {
return new ElementTag(command);
}
return super.getContext(name);
}
}