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; long innerCoreSum = 0;
for(long time : innerCoreTimes) for(long time : innerCoreTimes)
innerCoreSum += Math.min(20, 1000 / time); if(time != 0)
innerCoreSum += Math.min(20, 1000 / time);
else{
commandSender.sendMessage("Not enough information");
return true;
}
long nukkitSum = 0; long nukkitSum = 0;
for(long time : nukkitTimes) for(long time : nukkitTimes)
nukkitSum += Math.min(20, 1000 / time); if(time != 0)
nukkitSum += Math.min(20, 1000 / time);
else{
commandSender.sendMessage("Not enough information");
return true;
}
if(innerCoreSum != 0 && nukkitSum != 0) { if(innerCoreSum != 0 && nukkitSum != 0) {
commandSender.sendMessage("Inner core tps: " + (innerCoreSum / 20.0f)); commandSender.sendMessage("Inner core tps: " + (innerCoreSum / 20.0f));
@@ -66,9 +66,11 @@ public class Callback {
Scriptable parent; Scriptable parent;
if (funcs != null) { if (funcs != null) {
long profilingNanos = !profilingEnabled || isTick ? 0 : System.nanoTime(); long profilingNanos = !profilingEnabled || isTick ? 0 : System.nanoTime();
for (CallbackFunction callback : funcs) { synchronized (funcs) {
parent = callback.function.getParentScope(); for (CallbackFunction callback : funcs) {
callback.function.call(ctx, parent, parent, params); parent = callback.function.getParentScope();
callback.function.call(ctx, parent, parent, params);
}
} }
if (profilingNanos != 0) { if (profilingNanos != 0) {
profilingNanos = System.nanoTime() - profilingNanos; profilingNanos = System.nanoTime() - profilingNanos;
@@ -96,13 +98,15 @@ public class Callback {
if (profilingEnabled && !isTick) { if (profilingEnabled && !isTick) {
result.add(() -> profilingNanos.set(System.nanoTime())); result.add(() -> profilingNanos.set(System.nanoTime()));
} }
for (CallbackFunction func0 : funcs) { synchronized (funcs) {
result.add(new Runnable() { for (CallbackFunction func0 : funcs) {
public void run() { result.add(new Runnable() {
Scriptable parent = func0.function.getParentScope(); public void run() {
func0.function.call(Compiler.assureContextForCurrentThread(), parent, parent, params); Scriptable parent = func0.function.getParentScope();
} func0.function.call(Compiler.assureContextForCurrentThread(), parent, parent, params);
}); }
});
}
} }
if (profilingNanos.get() != 0) { if (profilingNanos.get() != 0) {
result.add(() -> Logger.debug("Profiling/" + name, funcs.size() + " functions in " result.add(() -> Logger.debug("Profiling/" + name, funcs.size() + " functions in "