1.17+ Support / Java Settings by Instance (#261)
* Patches to get 1.17 working, need to revise into real solutions. * Add version.jar to cp until 1.17. * Add server selection button to Java settings tab in preparation for by-instance java settings. * Java settings by instance * Use classpath flag instead of hardcode. * Support 1.19. * Fix refresh of java exec details. * Add doc. * Fix auto download of jdk 17. * Dependency upgrade.
This commit is contained in:
@@ -63,6 +63,27 @@ function resolveMinRAM(){
|
||||
return resolveMaxRAM()
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Copy pasted, should be in a utility file.
|
||||
*
|
||||
* Returns true if the actual version is greater than
|
||||
* or equal to the desired version.
|
||||
*
|
||||
* @param {string} desired The desired version.
|
||||
* @param {string} actual The actual version.
|
||||
*/
|
||||
function mcVersionAtLeast(desired, actual){
|
||||
const des = desired.split('.')
|
||||
const act = actual.split('.')
|
||||
|
||||
for(let i=0; i<des.length; i++){
|
||||
if(!(parseInt(act[i]) >= parseInt(des[i]))){
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Three types of values:
|
||||
* Static = Explicitly declared.
|
||||
@@ -71,17 +92,6 @@ function resolveMinRAM(){
|
||||
*/
|
||||
const DEFAULT_CONFIG = {
|
||||
settings: {
|
||||
java: {
|
||||
minRAM: resolveMinRAM(),
|
||||
maxRAM: resolveMaxRAM(), // Dynamic
|
||||
executable: null,
|
||||
jvmOptions: [
|
||||
'-XX:+UseConcMarkSweepGC',
|
||||
'-XX:+CMSIncrementalMode',
|
||||
'-XX:-UseAdaptiveSizePolicy',
|
||||
'-Xmn128M'
|
||||
],
|
||||
},
|
||||
game: {
|
||||
resWidth: 1280,
|
||||
resHeight: 720,
|
||||
@@ -103,7 +113,8 @@ const DEFAULT_CONFIG = {
|
||||
selectedServer: null, // Resolved
|
||||
selectedAccount: null,
|
||||
authenticationDatabase: {},
|
||||
modConfigurations: []
|
||||
modConfigurations: [],
|
||||
javaConfig: {}
|
||||
}
|
||||
|
||||
let config = null
|
||||
@@ -177,7 +188,7 @@ function validateKeySet(srcObj, destObj){
|
||||
if(srcObj == null){
|
||||
srcObj = {}
|
||||
}
|
||||
const validationBlacklist = ['authenticationDatabase']
|
||||
const validationBlacklist = ['authenticationDatabase', 'javaConfig']
|
||||
const keys = Object.keys(srcObj)
|
||||
for(let i=0; i<keys.length; i++){
|
||||
if(typeof destObj[keys[i]] === 'undefined'){
|
||||
@@ -511,16 +522,66 @@ exports.setModConfiguration = function(serverid, configuration){
|
||||
|
||||
// Java Settings
|
||||
|
||||
function defaultJavaConfig(mcVersion) {
|
||||
if(mcVersionAtLeast('1.17', mcVersion)) {
|
||||
return defaultJavaConfig117()
|
||||
} else {
|
||||
return defaultJavaConfigBelow117()
|
||||
}
|
||||
}
|
||||
|
||||
function defaultJavaConfigBelow117() {
|
||||
return {
|
||||
minRAM: resolveMinRAM(),
|
||||
maxRAM: resolveMaxRAM(), // Dynamic
|
||||
executable: null,
|
||||
jvmOptions: [
|
||||
'-XX:+UseConcMarkSweepGC',
|
||||
'-XX:+CMSIncrementalMode',
|
||||
'-XX:-UseAdaptiveSizePolicy',
|
||||
'-Xmn128M'
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
function defaultJavaConfig117() {
|
||||
return {
|
||||
minRAM: resolveMinRAM(),
|
||||
maxRAM: resolveMaxRAM(), // Dynamic
|
||||
executable: null,
|
||||
jvmOptions: [
|
||||
'-XX:+UnlockExperimentalVMOptions',
|
||||
'-XX:+UseG1GC',
|
||||
'-XX:G1NewSizePercent=20',
|
||||
'-XX:G1ReservePercent=20',
|
||||
'-XX:MaxGCPauseMillis=50',
|
||||
'-XX:G1HeapRegionSize=32M'
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a java config property is set for the given server.
|
||||
*
|
||||
* @param {string} serverid The server id.
|
||||
* @param {*} mcVersion The minecraft version of the server.
|
||||
*/
|
||||
exports.ensureJavaConfig = function(serverid, mcVersion) {
|
||||
if(!Object.prototype.hasOwnProperty.call(config.javaConfig, serverid)) {
|
||||
config.javaConfig[serverid] = defaultJavaConfig(mcVersion)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the minimum amount of memory for JVM initialization. This value
|
||||
* contains the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
|
||||
* 1024 MegaBytes, etc.
|
||||
*
|
||||
* @param {boolean} def Optional. If true, the default value will be returned.
|
||||
* @param {string} serverid The server id.
|
||||
* @returns {string} The minimum amount of memory for JVM initialization.
|
||||
*/
|
||||
exports.getMinRAM = function(def = false){
|
||||
return !def ? config.settings.java.minRAM : DEFAULT_CONFIG.settings.java.minRAM
|
||||
exports.getMinRAM = function(serverid){
|
||||
return config.javaConfig[serverid].minRAM
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,10 +589,11 @@ exports.getMinRAM = function(def = false){
|
||||
* contain the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
|
||||
* 1024 MegaBytes, etc.
|
||||
*
|
||||
* @param {string} serverid The server id.
|
||||
* @param {string} minRAM The new minimum amount of memory for JVM initialization.
|
||||
*/
|
||||
exports.setMinRAM = function(minRAM){
|
||||
config.settings.java.minRAM = minRAM
|
||||
exports.setMinRAM = function(serverid, minRAM){
|
||||
config.javaConfig[serverid].minRAM = minRAM
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,11 +601,11 @@ exports.setMinRAM = function(minRAM){
|
||||
* contains the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
|
||||
* 1024 MegaBytes, etc.
|
||||
*
|
||||
* @param {boolean} def Optional. If true, the default value will be returned.
|
||||
* @param {string} serverid The server id.
|
||||
* @returns {string} The maximum amount of memory for JVM initialization.
|
||||
*/
|
||||
exports.getMaxRAM = function(def = false){
|
||||
return !def ? config.settings.java.maxRAM : resolveMaxRAM()
|
||||
exports.getMaxRAM = function(serverid){
|
||||
return config.javaConfig[serverid].maxRAM
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -551,10 +613,11 @@ exports.getMaxRAM = function(def = false){
|
||||
* contain the units of memory. For example, '5G' = 5 GigaBytes, '1024M' =
|
||||
* 1024 MegaBytes, etc.
|
||||
*
|
||||
* @param {string} serverid The server id.
|
||||
* @param {string} maxRAM The new maximum amount of memory for JVM initialization.
|
||||
*/
|
||||
exports.setMaxRAM = function(maxRAM){
|
||||
config.settings.java.maxRAM = maxRAM
|
||||
exports.setMaxRAM = function(serverid, maxRAM){
|
||||
config.javaConfig[serverid].maxRAM = maxRAM
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -562,19 +625,21 @@ exports.setMaxRAM = function(maxRAM){
|
||||
*
|
||||
* This is a resolved configuration value and defaults to null until externally assigned.
|
||||
*
|
||||
* @param {string} serverid The server id.
|
||||
* @returns {string} The path of the Java Executable.
|
||||
*/
|
||||
exports.getJavaExecutable = function(){
|
||||
return config.settings.java.executable
|
||||
exports.getJavaExecutable = function(serverid){
|
||||
return config.javaConfig[serverid].executable
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path of the Java Executable.
|
||||
*
|
||||
* @param {string} serverid The server id.
|
||||
* @param {string} executable The new path of the Java Executable.
|
||||
*/
|
||||
exports.setJavaExecutable = function(executable){
|
||||
config.settings.java.executable = executable
|
||||
exports.setJavaExecutable = function(serverid, executable){
|
||||
config.javaConfig[serverid].executable = executable
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -582,11 +647,11 @@ exports.setJavaExecutable = function(executable){
|
||||
* such as memory allocation, will be dynamically resolved and will not be included
|
||||
* in this value.
|
||||
*
|
||||
* @param {boolean} def Optional. If true, the default value will be returned.
|
||||
* @param {string} serverid The server id.
|
||||
* @returns {Array.<string>} An array of the additional arguments for JVM initialization.
|
||||
*/
|
||||
exports.getJVMOptions = function(def = false){
|
||||
return !def ? config.settings.java.jvmOptions : DEFAULT_CONFIG.settings.java.jvmOptions
|
||||
exports.getJVMOptions = function(serverid){
|
||||
return config.javaConfig[serverid].jvmOptions
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -594,11 +659,12 @@ exports.getJVMOptions = function(def = false){
|
||||
* such as memory allocation, will be dynamically resolved and should not be
|
||||
* included in this value.
|
||||
*
|
||||
* @param {string} serverid The server id.
|
||||
* @param {Array.<string>} jvmOptions An array of the new additional arguments for JVM
|
||||
* initialization.
|
||||
*/
|
||||
exports.setJVMOptions = function(jvmOptions){
|
||||
config.settings.java.jvmOptions = jvmOptions
|
||||
exports.setJVMOptions = function(serverid, jvmOptions){
|
||||
config.javaConfig[serverid].jvmOptions = jvmOptions
|
||||
}
|
||||
|
||||
// Game Settings
|
||||
|
||||
Reference in New Issue
Block a user