mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-19 14:59:21 +00:00
feat: support 1.21.8 alongside 1.21.7
adds support for version range expressions to the CompatibilityChecker. Also adds tests for this.
This commit is contained in:
@@ -48,7 +48,7 @@ HuskSync supports the following [compatible versions](https://william278.net/doc
|
||||
|
||||
| Minecraft | Latest HuskSync | Java Version | Platforms | Support Status |
|
||||
|:---------------:|:---------------:|:------------:|:--------------|:------------------------------|
|
||||
| 1.21.7 | _latest_ | 21 | Paper | ✅ **Active Release** |
|
||||
| 1.21.7/8 | _latest_ | 21 | Paper | ✅ **Active Release** |
|
||||
| 1.21.6 | 3.8.5 | 21 | Paper | 🗃️ Archived (July 2025) |
|
||||
| 1.21.5 | _latest_ | 21 | Paper | ✅ **January 2026** (Non-LTS) |
|
||||
| 1.21.4 | _latest_ | 21 | Paper, Fabric | ✅ **November 2025** (Non-LTS) |
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
minecraft_version_range='1.20.1'
|
||||
minecraft_version_numeric=12001
|
||||
minecraft_api_version=1.20
|
||||
paper_api_version=1.20.1-R0.1-SNAPSHOT
|
||||
@@ -1,3 +1,4 @@
|
||||
minecraft_version_range='1.21.1'
|
||||
minecraft_version_numeric=12101
|
||||
minecraft_api_version=1.21
|
||||
paper_api_version=1.21.1-R0.1-SNAPSHOT
|
||||
@@ -1,3 +1,4 @@
|
||||
minecraft_version_range='1.21.4'
|
||||
minecraft_version_numeric=12104
|
||||
minecraft_api_version=1.21
|
||||
paper_api_version=1.21.4-R0.1-SNAPSHOT
|
||||
@@ -1,3 +1,4 @@
|
||||
minecraft_version_range='1.21.5'
|
||||
minecraft_version_numeric=12105
|
||||
minecraft_api_version=1.21
|
||||
paper_api_version=1.21.5-R0.1-SNAPSHOT
|
||||
@@ -1,3 +1,4 @@
|
||||
minecraft_version_numeric=12107
|
||||
minecraft_version_range='>=1.21.7 <=1.21.8'
|
||||
minecraft_version_numeric=12108
|
||||
minecraft_api_version=1.21
|
||||
paper_api_version=1.21.7-R0.1-SNAPSHOT
|
||||
paper_api_version=1.21.8-R0.1-SNAPSHOT
|
||||
@@ -42,6 +42,7 @@ processResources {
|
||||
version: version,
|
||||
paper_api_version: paper_api_version,
|
||||
minecraft_version: project.name,
|
||||
minecraft_version_range: minecraft_version_range,
|
||||
minecraft_api_version: minecraft_api_version
|
||||
])
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
# File used for checking Minecraft server compatibility with this version of HuskSync
|
||||
minecraft_version: '${minecraft_version}'
|
||||
minecraft_version_range: '${minecraft_version_range}'
|
||||
@@ -327,7 +327,7 @@ public class Settings {
|
||||
private Map<String, String> eventPriorities = EventListener.ListenerType.getDefaults();
|
||||
|
||||
@Comment("Enable check-in petitions for data syncing (don't change this unless you know what you're doing)")
|
||||
private boolean checkinPetitions = true;
|
||||
private boolean checkinPetitions = false;
|
||||
|
||||
public boolean doAutoPin(@NotNull DataSnapshot.SaveCause cause) {
|
||||
return autoPinnedSaveCauses.contains(cause.name());
|
||||
|
||||
@@ -22,12 +22,13 @@ package net.william278.husksync.util;
|
||||
import de.exlll.configlib.Configuration;
|
||||
import de.exlll.configlib.YamlConfigurationProperties;
|
||||
import de.exlll.configlib.YamlConfigurationStore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.william278.desertwell.util.Version;
|
||||
import net.william278.husksync.HuskSync;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static net.william278.husksync.config.ConfigProvider.YAML_CONFIGURATION_PROPERTIES;
|
||||
@@ -38,23 +39,22 @@ public interface CompatibilityChecker {
|
||||
|
||||
default void checkCompatibility() throws HuskSync.FailedToLoadException {
|
||||
final YamlConfigurationProperties p = YAML_CONFIGURATION_PROPERTIES.build();
|
||||
final Version compatible;
|
||||
final CompatibilityConfig compat;
|
||||
|
||||
// Load compatibility file
|
||||
try (InputStream input = getResource(COMPATIBILITY_FILE)) {
|
||||
final CompatibilityConfig compat = new YamlConfigurationStore<>(CompatibilityConfig.class, p).read(input);
|
||||
compatible = Objects.requireNonNull(compat.getCompatibleWith());
|
||||
compat = new YamlConfigurationStore<>(CompatibilityConfig.class, p).read(input);
|
||||
} catch (Throwable e) {
|
||||
getPlugin().log(Level.WARNING, "Failed to load compatibility config, skipping check.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check compatibility
|
||||
if (compatible.compareTo(getPlugin().getMinecraftVersion()) != 0) {
|
||||
if (!compat.isCompatibleWith(getPlugin().getMinecraftVersion())) {
|
||||
throw new HuskSync.FailedToLoadException("""
|
||||
Incompatible Minecraft version. This version of HuskSync is designed for Minecraft %s.
|
||||
Please download the correct version of HuskSync for your server's Minecraft version (%s)."""
|
||||
.formatted(compatible.toString(), getPlugin().getMinecraftVersion().toString()));
|
||||
.formatted(compat.minecraftVersionRange(), getPlugin().getMinecraftVersion().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,11 +64,38 @@ public interface CompatibilityChecker {
|
||||
HuskSync getPlugin();
|
||||
|
||||
@Configuration
|
||||
record CompatibilityConfig(@NotNull String minecraftVersion) {
|
||||
record CompatibilityConfig(@NotNull String minecraftVersionRange) {
|
||||
|
||||
@NotNull
|
||||
public Version getCompatibleWith() {
|
||||
return Version.fromString(minecraftVersion);
|
||||
@AllArgsConstructor
|
||||
enum ExpressionType {
|
||||
GTE(">=", (v, s) -> v.compareTo(Version.fromString(s.substring(2))) >= 0),
|
||||
LTE("<=", (v, s) -> v.compareTo(Version.fromString(s.substring(2))) <= 0),
|
||||
GT(">", (v, s) -> v.compareTo(Version.fromString(s.substring(1))) > 0),
|
||||
LT("<", (v, s) -> v.compareTo(Version.fromString(s.substring(1))) < 0),
|
||||
NOT("!", (v, s) -> v.compareTo(Version.fromString(s.substring(1))) != 0),
|
||||
E("=", (v, s) -> v.compareTo(Version.fromString(s.substring(1))) == 0);
|
||||
|
||||
private final String match;
|
||||
private final BiFunction<Version, String, Boolean> function;
|
||||
|
||||
private static boolean check(@NotNull String versionRange, @NotNull Version mcVer) {
|
||||
boolean passes = true;
|
||||
versions:
|
||||
for (String exp : versionRange.split(" ")) {
|
||||
for (ExpressionType type : values()) {
|
||||
if (exp.trim().startsWith(type.match)) {
|
||||
passes = passes && type.function.apply(mcVer, exp.trim());
|
||||
continue versions;
|
||||
}
|
||||
}
|
||||
passes = passes && mcVer.compareTo(Version.fromString(exp.trim())) == 0;
|
||||
}
|
||||
return passes;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCompatibleWith(@NotNull Version version) {
|
||||
return ExpressionType.check(minecraftVersionRange, version);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of HuskSync, licensed under the Apache License 2.0.
|
||||
*
|
||||
* Copyright (c) William278 <will27528@gmail.com>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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.
|
||||
*/
|
||||
|
||||
package net.william278.husksync.util;
|
||||
|
||||
import net.william278.desertwell.util.Version;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
@DisplayName("Compatibility Checker Tests")
|
||||
public class CompatibilityCheckerTests {
|
||||
|
||||
@ParameterizedTest(name = "Ver: {0}, Range: {1}")
|
||||
@DisplayName("Test Compatibility Checker")
|
||||
@CsvSource({
|
||||
"1.20.1, 1.21.1, false",
|
||||
"1.21.1, 1.20.1, false",
|
||||
"1.7.2, 1.21.5, false",
|
||||
"1.19.4, 1.21.1, false",
|
||||
"1.21.3, 1.21.3, true",
|
||||
"1.20.1, 1.20.1, true",
|
||||
"1.21.7, 1.21.7, true",
|
||||
"1.21.8, >=1.21.7, true",
|
||||
"1.21.8, >1.21.7, true",
|
||||
"1.0, <1.21.7, true",
|
||||
"1.17.1, !1.17.1, false",
|
||||
"1.21.7, '>=1.21.7 <=1.21.8', true",
|
||||
"1.21.8, '>=1.21.7 <=1.21.8', true",
|
||||
"1.21.5, '>=1.21.7 <=1.21.8', false",
|
||||
})
|
||||
public void testCompatibilityChecker(@NotNull String mcVer, @NotNull String range, boolean exp) {
|
||||
final Version version = Version.fromString(mcVer);
|
||||
Assertions.assertNotNull(version, "Version should not be null");
|
||||
|
||||
final CompatibilityChecker.CompatibilityConfig config = new CompatibilityChecker.CompatibilityConfig(range);
|
||||
Assertions.assertEquals(exp, config.isCompatibleWith(version), "Checker should return " + exp);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@ HuskSync supports the following versions of Minecraft. Since v3.7, you must down
|
||||
|
||||
| Minecraft | Latest HuskSync | Java Version | Platforms | Support Status |
|
||||
|:---------------:|:---------------:|:------------:|:--------------|:------------------------------|
|
||||
| 1.21.7 | _latest_ | 21 | Paper | ✅ **Active Release** |
|
||||
| 1.21.7/8 | _latest_ | 21 | Paper | ✅ **Active Release** |
|
||||
| 1.21.6 | 3.8.5 | 21 | Paper | 🗃️ Archived (July 2025) |
|
||||
| 1.21.5 | _latest_ | 21 | Paper | ✅ **January 2026** (Non-LTS) |
|
||||
| 1.21.4 | _latest_ | 21 | Paper, Fabric | ✅ **November 2025** (Non-LTS) |
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
essential.defaults.loom.mappings=net.fabricmc:yarn:1.20.1+build.10:v2
|
||||
|
||||
minecraft_version_range='1.20.1'
|
||||
|
||||
fabric_loader_version=0.15.11
|
||||
fabric_api_version=0.92.2+1.20.1
|
||||
fabric_permissions_api_version=0.2-SNAPSHOT
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
essential.defaults.loom.mappings=net.fabricmc:yarn:1.21.1+build.3:v2
|
||||
|
||||
minecraft_version_range='1.21.1'
|
||||
|
||||
fabric_loader_version=0.16.10
|
||||
fabric_api_version=0.107.0+1.21.1
|
||||
fabric_permissions_api_version=0.3.1
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
essential.defaults.loom.mappings=net.fabricmc:yarn:1.21.4+build.4:v2
|
||||
|
||||
minecraft_version_range='1.21.4'
|
||||
|
||||
fabric_loader_version=0.16.10
|
||||
fabric_api_version=0.116.1+1.21.4
|
||||
fabric_permissions_api_version=0.3.3
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
essential.defaults.loom.mappings=net.fabricmc:yarn:1.21.5+build.1:v2
|
||||
|
||||
minecraft_version_range='1.21.5'
|
||||
|
||||
fabric_loader_version=0.16.14
|
||||
fabric_api_version=0.122.0+1.21.5
|
||||
fabric_permissions_api_version=0.3.3
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
essential.defaults.loom.mappings=net.fabricmc:yarn:1.21.7+build.2:v2
|
||||
|
||||
minecraft_version_range='>=1.21.7 <=1.21.8'
|
||||
|
||||
fabric_loader_version=0.16.14
|
||||
fabric_api_version=0.128.1+1.21.7
|
||||
fabric_permissions_api_version=0.4.1
|
||||
|
||||
@@ -49,7 +49,8 @@ processResources {
|
||||
expand([
|
||||
version: version,
|
||||
fabric_loader_version: fabric_loader_version,
|
||||
fabric_minecraft_version: project.name
|
||||
fabric_minecraft_version: project.name,
|
||||
minecraft_version_range: minecraft_version_range
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
},
|
||||
"depends": {
|
||||
"fabricloader": ">=${fabric_loader_version}",
|
||||
"minecraft": "${fabric_minecraft_version}",
|
||||
"minecraft": "${minecraft_version_range}",
|
||||
"fabric-api": "*"
|
||||
},
|
||||
"suggests": {
|
||||
|
||||
@@ -4,7 +4,7 @@ org.gradle.daemon=true
|
||||
javaVersion=21
|
||||
|
||||
# Plugin metadata
|
||||
plugin_version=3.8.6
|
||||
plugin_version=3.8.7
|
||||
plugin_archive=husksync
|
||||
plugin_description=A modern, cross-server player data synchronization system
|
||||
|
||||
|
||||
Reference in New Issue
Block a user