Paper/patches/api/0188-Add-Player-Client-Options-API.patch

251 Zeilen
8.8 KiB
Diff

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2021-11-27 09:11:43 +01:00
From: MiniDigger <admin@benndorf.dev>
2021-06-11 14:02:28 +02:00
Date: Mon, 20 Jan 2020 21:38:34 +0100
Subject: [PATCH] Add Player Client Options API
diff --git a/src/main/java/com/destroystokyo/paper/ClientOption.java b/src/main/java/com/destroystokyo/paper/ClientOption.java
new file mode 100644
index 0000000000000000000000000000000000000000..f89bfeba29e6988db849957a508ca97ff5322242
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/ClientOption.java
@@ -0,0 +1,52 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper;
+
+import net.kyori.adventure.translation.Translatable;
+import net.kyori.adventure.util.Index;
2021-06-11 14:02:28 +02:00
+import org.jetbrains.annotations.NotNull;
+
+import org.bukkit.inventory.MainHand;
+
+public final class ClientOption<T> {
+
+ public static final ClientOption<SkinParts> SKIN_PARTS = new ClientOption<>(SkinParts.class);
+ public static final ClientOption<Boolean> CHAT_COLORS_ENABLED = new ClientOption<>(Boolean.class);
+ public static final ClientOption<ChatVisibility> CHAT_VISIBILITY = new ClientOption<>(ChatVisibility.class);
+ public static final ClientOption<String> LOCALE = new ClientOption<>(String.class);
+ public static final ClientOption<MainHand> MAIN_HAND = new ClientOption<>(MainHand.class);
+ public static final ClientOption<Integer> VIEW_DISTANCE = new ClientOption<>(Integer.class);
+ public static final ClientOption<Boolean> ALLOW_SERVER_LISTINGS = new ClientOption<>(Boolean.class);
+ public static final ClientOption<Boolean> TEXT_FILTERING_ENABLED = new ClientOption<>(Boolean.class);
2021-06-11 14:02:28 +02:00
+
+ private final Class<T> type;
+
+ private ClientOption(@NotNull Class<T> type) {
+ this.type = type;
+ }
+
+ @NotNull
+ public Class<T> getType() {
+ return type;
+ }
+
+ public enum ChatVisibility implements Translatable {
+ FULL("full"),
+ SYSTEM("system"),
+ HIDDEN("hidden"),
+ UNKNOWN("unknown");
+
+ public static Index<String, ChatVisibility> NAMES = Index.create(ChatVisibility.class, chatVisibility -> chatVisibility.name);
+ private final String name;
+
+ ChatVisibility(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public @NotNull String translationKey() {
+ if (this == UNKNOWN) {
+ throw new UnsupportedOperationException(this.name + " doesn't have a translation key");
+ }
+ return "options.chat.visibility." + this.name;
+ }
2021-06-11 14:02:28 +02:00
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/SkinParts.java b/src/main/java/com/destroystokyo/paper/SkinParts.java
new file mode 100644
index 0000000000000000000000000000000000000000..4a0c39405d4fbed457787e3c6ded4cc6591bc8c2
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/SkinParts.java
@@ -0,0 +1,20 @@
+package com.destroystokyo.paper;
+
+public interface SkinParts {
+
+ boolean hasCapeEnabled();
+
+ boolean hasJacketEnabled();
+
+ boolean hasLeftSleeveEnabled();
+
+ boolean hasRightSleeveEnabled();
+
+ boolean hasLeftPantsEnabled();
+
+ boolean hasRightPantsEnabled();
+
+ boolean hasHatsEnabled();
+
+ int getRaw();
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java
new file mode 100644
2024-02-01 10:15:57 +01:00
index 0000000000000000000000000000000000000000..1757055d821d9ec7c728aa6c1b52fa6aea591ae5
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java
2024-02-01 10:15:57 +01:00
@@ -0,0 +1,136 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper.event.player;
+
+import com.destroystokyo.paper.ClientOption;
+import com.destroystokyo.paper.ClientOption.ChatVisibility;
+import com.destroystokyo.paper.SkinParts;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.inventory.MainHand;
2024-02-01 10:15:57 +01:00
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Map;
2021-06-11 14:02:28 +02:00
+
+/**
+ * Called when the player changes their client settings
2021-06-11 14:02:28 +02:00
+ */
+public class PlayerClientOptionsChangeEvent extends PlayerEvent {
+
2024-02-01 10:15:57 +01:00
+ private static final HandlerList HANDLER_LIST = new HandlerList();
2021-06-11 14:02:28 +02:00
+
+ private final String locale;
+ private final int viewDistance;
+ private final ChatVisibility chatVisibility;
+ private final boolean chatColors;
+ private final SkinParts skinparts;
+ private final MainHand mainHand;
+ private final boolean allowsServerListings;
+ private final boolean textFilteringEnabled;
2021-06-11 14:02:28 +02:00
+
+ @Deprecated
2021-06-11 14:02:28 +02:00
+ public PlayerClientOptionsChangeEvent(@NotNull Player player, @NotNull String locale, int viewDistance, @NotNull ChatVisibility chatVisibility, boolean chatColors, @NotNull SkinParts skinParts, @NotNull MainHand mainHand) {
+ super(player);
+ this.locale = locale;
+ this.viewDistance = viewDistance;
+ this.chatVisibility = chatVisibility;
+ this.chatColors = chatColors;
+ this.skinparts = skinParts;
+ this.mainHand = mainHand;
+ this.allowsServerListings = false;
+ this.textFilteringEnabled = false;
+ }
+
2024-02-01 10:15:57 +01:00
+ @ApiStatus.Internal
+ public PlayerClientOptionsChangeEvent(@NotNull Player player, @NotNull Map<ClientOption<?>, ?> options) {
+ super(player);
+
+ this.locale = (String) options.get(ClientOption.LOCALE);
+ this.viewDistance = (int) options.get(ClientOption.VIEW_DISTANCE);
+ this.chatVisibility = (ChatVisibility) options.get(ClientOption.CHAT_VISIBILITY);
+ this.chatColors = (boolean) options.get(ClientOption.CHAT_COLORS_ENABLED);
+ this.skinparts = (SkinParts) options.get(ClientOption.SKIN_PARTS);
+ this.mainHand = (MainHand) options.get(ClientOption.MAIN_HAND);
+ this.allowsServerListings = (boolean) options.get(ClientOption.ALLOW_SERVER_LISTINGS);
+ this.textFilteringEnabled = (boolean) options.get(ClientOption.TEXT_FILTERING_ENABLED);
2021-06-11 14:02:28 +02:00
+ }
+
+ @NotNull
+ public String getLocale() {
2024-02-01 10:15:57 +01:00
+ return this.locale;
2021-06-11 14:02:28 +02:00
+ }
+
+ public boolean hasLocaleChanged() {
2024-02-01 10:15:57 +01:00
+ return !this.locale.equals(this.player.getClientOption(ClientOption.LOCALE));
2021-06-11 14:02:28 +02:00
+ }
+
+ public int getViewDistance() {
2024-02-01 10:15:57 +01:00
+ return this.viewDistance;
2021-06-11 14:02:28 +02:00
+ }
+
+ public boolean hasViewDistanceChanged() {
2024-02-01 10:15:57 +01:00
+ return this.viewDistance != this.player.getClientOption(ClientOption.VIEW_DISTANCE);
2021-06-11 14:02:28 +02:00
+ }
+
+ @NotNull
+ public ChatVisibility getChatVisibility() {
2024-02-01 10:15:57 +01:00
+ return this.chatVisibility;
2021-06-11 14:02:28 +02:00
+ }
+
+ public boolean hasChatVisibilityChanged() {
2024-02-01 10:15:57 +01:00
+ return this.chatVisibility != this.player.getClientOption(ClientOption.CHAT_VISIBILITY);
2021-06-11 14:02:28 +02:00
+ }
+
+ public boolean hasChatColorsEnabled() {
2024-02-01 10:15:57 +01:00
+ return this.chatColors;
2021-06-11 14:02:28 +02:00
+ }
+
+ public boolean hasChatColorsEnabledChanged() {
2024-02-01 10:15:57 +01:00
+ return this.chatColors != this.player.getClientOption(ClientOption.CHAT_COLORS_ENABLED);
2021-06-11 14:02:28 +02:00
+ }
+
+ @NotNull
+ public SkinParts getSkinParts() {
2024-02-01 10:15:57 +01:00
+ return this.skinparts;
2021-06-11 14:02:28 +02:00
+ }
+
+ public boolean hasSkinPartsChanged() {
2024-02-01 10:15:57 +01:00
+ return this.skinparts.getRaw() != this.player.getClientOption(ClientOption.SKIN_PARTS).getRaw();
2021-06-11 14:02:28 +02:00
+ }
+
+ @NotNull
+ public MainHand getMainHand() {
2024-02-01 10:15:57 +01:00
+ return this.mainHand;
2021-06-11 14:02:28 +02:00
+ }
+
+ public boolean hasMainHandChanged() {
2024-02-01 10:15:57 +01:00
+ return this.mainHand != this.player.getClientOption(ClientOption.MAIN_HAND);
2021-06-11 14:02:28 +02:00
+ }
+
+ public boolean allowsServerListings() {
2024-02-01 10:15:57 +01:00
+ return this.allowsServerListings;
+ }
+
+ public boolean hasAllowServerListingsChanged() {
2024-02-01 10:15:57 +01:00
+ return this.allowsServerListings != this.player.getClientOption(ClientOption.ALLOW_SERVER_LISTINGS);
+ }
+
+ public boolean hasTextFilteringEnabled() {
2024-02-01 10:15:57 +01:00
+ return this.textFilteringEnabled;
+ }
+
+ public boolean hasTextFilteringChanged() {
2024-02-01 10:15:57 +01:00
+ return this.textFilteringEnabled != this.player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED);
+ }
+
2021-06-11 14:02:28 +02:00
+ @Override
+ @NotNull
+ public HandlerList getHandlers() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
2024-02-01 10:15:57 +01:00
+ return HANDLER_LIST;
2021-06-11 14:02:28 +02:00
+ }
+}
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
Update upstream (Bukkit/CraftBukkit/Spigot) (#10875) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 376e37db SPIGOT-7677: Update which entities are marked as spawnable 06c4add3 SPIGOT-7737: Add separate TreeType.MEGA_PINE 19b7caaa SPIGOT-7731: Spawn eggs cannot have damage e585297e PR-1022: Add force option to Player#spawnParticle d26e0094 PR-1018: Add methods to get players seeing specific chunks 8df1ed18 PR-978: Add Material#isCompostable and Material#getCompostChance 4b9b59c7 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale 8d1e700a PR-1020: Cast instead of using #typed when getting BlockType and ItemType to better work with testing / mocks fa28607a PR-1016: Fix incorrect assumption of Fireball having constant speed 4c6c8586 PR-1015: Add a tool component to ItemMeta 6f6b2123 PR-1014: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects f511cfe1 PR-1013, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType def44cbf SPIGOT-7669: Fix typo in ProjectileHitEvent#getHitBlockFace documentation 53fa4f72 PR-1011: Throw an exception if a RecipeChoice is ever supplied air CraftBukkit Changes: ee95e171a SPIGOT-7737: Add separate TreeType.MEGA_PINE 0dae4c62c Fix spawn egg equality check and copy constructor ab59e847c Fix spawn eggs with no entity creating invalid stacks and disconnect creative clients 3b6093b28 SPIGOT-7736: Creative spawn egg use loses components c6b4d5a87 SPIGOT-7731: Spawn eggs cannot have damage 340ccd57f SPIGOT-7735: Fix serialization of player heads with note block sound fd2f41834 SPIGOT-7734: Can't register a custom advancement using unsafe() 02456e2a5 PR-1413: Add force option to Player#spawnParticle 6a61f38b2 SPIGOT-7680: Per-world weather command 58c41cebb PR-1409: Add methods to get players seeing specific chunks 16c976797 PR-1412: Fix shipwreck loot tables not being set for BlockTransformers 7189ba636 PR-1360: Add Material#isCompostable and Material#getCompostChance 900384556 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale bdb40c5f1 Increase outdated build delay d6607c7dd SPIGOT-7675: Fix FoodComponent config deserialization b148ed332 PR-1406: Fix incorrect assumption of Fireball having constant speed 3ec31ca75 PR-1405: Add a tool component to ItemMeta 5d7d675b9 PR-1404: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects 960827981 PR-1403, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType 94e44ec93 PR-1401: Add a config option to accept old keys in registry get calls a43701920 PR-1402: Fix ChunkSnapshot#isSectionEmpty() is always false 87d0a3368 SPIGOT-7668: Move NONE Registry updater to FieldRename to avoid some class loader issues 2ea1e7ac2 PR-1399: Fix regression preventing positive .setDamage value from causing knockback for 0 damage events ba2d49d21 Increase outdated build delay Spigot Changes: fcd94e21 Rebuild patches 342f4939 SPIGOT-7661: Add experimental unload-frozen-chunks option
2024-06-13 16:45:27 +02:00
index a0ea2ba0995a54fa12037d2a2ebe8ef9e2dd4bd0..9a9d3b9f19ad96704172cc709f49c2a517f117c2 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
Update upstream (Bukkit/CraftBukkit/Spigot) (#10875) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 376e37db SPIGOT-7677: Update which entities are marked as spawnable 06c4add3 SPIGOT-7737: Add separate TreeType.MEGA_PINE 19b7caaa SPIGOT-7731: Spawn eggs cannot have damage e585297e PR-1022: Add force option to Player#spawnParticle d26e0094 PR-1018: Add methods to get players seeing specific chunks 8df1ed18 PR-978: Add Material#isCompostable and Material#getCompostChance 4b9b59c7 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale 8d1e700a PR-1020: Cast instead of using #typed when getting BlockType and ItemType to better work with testing / mocks fa28607a PR-1016: Fix incorrect assumption of Fireball having constant speed 4c6c8586 PR-1015: Add a tool component to ItemMeta 6f6b2123 PR-1014: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects f511cfe1 PR-1013, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType def44cbf SPIGOT-7669: Fix typo in ProjectileHitEvent#getHitBlockFace documentation 53fa4f72 PR-1011: Throw an exception if a RecipeChoice is ever supplied air CraftBukkit Changes: ee95e171a SPIGOT-7737: Add separate TreeType.MEGA_PINE 0dae4c62c Fix spawn egg equality check and copy constructor ab59e847c Fix spawn eggs with no entity creating invalid stacks and disconnect creative clients 3b6093b28 SPIGOT-7736: Creative spawn egg use loses components c6b4d5a87 SPIGOT-7731: Spawn eggs cannot have damage 340ccd57f SPIGOT-7735: Fix serialization of player heads with note block sound fd2f41834 SPIGOT-7734: Can't register a custom advancement using unsafe() 02456e2a5 PR-1413: Add force option to Player#spawnParticle 6a61f38b2 SPIGOT-7680: Per-world weather command 58c41cebb PR-1409: Add methods to get players seeing specific chunks 16c976797 PR-1412: Fix shipwreck loot tables not being set for BlockTransformers 7189ba636 PR-1360: Add Material#isCompostable and Material#getCompostChance 900384556 SPIGOT-7676: Enforce locale parameter in toLowerCase and toUpperCase method calls and always use root locale bdb40c5f1 Increase outdated build delay d6607c7dd SPIGOT-7675: Fix FoodComponent config deserialization b148ed332 PR-1406: Fix incorrect assumption of Fireball having constant speed 3ec31ca75 PR-1405: Add a tool component to ItemMeta 5d7d675b9 PR-1404: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects 960827981 PR-1403, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType 94e44ec93 PR-1401: Add a config option to accept old keys in registry get calls a43701920 PR-1402: Fix ChunkSnapshot#isSectionEmpty() is always false 87d0a3368 SPIGOT-7668: Move NONE Registry updater to FieldRename to avoid some class loader issues 2ea1e7ac2 PR-1399: Fix regression preventing positive .setDamage value from causing knockback for 0 damage events ba2d49d21 Increase outdated build delay Spigot Changes: fcd94e21 Rebuild patches 342f4939 SPIGOT-7661: Add experimental unload-frozen-chunks option
2024-06-13 16:45:27 +02:00
@@ -3330,6 +3330,13 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
2021-06-11 14:02:28 +02:00
void resetCooldown();
// Paper end - attack cooldown API
+ // Paper start - client option API
2021-06-11 14:02:28 +02:00
+ /**
+ * @return the client option value of the player
+ */
+ <T> @NotNull T getClientOption(com.destroystokyo.paper.@NotNull ClientOption<T> option);
+ // Paper end - client option API
+
2021-06-11 14:02:28 +02:00
// Spigot start
public class Spigot extends Entity.Spigot {