package me.djtheredstoner.perspectivemod.forge; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import net.minecraft.launchwrapper.Launch; import net.minecraftforge.common.ForgeVersion; import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; import javax.swing.JOptionPane; import java.io.File; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; // this one will be loaded in prod, used to detect Canelex's perspective mod @IFMLLoadingPlugin.MCVersion(ForgeVersion.mcVersion) public class PerspectiveTweaker implements IFMLLoadingPlugin { public PerspectiveTweaker() { File mods = new File(Launch.minecraftHome, "mods"); if (!mods.exists()) { mods.mkdirs(); // mods folder may not exist in dev yet } File[] coreModList = mods.listFiles((dir, name) -> name.endsWith(".jar")); for (File file : coreModList) { try { try (ZipFile zipFile = new ZipFile(file)) { if (zipFile.getEntry("net/canelex/perspectivemod/PerspectiveMod.class") != null) { halt("

Perspective Mod v4 is not compatible with Perspective Mod v3 by Canelex. Please remove Canelex's in order to launch the game.

"); continue; } } } catch (Exception e) { e.printStackTrace(); } } } private void halt(final String message) { JOptionPane.showMessageDialog(null, message, "Launch Aborted", JOptionPane.ERROR_MESSAGE); try { final Class aClass = Class.forName("java.lang.Shutdown"); final Method exit = aClass.getDeclaredMethod("exit", int.class); exit.setAccessible(true); exit.invoke(null, 0); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } } @Override public String[] getASMTransformerClass() { return new String[0]; } @Override public String getModContainerClass() { return null; } @Override public String getSetupClass() { return null; } @Override public void injectData(Map map) { } @Override public String getAccessTransformerClass() { return null; } }