2021-06-11 14:02:28 +02:00
|
|
|
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/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
2021-11-24 02:09:49 +01:00
|
|
|
index 00ef714294b6cce5fec7613eed4ba228a48e3e11..67b300574655854249c1f7440f56a6e8f0fad351 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
2021-11-23 15:03:50 +01:00
|
|
|
@@ -341,12 +341,12 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener
|
2021-06-11 14:02:28 +02:00
|
|
|
final org.bukkit.craftbukkit.CraftServer server = ServerLoginPacketListenerImpl.this.server.server;
|
|
|
|
|
|
|
|
// Paper start
|
|
|
|
- PlayerProfile profile = Bukkit.createProfile(uniqueId, playerName);
|
2021-06-12 18:56:13 +02:00
|
|
|
+ PlayerProfile profile = CraftPlayerProfile.asBukkitMirror(ServerLoginPacketListenerImpl.this.gameProfile);
|
2021-06-11 14:02:28 +02:00
|
|
|
AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId, profile);
|
|
|
|
server.getPluginManager().callEvent(asyncEvent);
|
|
|
|
profile = asyncEvent.getPlayerProfile();
|
|
|
|
- profile.complete();
|
|
|
|
- gameProfile = CraftPlayerProfile.asAuthlibCopy(profile);
|
|
|
|
+ profile.complete(true);
|
2021-06-12 18:56:13 +02:00
|
|
|
+ ServerLoginPacketListenerImpl.this.gameProfile = CraftPlayerProfile.asAuthlib(profile);
|
2021-06-11 14:02:28 +02:00
|
|
|
playerName = gameProfile.getName();
|
|
|
|
uniqueId = gameProfile.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
|
2022-01-23 01:59:56 +01:00
|
|
|
index bc31a9d5f709362f986ce4132287746568bafa56..b808a8f5b1a2e663924b22aa0d65459abd9f865d 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2022-01-12 22:39:20 +01:00
|
|
|
@@ -72,6 +72,7 @@ import net.minecraft.world.entity.ai.attributes.Attributes;
|
2021-11-23 15:03:50 +01:00
|
|
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
2021-06-11 14:02:28 +02:00
|
|
|
import net.minecraft.world.level.GameType;
|
2021-06-12 18:56:13 +02:00
|
|
|
import net.minecraft.world.level.block.Blocks;
|
2021-06-11 14:02:28 +02:00
|
|
|
+import net.minecraft.world.level.biome.BiomeManager;
|
|
|
|
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
|
|
|
import net.minecraft.world.level.saveddata.maps.MapDecoration;
|
2021-06-12 18:56:13 +02:00
|
|
|
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
|
2022-01-23 01:59:56 +01:00
|
|
|
@@ -1380,8 +1381,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2021-11-29 00:46:53 +01:00
|
|
|
this.hiddenEntities.put(entity.getUniqueId(), hidingPlugins);
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-11-29 00:46:53 +01:00
|
|
|
// Remove this entity from the hidden player's EntityTrackerEntry
|
|
|
|
- ChunkMap tracker = ((ServerLevel) this.getHandle().level).getChunkSource().chunkMap;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start
|
2021-11-29 00:46:53 +01:00
|
|
|
Entity other = ((CraftEntity) entity).getHandle();
|
|
|
|
+ unregisterEntity(other);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-11-29 00:46:53 +01:00
|
|
|
+ private void unregisterEntity(Entity other) {
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
2021-11-29 00:46:53 +01:00
|
|
|
+ ChunkMap tracker = ((ServerLevel) this.getHandle().level).getChunkSource().chunkMap;
|
2021-06-11 14:02:28 +02:00
|
|
|
ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
|
|
|
|
if (entry != null) {
|
2021-06-12 18:56:13 +02:00
|
|
|
entry.removePlayer(this.getHandle());
|
2022-01-23 01:59:56 +01:00
|
|
|
@@ -1430,8 +1436,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
2021-11-29 00:46:53 +01:00
|
|
|
this.hiddenEntities.remove(entity.getUniqueId());
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2021-11-29 00:46:53 +01:00
|
|
|
- ChunkMap tracker = ((ServerLevel) this.getHandle().level).getChunkSource().chunkMap;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start
|
2021-11-29 00:46:53 +01:00
|
|
|
Entity other = ((CraftEntity) entity).getHandle();
|
|
|
|
+ registerEntity(other);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2021-11-29 00:46:53 +01:00
|
|
|
+ private void registerEntity(Entity other) {
|
|
|
|
+ ChunkMap tracker = ((ServerLevel) this.getHandle().level).getChunkSource().chunkMap;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
|
|
|
|
2021-11-29 00:46:53 +01:00
|
|
|
if (other instanceof ServerPlayer) {
|
|
|
|
ServerPlayer otherPlayer = (ServerPlayer) other;
|
2022-01-23 01:59:56 +01:00
|
|
|
@@ -1443,6 +1454,50 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2021-06-12 18:56:13 +02:00
|
|
|
entry.updatePlayer(this.getHandle());
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
|
|
+ private void reregisterPlayer(ServerPlayer player) {
|
2021-11-29 00:46:53 +01:00
|
|
|
+ if (!hiddenEntities.containsKey(player.getUUID())) {
|
|
|
|
+ unregisterEntity(player);
|
|
|
|
+ registerEntity(player);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public void setPlayerProfile(com.destroystokyo.paper.profile.PlayerProfile profile) {
|
|
|
|
+ ServerPlayer self = getHandle();
|
2021-06-12 18:56:13 +02:00
|
|
|
+ self.gameProfile = com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (!self.sentListPacket) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ List<ServerPlayer> players = server.getServer().getPlayerList().players;
|
|
|
|
+ for (ServerPlayer 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() {
|
|
|
|
+ ServerPlayer handle = getHandle();
|
|
|
|
+
|
|
|
|
+ Location loc = getLocation();
|
|
|
|
+
|
|
|
|
+ ServerGamePacketListenerImpl connection = handle.connection;
|
|
|
|
+ reregisterPlayer(handle);
|
|
|
|
+
|
|
|
|
+ //Respawn the player then update their position and selected slot
|
|
|
|
+ ServerLevel worldserver = handle.getLevel();
|
|
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundRespawnPacket(worldserver.dimensionType(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), handle.gameMode.getGameModeForPlayer(), handle.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), true));
|
|
|
|
+ handle.onUpdateAbilities();
|
2021-06-12 18:56:13 +02:00
|
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), java.util.Collections.emptySet(), 0, false));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ net.minecraft.server.MinecraftServer.getServer().getPlayerList().sendAllPlayerInfo(handle);
|
|
|
|
+
|
|
|
|
+ if (this.isOp()) {
|
|
|
|
+ this.setOp(false);
|
|
|
|
+ this.setOp(true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
2021-12-04 02:33:56 +01:00
|
|
|
public void onEntityRemove(Entity entity) {
|
|
|
|
this.hiddenEntities.remove(entity.getUUID());
|