mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-25 12:15:14 +01:00
Shade instead of downloading dependencies on runtime
This commit is contained in:
parent
12e378747d
commit
407d66b313
29
build.gradle
29
build.gradle
@ -31,11 +31,16 @@ processResources {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
configurations {
|
||||||
|
shade
|
||||||
|
compile.extendsFrom shade
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// transitive = false, viabackwards-core because Guava is conflicting on runClient
|
// transitive = false, viabackwards-core because Guava is conflicting on runClient
|
||||||
compile("us.myles:viaversion:2.0.0-19w09a") { transitive = false }
|
shade("us.myles:viaversion:2.0.0-19w11b") { transitive = false }
|
||||||
compile("de.gerrygames:viarewind-core:1.4.0") { transitive = false }
|
shade("de.gerrygames:viarewind-core:1.4.0") { transitive = false }
|
||||||
compile("nl.matsv:viabackwards-core:2.4.0-SNAPSHOT") { transitive = false }
|
shade("nl.matsv:viabackwards-core:3.0.0-19w11b") { transitive = false }
|
||||||
|
|
||||||
minecraft "com.mojang:minecraft:19w11b"
|
minecraft "com.mojang:minecraft:19w11b"
|
||||||
mappings "net.fabricmc:yarn:19w11b.2"
|
mappings "net.fabricmc:yarn:19w11b.2"
|
||||||
@ -44,6 +49,24 @@ dependencies {
|
|||||||
modCompile "net.fabricmc:fabric:0.2.3.110"
|
modCompile "net.fabricmc:fabric:0.2.3.110"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
configurations.shade.each { dep ->
|
||||||
|
from(project.zipTree(dep)) {
|
||||||
|
//exclude 'META-INF', 'META-INF/**'
|
||||||
|
exclude 'us/myles/ViaVersion/BungeePlugin.class'
|
||||||
|
exclude 'us/myles/ViaVersion/SpongePlugin.class'
|
||||||
|
exclude 'us/myles/ViaVersion/VelocityPlugin.class'
|
||||||
|
exclude 'us/myles/ViaVersion/ViaVersionPlugin.class'
|
||||||
|
exclude 'us/myles/ViaVersion/bukkit/**'
|
||||||
|
exclude 'us/myles/ViaVersion/velocity/**'
|
||||||
|
exclude 'us/viaversion/libs/javassist/**'
|
||||||
|
exclude 'mcmod.info'
|
||||||
|
exclude 'plugin.yml'
|
||||||
|
exclude 'bungee.yml'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
/*
|
|
||||||
* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2018 creeper123123321 and contributors
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.github.creeper123123321.viafabric;
|
|
||||||
|
|
||||||
import com.github.creeper123123321.viafabric.commands.VRCommandHandler;
|
|
||||||
import com.github.creeper123123321.viafabric.platform.*;
|
|
||||||
import com.github.creeper123123321.viafabric.protocol.protocol1_7_6_10to1_7_1_5.Protocol1_7_6_10to1_7_1_5;
|
|
||||||
import com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.Protocol1_8TO1_7_6_10;
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|
||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
|
||||||
import net.fabricmc.api.EnvType;
|
|
||||||
import net.fabricmc.fabric.api.registry.CommandRegistry;
|
|
||||||
import net.fabricmc.loader.FabricLoader;
|
|
||||||
import net.minecraft.server.command.CommandSource;
|
|
||||||
import us.myles.ViaVersion.ViaManager;
|
|
||||||
import us.myles.ViaVersion.api.Via;
|
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
|
||||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
public class VRViaVersionInitializer {
|
|
||||||
public static void init() {
|
|
||||||
Via.init(ViaManager.builder()
|
|
||||||
.injector(new VRInjector())
|
|
||||||
.loader(new VRLoader())
|
|
||||||
.commandHandler(new VRCommandHandler())
|
|
||||||
.platform(new VRPlatform()).build());
|
|
||||||
Via.getManager().init();
|
|
||||||
ProtocolRegistry.registerProtocol(new Protocol1_7_6_10to1_7_1_5(), Collections.singletonList(ProtocolVersion.v1_7_6.getId()), ProtocolVersion.v1_7_1.getId());
|
|
||||||
ProtocolRegistry.registerProtocol(new Protocol1_8TO1_7_6_10(), Collections.singletonList(ProtocolVersion.v1_8.getId()), ProtocolVersion.v1_7_6.getId());
|
|
||||||
new VRRewindPlatform().init();
|
|
||||||
new VRBackwardsPlatform().init();
|
|
||||||
|
|
||||||
if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT) {
|
|
||||||
try {
|
|
||||||
Class.forName("io.github.cottonmc.clientcommands.ClientCommands")
|
|
||||||
.getMethod("registerCommand", Consumer.class)
|
|
||||||
.invoke(null,
|
|
||||||
(Consumer<CommandDispatcher<CommandSource>>) c ->
|
|
||||||
c.register(command("viafabricclient"))
|
|
||||||
);
|
|
||||||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
|
||||||
Via.getPlatform().getLogger().warning("ClientCommands isn't installed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Class.forName("net.fabricmc.fabric.api.registry.CommandRegistry");
|
|
||||||
CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaversion")));
|
|
||||||
CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaver")));
|
|
||||||
CommandRegistry.INSTANCE.register(false, c -> c.register(command("vvfabric")));
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
Via.getPlatform().getLogger().warning("Fabric API isn't installed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <S extends CommandSource> LiteralArgumentBuilder<S> command(String commandName) {
|
|
||||||
return LiteralArgumentBuilder.<S>literal(commandName)
|
|
||||||
.then(
|
|
||||||
RequiredArgumentBuilder
|
|
||||||
.<S, String>argument("args", StringArgumentType.greedyString())
|
|
||||||
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute)
|
|
||||||
.suggests(((VRCommandHandler) Via.getManager().getCommandHandler())::suggestion)
|
|
||||||
)
|
|
||||||
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute);
|
|
||||||
}
|
|
||||||
}
|
|
@ -24,36 +24,35 @@
|
|||||||
|
|
||||||
package com.github.creeper123123321.viafabric;
|
package com.github.creeper123123321.viafabric;
|
||||||
|
|
||||||
|
import com.github.creeper123123321.viafabric.commands.VRCommandHandler;
|
||||||
|
import com.github.creeper123123321.viafabric.platform.*;
|
||||||
|
import com.github.creeper123123321.viafabric.protocol.protocol1_7_6_10to1_7_1_5.Protocol1_7_6_10to1_7_1_5;
|
||||||
|
import com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.Protocol1_8TO1_7_6_10;
|
||||||
import com.github.creeper123123321.viafabric.util.JLoggerToLog4j;
|
import com.github.creeper123123321.viafabric.util.JLoggerToLog4j;
|
||||||
import com.github.creeper123123321.viafabric.util.Version;
|
|
||||||
import com.google.common.io.CharStreams;
|
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
import io.netty.channel.DefaultEventLoop;
|
import io.netty.channel.DefaultEventLoop;
|
||||||
import io.netty.channel.EventLoop;
|
import io.netty.channel.EventLoop;
|
||||||
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
import net.fabricmc.fabric.api.registry.CommandRegistry;
|
||||||
import net.fabricmc.loader.FabricLoader;
|
import net.fabricmc.loader.FabricLoader;
|
||||||
import net.minecraft.SharedConstants;
|
import net.minecraft.server.command.CommandSource;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import us.myles.ViaVersion.ViaManager;
|
||||||
|
import us.myles.ViaVersion.api.Via;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||||
|
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.util.Collections;
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ThreadFactory;
|
import java.util.concurrent.ThreadFactory;
|
||||||
import java.util.regex.Matcher;
|
import java.util.function.Consumer;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class ViaFabric implements ModInitializer {
|
public class ViaFabric implements ModInitializer {
|
||||||
public static final java.util.logging.Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
|
public static final java.util.logging.Logger JLOGGER = new JLoggerToLog4j(LogManager.getLogger("ViaFabric"));
|
||||||
@ -71,84 +70,50 @@ public class ViaFabric implements ModInitializer {
|
|||||||
.get().getMetadata().getVersion().getFriendlyString();
|
.get().getMetadata().getVersion().getFriendlyString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForUpdates(File jar, String artifactName, String groupIdPath, String depName) throws Exception {
|
@Override
|
||||||
int timeDivisor = 1000 * 60 * 60 * 24;
|
public void onInitialize() {
|
||||||
long cachedTime = System.currentTimeMillis() / timeDivisor;
|
Via.init(ViaManager.builder()
|
||||||
if (!(jar.exists() && jar.lastModified() / timeDivisor >= cachedTime)) {
|
.injector(new VRInjector())
|
||||||
String localMd5 = null;
|
.loader(new VRLoader())
|
||||||
if (jar.exists()) {
|
.commandHandler(new VRCommandHandler())
|
||||||
try (InputStream is = Files.newInputStream(jar.toPath())) {
|
.platform(new VRPlatform()).build());
|
||||||
localMd5 = DigestUtils.md5Hex(is);
|
Via.getManager().init();
|
||||||
}
|
ProtocolRegistry.registerProtocol(new Protocol1_7_6_10to1_7_1_5(), Collections.singletonList(ProtocolVersion.v1_7_6.getId()), ProtocolVersion.v1_7_1.getId());
|
||||||
}
|
ProtocolRegistry.registerProtocol(new Protocol1_8TO1_7_6_10(), Collections.singletonList(ProtocolVersion.v1_8.getId()), ProtocolVersion.v1_7_6.getId());
|
||||||
URL versionsUrl = new URL("https://repo.viaversion.com/" + groupIdPath + "/" + artifactName + "/");
|
new VRRewindPlatform().init();
|
||||||
JLOGGER.info("Checking for " + depName + " updates " + versionsUrl);
|
new VRBackwardsPlatform().init();
|
||||||
HttpURLConnection con = (HttpURLConnection) versionsUrl.openConnection();
|
|
||||||
con.setRequestProperty("User-Agent", "ViaFabric/" + ViaFabric.getVersion());
|
if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT) {
|
||||||
String rawOutput = CharStreams.toString(new InputStreamReader(con.getInputStream()));
|
try {
|
||||||
Pattern urlPattern = Pattern.compile("<A href='([^']*)/'>");
|
Class.forName("io.github.cottonmc.clientcommands.ClientCommands")
|
||||||
Matcher matcher = urlPattern.matcher(rawOutput);
|
.getMethod("registerCommand", Consumer.class)
|
||||||
List<String> versions = new ArrayList<>();
|
.invoke(null,
|
||||||
while (matcher.find()) {
|
(Consumer<CommandDispatcher<CommandSource>>) c ->
|
||||||
versions.add(matcher.group(1));
|
c.register(command("viafabricclient"))
|
||||||
}
|
);
|
||||||
String mcVersion = SharedConstants.getGameVersion().getName();
|
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||||
String bestViaVersion = null;
|
Via.getPlatform().getLogger().warning("ClientCommands isn't installed");
|
||||||
if (mcVersion.contains("w") || mcVersion.contains("-")) {
|
|
||||||
bestViaVersion = versions.stream()
|
|
||||||
.filter(it -> it.endsWith(mcVersion))
|
|
||||||
.max(Comparator.comparing(Version::new))
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
if (bestViaVersion == null) {
|
|
||||||
bestViaVersion = versions.stream()
|
|
||||||
.filter(it -> it.endsWith("-SNAPSHOT") || it.endsWith("-DEV") || !it.contains("-"))
|
|
||||||
.max(Comparator.comparing(Version::new))
|
|
||||||
.orElse(null);
|
|
||||||
}
|
|
||||||
HttpURLConnection md5Con = (HttpURLConnection) new URL(
|
|
||||||
"https://repo.viaversion.com/" + groupIdPath + "/" + artifactName + "/" + bestViaVersion
|
|
||||||
+ "/" + artifactName + "-" + bestViaVersion + ".jar.md5").openConnection();
|
|
||||||
md5Con.setRequestProperty("User-Agent", "ViaFabric/" + ViaFabric.getVersion());
|
|
||||||
String remoteMd5 = CharStreams.toString(new InputStreamReader(md5Con.getInputStream()));
|
|
||||||
if (!remoteMd5.equals(localMd5)) {
|
|
||||||
URL url = new URL("https://repo.viaversion.com/" + groupIdPath + "/" + artifactName + "/" + bestViaVersion
|
|
||||||
+ "/" + artifactName + "-" + bestViaVersion + ".jar");
|
|
||||||
ViaFabric.JLOGGER.info("Downloading " + url);
|
|
||||||
HttpURLConnection jarCon = (HttpURLConnection) url.openConnection();
|
|
||||||
jarCon.setRequestProperty("User-Agent", "ViaFabric/" + ViaFabric.getVersion());
|
|
||||||
FileUtils.copyInputStreamToFile(jarCon.getInputStream(), jar);
|
|
||||||
} else {
|
|
||||||
JLOGGER.info("No updates found");
|
|
||||||
jar.setLastModified(System.currentTimeMillis());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class.forName("net.fabricmc.fabric.api.registry.CommandRegistry");
|
||||||
|
CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaversion")));
|
||||||
|
CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaver")));
|
||||||
|
CommandRegistry.INSTANCE.register(false, c -> c.register(command("vvfabric")));
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
Via.getPlatform().getLogger().warning("Fabric API isn't installed");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static <S extends CommandSource> LiteralArgumentBuilder<S> command(String commandName) {
|
||||||
public void onInitialize() {
|
return LiteralArgumentBuilder.<S>literal(commandName)
|
||||||
File viaVersionJar = FabricLoader.INSTANCE.getConfigDirectory().toPath().resolve("ViaFabric").resolve("viaversion.jar").toFile();
|
.then(
|
||||||
File viaRewindJar = FabricLoader.INSTANCE.getConfigDirectory().toPath().resolve("ViaFabric").resolve("viarewind.jar").toFile();
|
RequiredArgumentBuilder
|
||||||
File viaBackwardsJar = FabricLoader.INSTANCE.getConfigDirectory().toPath().resolve("ViaFabric").resolve("viabackwards.jar").toFile();
|
.<S, String>argument("args", StringArgumentType.greedyString())
|
||||||
try {
|
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute)
|
||||||
checkForUpdates(viaVersionJar, "viaversion", "us/myles", "ViaVersion");
|
.suggests(((VRCommandHandler) Via.getManager().getCommandHandler())::suggestion)
|
||||||
checkForUpdates(viaRewindJar, "viarewind-core", "de/gerrygames", "ViaRewind");
|
)
|
||||||
checkForUpdates(viaBackwardsJar, "viabackwards-core", "nl/matsv", "ViaBackwards");
|
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute);
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Method addUrl = ViaFabric.class.getClassLoader().getClass().getMethod("addURL", URL.class);
|
|
||||||
addUrl.setAccessible(true);
|
|
||||||
addUrl.invoke(ViaFabric.class.getClassLoader(), viaVersionJar.toURI().toURL());
|
|
||||||
addUrl.invoke(ViaFabric.class.getClassLoader(), viaRewindJar.toURI().toURL());
|
|
||||||
addUrl.invoke(ViaFabric.class.getClassLoader(), viaBackwardsJar.toURI().toURL());
|
|
||||||
// Need reflection because Fabric was loading the class before the jars were added to classpath
|
|
||||||
Class.forName("com.github.creeper123123321.viafabric.VRViaVersionInitializer")
|
|
||||||
.getMethod("init")
|
|
||||||
.invoke(null);
|
|
||||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | MalformedURLException | ClassNotFoundException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,4 +273,9 @@ public class VRViaConfig extends Config implements ViaVersionConfig {
|
|||||||
public int get1_13TabCompleteDelay() {
|
public int get1_13TabCompleteDelay() {
|
||||||
return this.getInt("1_13-tab-complete-delay", 0);
|
return this.getInt("1_13-tab-complete-delay", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean truncate1_14Books() {
|
||||||
|
return this.getBoolean("truncate-1_14-books", false);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user