ServerPackCreator icon indicating copy to clipboard operation
ServerPackCreator copied to clipboard

[Feature request]: Replace the "Error: could not find or load main class @user_jvm_args.txt" message

Open chorbintime opened this issue 3 years ago • 8 comments

Whats the feature you would like to be added?

Replace the "Error: could not find or load main class @user_jvm_args.txt" message that is generated when the wrong java version is being used with something more readable such as "Wrong java version installed!"

Anything else you would like to add?

No

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

chorbintime avatar Dec 10 '22 00:12 chorbintime

As I mentioned in Discord, it is a message generated by Java/Forge, not SPC, so I can not guarantee anything. :)

Griefed avatar Dec 10 '22 08:12 Griefed

Heya Chorb,

just poppin in to let you know that, unfortunately, I haven't had time to investigate this and whether a nice solution would be or is possible. It may be a while before I get to seriously tackle this. Unless someone else comes around and presents a nice solution to this issue.

Cheers, Griefed

Griefed avatar Mar 28 '23 08:03 Griefed

Its okay!

chorbintime avatar Mar 29 '23 00:03 chorbintime

Heya Chorb,

just poppin in to let you know that, unfortunately, I haven't had time to investigate this and whether a nice solution would be or is possible. It may be a while before I get to seriously tackle this. Unless someone else comes around and presents a nice solution to this issue.

Cheers, Griefed

Could maybe try to catch the issue before java does within the bash/batch script, i.e add another check like the one for the java-bit-ness

Could look like this (At least for the bash script):

checkJavaVersion() {
  # Define the minimum Minecraft version that uses Java 8
  min_java8_version="1.6"

  # Get the Minecraft version from the environment variable
  minecraft_version="$MINECRAFT_VERSION"

  # Split the Minecraft version into components
  IFS='.' read -ra version_components <<< "$minecraft_version"

  # Check if the Minecraft version is less than 1.18
  if [[ "${version_components[0]}" -lt 1 || ( "${version_components[0]}" -eq 1 && "${version_components[1]}" -lt 18 ) ]]; then
    # For versions below 1.18, check for Java 8
    if "$JAVA" -version 2>&1 | grep -q "1."; then
      echo "WARNING! Incorrect Java version detected, versions $min_java8_version to 1.17 use Java 8."
      crash
    else
      echo "Java version is correct for Minecraft $minecraft_version."
    fi
  else
    # For versions 1.18 and above, check for Java 17
    if ! "$JAVA" -version 2>&1 | grep -q "1.1[89]"; then
      echo "WARNING! Incorrect Java version detected, Minecraft $minecraft_version uses Java 17 or higher."
      crash
    else
      echo "Java version is correct for Minecraft $minecraft_version."
    fi
fi
  }

Just call it right after the java bitness check

DisruptionSystemsINC avatar Oct 30 '23 19:10 DisruptionSystemsINC

There is probably also easier or less convoluted ways to do this, but this is what i came up with for now

DisruptionSystemsINC avatar Oct 30 '23 19:10 DisruptionSystemsINC

I wouldn't be so definite on "use java 8 or else", since you can use up to java 21 on 1.16.5 without issue (requires special args though)

chorbintime avatar Oct 31 '23 04:10 chorbintime

I wouldn't be so definite on "use java 8 or else", since you can use up to java 21 on 1.16.5 without issue (requires special args though)

maybe add another variable to the variables.txt like SkipJavaVersionCheck=false Should someone really want to use a newer Java version with a Minecraft version Though, I don't really see a reason why you would want to run it using a newer version of Java

DisruptionSystemsINC avatar Oct 31 '23 05:10 DisruptionSystemsINC

Running a server or client with a newer version of Java results in a major performance boost.

chorbintime avatar Nov 05 '23 02:11 chorbintime

Java checks are available as of https://github.com/Griefed/ServerPackCreator/releases/tag/6.0.0-alpha.3

Checks are based on the info from MultiMC and the info Chorb posted somewhere, as in MC 1.16 and older can use Java 8 and 11, everything else has a "minimum required" check.

This should aleviate at least a portion of problems on the users side for their Java version.

Griefed avatar Jun 02 '24 17:06 Griefed

Thank you so much! I would maybe add an option somewhere to bypass the Java requirement, as some special args can allow super new Java versions to work on older versions. This would only be for advanced users though, so you could add it to variables.txt or something, and add a message when the server gets force-crashed that tells the user? Up to you how you'd want to execute this I suppose, but some sort of bypasss would be nice! Thanks again

chorbintime avatar Jun 03 '24 13:06 chorbintime

A skip is no problem at all, not even much work. I'll add it. Out of curiosity, is there a wiki or faq regarding the arguments you mentioned, or do you have your own documentation?

Might be worthwhile to add a section to the SPC help-docs. THe more the merrier.

As for the force-crash message: That's a tricky one, as I can't reliably catch the crash reason of the server across all scripts. I'll add a message if the skip is active which get#s displayed after the server stops, regardless of why it stopped.

Griefed avatar Jun 03 '24 17:06 Griefed

The only guide I know of would be https://github.com/embeddedt/ModernFix/wiki/1.16---required-arguments-for-Java-17

chorbintime avatar Jun 05 '24 02:06 chorbintime

Check out the latest alpha build: https://github.com/Griefed/ServerPackCreator/releases/tag/6.0.0-alpha.11

It not only has Java compatibility checks, which were added in alpha 3, but also automated Java installation based on the Java version recommended by Mojang themselves.

I'd appreciate some tests on this. :)

Griefed avatar Jun 24 '24 07:06 Griefed

Available as of 6.0.0

Griefed avatar Jul 26 '24 18:07 Griefed