From 259bdc2c94a298a2a0705a6e4af406aab53acf01 Mon Sep 17 00:00:00 2001 From: gnembon Date: Wed, 2 Dec 2020 22:36:20 -0400 Subject: [PATCH] ability to query client brand and server scarpet version. --- docs/scarpet/api/Auxiliary.md | 6 ++++-- docs/scarpet/api/Entities.md | 5 +++++ src/main/java/carpet/network/ServerNetworkHandler.java | 7 +++++++ src/main/java/carpet/script/utils/SystemInfo.java | 10 ++-------- src/main/java/carpet/script/value/EntityValue.java | 9 +++++++++ 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index e5e9209b..f759b4fd 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -500,7 +500,6 @@ Available options in the scarpet app space: * `game_version` - base version of the game Server related properties - * `server_motd` - the motd of the server visible when joining * `server_ip` - IP adress of the game hosted * `server_whitelisted` - boolean indicating whether the access to the server is only for whitelisted players @@ -516,4 +515,7 @@ Available options in the scarpet app space: * `java_version` - version of Java * `java_bits` - number indicating how many bits the Java has, 32 or 64 * `java_system_cpu_load` - current percentage of CPU used by the system - * `java_process_cpu_load` - current percentage of CPU used by JVM \ No newline at end of file + * `java_process_cpu_load` - current percentage of CPU used by JVM + + Scarpet related properties + * `scarpet_version` - returns the version of the carpet your scarpet comes with. \ No newline at end of file diff --git a/docs/scarpet/api/Entities.md b/docs/scarpet/api/Entities.md index a60d426c..e73c0697 100644 --- a/docs/scarpet/api/Entities.md +++ b/docs/scarpet/api/Entities.md @@ -366,6 +366,11 @@ Player's ping in milliseconds, or `null` if its not a player. Player's permission level, or `null` if not applicable for this entity. +### `query(e, 'client_brand')` + +Returns recognized type of client of the client connected. Possible results include `'vanilla'`, or `'carpet '` where +version indicates the version of the connected carpet client. + ### `query(e, 'effect', name?)` Without extra arguments, it returns list of effect active on a living entity. Each entry is a triple of short diff --git a/src/main/java/carpet/network/ServerNetworkHandler.java b/src/main/java/carpet/network/ServerNetworkHandler.java index 5971e93d..72ffc14f 100644 --- a/src/main/java/carpet/network/ServerNetworkHandler.java +++ b/src/main/java/carpet/network/ServerNetworkHandler.java @@ -217,6 +217,13 @@ public class ServerNetworkHandler } + public static String getPlayerStatus(ServerPlayerEntity player) + { + if (remoteCarpetPlayers.containsKey(player)) return "carpet "+remoteCarpetPlayers.get(player); + if (validCarpetPlayers.contains(player)) return "carpet "+CarpetSettings.carpetVersion; + return "vanilla"; + } + private static class DataBuilder { private CompoundTag tag; diff --git a/src/main/java/carpet/script/utils/SystemInfo.java b/src/main/java/carpet/script/utils/SystemInfo.java index 2dc048db..86b13735 100644 --- a/src/main/java/carpet/script/utils/SystemInfo.java +++ b/src/main/java/carpet/script/utils/SystemInfo.java @@ -1,6 +1,7 @@ package carpet.script.utils; import carpet.CarpetServer; +import carpet.CarpetSettings; import carpet.script.CarpetContext; import carpet.script.CarpetScriptHost; import carpet.script.value.ListValue; @@ -123,14 +124,7 @@ public class SystemInfo { }); return carpetRules; }); - - - - - - - - + put("scarpet_version", c -> StringValue.of(CarpetSettings.carpetVersion)); }}; public static Value get(String what, CarpetContext cc) diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index e1e6d897..cb6aa894 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -9,6 +9,7 @@ import carpet.fakes.MobEntityInterface; import carpet.fakes.HungerManagerInterface; import carpet.fakes.ServerPlayerInteractionManagerInterface; import carpet.helpers.Tracer; +import carpet.network.ServerNetworkHandler; import carpet.patches.EntityPlayerMPFake; import carpet.script.CarpetContext; import carpet.script.EntityEventsGroup; @@ -579,6 +580,14 @@ public class EntityValue extends Value return Value.NULL; }); + put("client_brand", (e, a) -> { + if (e instanceof ServerPlayerEntity) + { + return StringValue.of(ServerNetworkHandler.getPlayerStatus((ServerPlayerEntity) e)); + } + return Value.NULL; + }); + put("team", (e, a) -> e.getScoreboardTeam()==null?Value.NULL:new StringValue(e.getScoreboardTeam().getName())); put("ping", (e, a) -> {