Merge pull request #109 from DerTyan/exception-handling

Added ExceptionManager for custom exception handling
This commit is contained in:
TheMode 2021-01-21 06:06:27 +01:00 committed by GitHub
commit 1cd3228c06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 152 additions and 59 deletions

View File

@ -9,6 +9,7 @@ import net.minestom.server.data.SerializableData;
import net.minestom.server.entity.EntityType; import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.Player; import net.minestom.server.entity.Player;
import net.minestom.server.event.GlobalEventHandler; import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.exception.ExceptionManager;
import net.minestom.server.extensions.Extension; import net.minestom.server.extensions.Extension;
import net.minestom.server.extensions.ExtensionManager; import net.minestom.server.extensions.ExtensionManager;
import net.minestom.server.fluids.Fluid; import net.minestom.server.fluids.Fluid;
@ -99,6 +100,8 @@ public final class MinecraftServer {
private static int nettyThreadCount = Runtime.getRuntime().availableProcessors(); private static int nettyThreadCount = Runtime.getRuntime().availableProcessors();
private static boolean processNettyErrors = false; private static boolean processNettyErrors = false;
private static ExceptionManager exceptionManager;
// In-Game Manager // In-Game Manager
private static ConnectionManager connectionManager; private static ConnectionManager connectionManager;
private static InstanceManager instanceManager; private static InstanceManager instanceManager;
@ -140,6 +143,10 @@ public final class MinecraftServer {
public static MinecraftServer init() { public static MinecraftServer init() {
if (minecraftServer != null) // don't init twice if (minecraftServer != null) // don't init twice
return minecraftServer; return minecraftServer;
// Initialize the ExceptionManager at first
exceptionManager = new ExceptionManager();
extensionManager = new ExtensionManager(); extensionManager = new ExtensionManager();
// warmup/force-init registries // warmup/force-init registries
@ -401,6 +408,16 @@ public final class MinecraftServer {
return benchmarkManager; return benchmarkManager;
} }
/**
* Gets the exception manager for exception handling.
*
* @return the exception manager
*/
public static ExceptionManager getExceptionManager() {
checkInitStatus(exceptionManager);
return exceptionManager;
}
/** /**
* Gets the manager handling server connections. * Gets the manager handling server connections.
* *

View File

@ -80,7 +80,7 @@ public final class UpdateManager {
doTickCallback(tickEndCallbacks, tickTime / 1000000L); doTickCallback(tickEndCallbacks, tickTime / 1000000L);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
}, 0, MinecraftServer.TICK_MS, TimeUnit.MILLISECONDS); }, 0, MinecraftServer.TICK_MS, TimeUnit.MILLISECONDS);
} }
@ -103,7 +103,7 @@ public final class UpdateManager {
try { try {
future.get(); future.get();
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }
} }

View File

@ -67,7 +67,7 @@ public final class BenchmarkManager {
try { try {
Thread.sleep(time); Thread.sleep(time);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }

View File

@ -2,6 +2,7 @@ package net.minestom.server.command;
import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.ints.IntList;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.builder.Command; import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandDispatcher; import net.minestom.server.command.builder.CommandDispatcher;
import net.minestom.server.command.builder.CommandSyntax; import net.minestom.server.command.builder.CommandSyntax;
@ -63,7 +64,7 @@ public final class CommandManager {
execute(consoleSender, command); execute(consoleSender, command);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
continue; continue;
} }
@ -71,14 +72,14 @@ public final class CommandManager {
try { try {
Thread.sleep(200); Thread.sleep(200);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }
try { try {
bi.close(); bi.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
}, "ConsoleCommand-Thread"); }, "ConsoleCommand-Thread");
consoleThread.setDaemon(true); consoleThread.setDaemon(true);

View File

@ -1,5 +1,6 @@
package net.minestom.server.data; package net.minestom.server.data;
import net.minestom.server.MinecraftServer;
import net.minestom.server.utils.clone.PublicCloneable; import net.minestom.server.utils.clone.PublicCloneable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -126,7 +127,7 @@ public abstract class Data implements PublicCloneable<Data> {
try { try {
return (Data) super.clone(); return (Data) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
throw new IllegalStateException("Weird thing happened"); throw new IllegalStateException("Weird thing happened");
} }
} }

View File

@ -183,7 +183,7 @@ public class SerializableDataImpl extends SerializableData {
try { try {
return Class.forName(className); return Class.forName(className);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
}); });

View File

@ -0,0 +1,17 @@
package net.minestom.server.exception;
/**
* Used when you want to implement your own exception handling, instead of just printing the stack trace.
* <p>
* Sets with {@link ExceptionManager#setExceptionHandler(ExceptionHandler)}.
*/
@FunctionalInterface
public interface ExceptionHandler {
/**
* Called when a exception was caught.
*
* @param e the thrown exception
*/
void handleException(Throwable e);
}

View File

@ -0,0 +1,38 @@
package net.minestom.server.exception;
import org.jetbrains.annotations.Nullable;
/**
* Manages the handling of exceptions.
*/
public final class ExceptionManager {
private ExceptionHandler exceptionHandler;
/**
* Handles an exception, if no {@link ExceptionHandler} is set, it just prints the stack trace.
*
* @param e the occurred exception
*/
public void handleException(Throwable e) {
this.getExceptionHandler().handleException(e);
}
/**
* Changes the exception handler, to allow custom exception handling.
*
* @param exceptionHandler the new {@link ExceptionHandler}, can be set to null to apply the default provider
*/
public void setExceptionHandler(@Nullable ExceptionHandler exceptionHandler) {
this.exceptionHandler = exceptionHandler;
}
/**
* Retrieves the current {@link ExceptionHandler}, can be the default one if none is defined.
*
* @return the current {@link ExceptionHandler}
*/
public ExceptionHandler getExceptionHandler() {
return this.exceptionHandler == null ? exceptionHandler = Throwable::printStackTrace : this.exceptionHandler;
}
}

View File

@ -3,6 +3,7 @@ package net.minestom.server.extensions;
import com.google.gson.Gson; import com.google.gson.Gson;
import net.minestom.dependencies.DependencyGetter; import net.minestom.dependencies.DependencyGetter;
import net.minestom.dependencies.maven.MavenRepository; import net.minestom.dependencies.maven.MavenRepository;
import net.minestom.server.MinecraftServer;
import net.minestom.server.extras.selfmodification.MinestomExtensionClassLoader; import net.minestom.server.extras.selfmodification.MinestomExtensionClassLoader;
import net.minestom.server.extras.selfmodification.MinestomRootClassLoader; import net.minestom.server.extras.selfmodification.MinestomRootClassLoader;
import net.minestom.server.ping.ResponseDataConsumer; import net.minestom.server.ping.ResponseDataConsumer;
@ -98,7 +99,7 @@ public class ExtensionManager {
setupClassLoader(discoveredExtension); setupClassLoader(discoveredExtension);
} catch (Exception e) { } catch (Exception e) {
discoveredExtension.loadStatus = DiscoveredExtension.LoadStatus.FAILED_TO_SETUP_CLASSLOADER; discoveredExtension.loadStatus = DiscoveredExtension.LoadStatus.FAILED_TO_SETUP_CLASSLOADER;
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
LOGGER.error("Failed to load extension {}", discoveredExtension.getName()); LOGGER.error("Failed to load extension {}", discoveredExtension.getName());
LOGGER.error("Failed to load extension", e); LOGGER.error("Failed to load extension", e);
} }
@ -113,9 +114,8 @@ public class ExtensionManager {
attemptSingleLoad(discoveredExtension); attemptSingleLoad(discoveredExtension);
} catch (Exception e) { } catch (Exception e) {
discoveredExtension.loadStatus = DiscoveredExtension.LoadStatus.LOAD_FAILED; discoveredExtension.loadStatus = DiscoveredExtension.LoadStatus.LOAD_FAILED;
e.printStackTrace();
LOGGER.error("Failed to load extension {}", discoveredExtension.getName()); LOGGER.error("Failed to load extension {}", discoveredExtension.getName());
LOGGER.error("Failed to load extension", e); MinecraftServer.getExceptionManager().handleException(e);
} }
} }
} }
@ -210,7 +210,7 @@ public class ExtensionManager {
loggerField.set(extension, LoggerFactory.getLogger(extensionClass)); loggerField.set(extension, LoggerFactory.getLogger(extensionClass));
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
// We made it accessible, should not occur // We made it accessible, should not occur
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException e) {
// This should also not occur (unless someone changed the logger in Extension superclass). // This should also not occur (unless someone changed the logger in Extension superclass).
LOGGER.error("Main class '{}' in '{}' has no logger field.", mainClass, extensionName, e); LOGGER.error("Main class '{}' in '{}' has no logger field.", mainClass, extensionName, e);
@ -265,7 +265,7 @@ public class ExtensionManager {
extensions.add(extension); extensions.add(extension);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }
return extensions; return extensions;
@ -284,7 +284,7 @@ public class ExtensionManager {
return extension; return extension;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }
@ -497,7 +497,7 @@ public class ExtensionManager {
LOGGER.info("Found mixin in extension {}: {}", extension.getName(), mixinConfigFile); LOGGER.info("Found mixin in extension {}: {}", extension.getName(), mixinConfigFile);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
LOGGER.error("Failed to load code modifier for extension in files: " + LOGGER.error("Failed to load code modifier for extension in files: " +
extension.files extension.files
.stream() .stream()
@ -531,7 +531,7 @@ public class ExtensionManager {
// close resources // close resources
classloader.close(); classloader.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
MinestomRootClassLoader.getInstance().removeChildInHierarchy(classloader); MinestomRootClassLoader.getInstance().removeChildInHierarchy(classloader);
} }

View File

@ -1,5 +1,6 @@
package net.minestom.server.extras.mojangAuth; package net.minestom.server.extras.mojangAuth;
import net.minestom.server.MinecraftServer;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -20,7 +21,7 @@ public final class MojangCrypt {
keyGen.initialize(1024); keyGen.initialize(1024);
return keyGen.generateKeyPair(); return keyGen.generateKeyPair();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
LOGGER.error("Key pair generation failed!"); LOGGER.error("Key pair generation failed!");
return null; return null;
} }
@ -31,7 +32,7 @@ public final class MojangCrypt {
try { try {
return digestData("SHA-1", data.getBytes("ISO_8859_1"), secretKey.getEncoded(), publicKey.getEncoded()); return digestData("SHA-1", data.getBytes("ISO_8859_1"), secretKey.getEncoded(), publicKey.getEncoded());
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }
@ -47,7 +48,7 @@ public final class MojangCrypt {
return digest.digest(); return digest.digest();
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }
@ -64,7 +65,7 @@ public final class MojangCrypt {
try { try {
return setupCipher(mode, key.getAlgorithm(), key).doFinal(data); return setupCipher(mode, key.getAlgorithm(), key).doFinal(data);
} catch (IllegalBlockSizeException | BadPaddingException var4) { } catch (IllegalBlockSizeException | BadPaddingException var4) {
var4.printStackTrace(); MinecraftServer.getExceptionManager().handleException(var4);
} }
LOGGER.error("Cipher data failed!"); LOGGER.error("Cipher data failed!");
@ -77,7 +78,7 @@ public final class MojangCrypt {
cipher4.init(mode, key); cipher4.init(mode, key);
return cipher4; return cipher4;
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException var4) { } catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException var4) {
var4.printStackTrace(); MinecraftServer.getExceptionManager().handleException(var4);
} }
LOGGER.error("Cipher creation failed!"); LOGGER.error("Cipher creation failed!");

View File

@ -1,5 +1,6 @@
package net.minestom.server.extras.selfmodification; package net.minestom.server.extras.selfmodification;
import net.minestom.server.MinecraftServer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
@ -260,7 +261,7 @@ public class MinestomRootClassLoader extends HierarchyClassLoader {
} }
} }
} catch (MalformedURLException | ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) { } catch (MalformedURLException | ClassNotFoundException | InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }

View File

@ -3,6 +3,7 @@ package net.minestom.server.gamedata.loottables;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import net.minestom.server.MinecraftServer;
import net.minestom.server.gamedata.Condition; import net.minestom.server.gamedata.Condition;
import net.minestom.server.registry.ResourceGatherer; import net.minestom.server.registry.ResourceGatherer;
import net.minestom.server.utils.NamespaceID; import net.minestom.server.utils.NamespaceID;
@ -84,7 +85,7 @@ public final class LootTableManager {
try (reader) { try (reader) {
return cache.computeIfAbsent(name, _name -> create(reader)); return cache.computeIfAbsent(name, _name -> create(reader));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }

View File

@ -20,7 +20,7 @@ public class TagType implements LootTableEntryType {
try { try {
return new TagEntry(this, MinecraftServer.getTagManager().load(NamespaceID.from(name), "items"), expand, weight, quality, conditions); return new TagEntry(this, MinecraftServer.getTagManager().load(NamespaceID.from(name), "items"), expand, weight, quality, conditions);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }

View File

@ -2,6 +2,7 @@ package net.minestom.server.gamedata.tags;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import net.minestom.server.MinecraftServer;
import net.minestom.server.network.packet.server.play.TagsPacket; import net.minestom.server.network.packet.server.play.TagsPacket;
import net.minestom.server.registry.ResourceGatherer; import net.minestom.server.registry.ResourceGatherer;
import net.minestom.server.utils.NamespaceID; import net.minestom.server.utils.NamespaceID;
@ -288,7 +289,7 @@ public class TagManager {
try { try {
return load(name, type); return load(name, type);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return Tag.EMPTY; return Tag.EMPTY;
} }
} }

View File

@ -59,7 +59,7 @@ public interface IChunkLoader {
parallelSavingThreadPool.awaitTermination(1L, java.util.concurrent.TimeUnit.DAYS); parallelSavingThreadPool.awaitTermination(1L, java.util.concurrent.TimeUnit.DAYS);
OptionalCallback.execute(callback); OptionalCallback.execute(callback);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} else { } else {
AtomicInteger counter = new AtomicInteger(); AtomicInteger counter = new AtomicInteger();

View File

@ -2,6 +2,7 @@ package net.minestom.server.instance.palette;
import it.unimi.dsi.fastutil.shorts.Short2ShortLinkedOpenHashMap; import it.unimi.dsi.fastutil.shorts.Short2ShortLinkedOpenHashMap;
import it.unimi.dsi.fastutil.shorts.Short2ShortOpenHashMap; import it.unimi.dsi.fastutil.shorts.Short2ShortOpenHashMap;
import net.minestom.server.MinecraftServer;
import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Chunk;
import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.chunk.ChunkUtils;
@ -171,7 +172,7 @@ public class PaletteStorage implements PublicCloneable<PaletteStorage> {
paletteStorage.blockPaletteMaps = blockPaletteMaps.clone(); paletteStorage.blockPaletteMaps = blockPaletteMaps.clone();
return paletteStorage; return paletteStorage;
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
throw new IllegalStateException("Weird thing happened"); throw new IllegalStateException("Weird thing happened");
} }
} }

View File

@ -2,6 +2,7 @@ package net.minestom.server.item;
import it.unimi.dsi.fastutil.objects.Object2ShortMap; import it.unimi.dsi.fastutil.objects.Object2ShortMap;
import it.unimi.dsi.fastutil.objects.Object2ShortOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ShortOpenHashMap;
import net.minestom.server.MinecraftServer;
import net.minestom.server.chat.JsonMessage; import net.minestom.server.chat.JsonMessage;
import net.minestom.server.data.Data; import net.minestom.server.data.Data;
import net.minestom.server.data.DataContainer; import net.minestom.server.data.DataContainer;
@ -596,7 +597,7 @@ public class ItemStack implements DataContainer, PublicCloneable<ItemStack> {
return itemStack; return itemStack;
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }

View File

@ -1,5 +1,6 @@
package net.minestom.server.item.metadata; package net.minestom.server.item.metadata;
import net.minestom.server.MinecraftServer;
import net.minestom.server.item.ItemStack; import net.minestom.server.item.ItemStack;
import net.minestom.server.utils.clone.PublicCloneable; import net.minestom.server.utils.clone.PublicCloneable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -53,7 +54,7 @@ public abstract class ItemMeta implements PublicCloneable<ItemMeta> {
try { try {
return (ItemMeta) super.clone(); return (ItemMeta) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
throw new IllegalStateException("Weird thing happened"); throw new IllegalStateException("Weird thing happened");
} }
} }

View File

@ -1,5 +1,6 @@
package net.minestom.server.item.metadata; package net.minestom.server.item.metadata;
import net.minestom.server.MinecraftServer;
import net.minestom.server.chat.ChatColor; import net.minestom.server.chat.ChatColor;
import net.minestom.server.utils.clone.CloneUtils; import net.minestom.server.utils.clone.CloneUtils;
import net.minestom.server.utils.clone.PublicCloneable; import net.minestom.server.utils.clone.PublicCloneable;
@ -271,7 +272,7 @@ public class MapMeta extends ItemMeta {
try { try {
return (MapDecoration) super.clone(); return (MapDecoration) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
throw new IllegalStateException("Something weird happened"); throw new IllegalStateException("Something weird happened");
} }
} }

View File

@ -1,5 +1,6 @@
package net.minestom.server.map; package net.minestom.server.map;
import net.minestom.server.MinecraftServer;
import net.minestom.server.utils.thread.MinestomThread; import net.minestom.server.utils.thread.MinestomThread;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -104,7 +105,7 @@ public enum MapColors {
reduction = Integer.parseInt(reductionStr); reduction = Integer.parseInt(reductionStr);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
System.err.println("Invalid integer in reduction argument: " + reductionStr); System.err.println("Invalid integer in reduction argument: " + reductionStr);
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
if (reduction < 0 || reduction >= 255) { if (reduction < 0 || reduction >= 255) {
@ -195,7 +196,7 @@ public enum MapColors {
threads.shutdown(); threads.shutdown();
threads.awaitTermination(100, TimeUnit.MINUTES); threads.awaitTermination(100, TimeUnit.MINUTES);
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); MinecraftServer.getExceptionManager().handleException(t);
} }
} }

View File

@ -176,7 +176,7 @@ public final class PacketProcessor {
LOGGER.warn("Connection {} ({}) sent an unexpected packet.", LOGGER.warn("Connection {} ({}) sent an unexpected packet.",
connection.getRemoteAddress(), connection.getRemoteAddress(),
username); username);
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }
} }

View File

@ -219,7 +219,7 @@ public final class NettyServer {
this.serverChannel = (ServerSocketChannel) cf.channel(); this.serverChannel = (ServerSocketChannel) cf.channel();
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
ex.printStackTrace(); MinecraftServer.getExceptionManager().handleException(ex);
} }
} }
@ -263,7 +263,7 @@ public final class NettyServer {
this.worker.shutdownGracefully(); this.worker.shutdownGracefully();
this.boss.shutdownGracefully(); this.boss.shutdownGracefully();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
this.trafficScheduler.shutdown(); this.trafficScheduler.shutdown();

View File

@ -34,7 +34,7 @@ public class ClientChannel extends SimpleChannelInboundHandler<InboundPacket> {
try { try {
packetProcessor.process(ctx, packet); packetProcessor.process(ctx, packet);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} finally { } finally {
// Check remaining // Check remaining
final ByteBuf body = packet.getBody(); final ByteBuf body = packet.getBody();
@ -74,7 +74,7 @@ public class ClientChannel extends SimpleChannelInboundHandler<InboundPacket> {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
if (MinecraftServer.shouldProcessNettyErrors()) { if (MinecraftServer.shouldProcessNettyErrors()) {
LOGGER.info(cause.getMessage()); LOGGER.info(cause.getMessage());
cause.printStackTrace(); MinecraftServer.getExceptionManager().handleException(cause);
} }
ctx.close(); ctx.close();
} }

View File

@ -57,7 +57,7 @@ public class EncryptionResponsePacket implements ClientPreplayPacket {
CONNECTION_MANAGER.startPlayState(connection, gameProfile.getId(), gameProfile.getName(), true); CONNECTION_MANAGER.startPlayState(connection, gameProfile.getId(), gameProfile.getName(), true);
} }
} catch (AuthenticationUnavailableException e) { } catch (AuthenticationUnavailableException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
}); });
} }

View File

@ -150,7 +150,7 @@ public class NettyPlayerConnection extends PlayerConnection {
if (MinecraftServer.shouldProcessNettyErrors()) { if (MinecraftServer.shouldProcessNettyErrors()) {
return channelFuture.addListener(future -> { return channelFuture.addListener(future -> {
if (!future.isSuccess()) { if (!future.isSuccess()) {
future.cause().printStackTrace(); MinecraftServer.getExceptionManager().handleException(future.cause());
} }
}); });
} else { } else {
@ -165,7 +165,7 @@ public class NettyPlayerConnection extends PlayerConnection {
if (MinecraftServer.shouldProcessNettyErrors()) { if (MinecraftServer.shouldProcessNettyErrors()) {
return channelFuture.addListener(future -> { return channelFuture.addListener(future -> {
if (!future.isSuccess()) { if (!future.isSuccess()) {
future.cause().printStackTrace(); MinecraftServer.getExceptionManager().handleException(future.cause());
} }
}); });
} else { } else {

View File

@ -1,5 +1,6 @@
package net.minestom.server.potion; package net.minestom.server.potion;
import net.minestom.server.MinecraftServer;
import net.minestom.server.utils.clone.PublicCloneable; import net.minestom.server.utils.clone.PublicCloneable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -72,7 +73,7 @@ public class CustomPotionEffect implements PublicCloneable<CustomPotionEffect> {
try { try {
return (CustomPotionEffect) super.clone(); return (CustomPotionEffect) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
throw new IllegalStateException("Weird thing happened"); throw new IllegalStateException("Weird thing happened");
} }
} }

View File

@ -1,5 +1,6 @@
package net.minestom.server.storage.systems; package net.minestom.server.storage.systems;
import net.minestom.server.MinecraftServer;
import net.minestom.server.storage.StorageOptions; import net.minestom.server.storage.StorageOptions;
import net.minestom.server.storage.StorageSystem; import net.minestom.server.storage.StorageSystem;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -41,7 +42,7 @@ public class FileStorageSystem implements StorageSystem {
try { try {
this.rocksDB = RocksDB.open(options, location); this.rocksDB = RocksDB.open(options, location);
} catch (RocksDBException e) { } catch (RocksDBException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }
@ -50,7 +51,7 @@ public class FileStorageSystem implements StorageSystem {
try { try {
return rocksDB.get(getKey(key)); return rocksDB.get(getKey(key));
} catch (RocksDBException e) { } catch (RocksDBException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }
@ -60,7 +61,7 @@ public class FileStorageSystem implements StorageSystem {
try { try {
this.rocksDB.put(getKey(key), data); this.rocksDB.put(getKey(key), data);
} catch (RocksDBException e) { } catch (RocksDBException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }
@ -69,7 +70,7 @@ public class FileStorageSystem implements StorageSystem {
try { try {
this.rocksDB.delete(getKey(key)); this.rocksDB.delete(getKey(key));
} catch (RocksDBException e) { } catch (RocksDBException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }
@ -78,7 +79,7 @@ public class FileStorageSystem implements StorageSystem {
try { try {
this.rocksDB.closeE(); this.rocksDB.closeE();
} catch (RocksDBException e) { } catch (RocksDBException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }

View File

@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongArraySet; import it.unimi.dsi.fastutil.longs.LongArraySet;
import it.unimi.dsi.fastutil.longs.LongSet; import it.unimi.dsi.fastutil.longs.LongSet;
import net.minestom.server.MinecraftServer;
import net.minestom.server.instance.Instance; import net.minestom.server.instance.Instance;
import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.chunk.ChunkUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -150,7 +151,7 @@ public class PerGroupChunkProvider extends ThreadProvider {
try { try {
countDownLatch.await(); countDownLatch.await();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
// Tick all this chunk group // Tick all this chunk group

View File

@ -106,7 +106,7 @@ public final class SchedulerManager {
try { try {
batchesPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); batchesPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }

View File

@ -1,6 +1,7 @@
package net.minestom.server.timer; package net.minestom.server.timer;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minestom.server.MinecraftServer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Objects; import java.util.Objects;
@ -65,7 +66,7 @@ public class Task implements Runnable {
this.id, this.id,
e.getMessage() e.getMessage()
); );
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} finally { } finally {
if (this.repeat == 0) this.finish(); if (this.repeat == 0) this.finish();
this.currentThreadTask = null; this.currentThreadTask = null;

View File

@ -1,5 +1,6 @@
package net.minestom.server.utils; package net.minestom.server.utils;
import net.minestom.server.MinecraftServer;
import net.minestom.server.instance.block.BlockFace; import net.minestom.server.instance.block.BlockFace;
import net.minestom.server.utils.clone.PublicCloneable; import net.minestom.server.utils.clone.PublicCloneable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -229,7 +230,7 @@ public class BlockPosition implements PublicCloneable<BlockPosition> {
try { try {
return (BlockPosition) super.clone(); return (BlockPosition) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }

View File

@ -118,7 +118,7 @@ public final class NBTUtils {
loadDataIntoItem(item, nbt); loadDataIntoItem(item, nbt);
} }
} catch (IOException | NBTException e) { } catch (IOException | NBTException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
return item; return item;

View File

@ -165,7 +165,7 @@ public final class PacketUtils {
try { try {
packet.write(writer); packet.write(writer);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
return writer.getBuffer(); return writer.getBuffer();

View File

@ -1,5 +1,6 @@
package net.minestom.server.utils; package net.minestom.server.utils;
import net.minestom.server.MinecraftServer;
import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.utils.clone.PublicCloneable; import net.minestom.server.utils.clone.PublicCloneable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -203,7 +204,7 @@ public class Position implements PublicCloneable<Position> {
try { try {
return (Position) super.clone(); return (Position) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }

View File

@ -1,5 +1,6 @@
package net.minestom.server.utils; package net.minestom.server.utils;
import net.minestom.server.MinecraftServer;
import net.minestom.server.utils.clone.PublicCloneable; import net.minestom.server.utils.clone.PublicCloneable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -272,7 +273,7 @@ public class Vector implements PublicCloneable<Vector> {
try { try {
return (Vector) super.clone(); return (Vector) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
throw new IllegalStateException("Weird thing happened"); throw new IllegalStateException("Weird thing happened");
} }
} }

View File

@ -1,5 +1,6 @@
package net.minestom.server.utils.async; package net.minestom.server.utils.async;
import net.minestom.server.MinecraftServer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -11,7 +12,7 @@ public final class AsyncUtils {
try { try {
runnable.run(); runnable.run();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
}); });
} }

View File

@ -2,6 +2,7 @@ package net.minestom.server.utils.binary;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.minestom.server.MinecraftServer;
import net.minestom.server.item.ItemStack; import net.minestom.server.item.ItemStack;
import net.minestom.server.utils.BlockPosition; import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.NBTUtils; import net.minestom.server.utils.NBTUtils;
@ -248,7 +249,7 @@ public class BinaryWriter extends OutputStream {
nbtWriter.writeNamed(name, tag); nbtWriter.writeNamed(name, tag);
} catch (IOException e) { } catch (IOException e) {
// should not throw, as nbtWriter points to this PacketWriter // should not throw, as nbtWriter points to this PacketWriter
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
} }
} }

View File

@ -2,6 +2,7 @@ package net.minestom.server.utils.mojang;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import net.minestom.server.MinecraftServer;
import net.minestom.server.utils.url.URLUtils; import net.minestom.server.utils.url.URLUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -20,7 +21,7 @@ public final class MojangUtils {
final String response = URLUtils.getText(url); final String response = URLUtils.getText(url);
return JsonParser.parseString(response).getAsJsonObject(); return JsonParser.parseString(response).getAsJsonObject();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }
@ -33,7 +34,7 @@ public final class MojangUtils {
final String response = URLUtils.getText(url); final String response = URLUtils.getText(url);
return JsonParser.parseString(response).getAsJsonObject(); return JsonParser.parseString(response).getAsJsonObject();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); MinecraftServer.getExceptionManager().handleException(e);
return null; return null;
} }
} }