From 3b9d399afde1645e75a342936b2ed48c744f92fb Mon Sep 17 00:00:00 2001 From: Kichura <68134602+Kichura@users.noreply.github.com> Date: Sun, 14 Jan 2024 10:01:52 +0100 Subject: [PATCH 1/2] Update supported Velocity version to 3.3 (#3649) --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 679b81125..13b295806 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ projectVersion=4.9.3-SNAPSHOT mcVersions=1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9 mcVersionRange=1.8-1.20.4 waterfallVersion=1.20 -velocityVersion=3.2 +velocityVersion=3.3 # Gradle properties org.gradle.daemon=true From 5b29ac0d8a2feeec23135917453481bf39c8fbe9 Mon Sep 17 00:00:00 2001 From: vadage Date: Sun, 14 Jan 2024 10:04:15 +0100 Subject: [PATCH 2/2] Support config loading from input stream as fallback if URL cannot be acquired (#3647) --- .../viaversion/viaversion/util/Config.java | 18 ++++++++++--- .../viaversion/util/InputStreamSupplier.java | 27 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 common/src/main/java/com/viaversion/viaversion/util/InputStreamSupplier.java diff --git a/common/src/main/java/com/viaversion/viaversion/util/Config.java b/common/src/main/java/com/viaversion/viaversion/util/Config.java index 8acaf5bf6..3735af9fe 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/Config.java +++ b/common/src/main/java/com/viaversion/viaversion/util/Config.java @@ -66,14 +66,26 @@ public abstract class Config { return getClass().getClassLoader().getResource("assets/viaversion/config.yml"); } + public InputStream getDefaultConfigInputStream() { + return getClass().getClassLoader().getResourceAsStream("assets/viaversion/config.yml"); + } + public Map loadConfig(File location) { - return loadConfig(location, getDefaultConfigURL()); + final URL defaultConfigUrl = getDefaultConfigURL(); + if (defaultConfigUrl != null) { + return loadConfig(location, defaultConfigUrl); + } + return loadConfig(location, this::getDefaultConfigInputStream); } public synchronized Map loadConfig(File location, URL jarConfigFile) { + return loadConfig(location, jarConfigFile::openStream); + } + + private synchronized Map loadConfig(File location, InputStreamSupplier configSupplier) { List unsupported = getUnsupportedOptions(); try { - commentStore.storeComments(jarConfigFile.openStream()); + commentStore.storeComments(configSupplier.get()); for (String option : unsupported) { List comments = commentStore.header(option); if (comments != null) { @@ -96,7 +108,7 @@ public abstract class Config { } Map defaults = config; - try (InputStream stream = jarConfigFile.openStream()) { + try (InputStream stream = configSupplier.get()) { defaults = (Map) YAML.get().load(stream); for (String option : unsupported) { defaults.remove(option); diff --git a/common/src/main/java/com/viaversion/viaversion/util/InputStreamSupplier.java b/common/src/main/java/com/viaversion/viaversion/util/InputStreamSupplier.java new file mode 100644 index 000000000..45174aefc --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/util/InputStreamSupplier.java @@ -0,0 +1,27 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viaversion.util; + +import java.io.IOException; +import java.io.InputStream; + +@FunctionalInterface +public interface InputStreamSupplier { + + InputStream get() throws IOException; +}