diff --git a/build.gradle b/build.gradle index 318a4e6..f8f4fb6 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { - id 'fabric-loom' version '0.11-SNAPSHOT' - id 'io.github.juuxel.loom-quiltflower' version '1.6.0' + id 'fabric-loom' version '0.12-SNAPSHOT' + id 'io.github.juuxel.loom-quiltflower' version '1.7.2' } sourceCompatibility = JavaVersion.VERSION_17 @@ -28,10 +28,6 @@ tasks.withType(JavaCompile).configureEach { it.options.release = 17 } -java { - withSourcesJar() -} - jar { from("LICENSE") { rename { "${it}_${project.archivesBaseName}" } diff --git a/gradle.properties b/gradle.properties index 038d533..ec43c75 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,9 @@ org.gradle.jvmargs=-Xmx1G -minecraft_version=1.18.2 -yarn_mappings=1.18.2+build.1 -loader_version=0.13.3 +minecraft_version=1.19 +yarn_mappings=1.19+build.4 +loader_version=0.14.8 -mod_version=1.2.1 +mod_version=1.3.0 maven_group=me.thegiggitybyte archives_base_name=chathistory \ No newline at end of file diff --git a/src/main/java/me/thegiggitybyte/chathistory/ChatHistory.java b/src/main/java/me/thegiggitybyte/chathistory/ChatHistory.java index 2c6e5df..3f3958e 100644 --- a/src/main/java/me/thegiggitybyte/chathistory/ChatHistory.java +++ b/src/main/java/me/thegiggitybyte/chathistory/ChatHistory.java @@ -1,6 +1,8 @@ package me.thegiggitybyte.chathistory; import com.google.common.collect.EvictingQueue; +import me.thegiggitybyte.chathistory.message.Message; +import me.thegiggitybyte.chathistory.message.PlayerMessage; import net.darktree.simpleconfig.SimpleConfig; import net.fabricmc.api.DedicatedServerModInitializer; import net.fabricmc.api.EnvType; @@ -10,7 +12,7 @@ @Environment(EnvType.SERVER) public class ChatHistory implements DedicatedServerModInitializer { - public static Queue MESSAGE_CACHE; + public static Queue MESSAGE_CACHE; @Override public void onInitializeServer() { diff --git a/src/main/java/me/thegiggitybyte/chathistory/ChatMessage.java b/src/main/java/me/thegiggitybyte/chathistory/ChatMessage.java deleted file mode 100644 index e7d2b33..0000000 --- a/src/main/java/me/thegiggitybyte/chathistory/ChatMessage.java +++ /dev/null @@ -1,30 +0,0 @@ -package me.thegiggitybyte.chathistory; - -import net.minecraft.network.MessageType; -import net.minecraft.text.Text; - -import java.util.UUID; - -public class ChatMessage { - private final Text content; - private final MessageType type; - private final UUID senderUuid; - - public ChatMessage(Text content, MessageType type, UUID sender) { - this.content = content; - this.type = type; - this.senderUuid = sender; - } - - public Text getContent() { - return content; - } - - public MessageType getType() { - return type; - } - - public UUID getSender() { - return senderUuid; - } -} diff --git a/src/main/java/me/thegiggitybyte/chathistory/message/GameMessage.java b/src/main/java/me/thegiggitybyte/chathistory/message/GameMessage.java new file mode 100644 index 0000000..3eec39c --- /dev/null +++ b/src/main/java/me/thegiggitybyte/chathistory/message/GameMessage.java @@ -0,0 +1,19 @@ +package me.thegiggitybyte.chathistory.message; + +import net.minecraft.network.message.MessageType; +import net.minecraft.text.Text; +import net.minecraft.util.registry.RegistryKey; + +public class GameMessage extends Message { + private final Text message; + + public GameMessage(Text message, RegistryKey typeKey) { + super(typeKey); + + this.message = message; + } + + public Text getTextMessage() { + return message; + } +} diff --git a/src/main/java/me/thegiggitybyte/chathistory/message/Message.java b/src/main/java/me/thegiggitybyte/chathistory/message/Message.java new file mode 100644 index 0000000..85d371b --- /dev/null +++ b/src/main/java/me/thegiggitybyte/chathistory/message/Message.java @@ -0,0 +1,16 @@ +package me.thegiggitybyte.chathistory.message; + +import net.minecraft.network.message.MessageType; +import net.minecraft.util.registry.RegistryKey; + +public abstract class Message { + private final RegistryKey typeKey; + + protected Message(RegistryKey typeKey) { + this.typeKey = typeKey; + } + + public RegistryKey getTypeKey() { + return typeKey; + } +} diff --git a/src/main/java/me/thegiggitybyte/chathistory/message/PlayerMessage.java b/src/main/java/me/thegiggitybyte/chathistory/message/PlayerMessage.java new file mode 100644 index 0000000..849a5d2 --- /dev/null +++ b/src/main/java/me/thegiggitybyte/chathistory/message/PlayerMessage.java @@ -0,0 +1,26 @@ +package me.thegiggitybyte.chathistory.message; + +import net.minecraft.network.message.MessageSender; +import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SignedMessage; +import net.minecraft.util.registry.RegistryKey; + +public class PlayerMessage extends Message { + private final SignedMessage message; + private final MessageSender sender; + + public PlayerMessage(SignedMessage message, MessageSender sender, RegistryKey typeKey) { + super(typeKey); + + this.message = message; + this.sender = sender; + } + + public SignedMessage getSignedMessage() { + return message; + } + + public MessageSender getSender() { + return sender; + } +} diff --git a/src/main/java/me/thegiggitybyte/chathistory/mixin/PlayerManagerMixin.java b/src/main/java/me/thegiggitybyte/chathistory/mixin/PlayerManagerMixin.java index 582d51f..d1733e5 100644 --- a/src/main/java/me/thegiggitybyte/chathistory/mixin/PlayerManagerMixin.java +++ b/src/main/java/me/thegiggitybyte/chathistory/mixin/PlayerManagerMixin.java @@ -1,37 +1,44 @@ package me.thegiggitybyte.chathistory.mixin; import me.thegiggitybyte.chathistory.ChatHistory; -import me.thegiggitybyte.chathistory.ChatMessage; +import me.thegiggitybyte.chathistory.message.GameMessage; +import me.thegiggitybyte.chathistory.message.PlayerMessage; import net.minecraft.network.ClientConnection; -import net.minecraft.network.MessageType; +import net.minecraft.network.message.MessageSender; +import net.minecraft.network.message.MessageType; +import net.minecraft.network.message.SignedMessage; import net.minecraft.server.PlayerManager; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; +import net.minecraft.util.registry.RegistryKey; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.UUID; import java.util.function.Function; @Mixin(PlayerManager.class) public class PlayerManagerMixin { - @Inject(method = "broadcast(Lnet/minecraft/text/Text;Ljava/util/function/Function;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V", at = @At("HEAD")) - public void cacheMessage(Text content, Function messageFactory, MessageType type, UUID sender, CallbackInfo ci) { - ChatHistory.MESSAGE_CACHE.add(new ChatMessage(content, type, sender)); + @Inject(method = "broadcast(Lnet/minecraft/text/Text;Ljava/util/function/Function;Lnet/minecraft/util/registry/RegistryKey;)V", at = @At("HEAD")) + public void cacheGameMessage(Text message, Function playerMessageFactory, RegistryKey typeKey, CallbackInfo ci) { + ChatHistory.MESSAGE_CACHE.add(new GameMessage(message, typeKey)); } - - @Inject(method = "broadcast(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V", at = @At("HEAD")) - public void cacheMessage(Text content, MessageType type, UUID sender, CallbackInfo ci) { - ChatHistory.MESSAGE_CACHE.add(new ChatMessage(content, type, sender)); + + @Inject(method = "broadcast(Lnet/minecraft/network/message/SignedMessage;Ljava/util/function/Function;Lnet/minecraft/network/message/MessageSender;Lnet/minecraft/util/registry/RegistryKey;)V", at = @At("HEAD")) + public void cachePlayerMessage(SignedMessage message, Function playerMessageFactory, MessageSender sender, RegistryKey typeKey, CallbackInfo ci) { + ChatHistory.MESSAGE_CACHE.add(new PlayerMessage(message, sender, typeKey)); } - + @Inject(method = "onPlayerConnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;onSpawn()V")) public void sendCachedMessages(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { for (var message : ChatHistory.MESSAGE_CACHE) { - player.sendMessage(message.getContent(), message.getType(), message.getSender()); + if (message instanceof PlayerMessage playerMessage) { + player.sendChatMessage(playerMessage.getSignedMessage(), playerMessage.getSender(), playerMessage.getTypeKey()); + } else if (message instanceof GameMessage gameMessage) { + player.sendMessage(gameMessage.getTextMessage(), gameMessage.getTypeKey()); + } } } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index d1592d8..3d351bc 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -45,6 +45,6 @@ ], "depends": { "fabricloader": ">=0.9.3+build.207", - "minecraft": "1.18.x" + "minecraft": ">=1.19" } }