|
1 | 1 | package me.thegiggitybyte.chathistory.mixin;
|
2 | 2 |
|
3 |
| -import com.mojang.authlib.GameProfile; |
4 | 3 | import me.thegiggitybyte.chathistory.ChatHistory;
|
5 | 4 | import me.thegiggitybyte.chathistory.ChatMessage;
|
6 |
| -import net.fabricmc.api.EnvType; |
7 |
| -import net.fabricmc.api.Environment; |
8 |
| -import net.minecraft.nbt.NbtCompound; |
9 | 5 | import net.minecraft.network.ClientConnection;
|
10 | 6 | import net.minecraft.network.MessageType;
|
11 | 7 | import net.minecraft.server.PlayerManager;
|
12 |
| -import net.minecraft.server.network.ServerPlayNetworkHandler; |
13 | 8 | import net.minecraft.server.network.ServerPlayerEntity;
|
14 |
| -import net.minecraft.server.world.ServerWorld; |
15 |
| -import net.minecraft.text.MutableText; |
16 |
| -import net.minecraft.util.UserCache; |
17 |
| -import net.minecraft.util.Util; |
18 |
| -import net.minecraft.util.registry.RegistryKey; |
19 |
| -import net.minecraft.world.WorldProperties; |
| 9 | +import net.minecraft.text.Text; |
20 | 10 | import org.spongepowered.asm.mixin.Mixin;
|
21 | 11 | import org.spongepowered.asm.mixin.injection.At;
|
22 | 12 | import org.spongepowered.asm.mixin.injection.Inject;
|
23 | 13 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
24 |
| -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; |
25 | 14 |
|
26 |
| -import java.util.Optional; |
| 15 | +import java.util.UUID; |
| 16 | +import java.util.function.Function; |
27 | 17 |
|
28 |
| -@Environment(EnvType.SERVER) |
29 | 18 | @Mixin(PlayerManager.class)
|
30 |
| -public abstract class PlayerManagerMixin { |
| 19 | +public class PlayerManagerMixin { |
31 | 20 |
|
32 |
| - @Inject( |
33 |
| - method = "onPlayerConnect", |
34 |
| - locals = LocalCapture.CAPTURE_FAILHARD, |
35 |
| - at = @At( |
36 |
| - value = "INVOKE", |
37 |
| - target = "Lnet/minecraft/server/PlayerManager;broadcastChatMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/MessageType;Ljava/util/UUID;)V" |
38 |
| - ) |
39 |
| - ) |
40 |
| - public void cacheJoinMessage(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci, GameProfile gameProfile, UserCache userCache, Optional optional, String string, NbtCompound nbtCompound, RegistryKey registryKey, ServerWorld serverWorld, ServerWorld serverWorld3, String string2, WorldProperties worldProperties, ServerPlayNetworkHandler serverPlayNetworkHandler, MutableText content) { // :( |
41 |
| - var message = new ChatMessage(content, MessageType.SYSTEM, Util.NIL_UUID); |
42 |
| - ChatHistory.MESSAGE_CACHE.add(message); |
| 21 | + @Inject(method = "broadcast", at = @At("HEAD")) |
| 22 | + public void cacheMessage(Text content, Function<ServerPlayerEntity, Text> messageFactory, MessageType type, UUID sender, CallbackInfo ci) { |
| 23 | + ChatHistory.MESSAGE_CACHE.add(new ChatMessage(content, type, sender)); |
| 24 | + } |
| 25 | + |
| 26 | + @Inject(method = "broadcastChatMessage", at = @At("HEAD")) |
| 27 | + public void cacheMessage(Text content, MessageType type, UUID sender, CallbackInfo ci) { |
| 28 | + ChatHistory.MESSAGE_CACHE.add(new ChatMessage(content, type, sender)); |
43 | 29 | }
|
44 | 30 |
|
45 | 31 | @Inject(
|
|
0 commit comments