Skip to content

Commit

Permalink
feat(legacy): check Java version at start (#5550)
Browse files Browse the repository at this point in the history
  • Loading branch information
MukjepScarlet authored Feb 7, 2025
1 parent 0273c16 commit e1cbb19
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/ccbluex/liquidbounce/LiquidBounce.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import net.ccbluex.liquidbounce.utils.client.ClassUtils.hasForge
import net.ccbluex.liquidbounce.utils.client.ClientUtils.LOGGER
import net.ccbluex.liquidbounce.utils.client.ClientUtils.disableFastRender
import net.ccbluex.liquidbounce.utils.client.PacketUtils
import net.ccbluex.liquidbounce.utils.client.checkJavaVersion
import net.ccbluex.liquidbounce.utils.inventory.InventoryManager
import net.ccbluex.liquidbounce.utils.inventory.InventoryUtils
import net.ccbluex.liquidbounce.utils.inventory.SilentHotbar
Expand Down Expand Up @@ -117,6 +118,9 @@ object LiquidBounce {
* Start IO tasks
*/
fun preload(): Future<*> {

checkJavaVersion()

// Change theme of Swing
UIManager.setLookAndFeel(FlatMacLightLaf())

Expand Down
68 changes: 68 additions & 0 deletions src/main/java/net/ccbluex/liquidbounce/utils/client/JavaVersion.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* LiquidBounce Hacked Client
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
* https://github.com/CCBlueX/LiquidBounce/
*/
package net.ccbluex.liquidbounce.utils.client

import kotlinx.coroutines.launch
import net.ccbluex.liquidbounce.LiquidBounce
import net.ccbluex.liquidbounce.utils.io.MiscUtils
import net.ccbluex.liquidbounce.utils.kotlin.SharedScopes
import javax.swing.JOptionPane

private const val DOWNLOAD_PAGE = "https://www.java.com/download/manual.jsp"

/**
* Check if the client is run on a proper JVM.
*/
fun checkJavaVersion() {
val javaVersion = System.getProperty("java.version")

val regex = Regex("""(\d+)(?:\.(\d+))?(?:\.(\d+))?_?(\d+)?""")
val matchResult = regex.matchEntire(javaVersion)

if (matchResult != null) {
val (major, minor, patch, update) = matchResult.destructured

when {
// <= Java 8
major == "1" -> when {
// < Java 8, crash
minor.toInt() < 8 -> {
MiscUtils.showURL(DOWNLOAD_PAGE)
error("You should start ${LiquidBounce.CLIENT_NAME} with Java 8! Get it from $DOWNLOAD_PAGE")
}
// < Java 8u100, warn
update.toInt() < 100 -> {
SharedScopes.IO.launch {
MiscUtils.showMessageDialog(
title = "Warning",
message = "You are using an outdated version of Java 8 ($javaVersion).\n"
+ "This might cause unexpected bugs.\n"
+ "Please update it to 8u101+ or get a new one from $DOWNLOAD_PAGE.",
JOptionPane.WARNING_MESSAGE
)
MiscUtils.showURL(DOWNLOAD_PAGE)
}
}
}
// > Java 8
major.toInt() > 8 -> {
SharedScopes.IO.launch {
MiscUtils.showMessageDialog(
title = "Warning",
message = "This version of ${LiquidBounce.CLIENT_NAME} is designed for Java 8 environment.\n"
+ "Higher versions of Java might cause bug or crash.\n"
+ "You can get JRE 8 from $DOWNLOAD_PAGE.",
JOptionPane.WARNING_MESSAGE
)
MiscUtils.showURL(DOWNLOAD_PAGE)
}
}
}
} else {
// ???
ClientUtils.LOGGER.error("Failed to parse Java version $javaVersion")
}
}

0 comments on commit e1cbb19

Please sign in to comment.