2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-03-18 16:32:09 +00: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
|
2020-06-26 06:29:44 +00:00
|
|
|
index 5326e7433dc0a4ff0e1d0ca30aad95b1ec718d6a..74950d74e6a11d5552369e830f9fdd63c4306221 100644
|
2018-03-18 16:32:09 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/EntityHuman.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
|
2020-06-25 14:09:55 +00:00
|
|
|
@@ -65,7 +65,7 @@ public abstract class EntityHuman extends EntityLiving {
|
|
|
|
protected int bN;
|
|
|
|
protected final float bO = 0.02F;
|
|
|
|
private int g;
|
|
|
|
- private final GameProfile bQ;
|
2020-06-26 06:29:44 +00:00
|
|
|
+ private GameProfile bQ; public final void setProfile(final GameProfile profile) { this.bQ = profile; } // Paper - OBFHELPER
|
2020-06-25 14:09:55 +00:00
|
|
|
private ItemStack bS;
|
|
|
|
private final ItemCooldown bT;
|
2018-03-18 16:32:09 +00:00
|
|
|
@Nullable
|
2018-03-23 01:40:57 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
|
2020-06-25 14:09:55 +00:00
|
|
|
index 80a21dbc05ed3007f2e827f7a320131244c3044b..e0f0a1e91a037f93b239e779aa8fd92be8a8c01f 100644
|
2018-03-23 01:40:57 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/LoginListener.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/LoginListener.java
|
2020-06-25 14:09:55 +00:00
|
|
|
@@ -36,7 +36,7 @@ public class LoginListener implements PacketLoginInListener {
|
2018-03-23 01:40:57 +00:00
|
|
|
public final NetworkManager networkManager;
|
|
|
|
private LoginListener.EnumProtocolState g;
|
|
|
|
private int h;
|
|
|
|
- private GameProfile i;
|
2019-04-28 17:59:47 +00:00
|
|
|
+ private GameProfile i; private void setGameProfile(final GameProfile profile) { this.i = profile; } private GameProfile getGameProfile() { return this.i; } // Paper - OBFHELPER
|
2018-03-23 01:40:57 +00:00
|
|
|
private final String j;
|
|
|
|
private SecretKey loginKey;
|
|
|
|
private EntityPlayer l;
|
2020-06-25 14:09:55 +00:00
|
|
|
@@ -290,12 +290,12 @@ public class LoginListener implements PacketLoginInListener {
|
2018-03-23 01:40:57 +00:00
|
|
|
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
|
2018-03-18 16:32:09 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2020-07-22 08:01:35 +00:00
|
|
|
index d3db77324e06d7cd39f05b664e987cce7a5a06e5..172b11fc8473ee8cc18c7638cfdaa193df0e2e5e 100644
|
2018-03-18 16:32:09 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
@@ -1,6 +1,8 @@
|
|
|
|
package org.bukkit.craftbukkit.entity;
|
|
|
|
|
|
|
|
import com.destroystokyo.paper.Title;
|
|
|
|
+import com.destroystokyo.paper.profile.CraftPlayerProfile;
|
|
|
|
+import com.destroystokyo.paper.profile.PlayerProfile;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
|
import com.google.common.io.BaseEncoding;
|
2020-06-26 06:29:44 +00:00
|
|
|
@@ -41,6 +43,7 @@ import net.minecraft.server.EnumColor;
|
|
|
|
import net.minecraft.server.EnumGamemode;
|
|
|
|
import net.minecraft.server.GenericAttributes;
|
|
|
|
import net.minecraft.server.IChatBaseComponent;
|
|
|
|
+import net.minecraft.server.MCUtil;
|
|
|
|
import net.minecraft.server.MapIcon;
|
|
|
|
import net.minecraft.server.MinecraftKey;
|
|
|
|
import net.minecraft.server.NBTTagCompound;
|
2020-07-22 08:01:35 +00:00
|
|
|
@@ -1237,8 +1240,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2018-03-18 16:32:09 +00:00
|
|
|
hiddenPlayers.put(player.getUniqueId(), hidingPlugins);
|
|
|
|
|
|
|
|
// Remove this player from the hidden player's EntityTrackerEntry
|
2019-04-28 17:59:47 +00:00
|
|
|
- PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-18 16:32:09 +00:00
|
|
|
+ // Paper start
|
2019-04-28 17:59:47 +00:00
|
|
|
EntityPlayer other = ((CraftPlayer) player).getHandle();
|
2018-03-18 16:32:09 +00:00
|
|
|
+ unregisterPlayer(other);
|
|
|
|
+ }
|
|
|
|
+ private void unregisterPlayer(EntityPlayer other) {
|
2019-04-28 17:59:47 +00:00
|
|
|
+ PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-18 16:32:09 +00:00
|
|
|
+ // Paper end
|
2019-04-28 17:59:47 +00:00
|
|
|
PlayerChunkMap.EntityTracker entry = tracker.trackedEntities.get(other.getId());
|
2018-03-18 16:32:09 +00:00
|
|
|
if (entry != null) {
|
|
|
|
entry.clear(getHandle());
|
2020-07-22 08:01:35 +00:00
|
|
|
@@ -1279,8 +1287,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2018-03-18 16:32:09 +00:00
|
|
|
}
|
|
|
|
hiddenPlayers.remove(player.getUniqueId());
|
|
|
|
|
2019-04-28 17:59:47 +00:00
|
|
|
- PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-18 16:32:09 +00:00
|
|
|
+ // Paper start
|
|
|
|
EntityPlayer other = ((CraftPlayer) player).getHandle();
|
2018-03-20 16:27:00 +00:00
|
|
|
+ registerPlayer(other);
|
2018-03-18 16:32:09 +00:00
|
|
|
+ }
|
|
|
|
+ private void registerPlayer(EntityPlayer other) {
|
2019-04-28 17:59:47 +00:00
|
|
|
+ PlayerChunkMap tracker = ((WorldServer) entity.world).getChunkProvider().playerChunkMap;
|
2018-03-18 16:32:09 +00:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, other));
|
|
|
|
|
2020-07-22 08:01:35 +00:00
|
|
|
@@ -1289,6 +1302,50 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2018-03-18 16:32:09 +00:00
|
|
|
entry.updatePlayer(getHandle());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
|
|
+ private void reregisterPlayer(EntityPlayer player) {
|
|
|
|
+ if (!hiddenPlayers.containsKey(player.getUniqueID())) {
|
|
|
|
+ unregisterPlayer(player);
|
|
|
|
+ registerPlayer(player);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public void setPlayerProfile(PlayerProfile profile) {
|
|
|
|
+ EntityPlayer self = getHandle();
|
|
|
|
+ self.setProfile(CraftPlayerProfile.asAuthlibCopy(profile));
|
2020-02-22 14:13:29 +00:00
|
|
|
+ if (!self.sentListPacket) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
2018-03-18 16:32:09 +00:00
|
|
|
+ List<EntityPlayer> players = server.getServer().getPlayerList().players;
|
|
|
|
+ for (EntityPlayer player : players) {
|
|
|
|
+ player.getBukkitEntity().reregisterPlayer(self);
|
|
|
|
+ }
|
2018-07-24 00:31:33 +00:00
|
|
|
+ refreshPlayer();
|
2018-03-18 16:32:09 +00:00
|
|
|
+ }
|
|
|
|
+ public PlayerProfile getPlayerProfile() {
|
2018-03-23 01:40:57 +00:00
|
|
|
+ return new CraftPlayerProfile(this).clone();
|
2018-03-18 16:32:09 +00:00
|
|
|
+ }
|
2018-07-24 00:31:33 +00: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 11:16:36 +00:00
|
|
|
+ WorldServer worldserver = handle.getWorldServer();
|
|
|
|
+ connection.sendPacket(new net.minecraft.server.PacketPlayOutRespawn(worldserver.getTypeKey(), worldserver.getDimensionKey(), net.minecraft.server.BiomeManager.a(worldserver.getSeed()), handle.playerInteractManager.getGameMode(), handle.playerInteractManager.c(), worldserver.isDebugWorld(), worldserver.isFlatWorld(), true));
|
2018-07-24 00:31:33 +00:00
|
|
|
+ handle.updateAbilities();
|
2018-07-24 03:20:41 +00: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 00:31:33 +00:00
|
|
|
+
|
|
|
|
+ if (this.isOp()) {
|
|
|
|
+ this.setOp(false);
|
|
|
|
+ this.setOp(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
2018-03-18 16:32:09 +00:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
public void removeDisconnectingPlayer(Player player) {
|
|
|
|
hiddenPlayers.remove(player.getUniqueId());
|