2020-05-06 11:48:49 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-03-18 17:32:09 +01:00
|
|
|
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
|
2021-01-29 01:32:08 +01:00
|
|
|
index a4bdedde80eee8bac475854735284826f06fcaef..3df97e5a4a85efa8a77808e58039afc0c7fe073b 100644
|
2018-03-18 17:32:09 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
2021-01-29 01:32:08 +01:00
|
|
|
@@ -63,7 +63,7 @@ public abstract class EntityHuman extends EntityLiving {
|
2020-08-25 04:22:08 +02:00
|
|
|
protected int bG;
|
|
|
|
protected final float bH = 0.02F;
|
2020-06-25 16:09:55 +02:00
|
|
|
private int g;
|
2020-08-25 04:22:08 +02:00
|
|
|
- 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;
|
2018-03-18 17:32:09 +01:00
|
|
|
@Nullable
|
2018-03-23 02:40:57 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
|
2021-02-21 20:45:33 +01:00
|
|
|
index 92f42f17d7f554fca819d63c1f9401239894e0e1..066b0dbdbc101a8235fb872c2d1e9d427dfd6bb8 100644
|
2018-03-23 02:40:57 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/LoginListener.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/LoginListener.java
|
2021-02-21 20:45:33 +01:00
|
|
|
@@ -38,7 +38,7 @@ public class LoginListener implements PacketLoginInListener {
|
2018-03-23 02:40:57 +01:00
|
|
|
public final NetworkManager networkManager;
|
|
|
|
private LoginListener.EnumProtocolState g;
|
|
|
|
private int h;
|
|
|
|
- private GameProfile i;
|
2019-04-28 19:59:47 +02:00
|
|
|
+ private GameProfile i; private void setGameProfile(final GameProfile profile) { this.i = profile; } private GameProfile getGameProfile() { return this.i; } // Paper - OBFHELPER
|
2018-03-23 02:40:57 +01:00
|
|
|
private final String j;
|
|
|
|
private SecretKey loginKey;
|
|
|
|
private EntityPlayer l;
|
2021-02-21 20:45:33 +01:00
|
|
|
@@ -301,12 +301,12 @@ public class LoginListener implements PacketLoginInListener {
|
2020-11-03 03:22:15 +01:00
|
|
|
final org.bukkit.craftbukkit.CraftServer server = LoginListener.this.server.server;
|
2018-03-23 02:40:57 +01:00
|
|
|
|
|
|
|
// Paper start
|
|
|
|
- PlayerProfile profile = Bukkit.createProfile(uniqueId, playerName);
|
|
|
|
+ PlayerProfile profile = CraftPlayerProfile.asBukkitMirror(getGameProfile());
|
|
|
|
AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId, profile);
|
2020-11-03 03:22:15 +01:00
|
|
|
server.getPluginManager().callEvent(asyncEvent);
|
2018-03-23 02:40:57 +01:00
|
|
|
profile = asyncEvent.getPlayerProfile();
|
|
|
|
- profile.complete();
|
|
|
|
- i = CraftPlayerProfile.asAuthlibCopy(profile);
|
|
|
|
+ profile.complete(true);
|
|
|
|
+ setGameProfile(CraftPlayerProfile.asAuthlib(profile));
|
|
|
|
playerName = i.getName();
|
|
|
|
uniqueId = i.getId();
|
|
|
|
// Paper end
|
2018-03-18 17:32:09 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2021-02-24 10:32:17 +01:00
|
|
|
index d2f8b4b324b2a9719f409871afde88ad21a94efe..d9d7e5e6f3a5a84db61afefcc80ac723ce9f728a 100644
|
2018-03-18 17:32:09 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2021-02-24 10:32:17 +01:00
|
|
|
@@ -1338,8 +1338,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2018-03-18 17:32:09 +01:00
|
|
|
hiddenPlayers.put(player.getUniqueId(), hidingPlugins);
|
|
|
|
|
|
|
|
// Remove this player from the hidden player's EntityTrackerEntry
|
2019-04-28 19:59:47 +02:00
|
|
|
- PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-18 17:32:09 +01:00
|
|
|
+ // Paper start
|
2019-04-28 19:59:47 +02:00
|
|
|
EntityPlayer other = ((CraftPlayer) player).getHandle();
|
2018-03-18 17:32:09 +01:00
|
|
|
+ unregisterPlayer(other);
|
|
|
|
+ }
|
|
|
|
+ private void unregisterPlayer(EntityPlayer other) {
|
2019-04-28 19:59:47 +02:00
|
|
|
+ PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-18 17:32:09 +01:00
|
|
|
+ // Paper end
|
2019-04-28 19:59:47 +02:00
|
|
|
PlayerChunkMap.EntityTracker entry = tracker.trackedEntities.get(other.getId());
|
2018-03-18 17:32:09 +01:00
|
|
|
if (entry != null) {
|
|
|
|
entry.clear(getHandle());
|
2021-02-24 10:32:17 +01:00
|
|
|
@@ -1380,8 +1385,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2018-03-18 17:32:09 +01:00
|
|
|
}
|
|
|
|
hiddenPlayers.remove(player.getUniqueId());
|
|
|
|
|
2019-04-28 19:59:47 +02:00
|
|
|
- PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-18 17:32:09 +01:00
|
|
|
+ // Paper start
|
|
|
|
EntityPlayer other = ((CraftPlayer) player).getHandle();
|
2018-03-20 17:27:00 +01:00
|
|
|
+ registerPlayer(other);
|
2018-03-18 17:32:09 +01:00
|
|
|
+ }
|
|
|
|
+ private void registerPlayer(EntityPlayer other) {
|
2019-04-28 19:59:47 +02:00
|
|
|
+ PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-18 17:32:09 +01:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, other));
|
|
|
|
|
2021-02-24 10:32:17 +01:00
|
|
|
@@ -1390,6 +1400,50 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2018-03-18 17:32:09 +01:00
|
|
|
entry.updatePlayer(getHandle());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
|
|
+ private void reregisterPlayer(EntityPlayer player) {
|
|
|
|
+ if (!hiddenPlayers.containsKey(player.getUniqueID())) {
|
|
|
|
+ unregisterPlayer(player);
|
|
|
|
+ registerPlayer(player);
|
|
|
|
+ }
|
|
|
|
+ }
|
2020-08-25 04:22:08 +02:00
|
|
|
+ public void setPlayerProfile(com.destroystokyo.paper.profile.PlayerProfile profile) {
|
2018-03-18 17:32:09 +01:00
|
|
|
+ EntityPlayer self = getHandle();
|
2020-08-25 04:22:08 +02:00
|
|
|
+ self.setProfile(com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile));
|
2020-02-22 15:13:29 +01:00
|
|
|
+ if (!self.sentListPacket) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
2018-03-18 17:32:09 +01:00
|
|
|
+ List<EntityPlayer> players = server.getServer().getPlayerList().players;
|
|
|
|
+ for (EntityPlayer player : players) {
|
|
|
|
+ player.getBukkitEntity().reregisterPlayer(self);
|
|
|
|
+ }
|
2018-07-24 02:31:33 +02:00
|
|
|
+ refreshPlayer();
|
2018-03-18 17:32:09 +01:00
|
|
|
+ }
|
2020-08-25 04:22:08 +02:00
|
|
|
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() {
|
|
|
|
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(this).clone();
|
2018-03-18 17:32:09 +01:00
|
|
|
+ }
|
2018-07-24 02:31:33 +02:00
|
|
|
+
|
|
|
|
+ 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
|
2020-06-28 13:16:36 +02:00
|
|
|
+ WorldServer worldserver = handle.getWorldServer();
|
2020-08-25 04:22:08 +02:00
|
|
|
+ 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));
|
2018-07-24 02:31:33 +02:00
|
|
|
+ handle.updateAbilities();
|
2018-07-24 05:20:41 +02:00
|
|
|
+ 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);
|
2018-07-24 02:31:33 +02:00
|
|
|
+
|
|
|
|
+ if (this.isOp()) {
|
|
|
|
+ this.setOp(false);
|
|
|
|
+ this.setOp(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
2018-03-18 17:32:09 +01:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
public void removeDisconnectingPlayer(Player player) {
|
|
|
|
hiddenPlayers.remove(player.getUniqueId());
|