papermc/Spigot-Server-Patches/0336-Extend-player-profile-API-to-support-skin-changes.patch
2018-07-21 16:54:52 +01:00

64 lines
2.7 KiB
Diff

From 95e357f7dd549b278714a9ea76bf6d11d6c2b5fd Mon Sep 17 00:00:00 2001
From: NickAcPT <32451103+NickAcPT@users.noreply.github.com>
Date: Sat, 21 Jul 2018 01:30:30 +0100
Subject: [PATCH] Extend player profile API to support skin changes
Added code that refreshes the player's skin by sending packets with a special order, telling the client to respawn the player and re-apply the game profile
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 6cbf429f..57f17120 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -55,6 +55,7 @@ import org.bukkit.craftbukkit.CraftStatistic;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.advancement.CraftAdvancement;
import org.bukkit.craftbukkit.advancement.CraftAdvancementProgress;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.map.CraftMapView;
import org.bukkit.craftbukkit.map.RenderData;
import org.bukkit.craftbukkit.scoreboard.CraftScoreboard;
@@ -1176,10 +1177,41 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
for (EntityPlayer player : players) {
player.getBukkitEntity().reregisterPlayer(self);
}
+ refreshPlayer();
}
public PlayerProfile getPlayerProfile() {
return new CraftPlayerProfile(this).clone();
}
+
+ private void refreshPlayer() {
+ EntityPlayer entityplayer = getHandle();
+
+ Packet respawn = new PacketPlayOutRespawn(entityplayer.dimension, entityplayer.world.getDifficulty(), entityplayer.world.getWorldData().getType(), entityplayer.playerInteractManager.getGameMode());
+ Location l = getLocation();
+ Packet pos = new PacketPlayOutPosition(l.getX(), l.getY(), l.getZ(), l.getYaw(), l.getPitch(), new HashSet<>(), 0);
+ Packet slot = new PacketPlayOutHeldItemSlot(getInventory().getHeldItemSlot());
+
+ EntityPlayer handle = getHandle();
+ PlayerConnection playerCon = handle.playerConnection;
+ reregisterPlayer(handle);
+
+ //Respawn the player then update their position and selected slot
+ playerCon.sendPacket(respawn);
+ handle.updateAbilities();
+ playerCon.sendPacket(pos);
+ playerCon.sendPacket(slot);
+
+ updateScaledHealth();
+ this.updateInventory();
+
+ handle.triggerHealthUpdate();
+
+ if (this.isOp()) {
+ this.setOp(false);
+ this.setOp(true);
+ }
+
+ }
// Paper end
public void removeDisconnectingPlayer(Player player) {
--
2.16.2.windows.1