Skip to content

Commit

Permalink
Expose particle status client option
Browse files Browse the repository at this point in the history
  • Loading branch information
Lulu13022002 committed Nov 3, 2024
1 parent ce0a041 commit 30f9133
Show file tree
Hide file tree
Showing 30 changed files with 159 additions and 120 deletions.
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..98be38bcbf478ab298df673e87b1dd94db95282d
--- /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<ParticleStatus> PARTICLE_STATUS = new ClientOption<>(ParticleStatus.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 ParticleStatus implements Translatable {
+ ALL("all"),
+ DECREASED("decreased"),
+ MINIMAL("minimal");
+
+ public static final Index<String, ParticleStatus> NAMES = Index.create(ParticleStatus.class, particleStatus -> particleStatus.name);
+ private final String name;
+
+ ParticleStatus(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..62b876c3a74a9d48a9ee3252ebb0d5c2faa74d49
--- /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.ParticleStatus;
+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 ParticleStatus particleStatus;
+
+ @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.particleStatus = ParticleStatus.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.particleStatus = (ParticleStatus) options.get(ClientOption.PARTICLE_STATUS);
+ }
+
+ 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 ParticleStatus getParticleStatus() {
+ return this.particleStatus;
+ }
+
+ public boolean hasTextFilteringChanged() {
+ return this.textFilteringEnabled != this.player.getClientOption(ClientOption.TEXT_FILTERING_ENABLED);
+ public boolean hasParticleStatusChanged() {
+ return this.particleStatus != this.player.getClientOption(ClientOption.PARTICLE_STATUS);
+ }
+
+ @Override
Expand Down
73 changes: 40 additions & 33 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 66e1da081c2e2a9e1cf589f03c7594805ad5236f..5003e02fcbdeeae13b1ae8e3411bc45a2e7c8dea 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_STATUS, com.destroystokyo.paper.ClientOption.ParticleStatus.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 faab55435a0c4fc6ff9d117f29a2401677b9f828..69108fd869c7c929fd7971abea520d5ab9063f69 100644
index faab55435a0c4fc6ff9d117f29a2401677b9f828..22b7d1a63caae7e48a6166bdc3842801098970b1 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -670,6 +670,28 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -670,6 +670,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_STATUS == type) {
+ return type.getType().cast(com.destroystokyo.paper.ClientOption.ParticleStatus.valueOf(this.getHandle().particleStatus.name()));
+ }
+ throw new RuntimeException("Unknown settings type");
+ }
Expand All @@ -170,13 +169,14 @@ index faab55435a0c4fc6ff9d117f29a2401677b9f828..69108fd869c7c929fd7971abea520d5a
@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..99bdd944983a08c7d32edbeef94aecbc3fe5dc18
--- /dev/null
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
@@ -0,0 +1,18 @@
@@ -0,0 +1,26 @@
+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;
Expand All @@ -191,4 +191,11 @@ index 0000000000000000000000000000000000000000..7f8b6462d2a1bbd39a870d2543bebc13
+ Assertions.assertEquals(ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey(), chatVisibility + "'s translation key doesn't match");
+ }
+ }
+
+ @Test
+ public void testParticleStatusKeys() {
+ for (ClientOption.ParticleStatus particleStatus : ClientOption.ParticleStatus.values()) {
+ Assertions.assertEquals(ParticleStatus.valueOf(particleStatus.name()).getKey(), particleStatus.translationKey(), particleStatus + "'s translation key doesn't match");
+ }
+ }
+}
6 changes: 3 additions & 3 deletions patches/server/0389-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 807068fc6065f71961d34cb4f18b6eb39ae49637..c468947990cf05e554006e51d87b72fad7c28e55 100644
index 5200a0787fe77e39c0b4f2e5926d3d4da40a50ac..a022d8d412847501346a43d7e45f026381066acb 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 69108fd869c7c929fd7971abea520d5ab9063f69..3191c66c9e5b9c5fcfd07716733aaa51612d507f 100644
index 22b7d1a63caae7e48a6166bdc3842801098970b1..c029cd392bc8480cdb29281924fad85163477c71 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -3166,6 +3166,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -3168,6 +3168,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// Paper end
};

Expand Down
9 changes: 5 additions & 4 deletions patches/server/0401-Add-methods-to-get-translation-keys.patch
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ index 4921fc085c9d60c74028ef390325e26c598e8df1..4941e0afff8df5f10f06c715b54bf58e
case BALL:
return FireworkExplosion.Shape.SMALL_BALL;
diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
index 7f8b6462d2a1bbd39a870d2543bebc135f7eb45b..e8d5c3eb8ad98b2082bdd33d96bfb1d7124ea186 100644
index 99bdd944983a08c7d32edbeef94aecbc3fe5dc18..9f65459a0f920638931c48777172c85a05570ecf 100644
--- a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
@@ -1,11 +1,32 @@
@@ -1,12 +1,33 @@
package io.papermc.paper.world;

import com.destroystokyo.paper.ClientOption;
Expand All @@ -122,6 +122,7 @@ index 7f8b6462d2a1bbd39a870d2543bebc135f7eb45b..e8d5c3eb8ad98b2082bdd33d96bfb1d7
+import net.minecraft.network.chat.contents.TranslatableContents;
+import net.minecraft.resources.ResourceKey;
+import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ParticleStatus;
import net.minecraft.world.entity.player.ChatVisiblity;
+import net.minecraft.world.flag.FeatureFlags;
+import net.minecraft.world.level.GameRules;
Expand All @@ -145,8 +146,8 @@ index 7f8b6462d2a1bbd39a870d2543bebc135f7eb45b..e8d5c3eb8ad98b2082bdd33d96bfb1d7
public class TranslationKeyTest {

@Test
@@ -15,4 +36,70 @@ public class TranslationKeyTest {
Assertions.assertEquals(ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey(), chatVisibility + "'s translation key doesn't match");
@@ -23,4 +44,70 @@ public class TranslationKeyTest {
Assertions.assertEquals(ParticleStatus.valueOf(particleStatus.name()).getKey(), particleStatus.translationKey(), particleStatus + "'s translation key doesn't match");
}
}
+
Expand Down
Loading

0 comments on commit 30f9133

Please sign in to comment.