mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-11-02 08:59:31 +01:00
Fixed random crashes and load ViaVersion async
This commit is contained in:
parent
67285d4f4a
commit
cf93a0453a
@ -30,6 +30,7 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/*
|
||||
* TODO | General
|
||||
@ -66,17 +67,22 @@ public class ViaFabricPlus {
|
||||
private SettingsManager settingsManager;
|
||||
private SaveManager saveManager;
|
||||
|
||||
private CompletableFuture<Void> loadingFuture;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public void bootstrap() {
|
||||
directory.mkdir();
|
||||
ClassLoaderPriorityUtil.loadOverridingJars(directory); // Load overriding jars first so other code can access the new classes
|
||||
|
||||
ClientsideFixes.init(); // Init clientside related fixes
|
||||
ProtocolHack.init(directory); // Init ViaVersion protocol translator platform
|
||||
loadingFuture = ProtocolHack.init(directory); // Init ViaVersion protocol translator platform
|
||||
|
||||
settingsManager = new SettingsManager();
|
||||
saveManager = new SaveManager(settingsManager);
|
||||
PostGameLoadCallback.EVENT.register(saveManager::init); // Has to wait for Minecraft because of the translation system usages
|
||||
PostGameLoadCallback.EVENT.register(() -> {
|
||||
saveManager.init();
|
||||
loadingFuture.join();
|
||||
}); // Has to wait for Minecraft because of the translation system usages
|
||||
}
|
||||
|
||||
public static ViaFabricPlus global() {
|
||||
|
@ -1369,5 +1369,4 @@ public class ItemRegistryDiff {
|
||||
return !ITEM_DIFF.containsKey(item) || ITEM_DIFF.get(item).contains(ProtocolHack.getTargetVersion() /*ProtocolHack.getTargetVersion().isNewerThanOrEqualTo(ITEM_DIFF.get(item)*/);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -55,6 +55,7 @@ import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
@ -172,19 +173,7 @@ public class ProtocolHack {
|
||||
throw new IllegalStateException("The player is not connected to a server");
|
||||
}
|
||||
|
||||
public static void init(final File directory) {
|
||||
// Load ViaVersion and register all platforms and their components
|
||||
ViaLoader.init(
|
||||
new ViaVersionPlatformImpl(directory),
|
||||
new ViaFabricPlusVLLoader(),
|
||||
new ViaFabricPlusVLInjector(),
|
||||
new ViaFabricPlusVLCommandHandler(),
|
||||
ViaBackwardsPlatformImpl::new,
|
||||
ViaFabricPlusViaLegacyPlatformImpl::new,
|
||||
ViaAprilFoolsPlatformImpl::new,
|
||||
ViaBedrockPlatformImpl::new
|
||||
);
|
||||
|
||||
public static CompletableFuture<Void> init(final File directory) {
|
||||
// Register command callback for /viaversion and /viafabricplus
|
||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> {
|
||||
final var commandHandler = (ViaFabricPlusVLCommandHandler) Via.getManager().getCommandHandler();
|
||||
@ -195,6 +184,19 @@ public class ProtocolHack {
|
||||
dispatcher.register(LiteralArgumentBuilder.<FabricClientCommandSource>literal("viafabricplus").then(executor).executes(commandHandler::execute));
|
||||
});
|
||||
|
||||
PostViaVersionLoadCallback.EVENT.invoker().onPostViaVersionLoad();
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
// Load ViaVersion and register all platforms and their components
|
||||
ViaLoader.init(
|
||||
new ViaVersionPlatformImpl(directory),
|
||||
new ViaFabricPlusVLLoader(),
|
||||
new ViaFabricPlusVLInjector(),
|
||||
new ViaFabricPlusVLCommandHandler(),
|
||||
ViaBackwardsPlatformImpl::new,
|
||||
ViaFabricPlusViaLegacyPlatformImpl::new,
|
||||
ViaAprilFoolsPlatformImpl::new,
|
||||
ViaBedrockPlatformImpl::new
|
||||
);
|
||||
PostViaVersionLoadCallback.EVENT.invoker().onPostViaVersionLoad();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public class ItemTranslator {
|
||||
buf.writeShort(0); // slot
|
||||
buf.writeItemStack(stack); // item
|
||||
|
||||
final var wrapper = PacketWrapper.create(CREATIVE_INVENTORY_ACTION_ID, null, user);
|
||||
final var wrapper = PacketWrapper.create(CREATIVE_INVENTORY_ACTION_ID, buf, user);
|
||||
user.getProtocolInfo().getPipeline().transform(Direction.SERVERBOUND, State.PLAY, wrapper);
|
||||
|
||||
wrapper.read(Type.SHORT); // slot
|
||||
|
Loading…
Reference in New Issue
Block a user