Paper/patches/server/0410-Implement-Player-Client-Options-API.patch

141 Zeilen
7.3 KiB
Diff

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MiniDigger <admin@minidigger.me>
Date: Mon, 20 Jan 2020 21:38:15 +0100
Subject: [PATCH] Implement Player Client Options API
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
2021-06-15 07:49:09 +02:00
index 37fcc83cbaf8e80809c994b18f5a7f3f6d807202..efc6e03e86867665fc655e5a3e0f154af066ef24 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
2021-06-14 04:43:29 +02:00
@@ -1802,6 +1802,7 @@ public class ServerPlayer extends Player {
2021-06-11 14:02:28 +02:00
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(), packet.language, packet.viewDistance, com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(packet.getChatVisibility().name()), packet.getChatColors(), new com.destroystokyo.paper.PaperSkinParts(packet.getModelCustomisation()), packet.getMainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT).callEvent(); // Paper - settings event
2021-06-11 14:02:28 +02:00
// CraftBukkit start
if (getMainArm() != packet.getMainHand()) {
PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(this.getBukkitEntity(), getMainArm() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT);
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
index a3d31cec6d1b8de700b6cd2f7f51398debef5b6d..b916f629c2a0fb018cba19aaa612cbbcbb597dc1 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
@@ -144,7 +144,7 @@ public abstract class Player extends LivingEntity {
private static final int FLY_ACHIEVEMENT_SPEED = 25;
2021-06-11 14:02:28 +02:00
private static final EntityDataAccessor<Float> DATA_PLAYER_ABSORPTION_ID = SynchedEntityData.defineId(Player.class, EntityDataSerializers.FLOAT);
private static final EntityDataAccessor<Integer> DATA_SCORE_ID = SynchedEntityData.defineId(Player.class, EntityDataSerializers.INT);
- protected static final EntityDataAccessor<Byte> DATA_PLAYER_MODE_CUSTOMISATION = SynchedEntityData.defineId(Player.class, EntityDataSerializers.BYTE);
+ public static final EntityDataAccessor<Byte> DATA_PLAYER_MODE_CUSTOMISATION = SynchedEntityData.defineId(Player.class, EntityDataSerializers.BYTE); // Paper - protected -> public
2021-06-11 14:02:28 +02:00
protected static final EntityDataAccessor<Byte> DATA_PLAYER_MAIN_HAND = SynchedEntityData.defineId(Player.class, EntityDataSerializers.BYTE);
protected static final EntityDataAccessor<CompoundTag> DATA_SHOULDER_LEFT = SynchedEntityData.defineId(Player.class, EntityDataSerializers.COMPOUND_TAG);
protected static final EntityDataAccessor<CompoundTag> DATA_SHOULDER_RIGHT = SynchedEntityData.defineId(Player.class, EntityDataSerializers.COMPOUND_TAG);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 2ed7920b0e046bc9d581878a10b04ad784bb8655..0a6d6ea67eaf8b2a59ec45fb3ffb85096f509997 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
@@ -516,6 +516,24 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
public void setViewDistance(int viewDistance) {
throw new NotImplementedException("Per-Player View Distance APIs need further understanding to properly implement (There are per world view distances though!)"); // TODO
}
+
+ @Override
+ public <T> T getClientOption(com.destroystokyo.paper.ClientOption<T> type) {
+ if(com.destroystokyo.paper.ClientOption.SKIN_PARTS.equals(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.equals(type)) {
+ return type.getType().cast(getHandle().canChatInColor());
+ } else if(com.destroystokyo.paper.ClientOption.CHAT_VISIBILITY.equals(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.equals(type)) {
2021-06-11 14:02:28 +02:00
+ return type.getType().cast(getLocale());
+ } else if(com.destroystokyo.paper.ClientOption.MAIN_HAND.equals(type)) {
2021-06-11 14:02:28 +02:00
+ return type.getType().cast(getMainHand());
+ } else if(com.destroystokyo.paper.ClientOption.VIEW_DISTANCE.equals(type)) {
2021-06-11 14:02:28 +02:00
+ return type.getType().cast(getClientViewDistance());
+ }
+ throw new RuntimeException("Unknown settings type");
+ }
// Paper end
@Override