Java Code Examples for cn.nukkit.math.NukkitMath#round()
The following examples show how to use
cn.nukkit.math.NukkitMath#round() .
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: Server.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void titleTick() { if (!Nukkit.ANSI || !Nukkit.TITLE) { return; } Runtime runtime = Runtime.getRuntime(); double used = NukkitMath.round((double) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024, 2); double max = NukkitMath.round(((double) runtime.maxMemory()) / 1024 / 1024, 2); String usage = Math.round(used / max * 100) + "%"; String title = (char) 0x1b + "]0;" + this.getName() + " " + this.getNukkitVersion() + " | Online " + this.players.size() + "/" + this.getMaxPlayers() + " | Memory " + usage; if (!Nukkit.shortTitle) { title += " | U " + NukkitMath.round((this.network.getUpload() / 1024 * 1000), 2) + " D " + NukkitMath.round((this.network.getDownload() / 1024 * 1000), 2) + " kB/s"; } title += " | TPS " + this.getTicksPerSecond() + " | Load " + this.getTickUsage() + "%" + (char) 0x07; System.out.print(title); }
Example 2
Source File: Server.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public void titleTick() { if (!Nukkit.ANSI) { return; } Runtime runtime = Runtime.getRuntime(); double used = NukkitMath.round((double) (runtime.totalMemory() - runtime.freeMemory()) / 1024 / 1024, 2); double max = NukkitMath.round(((double) runtime.maxMemory()) / 1024 / 1024, 2); String usage = Math.round(used / max * 100) + "%"; String title = (char) 0x1b + "]0;" + this.getName() + " " + this.getNukkitVersion() + " | Online " + this.players.size() + "/" + this.getMaxPlayers() + " | Memory " + usage; if (!Nukkit.shortTitle) { title += " | U " + NukkitMath.round((this.network.getUpload() / 1024 * 1000), 2) + " D " + NukkitMath.round((this.network.getDownload() / 1024 * 1000), 2) + " kB/s"; } title += " | TPS " + this.getTicksPerSecond() + " | Load " + this.getTickUsage() + "%" + (char) 0x07; System.out.print(title); }
Example 3
Source File: Server.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public float getTicksPerSecondAverage() { float sum = 0; int count = this.tickAverage.length; for (float aTickAverage : this.tickAverage) { sum += aTickAverage; } return (float) NukkitMath.round(sum / count, 2); }
Example 4
Source File: Binary.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public static float readFloat(byte[] bytes, int accuracy) { float val = Float.intBitsToFloat(readInt(bytes)); if (accuracy > -1) { return (float) NukkitMath.round(val, accuracy); } else { return val; } }
Example 5
Source File: Binary.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public static float readLFloat(byte[] bytes, int accuracy) { float val = Float.intBitsToFloat(readLInt(bytes)); if (accuracy > -1) { return (float) NukkitMath.round(val, accuracy); } else { return val; } }
Example 6
Source File: Binary.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static float readLFloat(byte[] bytes, int accuracy) { float val = Float.intBitsToFloat(readLInt(bytes)); if (accuracy > -1) { return (float) NukkitMath.round(val, accuracy); } else { return val; } }
Example 7
Source File: Server.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public float getTicksPerSecondAverage() { float sum = 0; int count = this.tickAverage.length; for (float aTickAverage : this.tickAverage) { sum += aTickAverage; } return (float) NukkitMath.round(sum / count, 2); }
Example 8
Source File: Binary.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static float readFloat(byte[] bytes, int accuracy) { float val = Float.intBitsToFloat(readInt(bytes)); if (accuracy > -1) { return (float) NukkitMath.round(val, accuracy); } else { return val; } }
Example 9
Source File: Binary.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static float readFloat(byte[] bytes, int accuracy) { float val = Float.intBitsToFloat(readInt(bytes)); if (accuracy > -1) { return (float) NukkitMath.round(val, accuracy); } else { return val; } }
Example 10
Source File: Binary.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public static float readLFloat(byte[] bytes, int accuracy) { float val = Float.intBitsToFloat(readLInt(bytes)); if (accuracy > -1) { return (float) NukkitMath.round(val, accuracy); } else { return val; } }
Example 11
Source File: Server.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public float getTicksPerSecondAverage() { float sum = 0; int count = this.tickAverage.length; for (float aTickAverage : this.tickAverage) { sum += aTickAverage; } return (float) NukkitMath.round(sum / count, 2); }
Example 12
Source File: StatusCommand.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@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 13
Source File: Server.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public float getTickUsage() { return (float) NukkitMath.round(this.maxUse * 100, 2); }
Example 14
Source File: SynapseEntry.java From SynapseAPI with GNU General Public License v3.0 | 4 votes |
public double getTicksPerSecond() { long more = this.tickUseTime - 10; if (more < 0) return 100; return NukkitMath.round(10f / (double) this.tickUseTime, 3) * 100; }
Example 15
Source File: StatusCommand.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@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 16
Source File: Server.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public float getTickUsage() { return (float) NukkitMath.round(this.maxUse * 100, 2); }
Example 17
Source File: StatusCommand.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@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 18
Source File: Server.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public float getTickUsage() { return (float) NukkitMath.round(this.maxUse * 100, 2); }