Created DebugUtils

This commit is contained in:
themode 2020-11-13 21:57:45 +01:00
parent ade727cd0f
commit a1fd711b85
2 changed files with 53 additions and 0 deletions

View File

@ -489,6 +489,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
}
// handle block contacts
// TODO do not call every tick (it is pretty expensive)
final int minX = (int) Math.floor(boundingBox.getMinX());
final int maxX = (int) Math.ceil(boundingBox.getMaxX());
final int minY = (int) Math.floor(boundingBox.getMinY());

View File

@ -0,0 +1,52 @@
package net.minestom.server.utils.debug;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Utils class useful for debugging purpose.
*/
public final class DebugUtils {
public final static Logger LOGGER = LoggerFactory.getLogger(DebugUtils.class);
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private static final int OFFSET = 2; // Used to do not show DebugUtils in the stack trace
/**
* Prints the current thread stack trace elements.
*
* @param maxLine the maximum number of stack trace element
*/
public static synchronized void printStackTrace(int maxLine) {
maxLine += OFFSET;
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("START STACKTRACE");
stringBuilder.append(LINE_SEPARATOR);
for (int i = OFFSET; i < maxLine; i++) {
if (i >= elements.length)
break;
final StackTraceElement element = elements[i];
final String line = element.getClassName() + "." + element.getMethodName() + " (line:" + element.getLineNumber() + ")";
stringBuilder.append(line);
stringBuilder.append(LINE_SEPARATOR);
}
stringBuilder.append("END STACKTRACE");
LOGGER.info(stringBuilder.toString());
}
/**
* Prints the current thread stack trace elements.
*/
public static synchronized void printStackTrace() {
printStackTrace(Integer.MAX_VALUE);
}
}