mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
2fa8efce9b
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: 82af5dc6 SPIGOT-7396: Add PlayerSignOpenEvent 3f0281ca SPIGOT-7063, PR-763: Add DragonBattle#initiateRespawn with custom EnderCrystals f83c8df4 PR-873: Add PlayerRecipeBookClickEvent 14560d39 SPIGOT-7435: Add TeleportCause#EXIT_BED 2cc6db92 SPIGOT-7422, PR-887: Add API to set sherds on decorated pots 36022f02 PR-883: Add ItemFactory#getSpawnEgg 12eb5c46 PR-881: Update Scoreboard Javadocs, remove explicit exception throwing f6d8d44a PR-882: Add modern time API methods to ban API 21a7b710 Upgrade some Maven plugins to reduce warnings 11fd1225 PR-886: Deprecate the SmithingRecipe constructor as it now does nothing dbd1761d SPIGOT-7406: Improve documentation for getDragonBattle CraftBukkit Changes: d548daac2 SPIGOT-7446: BlockState#update not updating a spawner's type to null 70e0bc050 SPIGOT-7447: Fix --forceUpgrade 6752f1d63 SPIGOT-7396: Add PlayerSignOpenEvent 847b4cad5 SPIGOT-7063, PR-1071: Add DragonBattle#initiateRespawn with custom EnderCrystals c335a555f PR-1212: Add PlayerRecipeBookClickEvent 4be756ecb SPIGOT-7445: Fix opening smithing inventory db70bd6ed SPIGOT-7441: Fix issue placing certain items in creative/op f7fa6d993 SPIGOT-7435: Add TeleportCause#EXIT_BED b435e8e8d SPIGOT-7349: Player#setDisplayName not working when message/format unmodified a2fafdd1d PR-1232: Re-add fix for player rotation 7cf863de1 PR-1233: Remove some old MC bug fixes now fixed in vanilla 08ec344ad Fix ChunkGenerator#generateCaves never being called 5daeb502a SPIGOT-7422, PR-1228: Add API to set sherds on decorated pots 52faa6b32 PR-1224: Add ItemFactory#getSpawnEgg 01cae71b7 SPIGOT-7429: Fix LEFT_CLICK_AIR not working for passable entities and spectators a94277a18 PR-1223: Remove non-existent scoreboard display name/prefix/suffix limits 36b107660 PR-1225: Add modern time API methods to ban API 59ead25bc Upgrade some Maven plugins to reduce warnings 202fc5c4e Increase outdated build delay ce545de57 SPIGOT-7398: TextDisplay#setInterpolationDuration incorrectly updates the line width Spigot Changes: b41c46db Rebuild patches 3374045a SPIGOT-7431: Fix EntityMountEvent returning opposite entities 0ca4eb66 Rebuild patches
175 lines
8.3 KiB
Diff
175 lines
8.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MiniDigger <admin@benndorf.dev>
|
|
Date: Mon, 20 Jan 2020 21:38:15 +0100
|
|
Subject: [PATCH] Implement Player Client Options API
|
|
|
|
== AT ==
|
|
public net.minecraft.world.entity.player.Player DATA_PLAYER_MODE_CUSTOMISATION
|
|
|
|
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
|
|
index 65d17836785774d0f196321ba741ffd05a9db36e..fd34a2ace2efc819b06674ceab44ff78ec11f805 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1949,9 +1949,24 @@ public class ServerPlayer extends 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 String locale = null; // CraftBukkit - add, lowercase // Paper - default to null
|
|
public java.util.Locale adventure$locale = java.util.Locale.US; // Paper
|
|
public void updateOptions(ServerboundClientInformationPacket packet) {
|
|
+ new com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent(getBukkitEntity(), getClientOptionMap(packet.language, packet.viewDistance, com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(packet.chatVisibility().name()), packet.chatColors(), new com.destroystokyo.paper.PaperSkinParts(packet.modelCustomisation()), packet.mainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT, packet.allowsListing(), packet.textFilteringEnabled())).callEvent(); // Paper - settings event
|
|
// CraftBukkit start
|
|
if (getMainArm() != packet.mainHand()) {
|
|
PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(this.getBukkitEntity(), getMainArm() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT);
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 4714d063f18806187fbd39315467ce467e30c6a2..8094fbb1aa84c93cf6660e2c7a32772bfc3ec62f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -603,6 +603,28 @@ 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)));
|
|
+ } else if (com.destroystokyo.paper.ClientOption.CHAT_COLORS_ENABLED == type) {
|
|
+ return type.getType().cast(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()));
|
|
+ } else if (com.destroystokyo.paper.ClientOption.LOCALE == type) {
|
|
+ return type.getType().cast(getLocale());
|
|
+ } else if (com.destroystokyo.paper.ClientOption.MAIN_HAND == type) {
|
|
+ return type.getType().cast(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());
|
|
+ } else if (com.destroystokyo.paper.ClientOption.TEXT_FILTERING_ENABLED == type) {
|
|
+ return type.getType().cast(getHandle().isTextFilteringEnabled());
|
|
+ }
|
|
+ throw new RuntimeException("Unknown settings type");
|
|
+ }
|
|
// Paper end
|
|
|
|
@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..fab3063fffa959ac7f0eb5937f2fae94d11b6591
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java
|
|
@@ -0,0 +1,18 @@
|
|
+package io.papermc.paper.world;
|
|
+
|
|
+import com.destroystokyo.paper.ClientOption;
|
|
+import net.minecraft.world.entity.player.ChatVisiblity;
|
|
+import org.bukkit.Difficulty;
|
|
+import org.junit.Assert;
|
|
+import org.junit.Test;
|
|
+
|
|
+public class TranslationKeyTest {
|
|
+
|
|
+ @Test
|
|
+ public void testChatVisibilityKeys() {
|
|
+ for (ClientOption.ChatVisibility chatVisibility : ClientOption.ChatVisibility.values()) {
|
|
+ if (chatVisibility == ClientOption.ChatVisibility.UNKNOWN) continue;
|
|
+ Assert.assertEquals(chatVisibility + "'s translation key doesn't match", ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey());
|
|
+ }
|
|
+ }
|
|
+}
|