improve error handling

This commit is contained in:
Julian Krings 2024-10-07 20:46:00 +02:00
parent eda44a8ace
commit f3b1109804
8 changed files with 57 additions and 8 deletions

View File

@ -52,15 +52,18 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
public class MemoryWorld implements IMemoryWorld {
private static final AtomicLong C = new AtomicLong();
@ -112,7 +115,10 @@ public class MemoryWorld implements IMemoryWorld {
worldInfo = c.newInstance(worldData, access, creator.environment(), levelStem.typeHolder().value(), levelStem.generator(), server.registryAccess());
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
IllegalAccessException ex) {
throw new RuntimeException(ex);
var constructors = Arrays.stream(CraftWorldInfo.class.getDeclaredConstructors())
.map(Constructor::toGenericString)
.collect(Collectors.joining("\n"));
throw new IOException("Failed to find CraftWorldInfo constructor found: " + constructors, ex);
}
}
if (biomeProvider == null && generator != null) {

View File

@ -55,13 +55,16 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
public class MemoryWorld implements IMemoryWorld {
private static final AtomicLong C = new AtomicLong();
@ -118,7 +121,10 @@ public class MemoryWorld implements IMemoryWorld {
worldInfo = c.newInstance(worldData, access, creator.environment(), levelStem.type().value(), levelStem.generator(), server.registryAccess());
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
IllegalAccessException ex) {
throw new RuntimeException(ex);
var constructors = Arrays.stream(CraftWorldInfo.class.getDeclaredConstructors())
.map(Constructor::toGenericString)
.collect(Collectors.joining("\n"));
throw new IOException("Failed to find CraftWorldInfo constructor found: " + constructors, ex);
}
}
if (biomeProvider == null && generator != null) {

View File

@ -56,14 +56,17 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
public class MemoryWorld implements IMemoryWorld {
private static final AtomicLong C = new AtomicLong();
@ -120,7 +123,10 @@ public class MemoryWorld implements IMemoryWorld {
worldInfo = c.newInstance(worldData, access, creator.environment(), levelStem.type().value(), levelStem.generator(), server.registryAccess());
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
IllegalAccessException ex) {
throw new RuntimeException(ex);
var constructors = Arrays.stream(CraftWorldInfo.class.getDeclaredConstructors())
.map(Constructor::toGenericString)
.collect(Collectors.joining("\n"));
throw new IOException("Failed to find CraftWorldInfo constructor found: " + constructors, ex);
}
}
if (biomeProvider == null && generator != null) {

View File

@ -42,6 +42,7 @@ import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_20_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
import org.bukkit.craftbukkit.v1_20_R1.attribute.CraftAttributeInstance;
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_20_R1.generator.CraftWorldInfo;
@ -56,14 +57,17 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
public class MemoryWorld implements IMemoryWorld {
private static final AtomicLong C = new AtomicLong();
@ -120,7 +124,11 @@ public class MemoryWorld implements IMemoryWorld {
worldInfo = c.newInstance(worldData, access, creator.environment(), levelStem.type().value(), levelStem.generator(), server.registryAccess());
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
IllegalAccessException ex) {
throw new RuntimeException(ex);
var constructors = Arrays.stream(CraftWorldInfo.class.getDeclaredConstructors())
.map(Constructor::toGenericString)
.collect(Collectors.joining("\n"));
CraftAttributeInstance
throw new IOException("Failed to find CraftWorldInfo constructor found: " + constructors, ex);
}
}
if (biomeProvider == null && generator != null) {

View File

@ -56,14 +56,17 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
public class MemoryWorld implements IMemoryWorld {
private static final AtomicLong C = new AtomicLong();
@ -120,7 +123,10 @@ public class MemoryWorld implements IMemoryWorld {
worldInfo = c.newInstance(worldData, access, creator.environment(), levelStem.type().value(), levelStem.generator(), server.registryAccess());
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
IllegalAccessException ex) {
throw new RuntimeException(ex);
var constructors = Arrays.stream(CraftWorldInfo.class.getDeclaredConstructors())
.map(Constructor::toGenericString)
.collect(Collectors.joining("\n"));
throw new IOException("Failed to find CraftWorldInfo constructor found: " + constructors, ex);
}
}
if (biomeProvider == null && generator != null) {

View File

@ -60,14 +60,17 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
public class MemoryWorld implements IMemoryWorld {
private static final AtomicLong C = new AtomicLong();
@ -124,7 +127,10 @@ public class MemoryWorld implements IMemoryWorld {
worldInfo = c.newInstance(worldData, access, creator.environment(), levelStem.type().value(), levelStem.generator(), server.registryAccess());
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
IllegalAccessException ex) {
throw new RuntimeException(ex);
var constructors = Arrays.stream(CraftWorldInfo.class.getDeclaredConstructors())
.map(Constructor::toGenericString)
.collect(Collectors.joining("\n"));
throw new IOException("Failed to find CraftWorldInfo constructor found: " + constructors, ex);
}
}
if (biomeProvider == null && generator != null) {

View File

@ -57,14 +57,17 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
public class MemoryWorld implements IMemoryWorld {
private static final AtomicLong C = new AtomicLong();
@ -122,7 +125,10 @@ public class MemoryWorld implements IMemoryWorld {
worldInfo = c.newInstance(worldData, access, creator.environment(), levelStem.type().value(), levelStem.generator(), server.registryAccess());
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
IllegalAccessException ex) {
throw new RuntimeException(ex);
var constructors = Arrays.stream(CraftWorldInfo.class.getDeclaredConstructors())
.map(Constructor::toGenericString)
.collect(Collectors.joining("\n"));
throw new IOException("Failed to find CraftWorldInfo constructor found: " + constructors, ex);
}
}
if (biomeProvider == null && generator != null) {

View File

@ -57,8 +57,10 @@ import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Locale;
@ -124,7 +126,10 @@ public class MemoryWorld implements IMemoryWorld {
worldInfo = c.newInstance(worldData, access, creator.environment(), levelStem.type().value(), levelStem.generator(), server.registryAccess());
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException |
IllegalAccessException ex) {
throw new RuntimeException(ex);
var constructors = Arrays.stream(CraftWorldInfo.class.getDeclaredConstructors())
.map(Constructor::toGenericString)
.collect(Collectors.joining("\n"));
throw new IOException("Failed to find CraftWorldInfo constructor found: " + constructors, ex);
}
}
if (biomeProvider == null && generator != null) {