mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-16 21:30:08 +00:00
forge jarfile nightmare "solution"
This commit is contained in:
@@ -7,6 +7,7 @@ import com.dfsek.terra.api.platform.handle.WorldHandle;
|
||||
import com.dfsek.terra.api.platform.world.World;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.LockedRegistry;
|
||||
import com.dfsek.terra.api.util.JarUtil;
|
||||
import com.dfsek.terra.api.util.logging.DebugLogger;
|
||||
import com.dfsek.terra.api.util.logging.Logger;
|
||||
import com.dfsek.terra.config.PluginConfig;
|
||||
@@ -16,6 +17,9 @@ import com.dfsek.terra.profiler.Profiler;
|
||||
import com.dfsek.terra.world.TerraWorld;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* Represents a Terra mod/plugin instance.
|
||||
@@ -67,4 +71,8 @@ public interface TerraPlugin extends LoaderRegistrar {
|
||||
}
|
||||
|
||||
Profiler getProfiler();
|
||||
|
||||
default JarFile getModJar() throws URISyntaxException, IOException {
|
||||
return JarUtil.getJarFile();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.dfsek.terra.api.util;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
@@ -32,4 +36,12 @@ public class JarUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static JarFile getJarFile() throws URISyntaxException, IOException {
|
||||
return new JarFile(new File(getJarURL().toURI()));
|
||||
}
|
||||
|
||||
public static URL getJarURL() {
|
||||
return TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ public class PluginConfig implements ConfigTemplate {
|
||||
ConfigLoader loader = new ConfigLoader();
|
||||
loader.load(this, file);
|
||||
if(dumpDefaultConfig) { // Don't dump default config if already loaded.
|
||||
try(JarFile jar = new JarFile(new File(TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
|
||||
try(JarFile jar = main.getModJar()) {
|
||||
JarUtil.copyResourcesToDirectory(jar, "packs", new File(main.getDataFolder(), "packs").toString());
|
||||
} catch(IOException | URISyntaxException e) {
|
||||
main.getDebugLogger().error("Failed to dump default config files!");
|
||||
e.printStackTrace();
|
||||
main.getDebugLogger().error("Report this to Terra!");
|
||||
main.getDebugLogger().error("Either you're on Forge, or this is a bug. If it's the latter, report this to Terra!");
|
||||
}
|
||||
}
|
||||
} catch(ConfigException | IOException e) {
|
||||
|
||||
@@ -17,7 +17,7 @@ public final class LangUtil {
|
||||
public static void load(String langID, TerraPlugin main) {
|
||||
Logger logger = main.logger();
|
||||
File file = new File(main.getDataFolder(), "lang");
|
||||
try(JarFile jar = new JarFile(new File(TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {
|
||||
try(JarFile jar = main.getModJar()) {
|
||||
copyResourcesToDirectory(jar, "lang", file.toString());
|
||||
} catch(IOException | URISyntaxException e) {
|
||||
main.getDebugLogger().error("Failed to dump language files!");
|
||||
|
||||
Reference in New Issue
Block a user