mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-06 10:49:40 +01:00
189 lines
9.9 KiB
Diff
189 lines
9.9 KiB
Diff
|
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/network/protocol/game/ServerboundClientInformationPacket.java b/src/main/java/net/minecraft/network/protocol/game/ServerboundClientInformationPacket.java
|
||
|
index 1f486cfd77b49568540398b1b3fa6127b17ba6aa..4b43740f9ff4feab4f1cd2f8e91d55be3cf8eb50 100644
|
||
|
--- a/src/main/java/net/minecraft/network/protocol/game/ServerboundClientInformationPacket.java
|
||
|
+++ b/src/main/java/net/minecraft/network/protocol/game/ServerboundClientInformationPacket.java
|
||
|
@@ -41,14 +41,17 @@ public class ServerboundClientInformationPacket implements Packet<ServerGamePack
|
||
|
listener.handleClientInformation(this);
|
||
|
}
|
||
|
|
||
|
+ public ChatVisiblity getChatVisibility() { return getChatVisibility(); } // Paper - OBFHELPER
|
||
|
public ChatVisiblity getChatVisibility() {
|
||
|
return this.chatVisibility;
|
||
|
}
|
||
|
|
||
|
+ public boolean hasChatColorsEnabled() { return getChatColors(); } // Paper - OBFHELPER
|
||
|
public boolean getChatColors() {
|
||
|
return this.chatColors;
|
||
|
}
|
||
|
|
||
|
+ public int getSkinParts() { return getModelCustomisation(); } // Paper - OBFHELPER
|
||
|
public int getModelCustomisation() {
|
||
|
return this.modelCustomisation;
|
||
|
}
|
||
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||
|
index efacfcaab444270b985f3a7fe0ef97e33c18a9de..aa979d17c264840ebd528708df3d6118e69fec68 100644
|
||
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
||
|
@@ -2,6 +2,7 @@ package net.minecraft.server.level;
|
||
|
|
||
|
import com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent;
|
||
|
import com.google.common.collect.Lists;
|
||
|
+import com.destroystokyo.paper.event.player.PlayerClientOptionsChangeEvent; // Paper
|
||
|
import com.mojang.authlib.GameProfile;
|
||
|
import com.mojang.datafixers.util.Either;
|
||
|
import com.mojang.serialization.DataResult;
|
||
|
@@ -188,7 +189,7 @@ public class ServerPlayer extends Player implements ContainerListener {
|
||
|
public int lastSentExp = -99999999;
|
||
|
public int spawnInvulnerableTime = 60;
|
||
|
private ChatVisiblity chatVisibility;
|
||
|
- private boolean canChatColor = true;
|
||
|
+ private boolean canChatColor = true; public boolean hasChatColorsEnabled() { return this.canChatColor; } // Paper - OBFHELPER
|
||
|
private long lastActionTime = Util.getMillis();
|
||
|
private Entity camera;
|
||
|
public boolean isChangingDimension;
|
||
|
@@ -1807,6 +1808,7 @@ public class ServerPlayer extends Player implements ContainerListener {
|
||
|
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 PlayerClientOptionsChangeEvent(getBukkitEntity(), packet.language, packet.viewDistance, com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(packet.getChatVisibility().name()), packet.hasChatColorsEnabled(), new com.destroystokyo.paper.PaperSkinParts(packet.getSkinParts()), packet.getMainHand() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT).callEvent(); // Paper - settings event
|
||
|
// CraftBukkit start
|
||
|
if (getMainArm() != packet.getMainHand()) {
|
||
|
PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(getBukkitEntity(), getMainArm() == HumanoidArm.LEFT ? MainHand.LEFT : MainHand.RIGHT);
|
||
|
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 32f1b180e82f41f3ce1b49ea7d67b7d55d2b9ca7..525cd44411b344bc4b5d43c087094fea88fa41a6 100644
|
||
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
||
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
||
|
@@ -130,7 +130,7 @@ public abstract class Player extends LivingEntity {
|
||
|
private static final Map<Pose, EntityDimensions> POSES = ImmutableMap.<Pose, EntityDimensions>builder().put(Pose.STANDING, Player.STANDING_DIMENSIONS).put(Pose.SLEEPING, Player.SLEEPING_DIMENSIONS).put(Pose.FALL_FLYING, EntityDimensions.scalable(0.6F, 0.6F)).put(Pose.SWIMMING, EntityDimensions.scalable(0.6F, 0.6F)).put(Pose.SPIN_ATTACK, EntityDimensions.scalable(0.6F, 0.6F)).put(Pose.CROUCHING, EntityDimensions.scalable(0.6F, 1.5F)).put(Pose.DYING, EntityDimensions.fixed(0.2F, 0.2F)).build();
|
||
|
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);
|
||
|
+ protected static final EntityDataAccessor<Byte> DATA_PLAYER_MODE_CUSTOMISATION = SynchedEntityData.defineId(Player.class, EntityDataSerializers.BYTE); public static EntityDataAccessor<Byte> getSkinPartsWatcher() { return DATA_PLAYER_MODE_CUSTOMISATION; } // Paper - OBFHELPER
|
||
|
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 20de8e358789d05bb5ac15e4cdd7dda85b61b7f8..eb366396820c9b6731469df4198e0884a431a77c 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||
|
@@ -1,5 +1,8 @@
|
||
|
package org.bukkit.craftbukkit.entity;
|
||
|
|
||
|
+import com.destroystokyo.paper.ClientOption.ChatVisibility;
|
||
|
+import com.destroystokyo.paper.PaperSkinParts;
|
||
|
+import com.destroystokyo.paper.ClientOption;
|
||
|
import com.destroystokyo.paper.Title;
|
||
|
import com.google.common.base.Preconditions;
|
||
|
import com.google.common.collect.ImmutableSet;
|
||
|
@@ -2250,6 +2253,24 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||
|
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(ClientOption<T> type) {
|
||
|
+ if(ClientOption.SKIN_PARTS.equals(type)) {
|
||
|
+ return type.getType().cast(new PaperSkinParts(getHandle().getEntityData().get(net.minecraft.world.entity.player.Player.getSkinPartsWatcher())));
|
||
|
+ } else if(ClientOption.CHAT_COLORS_ENABLED.equals(type)) {
|
||
|
+ return type.getType().cast(getHandle().hasChatColorsEnabled());
|
||
|
+ } else if(ClientOption.CHAT_VISIBILITY.equals(type)) {
|
||
|
+ return type.getType().cast(getHandle().getChatVisibility() == null ? ChatVisibility.UNKNOWN : ChatVisibility.valueOf(getHandle().getChatVisibility().name()));
|
||
|
+ } else if(ClientOption.LOCALE.equals(type)) {
|
||
|
+ return type.getType().cast(getLocale());
|
||
|
+ } else if(ClientOption.MAIN_HAND.equals(type)) {
|
||
|
+ return type.getType().cast(getMainHand());
|
||
|
+ } else if(ClientOption.VIEW_DISTANCE.equals(type)) {
|
||
|
+ return type.getType().cast(getClientViewDistance());
|
||
|
+ }
|
||
|
+ throw new RuntimeException("Unknown settings type");
|
||
|
+ }
|
||
|
// Paper end
|
||
|
|
||
|
// Spigot start
|