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.
|
|
|
|
|
2022-11-20 00:53:20 +01:00
|
|
|
== AT ==
|
|
|
|
public-f net.minecraft.world.entity.player.Player gameProfile
|
|
|
|
|
2023-03-14 19:59:51 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2023-06-09 01:44:17 +02:00
|
|
|
index 5d1875b11d4768afc184416e38a0bd3e3334a9ce..e7d2bd1b2ee80c5cc68048f2d90dcf21e50f04d2 100644
|
2023-03-14 19:59:51 +01:00
|
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
2023-06-08 07:21:04 +02:00
|
|
|
@@ -1535,7 +1535,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
2023-03-14 19:59:51 +01:00
|
|
|
this.internalTeleport(dest.getX(), dest.getY(), dest.getZ(), dest.getYaw(), dest.getPitch(), Collections.emptySet());
|
|
|
|
}
|
|
|
|
|
|
|
|
- private void internalTeleport(double d0, double d1, double d2, float f, float f1, Set<RelativeMovement> set) {
|
|
|
|
+ public void internalTeleport(double d0, double d1, double d2, float f, float f1, Set<RelativeMovement> set) { // Paper
|
|
|
|
// CraftBukkit start
|
|
|
|
if (Float.isNaN(f)) {
|
|
|
|
f = 0;
|
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
|
2023-03-14 19:59:51 +01:00
|
|
|
index 6b31b0894e52ad6fc397624e50587ec04e46c099..0c7f280bae81bbb492d5780a43e5ffda0f58756a 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();
|
2022-12-20 19:56:33 +01:00
|
|
|
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
|
2023-06-08 15:25:35 +02:00
|
|
|
index fd7e9909875961a1a7288f235ef73de518467f25..26e89e7c9d648b9b1ce33714da8503122f100a9f 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
|
2023-04-14 01:52:42 +02:00
|
|
|
@@ -82,6 +82,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;
|
2023-06-07 21:54:11 +02:00
|
|
|
import net.minecraft.world.level.block.entity.SignText;
|
2022-04-16 10:29:50 +02:00
|
|
|
import net.minecraft.world.level.border.BorderChangeListener;
|
2023-06-08 07:21:04 +02:00
|
|
|
@@ -258,11 +259,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2022-02-12 14:20:33 +01: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;
|
2023-06-08 07:21:04 +02:00
|
|
|
@@ -1659,8 +1655,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2021-06-11 14:02:28 +02:00
|
|
|
|
2023-03-14 19:59:51 +01:00
|
|
|
private void untrackAndHideEntity(org.bukkit.entity.Entity entity) {
|
2021-11-29 00:46:53 +01:00
|
|
|
// Remove this entity from the hidden player's EntityTrackerEntry
|
2023-06-07 21:54:11 +02: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();
|
|
|
|
+ unregisterEntity(other);
|
2022-02-01 14:06:41 +01:00
|
|
|
+
|
|
|
|
+ server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
|
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
|
2023-06-07 21:54:11 +02: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());
|
2023-06-08 07:21:04 +02:00
|
|
|
@@ -1673,8 +1676,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())));
|
2022-02-01 14:06:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
-
|
|
|
|
- server.getPluginManager().callEvent(new PlayerHideEntityEvent(this, entity));
|
|
|
|
}
|
|
|
|
|
2023-03-14 19:59:51 +01:00
|
|
|
void resetAndHideEntity(org.bukkit.entity.Entity entity) {
|
2023-06-08 07:21:04 +02:00
|
|
|
@@ -1751,8 +1752,38 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2022-02-01 14:06:41 +01:00
|
|
|
if (entry != null && !entry.seenBy.contains(this.getHandle().connection)) {
|
|
|
|
entry.updatePlayer(this.getHandle());
|
|
|
|
}
|
2023-03-14 19:59:51 +01:00
|
|
|
+ server.getPluginManager().callEvent(new PlayerShowEntityEvent(this, entity)); // Paper
|
2022-02-01 14:06:41 +01:00
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper start
|
2023-03-07 00:15:25 +01:00
|
|
|
+ @Override
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public void setPlayerProfile(com.destroystokyo.paper.profile.PlayerProfile profile) {
|
2023-03-07 00:15:25 +01:00
|
|
|
+ ServerPlayer self = this.getHandle();
|
|
|
|
+ GameProfile gameProfile = com.destroystokyo.paper.profile.CraftPlayerProfile.asAuthlibCopy(profile);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (!self.sentListPacket) {
|
2023-03-07 00:15:25 +01:00
|
|
|
+ self.gameProfile = gameProfile;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ return;
|
|
|
|
+ }
|
2023-03-07 00:15:25 +01:00
|
|
|
+ List<ServerPlayer> players = this.server.getServer().getPlayerList().players;
|
|
|
|
+ // First unregister the player for all players with the OLD game profile
|
2021-06-11 14:02:28 +02:00
|
|
|
+ for (ServerPlayer player : players) {
|
2023-03-07 00:15:25 +01:00
|
|
|
+ CraftPlayer bukkitPlayer = player.getBukkitEntity();
|
|
|
|
+ if (bukkitPlayer.canSee(this)) {
|
|
|
|
+ bukkitPlayer.unregisterEntity(self);
|
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
2023-03-23 22:57:03 +01:00
|
|
|
+
|
2023-03-23 17:49:24 +01:00
|
|
|
+ // Set the game profile here, we should have unregistered the entity via iterating all player entities above.
|
|
|
|
+ self.gameProfile = gameProfile;
|
2023-03-23 22:57:03 +01:00
|
|
|
|
|
|
|
- server.getPluginManager().callEvent(new PlayerShowEntityEvent(this, entity));
|
2023-03-07 00:15:25 +01:00
|
|
|
+ // Re-register the game profile for all players
|
|
|
|
+ for (ServerPlayer player : players) {
|
|
|
|
+ CraftPlayer bukkitPlayer = player.getBukkitEntity();
|
|
|
|
+ if (bukkitPlayer.canSee(this)) {
|
2023-03-15 00:10:18 +01:00
|
|
|
+ bukkitPlayer.trackAndShowEntity(self.getBukkitEntity());
|
2023-03-07 00:15:25 +01:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Refresh misc player things AFTER sending game profile
|
|
|
|
+ this.refreshPlayer();
|
|
|
|
}
|
|
|
|
|
2023-03-14 19:59:51 +01:00
|
|
|
void resetAndShowEntity(org.bukkit.entity.Entity entity) {
|
2023-06-08 07:21:04 +02:00
|
|
|
@@ -1765,6 +1796,36 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
2023-03-14 19:59:51 +01:00
|
|
|
this.trackAndShowEntity(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ // Paper start
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() {
|
|
|
|
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(this).clone();
|
|
|
|
+ }
|
|
|
|
+
|
2023-03-07 00:15:25 +01:00
|
|
|
+ private void refreshPlayer() {
|
|
|
|
+ ServerPlayer handle = this.getHandle();
|
|
|
|
+ Location loc = this.getLocation();
|
2021-06-11 14:02:28 +02:00
|
|
|
+
|
|
|
|
+ ServerGamePacketListenerImpl connection = handle.connection;
|
|
|
|
+
|
|
|
|
+ //Respawn the player then update their position and selected slot
|
2023-06-08 00:12:41 +02:00
|
|
|
+ ServerLevel worldserver = handle.serverLevel();
|
|
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundRespawnPacket(worldserver.dimensionTypeId(), worldserver.dimension(), net.minecraft.world.level.biome.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(), handle.getPortalCooldown()));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ handle.onUpdateAbilities();
|
2023-03-14 19:59:51 +01:00
|
|
|
+ connection.internalTeleport(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch(), java.util.Collections.emptySet());
|
2021-06-11 14:02:28 +02:00
|
|
|
+ net.minecraft.server.MinecraftServer.getServer().getPlayerList().sendAllPlayerInfo(handle);
|
|
|
|
+
|
2023-04-07 01:21:33 +02:00
|
|
|
+ // Resend their XP and effects because the respawn packet resets it
|
|
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundSetExperiencePacket(handle.experienceProgress, handle.totalExperience, handle.experienceLevel));
|
|
|
|
+ for (net.minecraft.world.effect.MobEffectInstance mobEffect : handle.getActiveEffects()) {
|
|
|
|
+ connection.send(new net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket(handle.getId(), mobEffect));
|
|
|
|
+ }
|
|
|
|
+
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (this.isOp()) {
|
|
|
|
+ this.setOp(false);
|
|
|
|
+ this.setOp(true);
|
|
|
|
+ }
|
2023-03-07 00:15:25 +01:00
|
|
|
+ }
|
2021-06-11 14:02:28 +02:00
|
|
|
+ // Paper end
|
2023-03-14 19:59:51 +01:00
|
|
|
|
2021-12-04 02:33:56 +01:00
|
|
|
public void onEntityRemove(Entity entity) {
|
2023-03-14 19:59:51 +01:00
|
|
|
this.invertedVisibilityEntities.remove(entity.getUUID());
|
2022-12-20 19:56:33 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
2023-04-14 01:52:42 +02:00
|
|
|
index 173a2832f029e3d568208a1b56419c1b8501483c..48cdd483c25825571043800f3cfa41a4d723f649 100644
|
2022-12-20 19:56:33 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/Commodore.java
|
2023-04-14 01:52:42 +02:00
|
|
|
@@ -329,6 +329,12 @@ public class Commodore
|
2022-12-20 19:56:33 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start - Rewrite plugins
|
2022-12-26 13:34:23 +01:00
|
|
|
+ if ((owner.equals("org/bukkit/OfflinePlayer") || owner.equals("org/bukkit/entity/Player")) && name.equals("getPlayerProfile") && desc.equals("()Lorg/bukkit/profile/PlayerProfile;")) {
|
2022-12-20 19:56:33 +01:00
|
|
|
+ super.visitMethodInsn(opcode, owner, name, "()Lcom/destroystokyo/paper/profile/PlayerProfile;", itf);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
if ( modern )
|
|
|
|
{
|
|
|
|
if ( owner.equals( "org/bukkit/Material" ) )
|