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

Expose particle status client option #11573

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions patches/api/0183-Add-Player-Client-Options-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ 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
index 0000000000000000000000000000000000000000..7af28d6ba27c97a87ffbb9db03a5c340277853cc
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/ClientOption.java
@@ -0,0 +1,51 @@
@@ -0,0 +1,70 @@
+package com.destroystokyo.paper;
+
+import net.kyori.adventure.translation.Translatable;
Expand All @@ -26,8 +26,9 @@ index 0000000000000000000000000000000000000000..ed08f823e0620289392f7fc2ff0ac721
+ 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);
+ public static final ClientOption<Boolean> ALLOW_SERVER_LISTINGS = new ClientOption<>(Boolean.class);
+ public static final ClientOption<ParticleVisibility> PARTICLE_VISIBILITY = new ClientOption<>(ParticleVisibility.class);
+
+ private final Class<T> type;
+
Expand Down Expand Up @@ -60,6 +61,24 @@ index 0000000000000000000000000000000000000000..ed08f823e0620289392f7fc2ff0ac721
+ return "options.chat.visibility." + this.name;
+ }
+ }
+
+ public enum ParticleVisibility implements Translatable {
+ ALL("all"),
+ DECREASED("decreased"),
+ MINIMAL("minimal");
+
+ public static final Index<String, ParticleVisibility> NAMES = Index.create(ParticleVisibility.class, particleVisibility -> particleVisibility.name);
+ private final String name;
+
+ ParticleVisibility(final String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String translationKey() {
+ return "options.particles." + 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
Expand Down Expand Up @@ -89,14 +108,15 @@ index 0000000000000000000000000000000000000000..4a0c39405d4fbed457787e3c6ded4cc6
+}
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
index 0000000000000000000000000000000000000000..5245955fb3466d2b89eaad4027d145ebf7bb122c
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/player/PlayerClientOptionsChangeEvent.java
@@ -0,0 +1,130 @@
@@ -0,0 +1,142 @@
+package com.destroystokyo.paper.event.player;
+
+import com.destroystokyo.paper.ClientOption;
+import com.destroystokyo.paper.ClientOption.ChatVisibility;
+import com.destroystokyo.paper.ClientOption.ParticleVisibility;
+import com.destroystokyo.paper.SkinParts;
+import java.util.Map;
+import org.bukkit.entity.Player;
Expand All @@ -122,6 +142,7 @@ index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc58
+ private final MainHand mainHand;
+ private final boolean allowsServerListings;
+ private final boolean textFilteringEnabled;
+ private final ParticleVisibility particleVisibility;
+
+ @Deprecated
+ public PlayerClientOptionsChangeEvent(final Player player, final String locale, final int viewDistance, final ChatVisibility chatVisibility, final boolean chatColors, final SkinParts skinParts, final MainHand mainHand) {
Expand All @@ -134,6 +155,7 @@ index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc58
+ this.mainHand = mainHand;
+ this.allowsServerListings = false;
+ this.textFilteringEnabled = false;
+ this.particleVisibility = ParticleVisibility.ALL;
+ }
+
+ @ApiStatus.Internal
Expand All @@ -148,6 +170,7 @@ index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc58
+ 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);
+ this.particleVisibility = (ParticleVisibility) options.get(ClientOption.PARTICLE_VISIBILITY);
+ }
+
+ public String getLocale() {
Expand Down Expand Up @@ -198,6 +221,14 @@ index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc58
+ return this.mainHand != this.player.getClientOption(ClientOption.MAIN_HAND);
+ }
+
+ public boolean hasTextFilteringEnabled() {
+ return this.textFilteringEnabled;
+ }
+
+ public boolean hasTextFilteringChanged() {
+ return this.textFilteringEnabled != this.player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED);
+ }
+
+ public boolean allowsServerListings() {
+ return this.allowsServerListings;
+ }
Expand All @@ -206,12 +237,12 @@ index 0000000000000000000000000000000000000000..6cf6aa876278d0d3e75148608951fc58
+ return this.allowsServerListings != this.player.getClientOption(ClientOption.ALLOW_SERVER_LISTINGS);
+ }
+
+ public boolean hasTextFilteringEnabled() {
+ return this.textFilteringEnabled;
+ public ParticleVisibility getParticleVisibility() {
+ return this.particleVisibility;
+ }
+
+ public boolean hasTextFilteringChanged() {
+ return this.textFilteringEnabled != this.player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED);
+ public boolean hasParticleVisibilityChanged() {
+ return this.particleVisibility != this.player.getClientOption(ClientOption.PARTICLE_VISIBILITY);
+ }
+
+ @Override
Expand Down
74 changes: 40 additions & 34 deletions patches/server/0337-Implement-Player-Client-Options-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Subject: [PATCH] Implement Player Client Options API

== AT ==
public net.minecraft.world.entity.player.Player DATA_PLAYER_MODE_CUSTOMISATION
public net.minecraft.server.level.ServerPlayer particleStatus

diff --git a/src/main/java/com/destroystokyo/paper/PaperSkinParts.java b/src/main/java/com/destroystokyo/paper/PaperSkinParts.java
new file mode 100644
Expand Down Expand Up @@ -87,7 +88,7 @@ index 0000000000000000000000000000000000000000..b6f4400df3d8ec7e06a996de54f8cabb
+ }
+}
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 363175d3325c012f31ba84060bb0bfac694f6ab8..9911e231ad021286f2da90057b06874f7b4e3b4d 100644
index 0c68c0a9ec9b353b353eff0c36af2993df5f59b3..eebf44c7124c4f48b6d48562a00633b1e8ff9b00 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -420,7 +420,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
Expand All @@ -99,31 +100,27 @@ index 363175d3325c012f31ba84060bb0bfac694f6ab8..9911e231ad021286f2da90057b06874f
this.object = null;

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

+ // Paper start - Client option API
+ 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) {
+ java.util.Map<com.destroystokyo.paper.ClientOption<?>, Object> map = new java.util.HashMap<>();
+ map.put(com.destroystokyo.paper.ClientOption.LOCALE, locale);
+ map.put(com.destroystokyo.paper.ClientOption.VIEW_DISTANCE, viewDistance);
+ map.put(com.destroystokyo.paper.ClientOption.CHAT_VISIBILITY, chatVisibility);
+ map.put(com.destroystokyo.paper.ClientOption.CHAT_COLORS_ENABLED, chatColors);
+ map.put(com.destroystokyo.paper.ClientOption.SKIN_PARTS, skinParts);
+ map.put(com.destroystokyo.paper.ClientOption.MAIN_HAND, mainHand);
+ map.put(com.destroystokyo.paper.ClientOption.ALLOW_SERVER_LISTINGS, allowsServerListing);
+ map.put(com.destroystokyo.paper.ClientOption.TEXT_FILTERING_ENABLED, textFilteringEnabled);
+ return map;
+ }
+ // Paper end
+
public void updateOptions(ClientInformation clientOptions) {
+ 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
+ // Paper start - settings event
+ new com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent(this.getBukkitEntity(), Util.make(new java.util.IdentityHashMap<>(), map -> {
+ map.put(com.destroystokyo.paper.ClientOption.LOCALE, clientOptions.language());
+ map.put(com.destroystokyo.paper.ClientOption.VIEW_DISTANCE, clientOptions.viewDistance());
+ map.put(com.destroystokyo.paper.ClientOption.CHAT_VISIBILITY, com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(clientOptions.chatVisibility().name()));
+ map.put(com.destroystokyo.paper.ClientOption.CHAT_COLORS_ENABLED, clientOptions.chatColors());
+ map.put(com.destroystokyo.paper.ClientOption.SKIN_PARTS, new com.destroystokyo.paper.PaperSkinParts(clientOptions.modelCustomisation()));
+ map.put(com.destroystokyo.paper.ClientOption.MAIN_HAND, clientOptions.mainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT);
+ map.put(com.destroystokyo.paper.ClientOption.TEXT_FILTERING_ENABLED, clientOptions.textFilteringEnabled());
+ map.put(com.destroystokyo.paper.ClientOption.ALLOW_SERVER_LISTINGS, clientOptions.allowsListing());
+ map.put(com.destroystokyo.paper.ClientOption.PARTICLE_VISIBILITY, com.destroystokyo.paper.ClientOption.ParticleVisibility.valueOf(clientOptions.particleStatus().name()));
+ })).callEvent();
+ // Paper end - settings event
// CraftBukkit start
if (this.getMainArm() != clientOptions.mainHand()) {
PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(this.getBukkitEntity(), this.getMainArm() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT);
@@ -2415,6 +2431,11 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
@@ -2415,6 +2428,11 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
this.server.server.getPluginManager().callEvent(event);
}
// CraftBukkit end
Expand All @@ -136,32 +133,34 @@ index 363175d3325c012f31ba84060bb0bfac694f6ab8..9911e231ad021286f2da90057b06874f
this.adventure$locale = java.util.Objects.requireNonNullElse(net.kyori.adventure.translation.Translator.parseLocale(this.language), java.util.Locale.US); // Paper
this.requestedViewDistance = clientOptions.viewDistance();
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 341dbff92d15886afe8fe628e06d1c07817241ed..66e5e949c8711103ae9bf73161422f350c217874 100644
index b3b13f1baea0b170fd4f1546689aad40f53d3c27..8cfcd8797d056be07b09ec9627bc35bf75eb0d2d 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -658,6 +658,28 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -658,6 +658,30 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
connection.disconnect(message == null ? net.kyori.adventure.text.Component.empty() : message);
}
}
+
+ @Override
+ public <T> T getClientOption(com.destroystokyo.paper.ClientOption<T> type) {
+ if (com.destroystokyo.paper.ClientOption.SKIN_PARTS == type) {
+ return type.getType().cast(new com.destroystokyo.paper.PaperSkinParts(getHandle().getEntityData().get(net.minecraft.world.entity.player.Player.DATA_PLAYER_MODE_CUSTOMISATION)));
+ return type.getType().cast(new com.destroystokyo.paper.PaperSkinParts(this.getHandle().getEntityData().get(net.minecraft.world.entity.player.Player.DATA_PLAYER_MODE_CUSTOMISATION)));
+ } else if (com.destroystokyo.paper.ClientOption.CHAT_COLORS_ENABLED == type) {
+ return type.getType().cast(getHandle().canChatInColor());
+ return type.getType().cast(this.getHandle().canChatInColor());
+ } else if (com.destroystokyo.paper.ClientOption.CHAT_VISIBILITY == type) {
+ return type.getType().cast(getHandle().getChatVisibility() == null ? com.destroystokyo.paper.ClientOption.ChatVisibility.UNKNOWN : com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(getHandle().getChatVisibility().name()));
+ return type.getType().cast(this.getHandle().getChatVisibility() == null ? com.destroystokyo.paper.ClientOption.ChatVisibility.UNKNOWN : com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(this.getHandle().getChatVisibility().name()));
+ } else if (com.destroystokyo.paper.ClientOption.LOCALE == type) {
+ return type.getType().cast(getLocale());
+ return type.getType().cast(this.getLocale());
+ } else if (com.destroystokyo.paper.ClientOption.MAIN_HAND == type) {
+ return type.getType().cast(getMainHand());
+ return type.getType().cast(this.getMainHand());
+ } else if (com.destroystokyo.paper.ClientOption.VIEW_DISTANCE == type) {
+ return type.getType().cast(getClientViewDistance());
+ } else if (com.destroystokyo.paper.ClientOption.ALLOW_SERVER_LISTINGS == type) {
+ return type.getType().cast(getHandle().allowsListing());
+ return type.getType().cast(this.getClientViewDistance());
+ } else if (com.destroystokyo.paper.ClientOption.TEXT_FILTERING_ENABLED == type) {
+ return type.getType().cast(getHandle().isTextFilteringEnabled());
+ return type.getType().cast(this.getHandle().isTextFilteringEnabled());
+ } else if (com.destroystokyo.paper.ClientOption.ALLOW_SERVER_LISTINGS == type) {
+ return type.getType().cast(this.getHandle().allowsListing());
+ } else if (com.destroystokyo.paper.ClientOption.PARTICLE_VISIBILITY == type) {
+ return type.getType().cast(com.destroystokyo.paper.ClientOption.ParticleVisibility.valueOf(this.getHandle().particleStatus.name()));
+ }
+ throw new RuntimeException("Unknown settings type");
+ }
Expand All @@ -170,15 +169,15 @@ index 341dbff92d15886afe8fe628e06d1c07817241ed..66e5e949c8711103ae9bf73161422f35
@Override
diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..7f8b6462d2a1bbd39a870d2543bebc135f7eb45b
index 0000000000000000000000000000000000000000..01e0936ea8ce5bcacafd9e89a1c0dfd2c172024d
--- /dev/null
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
@@ -0,0 +1,18 @@
@@ -0,0 +1,25 @@
+package io.papermc.paper.world;
+
+import com.destroystokyo.paper.ClientOption;
+import net.minecraft.server.level.ParticleStatus;
+import net.minecraft.world.entity.player.ChatVisiblity;
+import org.bukkit.Difficulty;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
Expand All @@ -191,4 +190,11 @@ index 0000000000000000000000000000000000000000..7f8b6462d2a1bbd39a870d2543bebc13
+ Assertions.assertEquals(ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey(), chatVisibility + "'s translation key doesn't match");
+ }
+ }
+
+ @Test
+ public void testParticleVisibilityKeys() {
+ for (ClientOption.ParticleVisibility particleVisibility : ClientOption.ParticleVisibility.values()) {
+ Assertions.assertEquals(ParticleStatus.valueOf(particleVisibility.name()).getKey(), particleVisibility.translationKey(), particleVisibility + "'s translation key doesn't match");
+ }
+ }
+}
6 changes: 3 additions & 3 deletions patches/server/0388-Brand-support.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Brand support


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

Expand Down
Loading
Loading