fixed: tps command

This commit is contained in:
Reider745
2025-01-04 20:12:13 +03:00
parent 2ed453ef58
commit 728b2aaeb5
2 changed files with 9 additions and 28 deletions
@@ -2,12 +2,12 @@ package com.reider745.commands;
import cn.nukkit.command.Command; import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender; import cn.nukkit.command.CommandSender;
import cn.nukkit.math.NukkitMath;
import java.util.Arrays; import java.util.Arrays;
public class TpsCommand extends Command { public class TpsCommand extends Command {
public static long[] innerCoreTimes = new long[20]; public static long[] innerCoreTimes = new long[20];
public static long[] nukkitTimes = new long[20];
public TpsCommand() { public TpsCommand() {
super("tps"); super("tps");
@@ -19,36 +19,24 @@ public class TpsCommand extends Command {
return false; return false;
try{ try{
float aboba1 = 0, aboba2 = 0; float count = 0;
long innerCoreSum = 0; long sum = 0;
for(long time : innerCoreTimes) for(long time : innerCoreTimes)
if(time != 0) { if(time != 0) {
innerCoreSum += time; sum += time;
aboba1++; count++;
} }
long nukkitSum = 0; if(sum != 0) {
for(long time : nukkitTimes) final float avgTime = sum / count;
if(time != 0) { commandSender.sendMessage("Inner core tps: " + NukkitMath.round(Math.min(20, 1000 / avgTime), 2) + ", ms: "+avgTime);
nukkitSum += time;
aboba2++;
}
if(innerCoreSum != 0) {
final float avgTime = innerCoreSum / aboba1;
commandSender.sendMessage("Inner core tps: " + Math.min(20, 1000 / avgTime) + ", ms: "+avgTime);
}else }else
commandSender.sendMessage("Inner core tps: 20.0"); commandSender.sendMessage("Inner core tps: 20.0");
if(nukkitSum != 0) { commandSender.sendMessage("Nukkit tps: " + NukkitMath.round(commandSender.getServer().getTicksPerSecond(), 2));
final float avgTime = nukkitSum / aboba1;
commandSender.sendMessage("Nukkit tps: " + Math.min(20, 1000 / avgTime) + ", ms: "+avgTime);
}else
commandSender.sendMessage("Nukkit tps: 20.0");
}catch (Exception e){ }catch (Exception e){
commandSender.sendMessage("Not enough information"); commandSender.sendMessage("Not enough information");
commandSender.sendMessage(Arrays.toString(innerCoreTimes)); commandSender.sendMessage(Arrays.toString(innerCoreTimes));
commandSender.sendMessage(Arrays.toString(nukkitTimes));
} }
return true; return true;
@@ -1,7 +1,6 @@
package com.reider745.hooks; package com.reider745.hooks;
import cn.nukkit.Server; import cn.nukkit.Server;
import cn.nukkit.level.generator.Normal;
import cn.nukkit.network.protocol.ProtocolInfo; import cn.nukkit.network.protocol.ProtocolInfo;
import cn.nukkit.plugin.JavaPluginLoader; import cn.nukkit.plugin.JavaPluginLoader;
import cn.nukkit.plugin.PluginClassLoader; import cn.nukkit.plugin.PluginClassLoader;
@@ -9,8 +8,6 @@ import cn.nukkit.utils.Config;
import cn.nukkit.utils.Utils; import cn.nukkit.utils.Utils;
import com.reider745.InnerCoreServer; import com.reider745.InnerCoreServer;
import com.reider745.Main;
import com.reider745.api.hooks.HookClass;
import com.reider745.api.hooks.TypeHook; import com.reider745.api.hooks.TypeHook;
import com.reider745.api.hooks.annotation.Inject; import com.reider745.api.hooks.annotation.Inject;
import com.reider745.api.hooks.annotation.Hooks; import com.reider745.api.hooks.annotation.Hooks;
@@ -80,13 +77,11 @@ public class ServerHooks {
}; };
} }
private static long start_pre = 0;
private static int indexTime = 0; private static int indexTime = 0;
@Inject @Inject
public static void checkTickUpdates(Server server, int tick) { public static void checkTickUpdates(Server server, int tick) {
indexTime = (indexTime + 1) % 20; indexTime = (indexTime + 1) % 20;
TpsCommand.nukkitTimes[indexTime] = System.currentTimeMillis() - start_pre;
try { try {
try { try {
@@ -104,8 +99,6 @@ public class ServerHooks {
}catch (Throwable e){ }catch (Throwable e){
Logger.warning("IC-TICK", e); Logger.warning("IC-TICK", e);
} }
start_pre = System.currentTimeMillis();
} }
@Inject(type = TypeHook.AFTER) @Inject(type = TypeHook.AFTER)