diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml new file mode 100644 index 0000000..a366adf --- /dev/null +++ b/.github/workflows/gradle-publish.yml @@ -0,0 +1,105 @@ +name: Gradle Package + +on: + push: + branches: [master] + tags: + - v* + pull_request: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Get Version Name + id: version_name + run: | + echo version=${GITHUB_REF#refs/tags/v} >> $GITHUB_OUTPUT + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 + - name: Build with Gradle + uses: gradle/gradle-build-action@v2.9.0 + with: + arguments: build + env: + VERSION: ${{ steps.version_name.outputs.version }} + + - name: Generate Release Hash + id: hash + run: echo "$(git rev-parse --short HEAD)" > hash.env + + - name: Upload Build Artifact + uses: actions/upload-artifact@v3 + with: + name: jar + path: build/libs/kettingcommon-*.jar + + - name: Upload Hash + uses: actions/upload-artifact@v3 + with: + name: hash + path: hash.env + + + release: + needs: build + runs-on: ubuntu-latest + if: github.ref_type == 'tag' + permissions: + contents: write + packages: write + + steps: + - uses: actions/checkout@v3 + - name: Download Build Artifact + uses: actions/download-artifact@v3 + with: + name: jar + path: tmp + + - name: Download Hash + uses: actions/download-artifact@v3 + with: + name: hash + path: tmp + - name: Get Version Name + id: version_name + run: | + echo version=${GITHUB_REF#refs/tags/v} >> $GITHUB_OUTPUT + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 + - name: Build with Gradle + uses: gradle/gradle-build-action@v2.9.0 + with: + arguments: publish + env: + KETTINGUSERNAME: ${{ secrets.KETTINGUSERNAME }} + KETTINGPASSWORD: ${{ secrets.KETTINGPASSWORD }} + VERSION: ${{ steps.version_name.outputs.version }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Create Release + run: | + gh release create "v$VERSION" tmp/kettingcommon-*.jar \ + --repo="$GITHUB_REPOSITORY" \ + --title="${GITHUB_REPOSITORY#*/} v$VERSION" \ + --generate-notes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + VERSION: ${{ steps.version_name.outputs.version }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cd3d2f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +.gradle/ +build/ \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..4ded50b --- /dev/null +++ b/build.gradle @@ -0,0 +1,73 @@ +import net.minecraftforge.gradleutils.PomUtils + +plugins { + id 'java-library' + id 'maven-publish' + id 'net.minecraftforge.gradleutils' version '2.3.5' +} + +repositories { + mavenCentral() + maven { url = 'https://nexus.c0d3m4513r.com/repository/Ketting/' } + maven { url = 'https://nexus.c0d3m4513r.com/repository/Forge/' } + mavenLocal() +} + +dependencies { + compileOnly 'org.jetbrains:annotations:23.0.0' + api(libs.bundles.asm) // Needed by all the black magic +} + +java { + toolchain.languageVersion = JavaLanguageVersion.of(17) + withSourcesJar() +} + +tasks.withType(JavaCompile) { + options.compilerArgs << '-Xlint:-unchecked' +} + +group = 'org.kettingpowered' +version = System.getenv("VERSION") ?: 'dev-ver' + +publishing { + publications.register('mavenJava', MavenPublication).configure { + from components.java + artifactId = 'kettingcommon' + pom { + name = project.name + description = 'Version specific things needed in kettinglauncher and the server itself' + url = "https://github.com/kettingpowered/kettingcommon" + developers { + developer { + id = "justred23" + name = "JustRed23" + } + developer { + id = "c0d3m4513r" + name = "C0D3 M4513R" + } + } + PomUtils.setGitHubDetails(pom, 'kettingpowered', 'kettingcommon') + } + } + + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/kettingpowered/kettingcommon") + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + maven { + name = 'kettingRepo' + credentials { + username = System.getenv("KETTINGUSERNAME") + password = System.getenv("KETTINGPASSWORD") + } + url = "https://nexus.c0d3m4513r.com/repository/Ketting/" + } + } +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7f93135 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..01f330a --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,8 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionSha256Sum=f2b9ed0faf8472cbe469255ae6c86eddb77076c75191741b4a462f33128dd419 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..fcb6fca --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..9a4085e --- /dev/null +++ b/settings.gradle @@ -0,0 +1,15 @@ +dependencyResolutionManagement{ + versionCatalogs { + libs { + version('asm', '9.6') + library('asm', 'org.ow2.asm', 'asm' ).versionRef('asm') + library('asm-tree', 'org.ow2.asm', 'asm-tree' ).versionRef('asm') + library('asm-util', 'org.ow2.asm', 'asm-util' ).versionRef('asm') + library('asm-commons', 'org.ow2.asm', 'asm-commons' ).versionRef('asm') + library('asm-analysis', 'org.ow2.asm', 'asm-analysis').versionRef('asm') + bundle('asm', ['asm', 'asm-tree', 'asm-util', 'asm-commons', 'asm-analysis']) + } + } +} + +rootProject.name = 'kettingcommon' \ No newline at end of file diff --git a/src/main/java/org/kettingpowered/ketting/internal/KettingConstants.java b/src/main/java/org/kettingpowered/ketting/internal/KettingConstants.java new file mode 100644 index 0000000..5a2bd42 --- /dev/null +++ b/src/main/java/org/kettingpowered/ketting/internal/KettingConstants.java @@ -0,0 +1,52 @@ +package org.kettingpowered.ketting.internal; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.jar.JarFile; + +public class KettingConstants { + public static final String NAME = "Ketting"; + public static final String BRAND = "KettingPowered"; + public static final String SITE_LINK = "https://github.com/kettingpowered/"; + public static final String VERSION; + public static final String MINECRAFT_VERSION; + public static final String BUKKIT_PACKAGE_VERSION; + public static final String BUKKIT_VERSION; + public static final String FORGE_VERSION; + public static final String KETTING_VERSION; + public static final String MCP_VERSION; + public static final String INSTALLER_LIBRARIES_FOLDER = "libraries"; + public static final String KETTING_GROUP = "org.kettingpowered"; + public static final String KETTINGSERVER_GROUP = KETTING_GROUP + ".server"; + static{ + HashMap, List, MajorMinorPatchVersion>>> map = MajorMinorPatchVersion.parseKettingServerVersionList(KettingFiles.getKettingServerVersions().stream()); + if (map.isEmpty()) throw new IllegalStateException("No Ketting Server Version found."); + else if (map.size() > 1) throw new IllegalStateException("Multiple Ketting Server Versions for multiple Minecraft Versions found."); + final Map.Entry, List, MajorMinorPatchVersion>>> entry = map.entrySet().iterator().next(); + MINECRAFT_VERSION = entry.getKey().toString(); + if (entry.getValue().isEmpty()) throw new IllegalStateException("Found a Minecraft Version, but no Ketting Server versions for that version. This should not happen."); + else if (entry.getValue().size() > 1) throw new IllegalStateException("Found multiple Ketting Server versions."); + Tuple, MajorMinorPatchVersion> version = entry.getValue().get(0); + FORGE_VERSION = version.t1().toString(); + KETTING_VERSION = version.t2().toString(); + VERSION = MINECRAFT_VERSION + "-" + KETTING_VERSION; + + final String[] mcv = MINECRAFT_VERSION.split("\\."); + mcv[mcv.length-1] = "R"+mcv[mcv.length-1]; + BUKKIT_PACKAGE_VERSION = String.join("_", mcv); + BUKKIT_VERSION = MINECRAFT_VERSION + "-R0.1-SNAPSHOT"; + + final String + MC_FORGE_KETTING = MINECRAFT_VERSION + "-" + FORGE_VERSION + "-" + KETTING_VERSION, + FORGE_UNIVERSAL_NAME = "forge-" + MC_FORGE_KETTING + "-universal.jar"; + try (final JarFile jarFile = new JarFile(new File(KettingFiles.KETTINGSERVER_FORGE_DIR, MC_FORGE_KETTING + "/" + FORGE_UNIVERSAL_NAME))){ + final String fullVersion = (String) jarFile.getManifest().getEntries().get("org/kettingpowered/ketting/").getValue("Implementation-Version"); + MCP_VERSION = fullVersion.substring(fullVersion.lastIndexOf('-')+1); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/org/kettingpowered/ketting/internal/KettingFileVersioned.java b/src/main/java/org/kettingpowered/ketting/internal/KettingFileVersioned.java new file mode 100644 index 0000000..00c8267 --- /dev/null +++ b/src/main/java/org/kettingpowered/ketting/internal/KettingFileVersioned.java @@ -0,0 +1,50 @@ +package org.kettingpowered.ketting.internal; + +import java.io.File; + +public class KettingFileVersioned { + private static final String + MC = KettingConstants.MINECRAFT_VERSION, + FORGE = KettingConstants.FORGE_VERSION, + MCP = KettingConstants.MCP_VERSION, + MC_FORGE = MC + "-" + FORGE, + MC_FORGE_KETTING = MC + "-" + FORGE + "-" + KettingConstants.KETTING_VERSION, + MC_MCP = MC + "-" + MCP; + public static final File MCP_BASE_DIR = new File(KettingFiles.MCP_BASE_DIR, MC_MCP + "/"); + public static final File NMS_BASE_DIR = new File(KettingFiles.NMS_BASE_DIR, MC + "/"); + public static final File NMS_PATCHES_DIR = new File(KettingFiles.NMS_BASE_DIR, MC_MCP + "/"); + + public static final String + KETTINGSERVER_PATH = "org/kettingpowered/server", + FMLCORE_NAME = "fmlcore-" + MC_FORGE_KETTING + ".jar", + FMLLOADER_NAME = "fmlloader-" + MC_FORGE_KETTING + ".jar", + JAVAFMLLANGUAGE_NAME = "javafmllanguage-" + MC_FORGE_KETTING + ".jar", + LOWCODELANGUAGE_NAME = "lowcodelanguage-" + MC_FORGE_KETTING + ".jar", + MCLANGUAGE_NAME = "mclanguage-" + MC_FORGE_KETTING + ".jar"; + + public static final File + FMLCORE = new File(KettingFiles.KETTINGSERVER_BASE_DIR, "fmlcore/" + MC_FORGE_KETTING + "/" + FMLCORE_NAME), + FMLLOADER = new File(KettingFiles.KETTINGSERVER_BASE_DIR, "fmlloader/" + MC_FORGE_KETTING + "/" + FMLLOADER_NAME), + JAVAFMLLANGUAGE = new File(KettingFiles.KETTINGSERVER_BASE_DIR, "javafmllanguage/" + MC_FORGE_KETTING + "/" + JAVAFMLLANGUAGE_NAME), + LOWCODELANGUAGE = new File(KettingFiles.KETTINGSERVER_BASE_DIR, "lowcodelanguage/" + MC_FORGE_KETTING + "/" + LOWCODELANGUAGE_NAME), + MCLANGUAGE = new File(KettingFiles.KETTINGSERVER_BASE_DIR, "mclanguage/" + MC_FORGE_KETTING + "/" + MCLANGUAGE_NAME); + + public static final String + FORGE_UNIVERSAL_NAME = "forge-" + MC_FORGE_KETTING + "-universal.jar"; + + public static final File + FORGE_UNIVERSAL_JAR = new File(KettingFiles.KETTINGSERVER_FORGE_DIR, MC_FORGE_KETTING + "/" + FORGE_UNIVERSAL_NAME), + FORGE_PATCHED_JAR = new File(KettingFiles.KETTINGSERVER_FORGE_DIR, MC_FORGE_KETTING + "/forge-" + MC_FORGE_KETTING + "-server.jar"), + FORGE_KETTING_LIBS = new File(KettingFiles.KETTINGSERVER_FORGE_DIR, MC_FORGE_KETTING + "/forge-" + MC_FORGE_KETTING + "-ketting-libraries.txt"), + FORGE_INSTALL_JSON = new File(KettingFiles.KETTINGSERVER_FORGE_DIR, MC_FORGE_KETTING + "/forge-" + MC_FORGE_KETTING + "-installscript.json"), + MCP_ZIP = new File(MCP_BASE_DIR, "mcp_config-" + MC_MCP + ".zip"), + SERVER_JAR = new File(NMS_BASE_DIR, "server-" + MC + ".jar"), + SERVER_UNPACKED = new File(NMS_PATCHES_DIR, "server-" + MC_MCP + "-unpacked.jar"), + SERVER_SLIM = new File(NMS_PATCHES_DIR, "server-" + MC_MCP + "-slim.jar"), + SERVER_EXTRA = new File(NMS_PATCHES_DIR, "server-" + MC_MCP + "-extra.jar"), + SERVER_SRG = new File(NMS_PATCHES_DIR, "server-" + MC_MCP + "-srg.jar"), + MCP_MAPPINGS = new File(MCP_BASE_DIR, "mappings.txt"), + MOJANG_MAPPINGS = new File(NMS_PATCHES_DIR, "mappings.txt"), + MERGED_MAPPINGS = new File(MCP_BASE_DIR, "mappings-merged.txt"); + +} diff --git a/src/main/java/org/kettingpowered/ketting/internal/KettingFiles.java b/src/main/java/org/kettingpowered/ketting/internal/KettingFiles.java new file mode 100644 index 0000000..f3421d7 --- /dev/null +++ b/src/main/java/org/kettingpowered/ketting/internal/KettingFiles.java @@ -0,0 +1,55 @@ +package org.kettingpowered.ketting.internal; + +import java.io.File; +import java.net.URISyntaxException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public class KettingFiles { + public static final String DATA_DIR = "data/"; + public static final File MAIN_FOLDER_FILE; + + static { + String path = KettingFiles.class.getProtectionDomain().getCodeSource().getLocation().getFile(); + int indexJarSep = path.indexOf('!'); + if (indexJarSep>=0) path = path.substring(0, indexJarSep); + final String fileProto = "file://"; + int indexFile = path.indexOf(fileProto); + if (indexFile>=0) path = path.substring(fileProto.length()); + path = URLDecoder.decode(path, StandardCharsets.UTF_8); + MAIN_FOLDER_FILE = new File(path) + .getParentFile()//away with the kettingcore-version.jar + .getParentFile()//away with version folder + .getParentFile()//away with kettingcore + .getParentFile()//away with kettingpowered + .getParentFile()//away with org + .getParentFile()//away with libraries + .getAbsoluteFile(); + } + public static final File LIBRARIES_DIR = new File(MAIN_FOLDER_FILE, KettingConstants.INSTALLER_LIBRARIES_FOLDER).getAbsoluteFile(); + public static final String LIBRARIES_PATH = LIBRARIES_DIR.getAbsolutePath() + "/"; + public static final String LOGS_PATH = new File(MAIN_FOLDER_FILE, "logs").getAbsolutePath() + "/"; + public static final File FORGE_BASE_DIR = new File(LIBRARIES_PATH, "net/minecraftforge/"); + public static final File KETTINGSERVER_BASE_DIR = new File(LIBRARIES_PATH, "org/kettingpowered/server"); + public static final File KETTINGSERVER_FORGE_DIR = new File(KettingFiles.KETTINGSERVER_BASE_DIR, "forge"); + public static final File INSTALL_DIR = new File(KETTINGSERVER_BASE_DIR, "install/"); + public static final File MCP_BASE_DIR = new File(KettingFiles.LIBRARIES_PATH, "de/oceanlabs/mcp_config/"); + public static final File NMS_BASE_DIR = new File(KettingFiles.LIBRARIES_PATH, "net/minecraft/server/"); + + public static final File + SERVER_LZMA = new File(INSTALL_DIR, "server.lzma"), + STORED_HASHES = new File(INSTALL_DIR, "hashes.txt"), + PATCHER_LOGS = new File(LOGS_PATH, "install.txt"); + + public static List getKettingServerVersions(){ + final File[] kettingVersions = KettingFiles.KETTINGSERVER_FORGE_DIR.listFiles(File::isDirectory); + if (kettingVersions == null) return Collections.emptyList(); + return Arrays.stream(kettingVersions) + .map(File::getName) + .distinct() + .toList(); + } +} diff --git a/src/main/java/org/kettingpowered/ketting/internal/MajorMinorPatchVersion.java b/src/main/java/org/kettingpowered/ketting/internal/MajorMinorPatchVersion.java new file mode 100644 index 0000000..52bf643 --- /dev/null +++ b/src/main/java/org/kettingpowered/ketting/internal/MajorMinorPatchVersion.java @@ -0,0 +1,73 @@ +package org.kettingpowered.ketting.internal; + +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +/** + * @author C0D3 M4513R + * @param major major version + * @param minor minor version + * @param patch patch version + * @param version type + */ +public record MajorMinorPatchVersion>(T major, T minor, T patch) implements Comparable> { + public static MajorMinorPatchVersion parse(String version){ + return parse(version, "\\."); + } + public static MajorMinorPatchVersion parse(String version, String seperator){ + String major, minor, patch; + String[] parts = version.split(seperator); + if (parts.length>=1) major=parts[0]; + else throw new IllegalStateException("Split returned an empty array"); + if (parts.length>=2) minor = parts[1]; + else minor="0"; + if (parts.length>=3) patch = parts[2]; + else patch="0"; + return new MajorMinorPatchVersion<>(major, minor, patch); + } + + @Override + public String toString(){ + return String.format("%s.%s.%s", major, minor, patch); + } + + @Override + public int compareTo(@NotNull MajorMinorPatchVersion o) { + int mjc = major.compareTo(o.major); + if (mjc!=0) return mjc; + int mnc = minor.compareTo(o.minor); + if (mnc!=0) return mnc; + return patch.compareTo(o.patch); + } + + public static HashMap, List, MajorMinorPatchVersion>>> parseKettingServerVersionList(Stream versions){ + HashMap, List, MajorMinorPatchVersion>>> map = versions.map(version -> MajorMinorPatchVersion.parse(version, "-")) + .map(version -> new MajorMinorPatchVersion<>( + MajorMinorPatchVersion.parse(version.major()),//mc version + MajorMinorPatchVersion.parse(version.minor()),//forge version + MajorMinorPatchVersion.parse(version.patch())//Ketting version + )).map(version->new MajorMinorPatchVersion<>( + new MajorMinorPatchVersion<>(Integer.parseInt(version.major().major()), Integer.parseInt(version.major().minor()), Integer.parseInt(version.major().patch())), + new MajorMinorPatchVersion<>(Integer.parseInt(version.minor().major()), Integer.parseInt(version.minor().minor()), Integer.parseInt(version.minor().patch())), + new MajorMinorPatchVersion<>(Integer.parseInt(version.patch().major()), Integer.parseInt(version.patch().minor()), Integer.parseInt(version.patch().patch())) + )) + .reduce(new HashMap<>(), (hm, mmp)->{ + hm.computeIfAbsent(mmp.major(), (key)->new ArrayList<>()).add(new Tuple<>(mmp.minor(), mmp.patch())); + return hm; + }, (hm1, hm2)->{ + for(final Map.Entry, List, MajorMinorPatchVersion>>> entry : hm2.entrySet()){ + hm1.computeIfAbsent(entry.getKey(), (key)-> new ArrayList<>()).addAll(entry.getValue()); + } + hm2.clear(); + return hm1; + }); + map.values().forEach(list->list.sort(Comparator.comparing((Tuple, MajorMinorPatchVersion> t) -> t.t1()).thenComparing(Tuple::t2).reversed())); + return map; + } +} \ No newline at end of file diff --git a/src/main/java/org/kettingpowered/ketting/internal/Tuple.java b/src/main/java/org/kettingpowered/ketting/internal/Tuple.java new file mode 100644 index 0000000..4bcca39 --- /dev/null +++ b/src/main/java/org/kettingpowered/ketting/internal/Tuple.java @@ -0,0 +1,3 @@ +package org.kettingpowered.ketting.internal; + +public record Tuple (T1 t1, T2 t2) { } diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 0000000..59499bc --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 +