diff --git a/gradle.properties b/gradle.properties index f69721c..66df2f2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,4 +6,4 @@ org.gradle.configureondemand=true # Project properties maven_name=ViaProtocolHack maven_group=net.raphimc -maven_version=2.1.1 +maven_version=2.1.2 diff --git a/src/main/java/net/raphimc/viaprotocolhack/ViaProtocolHack.java b/src/main/java/net/raphimc/viaprotocolhack/ViaProtocolHack.java index bee988a..8c1bf70 100644 --- a/src/main/java/net/raphimc/viaprotocolhack/ViaProtocolHack.java +++ b/src/main/java/net/raphimc/viaprotocolhack/ViaProtocolHack.java @@ -36,6 +36,7 @@ import net.raphimc.viaprotocolhack.util.JLoggerToSLF4J; import org.slf4j.LoggerFactory; import java.util.function.Supplier; +import java.util.logging.Level; import java.util.logging.Logger; public class ViaProtocolHack { @@ -45,7 +46,7 @@ public class ViaProtocolHack { private static final Logger LOGGER = new JLoggerToSLF4J(LoggerFactory.getLogger("ViaProtocolHack")); @SuppressWarnings("ReassignedVariable") - public static void init(ViaPlatform platform, ViaPlatformLoader loader, ViaInjector injector, ViaCommandHandler commandHandler, Supplier viaBackwardsPlatformSupplier, Supplier viaRewindPlatformSupplier, Supplier viaLegacyPlatformSupplier) { + public static void init(ViaPlatform platform, ViaPlatformLoader loader, ViaInjector injector, ViaCommandHandler commandHandler, Supplier viaBackwardsPlatformSupplier, Supplier viaRewindPlatformSupplier, Supplier viaLegacyPlatformSupplier, final Supplier... additionalPlatformSuppliers) { if (platform == null) platform = new ViaVersionPlatformImpl(null); if (loader == null) loader = new VPLoader(); if (injector == null) injector = new VPInjector(); @@ -59,37 +60,43 @@ public class ViaProtocolHack { .build()); MappingDataLoader.enableMappingsCache(); - final Supplier finalViaBackwardsPlatformSupplier = viaBackwardsPlatformSupplier; - final Supplier finalViaRewindPlatformSupplier = viaRewindPlatformSupplier; - final Supplier finalViaLegacyPlatformSupplier = viaLegacyPlatformSupplier; Via.getManager().addEnableListener(() -> { - if (finalViaBackwardsPlatformSupplier != null) { + if (viaBackwardsPlatformSupplier != null) { try { - finalViaBackwardsPlatformSupplier.get(); + viaBackwardsPlatformSupplier.get(); } catch (Throwable e) { - LOGGER.severe("ViaBackwards failed to load: " + e.getMessage()); + LOGGER.log(Level.SEVERE, "ViaBackwards failed to load", e); } } else { LOGGER.info("ViaBackwards is not loaded."); } - if (finalViaRewindPlatformSupplier != null) { + if (viaRewindPlatformSupplier != null) { try { - finalViaRewindPlatformSupplier.get(); + viaRewindPlatformSupplier.get(); } catch (Throwable e) { - LOGGER.severe("ViaRewind failed to load: " + e.getMessage()); + LOGGER.log(Level.SEVERE, "ViaRewind failed to load", e); } } else { LOGGER.info("ViaRewind is not loaded."); } - if (finalViaLegacyPlatformSupplier != null) { + if (viaLegacyPlatformSupplier != null) { try { - finalViaLegacyPlatformSupplier.get(); + viaLegacyPlatformSupplier.get(); } catch (Throwable e) { - LOGGER.severe("ViaLegacy failed to load: " + e.getMessage()); + LOGGER.log(Level.SEVERE, "ViaLegacy failed to load", e); } } else { LOGGER.info("ViaLegacy is not loaded."); } + if (additionalPlatformSuppliers != null) { + for (Supplier additionalPlatformSupplier : additionalPlatformSuppliers) { + try { + additionalPlatformSupplier.get(); + } catch (Throwable e) { + LOGGER.log(Level.SEVERE, "Additional platform failed to load", e); + } + } + } }); ((ViaManagerImpl) Via.getManager()).init(); diff --git a/src/main/java/net/raphimc/viaprotocolhack/util/VersionEnum.java b/src/main/java/net/raphimc/viaprotocolhack/util/VersionEnum.java index 0565a12..2675ce7 100644 --- a/src/main/java/net/raphimc/viaprotocolhack/util/VersionEnum.java +++ b/src/main/java/net/raphimc/viaprotocolhack/util/VersionEnum.java @@ -77,7 +77,7 @@ public enum VersionEnum { r1_13(ProtocolVersion.v1_13), r1_13_1(ProtocolVersion.v1_13_1), r1_13_2(ProtocolVersion.v1_13_2), - s3d_shareware(getViaLegacyProtocol("s3d_shareware")), + s3d_shareware(getViaAprilFoolsProtocol("s3d_shareware")), r1_14(ProtocolVersion.v1_14), r1_14_1(ProtocolVersion.v1_14_1), r1_14_2(ProtocolVersion.v1_14_2), @@ -86,10 +86,10 @@ public enum VersionEnum { r1_15(ProtocolVersion.v1_15), r1_15_1(ProtocolVersion.v1_15_1), r1_15_2(ProtocolVersion.v1_15_2), - s20w14infinite(getViaLegacyProtocol("s20w14infinite")), + s20w14infinite(getViaAprilFoolsProtocol("s20w14infinite")), r1_16(ProtocolVersion.v1_16), r1_16_1(ProtocolVersion.v1_16_1), - sCombatTest8c(getViaLegacyProtocol("sCombatTest8c")), + sCombatTest8c(getViaAprilFoolsProtocol("sCombatTest8c")), r1_16_2(ProtocolVersion.v1_16_2), r1_16_3(ProtocolVersion.v1_16_3), r1_16_4tor1_16_5(ProtocolVersion.v1_16_4), @@ -222,7 +222,15 @@ public enum VersionEnum { private static ProtocolVersion getViaLegacyProtocol(final String name) { try { - return (ProtocolVersion) Class.forName("net.raphimc.vialegacy.api.LegacyProtocolVersions").getField(name).get(null); + return (ProtocolVersion) Class.forName("net.raphimc.vialegacy.api.LegacyProtocolVersion").getField(name).get(null); + } catch (Throwable e) { + return ProtocolVersion.unknown; + } + } + + private static ProtocolVersion getViaAprilFoolsProtocol(final String name) { + try { + return (ProtocolVersion) Class.forName("net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion").getField(name).get(null); } catch (Throwable e) { return ProtocolVersion.unknown; }