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.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||||
import xyz.ineanto.nicko.Nicko;
|
import xyz.ineanto.nicko.Nicko;
|
||||||
import xyz.ineanto.nicko.event.custom.PlayerDisguiseEvent;
|
import xyz.ineanto.nicko.event.custom.PlayerDisguiseEvent;
|
||||||
import xyz.ineanto.nicko.event.custom.PlayerResetDisguiseEvent;
|
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.
|
// Call the event.
|
||||||
final PlayerDisguiseEvent event = new PlayerDisguiseEvent(player, profile.getSkin(), profile.getName());
|
final PlayerDisguiseEvent event = new PlayerDisguiseEvent(player, profile.getSkin(), profile.getName());
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
packetSender.sendEntityMetadataUpdate();
|
|
||||||
packetSender.sendTabListUpdate(displayName);
|
|
||||||
|
|
||||||
packetSender.sendEntityRespawn();
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ import java.io.IOException;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public record PacketEventsPacketSender(Player player, NickoProfile profile) implements PacketSender {
|
public record PacketEventsPacketSender(Player player, NickoProfile profile) implements PacketSender {
|
||||||
|
@ -36,9 +35,11 @@ public record PacketEventsPacketSender(Player player, NickoProfile profile) impl
|
||||||
public void sendEntityRespawn() {
|
public void sendEntityRespawn() {
|
||||||
if (!profile.hasData()) return;
|
if (!profile.hasData()) return;
|
||||||
|
|
||||||
|
final int entityId = player.getEntityId();
|
||||||
|
|
||||||
final WrapperPlayServerDestroyEntities destroy = new WrapperPlayServerDestroyEntities(player.getEntityId());
|
final WrapperPlayServerDestroyEntities destroy = new WrapperPlayServerDestroyEntities(player.getEntityId());
|
||||||
final WrapperPlayServerSpawnEntity spawn = new WrapperPlayServerSpawnEntity(
|
final WrapperPlayServerSpawnEntity spawn = new WrapperPlayServerSpawnEntity(
|
||||||
new Random().nextInt(9999),
|
entityId,
|
||||||
Optional.of(player.getUniqueId()),
|
Optional.of(player.getUniqueId()),
|
||||||
EntityTypes.PLAYER,
|
EntityTypes.PLAYER,
|
||||||
new Vector3d(player.getX(), player.getY(), player.getZ()),
|
new Vector3d(player.getX(), player.getY(), player.getZ()),
|
||||||
|
@ -49,10 +50,12 @@ public record PacketEventsPacketSender(Player player, NickoProfile profile) impl
|
||||||
Optional.empty()
|
Optional.empty()
|
||||||
);
|
);
|
||||||
|
|
||||||
Bukkit.getOnlinePlayers().stream().filter(receiver -> receiver.getUniqueId() != player.getUniqueId()).forEach(receiver -> {
|
Bukkit.getOnlinePlayers().stream()
|
||||||
sendPacket(destroy, player);
|
.filter(receiver -> receiver.getUniqueId() != player.getUniqueId())
|
||||||
sendPacket(spawn, player);
|
.forEach(receiver -> {
|
||||||
});
|
sendPacket(destroy, receiver);
|
||||||
|
sendPacket(spawn, receiver);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,8 +86,7 @@ public record PacketEventsPacketSender(Player player, NickoProfile profile) impl
|
||||||
return ActionResult.error(LanguageKey.Error.MOJANG);
|
return ActionResult.error(LanguageKey.Error.MOJANG);
|
||||||
}
|
}
|
||||||
|
|
||||||
final MojangSkin skinResult = skin.get();
|
playerProfile.setProperties(skin.get().asProfileProperties());
|
||||||
playerProfile.setProperties(skinResult.asProfileProperties());
|
|
||||||
player.setPlayerProfile(playerProfile);
|
player.setPlayerProfile(playerProfile);
|
||||||
return ActionResult.ok();
|
return ActionResult.ok();
|
||||||
} catch (ExecutionException | IOException e) {
|
} catch (ExecutionException | IOException e) {
|
||||||
|
@ -127,7 +129,6 @@ public record PacketEventsPacketSender(Player player, NickoProfile profile) impl
|
||||||
public void sendTabListUpdate(String displayName) {
|
public void sendTabListUpdate(String displayName) {
|
||||||
final EnumSet<WrapperPlayServerPlayerInfoUpdate.Action> actions = EnumSet.of(
|
final EnumSet<WrapperPlayServerPlayerInfoUpdate.Action> actions = EnumSet.of(
|
||||||
WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER,
|
WrapperPlayServerPlayerInfoUpdate.Action.ADD_PLAYER,
|
||||||
WrapperPlayServerPlayerInfoUpdate.Action.INITIALIZE_CHAT,
|
|
||||||
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_LISTED,
|
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_LISTED,
|
||||||
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_DISPLAY_NAME,
|
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_DISPLAY_NAME,
|
||||||
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_GAME_MODE,
|
WrapperPlayServerPlayerInfoUpdate.Action.UPDATE_GAME_MODE,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue