fixed: tps command
This commit is contained in:
@@ -2,12 +2,12 @@ package com.reider745.commands;
|
||||
|
||||
import cn.nukkit.command.Command;
|
||||
import cn.nukkit.command.CommandSender;
|
||||
import cn.nukkit.math.NukkitMath;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TpsCommand extends Command {
|
||||
public static long[] innerCoreTimes = new long[20];
|
||||
public static long[] nukkitTimes = new long[20];
|
||||
|
||||
public TpsCommand() {
|
||||
super("tps");
|
||||
@@ -19,36 +19,24 @@ public class TpsCommand extends Command {
|
||||
return false;
|
||||
|
||||
try{
|
||||
float aboba1 = 0, aboba2 = 0;
|
||||
long innerCoreSum = 0;
|
||||
float count = 0;
|
||||
long sum = 0;
|
||||
for(long time : innerCoreTimes)
|
||||
if(time != 0) {
|
||||
innerCoreSum += time;
|
||||
aboba1++;
|
||||
sum += time;
|
||||
count++;
|
||||
}
|
||||
|
||||
long nukkitSum = 0;
|
||||
for(long time : nukkitTimes)
|
||||
if(time != 0) {
|
||||
nukkitSum += time;
|
||||
aboba2++;
|
||||
}
|
||||
|
||||
if(innerCoreSum != 0) {
|
||||
final float avgTime = innerCoreSum / aboba1;
|
||||
commandSender.sendMessage("Inner core tps: " + Math.min(20, 1000 / avgTime) + ", ms: "+avgTime);
|
||||
if(sum != 0) {
|
||||
final float avgTime = sum / count;
|
||||
commandSender.sendMessage("Inner core tps: " + NukkitMath.round(Math.min(20, 1000 / avgTime), 2) + ", ms: "+avgTime);
|
||||
}else
|
||||
commandSender.sendMessage("Inner core tps: 20.0");
|
||||
|
||||
if(nukkitSum != 0) {
|
||||
final float avgTime = nukkitSum / aboba1;
|
||||
commandSender.sendMessage("Nukkit tps: " + Math.min(20, 1000 / avgTime) + ", ms: "+avgTime);
|
||||
}else
|
||||
commandSender.sendMessage("Nukkit tps: 20.0");
|
||||
commandSender.sendMessage("Nukkit tps: " + NukkitMath.round(commandSender.getServer().getTicksPerSecond(), 2));
|
||||
}catch (Exception e){
|
||||
commandSender.sendMessage("Not enough information");
|
||||
commandSender.sendMessage(Arrays.toString(innerCoreTimes));
|
||||
commandSender.sendMessage(Arrays.toString(nukkitTimes));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.reider745.hooks;
|
||||
|
||||
import cn.nukkit.Server;
|
||||
import cn.nukkit.level.generator.Normal;
|
||||
import cn.nukkit.network.protocol.ProtocolInfo;
|
||||
import cn.nukkit.plugin.JavaPluginLoader;
|
||||
import cn.nukkit.plugin.PluginClassLoader;
|
||||
@@ -9,8 +8,6 @@ import cn.nukkit.utils.Config;
|
||||
import cn.nukkit.utils.Utils;
|
||||
|
||||
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.annotation.Inject;
|
||||
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;
|
||||
|
||||
@Inject
|
||||
public static void checkTickUpdates(Server server, int tick) {
|
||||
indexTime = (indexTime + 1) % 20;
|
||||
TpsCommand.nukkitTimes[indexTime] = System.currentTimeMillis() - start_pre;
|
||||
|
||||
try {
|
||||
try {
|
||||
@@ -104,8 +99,6 @@ public class ServerHooks {
|
||||
}catch (Throwable e){
|
||||
Logger.warning("IC-TICK", e);
|
||||
}
|
||||
|
||||
start_pre = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Inject(type = TypeHook.AFTER)
|
||||
|
||||
Reference in New Issue
Block a user