Skip to content

Commit f4741f2

Browse files
authored
Expose particle status client option (#11573)
1 parent 5f0932b commit f4741f2

30 files changed

+155
-121
lines changed

patches/api/0183-Add-Player-Client-Options-API.patch

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Subject: [PATCH] Add Player Client Options API
66

77
diff --git a/src/main/java/com/destroystokyo/paper/ClientOption.java b/src/main/java/com/destroystokyo/paper/ClientOption.java
88
new file mode 100644
9-
index 0000000000000000000000000000000000000000..ed08f823e0620289392f7fc2ff0ac721cff60478
9+
index 0000000000000000000000000000000000000000..7af28d6ba27c97a87ffbb9db03a5c340277853cc
1010
--- /dev/null
1111
+++ b/src/main/java/com/destroystokyo/paper/ClientOption.java
12-
@@ -0,0 +1,51 @@
12+
@@ -0,0 +1,70 @@
1313
+package com.destroystokyo.paper;
1414
+
1515
+import net.kyori.adventure.translation.Translatable;
@@ -26,8 +26,9 @@ index 0000000000000000000000000000000000000000..ed08f823e0620289392f7fc2ff0ac721
2626
+ public static final ClientOption<String> LOCALE = new ClientOption<>(String.class);
2727
+ public static final ClientOption<MainHand> MAIN_HAND = new ClientOption<>(MainHand.class);
2828
+ public static final ClientOption<Integer> VIEW_DISTANCE = new ClientOption<>(Integer.class);
29-
+ public static final ClientOption<Boolean> ALLOW_SERVER_LISTINGS = new ClientOption<>(Boolean.class);
3029
+ public static final ClientOption<Boolean> TEXT_FILTERING_ENABLED = new ClientOption<>(Boolean.class);
30+
+ public static final ClientOption<Boolean> ALLOW_SERVER_LISTINGS = new ClientOption<>(Boolean.class);
31+
+ public static final ClientOption<ParticleVisibility> PARTICLE_VISIBILITY = new ClientOption<>(ParticleVisibility.class);
3132
+
3233
+ private final Class<T> type;
3334
+
@@ -60,6 +61,24 @@ index 0000000000000000000000000000000000000000..ed08f823e0620289392f7fc2ff0ac721
6061
+ return "options.chat.visibility." + this.name;
6162
+ }
6263
+ }
64+
+
65+
+ public enum ParticleVisibility implements Translatable {
66+
+ ALL("all"),
67+
+ DECREASED("decreased"),
68+
+ MINIMAL("minimal");
69+
+
70+
+ public static final Index<String, ParticleVisibility> NAMES = Index.create(ParticleVisibility.class, particleVisibility -> particleVisibility.name);
71+
+ private final String name;
72+
+
73+
+ ParticleVisibility(final String name) {
74+
+ this.name = name;
75+
+ }
76+
+
77+
+ @Override
78+
+ public String translationKey() {
79+
+ return "options.particles." + this.name;
80+
+ }
81+
+ }
6382
+}
6483
diff --git a/src/main/java/com/destroystokyo/paper/SkinParts.java b/src/main/java/com/destroystokyo/paper/SkinParts.java
6584
new file mode 100644
@@ -89,14 +108,15 @@ index 0000000000000000000000000000000000000000..4a0c39405d4fbed457787e3c6ded4cc6
89108
+}
90109
diff --git a/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java b/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java
91110
new file mode 100644
92-
index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc5865ad5aee
111+
index 0000000000000000000000000000000000000000..5245955fb3466d2b89eaad4027d145ebf7bb122c
93112
--- /dev/null
94113
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java
95-
@@ -0,0 +1,130 @@
114+
@@ -0,0 +1,142 @@
96115
+package com.destroystokyo.paper.event.player;
97116
+
98117
+import com.destroystokyo.paper.ClientOption;
99118
+import com.destroystokyo.paper.ClientOption.ChatVisibility;
119+
+import com.destroystokyo.paper.ClientOption.ParticleVisibility;
100120
+import com.destroystokyo.paper.SkinParts;
101121
+import java.util.Map;
102122
+import org.bukkit.entity.Player;
@@ -122,6 +142,7 @@ index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc58
122142
+ private final MainHand mainHand;
123143
+ private final boolean allowsServerListings;
124144
+ private final boolean textFilteringEnabled;
145+
+ private final ParticleVisibility particleVisibility;
125146
+
126147
+ @Deprecated
127148
+ public PlayerClientOptionsChangeEvent(final Player player, final String locale, final int viewDistance, final ChatVisibility chatVisibility, final boolean chatColors, final SkinParts skinParts, final MainHand mainHand) {
@@ -134,6 +155,7 @@ index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc58
134155
+ this.mainHand = mainHand;
135156
+ this.allowsServerListings = false;
136157
+ this.textFilteringEnabled = false;
158+
+ this.particleVisibility = ParticleVisibility.ALL;
137159
+ }
138160
+
139161
+ @ApiStatus.Internal
@@ -148,6 +170,7 @@ index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc58
148170
+ this.mainHand = (MainHand) options.get(ClientOption.MAIN_HAND);
149171
+ this.allowsServerListings = (boolean) options.get(ClientOption.ALLOW_SERVER_LISTINGS);
150172
+ this.textFilteringEnabled = (boolean) options.get(ClientOption.TEXT_FILTERING_ENABLED);
173+
+ this.particleVisibility = (ParticleVisibility) options.get(ClientOption.PARTICLE_VISIBILITY);
151174
+ }
152175
+
153176
+ public String getLocale() {
@@ -198,6 +221,14 @@ index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc58
198221
+ return this.mainHand != this.player.getClientOption(ClientOption.MAIN_HAND);
199222
+ }
200223
+
224+
+ public boolean hasTextFilteringEnabled() {
225+
+ return this.textFilteringEnabled;
226+
+ }
227+
+
228+
+ public boolean hasTextFilteringChanged() {
229+
+ return this.textFilteringEnabled != this.player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED);
230+
+ }
231+
+
201232
+ public boolean allowsServerListings() {
202233
+ return this.allowsServerListings;
203234
+ }
@@ -206,12 +237,12 @@ index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc58
206237
+ return this.allowsServerListings != this.player.getClientOption(ClientOption.ALLOW_SERVER_LISTINGS);
207238
+ }
208239
+
209-
+ public boolean hasTextFilteringEnabled() {
210-
+ return this.textFilteringEnabled;
240+
+ public ParticleVisibility getParticleVisibility() {
241+
+ return this.particleVisibility;
211242
+ }
212243
+
213-
+ public boolean hasTextFilteringChanged() {
214-
+ return this.textFilteringEnabled != this.player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED);
244+
+ public boolean hasParticleVisibilityChanged() {
245+
+ return this.particleVisibility != this.player.getClientOption(ClientOption.PARTICLE_VISIBILITY);
215246
+ }
216247
+
217248
+ @Override

patches/server/0337-Implement-Player-Client-Options-API.patch

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Subject: [PATCH] Implement Player Client Options API
55

66
== AT ==
77
public net.minecraft.world.entity.player.Player DATA_PLAYER_MODE_CUSTOMISATION
8+
public net.minecraft.server.level.ServerPlayer particleStatus
89

910
diff --git a/src/main/java/com/destroystokyo/paper/PaperSkinParts.java b/src/main/java/com/destroystokyo/paper/PaperSkinParts.java
1011
new file mode 100644
@@ -87,7 +88,7 @@ index 0000000000000000000000000000000000000000..b6f4400df3d8ec7e06a996de54f8cabb
8788
+ }
8889
+}
8990
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
90-
index 363175d3325c012f31ba84060bb0bfac694f6ab8..9911e231ad021286f2da90057b06874f7b4e3b4d 100644
91+
index 0c68c0a9ec9b353b353eff0c36af2993df5f59b3..eebf44c7124c4f48b6d48562a00633b1e8ff9b00 100644
9192
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
9293
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
9394
@@ -420,7 +420,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
@@ -99,31 +100,27 @@ index 363175d3325c012f31ba84060bb0bfac694f6ab8..9911e231ad021286f2da90057b06874f
99100
this.object = null;
100101

101102
// CraftBukkit start
102-
@@ -2404,7 +2404,23 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
103-
}
103+
@@ -2405,6 +2405,19 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
104104
}
105105

106-
+ // Paper start - Client option API
107-
+ private java.util.Map<com.destroystokyo.paper.ClientOption<?>, ?> getClientOptionMap(String locale, int viewDistance, com.destroystokyo.paper.ClientOption.ChatVisibility chatVisibility, boolean chatColors, com.destroystokyo.paper.PaperSkinParts skinParts, org.bukkit.inventory.MainHand mainHand, boolean allowsServerListing, boolean textFilteringEnabled) {
108-
+ java.util.Map<com.destroystokyo.paper.ClientOption<?>, Object> map = new java.util.HashMap<>();
109-
+ map.put(com.destroystokyo.paper.ClientOption.LOCALE, locale);
110-
+ map.put(com.destroystokyo.paper.ClientOption.VIEW_DISTANCE, viewDistance);
111-
+ map.put(com.destroystokyo.paper.ClientOption.CHAT_VISIBILITY, chatVisibility);
112-
+ map.put(com.destroystokyo.paper.ClientOption.CHAT_COLORS_ENABLED, chatColors);
113-
+ map.put(com.destroystokyo.paper.ClientOption.SKIN_PARTS, skinParts);
114-
+ map.put(com.destroystokyo.paper.ClientOption.MAIN_HAND, mainHand);
115-
+ map.put(com.destroystokyo.paper.ClientOption.ALLOW_SERVER_LISTINGS, allowsServerListing);
116-
+ map.put(com.destroystokyo.paper.ClientOption.TEXT_FILTERING_ENABLED, textFilteringEnabled);
117-
+ return map;
118-
+ }
119-
+ // Paper end
120-
+
121106
public void updateOptions(ClientInformation clientOptions) {
122-
+ new com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent(getBukkitEntity(), getClientOptionMap(clientOptions.language(), clientOptions.viewDistance(), com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(clientOptions.chatVisibility().name()), clientOptions.chatColors(), new com.destroystokyo.paper.PaperSkinParts(clientOptions.modelCustomisation()), clientOptions.mainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT, clientOptions.allowsListing(), clientOptions.textFilteringEnabled())).callEvent(); // Paper - settings event
107+
+ // Paper start - settings event
108+
+ new com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent(this.getBukkitEntity(), Util.make(new java.util.IdentityHashMap<>(), map -> {
109+
+ map.put(com.destroystokyo.paper.ClientOption.LOCALE, clientOptions.language());
110+
+ map.put(com.destroystokyo.paper.ClientOption.VIEW_DISTANCE, clientOptions.viewDistance());
111+
+ map.put(com.destroystokyo.paper.ClientOption.CHAT_VISIBILITY, com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(clientOptions.chatVisibility().name()));
112+
+ map.put(com.destroystokyo.paper.ClientOption.CHAT_COLORS_ENABLED, clientOptions.chatColors());
113+
+ map.put(com.destroystokyo.paper.ClientOption.SKIN_PARTS, new com.destroystokyo.paper.PaperSkinParts(clientOptions.modelCustomisation()));
114+
+ map.put(com.destroystokyo.paper.ClientOption.MAIN_HAND, clientOptions.mainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT);
115+
+ map.put(com.destroystokyo.paper.ClientOption.TEXT_FILTERING_ENABLED, clientOptions.textFilteringEnabled());
116+
+ map.put(com.destroystokyo.paper.ClientOption.ALLOW_SERVER_LISTINGS, clientOptions.allowsListing());
117+
+ map.put(com.destroystokyo.paper.ClientOption.PARTICLE_VISIBILITY, com.destroystokyo.paper.ClientOption.ParticleVisibility.valueOf(clientOptions.particleStatus().name()));
118+
+ })).callEvent();
119+
+ // Paper end - settings event
123120
// CraftBukkit start
124121
if (this.getMainArm() != clientOptions.mainHand()) {
125122
PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(this.getBukkitEntity(), this.getMainArm() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT);
126-
@@ -2415,6 +2431,11 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
123+
@@ -2415,6 +2428,11 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
127124
this.server.server.getPluginManager().callEvent(event);
128125
}
129126
// CraftBukkit end
@@ -136,32 +133,34 @@ index 363175d3325c012f31ba84060bb0bfac694f6ab8..9911e231ad021286f2da90057b06874f
136133
this.adventure$locale = java.util.Objects.requireNonNullElse(net.kyori.adventure.translation.Translator.parseLocale(this.language), java.util.Locale.US); // Paper
137134
this.requestedViewDistance = clientOptions.viewDistance();
138135
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
139-
index 341dbff92d15886afe8fe628e06d1c07817241ed..66e5e949c8711103ae9bf73161422f350c217874 100644
136+
index b3b13f1baea0b170fd4f1546689aad40f53d3c27..8cfcd8797d056be07b09ec9627bc35bf75eb0d2d 100644
140137
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
141138
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
142-
@@ -658,6 +658,28 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
139+
@@ -658,6 +658,30 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
143140
connection.disconnect(message == null ? net.kyori.adventure.text.Component.empty() : message);
144141
}
145142
}
146143
+
147144
+ @Override
148145
+ public <T> T getClientOption(com.destroystokyo.paper.ClientOption<T> type) {
149146
+ if (com.destroystokyo.paper.ClientOption.SKIN_PARTS == type) {
150-
+ return type.getType().cast(new com.destroystokyo.paper.PaperSkinParts(getHandle().getEntityData().get(net.minecraft.world.entity.player.Player.DATA_PLAYER_MODE_CUSTOMISATION)));
147+
+ return type.getType().cast(new com.destroystokyo.paper.PaperSkinParts(this.getHandle().getEntityData().get(net.minecraft.world.entity.player.Player.DATA_PLAYER_MODE_CUSTOMISATION)));
151148
+ } else if (com.destroystokyo.paper.ClientOption.CHAT_COLORS_ENABLED == type) {
152-
+ return type.getType().cast(getHandle().canChatInColor());
149+
+ return type.getType().cast(this.getHandle().canChatInColor());
153150
+ } else if (com.destroystokyo.paper.ClientOption.CHAT_VISIBILITY == type) {
154-
+ return type.getType().cast(getHandle().getChatVisibility() == null ? com.destroystokyo.paper.ClientOption.ChatVisibility.UNKNOWN : com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(getHandle().getChatVisibility().name()));
151+
+ return type.getType().cast(this.getHandle().getChatVisibility() == null ? com.destroystokyo.paper.ClientOption.ChatVisibility.UNKNOWN : com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(this.getHandle().getChatVisibility().name()));
155152
+ } else if (com.destroystokyo.paper.ClientOption.LOCALE == type) {
156-
+ return type.getType().cast(getLocale());
153+
+ return type.getType().cast(this.getLocale());
157154
+ } else if (com.destroystokyo.paper.ClientOption.MAIN_HAND == type) {
158-
+ return type.getType().cast(getMainHand());
155+
+ return type.getType().cast(this.getMainHand());
159156
+ } else if (com.destroystokyo.paper.ClientOption.VIEW_DISTANCE == type) {
160-
+ return type.getType().cast(getClientViewDistance());
161-
+ } else if (com.destroystokyo.paper.ClientOption.ALLOW_SERVER_LISTINGS == type) {
162-
+ return type.getType().cast(getHandle().allowsListing());
157+
+ return type.getType().cast(this.getClientViewDistance());
163158
+ } else if (com.destroystokyo.paper.ClientOption.TEXT_FILTERING_ENABLED == type) {
164-
+ return type.getType().cast(getHandle().isTextFilteringEnabled());
159+
+ return type.getType().cast(this.getHandle().isTextFilteringEnabled());
160+
+ } else if (com.destroystokyo.paper.ClientOption.ALLOW_SERVER_LISTINGS == type) {
161+
+ return type.getType().cast(this.getHandle().allowsListing());
162+
+ } else if (com.destroystokyo.paper.ClientOption.PARTICLE_VISIBILITY == type) {
163+
+ return type.getType().cast(com.destroystokyo.paper.ClientOption.ParticleVisibility.valueOf(this.getHandle().particleStatus.name()));
165164
+ }
166165
+ throw new RuntimeException("Unknown settings type");
167166
+ }
@@ -170,15 +169,15 @@ index 341dbff92d15886afe8fe628e06d1c07817241ed..66e5e949c8711103ae9bf73161422f35
170169
@Override
171170
diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
172171
new file mode 100644
173-
index 0000000000000000000000000000000000000000..7f8b6462d2a1bbd39a870d2543bebc135f7eb45b
172+
index 0000000000000000000000000000000000000000..01e0936ea8ce5bcacafd9e89a1c0dfd2c172024d
174173
--- /dev/null
175174
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
176-
@@ -0,0 +1,18 @@
175+
@@ -0,0 +1,25 @@
177176
+package io.papermc.paper.world;
178177
+
179178
+import com.destroystokyo.paper.ClientOption;
179+
+import net.minecraft.server.level.ParticleStatus;
180180
+import net.minecraft.world.entity.player.ChatVisiblity;
181-
+import org.bukkit.Difficulty;
182181
+import org.junit.jupiter.api.Assertions;
183182
+import org.junit.jupiter.api.Test;
184183
+
@@ -191,4 +190,11 @@ index 0000000000000000000000000000000000000000..7f8b6462d2a1bbd39a870d2543bebc13
191190
+ Assertions.assertEquals(ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey(), chatVisibility + "'s translation key doesn't match");
192191
+ }
193192
+ }
193+
+
194+
+ @Test
195+
+ public void testParticleVisibilityKeys() {
196+
+ for (ClientOption.ParticleVisibility particleVisibility : ClientOption.ParticleVisibility.values()) {
197+
+ Assertions.assertEquals(ParticleStatus.valueOf(particleVisibility.name()).getKey(), particleVisibility.translationKey(), particleVisibility + "'s translation key doesn't match");
198+
+ }
199+
+ }
194200
+}

patches/server/0388-Brand-support.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Subject: [PATCH] Brand support
55

66

77
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
8-
index eacc0675d751caf996c9741a5ef5df28d1b9999b..80198c2f6419a3358f41df15dd7bbeb642d37585 100644
8+
index fd0fd75ed3e75cbdcc1abd56905ace176b871c25..b614be746f1b3c6470eddeb86bb1d4a976b84fcc 100644
99
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
1010
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
1111
@@ -322,6 +322,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
@@ -57,10 +57,10 @@ index b9fbaddcc8239bf737fdea51790f678306e511eb..9a8b08d4b70b8890961e4af7ce6e870a
5757
} catch (Exception ex) {
5858
ServerGamePacketListenerImpl.LOGGER.error("Couldn\'t dispatch custom payload", ex);
5959
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
60-
index e4c39eba10124ebf675ac721866e0c73bf15e533..ad109929cb8d9be8e147adaf744f6fa588414404 100644
60+
index 5ca3025700b3e8995ae003b73dd53e580c95b889..93caaea4832f2cf7102b43c24afaea55e11ae4c1 100644
6161
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
6262
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
63-
@@ -3154,6 +3154,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
63+
@@ -3156,6 +3156,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
6464
// Paper end
6565
};
6666

0 commit comments

Comments
 (0)