mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Merge branch 'master' into dev/7.0-2
This commit is contained in:
@@ -31,6 +31,8 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
@@ -371,6 +373,28 @@ public abstract class AbstractPlatform implements Platform {
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
private static final String moonrise = "Moonrise";
|
||||
public static int getMoonriseGenerationThreadsWithReflection() {
|
||||
try {
|
||||
Class<?> prioritisedThreadPoolClazz = Class.forName("ca.spottedleaf.concurrentutil.executor.thread.PrioritisedThreadPool");
|
||||
Method getCoreThreadsMethod = prioritisedThreadPoolClazz.getDeclaredMethod("getCoreThreads");
|
||||
getCoreThreadsMethod.setAccessible(true);
|
||||
Class<?> moonriseCommonClazz = Class.forName("ca.spottedleaf.moonrise.common.util.MoonriseCommon");
|
||||
Object pool = moonriseCommonClazz.getDeclaredField("WORKER_POOL").get(null);
|
||||
int threads = ((Thread[]) getCoreThreadsMethod.invoke(pool)).length;
|
||||
logger.info("{} found, setting {} generation threads.", moonrise, threads);
|
||||
return threads;
|
||||
} catch (ClassNotFoundException e) {
|
||||
logger.info("{} not found.", moonrise);
|
||||
} catch (NoSuchMethodException | NoSuchFieldException e) {
|
||||
logger.warn("{} found, but field/method not found this probably means {0} has changed its code and " +
|
||||
"Terra has not updated to reflect that.", moonrise);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
logger.error("Failed to access thread values in {}, assuming 1 generation thread.", moonrise, e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(TypeRegistry registry) {
|
||||
|
||||
@@ -44,13 +44,13 @@ public class ConfigRegistry extends OpenRegistryImpl<ConfigPack> {
|
||||
public void loadAll(Platform platform) throws IOException, PackLoadFailuresException {
|
||||
Path packsDirectory = platform.getDataFolder().toPath().resolve("packs");
|
||||
Files.createDirectories(packsDirectory);
|
||||
List<IOException> failedLoads = new ArrayList<>();
|
||||
List<Exception> failedLoads = new ArrayList<>();
|
||||
try(Stream<Path> packs = Files.list(packsDirectory)) {
|
||||
packs.forEach(path -> {
|
||||
try {
|
||||
ConfigPack pack = new ConfigPackImpl(path, platform);
|
||||
registerChecked(pack.getRegistryKey(), pack);
|
||||
} catch(IOException e) {
|
||||
} catch(IOException | RuntimeException e) {
|
||||
failedLoads.add(e);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user