diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..a93b14b --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,34 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Java CI with Gradle + +on: + push: + branches: [ master ] + pull_request: + types: [ opened, synchronize, reopened ] + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'zulu' + - name: Cache Gradle packages + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3966528 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +name: Release Build + +on: + push: + tags: + - 'v*' + +jobs: + build: + + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 8 + uses: actions/setup-java@v2 + with: + java-version: '8' + distribution: 'zulu' + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - name: Upload Release Asset + id: upload-release-assets + uses: alexellis/upload-assets@0.2.3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + asset_paths: '["build/distributions/*.zip", "build/libs/*.jar"]' diff --git a/build.gradle b/build.gradle index 89b38bf..dd0ad04 100644 --- a/build.gradle +++ b/build.gradle @@ -1,22 +1,14 @@ plugins { id 'java' - id "org.jetbrains.kotlin.jvm" version "1.2.51" - id "com.github.johnrengelman.shadow" version "2.0.4" - id "com.github.breadmoirai.github-release" version "2.2.9" + id 'distribution' + id "org.jetbrains.kotlin.jvm" version "1.4.32" + id "com.github.johnrengelman.shadow" version "6.1.0" } -group = 'atm.bloodworkxgaming' -version = '2.1.0' - -sourceCompatibility = 1.8 +java.toolchain.languageVersion = JavaLanguageVersion.of(8) repositories { mavenCentral() - - maven { - name = 'DVS1' - url = 'http://dvs1.progwml6.com/files/maven' - } } compileJava.options.encoding = 'UTF-8' @@ -25,94 +17,45 @@ tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } -dependencies { - testCompile group: 'junit', name: 'junit', version: '4.12' - - compile group: 'org.yaml', name: 'snakeyaml', version: '1.21' +distTar.enabled(false) +distributions { + main { + contents { + from jar + filesMatching("startserver.*") { + filter { it.replaceAll("@@serverstarter-libVersion@@", version as String) } + } + } + } +} - compile group: 'commons-io', name: 'commons-io', version: '2.6' - compile 'com.squareup.okhttp3:okhttp:3.10.0' - - compile group: 'com.google.code.gson', name: 'gson', version: '2.8.4' - - compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8") +dependencies { + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' - // https://mvnrepository.com/artifact/org.fusesource.jansi/jansi - compile group: 'org.fusesource.jansi', name: 'jansi', version: '1.17.1' + implementation 'com.squareup.okhttp3:okhttp:4.9.3' + implementation 'org.yaml:snakeyaml:1.29' + implementation 'commons-io:commons-io:2.11.0' + implementation 'com.google.code.gson:gson:2.8.9' + implementation 'org.fusesource.jansi:jansi:1.17.1' - compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.20' + testImplementation 'junit:junit:4.13.2' } +tasks.build.dependsOn shadowJar shadowJar { - classifier = "" + archiveClassifier.set('') } jar { manifest { attributes( - 'Class-Path': configurations.compile.collect { it.getName() }.join(' '), 'Main-Class': 'atm.bloodworkxgaming.serverstarter.ServerStarterKt' ) } } -tasks.build.dependsOn shadowJar - - -task copyJar(type: Copy) { - dependsOn build - - from file("$buildDir/libs/serverstarter-${version}.jar") - into file("$buildDir/dist/serverstarter-$version/") -} - -task packageDist(type: Copy) { - group = "build" - dependsOn copyJar - - from file("src/main/resources/startserver.bat") - from file("src/main/resources/startserver.sh") - from file("server-setup-config.yaml") - into file("$buildDir/dist/serverstarter-$version/") - - filter { it.replaceAll("@@serverstarter-libVersion@@", version as String) } -} - -task zipDist (type: Zip) { - dependsOn packageDist - group = "build" - - from file("$buildDir/dist/serverstarter-$version/") - include '*' - include '*/**' - archiveName = "serverstarter-${version}.zip" - destinationDir = file("$buildDir/release/") -} - - -githubRelease { - token = getGithubKey() - owner = "Yoosk" - repo = "ServerStarter" - - releaseAssets file("$buildDir/release/serverstarter-${version}.zip") -} - -tasks.githubRelease.dependsOn zipDist - -static String getGithubKey(){ - if (new File('secrets.properties').exists()) { - - Properties props = new Properties() - props.load(new FileInputStream(new File('secrets.properties'))) - return props['GITHUB_TOKEN'] - } - - return "" -} - task depsize { group = "help" doLast { diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..974c954 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,2 @@ +group=atm.bloodworkxgaming +version=2.0.2 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2b198bd..442d913 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Feb 08 22:19:47 CET 2020 -distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/server-setup-config.yaml b/src/main/dist/server-setup-config.yaml similarity index 63% rename from server-setup-config.yaml rename to src/main/dist/server-setup-config.yaml index 18172bd..3d01b86 100644 --- a/server-setup-config.yaml +++ b/src/main/dist/server-setup-config.yaml @@ -1,229 +1,195 @@ -# Version of the specs, only for internal usage if this format should ever change drastically -_specver: 2 - -# modpack related settings, changes the supposed to change the visual appearance of the launcher -modpack: - # Name of the mod pack, that is displayed in various places where it fits - name: Example Modpack - - # Description - description: This is a awesome modpack about making examples. - - -# settings regarding the installation of the modpack -install: - # version of minecraft, needs the exact version - mcVersion: 1.16.4 - - # exact version of forge or fabric that is supposed to be used - # if this value is a null value so ( ~, null, or "" ) then the version from the mod pack is going to be used - loaderVersion: 0.6.1.51 - - # If a custom installer is supposed to used, specify the url here: (Otherwise put "", ~ or null here) - # supports variables: {{@loaderversion@}} and {{@mcversion@}} - # For forge: "http://files.minecraftforge.net/maven/net/minecraftforge/forge/{{@mcversion@}}-{{@loaderversion@}}/forge-{{@mcversion@}}-{{@loaderversion@}}-installer.jar" - # For Fabric: "https://maven.fabricmc.net/net/fabricmc/fabric-installer/{{@loaderversion@}}/fabric-installer-{{@loaderversion@}}.jar" - installerUrl: https://maven.fabricmc.net/net/fabricmc/fabric-installer/{{@loaderversion@}}/fabric-installer-{{@loaderversion@}}.jar - - # Installer Arguments - # These Arguments have to be passed to the installer - # - # For Fabric: - # installerArguments: - # - "server" - # - "-downloadMinecraft" - # - "-snapshot" - # - "-mcversion" - # - "1.16.4" - # - "-loader" - # - "0.10.6+build.214" - # - # For Forge: - # installerArguments: - # - "--installServer" - installerArguments: - - "server" - - "-downloadMinecraft" - - "-snapshot" - - "-mcversion" - - "1.16.4" - - "-loader" - - "0.10.6+build.214" - - # Link to where the file where the modpack can be distributed - # This supports loading from local files as well for most pack types if there is file://{PathToFile} in the beginning - modpackUrl: https://media.forgecdn.net/files/3116/682/All+of+Fabric+3-2.4.4.zip - - # This is used to specify in which format the modpack is distributed, the server launcher has to handle each individually if their format differs - # current supported formats: - # - curseforge or curse - # - curseid - # - zip or zipfile - modpackFormat: curse - - # Settings which are specific to the format used, might not be needed in some casese - formatSpecific: - # optional paramenter used for curse to specify a whole project to ignore (mostly if it is client side only) - ignoreProject: - - 297038 #CraftPresence - - 308702 #Mod Menu - - 313219 #Health Overlay - - 317514 #Mouse Wheelie - - 325492 #Light Overlay - - 325625 #Roughly Enough Resources - - 335493 #Dynamic FPS - - 353641 #JumpOverFences - - 354047 #Ok Zoomer - - 355583 #Advancements Enlarger - - 360449 #Egg Tab - - 361550 #No Potion Offset - - 363126 #Boring Backgrounds - - 365521 #Pling - - 366240 #GameInfo - - 369122 #Better Enchanted Books - - 380393 #'Slight' Gui Modifications - - 388252 #Notes - - 398502 #Cherished Worlds - - 400929 #cAn i MiNe thIS bLOCk? - - 401978 #Disable Custom Worlds Advice - - 408366 #SlotLock - - 411705 #Damage Tilt - - # The base path where the server should be installed to, ~ for current path - baseInstallPath: ~ - - # a list of files which are supposed to be ignored when installing it from the client files - # this can either use regex or glob {default glob: https://docs.oracle.com/javase/8/docs/api/java/nio/file/FileSystem.html#getPathMatcher-java.lang.String-} - # specify with regex:.... or glob:.... if you want to force a matching type - ignoreFiles: - - mods/optifine*.jar - - resources/** - - # often a server needs more files, which are nearly useless on the client, such as tickprofiler - # This is a list of files, each ' - ' is a new file: - # url is the directlink to the file, destination is the path to where the file should be copied to - additionalFiles: - - url: https://media.forgecdn.net/files/3101/200/tellme-fabric-1.16.4-0.9.1-beta.1.jar - destination: mods/tellme-fabric-1.16.4-0.9.1-beta.1.jar - - url: https://media.forgecdn.net/files/3097/870/blocklogger-0.2.1.jar - destination: mods/blocklogger-0.2.1.jar -# - url: https://media.forgecdn.net/files/3072/467/BlueMap-1.2.0-snap-fabric-1.16.3.jar -# destination: mods/BlueMap-1.2.0-snap-fabric-1.16.3.jar - - url: https://media.forgecdn.net/files/3082/894/hypnos-0.1.1.jar - destination: mods/hypnos-0.1.1.jar - - url: https://media.forgecdn.net/files/3109/728/InvView-1.2.0-1.16.2%2B.jar - destination: mods/InvView-1.2.0-1.16.2%2B.jar - - url: https://media.forgecdn.net/files/3098/760/FabriKommander-1.0.0-MC1.16.3.jar - destination: mods/FabriKommander-1.0.0-MC1.16.3.jar -# - url: https://media.forgecdn.net/files/3104/633/flan-1.16.2-1.1.4.jar -# destination: mods/flan-1.16.2-1.1.4.jar - - url: https://ci.lucko.me/job/spark/lastSuccessfulBuild/artifact/spark-fabric/build/libs/spark-fabric.jar - destination: mods/spark-fabric.jar - - url: https://media.forgecdn.net/files/3115/560/disfabric-1.16.4-1.2.0.jar - destination: mods/disfabric-1.16.4-1.2.0.jar - - url: https://media.forgecdn.net/files/3009/753/shutupconsole-1.1.jar - destination: mods/shutupconsole-1.1.jar - - url: https://cdn.discordapp.com/attachments/750220836191076383/778900805402492958/advdebug-2.2.0.jar - destination: mods/advdebug-2.2.0.jar - - # For often there are config which the user wants to change, here is the place to put the local path to configs, jars or whatever - # You can copy files or folders: - # - localFiles: - - from: OLD_TO_DELETE/config/disfabric.json5 - to: config/disfabric.json5 - - from: OLD_TO_DELETE/config/charm.toml - to: config/charm.toml - - from: OLD_TO_DELETE/config/hypnos.json - to: config/hypnos.json - - from: OLD_TO_DELETE/config/shutupconsole.toml - to: config/shutupconsole.toml - - from: OLD_TO_DELETE/kubejs/server_scripts/custom.js - to: kubejs/server_scripts/custom.js - - from: OLD_TO_DELETE/config/indrev/cables.json - to: config/indrev/cables.json - - # This makes the program check the folder for whether it is supposed to use the - checkFolder: yes - - # Whether to install the Loader (Forge or Fabric) or not, should always be yes/true unless you only want to install the pack - installLoader: yes - - # Sponge bootstrapper jar URL - # Only needed if you have spongefix enabled - spongeBootstrapper: https://github.com/simon816/SpongeBootstrap/releases/download/v0.7.1/SpongeBootstrap-0.7.1.jar - - - - -# settings regarding the launching of the pack -launch: - # applies the launch wrapper to fix sponge for a few mods - spongefix: no - - # Use a RAMDisk for the world folder - # case-sensitive; use only lowercase `yes` or `no` - # NOTE: The server must have run once fully before switching to `yes`! - ramDisk: no - - # checks with the help of a few unrelated server whether the server is online - checkOffline: no - - # specifies the max amount of ram the server is supposed to launch with - maxRam: 5G - - # specifies the minimal amount of ram the server is supposed to launch with - minRam: 5G - - # specifies whether the server is supposed to auto restart after crash - autoRestart: yes - - # after a given amount of crashes in a given time the server will stop auto restarting - crashLimit: 10 - - # Time a crash should be still accounted for in the {crashLimit} - # 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: ~ - - # Start File Name, variables: {{@loaderversion@}} and {{@mcversion@}} - # This has to be the name the installer spits out - # For Forge 1.12-: "forge-{{@mcversion@}}-{{@loaderversion@}}-universal.jar" - # For Forge 1.13+: "forge-{{@mcversion@}}-{{@loaderversion@}}.jar" - # For Fabric: "fabric-server-launch.jar" - startFile: fabric-server-launch.jar - - # In case you have multiple javas installed you can add a absolute path to it here - # if the value is "", null, or ~ then 'java' from PATH is going to be used - # Example: "\"C:/Program Files/Java/jre1.8.0_201/bin/java.exe\"" - forcedJavaPath: ~ - - # 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 - # Keep in mind that some arguments only work on JRE 1.8 - javaArgs: - - "-XX:+UseG1GC" - - "-XX:+ParallelRefProcEnabled" - - "-XX:MaxGCPauseMillis=30" - - "-XX:+UnlockExperimentalVMOptions" - - "-XX:+DisableExplicitGC" - - "-XX:+AlwaysPreTouch" - - "-XX:G1NewSizePercent=30" - - "-XX:G1MaxNewSizePercent=40" - - "-XX:G1HeapRegionSize=8M" - - "-XX:G1ReservePercent=25" - - "-XX:G1HeapWastePercent=5" - - "-XX:G1MixedGCCountTarget=4" - - "-XX:InitiatingHeapOccupancyPercent=15" - - "-XX:G1MixedGCLiveThresholdPercent=90" - - "-XX:G1RSetUpdatingPauseTimePercent=5" - - "-XX:SurvivorRatio=32" - - "-XX:+PerfDisableSharedMem" - - "-XX:MaxTenuringThreshold=1" - - "-Dusing.aikars.flags=https://mcflags.emc.gs" - - "-Daikars.new.flags=true" - - "-XX:ConcGCThreads=3" - - "-XX:ParallelGCThreads=12" \ No newline at end of file +# Version of the specs, only for internal usage if this format should ever change drastically +_specver: 2 + +# modpack related settings, changes the supposed to change the visual appearance of the launcher +modpack: + # Name of the mod pack, that is displayed in various places where it fits + name: Example Modpack + + # Description + description: This is a awesome modpack about making examples. + + +# settings regarding the installation of the modpack +install: + # version of minecraft, needs the exact version + mcVersion: 1.16.5 + + # exact version of forge or fabric that is supposed to be used + # if this value is a null value so ( ~, null, or "" ) then the version from the mod pack is going to be used + loaderVersion: ~ + + # If a custom installer is supposed to used, specify the url here: (Otherwise put "", ~ or null here) + # supports variables: {{@loaderversion@}} and {{@mcversion@}} + # For forge: "http://files.minecraftforge.net/maven/net/minecraftforge/forge/{{@mcversion@}}-{{@loaderversion@}}/forge-{{@mcversion@}}-{{@loaderversion@}}-installer.jar" + # For Fabric: "https://maven.fabricmc.net/net/fabricmc/fabric-installer/{{@loaderversion@}}/fabric-installer-{{@loaderversion@}}.jar" + installerUrl: https://maven.minecraftforge.net/net/minecraftforge/forge/{{@mcversion@}}-{{@loaderversion@}}/forge-{{@mcversion@}}-{{@loaderversion@}}-installer.jar + + # Installer Arguments + # These Arguments have to be passed to the installer + # + # For Fabric: + # installerArguments: + # - "server" + # - "-downloadMinecraft" + # - "-snapshot" + # - "-mcversion" + # - "1.16.4" + # - "-loader" + # - "0.10.6+build.214" + # + # For Forge: + # installerArguments: + # - "--installServer" + installerArguments: + - "--installServer" + + # Link to where the file where the modpack can be distributed + # This supports loading from local files as well for most pack types if there is file://{PathToFile} in the beginning + modpackUrl: https://media.forgecdn.net/files/_/_/_.zip + + # This is used to specify in which format the modpack is distributed, the server launcher has to handle each individually if their format differs + # current supported formats: + # - curseforge or curse + # - curseid + # - zip or zipfile + modpackFormat: curse + + # Settings which are specific to the format used, might not be needed in some casese + formatSpecific: + # optional paramenter used for curse to specify a whole project to ignore (mostly if it is client side only) + ignoreProject: + - 263420 + - 317780 + - 232131 + - 231275 + - 367706 + - 261725 + - 243863 + - 305373 + - 325492 + - 296468 + - 308240 + - 362791 + - 291788 + - 326950 + - 237701 + - 391382 + - 358191 + - 271740 + - 428199 + - 431430 + + # The base path where the server should be installed to, ~ for current path + baseInstallPath: ~ + + # a list of files which are supposed to be ignored when installing it from the client files + # this can either use regex or glob {default glob: https://docs.oracle.com/javase/8/docs/api/java/nio/file/FileSystem.html#getPathMatcher-java.lang.String-} + # specify with regex:.... or glob:.... if you want to force a matching type + ignoreFiles: + - mods/Overrides.txt + - mods/optifine*.jar + - mods/optiforge*.jar + - resources/** + - packmenu/** + - openloader/resources/** + + # often a server needs more files, which are nearly useless on the client, such as tickprofiler + # This is a list of files, each ' - ' is a new file: + # url is the directlink to the file, destination is the path to where the file should be copied to + additionalFiles: +# - url: https://media.forgecdn.net/files/_/_/_.jar +# destination: mods/_.jar + + # For often there are config which the user wants to change, here is the place to put the local path to configs, jars or whatever + # You can copy files or folders: + # + localFiles: +# - from: OLD_TO_DELETE/config/_.toml +# to: config/_.toml + + + # This makes the program check the folder for whether it is supposed to use the + checkFolder: yes + + # Whether to install the Loader (Forge or Fabric) or not, should always be yes/true unless you only want to install the pack + installLoader: yes + + # Sponge bootstrapper jar URL + # Only needed if you have spongefix enabled + spongeBootstrapper: https://github.com/simon816/SpongeBootstrap/releases/download/v0.7.1/SpongeBootstrap-0.7.1.jar + + + + +# settings regarding the launching of the pack +launch: + # applies the launch wrapper to fix sponge for a few mods + spongefix: no + + # Use a RAMDisk for the world folder + # case-sensitive; use only lowercase `yes` or `no` + # NOTE: The server must have run once fully before switching to `yes`! + ramDisk: no + + # checks with the help of a few unrelated server whether the server is online + checkOffline: no + + # specifies the max amount of ram the server is supposed to launch with + maxRam: 5G + + # specifies the minimal amount of ram the server is supposed to launch with + minRam: 5G + + # specifies whether the server is supposed to auto restart after crash + autoRestart: yes + + # after a given amount of crashes in a given time the server will stop auto restarting + crashLimit: 10 + + # Time a crash should be still accounted for in the {crashLimit} + # 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: ~ + + # Start File Name, variables: {{@loaderversion@}} and {{@mcversion@}} + # This has to be the name the installer spits out + # For Forge 1.12-: "forge-{{@mcversion@}}-{{@loaderversion@}}-universal.jar" + # For Forge 1.13+: "forge-{{@mcversion@}}-{{@loaderversion@}}.jar" + # For Fabric: "fabric-server-launch.jar" + startFile: forge-{{@mcversion@}}-{{@loaderversion@}}.jar + + # In case you have multiple javas installed you can add a absolute path to it here + # if the value is "", null, or ~ then 'java' from PATH is going to be used + # Example: "\"C:/Program Files/Java/jre1.8.0_201/bin/java.exe\"" + forcedJavaPath: ~ + + # 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 + # Keep in mind that some arguments only work on JRE 1.8 + javaArgs: + - "-XX:+UseG1GC" + - "-XX:+ParallelRefProcEnabled" + - "-XX:MaxGCPauseMillis=200" + - "-XX:+UnlockExperimentalVMOptions" + - "-XX:+DisableExplicitGC" + - "-XX:+AlwaysPreTouch" + - "-XX:G1NewSizePercent=30" + - "-XX:G1MaxNewSizePercent=40" + - "-XX:G1HeapRegionSize=8M" + - "-XX:G1ReservePercent=20" + - "-XX:G1HeapWastePercent=5" + - "-XX:G1MixedGCCountTarget=4" + - "-XX:InitiatingHeapOccupancyPercent=15" + - "-XX:G1MixedGCLiveThresholdPercent=90" + - "-XX:G1RSetUpdatingPauseTimePercent=5" + - "-XX:SurvivorRatio=32" + - "-XX:+PerfDisableSharedMem" + - "-XX:MaxTenuringThreshold=1" + - "-Dusing.aikars.flags=https://mcflags.emc.gs" + - "-Daikars.new.flags=true" + - "-Dfml.readTimeout=90" # servertimeout + - "-Dfml.queryResult=confirm" # auto /fmlconfirm \ No newline at end of file diff --git a/src/main/resources/startserver.bat b/src/main/dist/startserver.bat similarity index 79% rename from src/main/resources/startserver.bat rename to src/main/dist/startserver.bat index 6830c37..9896b8c 100644 --- a/src/main/resources/startserver.bat +++ b/src/main/dist/startserver.bat @@ -13,7 +13,7 @@ CD "%~dp0" >nul 2>&1 REM Check if serverstarter JAR is already downloaded IF NOT EXIST "%cd%\serverstarter-@@serverstarter-libVersion@@.jar" ( ECHO serverstarter binary not found, downloading serverstarter... - %SYSTEMROOT%\SYSTEM32\bitsadmin.exe /rawreturn /nowrap /transfer starter /dynamic /download /priority foreground https://github.com/Yoosk/ServerStarter/releases/download/v@@serverstarter-libVersion@@/serverstarter-@@serverstarter-libVersion@@.jar "%cd%\serverstarter-@@serverstarter-libVersion@@.jar" + %SYSTEMROOT%\SYSTEM32\bitsadmin.exe /rawreturn /nowrap /transfer starter /dynamic /download /priority foreground https://github.com/AllTheMods/alltheservers/releases/download/v@@serverstarter-libVersion@@/serverstarter-@@serverstarter-libVersion@@.jar "%cd%\serverstarter-@@serverstarter-libVersion@@.jar" GOTO MAIN ) ELSE ( GOTO MAIN diff --git a/src/main/dist/startserver.sh b/src/main/dist/startserver.sh new file mode 100644 index 0000000..fcc767f --- /dev/null +++ b/src/main/dist/startserver.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -euo pipefail + +# check for serverstarter jar +if [[ -f serverstarter-@@serverstarter-libVersion@@.jar ]]; then + echo "Skipping download. Using existing serverstarter-@@serverstarter-libVersion@@.jar" + java -jar serverstarter-@@serverstarter-libVersion@@.jar + exit 0 +else + # download missing serverstarter jar + URL="https://github.com/AllTheMods/alltheservers/releases/download/v@@serverstarter-libVersion@@/serverstarter-@@serverstarter-libVersion@@.jar" + + if command -v wget &> /dev/null; then + echo "DEBUG: (wget) Downloading ${URL}" + wget -O serverstarter-@@serverstarter-libVersion@@.jar "${URL}" + elif command -v curl &> /dev/null; then + echo "DEBUG: (curl) Downloading ${URL}" + curl -L -o serverstarter-@@serverstarter-libVersion@@.jar "${URL}" + else + echo "Neither wget or curl were found on your system. Please install one and try again" + exit 1 + fi +fi + +java -jar serverstarter-@@serverstarter-libVersion@@.jar \ No newline at end of file diff --git a/src/main/kotlin/atm/bloodworkxgaming/serverstarter/InternetManager.kt b/src/main/kotlin/atm/bloodworkxgaming/serverstarter/InternetManager.kt index 80576b8..dd83b53 100644 --- a/src/main/kotlin/atm/bloodworkxgaming/serverstarter/InternetManager.kt +++ b/src/main/kotlin/atm/bloodworkxgaming/serverstarter/InternetManager.kt @@ -3,7 +3,8 @@ package atm.bloodworkxgaming.serverstarter import atm.bloodworkxgaming.serverstarter.ServerStarter.Companion.LOGGER import okhttp3.OkHttpClient import okhttp3.Request -import okio.Okio +import okio.buffer +import okio.sink import java.io.File import java.io.IOException import java.net.InetAddress @@ -13,7 +14,7 @@ object InternetManager { val httpClient = OkHttpClient.Builder() .connectTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) - .build()!! + .build() private val urls = listOf("8.8.8.8", "1.0.0.1") @@ -49,13 +50,13 @@ object InternetManager { .build() val res = httpClient.newCall(req).execute() - val source = res?.body()?.source() + val source = res.body?.source() source ?: throw IOException("Message body or source from $url was null") source.use { dest.parentFile?.mkdirs() - Okio.buffer(Okio.sink(dest)).use { + dest.sink().buffer().use { it.writeAll(source) } } diff --git a/src/main/kotlin/atm/bloodworkxgaming/serverstarter/logger/PrimitiveLogger.kt b/src/main/kotlin/atm/bloodworkxgaming/serverstarter/logger/PrimitiveLogger.kt index 54408f7..236071f 100644 --- a/src/main/kotlin/atm/bloodworkxgaming/serverstarter/logger/PrimitiveLogger.kt +++ b/src/main/kotlin/atm/bloodworkxgaming/serverstarter/logger/PrimitiveLogger.kt @@ -1,6 +1,7 @@ package atm.bloodworkxgaming.serverstarter.logger -import okio.Okio +import okio.buffer +import okio.sink import org.fusesource.jansi.Ansi import java.io.File import java.io.IOException @@ -12,7 +13,7 @@ import java.time.format.DateTimeFormatter class PrimitiveLogger(outputFile: File) { private val pattern = "\\x1b\\[[0-9;]*m".toRegex() private val dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss") - private val bufferedSink = Okio.buffer(Okio.sink(outputFile)) + private val bufferedSink = outputFile.sink().buffer() init { if (outputFile.exists()) { diff --git a/src/main/kotlin/atm/bloodworkxgaming/serverstarter/packtype/curse/CursePackType.kt b/src/main/kotlin/atm/bloodworkxgaming/serverstarter/packtype/curse/CursePackType.kt index e1d8355..a048e19 100644 --- a/src/main/kotlin/atm/bloodworkxgaming/serverstarter/packtype/curse/CursePackType.kt +++ b/src/main/kotlin/atm/bloodworkxgaming/serverstarter/packtype/curse/CursePackType.kt @@ -185,8 +185,7 @@ open class CursePackType(private val configFile: ConfigFile) : AbstractZipbasedP return@forEach } - val url = (configFile.install.getFormatSpecificSettingOrDefault("cursemeta", "https://cursemeta.dries007.net") - + "/" + mod.projectID + "/" + mod.fileID + ".json") + val url = "https://addons-ecs.forgesvc.net/api/v2/addon/${mod.projectID}/file/${mod.fileID}" LOGGER.info("Download url is: $url", true) try { @@ -200,14 +199,14 @@ open class CursePackType(private val configFile: ConfigFile) : AbstractZipbasedP if (!res.isSuccessful) throw IOException("Request to $url was not successful.") - val body = res.body() ?: throw IOException("Request to $url returned a null body.") + val body = res.body ?: throw IOException("Request to $url returned a null body.") val jsonRes = JsonParser().parse(body.string()).asJsonObject LOGGER.info("Response from manifest query: $jsonRes", true) urls.add(jsonRes .asJsonObject - .getAsJsonPrimitive("DownloadURL").asString) + .getAsJsonPrimitive("downloadUrl").asString) } catch (e: IOException) { LOGGER.error("Error while trying to get URL from cursemeta for mod $mod", e) } @@ -219,73 +218,6 @@ open class CursePackType(private val configFile: ConfigFile) : AbstractZipbasedP } - //region >>>>>>> Stuff for when cursemeta works again: - /* - private void downloadMods(List mods) { - Set ignoreSet = new HashSet<>(); - List ignoreListTemp = configFile.install.getFormatSpecificSettingOrDefault("ignoreProject", null); - - if (ignoreListTemp != null) - for (Object o : ignoreListTemp) { - if (o instanceof String) - ignoreSet.add((String) o); - - if (o instanceof Integer) - ignoreSet.add(String.valueOf(o)); - } - - // constructs the body - JsonObject request = new JsonObject(); - JsonArray array = new JsonArray(); - for (ModEntryRaw mod : mods) { - if (!ignoreSet.isEmpty() && ignoreSet.contains(mod.projectID)) { - LOGGER.info("Skipping mod with projectID: " + mod.projectID); - continue; - } - - JsonObject objMod = new JsonObject(); - objMod.addProperty("AddOnID", mod.projectID); - objMod.addProperty("FileID", mod.fileID); - array.add(objMod); - } - request.add("addOnFileKeys", array); - - LOGGER.info("Requesting Download links from cursemeta."); - LOGGER.info("About to make a request to cursemeta with body: " + request.toString(), true); - - try { - HttpResponse res = Unirest - .post(configFile.install.getFormatSpecificSettingOrDefault("cursemeta", "https://cursemeta.dries007.net") - + "/api/v2/direct/GetAddOnFiles") - .header("User-Agent", "All the mods server installer.") - .header("Content-Type", "application/json") - .body(request.toString()) - .asJson(); - - if (res.getStatus() != 200) - throw new UnirestException("Response was not OK"); - - // Gets the download links for the mods - List modsToDownload = new ArrayList<>(); - JsonArray jsonRes = new JsonParser().parse(res.getBody().toString()).getAsJsonArray(); - for (JsonElement modEntry : jsonRes) { - modsToDownload.add(modEntry - .getAsJsonObject() - .getAsJsonArray("Value").get(0) - .getAsJsonObject() - .getAsJsonPrimitive("DownloadURL").getAsString()); - } - - LOGGER.info("Response from manifest query: " + jsonRes, true); - LOGGER.info("Mods to download: " + modsToDownload, true); - processMods(modsToDownload); - - } catch (UnirestException e) { - e.printStackTrace(); - } - }*/ - //endregion - /** * Downloads all mods, with a second fallback if failed * This is done in parallel for better performance diff --git a/src/main/resources/startserver.sh b/src/main/resources/startserver.sh deleted file mode 100644 index 21ac0de..0000000 --- a/src/main/resources/startserver.sh +++ /dev/null @@ -1,40 +0,0 @@ -DO_RAMDISK=0 -if [[ $(cat server-setup-config.yaml | grep 'ramDisk:' | awk 'BEGIN {FS=":"}{print $2}') =~ "yes" ]]; then - SAVE_DIR=$(cat server.properties | grep 'level-name' | awk 'BEGIN {FS="="}{print $2}') - mv $SAVE_DIR "${SAVE_DIR}_backup" - mkdir $SAVE_DIR - sudo mount -t tmpfs -o size=2G tmpfs $SAVE_DIR - DO_RAMDISK=1 -fi - if [ -f serverstarter-@@serverstarter-libVersion@@.jar ]; then - echo "Skipping download. Using existing serverstarter-@@serverstarter-libVersion@@.jar" - java -jar serverstarter-@@serverstarter-libVersion@@.jar - if [[ $DO_RAMDISK -eq 1 ]]; then - sudo umount $SAVE_DIR - rm -rf $SAVE_DIR - mv "${SAVE_DIR}_backup" $SAVE_DIR - fi - exit 0 - else - export URL="https://github.com/Yoosk/ServerStarter/releases/download/v@@serverstarter-libVersion@@/serverstarter-@@serverstarter-libVersion@@.jar" - fi - echo $URL - which wget >> /dev/null - if [ $? -eq 0 ]; then - echo "DEBUG: (wget) Downloading ${URL}" - wget -O serverstarter-@@serverstarter-libVersion@@.jar "${URL}" - else - which curl >> /dev/null - if [ $? -eq 0 ]; then - echo "DEBUG: (curl) Downloading ${URL}" - curl -o serverstarter-@@serverstarter-libVersion@@.jar "${URL}" - else - echo "Neither wget or curl were found on your system. Please install one and try again" - fi - fi -java -jar serverstarter-@@serverstarter-libVersion@@.jar -if [[ $DO_RAMDISK -eq 1 ]]; then - sudo umount $SAVE_DIR - rm -rf $SAVE_DIR - mv "${SAVE_DIR}_backup" $SAVE_DIR -fi diff --git a/src/test/java/TestOKHttp.kt b/src/test/java/TestOKHttp.kt index bc0aa8f..ed2d3ef 100644 --- a/src/test/java/TestOKHttp.kt +++ b/src/test/java/TestOKHttp.kt @@ -1,7 +1,7 @@ import okhttp3.OkHttpClient import okhttp3.Request -import okio.Okio -import org.junit.Test +import okio.buffer +import okio.sink import java.io.File class TestOKHttp { @@ -36,9 +36,9 @@ class TestOKHttp { val res = client.newCall(req).execute() val file = File("D:\\Users\\jonas\\Documents\\GitHub\\serverstarter\\test/Pam's HarvestCraft 1.12.2u.jar") println("file = ${file.absolutePath}") - val sink = Okio.buffer(Okio.sink(file)) + val sink = file.sink().buffer() - val source = res.body()?.source() ?: return + val source = res.body?.source() ?: return sink.writeAll(source) sink.close()