Fixed: Исправлена ошибка в кэлбеках

- Исправлено деление на 0 в команде tps
This commit is contained in:
Reider745
2024-07-30 09:42:42 +03:00
parent 295ed8e686
commit a45ccf8109
2 changed files with 26 additions and 12 deletions
@@ -17,11 +17,21 @@ public class TpsCommand extends Command {
long innerCoreSum = 0;
for(long time : innerCoreTimes)
if(time != 0)
innerCoreSum += Math.min(20, 1000 / time);
else{
commandSender.sendMessage("Not enough information");
return true;
}
long nukkitSum = 0;
for(long time : nukkitTimes)
if(time != 0)
nukkitSum += Math.min(20, 1000 / time);
else{
commandSender.sendMessage("Not enough information");
return true;
}
if(innerCoreSum != 0 && nukkitSum != 0) {
commandSender.sendMessage("Inner core tps: " + (innerCoreSum / 20.0f));
@@ -66,10 +66,12 @@ public class Callback {
Scriptable parent;
if (funcs != null) {
long profilingNanos = !profilingEnabled || isTick ? 0 : System.nanoTime();
synchronized (funcs) {
for (CallbackFunction callback : funcs) {
parent = callback.function.getParentScope();
callback.function.call(ctx, parent, parent, params);
}
}
if (profilingNanos != 0) {
profilingNanos = System.nanoTime() - profilingNanos;
Logger.debug("Profiling/" + name,
@@ -96,6 +98,7 @@ public class Callback {
if (profilingEnabled && !isTick) {
result.add(() -> profilingNanos.set(System.nanoTime()));
}
synchronized (funcs) {
for (CallbackFunction func0 : funcs) {
result.add(new Runnable() {
public void run() {
@@ -104,6 +107,7 @@ public class Callback {
}
});
}
}
if (profilingNanos.get() != 0) {
result.add(() -> Logger.debug("Profiling/" + name, funcs.size() + " functions in "
+ ((System.nanoTime() - profilingNanos.get()) / 1000000f) + "ms."));