-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
LocationUtil.java
58 lines (50 loc) · 1.59 KB
/
LocationUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package me.nallar.tickthreading.util;
import java.io.File;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import me.nallar.tickthreading.Log;
import me.nallar.tickthreading.patcher.PatchMain;
public enum LocationUtil {
;
public static File directoryOf(Class clazz) {
File location = locationOf(clazz);
if (location.isDirectory()) {
return location;
}
return location.getParentFile();
}
public static File locationOf(Class clazz) {
String path = clazz.getProtectionDomain().getCodeSource().getLocation().getPath();
path = path.contains("!") ? path.substring(0, path.lastIndexOf('!')) : path;
if (path.startsWith("/")) {
path = "file:" + path;
}
try {
return new File(new URL(path).toURI());
} catch (Exception e) {
Log.severe("", e);
return new File(path);
}
}
public static File getServerDirectory() {
return directoryOf(PatchMain.class).getParentFile();
}
public
static File getModsDirectory() {
return new File(getServerDirectory(), "mods");
}
public static Set<File> getJarLocations() {
Set<File> jarLocations = new HashSet<File>();
File forgeJar = locationOf(net.minecraft.server.MinecraftServer.class);
// Tuple = class not likely to be modified by forge
// Minecraft and forge aren't necessarily in the same place
File minecraftJar = locationOf(net.minecraft.util.Tuple.class);
if (!minecraftJar.equals(forgeJar)) {
jarLocations.add(forgeJar.getParentFile());
}
jarLocations.add(minecraftJar);
jarLocations.add(getModsDirectory());
return jarLocations;
}
}