-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
ServerListPingScriptEventPaperImpl.java
45 lines (40 loc) · 1.97 KB
/
ServerListPingScriptEventPaperImpl.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
package com.denizenscript.denizen.paper.events;
import com.denizenscript.denizen.events.server.ListPingScriptEvent;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import org.bukkit.event.EventHandler;
public class ServerListPingScriptEventPaperImpl extends ListPingScriptEvent {
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (!isDefaultDetermination(determinationObj)) {
String determination = determinationObj.toString();
String lower = CoreUtilities.toLowerCase(determination);
if (lower.startsWith("protocol_version:") && ArgumentHelper.matchesInteger(determination.substring("protocol_version:".length()))) {
((PaperServerListPingEvent) event).setProtocolVersion(Integer.parseInt(determination.substring("protocol_version:".length())));
return true;
}
else if (lower.startsWith("version_name:")) {
((PaperServerListPingEvent) event).setVersion(determination.substring("version_name:".length()));
return true;
}
}
return super.applyDetermination(path, determinationObj);
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("protocol_version")) {
return new ElementTag(((PaperServerListPingEvent) event).getProtocolVersion());
}
else if (name.equals("version_name")) {
return new ElementTag(((PaperServerListPingEvent) event).getVersion());
}
return super.getContext(name);
}
@EventHandler
public void onListPing(PaperServerListPingEvent event) {
syncFire(event);
}
}