Clear scary stacktraces

This commit is contained in:
mastermc05 2022-08-11 11:36:27 +03:00
parent 36ea4c3938
commit 36924b4942
4 changed files with 46 additions and 17 deletions

View File

@ -93,11 +93,12 @@ public class AsyncChunkProvider118_2 {
}
//prepare data synchronously
CompletableFuture<?> future = CompletableFuture.supplyAsync(() -> {
//Null will mean that we save with spigot methods, which may be risky on async
//Since we're not in main thread, it now refuses new tasks because of shutdown, the risk is lower
if (!Bukkit.isPrimaryThread()) return null;
try {
return getAsyncSaveData.invoke(null, world.getHandle(), c);
} catch (IllegalAccessException | InvocationTargetException e) {
//Save as from main thread
if (((CraftServer) Bukkit.getServer()).getServer().hasStopped()) return null;
throw new RuntimeException(e);
}
}, ((CraftServer) Bukkit.getServer()).getServer());
@ -105,15 +106,21 @@ public class AsyncChunkProvider118_2 {
if (++currChunks > MapManager.mapman.getMaxChunkLoadsPerTick()) {
try {
Thread.sleep(25); //hold the lock so other threads also won't stress main thread
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} catch (InterruptedException ignored) {}
}
//save data asynchronously
return () -> {
Object o = null;
try {
return (NBTTagCompound) save.invoke(null, world.getHandle(), c, future.get());
} catch (ReflectiveOperationException | ExecutionException | InterruptedException e) {
o = future.get();
return (NBTTagCompound) save.invoke(null, world.getHandle(), c, o);
} catch (InterruptedException e) {
return null;
} catch (InvocationTargetException e) {
//We tried to use simple spigot methods at shutdown and failed, hopes for reading from disk
if (o == null) return null;
throw new RuntimeException(e);
} catch (ReflectiveOperationException | ExecutionException e) {
throw new RuntimeException(e);
}
};

View File

@ -22,7 +22,7 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;
/**
@ -61,7 +61,14 @@ public class MapChunkCache118_2 extends GenericMapChunkCache {
try {
CompletableFuture<NBTTagCompound> nbt = provider.getChunk(((CraftWorld) w).getHandle(), chunk.x, chunk.z);
return () -> {
NBTTagCompound compound = nbt.join();
NBTTagCompound compound;
try {
compound = nbt.get();
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
};
} catch (InvocationTargetException | IllegalAccessException ignored) {

View File

@ -92,11 +92,12 @@ public class AsyncChunkProvider119 {
}
//prepare data synchronously
CompletableFuture<?> future = CompletableFuture.supplyAsync(() -> {
//Null will mean that we save with spigot methods, which may be risky on async
//Since we're not in main thread, it now refuses new tasks because of shutdown, the risk is lower
if (!Bukkit.isPrimaryThread()) return null;
try {
return getAsyncSaveData.invoke(null, world.getHandle(), c);
} catch (ReflectiveOperationException e) {
//Save as from main thread
if (((CraftServer) Bukkit.getServer()).getServer().hasStopped()) return null;
throw new RuntimeException(e);
}
}, ((CraftServer) Bukkit.getServer()).getServer());
@ -104,15 +105,21 @@ public class AsyncChunkProvider119 {
if (++currChunks > MapManager.mapman.getMaxChunkLoadsPerTick()) {
try {
Thread.sleep(25); //hold the lock so other threads also won't stress main thread
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
} catch (InterruptedException ignored) {}
}
//save data asynchronously
return () -> {
Object o = null;
try {
return (NBTTagCompound) save.invoke(null, world.getHandle(), c, future.get());
} catch (ReflectiveOperationException | ExecutionException | InterruptedException e) {
o = future.get();
return (NBTTagCompound) save.invoke(null, world.getHandle(), c, o);
} catch (InterruptedException e) {
return null;
} catch (InvocationTargetException e) {
//We tried to use simple spigot methods at shutdown and failed, hopes for reading from disk
if (o == null) return null;
throw new RuntimeException(e);
} catch (ReflectiveOperationException | ExecutionException e) {
throw new RuntimeException(e);
}
};

View File

@ -19,6 +19,7 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Supplier;
/**
@ -58,7 +59,14 @@ public class MapChunkCache119 extends GenericMapChunkCache {
try {
CompletableFuture<NBTTagCompound> nbt = provider.getChunk(((CraftWorld) w).getHandle(), chunk.x, chunk.z);
return () -> {
NBTTagCompound compound = nbt.join();
NBTTagCompound compound;
try {
compound = nbt.get();
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
return compound == null ? null : parseChunkFromNBT(new NBT.NBTCompound(compound));
};
} catch (InvocationTargetException | IllegalAccessException ignored) {