Skip to content

Commit 008ef22

Browse files
committed
Remove mod downloading. Unreliable
1 parent bfe70b8 commit 008ef22

File tree

2 files changed

+9
-51
lines changed

2 files changed

+9
-51
lines changed

src/main/java/com/falsepattern/lib/FalsePatternLib.java

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package com.falsepattern.lib;
22

33
import com.falsepattern.lib.api.Version;
4-
import com.google.common.eventbus.EventBus;
5-
import com.google.common.eventbus.Subscribe;
64
import cpw.mods.fml.common.DummyModContainer;
7-
import cpw.mods.fml.common.FMLCommonHandler;
8-
import cpw.mods.fml.common.LoadController;
95
import cpw.mods.fml.common.ModMetadata;
10-
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
116
import lombok.NonNull;
127
import lombok.val;
138
import lombok.var;
@@ -18,13 +13,11 @@
1813
import scala.actors.threadpool.Arrays;
1914

2015
import javax.net.ssl.HttpsURLConnection;
21-
import javax.swing.*;
2216
import java.io.*;
2317
import java.net.URL;
2418
import java.util.*;
2519

2620

27-
@SuppressWarnings("UnstableApiUsage")
2821
public class FalsePatternLib extends DummyModContainer {
2922
public static Logger libLog = LogManager.getLogger(ModInfo.MODNAME);
3023
public static final boolean developerEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
@@ -33,12 +26,9 @@ public class FalsePatternLib extends DummyModContainer {
3326
private static final Map<String, String> loadedLibraryMods = new HashMap<>();
3427
private static final Set<String> mavenRepositories = new HashSet<>();
3528

36-
private static boolean modWasDownloaded = false;
37-
3829
@SuppressWarnings("unchecked")
3930
public FalsePatternLib() {
4031
super(new ModMetadata());
41-
libLog.info("FalsePatternLib has been awakened!");
4232
libLog.info("All your libraries are belong to us!");
4333
val meta = getMetadata();
4434
meta.modId = ModInfo.MODID;
@@ -51,29 +41,12 @@ public FalsePatternLib() {
5141
meta.useDependencyInformation = true;
5242
}
5343

54-
@Override
55-
public boolean registerBus(EventBus bus, LoadController controller) {
56-
bus.register(this);
57-
58-
return true;
59-
}
60-
61-
@Subscribe
62-
public void preInit(FMLPreInitializationEvent evt) {
63-
if (modWasDownloaded) {
64-
JOptionPane.showMessageDialog(null,
65-
"A mod has downloaded another mod as a dependency, and the game requires a restart so that the " +
66-
"downloaded mod is initialized properly! After you close this popup, FalsePatternLib will close the game.", "Reload Required", JOptionPane.WARNING_MESSAGE, null);
67-
FMLCommonHandler.instance().exitJava(0, false);
68-
}
69-
}
70-
7144
public static void addMavenRepo(String url) {
7245
mavenRepositories.add(url);
7346
}
7447

7548
@SuppressWarnings("ResultOfMethodCallIgnored")
76-
public static void loadLibrary(String loadingModId, String groupId, String artifactId, @NonNull Version minVersion, Version maxVersion, @NonNull Version preferredVersion, String devSuffix, boolean isMod) {
49+
public static void loadLibrary(String loadingModId, String groupId, String artifactId, @NonNull Version minVersion, Version maxVersion, @NonNull Version preferredVersion, String devSuffix) {
7750
libLog.info("Adding library {}:{}:{}, requested by mod {}", groupId, artifactId, preferredVersion, loadingModId);
7851
var artifact = groupId + ":" + artifactId;
7952
if (loadedLibraries.containsKey(artifact)) {
@@ -105,22 +78,15 @@ public static void loadLibrary(String loadingModId, String groupId, String artif
10578
}
10679
val modsDir = new File(CoreLoadingPlugin.mcDir, "mods");
10780
val mavenJarName = String.format("%s-%s%s.jar", artifactId, preferredVersion, (developerEnvironment && devSuffix != null) ? ("-" + devSuffix) : "");
108-
val jarName = String.format("%s%s", isMod ? "" : (groupId + "-"), mavenJarName);
109-
File file;
110-
if (isMod) {
111-
file = new File(modsDir, jarName);
112-
} else {
113-
val libDir = new File(modsDir, "falsepattern");
114-
if (!libDir.exists()) {
115-
libDir.mkdirs();
116-
}
117-
file = new File(libDir, jarName);
81+
val jarName = groupId + "-" + mavenJarName;
82+
val libDir = new File(modsDir, "falsepattern");
83+
if (!libDir.exists()) {
84+
libDir.mkdirs();
11885
}
86+
val file = new File(libDir, jarName);
11987
if (file.exists()) {
12088
try {
121-
if (!isMod) {
122-
addToClasspath(file);
123-
}
89+
addToClasspath(file);
12490
loadedLibraries.put(artifact, preferredVersion);
12591
libLog.info("Library {}:{}:{} successfully loaded from disk!", groupId, artifactId, preferredVersion);
12692
return;
@@ -148,13 +114,6 @@ public static void loadLibrary(String loadingModId, String groupId, String artif
148114
libLog.info("Downloaded {}:{}:{}", groupId, artifactId, preferredVersion);
149115
loadedLibraries.put(artifact, preferredVersion);
150116
loadedLibraryMods.put(artifact, loadingModId);
151-
if (isMod) {
152-
if (!modWasDownloaded) {
153-
modWasDownloaded = true;
154-
libLog.warn("A Minecraft mod was downloaded as a library! This will require a game restart! The game restart will trigger on preInit!");
155-
}
156-
return;
157-
}
158117
addToClasspath(file);
159118
return;
160119
} catch (IOException ignored) {}
@@ -176,7 +135,6 @@ private static void addToClasspath(File file) {
176135

177136
private static void download(InputStream is, File target) throws IOException {
178137
if (target.exists()) return;
179-
val name = target.getName();
180138

181139
var bytesRead = 0;
182140

src/main/java/com/falsepattern/lib/api/DependencyLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
public class DependencyLoader {
88
@Builder
9-
public static void loadLibrary(String loadingModId, String groupId, String artifactId, @NonNull Version minVersion, Version maxVersion, @NonNull Version preferredVersion, String devSuffix, boolean isMod) {
10-
FalsePatternLib.loadLibrary(loadingModId, groupId, artifactId, minVersion, maxVersion, preferredVersion, devSuffix, isMod);
9+
public static void loadLibrary(String loadingModId, String groupId, String artifactId, @NonNull Version minVersion, Version maxVersion, @NonNull Version preferredVersion, String devSuffix) {
10+
FalsePatternLib.loadLibrary(loadingModId, groupId, artifactId, minVersion, maxVersion, preferredVersion, devSuffix);
1111
}
1212

1313
public static void addMavenRepo(String url) {

0 commit comments

Comments
 (0)