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));
}
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);
}
}
}
Aggregations