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:15 +0100
|
|
|
|
Subject: [PATCH] Implement Player Client Options API
|
|
|
|
|
2022-11-20 00:53:20 +01:00
|
|
|
== AT ==
|
|
|
|
public net.minecraft.world.entity.player.Player DATA_PLAYER_MODE_CUSTOMISATION
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperSkinParts.java b/src/main/java/com/destroystokyo/paper/PaperSkinParts.java
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000000000000000000000000000000000000..b6f4400df3d8ec7e06a996de54f8cabba57885e1
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperSkinParts.java
|
|
|
|
@@ -0,0 +1,74 @@
|
|
|
|
+package com.destroystokyo.paper;
|
|
|
|
+
|
|
|
|
+import com.google.common.base.Objects;
|
|
|
|
+
|
|
|
|
+import java.util.StringJoiner;
|
|
|
|
+
|
|
|
|
+public class PaperSkinParts implements SkinParts {
|
|
|
|
+
|
|
|
|
+ private final int raw;
|
|
|
|
+
|
|
|
|
+ public PaperSkinParts(int raw) {
|
|
|
|
+ this.raw = raw;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean hasCapeEnabled() {
|
|
|
|
+ return (raw & 1) == 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean hasJacketEnabled() {
|
|
|
|
+ return (raw >> 1 & 1) == 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean hasLeftSleeveEnabled() {
|
|
|
|
+ return (raw >> 2 & 1) == 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean hasRightSleeveEnabled() {
|
|
|
|
+ return (raw >> 3 & 1) == 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean hasLeftPantsEnabled() {
|
|
|
|
+ return (raw >> 4 & 1) == 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean hasRightPantsEnabled() {
|
|
|
|
+ return (raw >> 5 & 1) == 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public boolean hasHatsEnabled() {
|
|
|
|
+ return (raw >> 6 & 1) == 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int getRaw() {
|
|
|
|
+ return raw;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean equals(Object o) {
|
|
|
|
+ if (this == o) return true;
|
|
|
|
+ if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
+ PaperSkinParts that = (PaperSkinParts) o;
|
|
|
|
+ return raw == that.raw;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int hashCode() {
|
|
|
|
+ return Objects.hashCode(raw);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String toString() {
|
|
|
|
+ return new StringJoiner(", ", PaperSkinParts.class.getSimpleName() + "[", "]")
|
|
|
|
+ .add("raw=" + raw)
|
|
|
|
+ .add("cape=" + hasCapeEnabled())
|
|
|
|
+ .add("jacket=" + hasJacketEnabled())
|
|
|
|
+ .add("leftSleeve=" + hasLeftSleeveEnabled())
|
|
|
|
+ .add("rightSleeve=" + hasRightSleeveEnabled())
|
|
|
|
+ .add("leftPants=" + hasLeftPantsEnabled())
|
|
|
|
+ .add("rightPants=" + hasRightPantsEnabled())
|
|
|
|
+ .add("hats=" + hasHatsEnabled())
|
|
|
|
+ .toString();
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2024-04-12 21:14:06 +02:00
|
|
|
index 3a856f28237246660665aef983e5e9fe2bac8c37..3d7a938f72424a4f30f75563393a953cf9f11933 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
2024-01-24 13:07:40 +01:00
|
|
|
@@ -338,7 +338,7 @@ public class ServerPlayer extends Player {
|
2023-10-14 20:32:00 +02:00
|
|
|
this.advancements = server.getPlayerList().getPlayerAdvancements(this);
|
|
|
|
this.setMaxUpStep(1.0F);
|
2024-01-21 12:11:43 +01:00
|
|
|
// this.fudgeSpawnLocation(world); // Paper - Don't move existing players to world spawn
|
2023-10-14 20:32:00 +02:00
|
|
|
- this.updateOptions(clientOptions);
|
|
|
|
+ this.updateOptionsNoEvents(clientOptions); // Paper - don't call options events on login
|
|
|
|
|
|
|
|
this.cachedSingleHashSet = new com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<>(this); // Paper
|
|
|
|
|
2024-01-24 13:07:40 +01:00
|
|
|
@@ -2004,7 +2004,23 @@ public class ServerPlayer extends Player {
|
2023-03-14 20:54:57 +01:00
|
|
|
}
|
2022-10-27 01:09:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // 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
|
2023-09-22 05:29:51 +02:00
|
|
|
+
|
|
|
|
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
|
2021-06-11 14:02:28 +02:00
|
|
|
// CraftBukkit start
|
2023-10-27 01:34:58 +02:00
|
|
|
if (this.getMainArm() != clientOptions.mainHand()) {
|
|
|
|
PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(this.getBukkitEntity(), this.getMainArm() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT);
|
2024-01-24 13:07:40 +01:00
|
|
|
@@ -2016,6 +2032,11 @@ public class ServerPlayer extends Player {
|
2023-10-14 20:32:00 +02:00
|
|
|
this.server.server.getPluginManager().callEvent(new com.destroystokyo.paper.event.player.PlayerLocaleChangeEvent(this.getBukkitEntity(), this.language, clientOptions.language())); // Paper
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
+ // Paper start - don't call options events on login
|
|
|
|
+ updateOptionsNoEvents(clientOptions);
|
|
|
|
+ }
|
|
|
|
+ public void updateOptionsNoEvents(ClientInformation clientOptions) {
|
|
|
|
+ // Paper end
|
|
|
|
this.language = clientOptions.language();
|
2024-02-09 21:30:50 +01:00
|
|
|
this.adventure$locale = java.util.Objects.requireNonNullElse(net.kyori.adventure.translation.Translator.parseLocale(this.language), java.util.Locale.US); // Paper
|
2023-10-14 20:32:00 +02:00
|
|
|
this.requestedViewDistance = clientOptions.viewDistance();
|
2021-06-11 14:02:28 +02:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2024-04-12 21:14:06 +02:00
|
|
|
index 476b7bc14b4d2e7ed30c23b65dbc7aa0c6679b6b..5ba0fa6fda6d496f7540185e6dc58439cc1e04f1 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
Updated Upstream (Bukkit/CraftBukkit) (#10242)
* Updated Upstream (Bukkit/CraftBukkit)
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:
a6a9d2a4 Remove some old ApiStatus.Experimental annotations
be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage
b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects
b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration
08f86d1c PR-971: Add Player methods for client-side potion effects
2e3024a9 PR-963: Add API for in-world structures
a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality
1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason
cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent
CraftBukkit Changes:
38fd4bd50 Fix accidentally renamed internal damage method
80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage
7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom
ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects
4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration
22a541a29 Improve support for per-world game rules
cb7dccce2 PR-1348: Add Player methods for client-side potion effects
b8d6109f0 PR-1335: Add API for in-world structures
4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity
e74107678 Fix Crafter maximum stack size
0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality
4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason
20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette
3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook
333701839 SPIGOT-7572: Bee nests generated without bees
f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
2024-02-11 22:28:00 +01:00
|
|
|
@@ -573,6 +573,28 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2022-09-26 10:02:51 +02:00
|
|
|
connection.disconnect(message == null ? net.kyori.adventure.text.Component.empty() : message);
|
|
|
|
}
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
2021-06-14 03:06:38 +02:00
|
|
|
+ public <T> T getClientOption(com.destroystokyo.paper.ClientOption<T> type) {
|
2022-10-27 01:09:03 +02:00
|
|
|
+ if (com.destroystokyo.paper.ClientOption.SKIN_PARTS == type) {
|
2021-06-14 03:06:38 +02:00
|
|
|
+ return type.getType().cast(new com.destroystokyo.paper.PaperSkinParts(getHandle().getEntityData().get(net.minecraft.world.entity.player.Player.DATA_PLAYER_MODE_CUSTOMISATION)));
|
2022-10-27 01:09:03 +02:00
|
|
|
+ } else if (com.destroystokyo.paper.ClientOption.CHAT_COLORS_ENABLED == type) {
|
2021-06-14 03:06:38 +02:00
|
|
|
+ return type.getType().cast(getHandle().canChatInColor());
|
2022-10-27 01:09:03 +02:00
|
|
|
+ } else if (com.destroystokyo.paper.ClientOption.CHAT_VISIBILITY == type) {
|
2021-06-14 03:06:38 +02:00
|
|
|
+ return type.getType().cast(getHandle().getChatVisibility() == null ? com.destroystokyo.paper.ClientOption.ChatVisibility.UNKNOWN : com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(getHandle().getChatVisibility().name()));
|
2022-10-27 01:09:03 +02:00
|
|
|
+ } else if (com.destroystokyo.paper.ClientOption.LOCALE == type) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return type.getType().cast(getLocale());
|
2022-10-27 01:09:03 +02:00
|
|
|
+ } else if (com.destroystokyo.paper.ClientOption.MAIN_HAND == type) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return type.getType().cast(getMainHand());
|
2022-10-27 01:09:03 +02:00
|
|
|
+ } else if (com.destroystokyo.paper.ClientOption.VIEW_DISTANCE == type) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return type.getType().cast(getClientViewDistance());
|
2022-10-27 01:09:03 +02:00
|
|
|
+ } else if (com.destroystokyo.paper.ClientOption.ALLOW_SERVER_LISTINGS == type) {
|
|
|
|
+ return type.getType().cast(getHandle().allowsListing());
|
|
|
|
+ } else if (com.destroystokyo.paper.ClientOption.TEXT_FILTERING_ENABLED == type) {
|
|
|
|
+ return type.getType().cast(getHandle().isTextFilteringEnabled());
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ throw new RuntimeException("Unknown settings type");
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
2021-06-14 03:06:38 +02:00
|
|
|
@Override
|
2021-08-14 06:11:12 +02:00
|
|
|
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
|
2023-09-25 01:05:05 +02:00
|
|
|
index 0000000000000000000000000000000000000000..7f8b6462d2a1bbd39a870d2543bebc135f7eb45b
|
2021-08-14 06:11:12 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
2022-06-08 17:31:27 +02:00
|
|
|
@@ -0,0 +1,18 @@
|
2021-08-14 06:11:12 +02:00
|
|
|
+package io.papermc.paper.world;
|
|
|
|
+
|
|
|
|
+import com.destroystokyo.paper.ClientOption;
|
|
|
|
+import net.minecraft.world.entity.player.ChatVisiblity;
|
|
|
|
+import org.bukkit.Difficulty;
|
2023-09-24 09:16:58 +02:00
|
|
|
+import org.junit.jupiter.api.Assertions;
|
|
|
|
+import org.junit.jupiter.api.Test;
|
2021-08-14 06:11:12 +02:00
|
|
|
+
|
|
|
|
+public class TranslationKeyTest {
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void testChatVisibilityKeys() {
|
|
|
|
+ for (ClientOption.ChatVisibility chatVisibility : ClientOption.ChatVisibility.values()) {
|
|
|
|
+ if (chatVisibility == ClientOption.ChatVisibility.UNKNOWN) continue;
|
2023-09-25 01:05:05 +02:00
|
|
|
+ Assertions.assertEquals(ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey(), chatVisibility + "'s translation key doesn't match");
|
2021-08-14 06:11:12 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|