diff --git a/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperPlayerExtensions.java b/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperPlayerExtensions.java index fba2df72d6..be56152901 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperPlayerExtensions.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperPlayerExtensions.java @@ -6,8 +6,12 @@ import com.denizenscript.denizen.objects.PlayerTag; import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.objects.core.ListTag; +import com.denizenscript.denizencore.objects.core.MapTag; +import com.destroystokyo.paper.ClientOption; +import com.destroystokyo.paper.SkinParts; import net.kyori.adventure.util.TriState; import org.bukkit.Material; +import org.bukkit.entity.Player; public class PaperPlayerExtensions { @@ -26,6 +30,55 @@ public static void register() { return new ElementTag(object.getPlayerEntity().getAffectsSpawning()); }); + // <--[tag] + // @attribute + // @returns MapTag + // @group paper + // @Plugin Paper + // @description + // Returns the player's client options. + // The output map contains the following keys: + // - 'allow_server_listings' (ElementTag(Boolean)): whether the player allows server listings. Available only on MC 1.19+. + // - 'chat_colors_enabled' (ElementTag(Boolean)): whether the player has chat colors enabled. + // - 'chat_visibility' (ElementTag): the player's current chat visibility option. Possible output values are: FULL, SYSTEM, HIDDEN, and UNKNOWN. + // - 'locale' (ElementTag): the player's current locale. + // - 'main_hand' (ElementTag): the player's main hand, either LEFT or RIGHT. + // - 'skin_parts' (MapTag): which skin parts the player has enabled. The output map contains the following keys: + // - 'cape' (ElementTag(Boolean)): whether the player's cape is enabled. + // - 'hat' (ElementTag(Boolean)): whether the player's hat is enabled. + // - 'jacket' (ElementTag(Boolean)): whether the player's jacket is enabled. + // - 'left_sleeve' (ElementTag(Boolean)): whether the player's left sleeve is enabled. + // - 'right_sleeve' (ElementTag(Boolean)): whether the player's right sleeve is enabled. + // - 'left_pants' (ElementTag(Boolean)): whether the player's left pants is enabled. + // - 'right_pants' (ElementTag(Boolean)): whether the player's right pants is enabled. + // - 'text_filtering_enabled' (ElementTag(Boolean)): whether the player has text filtering enabled. Available only on MC 1.19+. + // - 'view_distance' (ElementTag(Number)): the player's current view distance. + // --> + PlayerTag.registerOnlineOnlyTag(MapTag.class, "client_options", (attribute, object) -> { + MapTag map = new MapTag(); + Player player = object.getPlayerEntity(); + if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) { + map.putObject("allow_server_listings", new ElementTag(player.getClientOption(ClientOption.ALLOW_SERVER_LISTINGS))); + map.putObject("text_filtering_enabled", new ElementTag(player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED))); + } + map.putObject("chat_colors_enabled", new ElementTag(player.getClientOption(ClientOption.CHAT_COLORS_ENABLED))); + map.putObject("chat_visibility", new ElementTag(player.getClientOption(ClientOption.CHAT_VISIBILITY))); + map.putObject("locale", new ElementTag(player.getClientOption(ClientOption.LOCALE))); + map.putObject("main_hand", new ElementTag(player.getClientOption(ClientOption.MAIN_HAND))); + MapTag skinParts = new MapTag(); + SkinParts parts = player.getClientOption(ClientOption.SKIN_PARTS); + skinParts.putObject("cape", new ElementTag(parts.hasCapeEnabled())); + skinParts.putObject("hat", new ElementTag(parts.hasHatsEnabled())); + skinParts.putObject("jacket", new ElementTag(parts.hasJacketEnabled())); + skinParts.putObject("left_sleeve", new ElementTag(parts.hasLeftSleeveEnabled())); + skinParts.putObject("right_sleeve", new ElementTag(parts.hasRightSleeveEnabled())); + skinParts.putObject("left_pants", new ElementTag(parts.hasLeftPantsEnabled())); + skinParts.putObject("right_pants", new ElementTag(parts.hasRightPantsEnabled())); + map.putObject("skin_parts", skinParts); + map.putObject("view_distance", new ElementTag(player.getClientOption(ClientOption.VIEW_DISTANCE))); + return map; + }); + // <--[mechanism] // @object PlayerTag // @name affects_monster_spawning