aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0183-Add-Player-Client-Options-API.patch
blob: 56be6b483bb5b0e2ae795a51e287c1961ae48e21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MiniDigger <admin@benndorf.dev>
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..ed08f823e0620289392f7fc2ff0ac721cff60478
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/ClientOption.java
@@ -0,0 +1,51 @@
+package com.destroystokyo.paper;
+
+import net.kyori.adventure.translation.Translatable;
+import net.kyori.adventure.util.Index;
+import org.bukkit.inventory.MainHand;
+import org.jspecify.annotations.NullMarked;
+
+@NullMarked
+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);
+
+    private final Class<T> type;
+
+    private ClientOption(final Class<T> type) {
+        this.type = type;
+    }
+
+    public Class<T> getType() {
+        return this.type;
+    }
+
+    public enum ChatVisibility implements Translatable {
+        FULL("full"),
+        SYSTEM("system"),
+        HIDDEN("hidden"),
+        UNKNOWN("unknown");
+
+        public static final Index<String, ChatVisibility> NAMES = Index.create(ChatVisibility.class, chatVisibility -> chatVisibility.name);
+        private final String name;
+
+        ChatVisibility(final String name) {
+            this.name = name;
+        }
+
+        @Override
+        public String translationKey() {
+            if (this == UNKNOWN) {
+                throw new UnsupportedOperationException(this.name + " doesn't have a translation key");
+            }
+            return "options.chat.visibility." + this.name;
+        }
+    }
+}
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
index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc5865ad5aee
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java
@@ -0,0 +1,130 @@
+package com.destroystokyo.paper.event.player;
+
+import com.destroystokyo.paper.ClientOption;
+import com.destroystokyo.paper.ClientOption.ChatVisibility;
+import com.destroystokyo.paper.SkinParts;
+import java.util.Map;
+import org.bukkit.entity.Player;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.bukkit.inventory.MainHand;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Called when the player changes their client settings
+ */
+@NullMarked
+public class PlayerClientOptionsChangeEvent extends PlayerEvent {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    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;
+
+    @Deprecated
+    public PlayerClientOptionsChangeEvent(final Player player, final String locale, final int viewDistance, final ChatVisibility chatVisibility, final boolean chatColors, final SkinParts skinParts, final 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;
+    }
+
+    @ApiStatus.Internal
+    public PlayerClientOptionsChangeEvent(final Player player, final 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);
+    }
+
+    public String getLocale() {
+        return this.locale;
+    }
+
+    public boolean hasLocaleChanged() {
+        return !this.locale.equals(this.player.getClientOption(ClientOption.LOCALE));
+    }
+
+    public int getViewDistance() {
+        return this.viewDistance;
+    }
+
+    public boolean hasViewDistanceChanged() {
+        return this.viewDistance != this.player.getClientOption(ClientOption.VIEW_DISTANCE);
+    }
+
+    public ChatVisibility getChatVisibility() {
+        return this.chatVisibility;
+    }
+
+    public boolean hasChatVisibilityChanged() {
+        return this.chatVisibility != this.player.getClientOption(ClientOption.CHAT_VISIBILITY);
+    }
+
+    public boolean hasChatColorsEnabled() {
+        return this.chatColors;
+    }
+
+    public boolean hasChatColorsEnabledChanged() {
+        return this.chatColors != this.player.getClientOption(ClientOption.CHAT_COLORS_ENABLED);
+    }
+
+    public SkinParts getSkinParts() {
+        return this.skinparts;
+    }
+
+    public boolean hasSkinPartsChanged() {
+        return this.skinparts.getRaw() != this.player.getClientOption(ClientOption.SKIN_PARTS).getRaw();
+    }
+
+    public MainHand getMainHand() {
+        return this.mainHand;
+    }
+
+    public boolean hasMainHandChanged() {
+        return this.mainHand != this.player.getClientOption(ClientOption.MAIN_HAND);
+    }
+
+    public boolean allowsServerListings() {
+        return this.allowsServerListings;
+    }
+
+    public boolean hasAllowServerListingsChanged() {
+        return this.allowsServerListings != this.player.getClientOption(ClientOption.ALLOW_SERVER_LISTINGS);
+    }
+
+    public boolean hasTextFilteringEnabled() {
+        return this.textFilteringEnabled;
+    }
+
+    public boolean hasTextFilteringChanged() {
+        return this.textFilteringEnabled != this.player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED);
+    }
+
+    @Override
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index e65f4f0df2e6832cf089572822c96ecc7a83dab3..b5573a26486fdfb6eb3aa7f9c46a67c8cddba34d 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -3335,6 +3335,13 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
     void resetCooldown();
     // Paper end - attack cooldown API
 
+    // Paper start - client option API
+    /**
+     * @return the client option value of the player
+     */
+    <T> @NotNull T getClientOption(com.destroystokyo.paper.@NotNull ClientOption<T> option);
+    // Paper end - client option API
+
     // Spigot start
     public class Spigot extends Entity.Spigot {