From 2a10e00b6b4951834f42eb2fee555dbbe1a4d6dd Mon Sep 17 00:00:00 2001 From: Sylfare <12037446+Sylfare@users.noreply.github.com> Date: Mon, 8 Jul 2024 21:37:55 +0200 Subject: [PATCH 1/2] fix: Compile vane-velocity with Java 17 --- vane-proxy-core/build.gradle.kts | 13 ++++ .../oddlama/vane/proxycore/Maintenance.java | 2 +- .../commands/ProxyMaintenanceCommand.java | 2 +- .../proxycore/listeners/PreLoginEvent.java | 2 +- .../oddlama/vane/proxycore/util/IOUtil.java | 30 +++++++++ .../oddlama/vane/proxycore/util/Resolve.java | 37 ++++++++++ .../oddlama/vane/proxycore/util/TimeUtil.java | 67 +++++++++++++++++++ .../oddlama/vane/proxycore/util/Version.java | 7 ++ vane-velocity/build.gradle.kts | 19 ++---- .../java/org/oddlama/velocity/Velocity.java | 2 +- 10 files changed, 164 insertions(+), 17 deletions(-) create mode 100644 vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/IOUtil.java create mode 100644 vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/Resolve.java create mode 100644 vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/TimeUtil.java create mode 100644 vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/Version.java diff --git a/vane-proxy-core/build.gradle.kts b/vane-proxy-core/build.gradle.kts index cce7ebde1..66c9e5d3e 100644 --- a/vane-proxy-core/build.gradle.kts +++ b/vane-proxy-core/build.gradle.kts @@ -1,11 +1,23 @@ plugins { id("io.github.goooler.shadow") version "8.1.7" + id("net.kyori.blossom") version "1.2.0" +} + +blossom { + replaceToken("\$VERSION", project.version) } dependencies { implementation(group = "com.electronwill.night-config", name = "toml", version = "3.6.4") implementation(group = "org.slf4j", name = "slf4j-api", version = "1.7.30") implementation(rootProject.project(":vane-core")) + compileOnly(group = "org.json", name = "json", version = "20200518") +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } } tasks { @@ -15,5 +27,6 @@ tasks { } relocate("com.electronwill.night-config", "org.oddlama.vane.vane_velocity.external.night-config") + relocate("org.json", "org.oddlama.vane.external.json") } } diff --git a/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/Maintenance.java b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/Maintenance.java index 9a20b33ce..6b4d165b9 100644 --- a/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/Maintenance.java +++ b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/Maintenance.java @@ -7,7 +7,7 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import static org.oddlama.vane.util.TimeUtil.format_time; +import static org.oddlama.vane.proxycore.util.TimeUtil.format_time; public class Maintenance { diff --git a/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/commands/ProxyMaintenanceCommand.java b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/commands/ProxyMaintenanceCommand.java index ea7e59ae0..fc7d68b43 100644 --- a/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/commands/ProxyMaintenanceCommand.java +++ b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/commands/ProxyMaintenanceCommand.java @@ -4,7 +4,7 @@ import org.oddlama.vane.proxycore.ProxyPlayer; import org.oddlama.vane.proxycore.VaneProxyPlugin; -import static org.oddlama.vane.util.TimeUtil.parse_time; +import static org.oddlama.vane.proxycore.util.TimeUtil.parse_time; public class ProxyMaintenanceCommand extends ProxyCommand { diff --git a/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/listeners/PreLoginEvent.java b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/listeners/PreLoginEvent.java index 1bcf06708..ba9386998 100644 --- a/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/listeners/PreLoginEvent.java +++ b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/listeners/PreLoginEvent.java @@ -13,7 +13,7 @@ import java.util.logging.Level; import static org.oddlama.vane.proxycore.Util.add_uuid; -import static org.oddlama.vane.util.Resolve.resolve_uuid; +import static org.oddlama.vane.proxycore.util.Resolve.resolve_uuid; public abstract class PreLoginEvent implements ProxyEvent, ProxyCancellableEvent { diff --git a/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/IOUtil.java b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/IOUtil.java new file mode 100644 index 000000000..808ef1c72 --- /dev/null +++ b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/IOUtil.java @@ -0,0 +1,30 @@ +package org.oddlama.vane.proxycore.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; + +import org.json.JSONException; +import org.json.JSONObject; + +public class IOUtil { + private static String read_all(Reader rd) throws IOException { + final var sb = new StringBuilder(); + int cp; + while ((cp = rd.read()) != -1) { + sb.append((char) cp); + } + return sb.toString(); + } + + public static JSONObject read_json_from_url(String url) throws IOException, JSONException, URISyntaxException { + try (final var rd = new BufferedReader( + new InputStreamReader(new URI(url).toURL().openStream(), StandardCharsets.UTF_8))) { + return new JSONObject(read_all(rd)); + } + } +} diff --git a/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/Resolve.java b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/Resolve.java new file mode 100644 index 000000000..4fb0bd8e5 --- /dev/null +++ b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/Resolve.java @@ -0,0 +1,37 @@ +package org.oddlama.vane.proxycore.util; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.UUID; + +import org.json.JSONException; + +public class Resolve { + public static class Skin { + + public String texture; + public String signature; + } + + public static Skin resolve_skin(UUID id) throws IOException, JSONException, URISyntaxException { + final var url = "https://sessionserver.mojang.com/session/minecraft/profile/" + id + "?unsigned=false"; + + final var json = IOUtil.read_json_from_url(url); + final var skin = new Skin(); + final var obj = json.getJSONArray("properties").getJSONObject(0); + skin.texture = obj.getString("value"); + skin.signature = obj.getString("signature"); + return skin; + } + + public static UUID resolve_uuid(String name) throws IOException, JSONException, URISyntaxException { + final var url = "https://api.mojang.com/users/profiles/minecraft/" + name; + + final var json = IOUtil.read_json_from_url(url); + final var id_str = json.getString("id"); + final var uuid_str = id_str.replaceFirst( + "(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", + "$1-$2-$3-$4-$5"); + return UUID.fromString(uuid_str); + } +} diff --git a/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/TimeUtil.java b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/TimeUtil.java new file mode 100644 index 000000000..506e9c14b --- /dev/null +++ b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/TimeUtil.java @@ -0,0 +1,67 @@ +package org.oddlama.vane.proxycore.util; + +import java.util.HashMap; +import java.util.Map; + +public class TimeUtil { + private static Map time_multiplier; + + static { + Map mult = new HashMap<>(); + mult.put('s', 1000L); // seconds + mult.put('m', 60000L); // minutes + mult.put('h', 3600000L); // hours + mult.put('d', 86400000L); // days + mult.put('w', 604800000L); // weeks + mult.put('y', 31536000000L); // years + time_multiplier = mult; + } + + public static long parse_time(String input) throws NumberFormatException { + long ret = 0; + + for (String time : input.split("(?<=[^0-9])(?=[0-9])")) { + String content[] = time.split("(?=[^0-9])"); + + if (content.length != 2) { + throw new NumberFormatException("missing multiplier"); + } + + Long mult = time_multiplier.get(content[1].replace("and", "").replaceAll("[,+\\.\\s]+", "").charAt(0)); + if (mult == null) { + throw new NumberFormatException("\"" + content[1] + "\" is not a valid multiplier"); + } + + ret += Long.parseLong(content[0]) * mult; + } + + return ret; + } + + public static String format_time(long millis) { + String ret = ""; + + long days = millis / 86400000L; + long hours = (millis / 3600000L) % 24; + long minutes = (millis / 60000L) % 60; + long seconds = (millis / 1000L) % 60; + + if (days > 0) { + ret += days + "d"; + } + + if (hours > 0) { + ret += hours + "h"; + } + + if (minutes > 0) { + ret += minutes + "m"; + } + + if (seconds > 0 || ret.length() == 0) { + ret += seconds + "s"; + } + + return ret; + } +} diff --git a/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/Version.java b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/Version.java new file mode 100644 index 000000000..2b404d29a --- /dev/null +++ b/vane-proxy-core/src/main/java/org/oddlama/vane/proxycore/util/Version.java @@ -0,0 +1,7 @@ +package org.oddlama.vane.proxycore.util; + +public final class Version { + + public static final String VERSION = "$VERSION"; + +} diff --git a/vane-velocity/build.gradle.kts b/vane-velocity/build.gradle.kts index b9da65c18..e31e020df 100644 --- a/vane-velocity/build.gradle.kts +++ b/vane-velocity/build.gradle.kts @@ -13,6 +13,12 @@ dependencies { implementation(rootProject.project(":vane-proxy-core")) } +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } +} + tasks.create("copyJar") { from(tasks.shadowJar) into("${project.rootProject.projectDir}/target") @@ -27,19 +33,6 @@ tasks { include(dependency("org.bstats:bstats-base")) include(dependency("org.json:json")) include(dependency(rootProject.project(":vane-proxy-core"))) - - // Utilities to include from vane-core.util - val includedUtils = listOf( - "Resolve", - "TimeUtil", - "IOUtil" - ) - - from(rootProject.project(":vane-core").sourceSets.main.get().output) { - for (i in includedUtils) { - include("org/oddlama/vane/util/$i*.class") - } - } } relocate("org.json", "org.oddlama.vane.vane_velocity.external.json") diff --git a/vane-velocity/src/main/java/org/oddlama/velocity/Velocity.java b/vane-velocity/src/main/java/org/oddlama/velocity/Velocity.java index 2edf29a44..dc4233191 100644 --- a/vane-velocity/src/main/java/org/oddlama/velocity/Velocity.java +++ b/vane-velocity/src/main/java/org/oddlama/velocity/Velocity.java @@ -16,7 +16,7 @@ import org.bstats.velocity.Metrics; import org.oddlama.vane.proxycore.VaneProxyPlugin; import org.oddlama.vane.proxycore.log.slf4jCompatLogger; -import org.oddlama.vane.util.Version; +import org.oddlama.vane.proxycore.util.Version; import org.oddlama.velocity.commands.Maintenance; import org.oddlama.velocity.commands.Ping; import org.oddlama.velocity.compat.VelocityCompatProxyServer; From 51b26de004039467d22309a9adaf3da1895560aa Mon Sep 17 00:00:00 2001 From: Sylfare <12037446+Sylfare@users.noreply.github.com> Date: Mon, 8 Jul 2024 23:23:44 +0200 Subject: [PATCH 2/2] fix: Remove vane-waterfall + add java 21 --- .github/workflows/build.yml | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index db3dad1fe..60ffe9c7f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,23 +3,31 @@ name: Build on: push: pull_request: + workflow_dispatch: jobs: build: runs-on: ubuntu-latest strategy: matrix: - project: [ 'admin', 'bedtime', 'core', 'enchantments', 'permissions', 'portals', 'regions', 'trifles', 'waterfall', 'velocity' ] + project: [ 'admin', 'bedtime', 'core', 'enchantments', 'permissions', 'portals', 'regions', 'trifles', 'velocity' ] steps: - - uses: actions/checkout@v3.0.0 + - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v3.0.0 + uses: actions/setup-java@v4 with: java-version: 17 distribution: 'temurin' + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: 'temurin' + - name: Gradle build run: | cd vane-${{ matrix.project }} @@ -29,8 +37,8 @@ jobs: echo "git_hash=$git_hash" >> $GITHUB_ENV - name: Upload JAR - if: ${{ github.event_name == 'push' }} - uses: actions/upload-artifact@v3 + if: ${{ github.event_name != 'pull_request'}} + uses: actions/upload-artifact@v4 with: name: vane-${{ matrix.project }}-${{ env.git_hash }}.jar path: target/vane-${{ matrix.project }}-*.jar