/
BungeeProxyServerListPingScriptEvent.java
129 lines (111 loc) · 4.28 KB
/
BungeeProxyServerListPingScriptEvent.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package com.denizenscript.depenizen.bukkit.events.bungee;
import com.denizenscript.depenizen.bukkit.bungee.BungeeBridge;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.utilities.CoreUtilities;
public class BungeeProxyServerListPingScriptEvent extends BukkitScriptEvent {
// <--[event]
// @Events
// proxy server list ping
//
// @Regex ^on proxy server list ping$
//
// @Triggers when the bungeecord server is pinged and will return server details.
//
// @Context
// <context.address> returns the source address of the ping.
// <context.current_players> returns the number of players listed as currently online.
// <context.max_players> return the maximum number of players that can join according to the list.
// <context.motd> returns the server MOTD that will be displayed.
// <context.protocol> returns the protocol number that will be given to the ping requester.
// <context.version> returns the name of the server version that will be given to the ping requester.
//
// @Determine
// "MAX_PLAYERS:" + ElementTag(Number) to change the listed maximum number of players.
// "VERSION:" + ElementTag to change the listed server version.
// "MOTD:" + ElementTag to change the server MOTD that will be displayed.
//
// @Plugin Depenizen, BungeeCord
//
// -->
public BungeeProxyServerListPingScriptEvent() {
instance = this;
}
public static BungeeProxyServerListPingScriptEvent instance;
public String address;
public int currentPlayers;
public int maxPlayers;
public String motd;
public int protocol;
public String version;
@Override
public boolean couldMatch(ScriptPath path) {
if (!path.eventLower.startsWith("proxy server list ping")) {
return false;
}
return true;
}
@Override
public void init() {
BungeeBridge.instance.controlsProxyPing = true;
BungeeBridge.instance.checkBroadcastProxyPing();
}
@Override
public void destroy() {
BungeeBridge.instance.controlsProxyPing = false;
BungeeBridge.instance.checkBroadcastProxyPing();
}
@Override
public String getName() {
return "BungeeProxyServerListPing";
}
@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("max_players:")) {
maxPlayers = Integer.parseInt(determination.substring("max_players:".length()));
return true;
}
else if (determinationLow.startsWith("version:")) {
version = determination.substring("version:".length());
return true;
}
else if (determinationLow.startsWith("motd:")) {
motd = determination.substring("motd:".length());
return true;
}
}
return super.applyDetermination(path, determinationObj);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("address")) {
return new ElementTag(address);
}
else if (name.equals("num_players") || name.equals("current_players")) {
return new ElementTag(currentPlayers);
}
else if (name.equals("max_players")) {
return new ElementTag(maxPlayers);
}
else if (name.equals("motd")) {
return new ElementTag(motd);
}
else if (name.equals("protocol")) {
return new ElementTag(protocol);
}
else if (name.equals("version")) {
return new ElementTag(version);
}
return super.getContext(name);
}
}