mirror of
https://github.com/ViaVersion/ViaLoader.git
synced 2024-11-12 10:23:55 +01:00
Added support to load additional platforms
This commit is contained in:
parent
097e3fcf07
commit
814a300a97
@ -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
|
||||
|
@ -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<ViaBackwardsPlatform> viaBackwardsPlatformSupplier, Supplier<ViaRewindPlatform> viaRewindPlatformSupplier, Supplier<ViaLegacyPlatform> viaLegacyPlatformSupplier) {
|
||||
public static void init(ViaPlatform<?> platform, ViaPlatformLoader loader, ViaInjector injector, ViaCommandHandler commandHandler, Supplier<ViaBackwardsPlatform> viaBackwardsPlatformSupplier, Supplier<ViaRewindPlatform> viaRewindPlatformSupplier, Supplier<ViaLegacyPlatform> 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<ViaBackwardsPlatform> finalViaBackwardsPlatformSupplier = viaBackwardsPlatformSupplier;
|
||||
final Supplier<ViaRewindPlatform> finalViaRewindPlatformSupplier = viaRewindPlatformSupplier;
|
||||
final Supplier<ViaLegacyPlatform> 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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user