-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
LocationUtil.java
38 lines (32 loc) · 1010 Bytes
/
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
package me.nallar.tickthreading.util;
import java.io.File;
import java.net.URL;
import me.nallar.tickthreading.Log;
import net.minecraft.server.MinecraftServer;
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() {
File jarPath = directoryOf(MinecraftServer.class);
return MinecraftServer.getServer().isDedicatedServer() ? jarPath : jarPath.getParentFile();
}
}