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.Player;
import net.minestom.server.event.GlobalEventHandler;
import net.minestom.server.exception.ExceptionManager;
import net.minestom.server.extensions.Extension;
import net.minestom.server.extensions.ExtensionManager;
import net.minestom.server.fluids.Fluid;
@ -99,6 +100,8 @@ public final class MinecraftServer {
private static int nettyThreadCount = Runtime.getRuntime().availableProcessors();
private static boolean processNettyErrors = false;
private static ExceptionManager exceptionManager;
// In-Game Manager
private static ConnectionManager connectionManager;
private static InstanceManager instanceManager;
@ -140,6 +143,10 @@ public final class MinecraftServer {
public static MinecraftServer init() {
if (minecraftServer != null) // don't init twice
return minecraftServer;
// Initialize the ExceptionManager at first
exceptionManager = new ExceptionManager();
extensionManager = new ExtensionManager();
// warmup/force-init registries
@ -401,6 +408,16 @@ public final class MinecraftServer {
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.
*

View File

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

View File

@ -67,7 +67,7 @@ public final class BenchmarkManager {
try {
Thread.sleep(time);
} 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.IntList;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandDispatcher;
import net.minestom.server.command.builder.CommandSyntax;
@ -63,7 +64,7 @@ public final class CommandManager {
execute(consoleSender, command);
}
} catch (IOException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
continue;
}
@ -71,14 +72,14 @@ public final class CommandManager {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
}
}
try {
bi.close();
} catch (IOException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
}
}, "ConsoleCommand-Thread");
consoleThread.setDaemon(true);

View File

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

View File

@ -183,7 +183,7 @@ public class SerializableDataImpl extends SerializableData {
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
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 net.minestom.dependencies.DependencyGetter;
import net.minestom.dependencies.maven.MavenRepository;
import net.minestom.server.MinecraftServer;
import net.minestom.server.extras.selfmodification.MinestomExtensionClassLoader;
import net.minestom.server.extras.selfmodification.MinestomRootClassLoader;
import net.minestom.server.ping.ResponseDataConsumer;
@ -98,7 +99,7 @@ public class ExtensionManager {
setupClassLoader(discoveredExtension);
} catch (Exception e) {
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", e);
}
@ -113,9 +114,8 @@ public class ExtensionManager {
attemptSingleLoad(discoveredExtension);
} catch (Exception e) {
discoveredExtension.loadStatus = DiscoveredExtension.LoadStatus.LOAD_FAILED;
e.printStackTrace();
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));
} catch (IllegalAccessException e) {
// We made it accessible, should not occur
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
} catch (NoSuchFieldException e) {
// 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);
@ -265,7 +265,7 @@ public class ExtensionManager {
extensions.add(extension);
}
} catch (IOException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
}
}
return extensions;
@ -284,7 +284,7 @@ public class ExtensionManager {
return extension;
} catch (IOException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
return null;
}
}
@ -497,7 +497,7 @@ public class ExtensionManager {
LOGGER.info("Found mixin in extension {}: {}", extension.getName(), mixinConfigFile);
}
} catch (Exception e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
LOGGER.error("Failed to load code modifier for extension in files: " +
extension.files
.stream()
@ -531,7 +531,7 @@ public class ExtensionManager {
// close resources
classloader.close();
} catch (IOException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
}
MinestomRootClassLoader.getInstance().removeChildInHierarchy(classloader);
}

View File

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

View File

@ -1,5 +1,6 @@
package net.minestom.server.extras.selfmodification;
import net.minestom.server.MinecraftServer;
import org.jetbrains.annotations.NotNull;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
@ -260,7 +261,7 @@ public class MinestomRootClassLoader extends HierarchyClassLoader {
}
}
} 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.GsonBuilder;
import com.google.gson.JsonDeserializer;
import net.minestom.server.MinecraftServer;
import net.minestom.server.gamedata.Condition;
import net.minestom.server.registry.ResourceGatherer;
import net.minestom.server.utils.NamespaceID;
@ -84,7 +85,7 @@ public final class LootTableManager {
try (reader) {
return cache.computeIfAbsent(name, _name -> create(reader));
} catch (IOException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
return null;
}
}

View File

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

View File

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

View File

@ -59,7 +59,7 @@ public interface IChunkLoader {
parallelSavingThreadPool.awaitTermination(1L, java.util.concurrent.TimeUnit.DAYS);
OptionalCallback.execute(callback);
} catch (InterruptedException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
}
} else {
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.Short2ShortOpenHashMap;
import net.minestom.server.MinecraftServer;
import net.minestom.server.instance.Chunk;
import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.chunk.ChunkUtils;
@ -171,7 +172,7 @@ public class PaletteStorage implements PublicCloneable<PaletteStorage> {
paletteStorage.blockPaletteMaps = blockPaletteMaps.clone();
return paletteStorage;
} catch (CloneNotSupportedException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
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.Object2ShortOpenHashMap;
import net.minestom.server.MinecraftServer;
import net.minestom.server.chat.JsonMessage;
import net.minestom.server.data.Data;
import net.minestom.server.data.DataContainer;
@ -596,7 +597,7 @@ public class ItemStack implements DataContainer, PublicCloneable<ItemStack> {
return itemStack;
} catch (CloneNotSupportedException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
return null;
}
}
@ -787,4 +788,4 @@ public class ItemStack implements DataContainer, PublicCloneable<ItemStack> {
public void onInventoryClick(@NotNull Player player, @NotNull ClickType clickType, int slot, boolean playerInventory) {
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
package net.minestom.server.storage.systems;
import net.minestom.server.MinecraftServer;
import net.minestom.server.storage.StorageOptions;
import net.minestom.server.storage.StorageSystem;
import org.jetbrains.annotations.NotNull;
@ -41,7 +42,7 @@ public class FileStorageSystem implements StorageSystem {
try {
this.rocksDB = RocksDB.open(options, location);
} catch (RocksDBException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
}
}
@ -50,7 +51,7 @@ public class FileStorageSystem implements StorageSystem {
try {
return rocksDB.get(getKey(key));
} catch (RocksDBException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
return null;
}
}
@ -60,7 +61,7 @@ public class FileStorageSystem implements StorageSystem {
try {
this.rocksDB.put(getKey(key), data);
} catch (RocksDBException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
}
}
@ -69,7 +70,7 @@ public class FileStorageSystem implements StorageSystem {
try {
this.rocksDB.delete(getKey(key));
} catch (RocksDBException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
}
}
@ -78,7 +79,7 @@ public class FileStorageSystem implements StorageSystem {
try {
this.rocksDB.closeE();
} 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.LongArraySet;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minestom.server.MinecraftServer;
import net.minestom.server.instance.Instance;
import net.minestom.server.utils.chunk.ChunkUtils;
import org.jetbrains.annotations.NotNull;
@ -150,7 +151,7 @@ public class PerGroupChunkProvider extends ThreadProvider {
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
}
// Tick all this chunk group

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
package net.minestom.server.utils.async;
import net.minestom.server.MinecraftServer;
import org.jetbrains.annotations.NotNull;
import java.util.concurrent.CompletableFuture;
@ -11,7 +12,7 @@ public final class AsyncUtils {
try {
runnable.run();
} 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.Unpooled;
import net.minestom.server.MinecraftServer;
import net.minestom.server.item.ItemStack;
import net.minestom.server.utils.BlockPosition;
import net.minestom.server.utils.NBTUtils;
@ -248,7 +249,7 @@ public class BinaryWriter extends OutputStream {
nbtWriter.writeNamed(name, tag);
} catch (IOException e) {
// 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.JsonParser;
import net.minestom.server.MinecraftServer;
import net.minestom.server.utils.url.URLUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -20,7 +21,7 @@ public final class MojangUtils {
final String response = URLUtils.getText(url);
return JsonParser.parseString(response).getAsJsonObject();
} catch (IOException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
return null;
}
}
@ -33,7 +34,7 @@ public final class MojangUtils {
final String response = URLUtils.getText(url);
return JsonParser.parseString(response).getAsJsonObject();
} catch (IOException e) {
e.printStackTrace();
MinecraftServer.getExceptionManager().handleException(e);
return null;
}
}