Paper/patches/server/0183-Player.setPlayerProfile-API.patch

181 lines
9.5 KiB
Diff
Raw Normal View History

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.
== AT ==
public-f net.minecraft.world.entity.player.Player gameProfile
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
2022-12-07 19:52:24 +01:00
index bb5c4ecd43aa344dfe9cca8ab7c2ebf9760e94cf..203786383387765d1f5a2d2ccce79d792fd5b187 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
2022-12-07 19:52:24 +01:00
@@ -330,11 +330,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
2021-06-11 14:02:28 +02:00
final org.bukkit.craftbukkit.CraftServer server = ServerLoginPacketListenerImpl.this.server.server;
2022-03-01 06:43:03 +01:00
// Paper start
- com.destroystokyo.paper.profile.PlayerProfile profile = org.bukkit.Bukkit.createProfile(uniqueId, playerName);
+ com.destroystokyo.paper.profile.PlayerProfile profile = com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitMirror(ServerLoginPacketListenerImpl.this.gameProfile);
AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId, profile);
2021-06-11 14:02:28 +02:00
server.getPluginManager().callEvent(asyncEvent);
2022-03-01 06:43:03 +01:00
profile = asyncEvent.getPlayerProfile();
- profile.complete();
+ profile.complete(true); // Paper - setPlayerProfileAPI
gameProfile = com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile);
playerName = gameProfile.getName();
uniqueId = gameProfile.getId();
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
index e7442952ef1f03969949014492a7ddc6d0796ba5..69a1852905dd4724c30ac8ab88c14251eee2c371 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
@@ -76,8 +76,8 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
}
@Override
- public PlayerProfile getPlayerProfile() {
- return new CraftPlayerProfile(this.profile);
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() { // Paper
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(this.profile); // Paper
}
public Server getServer() {
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index fb157165d46f2f2d9bbaa6f7c8199885051060a8..c9a016af654fb73bd95c1f2d5704c12dcd62241b 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-12-07 19:52:24 +01:00
@@ -81,6 +81,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.border.BorderChangeListener;
2021-06-11 14:02:28 +02:00
import net.minecraft.world.level.saveddata.maps.MapDecoration;
2022-12-07 19:52:24 +01:00
@@ -284,11 +285,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return server.getPlayer(getUniqueId()) != null;
}
- @Override
- public PlayerProfile getPlayerProfile() {
- return new CraftPlayerProfile(this.getProfile());
- }
-
@Override
public InetSocketAddress getAddress() {
if (this.getHandle().connection == null) return null;
2022-12-16 18:15:21 +01:00
@@ -1580,8 +1576,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
this.hiddenEntities.put(entity.getUniqueId(), hidingPlugins);
2021-06-11 14:02:28 +02: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
Entity other = ((CraftEntity) entity).getHandle();
+ unregisterEntity(other);
+
+ server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
2021-06-11 14:02:28 +02:00
+ }
+ private void unregisterEntity(Entity other) {
2021-06-11 14:02:28 +02:00
+ // Paper end
+ 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-12-16 18:15:21 +01:00
@@ -1594,8 +1597,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2022-12-07 19:52:24 +01:00
this.getHandle().connection.send(new ClientboundPlayerInfoRemovePacket(List.of(otherPlayer.getUUID())));
}
}
-
- server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
}
@Override
2022-12-16 18:15:21 +01:00
@@ -1632,8 +1633,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2021-06-11 14:02:28 +02:00
}
this.hiddenEntities.remove(entity.getUniqueId());
2021-06-11 14:02:28 +02:00
- ChunkMap tracker = ((ServerLevel) this.getHandle().level).getChunkSource().chunkMap;
2021-06-11 14:02:28 +02:00
+ // Paper start
Entity other = ((CraftEntity) entity).getHandle();
+ registerEntity(other);
+
+ server.getPluginManager().callEvent(new PlayerShowEntityEvent(this, entity));
2021-06-11 14:02:28 +02:00
+ }
+ private void registerEntity(Entity other) {
+ ChunkMap tracker = ((ServerLevel) this.getHandle().level).getChunkSource().chunkMap;
2021-06-11 14:02:28 +02:00
+ // Paper end
if (other instanceof ServerPlayer) {
ServerPlayer otherPlayer = (ServerPlayer) other;
2022-12-16 18:15:21 +01:00
@@ -1644,9 +1652,51 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if (entry != null && !entry.seenBy.contains(this.getHandle().connection)) {
entry.updatePlayer(this.getHandle());
}
+ }
2021-06-11 14:02:28 +02:00
+ // Paper start
+ private void reregisterPlayer(ServerPlayer player) {
+ 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();
+ }
- server.getPluginManager().callEvent(new PlayerShowEntityEvent(this, entity));
2021-06-11 14:02:28 +02:00
+ 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();
2022-12-07 22:57:15 +01:00
+ connection.send(new net.minecraft.network.protocol.game.ClientboundRespawnPacket(worldserver.dimensionTypeId(), worldserver.dimension(), BiomeManager.obfuscateSeed(worldserver.getSeed()), handle.gameMode.getGameModeForPlayer(), handle.gameMode.getPreviousGameModeForPlayer(), worldserver.isDebug(), worldserver.isFlat(), net.minecraft.network.protocol.game.ClientboundRespawnPacket.KEEP_ALL_DATA, this.getHandle().getLastDeathLocation()));
2021-06-11 14:02:28 +02:00
+ handle.onUpdateAbilities();
+ connection.internalTeleport(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), java.util.Collections.emptySet(), 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);
+ }
}
2021-06-11 14:02:28 +02:00
+ // Paper end
public void onEntityRemove(Entity entity) {
this.hiddenEntities.remove(entity.getUUID());
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
index a679133a3de51e26eb19932ece9ade292879aefd..e342ea27a8a689ea080c7881711a5dcd6322c914 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
@@ -306,6 +306,12 @@ public class Commodore
return;
}
+ // Paper start - Rewrite plugins
+ if ((owner.equals("org/bukkit/OfflinePlayer") || owner.equals("org/bukkit/entity/Player")) && name.equals("getPlayerProfile") && desc.equals("()Lorg/bukkit/profile/PlayerProfile;")) {
+ super.visitMethodInsn(opcode, owner, name, "()Lcom/destroystokyo/paper/profile/PlayerProfile;", itf);
+ return;
+ }
+ // Paper end
if ( modern )
{
if ( owner.equals( "org/bukkit/Material" ) )