use of xyz.jpenilla.minimotd.common.config.MiniMOTDConfig in project MiniMOTD by jpenilla.
the class ClientPingServerEventListener method handle.
@Override
public void handle(@NonNull final ClientPingServerEvent event) {
final ClientPingServerEvent.Response response = event.response();
final ClientPingServerEvent.Response.Players players;
final ClientPingServerEvent.Response.Players players0 = response.players().orElse(null);
if (players0 != null) {
players = players0;
} else {
response.setHidePlayers(false);
players = response.players().orElse(null);
if (players == null) {
this.miniMOTD.logger().warn(String.format("Failed to handle ClientPingServerEvent: '%s', response.players() was null.", event));
return;
}
}
final MiniMOTDConfig config = this.miniMOTD.configManager().mainConfig();
final PingResponse<Favicon> mini = this.miniMOTD.createMOTD(config, players.online(), players.max());
mini.playerCount().applyCount(players::setOnline, players::setMax);
mini.motd(motd -> {
if (this.legacy(event.client().version())) {
response.setDescription(ComponentColorDownsampler.downsampler().downsample(motd));
} else {
response.setDescription(motd);
}
});
mini.icon(response::setFavicon);
if (mini.disablePlayerListHover()) {
players.profiles().clear();
}
if (mini.hidePlayerCount()) {
response.setHidePlayers(true);
}
}
use of xyz.jpenilla.minimotd.common.config.MiniMOTDConfig in project MiniMOTD by jpenilla.
the class PaperPingListener method handlePing.
@EventHandler
public void handlePing(@NonNull final PaperServerListPingEvent event) {
final MiniMOTDConfig cfg = this.miniMOTD.configManager().mainConfig();
final PingResponse<CachedServerIcon> response = this.miniMOTD.createMOTD(cfg, event.getNumPlayers(), event.getMaxPlayers());
response.playerCount().applyCount(event::setNumPlayers, event::setMaxPlayers);
response.motd(motd -> {
if (event.getClient().getProtocolVersion() < Constants.MINECRAFT_1_16_PROTOCOL_VERSION || PaperLib.getMinecraftVersion() < 16) {
event.setMotd(LegacyComponentSerializer.legacySection().serialize(motd));
} else {
event.setMotd(this.unusualHexSerializer.serialize(motd));
}
});
response.icon(event::setServerIcon);
if (response.disablePlayerListHover()) {
event.getPlayerSample().clear();
}
if (response.hidePlayerCount()) {
event.setHidePlayers(true);
}
}
use of xyz.jpenilla.minimotd.common.config.MiniMOTDConfig in project MiniMOTD by jpenilla.
the class PingListener method handlePing.
@EventHandler
public void handlePing(@NonNull final ServerListPingEvent event) {
final MiniMOTDConfig cfg = this.miniMOTD.configManager().mainConfig();
final PingResponse<CachedServerIcon> response = this.miniMOTD.createMOTD(cfg, event.getNumPlayers(), event.getMaxPlayers());
event.setMaxPlayers(response.playerCount().maxPlayers());
response.motd(motd -> {
if (PaperLib.getMinecraftVersion() > 15) {
event.setMotd(this.unusualHexSerializer.serialize(motd));
} else {
event.setMotd(LegacyComponentSerializer.legacySection().serialize(motd));
}
});
response.icon(event::setServerIcon);
}
use of xyz.jpenilla.minimotd.common.config.MiniMOTDConfig in project MiniMOTD by jpenilla.
the class ServerStatusPacketListenerImplMixin method injectHandleStatusRequest.
@Redirect(method = "handleStatusRequest", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;getStatus()Lnet/minecraft/network/protocol/status/ServerStatus;"))
public ServerStatus injectHandleStatusRequest(final MinecraftServer minecraftServer) {
final ServerStatus vanillaStatus = minecraftServer.getStatus();
final ServerStatus modifiedStatus = new ServerStatus();
modifiedStatus.setDescription(vanillaStatus.getDescription());
modifiedStatus.setFavicon(vanillaStatus.getFavicon());
modifiedStatus.setVersion(vanillaStatus.getVersion());
final MiniMOTDFabric miniMOTDFabric = MiniMOTDFabric.get();
final MiniMOTD<String> miniMOTD = miniMOTDFabric.miniMOTD();
final MiniMOTDConfig config = miniMOTD.configManager().mainConfig();
final PingResponse<String> response = miniMOTD.createMOTD(config, minecraftServer.getPlayerCount(), vanillaStatus.getPlayers().getMaxPlayers());
response.motd(motd -> {
if (((ConnectionAccess) this.connection).protocolVersion() >= Constants.MINECRAFT_1_16_PROTOCOL_VERSION) {
modifiedStatus.setDescription(miniMOTDFabric.audiences().toNative(motd));
} else {
modifiedStatus.setDescription(miniMOTDFabric.audiences().toNative(ComponentColorDownsampler.downsampler().downsample(motd)));
}
});
response.icon(modifiedStatus::setFavicon);
if (!response.hidePlayerCount()) {
final GameProfile[] oldSample = vanillaStatus.getPlayers().getSample();
final ServerStatus.Players newPlayers = new ServerStatus.Players(response.playerCount().maxPlayers(), response.playerCount().onlinePlayers());
if (response.disablePlayerListHover()) {
newPlayers.setSample(new GameProfile[] {});
} else {
newPlayers.setSample(oldSample);
}
modifiedStatus.setPlayers(newPlayers);
}
return modifiedStatus;
}
use of xyz.jpenilla.minimotd.common.config.MiniMOTDConfig in project MiniMOTD by jpenilla.
the class ClientPingServerEventListener method handle.
@Override
public void handle(@NonNull final ClientPingServerEvent event) {
final ClientPingServerEvent.Response response = event.getResponse();
final ClientPingServerEvent.Response.Players players;
final ClientPingServerEvent.Response.Players players0 = response.getPlayers().orElse(null);
if (players0 != null) {
players = players0;
} else {
response.setHidePlayers(false);
players = response.getPlayers().orElse(null);
if (players == null) {
this.miniMOTD.logger().warn(String.format("Failed to handle ClientPingServerEvent: '%s', response.getPlayers() was null.", event));
return;
}
}
final MiniMOTDConfig config = this.miniMOTD.configManager().mainConfig();
final PingResponse<Favicon> mini = this.miniMOTD.createMOTD(config, players.getOnline(), players.getMax());
mini.playerCount().applyCount(players::setOnline, players::setMax);
mini.motd(motd -> response.setDescription(SpongeComponentSerializer.get().serialize(motd)));
mini.icon(response::setFavicon);
if (mini.disablePlayerListHover()) {
players.getProfiles().clear();
}
if (mini.hidePlayerCount()) {
response.setHidePlayers(true);
}
}
Aggregations