From abb2eddfca7610ad1cd568d7025a58e32b6e5428 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Mon, 9 Jun 2014 20:21:41 -0500 Subject: [PATCH 1/3] Add Version Checker Support. --- services/VersionChecker.java | 63 ++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/services/VersionChecker.java b/services/VersionChecker.java index d2922b388..e12931287 100644 --- a/services/VersionChecker.java +++ b/services/VersionChecker.java @@ -5,18 +5,25 @@ import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.Date; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import net.minecraft.nbt.NBTTagCompound; import appeng.core.AEConfig; import appeng.core.AELog; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + +import cpw.mods.fml.common.event.FMLInterModComms; + public class VersionChecker implements Runnable { public static VersionChecker instance = null; private long delay = 0; + private boolean VersionChecker = true; public VersionChecker() { long now = (new Date()).getTime(); @@ -41,13 +48,12 @@ public class VersionChecker implements Runnable Thread.yield(); try { - URL url = new URL( "http://ae-mod.info/releases/?latest" ); - - String MCVersion = cpw.mods.fml.common.Loader.instance().getMCVersionString(); + String MCVersion = cpw.mods.fml.common.Loader.instance().getMCVersionString().replace( "Minecraft ", "" ); + URL url = new URL( "http://ae2.ae-mod.info/builds/latest.json?VersionMC=" + MCVersion + "&Channel=" + AEConfig.CHANNEL + "&CurrentVersion=" + + AEConfig.VERSION ); URLConnection yc = url.openConnection(); - yc.setRequestProperty( "User-Agent", "AE2/" + AEConfig.VERSION + " (Channel:" + AEConfig.CHANNEL + "," + MCVersion.replace( " ", ":" ) - + ")" ); + yc.setRequestProperty( "User-Agent", "AE2/" + AEConfig.VERSION + " (Channel:" + AEConfig.CHANNEL + "," + MCVersion.replace( " ", ":" ) + ")" ); BufferedReader in = new BufferedReader( new InputStreamReader( yc.getInputStream() ) ); String Version = ""; @@ -60,12 +66,42 @@ public class VersionChecker implements Runnable if ( Version.length() > 2 ) { - Matcher m = Pattern.compile( "\"Version\":\"([^\"]+)\"" ).matcher( Version ); - m.find(); - Version = m.group( 1 ); - AEConfig.instance.latestVersion = Version; - AEConfig.instance.latestTimeStamp = (new Date()).getTime(); - AEConfig.instance.save(); + JsonElement element = (new JsonParser()).parse( Version ); + + int version = element.getAsJsonObject().get( "FormatVersion" ).getAsInt(); + if ( version == 1 ) + { + JsonObject Meta = element.getAsJsonObject().get( "Meta" ).getAsJsonObject(); + JsonArray Versions = element.getAsJsonObject().get( "Versions" ).getAsJsonArray(); + if ( Versions.size() > 0 ) + { + JsonObject Latest = Versions.get( 0 ).getAsJsonObject(); + + AEConfig.instance.latestVersion = Latest.get( "Version" ).getAsString(); + AEConfig.instance.latestTimeStamp = (new Date()).getTime(); + AEConfig.instance.save(); + + if ( VersionChecker && !AEConfig.VERSION.equals( AEConfig.instance.latestVersion ) ) + { + NBTTagCompound versionInf = new NBTTagCompound(); + versionInf.setString( "modDisplayName", "Applied Energistics 2" ); + versionInf.setString( "oldVersion", AEConfig.VERSION ); + versionInf.setString( "newVersion", AEConfig.instance.latestVersion ); + versionInf.setString( "updateUrl", Latest.get( "UserBuild" ).getAsString() ); + versionInf.setBoolean( "isDirectLink", true ); + + JsonElement changeLog = Latest.get( "ChangeLog" ); + if ( changeLog == null ) + versionInf.setString( "changeLog", "For full change log please see: " + Meta.get( "DownloadLink" ).getAsString() ); + else + versionInf.setString( "changeLog", changeLog.getAsString() ); + + versionInf.setString( "newFileName", "appliedenergistics2-" + AEConfig.instance.latestVersion + ".jar" ); + FMLInterModComms.sendMessage( "VersionChecker", "addUpdate", versionInf ); + VersionChecker = false; + } + } + } } Thread.sleep( 1000 * 3600 * 4 ); @@ -83,5 +119,4 @@ public class VersionChecker implements Runnable } } } - } From 77f9a22d0305c472e862099aef0426eba0604a87 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Mon, 9 Jun 2014 20:42:48 -0500 Subject: [PATCH 2/3] Use sendRuntimeMessage --- services/VersionChecker.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/VersionChecker.java b/services/VersionChecker.java index e12931287..a72d5a9ba 100644 --- a/services/VersionChecker.java +++ b/services/VersionChecker.java @@ -9,6 +9,7 @@ import java.util.Date; import net.minecraft.nbt.NBTTagCompound; import appeng.core.AEConfig; import appeng.core.AELog; +import appeng.core.AppEng; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -97,7 +98,7 @@ public class VersionChecker implements Runnable versionInf.setString( "changeLog", changeLog.getAsString() ); versionInf.setString( "newFileName", "appliedenergistics2-" + AEConfig.instance.latestVersion + ".jar" ); - FMLInterModComms.sendMessage( "VersionChecker", "addUpdate", versionInf ); + FMLInterModComms.sendRuntimeMessage( AppEng.instance, "VersionChecker", "addUpdate", versionInf ); VersionChecker = false; } } From a73109b62e3e668cd490c28a14cfc7021f9a645d Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Mon, 9 Jun 2014 21:22:35 -0500 Subject: [PATCH 3/3] Fixed http://openeye.openmods.info/crashes/1cc02c8016ddc5ec81efb429f5653ad0 --- parts/automation/PartAnnihilationPlane.java | 32 ++++++++++--------- parts/automation/PartFormationPlane.java | 35 ++++++++++++--------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/parts/automation/PartAnnihilationPlane.java b/parts/automation/PartAnnihilationPlane.java index afb03ea21..386153454 100644 --- a/parts/automation/PartAnnihilationPlane.java +++ b/parts/automation/PartAnnihilationPlane.java @@ -134,26 +134,30 @@ public class PartAnnihilationPlane extends PartBasicState implements IGridTickab int maxX = 15; int maxY = 15; - TileEntity te = getHost().getTile(); + IPartHost host = getHost(); + if ( host != null ) + { + TileEntity te = host.getTile(); - int x = te.xCoord; - int y = te.yCoord; - int z = te.zCoord; + int x = te.xCoord; + int y = te.yCoord; + int z = te.zCoord; - ForgeDirection e = bch.getWorldX(); - ForgeDirection u = bch.getWorldY(); + ForgeDirection e = bch.getWorldX(); + ForgeDirection u = bch.getWorldY(); - if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - e.offsetX, y - e.offsetY, z - e.offsetZ ), side ) ) - minX = 0; + if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - e.offsetX, y - e.offsetY, z - e.offsetZ ), side ) ) + minX = 0; - if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + e.offsetX, y + e.offsetY, z + e.offsetZ ), side ) ) - maxX = 16; + if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + e.offsetX, y + e.offsetY, z + e.offsetZ ), side ) ) + maxX = 16; - if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - u.offsetX, y - u.offsetY, z - u.offsetZ ), side ) ) - minY = 0; + if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - u.offsetX, y - u.offsetY, z - u.offsetZ ), side ) ) + minY = 0; - if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + u.offsetX, y + u.offsetY, z + u.offsetZ ), side ) ) - maxY = 16; + if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + u.offsetX, y + u.offsetY, z + u.offsetZ ), side ) ) + maxY = 16; + } bch.addBox( 5, 5, 14, 11, 11, 15 ); bch.addBox( minX, minY, 15, maxX, maxY, bch.isBBCollision() ? 15 : 16 ); diff --git a/parts/automation/PartFormationPlane.java b/parts/automation/PartFormationPlane.java index 5f1a8d610..c20998803 100644 --- a/parts/automation/PartFormationPlane.java +++ b/parts/automation/PartFormationPlane.java @@ -201,26 +201,30 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine int maxX = 15; int maxY = 15; - TileEntity te = getHost().getTile(); + IPartHost host = getHost(); + if ( host != null ) + { + TileEntity te = host.getTile(); - int x = te.xCoord; - int y = te.yCoord; - int z = te.zCoord; + int x = te.xCoord; + int y = te.yCoord; + int z = te.zCoord; - ForgeDirection e = bch.getWorldX(); - ForgeDirection u = bch.getWorldY(); + ForgeDirection e = bch.getWorldX(); + ForgeDirection u = bch.getWorldY(); - if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - e.offsetX, y - e.offsetY, z - e.offsetZ ), side ) ) - minX = 0; + if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - e.offsetX, y - e.offsetY, z - e.offsetZ ), side ) ) + minX = 0; - if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + e.offsetX, y + e.offsetY, z + e.offsetZ ), side ) ) - maxX = 16; + if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + e.offsetX, y + e.offsetY, z + e.offsetZ ), side ) ) + maxX = 16; - if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - u.offsetX, y - u.offsetY, z - u.offsetZ ), side ) ) - minY = 0; + if ( isTransitionPlane( te.getWorldObj().getTileEntity( x - u.offsetX, y - u.offsetY, z - u.offsetZ ), side ) ) + minY = 0; - if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + u.offsetX, y + u.offsetY, z + u.offsetZ ), side ) ) - maxY = 16; + if ( isTransitionPlane( te.getWorldObj().getTileEntity( x + u.offsetX, y + u.offsetY, z + u.offsetZ ), side ) ) + maxY = 16; + } bch.addBox( 5, 5, 14, 11, 11, 15 ); bch.addBox( minX, minY, 15, maxX, maxY, 16 ); @@ -399,7 +403,8 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine side.offsetX, side.offsetY, side.offsetZ ); if ( Worked == false && side.offsetX == 0 && side.offsetZ == 0 ) - Worked = i.onItemUse( is, player, w, x-side.offsetX, y-side.offsetY, z-side.offsetZ, side.ordinal(), side.offsetX, side.offsetY, side.offsetZ ); + Worked = i.onItemUse( is, player, w, x - side.offsetX, y - side.offsetY, z - side.offsetZ, side.ordinal(), side.offsetX, + side.offsetY, side.offsetZ ); if ( Worked == false && side.offsetY == 0 ) Worked = i.onItemUse( is, player, w, x, y - 1, z, ForgeDirection.UP.ordinal(), side.offsetX, side.offsetY, side.offsetZ );