com.comphenix.protocol.wrappers.WrappedChatComponent Java Examples

The following examples show how to use com.comphenix.protocol.wrappers.WrappedChatComponent. 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: ProtocolLibLoginSource.java    From FastLogin with MIT License 6 votes vote down vote up
@Override
public void kick(String message) throws InvocationTargetException {
    ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();

    PacketContainer kickPacket = new PacketContainer(DISCONNECT);
    kickPacket.getChatComponents().write(0, WrappedChatComponent.fromText(message));

    try {
        //send kick packet at login state
        //the normal event.getPlayer.kickPlayer(String) method does only work at play state
        protocolManager.sendServerPacket(player, kickPacket);
    } finally {
        //tell the server that we want to close the connection
        player.kickPlayer("Disconnect");
    }
}
 
Example #2
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 #3
Source File: ProtocolUtils.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
/***
 * This method can be used to change the tab header and footer.
 * @param player The player to change the header / footer for
 * @param header The new header
 * @param footer The new footer
 */
public static void setPlayerHeaderFooter(Player player, String header, String footer){
    PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_LIST_HEADER_FOOTER);
    packet.getChatComponents().write(0, WrappedChatComponent.fromText(header));
    packet.getChatComponents().write(1, WrappedChatComponent.fromText(footer));
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
    }catch (InvocationTargetException ex){
        ex.printStackTrace();
    }
}
 
Example #4
Source File: VerifyResponseTask.java    From FastLogin with MIT License 5 votes vote down vote up
private void kickPlayer(String reason) {
    PacketContainer kickPacket = new PacketContainer(DISCONNECT);
    kickPacket.getChatComponents().write(0, WrappedChatComponent.fromText(reason));
    try {
        //send kick packet at login state
        //the normal event.getPlayer.kickPlayer(String) method does only work at play state
        ProtocolLibrary.getProtocolManager().sendServerPacket(player, kickPacket);
        //tell the server that we want to close the connection
        player.kickPlayer("Disconnect");
    } catch (InvocationTargetException ex) {
        plugin.getLog().error("Error sending kick packet for: {}", player, ex);
    }
}
 
Example #5
Source File: ActionBarMessenger.java    From UHC with MIT License 5 votes vote down vote up
public void sendMessage(Collection<? extends Player> players, String message) {
    final PacketContainer title = manager.createPacket(PacketType.Play.Server.CHAT);
    title.getChatComponents().write(0, WrappedChatComponent.fromText(message));
    title.getBytes().write(0, (byte) 2);

    try {
        for (final Player player : players) {
            manager.sendServerPacket(player, title);
        }
    } catch (InvocationTargetException ex) {
        ex.printStackTrace();
    }
}
 
Example #6
Source File: TitledTabList.java    From tabbed with MIT License 5 votes vote down vote up
private void updateHeaderFooter() {
    PacketContainer packet = new PacketContainer(Server.PLAYER_LIST_HEADER_FOOTER);
    packet.getChatComponents().write(0, WrappedChatComponent.fromText(this.header == null ? "" : this.header));
    packet.getChatComponents().write(1, WrappedChatComponent.fromText(this.footer == null ? "" : this.footer));
    try {
        ProtocolLibrary.getProtocolManager().sendServerPacket(this.player, packet);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
Example #7
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 #8
Source File: ProtocolHandshakeListener.java    From BungeeGuard with MIT License 5 votes vote down vote up
private static void closeConnection(Player player, String kickMessage) throws Exception {
    PacketContainer packet = new PacketContainer(PacketType.Login.Server.DISCONNECT);
    packet.getModifier().writeDefaults();

    WrappedChatComponent component = WrappedChatComponent.fromJson(ComponentSerializer.toString(TextComponent.fromLegacyText(kickMessage)));
    packet.getChatComponents().write(0, component);

    ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
    TemporaryPlayerFactory.getInjectorFromPlayer(player).getSocket().close();
}
 
Example #9
Source File: PacketScoreboard.java    From helper with MIT License 4 votes vote down vote up
static WrappedChatComponent toComponent(String text) {
    return WrappedChatComponent.fromJson(GsonComponentSerializer.INSTANCE.serialize(Text.fromLegacy(text)));
}
 
Example #10
Source File: FlagCountdownTitles.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
private WrappedChatComponent getChatComponent(String text) {
	return WrappedChatComponent.fromJson("{\"text\": \"" + text + "\"}");
}
 
Example #11
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 #12
Source File: WrapperPlayServerChat.java    From BetonQuest with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the chat message.
 * <p>
 * Limited to 32767 bytes
 *
 * @return The current message
 */
public WrappedChatComponent getMessage() {
    return handle.getChatComponents().read(0);
}
 
Example #13
Source File: WrapperPlayServerChat.java    From BetonQuest with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Set the message.
 *
 * @param value - new value.
 */
public void setMessage(WrappedChatComponent value) {
    handle.getChatComponents().write(0, value);
}
 
Example #14
Source File: WrapperLoginServerDisconnect.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the message that is displayed to the client when the connection terminates.
 * @return The current JSON message.
*/
public WrappedChatComponent getJsonData() {
    return handle.getChatComponents().read(0);
}
 
Example #15
Source File: WrapperLoginServerDisconnect.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the message that is displayed to the client when the connection terminates.
 * @param value - new message.
*/
public void setJsonData(WrappedChatComponent value) {
    handle.getChatComponents().write(0, value);
}
 
Example #16
Source File: WrapperPlayServerKickDisconnect.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the reason that is displayed to the client when the connection terminates. 
 * @return The current Reason
*/
public WrappedChatComponent getReason() {
    return handle.getChatComponents().read(0);
}
 
Example #17
Source File: WrapperPlayServerKickDisconnect.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the reason that is displayed to the client when the connection terminates.
 * @param value - new reason.
*/
public void setReason(WrappedChatComponent value) {
    handle.getChatComponents().write(0, value);
}
 
Example #18
Source File: WrapperPlayServerChat.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the chat message.
 * @return The current JSON Data
*/
public WrappedChatComponent getMessage() {
    return handle.getChatComponents().read(0);
}
 
Example #19
Source File: WrapperPlayServerChat.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the chat message.
 * @param value - new value.
*/
public void setMessage(WrappedChatComponent value) {
    handle.getChatComponents().write(0, value);
}