PaperMC/Spigot-Server-Patches/0200-Player.setPlayerProfile-API.patch
Riley Park 4e958e229f
We're going on an Adventure! (#4842)
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
Co-authored-by: zml <zml@stellardrift.ca>
Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com>
2021-02-21 20:45:33 +01:00

134 lines
7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sun, 18 Mar 2018 12:29:48 -0400
Subject: [PATCH] Player.setPlayerProfile API
This can be useful for changing name or skins after a player has logged in.
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index a4bdedde80eee8bac475854735284826f06fcaef..3df97e5a4a85efa8a77808e58039afc0c7fe073b 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -63,7 +63,7 @@ public abstract class EntityHuman extends EntityLiving {
protected int bG;
protected final float bH = 0.02F;
private int g;
- private final GameProfile bJ;
+ private GameProfile bJ; public final void setProfile(final GameProfile profile) { this.bJ = profile; } // Paper - OBFHELPER
private ItemStack bL;
private final ItemCooldown bM;
@Nullable
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
index 92f42f17d7f554fca819d63c1f9401239894e0e1..066b0dbdbc101a8235fb872c2d1e9d427dfd6bb8 100644
--- a/src/main/java/net/minecraft/server/LoginListener.java
+++ b/src/main/java/net/minecraft/server/LoginListener.java
@@ -38,7 +38,7 @@ public class LoginListener implements PacketLoginInListener {
public final NetworkManager networkManager;
private LoginListener.EnumProtocolState g;
private int h;
- private GameProfile i;
+ private GameProfile i; private void setGameProfile(final GameProfile profile) { this.i = profile; } private GameProfile getGameProfile() { return this.i; } // Paper - OBFHELPER
private final String j;
private SecretKey loginKey;
private EntityPlayer l;
@@ -301,12 +301,12 @@ public class LoginListener implements PacketLoginInListener {
final org.bukkit.craftbukkit.CraftServer server = LoginListener.this.server.server;
// Paper start
- PlayerProfile profile = Bukkit.createProfile(uniqueId, playerName);
+ PlayerProfile profile = CraftPlayerProfile.asBukkitMirror(getGameProfile());
AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId, profile);
server.getPluginManager().callEvent(asyncEvent);
profile = asyncEvent.getPlayerProfile();
- profile.complete();
- i = CraftPlayerProfile.asAuthlibCopy(profile);
+ profile.complete(true);
+ setGameProfile(CraftPlayerProfile.asAuthlib(profile));
playerName = i.getName();
uniqueId = i.getId();
// Paper end
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 8c72a53f1bf8846983122d3398ca22e70f1c429a..9398ec912372ffd4cd7042b9834290fa574b71b7 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1325,8 +1325,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
hiddenPlayers.put(player.getUniqueId(), hidingPlugins);
// Remove this player from the hidden player's EntityTrackerEntry
- PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
+ // Paper start
EntityPlayer other = ((CraftPlayer) player).getHandle();
+ unregisterPlayer(other);
+ }
+ private void unregisterPlayer(EntityPlayer other) {
+ PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
+ // Paper end
PlayerChunkMap.EntityTracker entry = tracker.trackedEntities.get(other.getId());
if (entry != null) {
entry.clear(getHandle());
@@ -1367,8 +1372,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
hiddenPlayers.remove(player.getUniqueId());
- PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
+ // Paper start
EntityPlayer other = ((CraftPlayer) player).getHandle();
+ registerPlayer(other);
+ }
+ private void registerPlayer(EntityPlayer other) {
+ PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
+ // Paper end
getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, other));
@@ -1377,6 +1387,50 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
entry.updatePlayer(getHandle());
}
}
+ // Paper start
+ private void reregisterPlayer(EntityPlayer player) {
+ if (!hiddenPlayers.containsKey(player.getUniqueID())) {
+ unregisterPlayer(player);
+ registerPlayer(player);
+ }
+ }
+ public void setPlayerProfile(com.destroystokyo.paper.profile.PlayerProfile profile) {
+ EntityPlayer self = getHandle();
+ self.setProfile(com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile));
+ if (!self.sentListPacket) {
+ return;
+ }
+ List<EntityPlayer> players = server.getServer().getPlayerList().players;
+ for (EntityPlayer player : players) {
+ player.getBukkitEntity().reregisterPlayer(self);
+ }
+ refreshPlayer();
+ }
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() {
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(this).clone();
+ }
+
+ private void refreshPlayer() {
+ EntityPlayer handle = getHandle();
+
+ Location loc = getLocation();
+
+ PlayerConnection connection = handle.playerConnection;
+ reregisterPlayer(handle);
+
+ //Respawn the player then update their position and selected slot
+ WorldServer worldserver = handle.getWorldServer();
+ connection.sendPacket(new net.minecraft.server.PacketPlayOutRespawn(worldserver.getDimensionManager(), worldserver.getDimensionKey(), net.minecraft.server.BiomeManager.a(worldserver.getSeed()), handle.playerInteractManager.getGameMode(), handle.playerInteractManager.c(), worldserver.isDebugWorld(), worldserver.isFlatWorld(), true));
+ handle.updateAbilities();
+ connection.sendPacket(new net.minecraft.server.PacketPlayOutPosition(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), new HashSet<>(), 0));
+ net.minecraft.server.MinecraftServer.getServer().getPlayerList().updateClient(handle);
+
+ if (this.isOp()) {
+ this.setOp(false);
+ this.setOp(true);
+ }
+ }
+ // Paper end
public void removeDisconnectingPlayer(Player player) {
hiddenPlayers.remove(player.getUniqueId());