cn.nukkit.Nukkit Java Examples

The following examples show how to use cn.nukkit.Nukkit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainLogger.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
private String colorize(String string) {
    if (string.indexOf(TextFormat.ESCAPE) < 0) {
        return string;
    } else if (Nukkit.ANSI) {
        for (TextFormat color : colors) {
            if (replacements.containsKey(color)) {
                string = string.replaceAll("(?i)" + color, replacements.get(color));
            } else {
                string = string.replaceAll("(?i)" + color, "");
            }
        }
    } else {
        return TextFormat.clean(string);
    }
    return string + Ansi.ansi().reset();
}
 
Example #2
Source File: MainLogger.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
private String colorize(String string) {
    if (string.indexOf(TextFormat.ESCAPE) < 0) {
        return string;
    } else if (Nukkit.ANSI) {
        for (TextFormat color : colors) {
            if (replacements.containsKey(color)) {
                string = string.replaceAll("(?i)" + color, replacements.get(color));
            } else {
                string = string.replaceAll("(?i)" + color, "");
            }
        }
    } else {
        return TextFormat.clean(string);
    }
    return string + Ansi.ansi().reset();
}
 
Example #3
Source File: RakNetInterface.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags) {
        if (this.players.containsKey(identifier)) {
            DataPacket pk = null;
            try {
                if (packet.buffer.length > 0) {
                    if (packet.buffer[0] == PING_DataPacket.ID) {
                        PING_DataPacket pingPacket = new PING_DataPacket();
                        pingPacket.buffer = packet.buffer;
                        pingPacket.decode();

                        this.networkLatency.put(identifier, (int) pingPacket.pingID);
                        return;
                    }

                    pk = this.getPacket(packet.buffer);
                    if (pk != null) {
                        pk.decode();
                        this.players.get(identifier).handleDataPacket(pk);
                    }
                }
            } catch (Exception e) {
                this.server.getLogger().logException(e);
                if (Nukkit.DEBUG > 1 && pk != null) {
                    MainLogger logger = this.server.getLogger();
//                    if (logger != null) {
                    logger.debug("Packet " + pk.getClass().getName() + " 0x" + Binary.bytesToHexString(packet.buffer));
                    //logger.logException(e);
//                    }
                }

                if (this.players.containsKey(identifier)) {
                    this.handler.blockAddress(this.players.get(identifier).getAddress(), 5);
                }
            }
        }
    }
 
Example #4
Source File: RakNetInterface.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags) {
        if (this.players.containsKey(identifier)) {
            DataPacket pk = null;
            try {
                if (packet.buffer.length > 0) {
                    if (packet.buffer[0] == PING_DataPacket.ID) {
                        PING_DataPacket pingPacket = new PING_DataPacket();
                        pingPacket.buffer = packet.buffer;
                        pingPacket.decode();

                        this.networkLatency.put(identifier, (int) pingPacket.pingID);
                        return;
                    }

                    pk = this.getPacket(packet.buffer);
                    if (pk != null) {
                        pk.decode();
                        this.players.get(identifier).handleDataPacket(pk);
                    }
                }
            } catch (Exception e) {
                this.server.getLogger().logException(e);
                if (Nukkit.DEBUG > 1 && pk != null) {
                    MainLogger logger = this.server.getLogger();
//                    if (logger != null) {
                    logger.debug("Packet " + pk.getClass().getName() + " 0x" + Binary.bytesToHexString(packet.buffer));
                    //logger.logException(e);
//                    }
                }

                if (this.players.containsKey(identifier)) {
                    this.handler.blockAddress(this.players.get(identifier).getAddress(), 5);
                }
            }
        }
    }
 
Example #5
Source File: Network.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void processInterfaces() {
    for (SourceInterface interfaz : this.interfaces) {
        try {
            interfaz.process();
        } catch (Exception e) {
            if (Nukkit.DEBUG > 1) {
                this.server.getLogger().logException(e);
            }

            interfaz.emergencyShutdown();
            this.unregisterInterface(interfaz);
            log.fatal(this.server.getLanguage().translateString("nukkit.server.networkError", new String[]{interfaz.getClass().getName(), Utils.getExceptionMessage(e)}));
        }
    }
}
 
Example #6
Source File: SynapseEntry.java    From SynapseAPI with GNU General Public License v3.0 5 votes vote down vote up
public void threadTick() {
    this.synapseInterface.process();
    if (!this.getSynapseInterface().isConnected() || !this.verified) return;
    long time = System.currentTimeMillis();
    if ((time - this.lastUpdate) >= 5000) {  //Heartbeat!
        this.lastUpdate = time;
        HeartbeatPacket pk = new HeartbeatPacket();
        pk.tps = this.getSynapse().getServer().getTicksPerSecondAverage();
        pk.load = this.getSynapse().getServer().getTickUsageAverage();
        pk.upTime = (System.currentTimeMillis() - Nukkit.START_TIME) / 1000;
        this.sendDataPacket(pk);
        //this.getSynapse().getServer().getLogger().debug(time + " -> Sending Heartbeat Packet to " + this.getHash());
    }
    /*
    for (int i = 0; i < new Random().nextInt(10) + 1; i++) {
        InformationPacket test = new InformationPacket();
        test.type = InformationPacket.TYPE_PLUGIN_MESSAGE;
        test.message = getRandomString(1024 * (new Random().nextInt(20) + 110));
        this.sendDataPacket(test);
    }*/

    long finalTime = System.currentTimeMillis();
    long usedTime = finalTime - time;
    //this.getSynapse().getServer().getLogger().warning(time + " -> threadTick 用时 " + usedTime + " 毫秒");
    if (((finalTime - this.lastUpdate) >= 30000) && this.synapseInterface.isConnected()) {  //30 seconds timeout
        this.synapseInterface.reconnect();
    }
}
 
Example #7
Source File: RakNetInterface.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public void handleEncapsulated(String identifier, EncapsulatedPacket packet, int flags) {
        if (this.players.containsKey(identifier)) {
            DataPacket pk = null;
            try {
                if (packet.buffer.length > 0) {
                    if (packet.buffer[0] == PING_DataPacket.ID) {
                        PING_DataPacket pingPacket = new PING_DataPacket();
                        pingPacket.buffer = packet.buffer;
                        pingPacket.decode();

                        this.networkLatency.put(identifier, (int) pingPacket.pingID);
                        return;
                    }

                    pk = this.getPacket(packet.buffer);
                    if (pk != null) {
                        pk.decode();
                        this.players.get(identifier).handleDataPacket(pk);
                    }
                }
            } catch (Exception e) {
                this.server.getLogger().logException(e);
                if (Nukkit.DEBUG > 1 && pk != null) {
                    MainLogger logger = this.server.getLogger();
//                    if (logger != null) {
                    logger.debug("Packet " + pk.getClass().getName() + " 0x" + Binary.bytesToHexString(packet.buffer));
                    //logger.logException(e);
//                    }
                }

                if (this.players.containsKey(identifier)) {
                    this.handler.blockAddress(this.players.get(identifier).getAddress(), 5);
                }
            }
        }
    }
 
Example #8
Source File: Network.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void processInterfaces() {
    for (SourceInterface interfaz : this.interfaces) {
        try {
            interfaz.process();
        } catch (Exception e) {
            if (Nukkit.DEBUG > 1) {
                this.server.getLogger().logException(e);
            }

            interfaz.emergencyShutdown();
            this.unregisterInterface(interfaz);
            this.server.getLogger().critical(this.server.getLanguage().translateString("nukkit.server.networkError", new String[]{interfaz.getClass().getName(), e.getMessage()}));
        }
    }
}
 
Example #9
Source File: StatusCommand.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Server server = sender.getServer();
    sender.sendMessage(TextFormat.GREEN + "---- " + TextFormat.WHITE + "Server status" + TextFormat.GREEN + " ----");

    long time = (System.currentTimeMillis() - Nukkit.START_TIME) / 1000;
    int seconds = NukkitMath.floorDouble(time % 60);
    int minutes = NukkitMath.floorDouble((time % 3600) / 60);
    int hours = NukkitMath.floorDouble(time % (3600 * 24) / 3600);
    int days = NukkitMath.floorDouble(time / (3600 * 24));
    String upTimeString = TextFormat.RED + "" + days + TextFormat.GOLD + " days " +
            TextFormat.RED + hours + TextFormat.GOLD + " hours " +
            TextFormat.RED + minutes + TextFormat.GOLD + " minutes " +
            TextFormat.RED + seconds + TextFormat.GOLD + " seconds";
    sender.sendMessage(TextFormat.GOLD + "Uptime: " + upTimeString);

    TextFormat tpsColor = TextFormat.GREEN;
    float tps = server.getTicksPerSecond();
    if (tps < 17) {
        tpsColor = TextFormat.GOLD;
    } else if (tps < 12) {
        tpsColor = TextFormat.RED;
    }

    sender.sendMessage(TextFormat.GOLD + "Current TPS: " + tpsColor + NukkitMath.round(tps, 2));

    sender.sendMessage(TextFormat.GOLD + "Load: " + tpsColor + server.getTickUsage() + "%");

    sender.sendMessage(TextFormat.GOLD + "Network upload: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getUpload() / 1024 * 1000), 2) + " kB/s");

    sender.sendMessage(TextFormat.GOLD + "Network download: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getDownload() / 1024 * 1000), 2) + " kB/s");

    sender.sendMessage(TextFormat.GOLD + "Thread count: " + TextFormat.GREEN + Thread.getAllStackTraces().size());


    Runtime runtime = Runtime.getRuntime();
    double totalMB = NukkitMath.round(((double) runtime.totalMemory()) / 1024 / 1024, 2);
    double usedMB = NukkitMath.round((double) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024, 2);
    double maxMB = NukkitMath.round(((double) runtime.maxMemory()) / 1024 / 1024, 2);
    double usage = usedMB / maxMB * 100;
    TextFormat usageColor = TextFormat.GREEN;

    if (usage > 85) {
        usageColor = TextFormat.GOLD;
    }

    sender.sendMessage(TextFormat.GOLD + "Used memory: " + usageColor + usedMB + " MB. (" + NukkitMath.round(usage, 2) + "%)");

    sender.sendMessage(TextFormat.GOLD + "Total memory: " + TextFormat.RED + totalMB + " MB.");

    sender.sendMessage(TextFormat.GOLD + "Maximum VM memory: " + TextFormat.RED + maxMB + " MB.");

    sender.sendMessage(TextFormat.GOLD + "Available processors: " + TextFormat.GREEN + runtime.availableProcessors());


    TextFormat playerColor = TextFormat.GREEN;
    if (((float) server.getOnlinePlayers().size() / (float) server.getMaxPlayers()) > 0.85) {
        playerColor = TextFormat.GOLD;
    }

    sender.sendMessage(TextFormat.GOLD + "Players: " + playerColor + server.getOnlinePlayers().size() + TextFormat.GREEN + " online, " +
            TextFormat.RED + server.getMaxPlayers() + TextFormat.GREEN + " max. ");

    for (Level level : server.getLevels().values()) {
        sender.sendMessage(
                TextFormat.GOLD + "World \"" + level.getFolderName() + "\"" + (!Objects.equals(level.getFolderName(), level.getName()) ? " (" + level.getName() + ")" : "") + ": " +
                        TextFormat.RED + level.getChunks().size() + TextFormat.GREEN + " chunks, " +
                        TextFormat.RED + level.getEntities().length + TextFormat.GREEN + " entities, " +
                        TextFormat.RED + level.getBlockEntities().size() + TextFormat.GREEN + " blockEntities." +
                        " Time " + ((level.getTickRate() > 1 || level.getTickRateTime() > 40) ? TextFormat.RED : TextFormat.YELLOW) + NukkitMath.round(level.getTickRateTime(), 2) + "ms" +
                        (level.getTickRate() > 1 ? " (tick rate " + level.getTickRate() + ")" : "")
        );
    }

    return true;
}
 
Example #10
Source File: BugReportGenerator.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private String generate() throws IOException {
    File reports = new File(Nukkit.DATA_PATH, "logs/bug_reports");
    if (!reports.isDirectory()) {
        reports.mkdirs();
    }

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
    String date = simpleDateFormat.format(new Date());

    StringBuilder model = new StringBuilder();
    long totalDiskSpace = 0;
    int diskNum = 0;
    for (Path root : FileSystems.getDefault().getRootDirectories()) {
        try {
            FileStore store = Files.getFileStore(root);
            model.append("Disk ").append(diskNum++).append(":(avail=").append(getCount(store.getUsableSpace(), true))
                    .append(", total=").append(getCount(store.getTotalSpace(), true))
                    .append(") ");
            totalDiskSpace += store.getTotalSpace();
        } catch (IOException e) {
            //
        }
    }

    StringWriter stringWriter = new StringWriter();
    throwable.printStackTrace(new PrintWriter(stringWriter));

    StackTraceElement[] stackTrace = throwable.getStackTrace();
    boolean pluginError = false;
    if (stackTrace.length > 0) {
        pluginError = !throwable.getStackTrace()[0].getClassName().startsWith("cn.nukkit");
    }


    File mdReport = new File(reports, date + "_" + throwable.getClass().getSimpleName() + ".md");
    mdReport.createNewFile();
    String content = Utils.readFile(this.getClass().getClassLoader().getResourceAsStream("report_template.md"));

    String cpuType = System.getenv("PROCESSOR_IDENTIFIER");
    OperatingSystemMXBean osMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    content = content.replace("${NUKKIT_VERSION}", Nukkit.VERSION);
    content = content.replace("${JAVA_VERSION}", System.getProperty("java.vm.name") + " (" + System.getProperty("java.runtime.version") + ")");
    content = content.replace("${HOSTOS}", osMXBean.getName() + "-" + osMXBean.getArch() + " [" + osMXBean.getVersion() + "]");
    content = content.replace("${MEMORY}", getCount(osMXBean.getTotalPhysicalMemorySize(), true));
    content = content.replace("${STORAGE_SIZE}", getCount(totalDiskSpace, true));
    content = content.replace("${CPU_TYPE}", cpuType == null ? "UNKNOWN" : cpuType);
    content = content.replace("${AVAILABLE_CORE}", String.valueOf(osMXBean.getAvailableProcessors()));
    content = content.replace("${STACKTRACE}", stringWriter.toString());
    content = content.replace("${PLUGIN_ERROR}", Boolean.toString(pluginError).toUpperCase());
    content = content.replace("${STORAGE_TYPE}", model.toString());

    Utils.writeFile(mdReport, content);

    return mdReport.getAbsolutePath();
}
 
Example #11
Source File: StatusCommand.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Server server = sender.getServer();
    sender.sendMessage(TextFormat.GREEN + "---- " + TextFormat.WHITE + "Server status" + TextFormat.GREEN + " ----");

    long time = System.currentTimeMillis() - Nukkit.START_TIME;

    sender.sendMessage(TextFormat.GOLD + "Uptime: " + formatUptime(time));

    TextFormat tpsColor = TextFormat.GREEN;
    float tps = server.getTicksPerSecond();
    if (tps < 17) {
        tpsColor = TextFormat.GOLD;
    } else if (tps < 12) {
        tpsColor = TextFormat.RED;
    }

    sender.sendMessage(TextFormat.GOLD + "Current TPS: " + tpsColor + NukkitMath.round(tps, 2));

    sender.sendMessage(TextFormat.GOLD + "Load: " + tpsColor + server.getTickUsage() + "%");

    sender.sendMessage(TextFormat.GOLD + "Network upload: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getUpload() / 1024 * 1000), 2) + " kB/s");

    sender.sendMessage(TextFormat.GOLD + "Network download: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getDownload() / 1024 * 1000), 2) + " kB/s");

    sender.sendMessage(TextFormat.GOLD + "Thread count: " + TextFormat.GREEN + Thread.getAllStackTraces().size());


    Runtime runtime = Runtime.getRuntime();
    double totalMB = NukkitMath.round(((double) runtime.totalMemory()) / 1024 / 1024, 2);
    double usedMB = NukkitMath.round((double) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024, 2);
    double maxMB = NukkitMath.round(((double) runtime.maxMemory()) / 1024 / 1024, 2);
    double usage = usedMB / maxMB * 100;
    TextFormat usageColor = TextFormat.GREEN;

    if (usage > 85) {
        usageColor = TextFormat.GOLD;
    }

    sender.sendMessage(TextFormat.GOLD + "Used memory: " + usageColor + usedMB + " MB. (" + NukkitMath.round(usage, 2) + "%)");

    sender.sendMessage(TextFormat.GOLD + "Total memory: " + TextFormat.RED + totalMB + " MB.");

    sender.sendMessage(TextFormat.GOLD + "Maximum VM memory: " + TextFormat.RED + maxMB + " MB.");

    sender.sendMessage(TextFormat.GOLD + "Available processors: " + TextFormat.GREEN + runtime.availableProcessors());


    TextFormat playerColor = TextFormat.GREEN;
    if (((float) server.getOnlinePlayers().size() / (float) server.getMaxPlayers()) > 0.85) {
        playerColor = TextFormat.GOLD;
    }

    sender.sendMessage(TextFormat.GOLD + "Players: " + playerColor + server.getOnlinePlayers().size() + TextFormat.GREEN + " online, " +
            TextFormat.RED + server.getMaxPlayers() + TextFormat.GREEN + " max. ");

    for (Level level : server.getLevels().values()) {
        sender.sendMessage(
                TextFormat.GOLD + "World \"" + level.getFolderName() + "\"" + (!Objects.equals(level.getFolderName(), level.getName()) ? " (" + level.getName() + ")" : "") + ": " +
                        TextFormat.RED + level.getChunks().size() + TextFormat.GREEN + " chunks, " +
                        TextFormat.RED + level.getEntities().length + TextFormat.GREEN + " entities, " +
                        TextFormat.RED + level.getBlockEntities().size() + TextFormat.GREEN + " blockEntities." +
                        " Time " + ((level.getTickRate() > 1 || level.getTickRateTime() > 40) ? TextFormat.RED : TextFormat.YELLOW) + NukkitMath.round(level.getTickRateTime(), 2) + "ms" +
                        (level.getTickRate() > 1 ? " (tick rate " + level.getTickRate() + ")" : "")
        );
    }

    return true;
}
 
Example #12
Source File: FaweNukkit.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getPlatformVersion() {
    return Nukkit.VERSION;
}
 
Example #13
Source File: BugReportGenerator.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
private String generate() throws IOException {
    File reports = new File(Nukkit.DATA_PATH, "logs/bug_reports");
    if (!reports.isDirectory()) {
        reports.mkdirs();
    }

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
    String date = simpleDateFormat.format(new Date());

    SystemInfo systemInfo = new SystemInfo();
    long totalDiskSize = 0;
    StringBuilder model = new StringBuilder();
    for (HWDiskStore hwDiskStore : systemInfo.getHardware().getDiskStores()) {
        totalDiskSize += hwDiskStore.getSize();
        if (!model.toString().contains(hwDiskStore.getModel())) {
            model.append(hwDiskStore.getModel()).append(" ");
        }
    }

    StringWriter stringWriter = new StringWriter();
    throwable.printStackTrace(new PrintWriter(stringWriter));


    File mdReport = new File(reports, date + "_" + throwable.getClass().getSimpleName() + ".md");
    mdReport.createNewFile();
    String content = Utils.readFile(this.getClass().getClassLoader().getResourceAsStream("report_template.md"));

    Properties properties = getGitRepositoryState();
    System.out.println(properties.getProperty("git.commit.id.abbrev"));
    String abbrev = properties.getProperty("git.commit.id.abbrev");

    content = content.replace("${NUKKIT_VERSION}", Nukkit.VERSION);
    content = content.replace("${GIT_COMMIT_ABBREV}", abbrev);
    content = content.replace("${JAVA_VERSION}", System.getProperty("java.vm.name") + " (" + System.getProperty("java.runtime.version") + ")");
    content = content.replace("${HOSTOS}", systemInfo.getOperatingSystem().getFamily() + " [" + systemInfo.getOperatingSystem().getVersion().getVersion() + "]");
    content = content.replace("${MEMORY}", getCount(systemInfo.getHardware().getMemory().getTotal(), true));
    content = content.replace("${STORAGE_SIZE}", getCount(totalDiskSize, true));
    content = content.replace("${CPU_TYPE}", systemInfo.getHardware().getProcessor().getName());
    content = content.replace("${PHYSICAL_CORE}", String.valueOf(systemInfo.getHardware().getProcessor().getPhysicalProcessorCount()));
    content = content.replace("${LOGICAL_CORE}", String.valueOf(systemInfo.getHardware().getProcessor().getLogicalProcessorCount()));
    content = content.replace("${STACKTRACE}", stringWriter.toString());
    content = content.replace("${PLUGIN_ERROR}", String.valueOf(!throwable.getStackTrace()[0].getClassName().startsWith("cn.nukkit")).toUpperCase());
    content = content.replace("${STORAGE_TYPE}", model.toString());

    Utils.writeFile(mdReport, content);

    return mdReport.getAbsolutePath();
}
 
Example #14
Source File: StatusCommand.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!this.testPermission(sender)) {
        return true;
    }

    Server server = sender.getServer();
    sender.sendMessage(TextFormat.GREEN + "---- " + TextFormat.WHITE + "Server status" + TextFormat.GREEN + " ----");

    long time = (System.currentTimeMillis() - Nukkit.START_TIME) / 1000;
    int seconds = NukkitMath.floorDouble(time % 60);
    int minutes = NukkitMath.floorDouble((time % 3600) / 60);
    int hours = NukkitMath.floorDouble(time % (3600 * 24) / 3600);
    int days = NukkitMath.floorDouble(time / (3600 * 24));
    String upTimeString = TextFormat.RED + "" + days + TextFormat.GOLD + " days " +
            TextFormat.RED + hours + TextFormat.GOLD + " hours " +
            TextFormat.RED + minutes + TextFormat.GOLD + " minutes " +
            TextFormat.RED + seconds + TextFormat.GOLD + " seconds";
    sender.sendMessage(TextFormat.GOLD + "Uptime: " + upTimeString);

    TextFormat tpsColor = TextFormat.GREEN;
    float tps = server.getTicksPerSecond();
    if (tps < 17) {
        tpsColor = TextFormat.GOLD;
    } else if (tps < 12) {
        tpsColor = TextFormat.RED;
    }

    sender.sendMessage(TextFormat.GOLD + "Current TPS: " + tpsColor + NukkitMath.round(tps, 2));

    sender.sendMessage(TextFormat.GOLD + "Load: " + tpsColor + server.getTickUsage() + "%");

    sender.sendMessage(TextFormat.GOLD + "Network upload: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getUpload() / 1024 * 1000), 2) + " kB/s");

    sender.sendMessage(TextFormat.GOLD + "Network download: " + TextFormat.GREEN + NukkitMath.round((server.getNetwork().getDownload() / 1024 * 1000), 2) + " kB/s");

    sender.sendMessage(TextFormat.GOLD + "Thread count: " + TextFormat.GREEN + Thread.getAllStackTraces().size());


    Runtime runtime = Runtime.getRuntime();
    double totalMB = NukkitMath.round(((double) runtime.totalMemory()) / 1024 / 1024, 2);
    double usedMB = NukkitMath.round((double) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024, 2);
    double maxMB = NukkitMath.round(((double) runtime.maxMemory()) / 1024 / 1024, 2);
    double usage = usedMB / maxMB * 100;
    TextFormat usageColor = TextFormat.GREEN;

    if (usage > 85) {
        usageColor = TextFormat.GOLD;
    }

    sender.sendMessage(TextFormat.GOLD + "Used memory: " + usageColor + usedMB + " MB. (" + NukkitMath.round(usage, 2) + "%)");

    sender.sendMessage(TextFormat.GOLD + "Total memory: " + TextFormat.RED + totalMB + " MB.");

    sender.sendMessage(TextFormat.GOLD + "Maximum VM memory: " + TextFormat.RED + maxMB + " MB.");

    sender.sendMessage(TextFormat.GOLD + "Available processors: " + TextFormat.GREEN + runtime.availableProcessors());


    TextFormat playerColor = TextFormat.GREEN;
    if (((float) server.getOnlinePlayers().size() / (float) server.getMaxPlayers()) > 0.85) {
        playerColor = TextFormat.GOLD;
    }

    sender.sendMessage(TextFormat.GOLD + "Players: " + playerColor + server.getOnlinePlayers().size() + TextFormat.GREEN + " online, " +
            TextFormat.RED + server.getMaxPlayers() + TextFormat.GREEN + " max. ");

    for (Level level : server.getLevels().values()) {
        sender.sendMessage(
                TextFormat.GOLD + "World \"" + level.getFolderName() + "\"" + (!Objects.equals(level.getFolderName(), level.getName()) ? " (" + level.getName() + ")" : "") + ": " +
                        TextFormat.RED + level.getChunks().size() + TextFormat.GREEN + " chunks, " +
                        TextFormat.RED + level.getEntities().length + TextFormat.GREEN + " entities, " +
                        TextFormat.RED + level.getBlockEntities().size() + TextFormat.GREEN + " blockEntities." +
                        " Time " + ((level.getTickRate() > 1 || level.getTickRateTime() > 40) ? TextFormat.RED : TextFormat.YELLOW) + NukkitMath.round(level.getTickRateTime(), 2) + "ms" +
                        (level.getTickRate() > 1 ? " (tick rate " + level.getTickRate() + ")" : "")
        );
    }

    return true;
}
 
Example #15
Source File: NukkitWorldEdit.java    From FastAsyncWorldedit with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the version of the WorldEdit Nukkit implementation.
 *
 * @return a version string
 */
public String getInternalVersion() {
    return Nukkit.API_VERSION;
}