2020-05-06 09:48:49 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2020-04-17 04:10:38 +00:00
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
2020-05-06 09:48:49 +00:00
index 0000000000000000000000000000000000000000..b6f4400df3d8ec7e06a996de54f8cabba57885e1
2020-04-17 04:10:38 +00:00
--- /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/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
2020-08-25 02:22:08 +00:00
index eae7bfa171e648b8ec51465a8d9f7d9b7c59a2c9..ce4ebc96c01f3dacf4e4d0569d86f52140440d43 100644
2020-04-17 04:10:38 +00:00
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
2020-06-26 01:53:21 +00:00
@@ -36,7 +36,7 @@ public abstract class EntityHuman extends EntityLiving {
2020-08-25 02:22:08 +00:00
private static final Map<EntityPose, EntitySize> b = ImmutableMap.<EntityPose, EntitySize>builder().put(EntityPose.STANDING, EntityHuman.bh).put(EntityPose.SLEEPING, EntityHuman.ah).put(EntityPose.FALL_FLYING, EntitySize.b(0.6F, 0.6F)).put(EntityPose.SWIMMING, EntitySize.b(0.6F, 0.6F)).put(EntityPose.SPIN_ATTACK, EntitySize.b(0.6F, 0.6F)).put(EntityPose.CROUCHING, EntitySize.b(0.6F, 1.5F)).put(EntityPose.DYING, EntitySize.c(0.2F, 0.2F)).build();
2020-04-17 04:10:38 +00:00
private static final DataWatcherObject<Float> c = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.c);
private static final DataWatcherObject<Integer> d = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.b);
2020-08-25 02:22:08 +00:00
- protected static final DataWatcherObject<Byte> bi = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.a);
+ protected static final DataWatcherObject<Byte> bi = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.a); public static DataWatcherObject<Byte> getSkinPartsWatcher() { return bi; } // Paper - OBFHELPER
protected static final DataWatcherObject<Byte> bj = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.a);
protected static final DataWatcherObject<NBTTagCompound> bk = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.p);
protected static final DataWatcherObject<NBTTagCompound> bl = DataWatcher.a(EntityHuman.class, DataWatcherRegistry.p);
2020-04-17 04:10:38 +00:00
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
2020-08-26 08:22:13 +00:00
index 4d117ed0de75672fe95341832ec032b665179b39..a5e3ba2ed7369473f61d0e5ceca58ac2b44ea3ee 100644
2020-04-17 04:10:38 +00:00
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -2,6 +2,7 @@ package net.minecraft.server;
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;
2020-06-26 01:53:21 +00:00
import com.mojang.serialization.DataResult;
2020-08-25 02:22:08 +00:00
@@ -60,7 +61,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
2020-04-17 04:10:38 +00:00
public int lastSentExp = -99999999;
public int invulnerableTicks = 60;
2020-08-25 02:22:08 +00:00
private EnumChatVisibility bY;
- private boolean bZ = true;
+ private boolean bZ = true; public boolean hasChatColorsEnabled() { return this.bZ; } // Paper - OBFHELPER
private long ca = SystemUtils.getMonotonicMillis();
2020-05-14 23:05:00 +00:00
private Entity spectatedEntity;
2020-04-17 04:10:38 +00:00
public boolean worldChangeInvuln;
2020-08-26 08:22:13 +00:00
@@ -1653,6 +1654,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
2020-04-17 04:10:38 +00:00
2020-06-26 01:53:21 +00:00
public String locale = null; // CraftBukkit - lowercase // Paper - default to null
2020-04-17 04:10:38 +00:00
public void a(PacketPlayInSettings packetplayinsettings) {
2020-08-02 05:39:36 +00:00
+ new PlayerClientOptionsChangeEvent(getBukkitEntity(), packetplayinsettings.locale, packetplayinsettings.viewDistance, com.destroystokyo.paper.ClientOption.ChatVisibility.valueOf(packetplayinsettings.getChatVisibility().name()), packetplayinsettings.hasChatColorsEnabled(), new com.destroystokyo.paper.PaperSkinParts(packetplayinsettings.getSkinParts()), packetplayinsettings.getMainHand() == EnumMainHand.LEFT ? MainHand.LEFT : MainHand.RIGHT).callEvent(); // Paper - settings event
2020-04-17 04:10:38 +00:00
// CraftBukkit start
if (getMainHand() != packetplayinsettings.getMainHand()) {
PlayerChangedMainHandEvent event = new PlayerChangedMainHandEvent(getBukkitEntity(), getMainHand() == EnumMainHand.LEFT ? MainHand.LEFT : MainHand.RIGHT);
diff --git a/src/main/java/net/minecraft/server/PacketPlayInSettings.java b/src/main/java/net/minecraft/server/PacketPlayInSettings.java
2020-08-02 05:39:36 +00:00
index dbc3552d50c4129e1844c8a379ab5ba396645f52..87ec3987d4b6de836016e91ef90383e3e5bb2d16 100644
2020-04-17 04:10:38 +00:00
--- a/src/main/java/net/minecraft/server/PacketPlayInSettings.java
+++ b/src/main/java/net/minecraft/server/PacketPlayInSettings.java
2020-06-26 01:53:21 +00:00
@@ -37,14 +37,17 @@ public class PacketPlayInSettings implements Packet<PacketListenerPlayIn> {
packetlistenerplayin.a(this);
2020-04-17 04:10:38 +00:00
}
+ public EnumChatVisibility getChatVisibility() { return d(); } // Paper - OBFHELPER
public EnumChatVisibility d() {
return this.c;
}
+ public boolean hasChatColorsEnabled() { return e(); } // Paper - OBFHELPER
public boolean e() {
return this.d;
}
+ public int getSkinParts() { return f(); } // Paper - OBFHELPER
public int f() {
return this.e;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2020-08-25 02:22:08 +00:00
index 747dd3c06d24b395d9d940413fe47a63b66e65d0..ff18c2d8c4752149ace290495d130e12baa52756 100644
2020-04-17 04:10:38 +00:00
--- 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;
2020-08-25 02:22:08 +00:00
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
@@ -2034,6 +2037,24 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2020-04-17 04:10:38 +00:00
public void setViewDistance(int viewDistance) {
2020-05-06 07:44:47 +00:00
throw new NotImplementedException("Per-Player View Distance APIs need further understanding to properly implement (There are per world view distances though!)"); // TODO
2020-04-17 04:10:38 +00:00
}
+
+ @Override
+ public <T> T getClientOption(ClientOption<T> type) {
+ if(ClientOption.SKIN_PARTS.equals(type)) {
+ return type.getType().cast(new PaperSkinParts(getHandle().getDataWatcher().get(EntityHuman.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().getChatFlags() == null ? ChatVisibility.UNKNOWN : ChatVisibility.valueOf(getHandle().getChatFlags().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