Skip to content

Commit

Permalink
Added preJava Arg, allowed Xms arg in list
Browse files Browse the repository at this point in the history
  • Loading branch information
BloodWorkXGaming committed Jun 5, 2018
1 parent ab14885 commit 128212d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = 'atm.bloodworkxgaming'
version = '1.2.1'
version = '1.2.2'

sourceCompatibility = 1.8

Expand Down
4 changes: 4 additions & 0 deletions server-setup-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ launch:
# syntax is either [number]h or [number]min or [number]s
crashTimer: 60min

# Arguments that need to go before the 'java' argument, something like linux niceness
# This is only a string, not a list.
preJavaArgs: ~

# Java args that are supposed to be used when the server launches
# keep in mind java args often need ' - ' in front of it to work, use clarifying parentheses to make sure it uses it correctly
javaArgs:
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/atm/bloodworkxgaming/serverstarter/ForgeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,20 @@ private void startServer() {

List<String> arguments = new ArrayList<>();

arguments.add(configFile.launch.preJavaArgs);
arguments.add("java");
arguments.addAll(configFile.launch.javaArgs);
arguments.add("-Xmx" + configFile.launch.maxRam);
try {
int xmx = Integer.parseInt(configFile.launch.maxRam.substring(0, configFile.launch.maxRam.length() - 1));
int xms = Math.max(1, xmx / 2);
arguments.add("-Xms" + xms + configFile.launch.maxRam.substring(configFile.launch.maxRam.length() - 1));

} catch (NumberFormatException e) {
LOGGER.error("Problem while calculating XMS", e);
if (configFile.launch.javaArgs.stream().noneMatch(s -> s.trim().startsWith("-Xms"))){
try {
int xmx = Integer.parseInt(configFile.launch.maxRam.substring(0, configFile.launch.maxRam.length() - 1));
int xms = Math.max(1, xmx / 2);
arguments.add("-Xms" + xms + configFile.launch.maxRam.substring(configFile.launch.maxRam.length() - 1));

} catch (NumberFormatException e) {
LOGGER.error("Problem while calculating XMS", e);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public class LaunchSettings {
public int crashLimit;
public String crashTimer;
public List<String> javaArgs;
public String preJavaArgs;

public LaunchSettings normalize(){
if (javaArgs == null) javaArgs = Collections.emptyList();
if (preJavaArgs == null) preJavaArgs = "";

return this;
}
Expand Down

0 comments on commit 128212d

Please sign in to comment.