fix: do not change entityid, packet send to receiver only, teleport player to avoid issue
This commit is contained in:
parent
b1d1570b39
commit
899a7e2f32
2 changed files with 23 additions and 14 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,9 +50,11 @@ 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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue