mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 08:25:31 +00:00
delete JarUtil
This commit is contained in:
parent
3261e7451f
commit
deedfb1f8d
@ -10,16 +10,11 @@ import com.dfsek.terra.api.lang.Language;
|
||||
import com.dfsek.terra.api.profiler.Profiler;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.registry.Registry;
|
||||
import com.dfsek.terra.api.tectonic.LoaderHolder;
|
||||
import com.dfsek.terra.api.tectonic.LoaderRegistrar;
|
||||
import com.dfsek.terra.api.util.JarUtil;
|
||||
import com.dfsek.terra.api.world.TerraWorld;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
* Represents a Terra mod/plugin instance.
|
||||
@ -69,8 +64,4 @@ public interface TerraPlugin extends LoaderRegistrar {
|
||||
}
|
||||
|
||||
Profiler getProfiler();
|
||||
|
||||
default JarFile getModJar() throws URISyntaxException, IOException {
|
||||
return JarUtil.getJarFile();
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +0,0 @@
|
||||
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;
|
||||
|
||||
public final class JarUtil {
|
||||
public static void copyResourcesToDirectory(JarFile fromJar, String sourceDir, String destDir) throws IOException {
|
||||
for(Enumeration<JarEntry> entries = fromJar.entries(); entries.hasMoreElements(); ) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
if(entry.getName().startsWith(sourceDir + "/") && !entry.isDirectory()) {
|
||||
File dest = new File(destDir + File.separator + entry.getName().substring(sourceDir.length() + 1));
|
||||
if(dest.exists()) continue;
|
||||
File parent = dest.getParentFile();
|
||||
if(parent != null) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
try(FileOutputStream out = new FileOutputStream(dest); InputStream in = fromJar.getInputStream(entry)) {
|
||||
byte[] buffer = new byte[(8192)];
|
||||
|
||||
int s;
|
||||
while((s = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, s);
|
||||
}
|
||||
} catch(IOException e) {
|
||||
throw new IOException("Could not copy asset from jar file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static JarFile getJarFile() throws URISyntaxException, IOException {
|
||||
return new JarFile(new File(getJarURL().toURI()));
|
||||
}
|
||||
|
||||
public static URL getJarURL() {
|
||||
return TerraPlugin.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
}
|
||||
}
|
@ -8,8 +8,6 @@ import com.dfsek.tectonic.loading.ConfigLoader;
|
||||
import com.dfsek.tectonic.yaml.YamlConfiguration;
|
||||
import com.dfsek.terra.api.Logger;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.util.JarUtil;
|
||||
import com.google.common.base.Charsets;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
@ -20,13 +18,10 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
@SuppressWarnings("FieldMayBeFinal")
|
||||
public class PluginConfigImpl implements ConfigTemplate, com.dfsek.terra.api.config.PluginConfig {
|
||||
|
@ -7,10 +7,6 @@ import com.dfsek.terra.api.lang.Language;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import static com.dfsek.terra.api.util.JarUtil.copyResourcesToDirectory;
|
||||
|
||||
public final class LangUtil {
|
||||
private static Language language;
|
||||
|
Loading…
x
Reference in New Issue
Block a user