Skip to content

Commit

Permalink
Add <context.hostname> to the server list ping event. (#2597)
Browse files Browse the repository at this point in the history
* Adds the hostname context

* Update ListPingScriptEvent.java

* Update ListPingScriptEvent.java
  • Loading branch information
heypr committed Feb 19, 2024
1 parent 557d3fc commit c58fdfe
Showing 1 changed file with 4 additions and 0 deletions.
Expand Up @@ -2,6 +2,8 @@

import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.nms.NMSVersion;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.objects.core.ElementTag;
Expand Down Expand Up @@ -34,6 +36,7 @@ public class ListPingScriptEvent extends BukkitScriptEvent implements Listener {
// <context.max_players> returns the number of max players that will show.
// <context.num_players> returns the number of online players that will show.
// <context.address> returns the IP address requesting the list.
// <context.hostname> returns an ElementTag of the server address that is being pinged. Available only on MC 1.19+.
// <context.protocol_version> returns the protocol ID of the server's version (only on Paper).
// <context.version_name> returns the name of the server's version (only on Paper).
// <context.client_protocol_version> returns the client's protocol version ID (only on Paper).
Expand Down Expand Up @@ -118,6 +121,7 @@ public ObjectTag getContext(String name) {
case "max_players" -> new ElementTag(event.getMaxPlayers());
case "num_players" -> new ElementTag(event.getNumPlayers());
case "address" -> new ElementTag(event.getAddress().toString());
case "hostname" -> NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19) ? new ElementTag(event.getHostname(), true) : null;
default -> super.getContext(name);
};
}
Expand Down

0 comments on commit c58fdfe

Please sign in to comment.