diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-09-03 12:50:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-03 13:50:40 +0200 |
commit | 4c60b452efda24794c0faa5f300fdd830edcd383 (patch) | |
tree | 06c4d425bdc405af0189f4707ba1302b864f7328 /versions/src | |
parent | b7169237c543bf549a4b03dcc9a23b516da635eb (diff) | |
download | OneConfig-4c60b452efda24794c0faa5f300fdd830edcd383.tar.gz OneConfig-4c60b452efda24794c0faa5f300fdd830edcd383.tar.bz2 OneConfig-4c60b452efda24794c0faa5f300fdd830edcd383.zip |
deprecator + Stack trace utilities (#121)
* deprecator
* check for more system packages because iterators n stuff
* add LogScanner, new loader platform features, spam protection
* oop~
* move to Preferences
* diamond review
* add back the exception
* try-catch things and associate OneConfig mods with an ActiveMod
* ok maybe not + api my beloved
Diffstat (limited to 'versions/src')
-rw-r--r-- | versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java | 73 | ||||
-rw-r--r-- | versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java | 16 |
2 files changed, 72 insertions, 17 deletions
diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java index 68065fd..4c10997 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java @@ -28,26 +28,33 @@ package cc.polyfrost.oneconfig.platform.impl; import cc.polyfrost.oneconfig.platform.LoaderPlatform; //#if MC>=11600 - //#if FORGE==1 - //$$ import net.minecraftforge.fml.ModList; - //#else - //$$ import net.fabricmc.loader.api.FabricLoader; - //#endif +//#if FORGE==1 +//$$ import net.minecraftforge.fml.ModList; +//#else +//$$ import net.fabricmc.loader.api.FabricLoader; +//$$ import net.fabricmc.loader.api.ModContainer; +//#endif //#endif //#if FORGE==1 import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.ModContainer; //#endif +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; public class LoaderPlatformImpl implements LoaderPlatform { @Override public boolean isModLoaded(String id) { //#if MC>=11600 - //#if FORGE==1 - //$$ return ModList.get().isLoaded(id); - //#else - //$$ return FabricLoader.getInstance().isModLoaded(id); - //#endif + //#if FORGE==1 + //$$ return ModList.get().isLoaded(id); + //#else + //$$ return FabricLoader.getInstance().isModLoaded(id); + //#endif //#else return Loader.isModLoaded(id); //#endif @@ -63,17 +70,49 @@ public class LoaderPlatformImpl implements LoaderPlatform { } @Override + public @NotNull List<ActiveMod> getLoadedMods() { + try { + return + //#if FORGE==1 + //#if MC<=11202 + Loader.instance().getActiveModList().stream().map + //#else + //$$ ModList.get().applyForEachModContainer + //#endif + //#else + //$$ FabricLoader.getInstance().getAllMods().stream().map + //#endif + (this::toActiveMod).collect(Collectors.toList()); + } catch (Exception e) { + return Collections.emptyList(); + } + } + + @Override public ActiveMod getActiveModContainer() { //#if FORGE==1 - ModContainer container = Loader.instance().activeModContainer(); - if (container == null) return null; - //#if MC==11202 - return new ActiveMod(container.getName(), container.getModId(), container.getVersion()); - //#else - //$$ return new ActiveMod(container.getModInfo().getDisplayName(), container.getModId(), container.getModInfo().getVersion().getQualifier()); - //#endif + return toActiveMod(Loader.instance().activeModContainer()); //#else //$$ return null; //#endif } + + @Override + public ActiveMod toActiveMod(@Nullable Object in) { + try { + ModContainer container = (ModContainer) in; + if (container == null) return null; + //#if FORGE==1 + //#if MC==11202 + return new ActiveMod(container.getName(), container.getModId(), container.getVersion(), container.getSource()); + //#else + //$$ return new ActiveMod(container.getModInfo().getDisplayName(), container.getModId(), container.getModInfo().getVersion().getQualifier(), ModList.get().getModFileById(container.getModId()).getFile().getFilePath().toFile()); + //#endif + //#else + //$$ return new ActiveMod(container.getMetadata().getName(), container.getMetadata().getId(), container.getMetadata().getVersion().getFriendlyString(), container.getRootPaths().get(0).toFile()); + //#endif + } catch (Exception e) { + return null; + } + } } diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java index 85bf795..e6e96f0 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java @@ -65,6 +65,22 @@ public class PlatformImpl implements Platform { } @Override + public boolean isDevelopmentEnvironment() { + //#if FORGE==1 && MC<=11202 + try { + Class.forName("net.minecraft.block.BlockDirt"); + return true; + } catch (Exception ignored) { + return false; + } + //#elseif FABRIC==1 + //$$ return net.fabricmc.loader.api.FabricLoader.getInstance().isDevelopmentEnvironment(); + //#else + //$$ return !net.minecraftforge.fml.loading.FMLLoader.isProduction(); + //#endif + } + + @Override public Loader getLoader() { //#if FORGE==1 return Loader.FORGE; |