Search in sources :

Example 1 with SPacketServerInfo

use of net.minecraft.network.status.server.SPacketServerInfo in project Magma by magmafoundation.

the class StandardPaperServerListPingEventImpl method processRequest.

@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));
}
Also used : ServerStatusResponse(net.minecraft.network.ServerStatusResponse) TextComponentString(net.minecraft.util.text.TextComponentString) SPacketServerInfo(net.minecraft.network.status.server.SPacketServerInfo)

Example 2 with SPacketServerInfo

use of net.minecraft.network.status.server.SPacketServerInfo in project SpongeCommon by SpongePowered.

the class MixinNetHandlerStatusServer method processServerQuery.

/**
 * @author Minecrell - January 18th, 2015
 * @reason Post the server status ping event for plugins.
 */
@Overwrite
public void processServerQuery(CPacketServerQuery packetIn) {
    if (this.handled) {
        this.networkManager.closeChannel(EXIT_MESSAGE);
    } else {
        this.handled = true;
        ServerStatusResponse response = SpongeStatusResponse.post(this.server, new SpongeStatusClient(this.networkManager));
        if (response != null) {
            this.networkManager.sendPacket(new SPacketServerInfo(response));
        } else {
            this.networkManager.closeChannel(null);
        }
    }
}
Also used : SpongeStatusClient(org.spongepowered.common.network.status.SpongeStatusClient) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) SPacketServerInfo(net.minecraft.network.status.server.SPacketServerInfo) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

ServerStatusResponse (net.minecraft.network.ServerStatusResponse)2 SPacketServerInfo (net.minecraft.network.status.server.SPacketServerInfo)2 TextComponentString (net.minecraft.util.text.TextComponentString)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 SpongeStatusClient (org.spongepowered.common.network.status.SpongeStatusClient)1