Search in sources :

Example 1 with ArclightPingEvent

use of io.izzel.arclight.common.mod.util.ArclightPingEvent in project Arclight by IzzelAliz.

the class ServerStatusNetHandlerMixin method arclight$handleServerPing.

@Redirect(method = "processServerQuery", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetworkManager;sendPacket(Lnet/minecraft/network/IPacket;)V"))
private void arclight$handleServerPing(NetworkManager networkManager, IPacket<?> packetIn) {
    Object[] players = this.server.getPlayerList().players.toArray();
    ArclightPingEvent event = new ArclightPingEvent(networkManager, server);
    Bukkit.getPluginManager().callEvent(event);
    List<GameProfile> profiles = new ArrayList<>(players.length);
    Object[] array;
    for (int length = (array = players).length, i = 0; i < length; ++i) {
        Object player = array[i];
        if (player != null) {
            profiles.add(((ServerPlayerEntity) player).getGameProfile());
        }
    }
    ServerStatusResponse.Players playerSample = new ServerStatusResponse.Players(event.getMaxPlayers(), profiles.size());
    if (!profiles.isEmpty()) {
        Collections.shuffle(profiles);
        profiles = profiles.subList(0, Math.min(profiles.size(), SpigotConfig.playerSample));
    }
    playerSample.setPlayers(profiles.toArray(new GameProfile[0]));
    ServerStatusResponse ping = new ServerStatusResponse();
    ping.setFavicon(event.icon.value);
    ping.setServerDescription(new StringTextComponent(event.getMotd()));
    ping.setPlayers(playerSample);
    int version = SharedConstants.getVersion().getProtocolVersion();
    ping.setVersion(new ServerStatusResponse.Version(this.server.getServerModName() + " " + this.server.getMinecraftVersion(), version));
    ping.setForgeData(this.server.getServerStatusResponse().getForgeData());
    networkManager.sendPacket(new SServerInfoPacket(ping));
}
Also used : ArrayList(java.util.ArrayList) GameProfile(com.mojang.authlib.GameProfile) StringTextComponent(net.minecraft.util.text.StringTextComponent) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) ArclightPingEvent(io.izzel.arclight.common.mod.util.ArclightPingEvent) SServerInfoPacket(net.minecraft.network.status.server.SServerInfoPacket) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)1 ArclightPingEvent (io.izzel.arclight.common.mod.util.ArclightPingEvent)1 ArrayList (java.util.ArrayList)1 ServerStatusResponse (net.minecraft.network.ServerStatusResponse)1 SServerInfoPacket (net.minecraft.network.status.server.SServerInfoPacket)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1