All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.eldoria.eldoutilities.debug.payload.ServerMeta Maven / Gradle / Ivy

There is a newer version: 2.1.7
Show newest version
/*
 *     SPDX-License-Identifier: LGPL-3.0-or-later
 *
 *     Copyright (C) EldoriaRPG Team and Contributor
 */

package de.eldoria.eldoutilities.debug.payload;

import de.eldoria.eldoutilities.debug.data.PluginMetaData;
import de.eldoria.eldoutilities.debug.data.ServerMetaData;
import org.bukkit.Bukkit;
import org.bukkit.World;

import java.util.Arrays;

public final class ServerMeta extends ServerMetaData {

    private ServerMeta(String version, int currentPlayers, String[] loadedWorlds, PluginMetaData[] plugins) {
        super(version, currentPlayers, loadedWorlds, plugins);
    }

    public static ServerMetaData create() {
        var server = Bukkit.getServer();
        var version = server.getVersion();
        var currentPlayers = server.getOnlinePlayers().size();
        var loadedWorlds = server.getWorlds().stream().map(World::getName).toArray(String[]::new);
        var plugins = Arrays.stream(server.getPluginManager().getPlugins())
                .map(PluginMeta::create)
                .toArray(PluginMeta[]::new);

        return new ServerMeta(version, currentPlayers, loadedWorlds, plugins);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy