PrismLauncher/api/logic/minecraft/launch/VerifyJavaInstall.cpp
Jamie Mansfield a20a7e987f
NOISSUE Fail launch if minimum Java requirement is not met
This will fail launch in the following conditions:
  1. A version greater than or equal to Minecraft 17w13a, and less than
     21w19a - and the Java version is less than 8.
  2. A version greater than or equal to Minecraft 21w19a - and the Java
     version is less than 16.
2021-06-23 21:24:25 +01:00

35 lines
1.3 KiB
C++

#include "VerifyJavaInstall.h"
#include <launch/LaunchTask.h>
#include <minecraft/MinecraftInstance.h>
#include <minecraft/PackProfile.h>
#include <minecraft/VersionFilterData.h>
void VerifyJavaInstall::executeTask() {
auto m_inst = std::dynamic_pointer_cast<MinecraftInstance>(m_parent->instance());
auto javaVersion = m_inst->getJavaVersion();
auto minecraftComponent = m_inst->getPackProfile()->getComponent("net.minecraft");
// Java 16 requirement
if (minecraftComponent->getReleaseDateTime() >= g_VersionFilterData.java16BeginsDate) {
if (javaVersion.major() < 16) {
emit logLine("Minecraft 21w19a and above require the use of Java 16",
MessageLevel::Fatal);
emitFailed(tr("Minecraft 21w19a and above require the use of Java 16"));
return;
}
}
// Java 8 requirement
else if (minecraftComponent->getReleaseDateTime() >= g_VersionFilterData.java8BeginsDate) {
if (javaVersion.major() < 8) {
emit logLine("Minecraft 17w13a and above require the use of Java 8",
MessageLevel::Fatal);
emitFailed(tr("Minecraft 17w13a and above require the use of Java 8"));
return;
}
}
emitSucceeded();
}