Search in sources :

Example 1 with NativeGameMode

use of com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode in project ChangeSkin by games647.

the class SkinApplier method sendPacketsSelf.

private void sendPacketsSelf(WrappedGameProfile gameProfile) {
    PacketContainer removeInfo;
    PacketContainer addInfo;
    PacketContainer respawn;
    PacketContainer teleport;
    try {
        NativeGameMode gamemode = NativeGameMode.fromBukkit(receiver.getGameMode());
        WrappedChatComponent displayName = WrappedChatComponent.fromText(receiver.getPlayerListName());
        PlayerInfoData playerInfoData = new PlayerInfoData(gameProfile, 0, gamemode, displayName);
        // remove the old skin - client updates it only on a complete remove and add
        removeInfo = new PacketContainer(PLAYER_INFO);
        removeInfo.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
        removeInfo.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData));
        // add info containing the skin data
        addInfo = removeInfo.deepClone();
        addInfo.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER);
        // Respawn packet - notify the client that it should update the own skin
        respawn = createRespawnPacket(gamemode);
        // prevent the moved too quickly message
        teleport = createTeleportPacket(receiver.getLocation().clone());
    } catch (ReflectiveOperationException reflectiveEx) {
        plugin.getLog().error("Error occurred preparing packets. Cancelling self update", reflectiveEx);
        return;
    }
    sendPackets(removeInfo, addInfo, respawn, teleport);
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) WrappedChatComponent(com.comphenix.protocol.wrappers.WrappedChatComponent) PlayerInfoData(com.comphenix.protocol.wrappers.PlayerInfoData) NativeGameMode(com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode)

Aggregations

PacketContainer (com.comphenix.protocol.events.PacketContainer)1 NativeGameMode (com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode)1 PlayerInfoData (com.comphenix.protocol.wrappers.PlayerInfoData)1 WrappedChatComponent (com.comphenix.protocol.wrappers.WrappedChatComponent)1