fix: do not change entityid, packet send to receiver only, teleport player to avoid issue

This commit is contained in:
ineanto 2025-08-31 15:33:50 +02:00
parent b1d1570b39
commit 899a7e2f32
Signed by: ineanto
GPG key ID: E511F9CAA2F9CE84
2 changed files with 23 additions and 14 deletions

View file

@ -2,6 +2,7 @@ package xyz.ineanto.nicko.appearance;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerTeleportEvent;
import xyz.ineanto.nicko.Nicko;
import xyz.ineanto.nicko.event.custom.PlayerDisguiseEvent;
import xyz.ineanto.nicko.event.custom.PlayerResetDisguiseEvent;
@ -60,16 +61,23 @@ public class AppearanceManager {
}
}
packetSender.sendPlayerRespawn();
packetSender.sendEntityMetadataUpdate();
packetSender.sendTabListUpdate(displayName);
packetSender.sendEntityRespawn();
//packetSender.sendChunkData();
//packetSender.sendPlayerRespawn();
// From "https://minecraft.wiki/w/Java_Edition_protocol/FAQ#%E2%80%A6my_player_isn't_spawning!"
// "The client will also spawn after spending 30 seconds in the
// loading screen, even if it never received Game Event 13."
// Sending a teleport to the player's current location fixes this.
player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
// Call the event.
final PlayerDisguiseEvent event = new PlayerDisguiseEvent(player, profile.getSkin(), profile.getName());
Bukkit.getPluginManager().callEvent(event);
packetSender.sendEntityMetadataUpdate();
packetSender.sendTabListUpdate(displayName);
packetSender.sendEntityRespawn();
return result;
}

View file

@ -28,7 +28,6 @@ import java.io.IOException;
import java.util.EnumSet;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.ExecutionException;
public record PacketEventsPacketSender(Player player, NickoProfile profile) implements PacketSender {
@ -36,9 +35,11 @@ public record PacketEventsPacketSender(Player player, NickoProfile profile) impl
public void sendEntityRespawn() {
if (!profile.hasData()) return;
final int entityId = player.getEntityId();
final WrapperPlayServerDestroyEntities destroy = new WrapperPlayServerDestroyEntities(player.getEntityId());
final WrapperPlayServerSpawnEntity spawn = new WrapperPlayServerSpawnEntity(
new Random().nextInt(9999),
entityId,
Optional.of(player.getUniqueId()),
EntityTypes.PLAYER,
new Vector3d(player.getX(), player.getY(), player.getZ()),
@ -49,10 +50,12 @@ public record PacketEventsPacketSender(Player player, NickoProfile profile) impl
Optional.empty()
);
Bukkit.getOnlinePlayers().stream().filter(receiver -> receiver.getUniqueId() != player.getUniqueId()).forEach(receiver -> {
sendPacket(destroy, player);
sendPacket(spawn, player);
});
Bukkit.getOnlinePlayers().stream()
.filter(receiver -> receiver.getUniqueId() != player.getUniqueId())
.forEach(receiver -> {
sendPacket(destroy, receiver);
sendPacket(spawn, receiver);
});
}
@Override
@ -83,8 +86,7 @@ public record PacketEventsPacketSender(Player player, NickoProfile profile) impl
return ActionResult.error(LanguageKey.Error.MOJANG);
}
final MojangSkin skinResult = skin.get();
playerProfile.setProperties(skinResult.asProfileProperties());
playerProfile.setProperties(skin.get().asProfileProperties());
player.setPlayerProfile(playerProfile);
return ActionResult.ok();
} catch (ExecutionException | IOException e) {
@ -127,7 +129,6 @@ public record PacketEventsPacketSender(Player player, NickoProfile profile) impl
public void sendTabListUpdate(String displayName) {
final EnumSet<WrapperPlayServerPlayerInfoUpdate.Action> actions = EnumSet.of(
WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER,
WrapperPlayServerPlayerInfoUpdate.Action.INITIALIZE_CHAT,
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_LISTED,
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_DISPLAY_NAME,
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_GAME_MODE,