Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paper-only client_options tag. #2619

Merged
merged 5 commits into from
Jun 3, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -26,6 +30,57 @@ public static void register() {
return new ElementTag(object.getPlayerEntity().getAffectsSpawning());
});

// <--[tag]
// @attribute <PlayerTag.client_options>
// @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("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);
if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_19)) {
map.putObject("text_filtering_enabled", new ElementTag(player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED)));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably merge this with the other isAtLeast(1.19) check

map.putObject("view_distance", new ElementTag(player.getClientOption(ClientOption.VIEW_DISTANCE)));
return map;
});

// <--[mechanism]
// @object PlayerTag
// @name affects_monster_spawning
Expand Down