2021-06-11 12:02:28 +00: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.
|
|
|
|
|
2022-11-19 23:53:20 +00:00
|
|
|
== AT ==
|
|
|
|
public-f net.minecraft.world.entity.player.Player gameProfile
|
|
|
|
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
2022-10-31 02:44:25 +00:00
|
|
|
index 4627d2a785120c6e69fc3c82054bf0703fe5477b..3a20c6e2214ad075e4cdd3fbdf0b59e1891b0f2b 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
2022-10-31 02:44:25 +00:00
|
|
|
@@ -369,11 +369,11 @@ public class ServerLoginPacketListenerImpl implements TickablePacketListener, Se
|
2021-06-11 12:02:28 +00:00
|
|
|
final org.bukkit.craftbukkit.CraftServer server = ServerLoginPacketListenerImpl.this.server.server;
|
|
|
|
|
2022-03-01 05:43:03 +00: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 12:02:28 +00:00
|
|
|
server.getPluginManager().callEvent(asyncEvent);
|
2022-03-01 05:43:03 +00: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();
|
2021-06-11 12:02:28 +00:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2022-10-31 02:44:25 +00:00
|
|
|
index a08c03bb984d27ded2979353f207693fb79d4256..88f12c573ed26dbf83f61679bbee4f0fbf566a08 100644
|
2021-06-11 12:02:28 +00:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
2022-09-24 01:38:12 +00:00
|
|
|
@@ -79,6 +79,7 @@ import net.minecraft.world.entity.ai.attributes.Attributes;
|
2021-11-23 14:03:50 +00:00
|
|
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
2021-06-11 12:02:28 +00:00
|
|
|
import net.minecraft.world.level.GameType;
|
2021-06-12 16:56:13 +00:00
|
|
|
import net.minecraft.world.level.block.Blocks;
|
2021-06-11 12:02:28 +00:00
|
|
|
+import net.minecraft.world.level.biome.BiomeManager;
|
|
|
|
import net.minecraft.world.level.block.entity.SignBlockEntity;
|
2022-04-16 08:29:50 +00:00
|
|
|
import net.minecraft.world.level.border.BorderChangeListener;
|
2021-06-11 12:02:28 +00:00
|
|
|
import net.minecraft.world.level.saveddata.maps.MapDecoration;
|
2022-09-26 08:02:51 +00:00
|
|
|
@@ -282,11 +283,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2022-02-12 13:20:33 +00:00
|
|
|
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-09-26 08:02:51 +00:00
|
|
|
@@ -1577,8 +1573,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2021-11-28 23:46:53 +00:00
|
|
|
this.hiddenEntities.put(entity.getUniqueId(), hidingPlugins);
|
2021-06-11 12:02:28 +00:00
|
|
|
|
2021-11-28 23:46:53 +00:00
|
|
|
// Remove this entity from the hidden player's EntityTrackerEntry
|
|
|
|
- ChunkMap tracker = ((ServerLevel) this.getHandle().level).getChunkSource().chunkMap;
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper start
|
2021-11-28 23:46:53 +00:00
|
|
|
Entity other = ((CraftEntity) entity).getHandle();
|
|
|
|
+ unregisterEntity(other);
|
2022-02-01 13:06:41 +00:00
|
|
|
+
|
|
|
|
+ server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
2021-11-28 23:46:53 +00:00
|
|
|
+ private void unregisterEntity(Entity other) {
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper end
|
2021-11-28 23:46:53 +00:00
|
|
|
+ ChunkMap tracker = ((ServerLevel) this.getHandle().level).getChunkSource().chunkMap;
|
2021-06-11 12:02:28 +00:00
|
|
|
ChunkMap.TrackedEntity entry = tracker.entityMap.get(other.getId());
|
|
|
|
if (entry != null) {
|
2021-06-12 16:56:13 +00:00
|
|
|
entry.removePlayer(this.getHandle());
|
2022-09-26 08:02:51 +00:00
|
|
|
@@ -1591,8 +1594,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2022-02-01 13:06:41 +00:00
|
|
|
this.getHandle().connection.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, otherPlayer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-
|
|
|
|
- server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-09-26 08:02:51 +00:00
|
|
|
@@ -1629,8 +1630,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2021-06-11 12:02:28 +00:00
|
|
|
}
|
2021-11-28 23:46:53 +00:00
|
|
|
this.hiddenEntities.remove(entity.getUniqueId());
|
2021-06-11 12:02:28 +00:00
|
|
|
|
2021-11-28 23:46:53 +00:00
|
|
|
- ChunkMap tracker = ((ServerLevel) this.getHandle().level).getChunkSource().chunkMap;
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper start
|
2021-11-28 23:46:53 +00:00
|
|
|
Entity other = ((CraftEntity) entity).getHandle();
|
|
|
|
+ registerEntity(other);
|
2022-02-01 13:06:41 +00:00
|
|
|
+
|
|
|
|
+ server.getPluginManager().callEvent(new PlayerShowEntityEvent(this, entity));
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
2021-11-28 23:46:53 +00:00
|
|
|
+ private void registerEntity(Entity other) {
|
|
|
|
+ ChunkMap tracker = ((ServerLevel) this.getHandle().level).getChunkSource().chunkMap;
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper end
|
|
|
|
|
2021-11-28 23:46:53 +00:00
|
|
|
if (other instanceof ServerPlayer) {
|
|
|
|
ServerPlayer otherPlayer = (ServerPlayer) other;
|
2022-09-26 08:02:51 +00:00
|
|
|
@@ -1641,9 +1649,51 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2022-02-01 13:06:41 +00:00
|
|
|
if (entry != null && !entry.seenBy.contains(this.getHandle().connection)) {
|
|
|
|
entry.updatePlayer(this.getHandle());
|
|
|
|
}
|
|
|
|
+ }
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper start
|
|
|
|
+ private void reregisterPlayer(ServerPlayer player) {
|
2021-11-28 23:46:53 +00:00
|
|
|
+ if (!hiddenEntities.containsKey(player.getUUID())) {
|
|
|
|
+ unregisterEntity(player);
|
|
|
|
+ registerEntity(player);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ public void setPlayerProfile(com.destroystokyo.paper.profile.PlayerProfile profile) {
|
|
|
|
+ ServerPlayer self = getHandle();
|
2021-06-12 16:56:13 +00:00
|
|
|
+ self.gameProfile = com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile);
|
2021-06-11 12:02:28 +00: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();
|
|
|
|
+ }
|
2022-02-01 13:06:41 +00:00
|
|
|
|
|
|
|
- server.getPluginManager().callEvent(new PlayerShowEntityEvent(this, entity));
|
2021-06-11 12:02:28 +00: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-06-07 21:15:14 +00: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(), true, this.getHandle().getLastDeathLocation()));
|
2021-06-11 12:02:28 +00:00
|
|
|
+ handle.onUpdateAbilities();
|
2022-08-10 14:01:39 +00:00
|
|
|
+ connection.internalTeleport(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), java.util.Collections.emptySet(), false);
|
2021-06-11 12:02:28 +00:00
|
|
|
+ net.minecraft.server.MinecraftServer.getServer().getPlayerList().sendAllPlayerInfo(handle);
|
|
|
|
+
|
|
|
|
+ if (this.isOp()) {
|
|
|
|
+ this.setOp(false);
|
|
|
|
+ this.setOp(true);
|
|
|
|
+ }
|
2022-02-01 13:06:41 +00:00
|
|
|
}
|
2021-06-11 12:02:28 +00:00
|
|
|
+ // Paper end
|
|
|
|
|
2021-12-04 01:33:56 +00:00
|
|
|
public void onEntityRemove(Entity entity) {
|
|
|
|
this.hiddenEntities.remove(entity.getUUID());
|