com.comphenix.protocol.wrappers.PlayerInfoData Java Examples

The following examples show how to use com.comphenix.protocol.wrappers.PlayerInfoData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VanishIndication.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
private void sendPlayerInfoChangeGameModePacket(Player p, Player change, boolean spectator) {
    PacketContainer packet = new PacketContainer(PLAYER_INFO);
    packet.getPlayerInfoAction().write(0, EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE);
    List<PlayerInfoData> data = new ArrayList<>();
    int ping = ThreadLocalRandom.current().nextInt(20) + 15;
    data.add(new PlayerInfoData(WrappedGameProfile.fromPlayer(change), ping,
            spectator ? EnumWrappers.NativeGameMode.SPECTATOR
                    : EnumWrappers.NativeGameMode.fromBukkit(change.getGameMode()),
            WrappedChatComponent.fromText(change.getPlayerListName())));
    packet.getPlayerInfoDataLists().write(0, data);
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("Cannot send packet", e);
    }
}
 
Example #2
Source File: SimpleTabList.java    From tabbed with MIT License 5 votes vote down vote up
private PlayerInfoData getPlayerInfoData(WrappedGameProfile profile, int ping, String displayName) {
    if (displayName != null) {
        // min width
        while (displayName.length() < this.minColumnWidth)
            displayName += " ";

        // max width
        if (this.maxColumnWidth > 0)
            while (displayName.length() > this.maxColumnWidth)
                displayName = displayName.substring(0, displayName.length() - 1);
    }

    return new PlayerInfoData(profile, ping, NativeGameMode.SURVIVAL, displayName == null ? null : WrappedChatComponent.fromText(displayName));
}
 
Example #3
Source File: Packets.java    From tabbed with MIT License 5 votes vote down vote up
/**
 * Creates a PLAYER_INFO packet from the params.
 * @param action
 * @param data
 * @return
 */

public static PacketContainer getPacket(PlayerInfoAction action, List<PlayerInfoData> data) {
    PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacket(Server.PLAYER_INFO);
    packet.getPlayerInfoAction().write(0, action);
    packet.getPlayerInfoDataLists().write(0, data);
    return packet;
}
 
Example #4
Source File: ProtocolUtils.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
private ProtocolUtils(){
    protocolUtils = this;

    ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(UhcCore.getPlugin(), PacketType.Play.Server.PLAYER_INFO) {

        @Override
        public void onPacketSending(PacketEvent event) {
            if (event.getPacket().getPlayerInfoAction().read(0) != EnumWrappers.PlayerInfoAction.ADD_PLAYER){
                return;
            }

            List<PlayerInfoData> newPlayerInfoDataList = new ArrayList<>();
            List<PlayerInfoData> playerInfoDataList = event.getPacket().getPlayerInfoDataLists().read(0);
            PlayersManager pm = GameManager.getGameManager().getPlayersManager();

            for (PlayerInfoData playerInfoData : playerInfoDataList) {
                if (
                        playerInfoData == null ||
                        playerInfoData.getProfile() == null ||
                        Bukkit.getPlayer(playerInfoData.getProfile().getUUID()) == null
                ){ // Unknown player
                    newPlayerInfoDataList.add(playerInfoData);
                    continue;
                }

                WrappedGameProfile profile = playerInfoData.getProfile();
                UhcPlayer uhcPlayer;

                try {
                    uhcPlayer = pm.getUhcPlayer(profile.getUUID());
                }catch (UhcPlayerDoesntExistException ex){ // UhcPlayer does not exist
                    newPlayerInfoDataList.add(playerInfoData);
                    continue;
                }

                // No display-name so don't change player data.
                if (!uhcPlayer.hasNickName()){
                    newPlayerInfoDataList.add(playerInfoData);
                    continue;
                }

                profile = profile.withName(uhcPlayer.getName());

                PlayerInfoData newPlayerInfoData = new PlayerInfoData(profile, playerInfoData.getPing(), playerInfoData.getGameMode(), playerInfoData.getDisplayName());
                newPlayerInfoDataList.add(newPlayerInfoData);
            }
            event.getPacket().getPlayerInfoDataLists().write(0, newPlayerInfoDataList);
        }

    });
}
 
Example #5
Source File: WrapperPlayServerPlayerInfo.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
public List<PlayerInfoData> getData()
{
    return handle.getPlayerInfoDataLists().read(0);
}
 
Example #6
Source File: WrapperPlayServerPlayerInfo.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
public void setData(List<PlayerInfoData> value)
{
    handle.getPlayerInfoDataLists().write(0, value);
}
 
Example #7
Source File: SimpleTabList.java    From tabbed with MIT License 4 votes vote down vote up
private List<PacketContainer> getUpdate(Map<Integer,TabItem> oldItems, Map<Integer,TabItem> newItems) {
    List<PlayerInfoData> removePlayer = new ArrayList<>();
    List<PlayerInfoData> addPlayer = new ArrayList<>();
    List<PlayerInfoData> displayChanged = new ArrayList<>();
    List<PlayerInfoData> pingUpdated = new ArrayList<>();

    for (Entry<Integer, TabItem> entry : newItems.entrySet()) {
        int index = entry.getKey();
        TabItem oldItem = oldItems.get(index);
        TabItem newItem = entry.getValue();

        if (newItem == null && oldItem != null) { // TabItem has been removed.
            removePlayer.add(getPlayerInfoData(index, oldItem));
            continue;
        }

        boolean skinChanged = oldItem == null || newItem.updateSkin() || !newItem.getSkin().equals(oldItem.getSkin());
        boolean textChanged = oldItem == null || newItem.updateText() || !newItem.getText().equals(oldItem.getText());
        boolean pingChanged = oldItem == null || newItem.updatePing() || oldItem.getPing() != newItem.getPing();

        if (skinChanged) {
            if (oldItem != null)
                removePlayer.add(getPlayerInfoData(index, oldItem));
            addPlayer.add(getPlayerInfoData(index, newItem));
        } else if (pingChanged) {
            pingUpdated.add(getPlayerInfoData(index, newItem));
        }

        if (textChanged)
            displayChanged.add(getPlayerInfoData(index, newItem));
    }

    List<PacketContainer> result = new ArrayList<>(4);

    if (removePlayer.size() > 0 || addPlayer.size() > 0) {
        result.add(Packets.getPacket(PlayerInfoAction.REMOVE_PLAYER, removePlayer));
        result.add(Packets.getPacket(PlayerInfoAction.ADD_PLAYER, addPlayer));
    }
    if (displayChanged.size() > 0)
        result.add(Packets.getPacket(PlayerInfoAction.UPDATE_DISPLAY_NAME, displayChanged));
    if (pingUpdated.size() > 0)
        result.add(Packets.getPacket(PlayerInfoAction.UPDATE_LATENCY, pingUpdated));

    return result;
}
 
Example #8
Source File: SimpleTabList.java    From tabbed with MIT License 4 votes vote down vote up
private PlayerInfoData getPlayerInfoData(int index, TabItem item) {
    WrappedGameProfile profile = getGameProfile(index, item);
    return getPlayerInfoData(profile, item.getPing(), item.getText());
}
 
Example #9
Source File: VanishIndication.java    From SuperVanish with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onEnable() {
    ProtocolLibrary.getProtocolManager().addPacketListener(
            new PacketAdapter(plugin, ListenerPriority.NORMAL, PacketType.Play.Server.PLAYER_INFO) {
                @Override
                public void onPacketSending(PacketEvent event) {
                    // multiple events share same packet object
                    event.setPacket(event.getPacket().shallowClone());
                    List<PlayerInfoData> infoDataList = new ArrayList<>(
                            event.getPacket().getPlayerInfoDataLists().read(0));
                    Player receiver = event.getPlayer();
                    for (PlayerInfoData infoData : ImmutableList.copyOf(infoDataList)) {
                        try {
                            if (!VanishIndication.this.plugin.getVisibilityChanger().getHider()
                                    .isHidden(infoData.getProfile().getUUID(), receiver)
                                    && VanishIndication.this.plugin.getVanishStateMgr()
                                    .isVanished(infoData.getProfile().getUUID())) {
                                if (!receiver.getUniqueId().equals(infoData.getProfile().getUUID()))
                                    if (infoData.getGameMode() != EnumWrappers.NativeGameMode.SPECTATOR) {
                                        int latency;
                                        try {
                                            latency = infoData.getLatency();
                                        } catch (NoSuchMethodError e) {
                                            latency = 21;
                                        }
                                        if (event.getPacket().getPlayerInfoAction().read(0)
                                                != EnumWrappers.PlayerInfoAction.UPDATE_GAME_MODE) {
                                            continue;
                                        }
                                        PlayerInfoData newData = new PlayerInfoData(infoData.getProfile(),
                                                latency, EnumWrappers.NativeGameMode.SPECTATOR,
                                                infoData.getDisplayName());
                                        infoDataList.remove(infoData);
                                        infoDataList.add(newData);
                                    }
                            }
                        } catch (UnsupportedOperationException ignored) {
                            // Ignore temporary players
                        }
                    }
                    event.getPacket().getPlayerInfoDataLists().write(0, infoDataList);
                }
            });
}
 
Example #10
Source File: DisplayInformation.java    From AACAdditionPro with GNU General Public License v3.0 3 votes vote down vote up
/**
 * This method updates the player information, and thus the tablist of a player.
 *
 * @param action         the {@link com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction} that will be executed.
 * @param gameProfile    the {@link WrappedGameProfile} of the player whose information will be updated.<br>
 *                       Use {@link WrappedGameProfile#fromPlayer(Player)} in order to get a {@link WrappedGameProfile} from a {@link Player}.
 * @param ping           the new ping of the updated {@link Player}.
 * @param gameMode       the {@link com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode} of the updated {@link Player}.
 *                       Use {@link de.photon.aacadditionpro.util.server.ServerUtil#getPing(Player)} to get the ping of a {@link Player}.
 * @param displayName    the new displayName of the updated {@link Player}
 * @param affectedPlayer the {@link Player} who will see the updated information as the packet is sent to him.
 */
public static void updatePlayerInformation(final EnumWrappers.PlayerInfoAction action, final WrappedGameProfile gameProfile, final int ping, final EnumWrappers.NativeGameMode gameMode, final WrappedChatComponent displayName, final Player affectedPlayer)
{
    final PlayerInfoData playerInfoData = new PlayerInfoData(gameProfile, ping, gameMode, displayName);

    final WrapperPlayServerPlayerInfo playerInfoWrapper = new WrapperPlayServerPlayerInfo();
    playerInfoWrapper.setAction(action);
    playerInfoWrapper.setData(Collections.singletonList(playerInfoData));

    playerInfoWrapper.sendPacket(affectedPlayer);
}
 
Example #11
Source File: Packets.java    From tabbed with MIT License 2 votes vote down vote up
/**
 * Creates a PLAYER_INFO packet from the params.
 * @param action
 * @param data
 * @return
 */
public static PacketContainer getPacket(PlayerInfoAction action, PlayerInfoData data) {
    return getPacket(action, Collections.singletonList(data));
}