From 869225e1597bfc0b151adea97ab38303a7bb3c56 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Tue, 14 Mar 2023 23:45:57 +0100 Subject: [PATCH] full recode --- README.md | 32 ++++ build.gradle | 13 +- gradle.properties | 4 +- .../viafabricplus/ViaFabricPlus.java | 153 +++--------------- .../definition/ChatLengthDefinition.java | 28 ++-- .../ItemReleaseVersionDefinition.java | 30 ++-- .../definition/PackFormatsDefinition.java | 2 + .../c0_30/ClassicItemSelectionScreen.java | 14 +- .../c0_30/ClassicProgressRenderer.java | 3 +- .../CustomClassicProtocolExtensions.java | 26 +-- .../definition/c0_30/command/ICommand.java | 3 +- .../event/ChangeProtocolVersionListener.java | 46 ++++++ .../event/FinishMinecraftLoadListener.java | 41 +++++ .../FinishViaLoadingBaseStartupListener.java | 41 +++++ .../event/InitializeSettingsListener.java | 41 +++++ .../LoadClassicProtocolExtensionListener.java | 46 ++++++ .../LoadListener.java} | 29 ++-- .../SkipIdlePacketListener.java} | 24 ++- .../mixin/base/MixinClientConnection.java | 6 +- .../mixin/base/MixinClientConnection_1.java | 20 +-- .../base/MixinClientLoginNetworkHandler.java | 3 +- .../injection/mixin/base/MixinMain.java | 2 +- .../mixin/base/MixinMinecraftClient.java | 5 +- .../MixinMultiplayerServerListPinger.java | 2 +- .../injection/mixin/bridge/MixinDebugHud.java | 3 +- .../MixinClientPlayerInteractionManager.java | 7 +- .../mixin/fixes/MixinMinecraftClient.java | 3 +- .../mixin/fixes/MixinStringHelper.java | 2 +- .../fixes/entity/MixinClientPlayerEntity.java | 5 +- .../mixin/fixes/entity/MixinWolfEntity.java | 3 +- .../item/MixinItemGroup_EntriesImpl.java | 2 +- .../packet/MixinChatMessageC2SPacket.java | 2 +- .../mixin/fixes/screen/MixinChatScreen.java | 2 +- .../fixes/screen/MixinConnectScreen_1.java | 3 +- .../MixinClassicProtocolExtension.java | 6 +- .../MixinClientboundPacketsc0_30cpe.java | 4 +- ...MixinExtensionProtocolMetadataStorage.java | 6 +- .../MixinProtocol1_11To1_10.java | 2 +- .../screen/settings/SettingsScreen.java | 12 +- .../BooleanSettingRenderer.java | 2 +- .../settingrenderer/ModeSettingRenderer.java | 7 +- .../ProtocolSyncBooleanSettingRenderer.java | 6 +- .../SettingsSystem.java} | 65 ++++++-- .../settings/{ => base}/AbstractSetting.java | 2 +- .../settings/{ => base}/SettingGroup.java | 2 +- .../settings/groups/BridgeSettings.java | 4 +- .../settings/groups/DebugSettings.java | 4 +- .../settings/groups/GeneralSettings.java | 6 +- .../settings/groups/MPPassSettings.java | 4 +- .../settings/groups/VisualSettings.java | 4 +- .../{impl => type_impl}/BooleanSetting.java | 6 +- .../{impl => type_impl}/ModeSetting.java | 6 +- .../ProtocolSyncBooleanSetting.java | 4 +- .../{translator => util}/ItemTranslator.java | 2 +- .../vialoadingbase/ViaLoadingBaseStartup.java | 101 ++++++++++++ .../platform/VFPVLBViaDecodeHandler.java | 2 +- .../platform/ViaAprilFoolsPlatformImpl.java | 2 +- .../platform/ViaBedrockPlatformImpl.java | 2 +- .../platform/ViaLegacyPlatformImpl.java | 2 +- .../platform/pre_netty/PreNettyConstants.java | 2 +- .../pre_netty/VFPPreNettyDecoder.java | 2 +- .../pre_netty/VFPPreNettyEncoder.java | 2 +- .../raknet/BedrockRakNetConstants.java | 2 +- .../platform/raknet/DisconnectHandler.java | 2 +- .../raknet/PingEncapsulationCodec.java | 2 +- .../raknet/RakMessageEncapsulationCodec.java | 2 +- .../platform/raknet/RakNetPingSessions.java | 2 +- .../FixedUnconnectedPingEncoder.java | 2 +- .../FixedUnconnectedPongDecoder.java | 2 +- ...abricPlusClassicCustomCommandProvider.java | 2 +- .../ViaFabricPlusClassicMPPassProvider.java | 3 +- ...aFabricPlusClassicWorldHeightProvider.java | 2 +- ...ViaFabricPlusCommandArgumentsProvider.java | 2 +- .../ViaFabricPlusEncryptionProvider.java | 5 +- .../ViaFabricPlusGameProfileFetcher.java | 2 +- .../ViaFabricPlusHandItemProvider.java | 4 +- ...FabricPlusMovementTransmitterProvider.java | 2 +- .../ViaFabricPlusNettyPipelineProvider.java | 7 +- .../ViaFabricPlusOldAuthProvider.java | 5 +- 79 files changed, 658 insertions(+), 305 deletions(-) create mode 100644 src/main/java/de/florianmichael/viafabricplus/event/ChangeProtocolVersionListener.java create mode 100644 src/main/java/de/florianmichael/viafabricplus/event/FinishMinecraftLoadListener.java create mode 100644 src/main/java/de/florianmichael/viafabricplus/event/FinishViaLoadingBaseStartupListener.java create mode 100644 src/main/java/de/florianmichael/viafabricplus/event/InitializeSettingsListener.java create mode 100644 src/main/java/de/florianmichael/viafabricplus/event/LoadClassicProtocolExtensionListener.java rename src/main/java/de/florianmichael/viafabricplus/{definition/v1_8_x/IdlePacketExecutor.java => event/LoadListener.java} (55%) rename src/main/java/de/florianmichael/viafabricplus/{ViaFabricPlusAddon.java => event/SkipIdlePacketListener.java} (51%) rename src/main/java/de/florianmichael/viafabricplus/{util/SettingsSave.java => settings/SettingsSystem.java} (50%) rename src/main/java/de/florianmichael/viafabricplus/settings/{ => base}/AbstractSetting.java (96%) rename src/main/java/de/florianmichael/viafabricplus/settings/{ => base}/SettingGroup.java (95%) rename src/main/java/de/florianmichael/viafabricplus/settings/{impl => type_impl}/BooleanSetting.java (87%) rename src/main/java/de/florianmichael/viafabricplus/settings/{impl => type_impl}/ModeSetting.java (89%) rename src/main/java/de/florianmichael/viafabricplus/settings/{impl => type_impl}/ProtocolSyncBooleanSetting.java (94%) rename src/main/java/de/florianmichael/viafabricplus/{translator => util}/ItemTranslator.java (98%) create mode 100644 src/main/java/de/florianmichael/viafabricplus/vialoadingbase/ViaLoadingBaseStartup.java rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/VFPVLBViaDecodeHandler.java (96%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/ViaAprilFoolsPlatformImpl.java (95%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/ViaBedrockPlatformImpl.java (95%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/ViaLegacyPlatformImpl.java (95%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/pre_netty/PreNettyConstants.java (93%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/pre_netty/VFPPreNettyDecoder.java (95%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/pre_netty/VFPPreNettyEncoder.java (95%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/raknet/BedrockRakNetConstants.java (95%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/raknet/DisconnectHandler.java (95%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/raknet/PingEncapsulationCodec.java (97%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/raknet/RakMessageEncapsulationCodec.java (96%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/raknet/RakNetPingSessions.java (94%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/raknet/library_fix/FixedUnconnectedPingEncoder.java (96%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/platform/raknet/library_fix/FixedUnconnectedPongDecoder.java (97%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/provider/ViaFabricPlusClassicCustomCommandProvider.java (97%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/provider/ViaFabricPlusClassicMPPassProvider.java (96%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/provider/ViaFabricPlusClassicWorldHeightProvider.java (94%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/provider/ViaFabricPlusCommandArgumentsProvider.java (96%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/provider/ViaFabricPlusEncryptionProvider.java (87%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/provider/ViaFabricPlusGameProfileFetcher.java (98%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/provider/ViaFabricPlusHandItemProvider.java (92%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/provider/ViaFabricPlusMovementTransmitterProvider.java (95%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/provider/ViaFabricPlusNettyPipelineProvider.java (88%) rename src/main/java/de/florianmichael/viafabricplus/{ => vialoadingbase}/provider/ViaFabricPlusOldAuthProvider.java (81%) diff --git a/README.md b/README.md index e4f90934..43ef603f 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,38 @@ public class ExampleSettingGroup extends SettingGroup { } ``` +#### Implementing classic protocol commands: +```java +public class ExampleCommand implements ICommand { + + @Override + public String name() { + return "example"; + } + + @Override + public String description() { + return null; + } + + @Override + public void execute(String[] args) { + } +} +``` +and then you register the command in your onLoad method: +```java +// addon main [...] + +@Override +public void onLoad() { + ClassicProtocolCommands.commands.add(new ExampleCommand()); +} +``` + +#### Implementing custom classic protocol extensions: + + ## Alternatives - [ClientViaVersion](https://github.com/Gerrygames/ClientViaVersion): Discontinued 5zig plugin. - [multiconnect](https://www.curseforge.com/minecraft/mc-mods/multiconnect): Fabric mod for connecting to older diff --git a/build.gradle b/build.gradle index dfb4cae9..3bd9c139 100644 --- a/build.gradle +++ b/build.gradle @@ -56,6 +56,13 @@ dependencies { modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}" libs "com.github.FlorianMichael:ViaLoadingBase:${project.vialoadingbase_version}" + libs "com.github.FlorianMichael:DietrichEvents:${project.dietrichevents_version}" + libs("org.cloudburstmc.netty:netty-transport-raknet:${project.raknet_transport_version}") { + exclude group: "io.netty", module: "netty-common" + exclude group: "io.netty", module: "netty-buffer" + exclude group: "io.netty", module: "netty-codec" + exclude group: "io.netty", module: "netty-transport" + } libs "com.viaversion:viaversion:${project.viaversion_version}" libs "com.viaversion:viabackwards-common:${project.viabackwards_version}" @@ -67,12 +74,6 @@ dependencies { libs "net.lenni0451.mcstructs:text:${project.mcstructs_text_version}" libs "net.lenni0451:Reflect:${project.reflect_version}" - libs("org.cloudburstmc.netty:netty-transport-raknet:1.0.0.CR1-SNAPSHOT") { - exclude group: "io.netty", module: "netty-common" - exclude group: "io.netty", module: "netty-buffer" - exclude group: "io.netty", module: "netty-codec" - exclude group: "io.netty", module: "netty-transport" - } } processResources { diff --git a/gradle.properties b/gradle.properties index 1ab77f20..57ea1155 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,12 +8,14 @@ yarn_mappings=1.19.3+build.5 loader_version=0.14.14 # viafabricplus -mod_version=1.8.11 +mod_version=1.9.0 maven_group=de.florianmichael archives_base_name=viafabricplus # base lib vialoadingbase_version=6dad0a2561 +dietrichevents_version=1.0.0 +raknet_transport_version=1.0.0.CR1-SNAPSHOT # viaversion (and required) libs viaversion_version=4.6.0 diff --git a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java index 0da683b1..52b1f05c 100644 --- a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java +++ b/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlus.java @@ -17,154 +17,53 @@ */ package de.florianmichael.viafabricplus; -import com.viaversion.viaversion.api.connection.UserConnection; -import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider; -import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; +import de.florianmichael.dietrichevents.EventDispatcher; import de.florianmichael.viafabricplus.definition.ChatLengthDefinition; import de.florianmichael.viafabricplus.definition.ItemReleaseVersionDefinition; import de.florianmichael.viafabricplus.definition.PackFormatsDefinition; import de.florianmichael.viafabricplus.definition.c0_30.ClassicItemSelectionScreen; import de.florianmichael.viafabricplus.definition.c0_30.CustomClassicProtocolExtensions; import de.florianmichael.viafabricplus.definition.c0_30.command.ClassicProtocolCommands; -import de.florianmichael.viafabricplus.definition.v1_19_0.provider.CommandArgumentsProvider; import de.florianmichael.viafabricplus.definition.v1_8_x.ArmorPointsDefinition; -import de.florianmichael.viafabricplus.platform.ViaAprilFoolsPlatformImpl; -import de.florianmichael.viafabricplus.platform.ViaBedrockPlatformImpl; -import de.florianmichael.viafabricplus.platform.ViaLegacyPlatformImpl; -import de.florianmichael.viafabricplus.provider.*; -import de.florianmichael.viafabricplus.settings.SettingGroup; -import de.florianmichael.viafabricplus.settings.groups.*; -import de.florianmichael.viafabricplus.util.SettingsSave; -import de.florianmichael.vialoadingbase.ViaLoadingBase; -import de.florianmichael.vialoadingbase.platform.SubPlatform; -import io.netty.util.AttributeKey; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.SharedConstants; -import net.minecraft.client.MinecraftClient; -import net.minecraft.network.ClientConnection; -import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion; -import net.raphimc.viabedrock.api.BedrockProtocolVersion; -import net.raphimc.viabedrock.protocol.providers.NettyPipelineProvider; -import net.raphimc.vialegacy.api.LegacyProtocolVersion; -import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicCustomCommandProvider; -import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider; -import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider; -import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider; -import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.providers.EncryptionProvider; -import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher; +import de.florianmichael.viafabricplus.event.FinishMinecraftLoadListener; +import de.florianmichael.viafabricplus.event.LoadListener; +import de.florianmichael.viafabricplus.settings.SettingsSystem; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; public class ViaFabricPlus { public final static File RUN_DIRECTORY = new File("ViaFabricPlus"); - public final static AttributeKey LOCAL_VIA_CONNECTION = AttributeKey.newInstance("viafabricplus-via-connection"); - public final static AttributeKey LOCAL_MINECRAFT_CONNECTION = AttributeKey.newInstance("viafabricplus-minecraft-connection"); + public final static ViaFabricPlus INSTANCE = new ViaFabricPlus(); - private final static ViaFabricPlus self = new ViaFabricPlus(); + private final EventDispatcher eventDispatcher = new EventDispatcher(); + private final SettingsSystem settingsSystem = new SettingsSystem(); - private final List settingGroups = new ArrayList<>(); + public void init() { + eventDispatcher.subscribe(FinishMinecraftLoadListener.class, () -> { + settingsSystem.init(); - private final SubPlatform SUB_PLATFORM_VIA_LEGACY = new SubPlatform("ViaLegacy", () -> true, ViaLegacyPlatformImpl::new, protocolVersions -> { - final List legacyProtocols = new ArrayList<>(LegacyProtocolVersion.PROTOCOLS); - Collections.reverse(legacyProtocols); + // General definitions + PackFormatsDefinition.load(); + ItemReleaseVersionDefinition.create(); + ArmorPointsDefinition.load(); - legacyProtocols.remove(LegacyProtocolVersion.c0_30cpe); - legacyProtocols.add(legacyProtocols.indexOf(LegacyProtocolVersion.c0_28toc0_30) + 1, LegacyProtocolVersion.c0_30cpe); - - protocolVersions.addAll(legacyProtocols); - }); - private final SubPlatform SUB_PLATFORM_VIA_APRIL_FOOLS = new SubPlatform("ViaAprilFools", () -> true, ViaAprilFoolsPlatformImpl::new, protocolVersions -> { - protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_14) + 1,AprilFoolsProtocolVersion.s3d_shareware); - protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_16) + 1, AprilFoolsProtocolVersion.s20w14infinite); - protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_16_2) + 1, AprilFoolsProtocolVersion.sCombatTest8c); - }); - private final SubPlatform SUB_PLATFORM_VIA_BEDROCK = new SubPlatform("ViaBedrock", () -> true, ViaBedrockPlatformImpl::new, protocolVersions -> protocolVersions.add(BedrockProtocolVersion.bedrockLatest)); - - public void preLoad() { - CustomClassicProtocolExtensions.reflect(); - - ViaLoadingBase.ViaLoadingBaseBuilder builder = ViaLoadingBase.ViaLoadingBaseBuilder.create(); - - builder = builder.subPlatform(SUB_PLATFORM_VIA_BEDROCK, 0); - builder = builder.subPlatform(SUB_PLATFORM_VIA_LEGACY); - builder = builder.subPlatform(SUB_PLATFORM_VIA_APRIL_FOOLS); - - builder = builder.runDirectory(RUN_DIRECTORY); - builder = builder.nativeVersion(SharedConstants.getProtocolVersion()); - builder = builder.forceNativeVersionCondition(() -> { - if (MinecraftClient.getInstance() == null) return true; - - return MinecraftClient.getInstance().isInSingleplayer(); + // Classic Stuff + ChatLengthDefinition.create(); + ClassicItemSelectionScreen.create(); + ClassicProtocolCommands.load(); }); - builder = builder.providers(providers -> { - providers.use(MovementTransmitterProvider.class, new ViaFabricPlusMovementTransmitterProvider()); - providers.use(HandItemProvider.class, new ViaFabricPlusHandItemProvider()); + eventDispatcher.post(new LoadListener.LoadEvent()); - providers.use(CommandArgumentsProvider.class, new ViaFabricPlusCommandArgumentsProvider()); - - providers.use(OldAuthProvider.class, new ViaFabricPlusOldAuthProvider()); - providers.use(ClassicWorldHeightProvider.class, new ViaFabricPlusClassicWorldHeightProvider()); - providers.use(EncryptionProvider.class, new ViaFabricPlusEncryptionProvider()); - providers.use(GameProfileFetcher.class, new ViaFabricPlusGameProfileFetcher()); - providers.use(ClassicMPPassProvider.class, new ViaFabricPlusClassicMPPassProvider()); - providers.use(ClassicCustomCommandProvider.class, new ViaFabricPlusClassicCustomCommandProvider()); - providers.use(NettyPipelineProvider.class, new ViaFabricPlusNettyPipelineProvider()); - }); - builder = builder.onProtocolReload(protocolVersion -> { - FabricLoader.getInstance().getEntrypoints("viafabricplus", ViaFabricPlusAddon.class).forEach(viaFabricPlusAddon -> viaFabricPlusAddon.onChangeVersion(protocolVersion)); - ItemReleaseVersionDefinition.reload(protocolVersion); - ChatLengthDefinition.reload(protocolVersion); - if (protocolVersion.isOlderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) { - ClassicItemSelectionScreen.INSTANCE.reload(protocolVersion, false); - } - }); - builder.build(); + CustomClassicProtocolExtensions.create(); + new ViaLoadingBaseStartup(); } - public void postLoad() throws Exception { - loadGroup( - GeneralSettings.getClassWrapper(), - BridgeSettings.getClassWrapper(), - MPPassSettings.getClassWrapper(), - VisualSettings.getClassWrapper(), - DebugSettings.getClassWrapper() - ); - - FabricLoader.getInstance().getEntrypoints("viafabricplus", ViaFabricPlusAddon.class).forEach(ViaFabricPlusAddon::onLoad); - - SettingsSave.load(this); - - PackFormatsDefinition.load(); - ItemReleaseVersionDefinition.load(); - ArmorPointsDefinition.load(); - - PackFormatsDefinition.checkOutdated(SharedConstants.getProtocolVersion()); - - ClassicProtocolCommands.load(); - - Runtime.getRuntime().addShutdownHook(new Thread(() -> { - try { - SettingsSave.save(this); - } catch (Exception e) { - throw new RuntimeException(e); - } - })); + public EventDispatcher getEventDispatcher() { + return eventDispatcher; } - public void loadGroup(final SettingGroup... groups) { - this.settingGroups.addAll(Arrays.asList(groups)); - } - - public List getSettingGroups() { - return settingGroups; - } - - public static ViaFabricPlus getClassWrapper() { - return ViaFabricPlus.self; + public SettingsSystem getSettingsSystem() { + return settingsSystem; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/ChatLengthDefinition.java b/src/main/java/de/florianmichael/viafabricplus/definition/ChatLengthDefinition.java index cce704a2..ef33af9b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/ChatLengthDefinition.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/ChatLengthDefinition.java @@ -18,29 +18,37 @@ package de.florianmichael.viafabricplus.definition; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import de.florianmichael.viafabricplus.ViaFabricPlus; +import de.florianmichael.viafabricplus.event.ChangeProtocolVersionListener; import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion; import net.minecraft.client.MinecraftClient; import net.raphimc.vialegacy.api.LegacyProtocolVersion; public class ChatLengthDefinition { - private static int maxLength = 256; + public static ChatLengthDefinition INSTANCE; - public static void reload(final ComparableProtocolVersion protocolVersion) { - maxLength = 256; - if (protocolVersion.isOlderThanOrEqualTo(ProtocolVersion.v1_10)) { - maxLength = 100; + public static void create() { + INSTANCE = new ChatLengthDefinition(); - if (protocolVersion.isOlderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) { - maxLength = 64 - MinecraftClient.getInstance().getSession().getUsername().length() - 2; + ViaFabricPlus.INSTANCE.getEventDispatcher().subscribe(ChangeProtocolVersionListener.class, protocolVersion -> { + INSTANCE.maxLength = 256; + if (protocolVersion.isOlderThanOrEqualTo(ProtocolVersion.v1_10)) { + INSTANCE.maxLength = 100; + + if (protocolVersion.isOlderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) { + INSTANCE.maxLength = 64 - MinecraftClient.getInstance().getSession().getUsername().length() - 2; + } } - } + }); } - public static void expand() { + private int maxLength = 256; + + public void expand() { maxLength = Short.MAX_VALUE * 2; } - public static int getMaxLength() { + public int getMaxLength() { return maxLength; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/ItemReleaseVersionDefinition.java b/src/main/java/de/florianmichael/viafabricplus/definition/ItemReleaseVersionDefinition.java index e58c7802..93eb07d5 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/ItemReleaseVersionDefinition.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/ItemReleaseVersionDefinition.java @@ -18,6 +18,8 @@ package de.florianmichael.viafabricplus.definition; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import de.florianmichael.viafabricplus.ViaFabricPlus; +import de.florianmichael.viafabricplus.event.ChangeProtocolVersionListener; import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion; import de.florianmichael.vialoadingbase.platform.ProtocolRange; import net.minecraft.item.Item; @@ -33,21 +35,27 @@ import java.util.*; * @copyright FlorianMichael as Jesse - 2020-2023 */ public class ItemReleaseVersionDefinition { - private final static Map itemMap = new HashMap<>(); - private final static List currentMap = new ArrayList<>(); + public static ItemReleaseVersionDefinition INSTANCE; - public static void reload(final ComparableProtocolVersion protocolVersion) { - currentMap.clear(); - currentMap.addAll(Registries.ITEM.stream().filter(item -> ItemReleaseVersionDefinition.contains(item, protocolVersion)).toList()); + public static void create() { + INSTANCE = new ItemReleaseVersionDefinition(); + + ViaFabricPlus.INSTANCE.getEventDispatcher().subscribe(ChangeProtocolVersionListener.class, (protocolVersion -> { + INSTANCE.currentMap.clear(); + INSTANCE.currentMap.addAll(Registries.ITEM.stream().filter(item -> INSTANCE.contains(item, protocolVersion)).toList()); + })); } - public static boolean contains(final Item item, final ComparableProtocolVersion protocolVersion) { + private final Map itemMap = new HashMap<>(); + private final List currentMap = new ArrayList<>(); + + public boolean contains(final Item item, final ComparableProtocolVersion protocolVersion) { if (!itemMap.containsKey(item)) return true; return Arrays.stream(itemMap.get(item)).anyMatch(protocolRange -> protocolRange.contains(protocolVersion)); } - public static void load() { + public void load() { register(Items.IRON_GOLEM_SPAWN_EGG, ProtocolRange.andNewer(ProtocolVersion.v1_19_3)); register(Items.SNOW_GOLEM_SPAWN_EGG, ProtocolRange.andNewer(ProtocolVersion.v1_19_3)); @@ -1300,19 +1308,19 @@ public class ItemReleaseVersionDefinition { register(Items.SPONGE, ProtocolRange.andNewer(LegacyProtocolVersion.c0_0_19a_06)); } - private static void register(final Item item, final ProtocolRange range) { + private void register(final Item item, final ProtocolRange range) { itemMap.put(item, new ProtocolRange[]{range}); } - private static void register(final Item item, final ProtocolRange... ranges) { + private void register(final Item item, final ProtocolRange... ranges) { itemMap.put(item, ranges); } - public static Map getItemMap() { + public Map getItemMap() { return itemMap; } - public static List getCurrentMap() { + public List getCurrentMap() { return currentMap; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/PackFormatsDefinition.java b/src/main/java/de/florianmichael/viafabricplus/definition/PackFormatsDefinition.java index 8f3d5928..2b58cad1 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/PackFormatsDefinition.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/PackFormatsDefinition.java @@ -68,6 +68,8 @@ public class PackFormatsDefinition { registerVersion(ProtocolVersion.v1_8, 1, "1.8.9"); registerVersion(ProtocolVersion.v1_7_6, 1, "1.7.10"); registerVersion(ProtocolVersion.v1_7_1, 1, "1.7.5"); + + checkOutdated(SharedConstants.getProtocolVersion()); } public static void checkOutdated(final int nativeVersion) { diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/ClassicItemSelectionScreen.java b/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/ClassicItemSelectionScreen.java index d306c685..c7494f06 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/ClassicItemSelectionScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/ClassicItemSelectionScreen.java @@ -17,6 +17,8 @@ */ package de.florianmichael.viafabricplus.definition.c0_30; +import de.florianmichael.viafabricplus.ViaFabricPlus; +import de.florianmichael.viafabricplus.event.ChangeProtocolVersionListener; import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion; import de.florianmichael.vialoadingbase.platform.InternalProtocolList; import net.minecraft.client.MinecraftClient; @@ -37,7 +39,17 @@ import java.util.List; @SuppressWarnings("DataFlowIssue") public class ClassicItemSelectionScreen extends Screen { - public static ClassicItemSelectionScreen INSTANCE = new ClassicItemSelectionScreen(); + public static ClassicItemSelectionScreen INSTANCE; + + public static void create() { + INSTANCE = new ClassicItemSelectionScreen(); + + ViaFabricPlus.INSTANCE.getEventDispatcher().subscribe(ChangeProtocolVersionListener.class, protocolVersion -> { + if (protocolVersion.isOlderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) { + INSTANCE.reload(protocolVersion, false); + } + }); + } private final static int MAX_ROW_DIVIDER = 9; private final static int ITEM_XY_BOX_DIMENSION_CLASSIC = 25; diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/ClassicProgressRenderer.java b/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/ClassicProgressRenderer.java index 29f1252c..98040db4 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/ClassicProgressRenderer.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/ClassicProgressRenderer.java @@ -19,6 +19,7 @@ package de.florianmichael.viafabricplus.definition.c0_30; import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viafabricplus.ViaFabricPlus; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.util.Window; @@ -29,7 +30,7 @@ public class ClassicProgressRenderer extends DrawableHelper { public static void renderProgress(final MatrixStack matrices) { if (MinecraftClient.getInstance().getNetworkHandler() == null) return; - final UserConnection connection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get(); + final UserConnection connection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get(); if (connection == null) return; final ClassicProgressStorage classicProgressStorage = connection.get(ClassicProgressStorage.class); if (classicProgressStorage == null) return; diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/CustomClassicProtocolExtensions.java b/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/CustomClassicProtocolExtensions.java index 77ec1eee..d623b1ac 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/CustomClassicProtocolExtensions.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/CustomClassicProtocolExtensions.java @@ -18,7 +18,11 @@ package de.florianmichael.viafabricplus.definition.c0_30; import com.viaversion.viaversion.api.connection.UserConnection; +import de.florianmichael.dietrichevents.EventDispatcher; +import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.definition.ChatLengthDefinition; +import de.florianmichael.viafabricplus.event.LoadClassicProtocolExtensionListener; +import de.florianmichael.viafabricplus.event.LoadListener; import de.florianmichael.vialoadingbase.ViaLoadingBase; import io.netty.buffer.ByteBuf; import net.lenni0451.reflect.Enums; @@ -32,24 +36,28 @@ import java.util.Map; import java.util.function.BiConsumer; public class CustomClassicProtocolExtensions { - public final static List ALLOWED_EXTENSIONS = Arrays.asList(ClassicProtocolExtension.ENV_WEATHER_TYPE); + public static CustomClassicProtocolExtensions INSTANCE; - public final static Map CUSTOM_PACKETS = new HashMap<>(); - public static ClientboundPacketsc0_30cpe EXT_WEATHER_TYPE; + public static void create() { + CustomClassicProtocolExtensions.INSTANCE = new CustomClassicProtocolExtensions(); - public static void reflect() { EXT_WEATHER_TYPE = createNewPacket(ClassicProtocolExtension.ENV_WEATHER_TYPE, 31, (user, buf) -> buf.readByte()); + + ViaFabricPlus.INSTANCE.getEventDispatcher().subscribe(LoadClassicProtocolExtensionListener.class, (classicProtocolExtension) -> { + if (classicProtocolExtension == ClassicProtocolExtension.LONGER_MESSAGES) ChatLengthDefinition.INSTANCE.expand(); + if (classicProtocolExtension == ClassicProtocolExtension.CUSTOM_BLOCKS) ClassicItemSelectionScreen.INSTANCE.reload(ViaLoadingBase.getClassWrapper().getTargetVersion(), true); + }); } - public static void onAddServerExtension(final ClassicProtocolExtension extension) { - if (extension == ClassicProtocolExtension.LONGER_MESSAGES) ChatLengthDefinition.expand(); - if (extension == ClassicProtocolExtension.CUSTOM_BLOCKS) ClassicItemSelectionScreen.INSTANCE.reload(ViaLoadingBase.getClassWrapper().getTargetVersion(), true); - } + public final List ALLOWED_EXTENSIONS = Arrays.asList(ClassicProtocolExtension.ENV_WEATHER_TYPE); + public final Map CUSTOM_PACKETS = new HashMap<>(); + + public static ClientboundPacketsc0_30cpe EXT_WEATHER_TYPE; public static ClientboundPacketsc0_30cpe createNewPacket(final ClassicProtocolExtension classicProtocolExtension, final int packetId, final BiConsumer packetSplitter) { final ClientboundPacketsc0_30cpe packet = Enums.newInstance(ClientboundPacketsc0_30cpe.class, classicProtocolExtension.getName(), ClassicProtocolExtension.values().length, new Class[] { int.class, BiConsumer.class }, new Object[] { packetId, packetSplitter }); Enums.addEnumInstance(ClientboundPacketsc0_30cpe.class, packet); - CUSTOM_PACKETS.put(packetId, packet); + INSTANCE.CUSTOM_PACKETS.put(packetId, packet); return packet; } } diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/command/ICommand.java b/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/command/ICommand.java index 1825d5d7..ab32bcc6 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/command/ICommand.java +++ b/src/main/java/de/florianmichael/viafabricplus/definition/c0_30/command/ICommand.java @@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.util.ScreenUtil; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import net.minecraft.client.MinecraftClient; import net.minecraft.util.Formatting; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicCustomCommandProvider; @@ -44,7 +45,7 @@ public interface ICommand { } default UserConnection currentViaConnection() { - return MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get(); + return MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get(); } void execute(String[] args) throws Exception; diff --git a/src/main/java/de/florianmichael/viafabricplus/event/ChangeProtocolVersionListener.java b/src/main/java/de/florianmichael/viafabricplus/event/ChangeProtocolVersionListener.java new file mode 100644 index 00000000..23f2d4dd --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/event/ChangeProtocolVersionListener.java @@ -0,0 +1,46 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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 . + */ +package de.florianmichael.viafabricplus.event; + +import de.florianmichael.dietrichevents.AbstractEvent; +import de.florianmichael.dietrichevents.handle.EventExecutor; +import de.florianmichael.dietrichevents.handle.Listener; +import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion; + +public interface ChangeProtocolVersionListener extends Listener { + + void onChangeProtocolVersion(final ComparableProtocolVersion protocolVersion); + + class ChangeProtocolVersionEvent extends AbstractEvent { + private final EventExecutor eventExecutor; + + public ChangeProtocolVersionEvent(final ComparableProtocolVersion protocolVersion) { + this.eventExecutor = listener -> listener.onChangeProtocolVersion(protocolVersion); + } + + @Override + public EventExecutor getEventExecutor() { + return this.eventExecutor; + } + + @Override + public Class getListenerType() { + return ChangeProtocolVersionListener.class; + } + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/event/FinishMinecraftLoadListener.java b/src/main/java/de/florianmichael/viafabricplus/event/FinishMinecraftLoadListener.java new file mode 100644 index 00000000..c1538935 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/event/FinishMinecraftLoadListener.java @@ -0,0 +1,41 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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 . + */ +package de.florianmichael.viafabricplus.event; + +import de.florianmichael.dietrichevents.AbstractEvent; +import de.florianmichael.dietrichevents.handle.EventExecutor; +import de.florianmichael.dietrichevents.handle.Listener; + +public interface FinishMinecraftLoadListener extends Listener { + + void onFinishMinecraftLoad(); + + class FinishMinecraftLoadEvent extends AbstractEvent { + private final EventExecutor eventExecutor = FinishMinecraftLoadListener::onFinishMinecraftLoad; + + @Override + public EventExecutor getEventExecutor() { + return eventExecutor; + } + + @Override + public Class getListenerType() { + return FinishMinecraftLoadListener.class; + } + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/event/FinishViaLoadingBaseStartupListener.java b/src/main/java/de/florianmichael/viafabricplus/event/FinishViaLoadingBaseStartupListener.java new file mode 100644 index 00000000..ca92cab5 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/event/FinishViaLoadingBaseStartupListener.java @@ -0,0 +1,41 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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 . + */ +package de.florianmichael.viafabricplus.event; + +import de.florianmichael.dietrichevents.AbstractEvent; +import de.florianmichael.dietrichevents.handle.EventExecutor; +import de.florianmichael.dietrichevents.handle.Listener; + +public interface FinishViaLoadingBaseStartupListener extends Listener { + + void onFinishViaLoadingBaseStartup(); + + class FinishViaLoadingBaseStartupEvent extends AbstractEvent { + private final EventExecutor eventExecutor = FinishViaLoadingBaseStartupListener::onFinishViaLoadingBaseStartup; + + @Override + public EventExecutor getEventExecutor() { + return eventExecutor; + } + + @Override + public Class getListenerType() { + return FinishViaLoadingBaseStartupListener.class; + } + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/event/InitializeSettingsListener.java b/src/main/java/de/florianmichael/viafabricplus/event/InitializeSettingsListener.java new file mode 100644 index 00000000..7c9d570f --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/event/InitializeSettingsListener.java @@ -0,0 +1,41 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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 . + */ +package de.florianmichael.viafabricplus.event; + +import de.florianmichael.dietrichevents.AbstractEvent; +import de.florianmichael.dietrichevents.handle.EventExecutor; +import de.florianmichael.dietrichevents.handle.Listener; + +public interface InitializeSettingsListener extends Listener { + + void onInitializeSettings(); + + class InitializeSettingsEvent extends AbstractEvent { + private final EventExecutor eventExecutor = InitializeSettingsListener::onInitializeSettings; + + @Override + public EventExecutor getEventExecutor() { + return eventExecutor; + } + + @Override + public Class getListenerType() { + return InitializeSettingsListener.class; + } + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/event/LoadClassicProtocolExtensionListener.java b/src/main/java/de/florianmichael/viafabricplus/event/LoadClassicProtocolExtensionListener.java new file mode 100644 index 00000000..6029680c --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/event/LoadClassicProtocolExtensionListener.java @@ -0,0 +1,46 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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 . + */ +package de.florianmichael.viafabricplus.event; + +import de.florianmichael.dietrichevents.AbstractEvent; +import de.florianmichael.dietrichevents.handle.EventExecutor; +import de.florianmichael.dietrichevents.handle.Listener; +import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ClassicProtocolExtension; + +public interface LoadClassicProtocolExtensionListener extends Listener { + + void onLoadClassicProtocolExtension(final ClassicProtocolExtension classicProtocolExtension); + + class LoadClassicProtocolExtensionEvent extends AbstractEvent { + private final EventExecutor eventExecutor; + + public LoadClassicProtocolExtensionEvent(final ClassicProtocolExtension classicProtocolExtension) { + this.eventExecutor = listener -> listener.onLoadClassicProtocolExtension(classicProtocolExtension); + } + + @Override + public EventExecutor getEventExecutor() { + return this.eventExecutor; + } + + @Override + public Class getListenerType() { + return LoadClassicProtocolExtensionListener.class; + } + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/definition/v1_8_x/IdlePacketExecutor.java b/src/main/java/de/florianmichael/viafabricplus/event/LoadListener.java similarity index 55% rename from src/main/java/de/florianmichael/viafabricplus/definition/v1_8_x/IdlePacketExecutor.java rename to src/main/java/de/florianmichael/viafabricplus/event/LoadListener.java index 23eaf453..5e6bac93 100644 --- a/src/main/java/de/florianmichael/viafabricplus/definition/v1_8_x/IdlePacketExecutor.java +++ b/src/main/java/de/florianmichael/viafabricplus/event/LoadListener.java @@ -15,18 +15,27 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.definition.v1_8_x; +package de.florianmichael.viafabricplus.event; -public class IdlePacketExecutor { - private static Runnable skipIdlePacketExecute; +import de.florianmichael.dietrichevents.AbstractEvent; +import de.florianmichael.dietrichevents.handle.EventExecutor; +import de.florianmichael.dietrichevents.handle.Listener; - public static void skipIdlePacket() { - if (skipIdlePacketExecute != null) { - skipIdlePacketExecute.run(); +public interface LoadListener extends Listener { + + void onLoad(); + + class LoadEvent extends AbstractEvent { + private final EventExecutor eventExecutor = LoadListener::onLoad; + + @Override + public EventExecutor getEventExecutor() { + return this.eventExecutor; + } + + @Override + public Class getListenerType() { + return LoadListener.class; } } - - public static void registerIdlePacketSkipExecute(final Runnable runnable) { - skipIdlePacketExecute = runnable; - } } diff --git a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlusAddon.java b/src/main/java/de/florianmichael/viafabricplus/event/SkipIdlePacketListener.java similarity index 51% rename from src/main/java/de/florianmichael/viafabricplus/ViaFabricPlusAddon.java rename to src/main/java/de/florianmichael/viafabricplus/event/SkipIdlePacketListener.java index 7273adba..bce9c96f 100644 --- a/src/main/java/de/florianmichael/viafabricplus/ViaFabricPlusAddon.java +++ b/src/main/java/de/florianmichael/viafabricplus/event/SkipIdlePacketListener.java @@ -15,13 +15,27 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus; +package de.florianmichael.viafabricplus.event; -import de.florianmichael.vialoadingbase.platform.ComparableProtocolVersion; +import de.florianmichael.dietrichevents.AbstractEvent; +import de.florianmichael.dietrichevents.handle.EventExecutor; +import de.florianmichael.dietrichevents.handle.Listener; -public interface ViaFabricPlusAddon { +public interface SkipIdlePacketListener extends Listener { - default void onLoad() {} - default void onChangeVersion(final ComparableProtocolVersion protocolVersion) { + void onSkipIdlePacket(); + + class SkipIdlePacketEvent extends AbstractEvent { + private final EventExecutor eventExecutor = SkipIdlePacketListener::onSkipIdlePacket; + + @Override + public EventExecutor getEventExecutor() { + return eventExecutor; + } + + @Override + public Class getListenerType() { + return SkipIdlePacketListener.class; + } } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection.java index c39aca23..d76e3cf7 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection.java @@ -18,9 +18,9 @@ package de.florianmichael.viafabricplus.injection.mixin.base; import de.florianmichael.viafabricplus.injection.access.IClientConnection; -import de.florianmichael.viafabricplus.platform.pre_netty.PreNettyConstants; -import de.florianmichael.viafabricplus.platform.raknet.BedrockRakNetConstants; -import de.florianmichael.viafabricplus.platform.raknet.RakNetPingSessions; +import de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty.PreNettyConstants; +import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.BedrockRakNetConstants; +import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.RakNetPingSessions; import de.florianmichael.vialoadingbase.ViaLoadingBase; import de.florianmichael.vialoadingbase.event.PipelineReorderEvent; import io.netty.bootstrap.AbstractBootstrap; diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection_1.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection_1.java index e03c8115..d2262dae 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection_1.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientConnection_1.java @@ -17,19 +17,19 @@ */ package de.florianmichael.viafabricplus.injection.mixin.base; -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.injection.access.IClientConnection; -import de.florianmichael.viafabricplus.platform.pre_netty.PreNettyConstants; -import de.florianmichael.viafabricplus.platform.pre_netty.VFPPreNettyDecoder; -import de.florianmichael.viafabricplus.platform.pre_netty.VFPPreNettyEncoder; -import de.florianmichael.viafabricplus.platform.VFPVLBViaDecodeHandler; -import de.florianmichael.viafabricplus.platform.raknet.*; -import de.florianmichael.viafabricplus.platform.raknet.library_fix.FixedUnconnectedPingEncoder; -import de.florianmichael.viafabricplus.platform.raknet.library_fix.FixedUnconnectedPongDecoder; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; +import de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty.PreNettyConstants; +import de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty.VFPPreNettyDecoder; +import de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty.VFPPreNettyEncoder; +import de.florianmichael.viafabricplus.vialoadingbase.platform.VFPVLBViaDecodeHandler; +import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.*; +import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.library_fix.FixedUnconnectedPingEncoder; +import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.library_fix.FixedUnconnectedPongDecoder; import de.florianmichael.vialoadingbase.ViaLoadingBase; import de.florianmichael.vialoadingbase.netty.VLBViaEncodeHandler; import de.florianmichael.vialoadingbase.netty.NettyConstants; @@ -83,8 +83,8 @@ public class MixinClientConnection_1 { if (channel instanceof SocketChannel || rakNet) { final UserConnection user = new UserConnectionImpl(channel, true); - channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).set(user); - channel.attr(ViaFabricPlus.LOCAL_MINECRAFT_CONNECTION).set(field_11663); + channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).set(user); + channel.attr(ViaLoadingBaseStartup.LOCAL_MINECRAFT_CONNECTION).set(field_11663); new ProtocolPipelineImpl(user); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientLoginNetworkHandler.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientLoginNetworkHandler.java index 4d7db49b..ae0c87e6 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientLoginNetworkHandler.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinClientLoginNetworkHandler.java @@ -18,6 +18,7 @@ package de.florianmichael.viafabricplus.injection.mixin.base; import de.florianmichael.viafabricplus.ViaFabricPlus; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import de.florianmichael.vialoadingbase.ViaLoadingBase; import net.minecraft.client.network.ClientLoginNetworkHandler; import net.minecraft.network.ClientConnection; @@ -40,7 +41,7 @@ public class MixinClientLoginNetworkHandler { @Inject(method = "joinServerSession", at = @At("HEAD"), cancellable = true) public void dontVerifySessionIfCracked(String serverId, CallbackInfoReturnable cir) { if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) { - if (!connection.channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get().get(ProtocolMetadataStorage.class).authenticate) { + if (!connection.channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get().get(ProtocolMetadataStorage.class).authenticate) { cir.setReturnValue(null); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMain.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMain.java index b396cb27..289ea136 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMain.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMain.java @@ -29,6 +29,6 @@ public class MixinMain { @Inject(method = "main([Ljava/lang/String;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/crash/CrashReport;initCrashReport()V")) private static void preLoad(CallbackInfo ci) { - ViaFabricPlus.getClassWrapper().preLoad(); + ViaFabricPlus.INSTANCE.init(); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMinecraftClient.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMinecraftClient.java index 6d499260..16aea76b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMinecraftClient.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMinecraftClient.java @@ -18,6 +18,7 @@ package de.florianmichael.viafabricplus.injection.mixin.base; import de.florianmichael.viafabricplus.ViaFabricPlus; +import de.florianmichael.viafabricplus.event.FinishMinecraftLoadListener; import net.minecraft.client.MinecraftClient; import net.minecraft.client.RunArgs; import org.spongepowered.asm.mixin.Mixin; @@ -30,8 +31,6 @@ public class MixinMinecraftClient { @Inject(method = "", at = @At("RETURN")) public void postLoad(RunArgs args, CallbackInfo ci) { - try { - ViaFabricPlus.getClassWrapper().postLoad(); - } catch (Exception ignored) {} + ViaFabricPlus.INSTANCE.getEventDispatcher().post(new FinishMinecraftLoadListener.FinishMinecraftLoadEvent()); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerServerListPinger.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerServerListPinger.java index b909f3e9..de859296 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerServerListPinger.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/base/MixinMultiplayerServerListPinger.java @@ -17,7 +17,7 @@ */ package de.florianmichael.viafabricplus.injection.mixin.base; -import de.florianmichael.viafabricplus.platform.raknet.RakNetPingSessions; +import de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.RakNetPingSessions; import de.florianmichael.vialoadingbase.ViaLoadingBase; import net.minecraft.client.network.MultiplayerServerListPinger; import net.raphimc.viabedrock.api.BedrockProtocolVersion; diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/bridge/MixinDebugHud.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/bridge/MixinDebugHud.java index 98d6669f..29e51fe0 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/bridge/MixinDebugHud.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/bridge/MixinDebugHud.java @@ -22,6 +22,7 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.settings.groups.BridgeSettings; import de.florianmichael.viafabricplus.util.ScreenUtil; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import de.florianmichael.vialoadingbase.ViaLoadingBase; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.hud.DebugHud; @@ -46,7 +47,7 @@ public class MixinDebugHud { final List information = new ArrayList<>(); if (MinecraftClient.getInstance().getNetworkHandler() != null) { - final UserConnection userConnection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get(); + final UserConnection userConnection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get(); information.add("Pipeline count: " + userConnection.getProtocolInfo().getPipeline().pipes().size()); information.add("Target version: " + ViaLoadingBase.getClassWrapper().getTargetVersion().getName() + " (" + ViaLoadingBase.getClassWrapper().getTargetVersion().getVersion() + ")"); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinClientPlayerInteractionManager.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinClientPlayerInteractionManager.java index abd70099..7dc6de3f 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinClientPlayerInteractionManager.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinClientPlayerInteractionManager.java @@ -25,8 +25,9 @@ import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.Protocol1_17To1_ import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.injection.access.IClientPlayerEntity; import de.florianmichael.viafabricplus.injection.access.IScreenHandler; -import de.florianmichael.viafabricplus.provider.ViaFabricPlusHandItemProvider; -import de.florianmichael.viafabricplus.translator.ItemTranslator; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; +import de.florianmichael.viafabricplus.vialoadingbase.provider.ViaFabricPlusHandItemProvider; +import de.florianmichael.viafabricplus.util.ItemTranslator; import de.florianmichael.vialoadingbase.ViaLoadingBase; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; @@ -110,7 +111,7 @@ public abstract class MixinClientPlayerInteractionManager { else slotItemBeforeModification = viafabricplus_oldItems.get(clickSlot.getSlot()); - final PacketWrapper clickSlotPacket = PacketWrapper.create(ServerboundPackets1_16_2.CLICK_WINDOW, networkHandler.getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get()); + final PacketWrapper clickSlotPacket = PacketWrapper.create(ServerboundPackets1_16_2.CLICK_WINDOW, networkHandler.getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get()); clickSlotPacket.write(Type.UNSIGNED_BYTE, (short) clickSlot.getSyncId()); clickSlotPacket.write(Type.SHORT, (short) clickSlot.getSlot()); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinMinecraftClient.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinMinecraftClient.java index 4a72fa0b..0c760420 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinMinecraftClient.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinMinecraftClient.java @@ -25,6 +25,7 @@ import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPac import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.definition.v1_12_2.SyncInputExecutor; import de.florianmichael.viafabricplus.settings.groups.DebugSettings; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import de.florianmichael.vialoadingbase.ViaLoadingBase; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import net.minecraft.client.MinecraftClient; @@ -106,7 +107,7 @@ public abstract class MixinMinecraftClient { @Inject(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;hasRidingInventory()Z")) private void onInventoryKeyPressed(CallbackInfo ci) throws Exception { if (getNetworkHandler() != null && DebugSettings.getClassWrapper().sendOpenInventoryPacket.getValue()) { - final UserConnection viaConnection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get(); + final UserConnection viaConnection = MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get(); if (viaConnection != null && ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_11_1)) { final PacketWrapper clientStatus = PacketWrapper.create(ServerboundPackets1_9_3.CLIENT_STATUS, viaConnection); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinStringHelper.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinStringHelper.java index 557da66e..bab3501d 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinStringHelper.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/MixinStringHelper.java @@ -28,6 +28,6 @@ public class MixinStringHelper { @ModifyConstant(method = "truncateChat", constant = @Constant(intValue = 256)) private static int expandChatLength(int constant) { - return ChatLengthDefinition.getMaxLength(); + return ChatLengthDefinition.INSTANCE.getMaxLength(); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/entity/MixinClientPlayerEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/entity/MixinClientPlayerEntity.java index 1d225c98..ddd6cb07 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/entity/MixinClientPlayerEntity.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/entity/MixinClientPlayerEntity.java @@ -19,8 +19,9 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.entity; import com.mojang.authlib.GameProfile; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.definition.v1_8_x.ArmorPointsDefinition; -import de.florianmichael.viafabricplus.definition.v1_8_x.IdlePacketExecutor; +import de.florianmichael.viafabricplus.event.SkipIdlePacketListener; import de.florianmichael.viafabricplus.injection.access.IClientPlayerEntity; import de.florianmichael.viafabricplus.settings.groups.DebugSettings; import de.florianmichael.viafabricplus.settings.groups.VisualSettings; @@ -116,7 +117,7 @@ public abstract class MixinClientPlayerEntity extends AbstractClientPlayerEntity } else if (this.lastOnGround != this.onGround || DebugSettings.getClassWrapper().sendIdlePacket.getValue()) { this.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(this.onGround)); } else { - IdlePacketExecutor.skipIdlePacket(); + ViaFabricPlus.INSTANCE.getEventDispatcher().post(new SkipIdlePacketListener.SkipIdlePacketEvent()); } if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_8)) { ++this.ticksSinceLastPositionPacketSent; diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/entity/MixinWolfEntity.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/entity/MixinWolfEntity.java index dae94f71..d5829feb 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/entity/MixinWolfEntity.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/entity/MixinWolfEntity.java @@ -20,6 +20,7 @@ package de.florianmichael.viafabricplus.injection.mixin.fixes.entity; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.definition.v1_14_4.Meta18Storage; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import de.florianmichael.vialoadingbase.ViaLoadingBase; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.passive.WolfEntity; @@ -35,7 +36,7 @@ public class MixinWolfEntity { public float rewriteHealth(WolfEntity instance) { float health = instance.getHealth(); if (ViaLoadingBase.getClassWrapper().getTargetVersion().isOlderThanOrEqualTo(ProtocolVersion.v1_14_4)) { - return MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get().get(Meta18Storage.class).getHealthDataMap().getOrDefault(instance.getId(), health); + return MinecraftClient.getInstance().getNetworkHandler().getConnection().channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get().get(Meta18Storage.class).getHealthDataMap().getOrDefault(instance.getId(), health); } return health; } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/item/MixinItemGroup_EntriesImpl.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/item/MixinItemGroup_EntriesImpl.java index 8e218b94..526f8eca 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/item/MixinItemGroup_EntriesImpl.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/item/MixinItemGroup_EntriesImpl.java @@ -32,7 +32,7 @@ public class MixinItemGroup_EntriesImpl { @Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Item;isEnabled(Lnet/minecraft/resource/featuretoggle/FeatureSet;)Z")) public boolean removeUnknownItems(Item instance, FeatureSet featureSet) { if (!GeneralSettings.getClassWrapper().removeNotAvailableItemsFromCreativeTab.getValue() || MinecraftClient.getInstance().isInSingleplayer()) return instance.isEnabled(featureSet); - if (ItemReleaseVersionDefinition.getCurrentMap().contains(instance)) return instance.isEnabled(featureSet); + if (ItemReleaseVersionDefinition.INSTANCE.getCurrentMap().contains(instance)) return instance.isEnabled(featureSet); return false; } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/packet/MixinChatMessageC2SPacket.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/packet/MixinChatMessageC2SPacket.java index c79aa99f..c84d9fe6 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/packet/MixinChatMessageC2SPacket.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/packet/MixinChatMessageC2SPacket.java @@ -28,6 +28,6 @@ public class MixinChatMessageC2SPacket { @ModifyConstant(method = "write", constant = @Constant(intValue = 256)) public int expandChatLength(int constant) { - return ChatLengthDefinition.getMaxLength(); + return ChatLengthDefinition.INSTANCE.getMaxLength(); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/screen/MixinChatScreen.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/screen/MixinChatScreen.java index add3f8ba..676f7683 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/screen/MixinChatScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/screen/MixinChatScreen.java @@ -37,7 +37,7 @@ public class MixinChatScreen { @Inject(method = "init", at = @At("RETURN")) public void changeChatLength(CallbackInfo ci) { - this.chatField.setMaxLength(ChatLengthDefinition.getMaxLength()); + this.chatField.setMaxLength(ChatLengthDefinition.INSTANCE.getMaxLength()); } @Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/ChatHud;getIndicatorAt(DD)Lnet/minecraft/client/gui/hud/MessageIndicator;")) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/screen/MixinConnectScreen_1.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/screen/MixinConnectScreen_1.java index 823e72b8..f858c5e0 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/screen/MixinConnectScreen_1.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/screen/MixinConnectScreen_1.java @@ -24,6 +24,7 @@ import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.injection.access.IPublicKeyData; import de.florianmichael.viafabricplus.definition.v1_19_0.storage.ChatSession1_19_0; import de.florianmichael.viafabricplus.definition.v1_19_2.storage.ChatSession1_19_2; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import de.florianmichael.vialoadingbase.ViaLoadingBase; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ConnectScreen; @@ -76,7 +77,7 @@ public class MixinConnectScreen_1 { final ClientConnection connection = field_2416.connection; if (connection == null || connection.channel == null) return; - final UserConnection userConnection = connection.channel.attr(ViaFabricPlus.LOCAL_VIA_CONNECTION).get(); + final UserConnection userConnection = connection.channel.attr(ViaLoadingBaseStartup.LOCAL_VIA_CONNECTION).get(); if (userConnection == null) { ViaLoadingBase.LOGGER.log(Level.WARNING, "ViaVersion userConnection is null"); diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinClassicProtocolExtension.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinClassicProtocolExtension.java index 8911394e..54bf9224 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinClassicProtocolExtension.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinClassicProtocolExtension.java @@ -29,19 +29,19 @@ public class MixinClassicProtocolExtension { @Inject(method = "supportsVersion", at = @At("HEAD"), cancellable = true) public void allowExtensions_supportsVersion(int version, CallbackInfoReturnable cir) { - if (CustomClassicProtocolExtensions.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this)) + if (CustomClassicProtocolExtensions.INSTANCE.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this)) cir.setReturnValue(true); } @Inject(method = "isSupported", at = @At("HEAD"), cancellable = true) public void allowExtensions_isSupported(CallbackInfoReturnable cir) { - if (CustomClassicProtocolExtensions.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this)) + if (CustomClassicProtocolExtensions.INSTANCE.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this)) cir.setReturnValue(true); } @Inject(method = "getHighestSupportedVersion", at = @At("HEAD"), cancellable = true) public void allowExtensions_getHighestSupportedVersion(CallbackInfoReturnable cir) { - if (CustomClassicProtocolExtensions.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this)) + if (CustomClassicProtocolExtensions.INSTANCE.ALLOWED_EXTENSIONS.contains((ClassicProtocolExtension) (Object) this)) cir.setReturnValue(1); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinClientboundPacketsc0_30cpe.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinClientboundPacketsc0_30cpe.java index 0e174765..bc443d31 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinClientboundPacketsc0_30cpe.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinClientboundPacketsc0_30cpe.java @@ -29,8 +29,8 @@ public class MixinClientboundPacketsc0_30cpe { @Inject(method = "getPacket", at = @At("HEAD"), cancellable = true) private static void addCustomPackets(int id, CallbackInfoReturnable cir) { - if (CustomClassicProtocolExtensions.CUSTOM_PACKETS.containsKey(id)) { - cir.setReturnValue(CustomClassicProtocolExtensions.CUSTOM_PACKETS.get(id)); + if (CustomClassicProtocolExtensions.INSTANCE.CUSTOM_PACKETS.containsKey(id)) { + cir.setReturnValue(CustomClassicProtocolExtensions.INSTANCE.CUSTOM_PACKETS.get(id)); } } } diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinExtensionProtocolMetadataStorage.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinExtensionProtocolMetadataStorage.java index 9b2a8898..93bcbcbf 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinExtensionProtocolMetadataStorage.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/vialegacy/MixinExtensionProtocolMetadataStorage.java @@ -17,9 +17,9 @@ */ package de.florianmichael.viafabricplus.injection.mixin.fixes.vialegacy; -import de.florianmichael.viafabricplus.definition.ChatLengthDefinition; -import de.florianmichael.viafabricplus.definition.c0_30.CustomClassicProtocolExtensions; +import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.injection.access.IExtensionProtocolMetadataStorage; +import de.florianmichael.viafabricplus.event.LoadClassicProtocolExtensionListener; import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ClassicProtocolExtension; import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage.ExtensionProtocolMetadataStorage; import org.spongepowered.asm.mixin.Final; @@ -38,7 +38,7 @@ public class MixinExtensionProtocolMetadataStorage implements IExtensionProtocol @Inject(method = "addServerExtension", at = @At("RETURN")) public void updateChatLengthDefinition(ClassicProtocolExtension extension, int version, CallbackInfo ci) { - CustomClassicProtocolExtensions.onAddServerExtension(extension); + ViaFabricPlus.INSTANCE.getEventDispatcher().post(new LoadClassicProtocolExtensionListener.LoadClassicProtocolExtensionEvent(extension)); } @Override diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_11to1_10/MixinProtocol1_11To1_10.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_11to1_10/MixinProtocol1_11To1_10.java index a0e359b4..ba39bbc0 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_11to1_10/MixinProtocol1_11To1_10.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/viaversion/protocol1_11to1_10/MixinProtocol1_11To1_10.java @@ -27,6 +27,6 @@ public class MixinProtocol1_11To1_10 { @ModifyConstant(method = "lambda$register$0", constant = @Constant(intValue = 100)) private static int changeMaxChatLength(int constant) { - return ChatLengthDefinition.getMaxLength(); + return ChatLengthDefinition.INSTANCE.getMaxLength(); } } diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java b/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java index ac0570a4..2ac94f77 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/settings/SettingsScreen.java @@ -22,11 +22,11 @@ import de.florianmichael.viafabricplus.screen.settings.settingrenderer.BooleanSe import de.florianmichael.viafabricplus.screen.settings.settingrenderer.ModeSettingRenderer; import de.florianmichael.viafabricplus.screen.settings.settingrenderer.ProtocolSyncBooleanSettingRenderer; import de.florianmichael.viafabricplus.screen.settings.settingrenderer.meta.TitleRenderer; -import de.florianmichael.viafabricplus.settings.AbstractSetting; -import de.florianmichael.viafabricplus.settings.SettingGroup; -import de.florianmichael.viafabricplus.settings.impl.BooleanSetting; -import de.florianmichael.viafabricplus.settings.impl.ModeSetting; -import de.florianmichael.viafabricplus.settings.impl.ProtocolSyncBooleanSetting; +import de.florianmichael.viafabricplus.settings.base.AbstractSetting; +import de.florianmichael.viafabricplus.settings.base.SettingGroup; +import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting; +import de.florianmichael.viafabricplus.settings.type_impl.ModeSetting; +import de.florianmichael.viafabricplus.settings.type_impl.ProtocolSyncBooleanSetting; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget; @@ -90,7 +90,7 @@ public class SettingsScreen extends Screen { public SlotList(MinecraftClient minecraftClient, int width, int height, int top, int bottom, int entryHeight) { super(minecraftClient, width, height, top, bottom, entryHeight); - for (SettingGroup group : ViaFabricPlus.getClassWrapper().getSettingGroups()) { + for (SettingGroup group : ViaFabricPlus.INSTANCE.getSettingsSystem().getGroups()) { this.addEntry(new TitleRenderer(group.getName())); for (AbstractSetting setting : group.getSettings()) { try { diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/BooleanSettingRenderer.java b/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/BooleanSettingRenderer.java index d1bd5754..da2bc84e 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/BooleanSettingRenderer.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/BooleanSettingRenderer.java @@ -18,7 +18,7 @@ package de.florianmichael.viafabricplus.screen.settings.settingrenderer; import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer; -import de.florianmichael.viafabricplus.settings.impl.BooleanSetting; +import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting; import de.florianmichael.viafabricplus.util.ScreenUtil; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/ModeSettingRenderer.java b/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/ModeSettingRenderer.java index 856a7bf1..afd0e2d5 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/ModeSettingRenderer.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/ModeSettingRenderer.java @@ -18,11 +18,7 @@ package de.florianmichael.viafabricplus.screen.settings.settingrenderer; import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer; -import de.florianmichael.viafabricplus.settings.AbstractSetting; -import de.florianmichael.viafabricplus.settings.groups.GeneralSettings; -import de.florianmichael.viafabricplus.settings.impl.BooleanSetting; -import de.florianmichael.viafabricplus.settings.impl.ModeSetting; -import de.florianmichael.viafabricplus.settings.impl.ProtocolSyncBooleanSetting; +import de.florianmichael.viafabricplus.settings.type_impl.ModeSetting; import de.florianmichael.viafabricplus.util.ScreenUtil; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; @@ -31,7 +27,6 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import java.awt.*; import java.util.Arrays; public class ModeSettingRenderer extends AbstractSettingRenderer { diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/ProtocolSyncBooleanSettingRenderer.java b/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/ProtocolSyncBooleanSettingRenderer.java index f6a8ce16..920cc17c 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/ProtocolSyncBooleanSettingRenderer.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/settings/settingrenderer/ProtocolSyncBooleanSettingRenderer.java @@ -18,11 +18,8 @@ package de.florianmichael.viafabricplus.screen.settings.settingrenderer; import de.florianmichael.viafabricplus.screen.settings.AbstractSettingRenderer; -import de.florianmichael.viafabricplus.settings.AbstractSetting; import de.florianmichael.viafabricplus.settings.groups.GeneralSettings; -import de.florianmichael.viafabricplus.settings.impl.BooleanSetting; -import de.florianmichael.viafabricplus.settings.impl.ModeSetting; -import de.florianmichael.viafabricplus.settings.impl.ProtocolSyncBooleanSetting; +import de.florianmichael.viafabricplus.settings.type_impl.ProtocolSyncBooleanSetting; import de.florianmichael.viafabricplus.util.ScreenUtil; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; @@ -32,7 +29,6 @@ import net.minecraft.text.Text; import net.minecraft.util.Formatting; import java.awt.*; -import java.util.Arrays; public class ProtocolSyncBooleanSettingRenderer extends AbstractSettingRenderer { private final ProtocolSyncBooleanSetting value; diff --git a/src/main/java/de/florianmichael/viafabricplus/util/SettingsSave.java b/src/main/java/de/florianmichael/viafabricplus/settings/SettingsSystem.java similarity index 50% rename from src/main/java/de/florianmichael/viafabricplus/util/SettingsSave.java rename to src/main/java/de/florianmichael/viafabricplus/settings/SettingsSystem.java index 919d3eaf..347c1f6c 100644 --- a/src/main/java/de/florianmichael/viafabricplus/util/SettingsSave.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/SettingsSystem.java @@ -15,30 +15,61 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.util; +package de.florianmichael.viafabricplus.settings; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import de.florianmichael.viafabricplus.ViaFabricPlus; -import de.florianmichael.viafabricplus.settings.AbstractSetting; -import de.florianmichael.viafabricplus.settings.SettingGroup; +import de.florianmichael.viafabricplus.event.InitializeSettingsListener; +import de.florianmichael.viafabricplus.settings.base.AbstractSetting; +import de.florianmichael.viafabricplus.settings.base.SettingGroup; +import de.florianmichael.viafabricplus.settings.groups.*; import de.florianmichael.vialoadingbase.ViaLoadingBase; import de.florianmichael.vialoadingbase.platform.InternalProtocolList; import java.io.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; -public class SettingsSave { - public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - public final static File CONFIG_FILE = new File(ViaFabricPlus.RUN_DIRECTORY, "settings.json"); +public class SettingsSystem { + private final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private final File CONFIG_FILE = new File(ViaFabricPlus.RUN_DIRECTORY, "settings.json"); - public static void load(final ViaFabricPlus viaFabricPlus) throws Exception { + private final List groups = new ArrayList<>(); + + public void init() { + addGroup( + GeneralSettings.getClassWrapper(), + BridgeSettings.getClassWrapper(), + MPPassSettings.getClassWrapper(), + VisualSettings.getClassWrapper(), + DebugSettings.getClassWrapper() + ); + + ViaFabricPlus.INSTANCE.getEventDispatcher().post(new InitializeSettingsListener.InitializeSettingsEvent()); + + loadConfig(); + Runtime.getRuntime().addShutdownHook(new Thread(this::save)); + } + + public void addGroup(final SettingGroup... groups) { + Collections.addAll(this.groups, groups); + } + + public void loadConfig() { if (CONFIG_FILE.exists()) { - final JsonObject parentNode = GSON.fromJson(new FileReader(CONFIG_FILE), JsonObject.class).getAsJsonObject(); + final JsonObject parentNode; + try { + parentNode = GSON.fromJson(new FileReader(CONFIG_FILE), JsonObject.class).getAsJsonObject(); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } if (parentNode.has("protocol")) { ViaLoadingBase.getClassWrapper().reload(InternalProtocolList.fromProtocolId(parentNode.get("protocol").getAsInt())); } - for (SettingGroup group : viaFabricPlus.getSettingGroups()) { + for (SettingGroup group : groups) { for (AbstractSetting setting : group.getSettings()) { setting.read(parentNode); } @@ -46,20 +77,30 @@ public class SettingsSave { } } - public static void save(final ViaFabricPlus viaFabricPlus) throws IOException { + public void save() { CONFIG_FILE.delete(); - CONFIG_FILE.createNewFile(); + try { + CONFIG_FILE.createNewFile(); + } catch (IOException e) { + throw new RuntimeException(e); + } try (final FileWriter fw = new FileWriter(CONFIG_FILE)) { final JsonObject parentNode = new JsonObject(); parentNode.addProperty("protocol", ViaLoadingBase.getClassWrapper().getTargetVersion().getVersion()); - for (SettingGroup group : viaFabricPlus.getSettingGroups()) { + for (SettingGroup group : groups) { for (AbstractSetting setting : group.getSettings()) { setting.write(parentNode); } } fw.write(GSON.toJson(parentNode)); fw.flush(); + } catch (IOException e) { + throw new RuntimeException(e); } } + + public List getGroups() { + return groups; + } } diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/AbstractSetting.java b/src/main/java/de/florianmichael/viafabricplus/settings/base/AbstractSetting.java similarity index 96% rename from src/main/java/de/florianmichael/viafabricplus/settings/AbstractSetting.java rename to src/main/java/de/florianmichael/viafabricplus/settings/base/AbstractSetting.java index ec70b565..e4a4c7bf 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/AbstractSetting.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/base/AbstractSetting.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.settings; +package de.florianmichael.viafabricplus.settings.base; import com.google.gson.JsonObject; diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/SettingGroup.java b/src/main/java/de/florianmichael/viafabricplus/settings/base/SettingGroup.java similarity index 95% rename from src/main/java/de/florianmichael/viafabricplus/settings/SettingGroup.java rename to src/main/java/de/florianmichael/viafabricplus/settings/base/SettingGroup.java index 77cb345f..677ea05d 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/SettingGroup.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/base/SettingGroup.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.settings; +package de.florianmichael.viafabricplus.settings.base; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/groups/BridgeSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/groups/BridgeSettings.java index e04832a7..b40bcf74 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/groups/BridgeSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/groups/BridgeSettings.java @@ -17,8 +17,8 @@ */ package de.florianmichael.viafabricplus.settings.groups; -import de.florianmichael.viafabricplus.settings.SettingGroup; -import de.florianmichael.viafabricplus.settings.impl.BooleanSetting; +import de.florianmichael.viafabricplus.settings.base.SettingGroup; +import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting; public class BridgeSettings extends SettingGroup { private final static BridgeSettings self = new BridgeSettings(); diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/groups/DebugSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/groups/DebugSettings.java index 4291f88d..f8801bee 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/groups/DebugSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/groups/DebugSettings.java @@ -18,8 +18,8 @@ package de.florianmichael.viafabricplus.settings.groups; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viafabricplus.settings.SettingGroup; -import de.florianmichael.viafabricplus.settings.impl.ProtocolSyncBooleanSetting; +import de.florianmichael.viafabricplus.settings.base.SettingGroup; +import de.florianmichael.viafabricplus.settings.type_impl.ProtocolSyncBooleanSetting; import de.florianmichael.vialoadingbase.platform.ProtocolRange; import net.raphimc.vialegacy.api.LegacyProtocolVersion; diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/groups/GeneralSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/groups/GeneralSettings.java index de9abd1c..3634f0fb 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/groups/GeneralSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/groups/GeneralSettings.java @@ -17,9 +17,9 @@ */ package de.florianmichael.viafabricplus.settings.groups; -import de.florianmichael.viafabricplus.settings.SettingGroup; -import de.florianmichael.viafabricplus.settings.impl.BooleanSetting; -import de.florianmichael.viafabricplus.settings.impl.ModeSetting; +import de.florianmichael.viafabricplus.settings.base.SettingGroup; +import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting; +import de.florianmichael.viafabricplus.settings.type_impl.ModeSetting; public class GeneralSettings extends SettingGroup { private final static GeneralSettings self = new GeneralSettings(); diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/groups/MPPassSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/groups/MPPassSettings.java index e878b0ed..ff2904ef 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/groups/MPPassSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/groups/MPPassSettings.java @@ -17,8 +17,8 @@ */ package de.florianmichael.viafabricplus.settings.groups; -import de.florianmichael.viafabricplus.settings.SettingGroup; -import de.florianmichael.viafabricplus.settings.impl.BooleanSetting; +import de.florianmichael.viafabricplus.settings.base.SettingGroup; +import de.florianmichael.viafabricplus.settings.type_impl.BooleanSetting; public class MPPassSettings extends SettingGroup { private final static MPPassSettings self = new MPPassSettings(); diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/groups/VisualSettings.java b/src/main/java/de/florianmichael/viafabricplus/settings/groups/VisualSettings.java index ee2064ff..a4ac0402 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/groups/VisualSettings.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/groups/VisualSettings.java @@ -18,8 +18,8 @@ package de.florianmichael.viafabricplus.settings.groups; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; -import de.florianmichael.viafabricplus.settings.SettingGroup; -import de.florianmichael.viafabricplus.settings.impl.ProtocolSyncBooleanSetting; +import de.florianmichael.viafabricplus.settings.base.SettingGroup; +import de.florianmichael.viafabricplus.settings.type_impl.ProtocolSyncBooleanSetting; import de.florianmichael.vialoadingbase.platform.ProtocolRange; import net.raphimc.vialegacy.api.LegacyProtocolVersion; diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/BooleanSetting.java b/src/main/java/de/florianmichael/viafabricplus/settings/type_impl/BooleanSetting.java similarity index 87% rename from src/main/java/de/florianmichael/viafabricplus/settings/impl/BooleanSetting.java rename to src/main/java/de/florianmichael/viafabricplus/settings/type_impl/BooleanSetting.java index c0e3a4c9..52ed8753 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/BooleanSetting.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/type_impl/BooleanSetting.java @@ -15,11 +15,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.settings.impl; +package de.florianmichael.viafabricplus.settings.type_impl; import com.google.gson.JsonObject; -import de.florianmichael.viafabricplus.settings.AbstractSetting; -import de.florianmichael.viafabricplus.settings.SettingGroup; +import de.florianmichael.viafabricplus.settings.base.AbstractSetting; +import de.florianmichael.viafabricplus.settings.base.SettingGroup; public class BooleanSetting extends AbstractSetting { diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/ModeSetting.java b/src/main/java/de/florianmichael/viafabricplus/settings/type_impl/ModeSetting.java similarity index 89% rename from src/main/java/de/florianmichael/viafabricplus/settings/impl/ModeSetting.java rename to src/main/java/de/florianmichael/viafabricplus/settings/type_impl/ModeSetting.java index 56550e79..427fae43 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/ModeSetting.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/type_impl/ModeSetting.java @@ -15,11 +15,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.settings.impl; +package de.florianmichael.viafabricplus.settings.type_impl; import com.google.gson.JsonObject; -import de.florianmichael.viafabricplus.settings.AbstractSetting; -import de.florianmichael.viafabricplus.settings.SettingGroup; +import de.florianmichael.viafabricplus.settings.base.AbstractSetting; +import de.florianmichael.viafabricplus.settings.base.SettingGroup; import java.util.Arrays; diff --git a/src/main/java/de/florianmichael/viafabricplus/settings/impl/ProtocolSyncBooleanSetting.java b/src/main/java/de/florianmichael/viafabricplus/settings/type_impl/ProtocolSyncBooleanSetting.java similarity index 94% rename from src/main/java/de/florianmichael/viafabricplus/settings/impl/ProtocolSyncBooleanSetting.java rename to src/main/java/de/florianmichael/viafabricplus/settings/type_impl/ProtocolSyncBooleanSetting.java index e70f45de..0d10766b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/settings/impl/ProtocolSyncBooleanSetting.java +++ b/src/main/java/de/florianmichael/viafabricplus/settings/type_impl/ProtocolSyncBooleanSetting.java @@ -15,10 +15,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.settings.impl; +package de.florianmichael.viafabricplus.settings.type_impl; import com.google.gson.JsonObject; -import de.florianmichael.viafabricplus.settings.SettingGroup; +import de.florianmichael.viafabricplus.settings.base.SettingGroup; import de.florianmichael.viafabricplus.settings.groups.GeneralSettings; import de.florianmichael.vialoadingbase.ViaLoadingBase; import de.florianmichael.vialoadingbase.platform.ProtocolRange; diff --git a/src/main/java/de/florianmichael/viafabricplus/translator/ItemTranslator.java b/src/main/java/de/florianmichael/viafabricplus/util/ItemTranslator.java similarity index 98% rename from src/main/java/de/florianmichael/viafabricplus/translator/ItemTranslator.java rename to src/main/java/de/florianmichael/viafabricplus/util/ItemTranslator.java index f175f556..f21c8907 100644 --- a/src/main/java/de/florianmichael/viafabricplus/translator/ItemTranslator.java +++ b/src/main/java/de/florianmichael/viafabricplus/util/ItemTranslator.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.translator; +package de.florianmichael.viafabricplus.util; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; diff --git a/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/ViaLoadingBaseStartup.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/ViaLoadingBaseStartup.java new file mode 100644 index 00000000..83c8b596 --- /dev/null +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/ViaLoadingBaseStartup.java @@ -0,0 +1,101 @@ +/* + * This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus + * Copyright (C) 2021-2023 FlorianMichael/MrLookAtMe (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 . + */ +package de.florianmichael.viafabricplus.vialoadingbase; + +import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; +import de.florianmichael.viafabricplus.ViaFabricPlus; +import de.florianmichael.viafabricplus.definition.v1_19_0.provider.CommandArgumentsProvider; +import de.florianmichael.viafabricplus.event.ChangeProtocolVersionListener; +import de.florianmichael.viafabricplus.event.FinishViaLoadingBaseStartupListener; +import de.florianmichael.viafabricplus.vialoadingbase.platform.ViaAprilFoolsPlatformImpl; +import de.florianmichael.viafabricplus.vialoadingbase.platform.ViaBedrockPlatformImpl; +import de.florianmichael.viafabricplus.vialoadingbase.platform.ViaLegacyPlatformImpl; +import de.florianmichael.viafabricplus.vialoadingbase.provider.*; +import de.florianmichael.vialoadingbase.ViaLoadingBase; +import de.florianmichael.vialoadingbase.platform.SubPlatform; +import io.netty.util.AttributeKey; +import net.minecraft.SharedConstants; +import net.minecraft.client.MinecraftClient; +import net.minecraft.network.ClientConnection; +import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion; +import net.raphimc.viabedrock.api.BedrockProtocolVersion; +import net.raphimc.viabedrock.protocol.providers.NettyPipelineProvider; +import net.raphimc.vialegacy.api.LegacyProtocolVersion; +import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicCustomCommandProvider; +import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider; +import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider; +import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider; +import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.providers.EncryptionProvider; +import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.GameProfileFetcher; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class ViaLoadingBaseStartup { + public final static AttributeKey LOCAL_VIA_CONNECTION = AttributeKey.newInstance("viafabricplus-via-connection"); + public final static AttributeKey LOCAL_MINECRAFT_CONNECTION = AttributeKey.newInstance("viafabricplus-minecraft-connection"); + + public ViaLoadingBaseStartup() { + ViaLoadingBase.ViaLoadingBaseBuilder builder = ViaLoadingBase.ViaLoadingBaseBuilder.create(); + + builder = builder.subPlatform(new SubPlatform("ViaBedrock", () -> true, ViaBedrockPlatformImpl::new, protocolVersions -> protocolVersions.add(BedrockProtocolVersion.bedrockLatest)), 0); + builder = builder.subPlatform(new SubPlatform("ViaLegacy", () -> true, ViaLegacyPlatformImpl::new, protocolVersions -> { + final List legacyProtocols = new ArrayList<>(LegacyProtocolVersion.PROTOCOLS); + Collections.reverse(legacyProtocols); + + legacyProtocols.remove(LegacyProtocolVersion.c0_30cpe); + legacyProtocols.add(legacyProtocols.indexOf(LegacyProtocolVersion.c0_28toc0_30) + 1, LegacyProtocolVersion.c0_30cpe); + + protocolVersions.addAll(legacyProtocols); + })); + builder = builder.subPlatform(new SubPlatform("ViaAprilFools", () -> true, ViaAprilFoolsPlatformImpl::new, protocolVersions -> { + protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_14) + 1, AprilFoolsProtocolVersion.s3d_shareware); + protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_16) + 1, AprilFoolsProtocolVersion.s20w14infinite); + protocolVersions.add(protocolVersions.indexOf(ProtocolVersion.v1_16_2) + 1, AprilFoolsProtocolVersion.sCombatTest8c); + })); + + builder = builder.runDirectory(ViaFabricPlus.RUN_DIRECTORY); + builder = builder.nativeVersion(SharedConstants.getProtocolVersion()); + builder = builder.forceNativeVersionCondition(() -> { + if (MinecraftClient.getInstance() == null) return true; + + return MinecraftClient.getInstance().isInSingleplayer(); + }); + builder = builder.providers(providers -> { + providers.use(MovementTransmitterProvider.class, new ViaFabricPlusMovementTransmitterProvider()); + providers.use(HandItemProvider.class, new ViaFabricPlusHandItemProvider()); + + providers.use(CommandArgumentsProvider.class, new ViaFabricPlusCommandArgumentsProvider()); + + providers.use(OldAuthProvider.class, new ViaFabricPlusOldAuthProvider()); + providers.use(ClassicWorldHeightProvider.class, new ViaFabricPlusClassicWorldHeightProvider()); + providers.use(EncryptionProvider.class, new ViaFabricPlusEncryptionProvider()); + providers.use(GameProfileFetcher.class, new ViaFabricPlusGameProfileFetcher()); + providers.use(ClassicMPPassProvider.class, new ViaFabricPlusClassicMPPassProvider()); + providers.use(ClassicCustomCommandProvider.class, new ViaFabricPlusClassicCustomCommandProvider()); + providers.use(NettyPipelineProvider.class, new ViaFabricPlusNettyPipelineProvider()); + }); + builder = builder.onProtocolReload(protocolVersion -> ViaFabricPlus.INSTANCE.getEventDispatcher().post(new ChangeProtocolVersionListener.ChangeProtocolVersionEvent(protocolVersion))); + builder.build(); + ViaFabricPlus.INSTANCE.getEventDispatcher().post(new FinishViaLoadingBaseStartupListener.FinishViaLoadingBaseStartupEvent()); + } +} diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/VFPVLBViaDecodeHandler.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/VFPVLBViaDecodeHandler.java similarity index 96% rename from src/main/java/de/florianmichael/viafabricplus/platform/VFPVLBViaDecodeHandler.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/VFPVLBViaDecodeHandler.java index c0809067..a0111234 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/VFPVLBViaDecodeHandler.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/VFPVLBViaDecodeHandler.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform; +package de.florianmichael.viafabricplus.vialoadingbase.platform; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/ViaAprilFoolsPlatformImpl.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/ViaAprilFoolsPlatformImpl.java similarity index 95% rename from src/main/java/de/florianmichael/viafabricplus/platform/ViaAprilFoolsPlatformImpl.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/ViaAprilFoolsPlatformImpl.java index 6e33fb8b..3dc8c5ba 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/ViaAprilFoolsPlatformImpl.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/ViaAprilFoolsPlatformImpl.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform; +package de.florianmichael.viafabricplus.vialoadingbase.platform; import com.viaversion.viaversion.api.Via; import de.florianmichael.vialoadingbase.util.JLoggerToLog4j; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/ViaBedrockPlatformImpl.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/ViaBedrockPlatformImpl.java similarity index 95% rename from src/main/java/de/florianmichael/viafabricplus/platform/ViaBedrockPlatformImpl.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/ViaBedrockPlatformImpl.java index 01ab853e..615855f4 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/ViaBedrockPlatformImpl.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/ViaBedrockPlatformImpl.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform; +package de.florianmichael.viafabricplus.vialoadingbase.platform; import com.viaversion.viaversion.api.Via; import de.florianmichael.vialoadingbase.util.JLoggerToLog4j; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/ViaLegacyPlatformImpl.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/ViaLegacyPlatformImpl.java similarity index 95% rename from src/main/java/de/florianmichael/viafabricplus/platform/ViaLegacyPlatformImpl.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/ViaLegacyPlatformImpl.java index a82a6c8a..e814b390 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/ViaLegacyPlatformImpl.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/ViaLegacyPlatformImpl.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform; +package de.florianmichael.viafabricplus.vialoadingbase.platform; import com.viaversion.viaversion.api.Via; import de.florianmichael.vialoadingbase.util.JLoggerToLog4j; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/pre_netty/PreNettyConstants.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/pre_netty/PreNettyConstants.java similarity index 93% rename from src/main/java/de/florianmichael/viafabricplus/platform/pre_netty/PreNettyConstants.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/pre_netty/PreNettyConstants.java index 63225064..752ae0a6 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/pre_netty/PreNettyConstants.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/pre_netty/PreNettyConstants.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform.pre_netty; +package de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty; public class PreNettyConstants { diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/pre_netty/VFPPreNettyDecoder.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/pre_netty/VFPPreNettyDecoder.java similarity index 95% rename from src/main/java/de/florianmichael/viafabricplus/platform/pre_netty/VFPPreNettyDecoder.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/pre_netty/VFPPreNettyDecoder.java index bf59aa16..7f246b69 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/pre_netty/VFPPreNettyDecoder.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/pre_netty/VFPPreNettyDecoder.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform.pre_netty; +package de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/pre_netty/VFPPreNettyEncoder.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/pre_netty/VFPPreNettyEncoder.java similarity index 95% rename from src/main/java/de/florianmichael/viafabricplus/platform/pre_netty/VFPPreNettyEncoder.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/pre_netty/VFPPreNettyEncoder.java index 3b9997de..1bc4f36a 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/pre_netty/VFPPreNettyEncoder.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/pre_netty/VFPPreNettyEncoder.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform.pre_netty; +package de.florianmichael.viafabricplus.vialoadingbase.platform.pre_netty; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/BedrockRakNetConstants.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/BedrockRakNetConstants.java similarity index 95% rename from src/main/java/de/florianmichael/viafabricplus/platform/raknet/BedrockRakNetConstants.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/BedrockRakNetConstants.java index 1e8a1110..46b569de 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/BedrockRakNetConstants.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/BedrockRakNetConstants.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform.raknet; +package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet; public class BedrockRakNetConstants { diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/DisconnectHandler.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/DisconnectHandler.java similarity index 95% rename from src/main/java/de/florianmichael/viafabricplus/platform/raknet/DisconnectHandler.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/DisconnectHandler.java index 37e3d973..54928ee0 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/DisconnectHandler.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/DisconnectHandler.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform.raknet; +package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandlerAdapter; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/PingEncapsulationCodec.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/PingEncapsulationCodec.java similarity index 97% rename from src/main/java/de/florianmichael/viafabricplus/platform/raknet/PingEncapsulationCodec.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/PingEncapsulationCodec.java index d4c15030..3adbd34e 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/PingEncapsulationCodec.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/PingEncapsulationCodec.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform.raknet; +package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/RakMessageEncapsulationCodec.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/RakMessageEncapsulationCodec.java similarity index 96% rename from src/main/java/de/florianmichael/viafabricplus/platform/raknet/RakMessageEncapsulationCodec.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/RakMessageEncapsulationCodec.java index 2aa3aece..d6fcf410 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/RakMessageEncapsulationCodec.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/RakMessageEncapsulationCodec.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform.raknet; +package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet; import io.netty.buffer.ByteBuf; import io.netty.buffer.CompositeByteBuf; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/RakNetPingSessions.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/RakNetPingSessions.java similarity index 94% rename from src/main/java/de/florianmichael/viafabricplus/platform/raknet/RakNetPingSessions.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/RakNetPingSessions.java index efba61b7..eb0c28df 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/RakNetPingSessions.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/RakNetPingSessions.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform.raknet; +package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet; import java.net.InetAddress; import java.util.ArrayList; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/library_fix/FixedUnconnectedPingEncoder.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/library_fix/FixedUnconnectedPingEncoder.java similarity index 96% rename from src/main/java/de/florianmichael/viafabricplus/platform/raknet/library_fix/FixedUnconnectedPingEncoder.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/library_fix/FixedUnconnectedPingEncoder.java index d87aa1db..63eef036 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/library_fix/FixedUnconnectedPingEncoder.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/library_fix/FixedUnconnectedPingEncoder.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform.raknet.library_fix; +package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.library_fix; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/library_fix/FixedUnconnectedPongDecoder.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/library_fix/FixedUnconnectedPongDecoder.java similarity index 97% rename from src/main/java/de/florianmichael/viafabricplus/platform/raknet/library_fix/FixedUnconnectedPongDecoder.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/library_fix/FixedUnconnectedPongDecoder.java index d5df8d4e..a78f7727 100644 --- a/src/main/java/de/florianmichael/viafabricplus/platform/raknet/library_fix/FixedUnconnectedPongDecoder.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/platform/raknet/library_fix/FixedUnconnectedPongDecoder.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.platform.raknet.library_fix; +package de.florianmichael.viafabricplus.vialoadingbase.platform.raknet.library_fix; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; diff --git a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusClassicCustomCommandProvider.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusClassicCustomCommandProvider.java similarity index 97% rename from src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusClassicCustomCommandProvider.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusClassicCustomCommandProvider.java index d4168a30..f7ecdea3 100644 --- a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusClassicCustomCommandProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusClassicCustomCommandProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.provider; +package de.florianmichael.viafabricplus.vialoadingbase.provider; import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viafabricplus.definition.c0_30.command.ClassicProtocolCommands; diff --git a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusClassicMPPassProvider.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusClassicMPPassProvider.java similarity index 96% rename from src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusClassicMPPassProvider.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusClassicMPPassProvider.java index daac81d4..1eaa4b43 100644 --- a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusClassicMPPassProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusClassicMPPassProvider.java @@ -15,13 +15,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.provider; +package de.florianmichael.viafabricplus.vialoadingbase.provider; import com.google.common.hash.Hashing; import com.google.common.io.Resources; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; -import de.florianmichael.viafabricplus.settings.groups.GeneralSettings; import de.florianmichael.viafabricplus.settings.groups.MPPassSettings; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider; import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider; diff --git a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusClassicWorldHeightProvider.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusClassicWorldHeightProvider.java similarity index 94% rename from src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusClassicWorldHeightProvider.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusClassicWorldHeightProvider.java index 1bc51c65..5bb1628f 100644 --- a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusClassicWorldHeightProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusClassicWorldHeightProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.provider; +package de.florianmichael.viafabricplus.vialoadingbase.provider; import com.viaversion.viaversion.api.connection.UserConnection; import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider; diff --git a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusCommandArgumentsProvider.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusCommandArgumentsProvider.java similarity index 96% rename from src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusCommandArgumentsProvider.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusCommandArgumentsProvider.java index 3369469b..6f7c4ef3 100644 --- a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusCommandArgumentsProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusCommandArgumentsProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.provider; +package de.florianmichael.viafabricplus.vialoadingbase.provider; import com.viaversion.viaversion.util.Pair; import de.florianmichael.viafabricplus.definition.v1_19_0.provider.CommandArgumentsProvider; diff --git a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusEncryptionProvider.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusEncryptionProvider.java similarity index 87% rename from src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusEncryptionProvider.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusEncryptionProvider.java index e0a2fa94..e73c6bb9 100644 --- a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusEncryptionProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusEncryptionProvider.java @@ -15,11 +15,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.provider; +package de.florianmichael.viafabricplus.vialoadingbase.provider; import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.injection.access.IClientConnection; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import net.minecraft.network.ClientConnection; import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.providers.EncryptionProvider; @@ -27,7 +28,7 @@ public class ViaFabricPlusEncryptionProvider extends EncryptionProvider { @Override public void enableDecryption(UserConnection user) { - final ClientConnection clientConnection = user.getChannel().attr(ViaFabricPlus.LOCAL_MINECRAFT_CONNECTION).get(); + final ClientConnection clientConnection = user.getChannel().attr(ViaLoadingBaseStartup.LOCAL_MINECRAFT_CONNECTION).get(); if (clientConnection != null) { ((IClientConnection) clientConnection).viafabricplus_setupPreNettyEncryption(); } diff --git a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusGameProfileFetcher.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusGameProfileFetcher.java similarity index 98% rename from src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusGameProfileFetcher.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusGameProfileFetcher.java index b2ad56b0..2202ce43 100644 --- a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusGameProfileFetcher.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusGameProfileFetcher.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.provider; +package de.florianmichael.viafabricplus.vialoadingbase.provider; import com.mojang.authlib.Agent; import com.mojang.authlib.GameProfileRepository; diff --git a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusHandItemProvider.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusHandItemProvider.java similarity index 92% rename from src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusHandItemProvider.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusHandItemProvider.java index 2182faea..23192e2b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusHandItemProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusHandItemProvider.java @@ -15,13 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.provider; +package de.florianmichael.viafabricplus.vialoadingbase.provider; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider; -import de.florianmichael.viafabricplus.translator.ItemTranslator; +import de.florianmichael.viafabricplus.util.ItemTranslator; import net.minecraft.item.ItemStack; public class ViaFabricPlusHandItemProvider extends HandItemProvider { diff --git a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusMovementTransmitterProvider.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusMovementTransmitterProvider.java similarity index 95% rename from src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusMovementTransmitterProvider.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusMovementTransmitterProvider.java index 752d5c74..e6aaddf9 100644 --- a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusMovementTransmitterProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusMovementTransmitterProvider.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.provider; +package de.florianmichael.viafabricplus.vialoadingbase.provider; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; diff --git a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusNettyPipelineProvider.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusNettyPipelineProvider.java similarity index 88% rename from src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusNettyPipelineProvider.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusNettyPipelineProvider.java index c3d35407..91f82b55 100644 --- a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusNettyPipelineProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusNettyPipelineProvider.java @@ -15,11 +15,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.provider; +package de.florianmichael.viafabricplus.vialoadingbase.provider; import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.injection.access.IClientConnection; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import net.raphimc.viabedrock.protocol.providers.NettyPipelineProvider; import javax.crypto.NoSuchPaddingException; @@ -32,7 +33,7 @@ public class ViaFabricPlusNettyPipelineProvider extends NettyPipelineProvider { @Override public void enableCompression(UserConnection user, int threshold, int algorithm) { - final IClientConnection currentConnection = (IClientConnection) user.getChannel().attr(ViaFabricPlus.LOCAL_MINECRAFT_CONNECTION).get(); + final IClientConnection currentConnection = (IClientConnection) user.getChannel().attr(ViaLoadingBaseStartup.LOCAL_MINECRAFT_CONNECTION).get(); try { switch (algorithm) { @@ -48,7 +49,7 @@ public class ViaFabricPlusNettyPipelineProvider extends NettyPipelineProvider { @Override public void enableEncryption(UserConnection user, SecretKey key) { - final IClientConnection currentConnection = (IClientConnection) user.getChannel().attr(ViaFabricPlus.LOCAL_MINECRAFT_CONNECTION).get(); + final IClientConnection currentConnection = (IClientConnection) user.getChannel().attr(ViaLoadingBaseStartup.LOCAL_MINECRAFT_CONNECTION).get(); try { currentConnection.viafabricplus_enableAesGcmEncryption(key); diff --git a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusOldAuthProvider.java b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusOldAuthProvider.java similarity index 81% rename from src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusOldAuthProvider.java rename to src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusOldAuthProvider.java index 2c29646b..4fb72a05 100644 --- a/src/main/java/de/florianmichael/viafabricplus/provider/ViaFabricPlusOldAuthProvider.java +++ b/src/main/java/de/florianmichael/viafabricplus/vialoadingbase/provider/ViaFabricPlusOldAuthProvider.java @@ -15,12 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package de.florianmichael.viafabricplus.provider; +package de.florianmichael.viafabricplus.vialoadingbase.provider; import com.viaversion.viaversion.api.connection.UserConnection; import de.florianmichael.viafabricplus.ViaFabricPlus; import de.florianmichael.viafabricplus.settings.groups.MPPassSettings; import de.florianmichael.viafabricplus.util.ScreenUtil; +import de.florianmichael.viafabricplus.vialoadingbase.ViaLoadingBaseStartup; import net.minecraft.client.MinecraftClient; import net.minecraft.text.Text; import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider; @@ -37,7 +38,7 @@ public class ViaFabricPlusOldAuthProvider extends OldAuthProvider { mc.getSessionService().joinServer(mc.getSession().getProfile(), mc.getSession().getAccessToken(), serverId); } catch (Exception e) { if (MPPassSettings.getClassWrapper().disconnectIfJoinServerCallFails.getValue()) { - user.getChannel().attr(ViaFabricPlus.LOCAL_MINECRAFT_CONNECTION).get().disconnect(Text.literal(ScreenUtil.prefixedMessage("ViaLegacy fails to verify your session! Please log in into an Account or disable the BetaCraft authentication in the ViaFabricPlus Settings"))); + user.getChannel().attr(ViaLoadingBaseStartup.LOCAL_MINECRAFT_CONNECTION).get().disconnect(Text.literal(ScreenUtil.prefixedMessage("ViaLegacy fails to verify your session! Please log in into an Account or disable the BetaCraft authentication in the ViaFabricPlus Settings"))); } else { e.printStackTrace(); }