diff --git a/build.gradle b/build.gradle index 51d24591..88c70992 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,9 @@ plugins { id 'maven-publish' - id 'net.neoforged.gradle.userdev' version '7.0.96' + id 'net.neoforged.gradle.userdev' version '7.0.120' id 'com.github.johnrengelman.shadow' version '8.1.1' id 'org.cadixdev.licenser' version '0.6.1' - id 'tk.sciwhiz12.gradle.simplversion' version '0.1.0' + id 'dev.sciwhiz12.gradle.simplversion' version '0.2.0' } versions { @@ -111,7 +111,7 @@ tasks.withType(Jar).configureEach { reproducibleFileOrder = true // Normalize line endings from CRLF to LF - filesMatching('META-INF/mods.toml') { + filesMatching('META-INF/neoforge.mods.toml') { //noinspection UnnecessaryQualifiedReference filter(org.apache.tools.ant.filters.FixCrLfFilter.class, eol: org.apache.tools.ant.filters.FixCrLfFilter.CrLf.newInstance('lf')) diff --git a/gradle.properties b/gradle.properties index 512fb78b..765356c3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,16 +9,16 @@ neogradle.subsystems.decompiler.maxMemory=4g org.gradle.caching=true # Minecraft, Forge, and mappings versions -mc_version=1.20.4 -neoforge_version=20.4.182 +mc_version=1.20.6 +neoforge_version=20.6.62-beta mappings_channel=parchment -mappings_version=2023.08.06-1.20.1 -java_version=17 +mappings_version=2024.05.01 +java_version=21 # Logging markers and console logging level logging_markers=REGISTRIES logging_console=debug # Versions of dependencies -jda_version=5.0.0-beta.20 +jda_version=5.0.0-beta.24 webhook_version=0.8.4 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d64cd491..e6441136 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a80b22ce..b82aa23a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/data/java/dev/sciwhiz12/concord/datagen/DataGeneration.java b/src/data/java/dev/sciwhiz12/concord/datagen/DataGeneration.java index af6cf5d2..2fc65f3a 100644 --- a/src/data/java/dev/sciwhiz12/concord/datagen/DataGeneration.java +++ b/src/data/java/dev/sciwhiz12/concord/datagen/DataGeneration.java @@ -32,12 +32,12 @@ import net.minecraft.server.packs.metadata.pack.PackMetadataSection; import net.minecraft.util.InclusiveRange; import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; +import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.data.event.GatherDataEvent; import java.util.Optional; -@Mod.EventBusSubscriber(modid = Concord.MODID, bus = Mod.EventBusSubscriber.Bus.MOD) +@EventBusSubscriber(modid = Concord.MODID, bus = EventBusSubscriber.Bus.MOD) public class DataGeneration { @SubscribeEvent static void onGatherData(GatherDataEvent event) { diff --git a/src/data/resources/.cache/0f202e000d40347127b33b6edbbb29689b8cbf86 b/src/data/resources/.cache/0f202e000d40347127b33b6edbbb29689b8cbf86 index 9f461354..36ec798c 100644 --- a/src/data/resources/.cache/0f202e000d40347127b33b6edbbb29689b8cbf86 +++ b/src/data/resources/.cache/0f202e000d40347127b33b6edbbb29689b8cbf86 @@ -1,2 +1,2 @@ -// 1.20.4 2024-02-29T05:09:37.7276443 Pack Metadata -6640faea5dcd2503e4ce56c9abce87dce67ea86d pack.mcmeta +// 1.20.6 2024-05-13T21:50:15.7912936 Pack Metadata +e6104518bcfaf9d156fa44714a7934fce53b4660 pack.mcmeta diff --git a/src/data/resources/.cache/2e01598ed0d2f87cdb26ab1befacb73da33cab44 b/src/data/resources/.cache/2e01598ed0d2f87cdb26ab1befacb73da33cab44 index 6f17427b..d5bbe420 100644 --- a/src/data/resources/.cache/2e01598ed0d2f87cdb26ab1befacb73da33cab44 +++ b/src/data/resources/.cache/2e01598ed0d2f87cdb26ab1befacb73da33cab44 @@ -1,2 +1,2 @@ -// 1.20.4 2024-03-01T06:11:22.5691513 Languages: en_us for mod: concord +// 1.20.6 2024-05-13T21:50:15.788291 Languages: en_us for mod: concord 9aada5c1a216ea46fcf82e4f1c65fe748c2bd007 assets/concord/lang/en_us.json diff --git a/src/data/resources/pack.mcmeta b/src/data/resources/pack.mcmeta index 7cad561f..8cc07dd3 100644 --- a/src/data/resources/pack.mcmeta +++ b/src/data/resources/pack.mcmeta @@ -1,10 +1,10 @@ { "pack": { "description": "concord resources", - "pack_format": 26, + "pack_format": 41, "supported_formats": [ - 22, - 26 + 32, + 41 ] } } \ No newline at end of file diff --git a/src/main/java/dev/sciwhiz12/concord/Concord.java b/src/main/java/dev/sciwhiz12/concord/Concord.java index 97f71d0b..2e0cdb86 100644 --- a/src/main/java/dev/sciwhiz12/concord/Concord.java +++ b/src/main/java/dev/sciwhiz12/concord/Concord.java @@ -64,7 +64,6 @@ public Concord(ModContainer container, IEventBus modBus) { // ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, // () -> new IExtensionPoint.DisplayTest(() -> NetworkConstants.IGNORESERVERONLY, (ver, remote) -> true)); ConcordNetwork.register(modBus); - ConcordFeatures.register(modBus); ConcordConfig.register(container); NeoForge.EVENT_BUS.addListener(EventPriority.LOWEST, this::onServerStarting); diff --git a/src/main/java/dev/sciwhiz12/concord/features/ConcordFeatures.java b/src/main/java/dev/sciwhiz12/concord/features/ConcordFeatures.java index 6a9b4b69..56b3c0a8 100644 --- a/src/main/java/dev/sciwhiz12/concord/features/ConcordFeatures.java +++ b/src/main/java/dev/sciwhiz12/concord/features/ConcordFeatures.java @@ -23,42 +23,19 @@ package dev.sciwhiz12.concord.features; import dev.sciwhiz12.concord.Concord; -import net.minecraft.nbt.Tag; -import net.neoforged.bus.api.IEventBus; -import net.neoforged.neoforge.attachment.AttachmentType; -import net.neoforged.neoforge.attachment.IAttachmentHolder; -import net.neoforged.neoforge.attachment.IAttachmentSerializer; -import net.neoforged.neoforge.registries.DeferredRegister; -import net.neoforged.neoforge.registries.NeoForgeRegistries; +import io.netty.util.AttributeKey; +import net.minecraft.server.level.ServerPlayer; import org.apache.maven.artifact.versioning.ArtifactVersion; import javax.annotation.Nullable; import java.util.Map; import java.util.NoSuchElementException; import java.util.Objects; -import java.util.function.Supplier; +import java.util.Optional; public class ConcordFeatures { - private static final DeferredRegister> ATTACHMENT_TYPES = - DeferredRegister.create(NeoForgeRegistries.ATTACHMENT_TYPES, Concord.MODID); - - public static final Supplier> ATTACHMENT = ATTACHMENT_TYPES.register( - "features", () -> AttachmentType.builder(holder -> new ConcordFeatures(Map.of())) - .serialize(new IAttachmentSerializer<>() { - @Override - public @Nullable Tag write(ConcordFeatures attachment) { - return null; - } - - @Override - public ConcordFeatures read(IAttachmentHolder holder, Tag tag) { - throw new UnsupportedOperationException("Attempted to deserialize attachment that can never be serialized"); - } - }) - .copyHandler((holder, attachment) -> new ConcordFeatures(attachment.features)) - .copyOnDeath() - .build() - ); + public static final AttributeKey CHANNEL_ATTRIBUTE_KEY = AttributeKey.newInstance(Concord.MODID +":features"); + public static final ConcordFeatures EMPTY =new ConcordFeatures(Map.of()); private final Map features; @@ -104,8 +81,13 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(features); } - - public static void register(IEventBus modBus) { - ATTACHMENT_TYPES.register(modBus); + + @Nullable + public static ConcordFeatures getOrNull(ServerPlayer player) { + return player.connection.getConnection().channel().attr(CHANNEL_ATTRIBUTE_KEY).get(); + } + + public static ConcordFeatures getOrEmpty(ServerPlayer player) { + return Optional.ofNullable(getOrNull(player)).orElse(EMPTY); } } diff --git a/src/main/java/dev/sciwhiz12/concord/msg/FormattingUtilities.java b/src/main/java/dev/sciwhiz12/concord/msg/FormattingUtilities.java index 886dc13e..9c55235f 100644 --- a/src/main/java/dev/sciwhiz12/concord/msg/FormattingUtilities.java +++ b/src/main/java/dev/sciwhiz12/concord/msg/FormattingUtilities.java @@ -191,7 +191,7 @@ public static MutableComponent processCustomFormatting(String input) { // Make sure that formatting at the end of messages, or lone formatting, is dealt with. final String formatString = firstSpacePosition == -1 ? part.substring(1) : part.substring(1, firstSpacePosition); // Use TextColor's built-in parsing to do the heavy lifting. - final TextColor color = TextColor.parseColor(formatString).get().left().orElse(TextColor.fromLegacyFormat(WHITE)); + final TextColor color = TextColor.parseColor(formatString).result().orElse(TextColor.fromLegacyFormat(WHITE)); // Assign the TextColor into a Style instance so that we can use it with a TextComponent. final Style formatting = Style.EMPTY.withColor(color); diff --git a/src/main/java/dev/sciwhiz12/concord/msg/MessageListener.java b/src/main/java/dev/sciwhiz12/concord/msg/MessageListener.java index e6c40a4c..ab11d6a3 100644 --- a/src/main/java/dev/sciwhiz12/concord/msg/MessageListener.java +++ b/src/main/java/dev/sciwhiz12/concord/msg/MessageListener.java @@ -34,7 +34,7 @@ import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.ServerChatEvent; -import net.neoforged.neoforge.event.TickEvent; +import net.neoforged.neoforge.event.tick.ServerTickEvent; import java.util.Objects; @@ -69,8 +69,7 @@ public void onMessageReceived(MessageReceivedEvent event) { } @SubscribeEvent - void onServerTick(TickEvent.ServerTickEvent event) { - if (event.phase != TickEvent.Phase.END) return; + void onServerTickPost(ServerTickEvent.Post event) { bot.messaging().processMessages(); } diff --git a/src/main/java/dev/sciwhiz12/concord/msg/Messaging.java b/src/main/java/dev/sciwhiz12/concord/msg/Messaging.java index 5b39f8f4..2c12bf76 100644 --- a/src/main/java/dev/sciwhiz12/concord/msg/Messaging.java +++ b/src/main/java/dev/sciwhiz12/concord/msg/Messaging.java @@ -194,7 +194,7 @@ static record DiscordBound(String message, CompletableFuture future) im private static final DefaultArtifactVersion ZERO_VERSION = new DefaultArtifactVersion("0.0.0"); static ArtifactVersion getFeatureVersionWithDefault(ServerPlayer player, FeatureVersion feature) { - final @Nullable ArtifactVersion version = player.getData(ConcordFeatures.ATTACHMENT).getFeature(feature); + final @Nullable ArtifactVersion version = ConcordFeatures.getOrEmpty(player).getFeature(feature); if (version == null) return ZERO_VERSION; return version; } diff --git a/src/main/java/dev/sciwhiz12/concord/network/ConcordNetwork.java b/src/main/java/dev/sciwhiz12/concord/network/ConcordNetwork.java index 8f7f5c18..066c6ebb 100644 --- a/src/main/java/dev/sciwhiz12/concord/network/ConcordNetwork.java +++ b/src/main/java/dev/sciwhiz12/concord/network/ConcordNetwork.java @@ -27,10 +27,10 @@ import dev.sciwhiz12.concord.features.FeatureVersion; import net.minecraft.Util; import net.neoforged.bus.api.IEventBus; -import net.neoforged.neoforge.network.event.OnGameConfigurationEvent; -import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent; +import net.neoforged.neoforge.network.event.RegisterConfigurationTasksEvent; +import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; import net.neoforged.neoforge.network.handling.IPayloadContext; -import net.neoforged.neoforge.network.registration.IPayloadRegistrar; +import net.neoforged.neoforge.network.registration.PayloadRegistrar; import org.apache.maven.artifact.versioning.ArtifactVersion; import java.util.Arrays; @@ -42,27 +42,31 @@ public static void register(IEventBus modBus) { modBus.addListener(ConcordNetwork::onGatherPayloads); } - static void onRegisterPayloadHandlers(RegisterPayloadHandlerEvent event) { - final IPayloadRegistrar registrar = event.registrar(Concord.MODID) + static void onRegisterPayloadHandlers(RegisterPayloadHandlersEvent event) { + final PayloadRegistrar registrar = event.registrar(Concord.MODID) .optional(); - registrar.configuration(FeaturesPayload.ID, FeaturesPayload::read, - handlers -> handlers - .client(ConcordNetwork::handleClient) - .server(ConcordNetwork::handleServer)); + registrar.configurationBidirectional(FeaturesPayload.TYPE, FeaturesPayload.STREAM_CODEC, ConcordNetwork::handle); } - static void onGatherPayloads(OnGameConfigurationEvent event) { + static void onGatherPayloads(RegisterConfigurationTasksEvent event) { event.register(new FeaturesTask(event.getListener())); } + static void handle(FeaturesPayload payload, IPayloadContext context) { + switch (context.flow()) { + case CLIENTBOUND -> handleClient(payload, context); + case SERVERBOUND -> handleServer(payload, context); + } + } + static void handleClient(FeaturesPayload payload, IPayloadContext context) { // Received the payload from the server, so we know the server has Concord enabled // Send back our own payload, to inform the server that we, the client, have Concord enabled too final Map features = Arrays.stream(FeatureVersion.values()) .map(f -> Map.entry(f.featureName(), f.currentVersion())) .collect(Util.toMap()); - context.replyHandler().send(new FeaturesPayload(features)); + context.reply(new FeaturesPayload(features)); // In the future, we can use the info from the payload to decide on what we are going to do // For now, the features payload is a 'ping' for server->client @@ -71,7 +75,6 @@ static void handleClient(FeaturesPayload payload, IPayloadContext context) { static void handleServer(FeaturesPayload payload, IPayloadContext context) { // The client sent back the features payload, so it has Concord enabled // Store the features info it sent - context.player().ifPresent(player -> - player.setData(ConcordFeatures.ATTACHMENT, new ConcordFeatures(payload.features()))); + context.connection().channel().attr(ConcordFeatures.CHANNEL_ATTRIBUTE_KEY).set(new ConcordFeatures(payload.features())); } } diff --git a/src/main/java/dev/sciwhiz12/concord/network/FeaturesPayload.java b/src/main/java/dev/sciwhiz12/concord/network/FeaturesPayload.java index 0309aeab..840113a2 100644 --- a/src/main/java/dev/sciwhiz12/concord/network/FeaturesPayload.java +++ b/src/main/java/dev/sciwhiz12/concord/network/FeaturesPayload.java @@ -22,8 +22,14 @@ package dev.sciwhiz12.concord.network; +import com.google.common.collect.Maps; import dev.sciwhiz12.concord.Concord; +import dev.sciwhiz12.concord.features.ConcordFeatures; +import io.netty.buffer.ByteBuf; +import io.netty.util.AttributeKey; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -32,29 +38,26 @@ import java.util.Map; public record FeaturesPayload(Map features) implements CustomPacketPayload { - public static final ResourceLocation ID = new ResourceLocation(Concord.MODID, "features"); + public static final Type TYPE = new Type<>(new ResourceLocation(Concord.MODID, "features")); + private static final StreamCodec ARTIFACT_VERSION_CODEC = ByteBufCodecs.STRING_UTF8.map( + DefaultArtifactVersion::new, + ArtifactVersion::toString + ); + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.map( + Maps::newHashMapWithExpectedSize, + ByteBufCodecs.STRING_UTF8, + ARTIFACT_VERSION_CODEC + ), + FeaturesPayload::features, + FeaturesPayload::new); public FeaturesPayload { features = Map.copyOf(features); } @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeMap(features, - FriendlyByteBuf::writeUtf, - (buf, ver) -> buf.writeUtf(ver.toString()) - ); - } - - public static FeaturesPayload read(FriendlyByteBuf buffer) { - return new FeaturesPayload(buffer.readMap( - FriendlyByteBuf::readUtf, - buf -> new DefaultArtifactVersion(buf.readUtf()) - )); - } - - @Override - public ResourceLocation id() { - return ID; + public Type type() { + return TYPE; } } diff --git a/src/main/java/dev/sciwhiz12/concord/util/Translation.java b/src/main/java/dev/sciwhiz12/concord/util/Translation.java index 04433139..1ad50d99 100644 --- a/src/main/java/dev/sciwhiz12/concord/util/Translation.java +++ b/src/main/java/dev/sciwhiz12/concord/util/Translation.java @@ -131,12 +131,12 @@ default MutableComponent eagerComponent(Object... formatArgs) { private boolean translateEagerly(CommandSourceStack source) { return !ConcordConfig.LAZY_TRANSLATIONS.get() - || (source.getEntity() instanceof ServerPlayer player && !player.getData(ConcordFeatures.ATTACHMENT).isEmpty()); + || (source.getEntity() instanceof ServerPlayer player && ConcordFeatures.getOrNull(player) != null); } private boolean translateEagerly(@Nullable Entity sourceEntity) { return !ConcordConfig.LAZY_TRANSLATIONS.get() - || (sourceEntity instanceof ServerPlayer player && !player.getData(ConcordFeatures.ATTACHMENT).isEmpty()); + || (sourceEntity instanceof ServerPlayer player && ConcordFeatures.getOrNull(player) != null); } /** diff --git a/src/main/java/dev/sciwhiz12/concord/util/TranslationUtil.java b/src/main/java/dev/sciwhiz12/concord/util/TranslationUtil.java index 2871595f..667c267f 100644 --- a/src/main/java/dev/sciwhiz12/concord/util/TranslationUtil.java +++ b/src/main/java/dev/sciwhiz12/concord/util/TranslationUtil.java @@ -80,7 +80,7 @@ public static MutableComponent createTranslation(boolean lazyTranslate, final St } public static MutableComponent createTranslation(@Nullable ServerPlayer entity, String translationKey, Object... args) { - return createTranslation(!ConcordConfig.LAZY_TRANSLATIONS.get() || (entity != null && !entity.getData(ConcordFeatures.ATTACHMENT).isEmpty()), + return createTranslation(!ConcordConfig.LAZY_TRANSLATIONS.get() || (entity != null && ConcordFeatures.getOrNull(entity) != null), translationKey, args); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/neoforge.mods.toml similarity index 91% rename from src/main/resources/META-INF/mods.toml rename to src/main/resources/META-INF/neoforge.mods.toml index 93f5555e..91609880 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -1,41 +1,41 @@ -modLoader = "javafml" -loaderVersion = "[1,)" -license = "MIT License" - -[[mods]] - modId = "concord" - version = "${file.jarVersion}" - displayName = "Concord" - authors = "sciwhiz12" - logoFile = "logo.png" - logoBlur = false - description = ''' - A Discord chat integration mod. - - Thank you to the following projects, which are repackaged in this mod: - - JDA, a Java wrapper for the Discord REST API - - nv-websocket-client, a high-quality WebSocket client implementation in Java - - OkHttp, a meticulous HTTP client for the JVM, Android, and GraalVM - - Okio, a modern I/O library for Android, Java, and Kotlin - - Apache Commons Collections, contains types that extend and augment the Java Collections Framework - - Jackson, a suite of data-processing tools for Java and the JVM platform, including a streaming JSON parser / generator library - - Trove, provides high speed Object and primitive collections for Java - - FindBugs JSR305, the JSR305 Annotations provided by Findbugs - ''' - -[[mixins]] - config = "mixins.concord.json" - -[[dependencies.concord]] - modId = "neoforge" - type = "required" - versionRange = "[20.4.182,20.5.0)" - ordering = "NONE" - side = "BOTH" - -[[dependencies.concord]] - modId = "minecraft" - type = "required" - versionRange = "[1.20.4,1.20.5)" - ordering = "NONE" - side = "BOTH" +modLoader = "javafml" +loaderVersion = "[1,)" +license = "MIT License" + +[[mods]] + modId = "concord" + version = "${file.jarVersion}" + displayName = "Concord" + authors = "sciwhiz12" + logoFile = "logo.png" + logoBlur = false + description = ''' + A Discord chat integration mod. + + Thank you to the following projects, which are repackaged in this mod: + - JDA, a Java wrapper for the Discord REST API + - nv-websocket-client, a high-quality WebSocket client implementation in Java + - OkHttp, a meticulous HTTP client for the JVM, Android, and GraalVM + - Okio, a modern I/O library for Android, Java, and Kotlin + - Apache Commons Collections, contains types that extend and augment the Java Collections Framework + - Jackson, a suite of data-processing tools for Java and the JVM platform, including a streaming JSON parser / generator library + - Trove, provides high speed Object and primitive collections for Java + - FindBugs JSR305, the JSR305 Annotations provided by Findbugs + ''' + +[[mixins]] + config = "mixins.concord.json" + +[[dependencies.concord]] + modId = "neoforge" + type = "required" + versionRange = "[20.6.62-beta,20.7.0)" + ordering = "NONE" + side = "BOTH" + +[[dependencies.concord]] + modId = "minecraft" + type = "required" + versionRange = "[1.20.6,1.20.7)" + ordering = "NONE" + side = "BOTH"