This repository has been archived by the owner on Nov 20, 2023. It is now read-only.
forked from JuergenSchT/chathistory
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
90 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
src/main/java/me/thegiggitybyte/chathistory/ChatMessage.java
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/main/java/me/thegiggitybyte/chathistory/message/GameMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MessageType> typeKey) { | ||
super(typeKey); | ||
|
||
this.message = message; | ||
} | ||
|
||
public Text getTextMessage() { | ||
return message; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/me/thegiggitybyte/chathistory/message/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MessageType> typeKey; | ||
|
||
protected Message(RegistryKey<MessageType> typeKey) { | ||
this.typeKey = typeKey; | ||
} | ||
|
||
public RegistryKey<MessageType> getTypeKey() { | ||
return typeKey; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/me/thegiggitybyte/chathistory/message/PlayerMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<MessageType> typeKey) { | ||
super(typeKey); | ||
|
||
this.message = message; | ||
this.sender = sender; | ||
} | ||
|
||
public SignedMessage getSignedMessage() { | ||
return message; | ||
} | ||
|
||
public MessageSender getSender() { | ||
return sender; | ||
} | ||
} |
31 changes: 19 additions & 12 deletions
31
src/main/java/me/thegiggitybyte/chathistory/mixin/PlayerManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ServerPlayerEntity, Text> 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<ServerPlayerEntity, Text> playerMessageFactory, RegistryKey<MessageType> 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<ServerPlayerEntity, SignedMessage> playerMessageFactory, MessageSender sender, RegistryKey<MessageType> 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()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,6 @@ | |
], | ||
"depends": { | ||
"fabricloader": ">=0.9.3+build.207", | ||
"minecraft": "1.18.x" | ||
"minecraft": ">=1.19" | ||
} | ||
} |