mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-25 12:25:22 +01:00
Added system to override Via jars
This commit is contained in:
parent
dada02cb37
commit
e1cae0d81d
@ -19,20 +19,20 @@ package de.florianmichael.viafabricplus;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import de.florianmichael.viafabricplus.definition.ChatLengthCalculation;
|
||||
import de.florianmichael.viafabricplus.definition.v1_12_2.FontCacheFix;
|
||||
import de.florianmichael.viafabricplus.mappings.ItemReleaseVersionMappings;
|
||||
import de.florianmichael.viafabricplus.mappings.PackFormatsMappings;
|
||||
import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountHandler;
|
||||
import de.florianmichael.viafabricplus.screen.impl.ClassicItemSelectionScreen;
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.ClassiCubeAccountHandler;
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.protocol.CustomClassicProtocolExtensions;
|
||||
import de.florianmichael.viafabricplus.definition.v1_8.ArmorPointCalculation;
|
||||
import de.florianmichael.viafabricplus.base.event.FinishMinecraftLoadCallback;
|
||||
import de.florianmichael.viafabricplus.base.event.PreLoadCallback;
|
||||
import de.florianmichael.viafabricplus.information.InformationSystem;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import de.florianmichael.viafabricplus.base.settings.SettingsSystem;
|
||||
import de.florianmichael.viafabricplus.definition.ChatLengthCalculation;
|
||||
import de.florianmichael.viafabricplus.definition.bedrock.BedrockAccountHandler;
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.ClassiCubeAccountHandler;
|
||||
import de.florianmichael.viafabricplus.definition.c0_30.protocol.CustomClassicProtocolExtensions;
|
||||
import de.florianmichael.viafabricplus.definition.v1_12_2.FontCacheFix;
|
||||
import de.florianmichael.viafabricplus.definition.v1_8.ArmorPointCalculation;
|
||||
import de.florianmichael.viafabricplus.information.InformationSystem;
|
||||
import de.florianmichael.viafabricplus.mappings.ItemReleaseVersionMappings;
|
||||
import de.florianmichael.viafabricplus.mappings.PackFormatsMappings;
|
||||
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
|
||||
import de.florianmichael.viafabricplus.screen.impl.ClassicItemSelectionScreen;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@ -60,6 +60,9 @@ public class ViaFabricPlus {
|
||||
private final InformationSystem informationSystem = new InformationSystem();
|
||||
|
||||
public void init() {
|
||||
// Load overriding jars first so other code can access the new classes
|
||||
ViaJarReplacer.loadOverridingJars();
|
||||
|
||||
PreLoadCallback.EVENT.invoker().onLoad();
|
||||
|
||||
// Classic Stuff
|
||||
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.florianmichael.viafabricplus;
|
||||
|
||||
import net.lenni0451.reflect.ClassLoaders;
|
||||
import net.lenni0451.reflect.stream.RStream;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ViaJarReplacer {
|
||||
|
||||
public final static File VIA_JAR_OVERRIDING_FOLDER = new File(ViaFabricPlus.RUN_DIRECTORY, "jars");
|
||||
|
||||
public static void loadOverridingJars() {
|
||||
try {
|
||||
VIA_JAR_OVERRIDING_FOLDER.mkdirs();
|
||||
final File[] files = VIA_JAR_OVERRIDING_FOLDER.listFiles();
|
||||
if (files != null && files.length > 0) {
|
||||
final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
final ClassLoader actualLoader = RStream.of(oldLoader).fields().by("urlLoader").get();
|
||||
Thread.currentThread().setContextClassLoader(actualLoader);
|
||||
for (File file : files) {
|
||||
if (file.getName().endsWith(".jar")) {
|
||||
ClassLoaders.loadToFront(file.toURI().toURL());
|
||||
ViaFabricPlus.LOGGER.info("Loaded overriding jar " + file.getName());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
Thread.currentThread().setContextClassLoader(oldLoader);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
ViaFabricPlus.LOGGER.error("Failed to load overriding jars", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.connection.UserConnectionImpl;
|
||||
import com.viaversion.viaversion.protocol.ProtocolPipelineImpl;
|
||||
import de.florianmichael.viafabricplus.ViaFabricPlus;
|
||||
import de.florianmichael.viafabricplus.base.event.ChangeProtocolVersionCallback;
|
||||
import de.florianmichael.viafabricplus.base.event.FinishViaVersionStartupCallback;
|
||||
import de.florianmichael.viafabricplus.protocolhack.command.ViaFabricPlusVLCommandHandler;
|
||||
@ -32,7 +33,7 @@ import de.florianmichael.viafabricplus.protocolhack.impl.ViaFabricPlusVLLoader;
|
||||
import de.florianmichael.viafabricplus.protocolhack.impl.platform.ViaFabricPlusViaLegacyPlatformImpl;
|
||||
import de.florianmichael.viafabricplus.protocolhack.impl.platform.ViaFabricPlusViaVersionPlatformImpl;
|
||||
import de.florianmichael.viafabricplus.protocolhack.netty.ViaFabricPlusVLLegacyPipeline;
|
||||
import io.netty.channel.*;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.util.AttributeKey;
|
||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
@ -45,7 +46,8 @@ import net.raphimc.vialoader.impl.platform.ViaBedrockPlatformImpl;
|
||||
import net.raphimc.vialoader.util.VersionEnum;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProtocolHack {
|
||||
public final static AttributeKey<UserConnection> LOCAL_VIA_CONNECTION = AttributeKey.newInstance("viafabricplus-via-connection");
|
||||
@ -117,7 +119,7 @@ public class ProtocolHack {
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
ViaLoader.init(new ViaFabricPlusViaVersionPlatformImpl(null), new ViaFabricPlusVLLoader(), new ViaFabricPlusVLInjector(), new ViaFabricPlusVLCommandHandler(), ViaBackwardsPlatformImpl::new, ViaFabricPlusViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new, ViaBedrockPlatformImpl::new);
|
||||
ViaLoader.init(new ViaFabricPlusViaVersionPlatformImpl(ViaFabricPlus.RUN_DIRECTORY), new ViaFabricPlusVLLoader(), new ViaFabricPlusVLInjector(), new ViaFabricPlusVLCommandHandler(), ViaBackwardsPlatformImpl::new, ViaFabricPlusViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new, ViaBedrockPlatformImpl::new);
|
||||
initCommands();
|
||||
|
||||
FinishViaVersionStartupCallback.EVENT.invoker().onFinishViaVersionStartup();
|
||||
|
Loading…
Reference in New Issue
Block a user