Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable update checking #3

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 5 additions & 73 deletions src/main/scala/mrtjp/core/data/UpdateChecker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,9 @@
*/
package mrtjp.core.data

import java.io.{BufferedReader, InputStreamReader}
import java.net.URL

import cpw.mods.fml.common.FMLCommonHandler
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import cpw.mods.fml.common.gameevent.TickEvent
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent
import net.minecraft.client.Minecraft
import net.minecraft.util.ChatComponentText

trait UpdateChecker extends Thread
{
setName(project+" version checker")
setDaemon(true)

try { if (shouldRun) FMLCommonHandler.instance.bus.register(this) } catch { case t:Throwable => }

def project:String
def changelogURL:String
Expand All @@ -32,69 +19,14 @@ trait UpdateChecker extends Thread

def downloadVersions:Seq[String] =
{
try
{
val url = new URL(changelogURL)
val in = new BufferedReader(new InputStreamReader(url.openStream()))

var line:String = ""
def next() = {line = in.readLine(); line}

val builder = Seq.newBuilder[String]

while (next() != null)
{
if (line.startsWith("v"))
builder += line.substring(1)
}
builder.result()
}
catch
{
case e:Exception => Seq.empty
}
Seq.empty
}

def isVersionOutdated(v:String) = v != availableVersions.head && availableVersions.contains(v)
def isVersionOutdated(v:String) = false

var updatesChecked = false
override def run()
{
if (updatesChecked) return
try
{
if (!shouldRun) return
if (isVersionOutdated(currentVersion))
{
val message = Seq.newBuilder[String]
message += s"$project ${availableVersions.head} available."
updateMessage = message.result()
}
}
catch
{
case t:Throwable => t.printStackTrace()
}
updatesChecked = true
}

private var messageDisplayed = false
private var updateMessage:Seq[String] = null
var updatesChecked = true

@SubscribeEvent
def tickEnd(event:PlayerTickEvent)
{
if (event.phase == TickEvent.Phase.END)
{
if (messageDisplayed) return
if (updateMessage != null)
{
val p = Minecraft.getMinecraft.thePlayer
for (s <- updateMessage) p.addChatMessage(new ChatComponentText(s))
}
messageDisplayed = true
}
}
override def run() {}

start()
}
}