3
0
Fork 1
KCauldronX/src/main/java/kcauldron/KCauldron.java

146 lines
4.4 KiB
Java
Raw Normal View History

2015-05-31 11:21:26 +00:00
package kcauldron;
import java.io.File;
2015-06-27 12:47:27 +00:00
import java.io.InputStream;
2015-05-31 11:21:26 +00:00
import java.net.URL;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.Properties;
2015-06-14 12:50:18 +00:00
import org.spigotmc.RestartCommand;
2015-06-27 12:47:27 +00:00
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
2015-06-27 12:47:27 +00:00
2015-05-31 11:21:26 +00:00
public class KCauldron {
public static final ThreadGroup sKCauldronThreadGroup = new ThreadGroup("KCauldron");
public static final String name="KCauldronX";
2015-06-27 09:32:21 +00:00
private static boolean sManifestParsed = false;
private static void parseManifest() {
2015-06-27 12:47:27 +00:00
if (sManifestParsed)
return;
sManifestParsed = true;
try {
Enumeration<URL> resources = KCauldron.class.getClassLoader()
.getResources("META-INF/MANIFEST.MF");
Properties manifest = new Properties();
while (resources.hasMoreElements()) {
URL url = resources.nextElement();
manifest.load(url.openStream());
String version = manifest.getProperty("KCauldronX-Version");
2015-06-27 12:47:27 +00:00
if (version != null) {
String path = url.getPath();
String jarFilePath = path.substring(path.indexOf(":") + 1,
path.indexOf("!"));
jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
sServerLocation = new File(jarFilePath);
sCurrentVersion = version;
sGroup = manifest.getProperty("KCauldronX-Group");
sBranch = manifest.getProperty("KCauldronX-Branch");
sChannel = manifest.getProperty("KCauldronX-Channel");
sLegacy = Boolean.parseBoolean(manifest.getProperty("KCauldronX-Legacy"));
sOfficial = Boolean.parseBoolean(manifest.getProperty("KCauldronX-Official"));
2015-06-27 12:47:27 +00:00
break;
}
manifest.clear();
}
} catch (Exception e) {
e.printStackTrace();
}
2015-06-27 09:32:21 +00:00
}
private static String sCurrentVersion;
public static String getCurrentVersion() {
2015-06-27 12:47:27 +00:00
parseManifest();
return sCurrentVersion;
2015-06-27 09:32:21 +00:00
}
private static File sServerLocation;
public static File getServerLocation() {
2015-06-27 12:47:27 +00:00
parseManifest();
return sServerLocation;
2015-06-27 09:32:21 +00:00
}
2015-06-27 12:47:27 +00:00
2015-06-27 09:32:21 +00:00
private static File sServerHome;
2015-06-27 12:47:27 +00:00
2015-06-27 09:32:21 +00:00
public static File getServerHome() {
2015-06-27 12:47:27 +00:00
if (sServerHome == null) {
String home = System.getenv("KCAULDRON_HOME");
if (home != null) {
sServerHome = new File(home);
} else {
parseManifest();
sServerHome = sServerLocation.getParentFile();
}
}
return sServerHome;
2015-06-27 09:32:21 +00:00
}
private static String sGroup;
public static String getGroup() {
2015-06-27 12:47:27 +00:00
parseManifest();
return sGroup;
2015-06-27 09:32:21 +00:00
}
private static String sBranch;
public static String getBranch() {
2015-06-27 12:47:27 +00:00
parseManifest();
return sBranch;
2015-06-27 09:32:21 +00:00
}
private static String sChannel;
public static String getChannel() {
2015-06-27 12:47:27 +00:00
parseManifest();
return sChannel;
2015-06-27 09:32:21 +00:00
}
private static boolean sLegacy, sOfficial;
public static boolean isLegacy() {
parseManifest();
return sLegacy;
}
public static boolean isOfficial() {
parseManifest();
return sOfficial;
}
2015-06-27 09:32:21 +00:00
public static File sNewServerLocation;
public static String sNewServerVersion;
public static boolean sUpdateInProgress;
public static void restart() {
2015-06-27 12:47:27 +00:00
RestartCommand.restart(true);
}
private static int sForgeRevision = 0;
public static int lookupForgeRevision() {
if (sForgeRevision != 0) return sForgeRevision;
int revision = Integer.parseInt(System.getProperty("kcauldron.forgeRevision", "0"));
if (revision != 0) return sForgeRevision = revision;
2015-06-27 12:47:27 +00:00
try {
Properties p = new Properties();
p.load(KCauldron.class
.getResourceAsStream("/fmlversion.properties"));
2015-06-29 12:29:00 +00:00
revision = Integer.parseInt(String.valueOf(p.getProperty(
2015-06-27 12:47:27 +00:00
"fmlbuild.build.number", "0")));
} catch (Exception e) {
}
if (revision == 0) {
KLog.get().warning("KCauldron: could not parse forge revision, critical error");
FMLCommonHandler.instance().exitJava(1, false);
}
return sForgeRevision = revision;
2015-06-27 09:32:21 +00:00
}
2015-05-31 11:21:26 +00:00
}