mirror of
https://github.com/GTNewHorizons/MagicBees.git
synced 2026-11-19 03:49:13 +00:00
Merge pull request #16 from GTNewHorizons/yeet_version_checker
update buildscript and remove update checker
This commit is contained in:
4 files changed
+79
-352
No files matched your search
+79
-53
@@ -1,8 +1,8 @@
|
||||
//version: 1665425597
|
||||
//version: 1673027205
|
||||
/*
|
||||
DO NOT CHANGE THIS FILE!
|
||||
Also, you may replace this file at any time if there is an update available.
|
||||
Please check https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle for updates.
|
||||
Please check https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/master/build.gradle for updates.
|
||||
*/
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ buildscript {
|
||||
url 'https://maven.minecraftforge.net'
|
||||
}
|
||||
maven {
|
||||
// GTNH ForgeGradle Fork
|
||||
// GTNH ForgeGradle and ASM Fork
|
||||
name = "GTNH Maven"
|
||||
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
|
||||
}
|
||||
@@ -45,7 +45,9 @@ buildscript {
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2.9'
|
||||
//Overwrite the current ASM version to fix shading newer than java 8 applicatations.
|
||||
classpath 'org.ow2.asm:asm-debug-all-custom:5.0.3'
|
||||
classpath 'net.minecraftforge.gradle:ForgeGradle:1.2.13'
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
@@ -147,17 +149,21 @@ String javaSourceDir = "src/main/java/"
|
||||
String scalaSourceDir = "src/main/scala/"
|
||||
String kotlinSourceDir = "src/main/kotlin/"
|
||||
|
||||
String targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/")
|
||||
String targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/")
|
||||
String targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/")
|
||||
|
||||
final String modGroupPath = modGroup.toString().replaceAll("\\.", "/")
|
||||
final String apiPackagePath = apiPackage.toString().replaceAll("\\.", "/")
|
||||
|
||||
String targetPackageJava = javaSourceDir + modGroupPath
|
||||
String targetPackageScala = scalaSourceDir + modGroupPath
|
||||
String targetPackageKotlin = kotlinSourceDir + modGroupPath
|
||||
if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) {
|
||||
throw new GradleException("Could not resolve \"modGroup\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin)
|
||||
}
|
||||
|
||||
if (apiPackage) {
|
||||
targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/")
|
||||
targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/")
|
||||
targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/")
|
||||
targetPackageJava = javaSourceDir + modGroupPath + "/" + apiPackagePath
|
||||
targetPackageScala = scalaSourceDir + modGroupPath + "/" + apiPackagePath
|
||||
targetPackageKotlin = kotlinSourceDir + modGroupPath + "/" + apiPackagePath
|
||||
if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) {
|
||||
throw new GradleException("Could not resolve \"apiPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin)
|
||||
}
|
||||
@@ -171,31 +177,36 @@ if (accessTransformersFile) {
|
||||
}
|
||||
|
||||
if (usesMixins.toBoolean()) {
|
||||
if (mixinsPackage.isEmpty() || mixinPlugin.isEmpty()) {
|
||||
throw new GradleException("\"mixinPlugin\" requires \"mixinsPackage\" and \"mixinPlugin\" to be set!")
|
||||
if (mixinsPackage.isEmpty()) {
|
||||
throw new GradleException("\"usesMixins\" requires \"mixinsPackage\" to be set!")
|
||||
}
|
||||
final String mixinPackagePath = mixinsPackage.toString().replaceAll("\\.", "/")
|
||||
final String mixinPluginPath = mixinPlugin.toString().replaceAll("\\.", "/")
|
||||
|
||||
targetPackageJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
|
||||
targetPackageScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
|
||||
targetPackageKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
|
||||
targetPackageJava = javaSourceDir + modGroupPath + "/" + mixinPackagePath
|
||||
targetPackageScala = scalaSourceDir + modGroupPath + "/" + mixinPackagePath
|
||||
targetPackageKotlin = kotlinSourceDir + modGroupPath + "/" + mixinPackagePath
|
||||
if (!(getFile(targetPackageJava).exists() || getFile(targetPackageScala).exists() || getFile(targetPackageKotlin).exists())) {
|
||||
throw new GradleException("Could not resolve \"mixinsPackage\"! Could not find " + targetPackageJava + " or " + targetPackageScala + " or " + targetPackageKotlin)
|
||||
}
|
||||
|
||||
String targetFileJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".java"
|
||||
String targetFileScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".scala"
|
||||
String targetFileScalaJava = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".java"
|
||||
String targetFileKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".kt"
|
||||
if (!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists() || getFile(targetFileKotlin).exists())) {
|
||||
throw new GradleException("Could not resolve \"mixinPlugin\"! Could not find " + targetFileJava + " or " + targetFileScala + " or " + targetFileScalaJava + " or " + targetFileKotlin)
|
||||
if (!mixinPlugin.isEmpty()) {
|
||||
String targetFileJava = javaSourceDir + modGroupPath + "/" + mixinPluginPath + ".java"
|
||||
String targetFileScala = scalaSourceDir + modGroupPath + "/" + mixinPluginPath + ".scala"
|
||||
String targetFileScalaJava = scalaSourceDir + modGroupPath + "/" + mixinPluginPath + ".java"
|
||||
String targetFileKotlin = kotlinSourceDir + modGroupPath + "/" + mixinPluginPath + ".kt"
|
||||
if (!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists() || getFile(targetFileKotlin).exists())) {
|
||||
throw new GradleException("Could not resolve \"mixinPlugin\"! Could not find " + targetFileJava + " or " + targetFileScala + " or " + targetFileScalaJava + " or " + targetFileKotlin)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (coreModClass) {
|
||||
String targetFileJava = javaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".java"
|
||||
String targetFileScala = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".scala"
|
||||
String targetFileScalaJava = scalaSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".java"
|
||||
String targetFileKotlin = kotlinSourceDir + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".kt"
|
||||
final String coreModPath = coreModClass.toString().replaceAll("\\.", "/")
|
||||
String targetFileJava = javaSourceDir + modGroupPath + "/" + coreModPath + ".java"
|
||||
String targetFileScala = scalaSourceDir + modGroupPath + "/" + coreModPath + ".scala"
|
||||
String targetFileScalaJava = scalaSourceDir + modGroupPath + "/" + coreModPath + ".java"
|
||||
String targetFileKotlin = kotlinSourceDir + modGroupPath + "/" + coreModPath + ".kt"
|
||||
if (!(getFile(targetFileJava).exists() || getFile(targetFileScala).exists() || getFile(targetFileScalaJava).exists() || getFile(targetFileKotlin).exists())) {
|
||||
throw new GradleException("Could not resolve \"coreModClass\"! Could not find " + targetFileJava + " or " + targetFileScala + " or " + targetFileScalaJava + " or " + targetFileKotlin)
|
||||
}
|
||||
@@ -251,7 +262,7 @@ if (project.hasProperty("customArchiveBaseName") && customArchiveBaseName) {
|
||||
def arguments = []
|
||||
def jvmArguments = []
|
||||
|
||||
if (usesMixins.toBoolean() || forceEnableMixins) {
|
||||
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
|
||||
arguments += [
|
||||
"--tweakClass org.spongepowered.asm.launch.MixinTweaker"
|
||||
]
|
||||
@@ -269,7 +280,9 @@ minecraft {
|
||||
runDir = 'run'
|
||||
|
||||
if (replaceGradleTokenInFile) {
|
||||
replaceIn replaceGradleTokenInFile
|
||||
for (f in replaceGradleTokenInFile.split(',')) {
|
||||
replaceIn f
|
||||
}
|
||||
if (gradleTokenModId) {
|
||||
replace gradleTokenModId, modId
|
||||
}
|
||||
@@ -306,9 +319,13 @@ if (file('addon.gradle').exists()) {
|
||||
apply from: 'repositories.gradle'
|
||||
|
||||
configurations {
|
||||
implementation.extendsFrom(shadowImplementation) // TODO: remove after all uses are refactored
|
||||
implementation.extendsFrom(shadowCompile)
|
||||
implementation.extendsFrom(shadeCompile)
|
||||
// TODO: remove Compile after all uses are refactored to Implementation
|
||||
for (config in [shadowImplementation, shadowCompile, shadeCompile]) {
|
||||
compileClasspath.extendsFrom(config)
|
||||
runtimeClasspath.extendsFrom(config)
|
||||
testCompileClasspath.extendsFrom(config)
|
||||
testRuntimeClasspath.extendsFrom(config)
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -316,13 +333,16 @@ repositories {
|
||||
name 'Overmind forge repo mirror'
|
||||
url 'https://gregtech.overminddl1.com/'
|
||||
}
|
||||
if (usesMixins.toBoolean() || forceEnableMixins) {
|
||||
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
|
||||
maven {
|
||||
name 'sponge'
|
||||
url 'https://repo.spongepowered.org/repository/maven-public'
|
||||
name = "GTNH Maven"
|
||||
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
|
||||
}
|
||||
maven {
|
||||
url 'https://jitpack.io'
|
||||
if (usesMixinDebug.toBoolean()) {
|
||||
maven {
|
||||
name = "Fabric Maven"
|
||||
url = "https://maven.fabricmc.net/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -332,19 +352,14 @@ dependencies {
|
||||
annotationProcessor('org.ow2.asm:asm-debug-all:5.0.3')
|
||||
annotationProcessor('com.google.guava:guava:24.1.1-jre')
|
||||
annotationProcessor('com.google.code.gson:gson:2.8.6')
|
||||
annotationProcessor('org.spongepowered:mixin:0.8-SNAPSHOT')
|
||||
}
|
||||
if (usesMixins.toBoolean() || forceEnableMixins) {
|
||||
// using 0.8 to workaround a issue in 0.7 which fails mixin application
|
||||
compile('com.github.GTNewHorizons:SpongePoweredMixin:0.7.12-GTNH') {
|
||||
// Mixin includes a lot of dependencies that are too up-to-date
|
||||
exclude module: 'launchwrapper'
|
||||
exclude module: 'guava'
|
||||
exclude module: 'gson'
|
||||
exclude module: 'commons-io'
|
||||
exclude module: 'log4j-core'
|
||||
annotationProcessor('com.gtnewhorizon:gtnhmixins:2.1.3:processor')
|
||||
if (usesMixinDebug.toBoolean()) {
|
||||
runtimeClasspath('org.jetbrains:intellij-fernflower:1.2.1.16')
|
||||
testRuntimeClasspath('org.jetbrains:intellij-fernflower:1.2.1.16')
|
||||
}
|
||||
compile('com.github.GTNewHorizons:SpongeMixins:1.5.0')
|
||||
}
|
||||
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
|
||||
compile('com.gtnewhorizon:gtnhmixins:2.1.3')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,13 +371,18 @@ def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + "mixins.srg"
|
||||
|
||||
task generateAssets {
|
||||
if (usesMixins.toBoolean()) {
|
||||
def mixinConfigFile = getFile("/src/main/resources/mixins." + modId + ".json");
|
||||
def mixinConfigFile = getFile("/src/main/resources/mixins." + modId + ".json")
|
||||
if (!mixinConfigFile.exists()) {
|
||||
def mixinPluginLine = ""
|
||||
if(!mixinPlugin.isEmpty()) {
|
||||
// We might not have a mixin plugin if we're using early/late mixins
|
||||
mixinPluginLine += """\n "plugin": "${modGroup}.${mixinPlugin}", """
|
||||
}
|
||||
|
||||
mixinConfigFile.text = """{
|
||||
"required": true,
|
||||
"minVersion": "0.7.11",
|
||||
"package": "${modGroup}.${mixinsPackage}",
|
||||
"plugin": "${modGroup}.${mixinPlugin}",
|
||||
"minVersion": "0.8.5-GTNH",
|
||||
"package": "${modGroup}.${mixinsPackage}",${mixinPluginLine}
|
||||
"refmap": "${mixingConfigRefMap}",
|
||||
"target": "@env(DEFAULT)",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
@@ -574,11 +594,11 @@ task devJar(type: Jar) {
|
||||
|
||||
task apiJar(type: Jar) {
|
||||
from(sourceSets.main.allSource) {
|
||||
include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**'
|
||||
include modGroupPath + "/" + apiPackagePath + '/**'
|
||||
}
|
||||
|
||||
from(sourceSets.main.output) {
|
||||
include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/") + '/**'
|
||||
include modGroupPath + "/" + apiPackagePath + '/**'
|
||||
}
|
||||
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
@@ -691,6 +711,9 @@ if (modrinthProjectId.size() != 0 && System.getenv("MODRINTH_TOKEN") != null) {
|
||||
addModrinthDep(qual[0], qual[1], parts[1])
|
||||
}
|
||||
}
|
||||
if (usesMixins.toBoolean()) {
|
||||
addModrinthDep("required", "project", "gtnhmixins")
|
||||
}
|
||||
tasks.modrinth.dependsOn(build)
|
||||
tasks.publish.dependsOn(tasks.modrinth)
|
||||
}
|
||||
@@ -732,6 +755,9 @@ if (curseForgeProjectId.size() != 0 && System.getenv("CURSEFORGE_TOKEN") != null
|
||||
addCurseForgeRelation(parts[0], parts[1])
|
||||
}
|
||||
}
|
||||
if (usesMixins.toBoolean()) {
|
||||
addCurseForgeRelation("requiredDependency", "gtnhmixins")
|
||||
}
|
||||
tasks.curseforge.dependsOn(build)
|
||||
tasks.publish.dependsOn(tasks.curseforge)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ public class MagicBees {
|
||||
CraftingManager.setupCrafting();
|
||||
CraftingManager.registerLiquidContainers();
|
||||
|
||||
VersionInfo.doVersionCheck();
|
||||
LogHelper.info("Postinit completed");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
package magicbees.main.utils;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
|
||||
import magicbees.main.Config;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.event.ClickEvent;
|
||||
import net.minecraft.event.HoverEvent;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.ChatComponentTranslation;
|
||||
import net.minecraft.util.ChatStyle;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
public class TickHandlerVersion {
|
||||
|
||||
private static int TICK_POLL_INTERVAL = 250;
|
||||
|
||||
private static class LazyHolder {
|
||||
private static final TickHandlerVersion instance = new TickHandlerVersion();
|
||||
}
|
||||
|
||||
private int ticksToPoll;
|
||||
private VersionInfo versionInfo;
|
||||
|
||||
private final ChatStyle newVersion =
|
||||
new ChatStyle().setColor(EnumChatFormatting.GOLD).setBold(true);
|
||||
private final ChatStyle description = new ChatStyle().setColor(EnumChatFormatting.GRAY);
|
||||
private final ChatStyle alert = new ChatStyle().setColor(EnumChatFormatting.RED);
|
||||
|
||||
private TickHandlerVersion() {
|
||||
ticksToPoll = TICK_POLL_INTERVAL;
|
||||
}
|
||||
|
||||
private void setVersionInfo(VersionInfo vInfo) {
|
||||
versionInfo = vInfo;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tickStart(PlayerTickEvent evt) {
|
||||
if (evt.phase != Phase.START) {
|
||||
return;
|
||||
}
|
||||
if (ticksToPoll > 0) {
|
||||
ticksToPoll--;
|
||||
return;
|
||||
}
|
||||
ticksToPoll = TICK_POLL_INTERVAL;
|
||||
|
||||
if (versionInfo.versionCheckComplete) {
|
||||
unsubscribeFromBus();
|
||||
|
||||
if (updateNotificationsEnabledOrCriticalUpdate()) {
|
||||
sendNotificationToPlayer(evt.player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendNotificationToPlayer(EntityPlayer player) {
|
||||
if (versionInfo.isCriticalUpdate()) {
|
||||
player.addChatMessage(
|
||||
new ChatComponentTranslation("magicbees.versioning.critical", versionInfo.getLatestVersion())
|
||||
.setChatStyle(alert));
|
||||
} else {
|
||||
player.addChatMessage(
|
||||
new ChatComponentTranslation("magicbees.versioning.newVersion", versionInfo.getLatestVersion())
|
||||
.setChatStyle(newVersion));
|
||||
}
|
||||
ChatStyle thisDescription = description.createShallowCopy();
|
||||
thisDescription.setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, VersionInfo.DownloadURL));
|
||||
thisDescription.setChatHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT, new ChatComponentText(versionInfo.getVersionDescription())));
|
||||
player.addChatMessage(
|
||||
new ChatComponentTranslation("magicbees.versioning.clickDownload").setChatStyle(thisDescription));
|
||||
}
|
||||
|
||||
private boolean updateNotificationsEnabledOrCriticalUpdate() {
|
||||
return (!Config.disableUpdateNotification || versionInfo.isCriticalUpdate())
|
||||
&& versionInfo.isNewVersionAvailable();
|
||||
}
|
||||
|
||||
private void subscribeToBus() {
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
}
|
||||
|
||||
private void unsubscribeFromBus() {
|
||||
FMLCommonHandler.instance().bus().unregister(this);
|
||||
}
|
||||
|
||||
public static void go(VersionInfo vInfo) {
|
||||
LazyHolder.instance.setVersionInfo(vInfo);
|
||||
LazyHolder.instance.subscribeToBus();
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public void tickStart(EnumSet<TickType> type, Object... tickData)
|
||||
{
|
||||
if (sent) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (modIndex < modVersionInfo.size()) {
|
||||
VersionInfo anInfo = modVersionInfo.get(modIndex);
|
||||
|
||||
if ((!Config.DisableUpdateNotification || anInfo.isCriticalUpdate()) && anInfo.isNewVersionAvailable())
|
||||
{
|
||||
EntityPlayer player = (EntityPlayer) tickData[0];
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText("[" + anInfo.modName + "] A new version is available: " + anInfo.getLatestVersion()));
|
||||
player.sendChatToPlayer(ChatMessageComponent.createFromText(anInfo.getVersionDescription()));
|
||||
}
|
||||
modIndex += 1;
|
||||
}
|
||||
else {
|
||||
sent = true;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
@@ -1,13 +1,5 @@
|
||||
package magicbees.main.utils;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Using some of the VersionInfo code from cofh. (Thanks, Lemming!)
|
||||
*
|
||||
@@ -16,179 +8,8 @@ import java.util.logging.Logger;
|
||||
public class VersionInfo {
|
||||
public static final String ModName = "MagicBees";
|
||||
public static final String Version = "GRADLETOKEN_VERSION";
|
||||
public static final String VersionURL =
|
||||
"https://raw.githubusercontent.com/MagicBees/MagicBees/master/etc/version-1.7.txt";
|
||||
public static final String DownloadURL = "http://minecraft.curseforge.com/mc-mods/65764-magic-bees/files";
|
||||
public static final String GUI_FACTORY_CLASS = "magicbees.client.gui.GuiFactory";
|
||||
|
||||
public static final String Logo = "/gfx/magicbees/logo.png";
|
||||
|
||||
public static final String Depends =
|
||||
"required-after:Forestry@[4.2.5,);after:Thaumcraft;after:ExtraBees;after:EE3;after:ArsMagica;after:TConstruct;after:Railcraft;after:ThermalFoundation;after:ThermalExpansion;after:RedstoneArsenal;after:AWWayofTime;after:Botania;after:appliedenergistics2";
|
||||
|
||||
boolean criticalUpdate;
|
||||
boolean newVersion;
|
||||
boolean versionCheckComplete;
|
||||
|
||||
String latestModVersion;
|
||||
String description = "";
|
||||
|
||||
String modName;
|
||||
String modVersion;
|
||||
String releaseURL;
|
||||
|
||||
public static int[] parseVersion(String rawVersion) {
|
||||
ArrayList<Integer> versionTokens = new ArrayList<Integer>();
|
||||
String[] tokens = rawVersion.trim().split("[\\. ]");
|
||||
|
||||
for (int i = 0; i < tokens.length; ++i) {
|
||||
tokens[i] = tokens[i].trim();
|
||||
if (tokens[i].matches("[0-9]+")) {
|
||||
versionTokens.add(Integer.valueOf(tokens[i]));
|
||||
} else if (tokens[i].matches("[0-9]+[a-z]")) {
|
||||
String numberString = tokens[i].substring(0, tokens[i].length() - 1);
|
||||
versionTokens.add(Integer.valueOf(numberString));
|
||||
versionTokens.add(Character.getNumericValue(tokens[i].charAt(tokens[i].length() - 1)));
|
||||
}
|
||||
}
|
||||
|
||||
// Can't use versionTokens.toArray 'cause that returns an Integer[], not int[]
|
||||
int[] value = new int[versionTokens.size()];
|
||||
for (int i = 0; i < value.length; ++i) {
|
||||
value[i] = versionTokens.get(i).intValue();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static boolean beforeTargetVersion(String version, String target) {
|
||||
boolean result = false;
|
||||
int[] versionTokens = parseVersion(version);
|
||||
int[] targetTokens = parseVersion(target);
|
||||
|
||||
for (int i = 0; i < versionTokens.length && i < targetTokens.length; ++i) {
|
||||
if (versionTokens[i] < targetTokens[i]) {
|
||||
result = true;
|
||||
break;
|
||||
} else if (versionTokens[i] > targetTokens[i]) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == versionTokens.length - 1 && versionTokens.length < targetTokens.length) {
|
||||
// If the versions compared are the same, but target has an extra token, it's probably a "letter" build
|
||||
// and is ahead of this one.
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static boolean afterTargetVersion(String version, String target) {
|
||||
boolean result = false;
|
||||
int[] versionTokens = parseVersion(version);
|
||||
int[] targetTokens = parseVersion(target);
|
||||
|
||||
for (int i = 0; i < versionTokens.length && i < targetTokens.length; ++i) {
|
||||
if (versionTokens[i] > targetTokens[i]) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public VersionInfo(String name, String version, String url) {
|
||||
modName = name;
|
||||
modVersion = latestModVersion = version;
|
||||
releaseURL = url;
|
||||
}
|
||||
|
||||
public VersionInfo(String name, String version, String url, Logger logger) {
|
||||
modName = name;
|
||||
modVersion = latestModVersion = version;
|
||||
releaseURL = url;
|
||||
}
|
||||
|
||||
public void checkForNewVersion() {
|
||||
Thread versionCheckThread = new VersionCheckThread();
|
||||
versionCheckThread.start();
|
||||
}
|
||||
|
||||
public String getCurrentVersion() {
|
||||
return modVersion;
|
||||
}
|
||||
|
||||
public String getLatestVersion() {
|
||||
return latestModVersion;
|
||||
}
|
||||
|
||||
public String getVersionDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean isCriticalUpdate() {
|
||||
return criticalUpdate;
|
||||
}
|
||||
|
||||
public boolean isNewVersionAvailable() {
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
public boolean isVersionCheckComplete() {
|
||||
return versionCheckComplete;
|
||||
}
|
||||
|
||||
private class VersionCheckThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String location = VersionURL;
|
||||
|
||||
HttpURLConnection connection = null;
|
||||
|
||||
// Used to "dereference" any location headers we may get.
|
||||
while (location != null && !location.isEmpty()) {
|
||||
URL url = new URL(location);
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestProperty(
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17");
|
||||
connection.connect();
|
||||
location = connection.getHeaderField("Location");
|
||||
}
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
latestModVersion = reader.readLine();
|
||||
criticalUpdate = Boolean.parseBoolean(reader.readLine());
|
||||
while (reader.ready()) {
|
||||
description = description + reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
|
||||
if (beforeTargetVersion(modVersion, latestModVersion)) {
|
||||
FMLLog.info("An updated version of " + modName + " is available: " + latestModVersion
|
||||
+ ". You are currently using " + Version);
|
||||
newVersion = true;
|
||||
if (criticalUpdate) {
|
||||
LogHelper.info(
|
||||
"This update has been marked as CRITICAL and will ignore notification suppression.");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
LogHelper.warn("Version check Failed: " + e.getMessage());
|
||||
}
|
||||
versionCheckComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void doVersionCheck() {
|
||||
VersionInfo versionInfo = new VersionInfo(ModName, Version, VersionURL);
|
||||
TickHandlerVersion.go(versionInfo);
|
||||
|
||||
VersionCheckThread thread = versionInfo.new VersionCheckThread();
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user