Java Code Examples for net.minecraft.network.NetworkManager#sendPacket()

The following examples show how to use net.minecraft.network.NetworkManager#sendPacket() . 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: StandardPaperServerListPingEventImpl.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static void processRequest(MinecraftServer server, NetworkManager networkManager) {
    StandardPaperServerListPingEventImpl event = new StandardPaperServerListPingEventImpl(server, networkManager, server.getServerStatusResponse());
    server.server.getPluginManager().callEvent(event);

    // Close connection immediately if event is cancelled
    if (event.isCancelled()) {
        networkManager.closeChannel(null);
        return;
    }

    // Setup response
    ServerStatusResponse ping = new ServerStatusResponse();

    // Description
    ping.setServerDescription(new TextComponentString(event.getMotd()));

    // Players
    if (!event.shouldHidePlayers()) {
        ping.setPlayers(new ServerStatusResponse.Players(event.getMaxPlayers(), event.getNumPlayers()));
        ping.getPlayers().setPlayers(event.getPlayerSampleHandle());
    }

    // Version
    ping.setVersion(new ServerStatusResponse.Version(event.getVersion(), event.getProtocolVersion()));

    // Favicon
    if (event.getServerIcon() != null) {
        ping.setFavicon(event.getServerIcon().getData());
    }

    // Send response
    networkManager.sendPacket(new SPacketServerInfo(ping));
}
 
Example 2
Source File: ClientUtils.java    From LiquidBounce with GNU General Public License v3.0 4 votes vote down vote up
public static void sendEncryption(final NetworkManager networkManager, final SecretKey secretKey, final PublicKey publicKey, final S01PacketEncryptionRequest encryptionRequest) {
    networkManager.sendPacket(new C01PacketEncryptionResponse(secretKey, publicKey, encryptionRequest.getVerifyToken()), p_operationComplete_1_ -> networkManager.enableEncryption(secretKey));
}