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.length() > 0 && path.charAt(0) == '/') {
			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;
	}
}

@@ -95,22 +95,24 @@
 va.util.
-HashSe
+ArrayLis
 t;%0D%0Aimpo
@@ -124,18 +124,19 @@
 va.util.
-Se
+Lis
 t;%0D%0A%0D%0Aim
@@ -996,19 +996,123 @@
 %0A%09public
-%0D%0A%09
+ static File getCoreModsDirectory() %7B%0D%0A%09%09return new File(getServerDirectory(), %22coremods%22);%0D%0A%09%7D%0D%0A%0D%0A%09public 
 static F
@@ -1208,18 +1208,19 @@
  static 
-Se
+Lis
 t%3CFile%3E 
@@ -1242,18 +1242,19 @@
 () %7B%0D%0A%09%09
-Se
+Lis
 t%3CFile%3E 
@@ -1276,14 +1276,16 @@
 new 
-HashSe
+ArrayLis
 t%3CFi
@@ -1681,16 +1681,61 @@
 tJar);%0D%0A
+%09%09jarLocations.add(getCoreModsDirectory());%0D%0A
 %09%09jarLoc

Correct patching order, patch coremods