diff --git a/build.gradle.kts b/build.gradle.kts index 98ca127..b83c756 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -34,7 +34,7 @@ repositories { dependencies { // To change the versions see the gradle.properties file minecraft(libs.minecraft) - mappings(libs.fabricYarn) + mappings(loom.officialMojangMappings()) modImplementation(libs.fabricLoader) // Make a set of all api modules we wish to use diff --git a/gradle.properties b/gradle.properties index 4019b01..1af1213 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.parallel=true org.gradle.configuration-cache=true # Mod Properties -mod_version=1.1.0-SNAPSHOT+1.21.10 +mod_version=1.0.0-SNAPSHOT+1.21.11 maven_group=io.github.communityradargg.fabric archives_base_name=communityradar-fabric diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 05fe99a..8f5cc2f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,17 +1,15 @@ [versions] # Plugins -fabricLoom = "1.11-SNAPSHOT" +fabricLoom = "1.14-SNAPSHOT" spotless = "8.1.0" # Libraries -minecraft = "1.21.10" -fabricYarn = "1.21.10+build.1" -fabricLoader = "0.17.2" -fabricApi = "0.134.1+1.21.10" +minecraft = "1.21.11" +fabricLoader = "0.18.2" +fabricApi = "0.139.4+1.21.11" [libraries] minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft" } -fabricYarn = { group = "net.fabricmc", name = "yarn", version.ref = "fabricYarn" } fabricLoader = { group = "net.fabricmc", name = "fabric-loader", version.ref = "fabricLoader" } [plugins] diff --git a/src/main/java/io/github/communityradargg/fabric/CommunityRadarMod.java b/src/main/java/io/github/communityradargg/fabric/CommunityRadarMod.java index f4e8e17..8fce7ea 100644 --- a/src/main/java/io/github/communityradargg/fabric/CommunityRadarMod.java +++ b/src/main/java/io/github/communityradargg/fabric/CommunityRadarMod.java @@ -31,15 +31,15 @@ public class CommunityRadarMod implements ModInitializer { /** The id of the mod. */ - private static final String MODID = "communityradar"; + private static final String MOD_ID = "communityradar"; /** The version of the mod. */ - private static final String VERSION = getModVersion(MODID); + private static final String VERSION = getModVersion(MOD_ID); private static final Logger logger = LogManager.getLogger(CommunityRadarMod.class); private static RadarListManager listManager; @Override public void onInitialize() { - logger.info("Starting the mod '{}' with the version '{}'!", MODID, VERSION); + logger.info("Starting the mod '{}' with the version '{}'!", MOD_ID, VERSION); final File directoryPath = Paths.get(new File("") .getAbsolutePath(),"communityradar", "lists") .toFile(); @@ -52,7 +52,7 @@ public void onInitialize() { // Needs to be after loading public lists listManager.loadPrivateLists(); registerCommands(); - logger.info("Successfully started the mod '{}'!", MODID); + logger.info("Successfully started the mod '{}'!", MOD_ID); } /** @@ -76,18 +76,18 @@ private void registerPublicLists() { } /** - * Gets the mod version for a given modid. + * Gets the mod version for a given mod id. * - * @param modid The modid to get the version for. + * @param modId The mod-id to get the version for. * @return Returns the version in a friendly String. - * @throws IllegalArgumentException Thrown, when the mod container cannot be got for the given modid. + * @throws IllegalArgumentException Thrown, when the mod container cannot be got for the given mod id. */ - public static @NotNull String getModVersion(final @NotNull String modid) { - final Optional modContainer = FabricLoader.getInstance().getModContainer(modid); + public static @NotNull String getModVersion(final @NotNull String modId) { + final Optional modContainer = FabricLoader.getInstance().getModContainer(modId); if (modContainer.isPresent()) { return modContainer.get().getMetadata().getVersion().getFriendlyString(); } - throw new IllegalArgumentException("Cannot get the version for the given modid: " + modid); + throw new IllegalArgumentException("Cannot get the version for the given mod id: " + modId); } /** @@ -100,12 +100,12 @@ private void registerPublicLists() { } /** - * Gets the modid. + * Gets the mod id. * - * @return Returns the modid. + * @return Returns the mod id. */ - public static @NotNull String getModid() { - return MODID; + public static @NotNull String getModId() { + return MOD_ID; } /** diff --git a/src/main/java/io/github/communityradargg/fabric/accessors/PlayerEntityRenderStateAccessor.java b/src/main/java/io/github/communityradargg/fabric/accessors/AvatarRenderStateAccessor.java similarity index 90% rename from src/main/java/io/github/communityradargg/fabric/accessors/PlayerEntityRenderStateAccessor.java rename to src/main/java/io/github/communityradargg/fabric/accessors/AvatarRenderStateAccessor.java index 687c041..34c28e1 100644 --- a/src/main/java/io/github/communityradargg/fabric/accessors/PlayerEntityRenderStateAccessor.java +++ b/src/main/java/io/github/communityradargg/fabric/accessors/AvatarRenderStateAccessor.java @@ -18,9 +18,9 @@ import java.util.UUID; /** - * Serves as accessor for the self added field in the {@link net.minecraft.client.render.entity.PlayerEntityRenderer} class. + * Serves as accessor for the self added field in the {@link net.minecraft.client.renderer.entity.player.AvatarRenderer} class. */ -public interface PlayerEntityRenderStateAccessor { +public interface AvatarRenderStateAccessor { /** * Gets the player uuid field value. * diff --git a/src/main/java/io/github/communityradargg/fabric/commands/RadarCommand.java b/src/main/java/io/github/communityradargg/fabric/commands/RadarCommand.java index 0e6546f..d646428 100644 --- a/src/main/java/io/github/communityradargg/fabric/commands/RadarCommand.java +++ b/src/main/java/io/github/communityradargg/fabric/commands/RadarCommand.java @@ -29,9 +29,11 @@ import io.github.communityradargg.fabric.utils.Utils; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.client.multiplayer.PlayerInfo; +import net.minecraft.server.permissions.Permission; +import net.minecraft.server.permissions.PermissionLevel; import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Optional; @@ -40,11 +42,11 @@ public class RadarCommand { private static final String COMMAND_NAME = "radar"; private static final List COMMAND_ALIASES = List.of("communityradar", "scammer", "trustedmm", "mm"); - private static final int REQUIRED_PERMISSION_LEVEL = 0; + private static final PermissionLevel REQUIRED_PERMISSION_LEVEL = PermissionLevel.ALL; public static void register(final @NotNull CommandDispatcher dispatcher) { final LiteralCommandNode mainCommand = dispatcher.register(ClientCommandManager.literal(COMMAND_NAME) - .requires(source -> source.getPlayer().hasPermissionLevel(REQUIRED_PERMISSION_LEVEL)) + .requires(source -> source.getPlayer().permissions().hasPermission(new Permission.HasCommandLevel(REQUIRED_PERMISSION_LEVEL))) .then(ClientCommandManager.literal("help") .executes(context -> handleHelpSubcommand(context.getSource())) ) @@ -160,7 +162,7 @@ public static void register(final @NotNull CommandDispatcher { if (checkPlayerOptional.isEmpty()) { // player uuid could not be fetched source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Check.FAILED) - .build().toText()); + .build().toComponent()); return; } @@ -240,7 +242,7 @@ private static void handleCheckPlayerSubcommand(final @NotNull FabricClientComma if (entryOptional.isEmpty()) { // player uuid is on no list source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Check.FAILED) - .build().toText()); + .build().toComponent()); return; } @@ -251,7 +253,7 @@ private static void handleCheckPlayerSubcommand(final @NotNull FabricClientComma .replace("{cause}", entry.cause()) .replace("{entryCreationDate}", Utils.formatDateTime(entry.entryCreationDate())) .replace("{entryUpdateDate}", Utils.formatDateTime(entry.entryUpdateDate())) - .build().toText()); + .build().toComponent()); }); } @@ -261,21 +263,21 @@ private static void handleCheckPlayerSubcommand(final @NotNull FabricClientComma * @param source The command source, which executed the subcommand. */ private static void handleCheckAllSubcommand(final @NotNull FabricClientCommandSource source) { - final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler(); - if (networkHandler == null) { + final ClientPacketListener clientPacketListener = Minecraft.getInstance().getConnection(); + if (clientPacketListener == null) { source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Check.NOT_FOUND) - .build().toText()); + .build().toComponent()); return; } boolean anyPlayerFound = false; - for (final PlayerListEntry player : networkHandler.getPlayerList()) { - if (player.getProfile().id() == null) { + for (final PlayerInfo playerInfo : clientPacketListener.getOnlinePlayers()) { + if (playerInfo.getProfile().id() == null) { continue; } final Optional listEntryOptional = CommunityRadarMod.getListManager() - .getRadarListEntry(player.getProfile().id()); + .getRadarListEntry(playerInfo.getProfile().id()); if (listEntryOptional.isEmpty()) { // player uuid is on no list continue; @@ -283,7 +285,7 @@ private static void handleCheckAllSubcommand(final @NotNull FabricClientCommandS if (!anyPlayerFound) { source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Check.EVERYONE) - .build().toText()); + .build().toComponent()); anyPlayerFound = true; } @@ -294,12 +296,12 @@ private static void handleCheckAllSubcommand(final @NotNull FabricClientCommandS .replace("{cause}", entry.cause()) .replace("{entryCreationDate}", Utils.formatDateTime(entry.entryCreationDate())) .replace("{entryUpdateDate}", Utils.formatDateTime(entry.entryUpdateDate())) - .build().toText()); + .build().toComponent()); } if (!anyPlayerFound) { source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Check.NOT_FOUND) - .build().toText()); + .build().toComponent()); } } @@ -315,17 +317,17 @@ private static void handlePlayerAddSubcommand(final @NotNull FabricClientCommand if (listOptional.isEmpty()) { // list not existing source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_FAILED) - .build().toText()); + .build().toComponent()); return; } source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.INPUT_PROCESSING) - .build().toText()); + .build().toComponent()); Utils.getUUID(player).thenAccept(uuidOptional -> { if (uuidOptional.isEmpty()) { // player uuid could not be fetched source.sendFeedback(new RadarMessage.RadarMessageBuilder(player.startsWith("!") ? Messages.Player.NAME_INVALID_BEDROCK : Messages.Player.NAME_INVALID) - .build().toText()); + .build().toComponent()); return; } @@ -333,19 +335,19 @@ private static void handlePlayerAddSubcommand(final @NotNull FabricClientCommand if (listOptional.get().isInList(uuid)) { // player already on list source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_IN_LIST) - .build().toText()); + .build().toComponent()); return; } if (!CommunityRadarMod.getListManager().addRadarListEntry(namespace, uuid, player, cause)) { // list is not private source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_FAILED) - .build().toText()); + .build().toComponent()); return; } source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Player.ADD_SUCCESS) - .build().toText()); + .build().toComponent()); }); } @@ -360,18 +362,18 @@ private static void handlePlayerRemoveSubcommand(final @NotNull FabricClientComm if (listOptional.isEmpty()) { // list is not existing source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Player.REMOVE_FAILED) - .build().toText()); + .build().toComponent()); return; } source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.INPUT_PROCESSING) - .build().toText()); + .build().toComponent()); final RadarList list = listOptional.get(); Utils.getUUID(player).thenAccept(uuidOptional -> { if (uuidOptional.isEmpty()) { // player uuid could not be fetched source.sendFeedback(new RadarMessage.RadarMessageBuilder(player.startsWith("!") ? Messages.Player.NAME_INVALID_BEDROCK : Messages.Player.NAME_INVALID) - .build().toText()); + .build().toComponent()); return; } @@ -379,13 +381,13 @@ private static void handlePlayerRemoveSubcommand(final @NotNull FabricClientComm if (!list.isInList(uuid)) { // player uuid not on list source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Player.REMOVE_NOT_IN_LIST) - .build().toText()); + .build().toComponent()); return; } list.getPlayerMap().remove(uuid); source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.Player.REMOVE_SUCCESS) - .build().toText()); + .build().toComponent()); }); } @@ -398,19 +400,19 @@ private static void handleListAddSubcommand(final @NotNull FabricClientCommandSo if (CommunityRadarMod.getListManager().getRadarList(namespace).isPresent()) { // list already existing source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.List.CREATE_FAILED) - .build().toText()); + .build().toComponent()); return; } if (!CommunityRadarMod.getListManager().registerPrivateList(namespace, prefix)) { // list could not be registered source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.List.CREATE_FAILED) - .build().toText()); + .build().toComponent()); return; } source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.List.CREATE_SUCCESS) - .build().toText()); + .build().toComponent()); } /** @@ -423,12 +425,12 @@ private static void handleListDeleteSubcommand(final @NotNull FabricClientComman if (!listManager.unregisterList(namespace)) { // list is not existing, list is not private, file cannot be deleted source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.List.DELETE_FAILED) - .build().toText()); + .build().toComponent()); return; } source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.List.DELETE_SUCCESS) - .build().toText()); + .build().toComponent()); } /** @@ -441,7 +443,7 @@ private static void handleListShowSubcommand(final @NotNull FabricClientCommandS if (listOptional.isEmpty()) { // list is not existing source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.List.SHOW_FAILED) - .build().toText()); + .build().toComponent()); return; } @@ -449,7 +451,7 @@ private static void handleListShowSubcommand(final @NotNull FabricClientCommandS if (list.getPlayerMap().isEmpty()) { // list is empty source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.List.SHOW_EMPTY) - .build().toText()); + .build().toComponent()); return; } @@ -459,7 +461,7 @@ private static void handleListShowSubcommand(final @NotNull FabricClientCommandS .replace("{list}", list.getNamespace()) .replaceWithColorCodes("{prefix}", listOptional.get().getPrefix()) .replace("{players}", players.substring(0, players.length() - 2)) - .build().toText()); + .build().toComponent()); } /** @@ -473,7 +475,7 @@ private static void handleListPrefixSubcommand(final @NotNull FabricClientComman if (listOptional.isEmpty()) { // list is not existing source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.List.PREFIX_FAILED) - .build().toText()); + .build().toComponent()); return; } @@ -483,6 +485,6 @@ private static void handleListPrefixSubcommand(final @NotNull FabricClientComman source.sendFeedback(new RadarMessage.RadarMessageBuilder(Messages.List.PREFIX_SUCCESS) .replaceWithColorCodes("{prefix}", prefix) - .build().toText()); + .build().toComponent()); } } diff --git a/src/main/java/io/github/communityradargg/fabric/mixin/PlayerEntityRenderStateMixin.java b/src/main/java/io/github/communityradargg/fabric/mixin/AvatarRenderStateMixin.java similarity index 77% rename from src/main/java/io/github/communityradargg/fabric/mixin/PlayerEntityRenderStateMixin.java rename to src/main/java/io/github/communityradargg/fabric/mixin/AvatarRenderStateMixin.java index 3d794e8..52eb9af 100644 --- a/src/main/java/io/github/communityradargg/fabric/mixin/PlayerEntityRenderStateMixin.java +++ b/src/main/java/io/github/communityradargg/fabric/mixin/AvatarRenderStateMixin.java @@ -15,17 +15,17 @@ */ package io.github.communityradargg.fabric.mixin; -import io.github.communityradargg.fabric.accessors.PlayerEntityRenderStateAccessor; -import net.minecraft.client.render.entity.state.PlayerEntityRenderState; +import io.github.communityradargg.fabric.accessors.AvatarRenderStateAccessor; +import net.minecraft.client.renderer.entity.state.AvatarRenderState; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import java.util.UUID; /** - * Mixin for the class {@link PlayerEntityRenderState}. + * Mixin for the class {@link AvatarRenderState}. */ -@Mixin(PlayerEntityRenderState.class) -public class PlayerEntityRenderStateMixin implements PlayerEntityRenderStateAccessor { +@Mixin(AvatarRenderState.class) +public class AvatarRenderStateMixin implements AvatarRenderStateAccessor { @Unique private UUID communityradar_fabric$playerUuid; diff --git a/src/main/java/io/github/communityradargg/fabric/mixin/AvatarRendererMixin.java b/src/main/java/io/github/communityradargg/fabric/mixin/AvatarRendererMixin.java new file mode 100644 index 0000000..4159cd6 --- /dev/null +++ b/src/main/java/io/github/communityradargg/fabric/mixin/AvatarRendererMixin.java @@ -0,0 +1,74 @@ +/* + * Copyright 2024 - present CommunityRadarGG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.github.communityradargg.fabric.mixin; + +import com.llamalad7.mixinextras.sugar.Local; +import io.github.communityradargg.fabric.accessors.AvatarRenderStateAccessor; +import io.github.communityradargg.fabric.utils.Utils; +import net.minecraft.client.renderer.entity.player.AvatarRenderer; +import net.minecraft.client.renderer.entity.state.AvatarRenderState; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.Avatar; +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.ModifyArg; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.UUID; + +/** + * An abstract Mixin class for {@link AvatarRenderer}. + */ +@Mixin(AvatarRenderer.class) +public abstract class AvatarRendererMixin { + /** + * Modifies the player name tag. This gets called once every tick with the original non-modified prefix. + * + * @param component The original component to modify. + * @param avatarRenderState The needed local variable of the avatar render state. + * @return Returns the modified local variable. + */ + @ModifyArg( + method = "submitNameTag(Lnet/minecraft/client/renderer/entity/state/AvatarRenderState;Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/SubmitNodeCollector;Lnet/minecraft/client/renderer/state/CameraRenderState;)V", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/renderer/SubmitNodeCollector;submitNameTag(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/world/phys/Vec3;ILnet/minecraft/network/chat/Component;ZIDLnet/minecraft/client/renderer/state/CameraRenderState;)V", + ordinal = 1 + ), + index = 3 + ) + private Component modifySubmitNameTag(final Component component, final @Local(index = 1, argsOnly = true) AvatarRenderState avatarRenderState) { + final UUID uuid = ((AvatarRenderStateAccessor) avatarRenderState).communityradar_fabric$getPlayerUuid(); + + if (uuid == null || !Utils.isOnGrieferGames()) { + return component; + } + return Utils.includePrefixComponent(uuid, component); + } + + /** + * Modifies the player entity render state to set the self added uuid field. + * + * @param avatar The avatar as the source for the uuid. + * @param avatarRenderState The avatar render state to set the uuid. + * @param f The float f. + * @param ci The callback info. + */ + @Inject(method = "extractRenderState(Lnet/minecraft/world/entity/Avatar;Lnet/minecraft/client/renderer/entity/state/AvatarRenderState;F)V", at = @At(value = "TAIL")) + private void modifyExtractRenderState(final Avatar avatar, final AvatarRenderState avatarRenderState, final float f, final CallbackInfo ci) { + ((AvatarRenderStateAccessor) avatarRenderState).communityradar_fabric$setPlayerUuid(avatar.getUUID()); + } +} diff --git a/src/main/java/io/github/communityradargg/fabric/mixin/ChatHudMixin.java b/src/main/java/io/github/communityradargg/fabric/mixin/ChatComponentMixin.java similarity index 70% rename from src/main/java/io/github/communityradargg/fabric/mixin/ChatHudMixin.java rename to src/main/java/io/github/communityradargg/fabric/mixin/ChatComponentMixin.java index f976317..540380a 100644 --- a/src/main/java/io/github/communityradargg/fabric/mixin/ChatHudMixin.java +++ b/src/main/java/io/github/communityradargg/fabric/mixin/ChatComponentMixin.java @@ -17,8 +17,8 @@ import io.github.communityradargg.fabric.CommunityRadarMod; import io.github.communityradargg.fabric.utils.Utils; -import net.minecraft.client.gui.hud.ChatHud; -import net.minecraft.text.Text; +import net.minecraft.client.gui.components.ChatComponent; +import net.minecraft.network.chat.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongepowered.asm.mixin.Mixin; @@ -30,40 +30,35 @@ import java.util.concurrent.ExecutionException; /** - * An abstract Mixin class for {@link ChatHud}. + * An abstract Mixin class for {@link ChatComponent}. */ -@Mixin(ChatHud.class) -public abstract class ChatHudMixin { +@Mixin(ChatComponent.class) +public abstract class ChatComponentMixin { @Unique - private static final Logger logger = LoggerFactory.getLogger(ChatHudMixin.class); + private static final Logger logger = LoggerFactory.getLogger(ChatComponentMixin.class); /** * Modifies the player chat messages. This gets called when a message should be added to the player chat. * - * @param text The original chat message text to modify. + * @param component The original chat message component to modify. * @return Returns the modified local variable. */ - @ModifyVariable(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At(value = "HEAD"), index = 1, argsOnly = true) - private Text modifyChatMessages(final Text text) { + @ModifyVariable(method = "addMessage(Lnet/minecraft/network/chat/Component;Lnet/minecraft/network/chat/MessageSignature;Lnet/minecraft/client/GuiMessageTag;)V", at = @At(value = "HEAD"), index = 1, argsOnly = true) + private Component modifyAddMessage(final Component component) { if (!Utils.isOnGrieferGames()) { - return text; - } - - final String plainText = text.getString(); - if (plainText == null) { - return text; + return component; } // On a chat message there should be never be the need to call to the Mojang API. try { - final Optional playerUuid = Utils.getChatMessagePlayer(plainText).get(); + final Optional playerUuid = Utils.getChatMessagePlayer(component.getString()).get(); if (playerUuid.isPresent() && CommunityRadarMod.getListManager().isInList(playerUuid.get())) { - return Utils.includePrefixText(playerUuid.get(), text); + return Utils.includePrefixComponent(playerUuid.get(), component); } } catch (final ExecutionException | InterruptedException e) { logger.error("Could not get the player uuid in the message edit process", e); } - return text; + return component; } } diff --git a/src/main/java/io/github/communityradargg/fabric/mixin/PlayerEntityRendererMixin.java b/src/main/java/io/github/communityradargg/fabric/mixin/PlayerEntityRendererMixin.java deleted file mode 100644 index 48c1123..0000000 --- a/src/main/java/io/github/communityradargg/fabric/mixin/PlayerEntityRendererMixin.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2024 - present CommunityRadarGG - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.github.communityradargg.fabric.mixin; - -import com.llamalad7.mixinextras.sugar.Local; -import io.github.communityradargg.fabric.accessors.PlayerEntityRenderStateAccessor; -import io.github.communityradargg.fabric.utils.Utils; -import net.minecraft.client.render.entity.PlayerEntityRenderer; -import net.minecraft.client.render.entity.state.PlayerEntityRenderState; -import net.minecraft.entity.PlayerLikeEntity; -import net.minecraft.text.Text; -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.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.UUID; - -/** - * An abstract Mixin class for {@link PlayerEntityRenderer}. - */ -@Mixin(PlayerEntityRenderer.class) -public abstract class PlayerEntityRendererMixin { - /** - * Modifies the player name tag. This gets called once every tick with the original non-modified prefix. - * - * @param text The original text to modify. - * @param playerEntityRenderState The needed local variable of the player entity render state. - * @return Returns the modified local variable. - */ - @ModifyArg( - method = "renderLabelIfPresent(Lnet/minecraft/client/render/entity/state/PlayerEntityRenderState;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/command/OrderedRenderCommandQueue;Lnet/minecraft/client/render/state/CameraRenderState;)V", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/render/command/OrderedRenderCommandQueue;submitLabel(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/util/math/Vec3d;ILnet/minecraft/text/Text;ZIDLnet/minecraft/client/render/state/CameraRenderState;)V", - ordinal = 1 - ), - index = 3 - ) - private Text modifyPlayerNameTag(final Text text, final @Local(index = 1, argsOnly = true) PlayerEntityRenderState playerEntityRenderState) { - final UUID uuid = ((PlayerEntityRenderStateAccessor) playerEntityRenderState).communityradar_fabric$getPlayerUuid(); - - if (uuid == null || !Utils.isOnGrieferGames()) { - return text; - } - return Utils.includePrefixText(uuid, text); - } - - /** - * Modifies the player entity render state to set the self added uuid field. - * - * @param playerLikeEntity The player like entity as the source for the uuid. - * @param playerEntityRenderState The player entity render state to set the uuid. - * @param f The float f. - * @param ci The callback info. - */ - @Inject(method = "updateRenderState(Lnet/minecraft/entity/PlayerLikeEntity;Lnet/minecraft/client/render/entity/state/PlayerEntityRenderState;F)V", at = @At(value = "TAIL")) - private void modifyUpdateRenderState(final PlayerLikeEntity playerLikeEntity, final PlayerEntityRenderState playerEntityRenderState, final float f, final CallbackInfo ci) { - ((PlayerEntityRenderStateAccessor) playerEntityRenderState).communityradar_fabric$setPlayerUuid(playerLikeEntity.getUuid()); - } -} diff --git a/src/main/java/io/github/communityradargg/fabric/mixin/PlayerListHudMixin.java b/src/main/java/io/github/communityradargg/fabric/mixin/PlayerTabOverlayMixin.java similarity index 56% rename from src/main/java/io/github/communityradargg/fabric/mixin/PlayerListHudMixin.java rename to src/main/java/io/github/communityradargg/fabric/mixin/PlayerTabOverlayMixin.java index 6686375..cb53345 100644 --- a/src/main/java/io/github/communityradargg/fabric/mixin/PlayerListHudMixin.java +++ b/src/main/java/io/github/communityradargg/fabric/mixin/PlayerTabOverlayMixin.java @@ -18,29 +18,29 @@ import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.llamalad7.mixinextras.sugar.Local; import io.github.communityradargg.fabric.utils.Utils; -import net.minecraft.client.gui.hud.PlayerListHud; -import net.minecraft.client.network.PlayerListEntry; -import net.minecraft.text.Text; +import net.minecraft.client.gui.components.PlayerTabOverlay; +import net.minecraft.client.multiplayer.PlayerInfo; +import net.minecraft.network.chat.Component; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; /** - * An abstract Mixin class for {@link PlayerListHudMixin}. + * An abstract Mixin class for {@link PlayerTabOverlay}. */ -@Mixin(PlayerListHud.class) -public abstract class PlayerListHudMixin { +@Mixin(PlayerTabOverlay.class) +public abstract class PlayerTabOverlayMixin { /** - * Modifies the player player-list entry text. This gets called when the player-list entry gets updated. + * Modifies the player info component. This gets called when the player info gets updated. * - * @param text The original chat message text to modify. - * @param entry The needed local variable of the player list entry. + * @param component The original chat message component to modify. + * @param playerInfo The needed local variable of the player info. * @return Returns the modified local variable. */ - @ModifyReturnValue(method = "getPlayerName", at = @At("RETURN")) - private Text modifyGetPlayerName(final Text text, final @Local(argsOnly = true) PlayerListEntry entry) { + @ModifyReturnValue(method = "getNameForDisplay", at = @At("RETURN")) + private Component modifyGetNameForDisplay(final Component component, final @Local(argsOnly = true) PlayerInfo playerInfo) { if (!Utils.isOnGrieferGames()) { - return text; + return component; } - return Utils.includePrefixText(entry.getProfile().id(), text); + return Utils.includePrefixComponent(playerInfo.getProfile().id(), component); } } diff --git a/src/main/java/io/github/communityradargg/fabric/utils/RadarMessage.java b/src/main/java/io/github/communityradargg/fabric/utils/RadarMessage.java index 3e16c4b..a42c651 100644 --- a/src/main/java/io/github/communityradargg/fabric/utils/RadarMessage.java +++ b/src/main/java/io/github/communityradargg/fabric/utils/RadarMessage.java @@ -15,7 +15,7 @@ */ package io.github.communityradargg.fabric.utils; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.NotNull; /** @@ -35,12 +35,12 @@ private RadarMessage(final @NotNull String text, final boolean includePrefix) { } /** - * Converts this class instance to a {@link Text}. + * Converts this class instance to a {@link Component}. * - * @return Returns the text converted to a {@link Text}. + * @return Returns the text converted to a {@link Component}. */ - public @NotNull Text toText() { - return Text.of(text); + public @NotNull Component toComponent() { + return Component.nullToEmpty(text); } /** diff --git a/src/main/java/io/github/communityradargg/fabric/utils/Utils.java b/src/main/java/io/github/communityradargg/fabric/utils/Utils.java index 703320e..0a7456a 100644 --- a/src/main/java/io/github/communityradargg/fabric/utils/Utils.java +++ b/src/main/java/io/github/communityradargg/fabric/utils/Utils.java @@ -18,11 +18,11 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import io.github.communityradargg.fabric.CommunityRadarMod; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.PlayerListEntry; -import net.minecraft.network.ClientConnection; -import net.minecraft.text.Text; +import net.minecraft.client.Minecraft; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.client.multiplayer.PlayerInfo; +import net.minecraft.network.Connection; +import net.minecraft.network.chat.Component; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.jetbrains.annotations.NotNull; @@ -64,8 +64,8 @@ public class Utils { * @return Returns a CompletableFuture with an optional with the player uuid. */ public static @NotNull CompletableFuture> getUUID(final @NotNull String playerName) { - final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler(); - if (networkHandler == null || networkHandler.getWorld() == null) { + final ClientPacketListener clientPacketListener = Minecraft.getInstance().getConnection(); + if (clientPacketListener == null) { // user has to be in a world return CompletableFuture.completedFuture(Optional.empty()); } @@ -76,10 +76,10 @@ public class Utils { } // checking if there is a player with same name in the loaded world. If so, returning the uuid from the profile - for (final PlayerListEntry playerListEntry : networkHandler.getPlayerList()) { - if (playerListEntry.getProfile().name().equalsIgnoreCase(playerName)) { - uuidNameCache.put(playerName, playerListEntry.getProfile().id()); - return CompletableFuture.completedFuture(Optional.of(playerListEntry.getProfile().id())); + for (final PlayerInfo playerInfo : clientPacketListener.getOnlinePlayers()) { + if (playerInfo.getProfile().name().equalsIgnoreCase(playerName)) { + uuidNameCache.put(playerName, playerInfo.getProfile().id()); + return CompletableFuture.completedFuture(Optional.of(playerInfo.getProfile().id())); } } @@ -103,7 +103,7 @@ public class Utils { final HttpRequest httpRequest = HttpRequest.newBuilder() .uri(uri) .timeout(Duration.ofSeconds(3)) - .header("User-Agent", CommunityRadarMod.getModid() + "/" + CommunityRadarMod.getVersion()) + .header("User-Agent", CommunityRadarMod.getModId() + "/" + CommunityRadarMod.getVersion()) .GET() .build(); @@ -168,34 +168,34 @@ private static boolean isGrieferGamesHostName(final @NotNull String hostName) { */ @SuppressWarnings("BooleanMethodIsAlwaysInverted") // better readable this way public static boolean isOnGrieferGames() { - final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler(); - if (networkHandler == null) { + final ClientPacketListener clientPacketListener = Minecraft.getInstance().getConnection(); + if (clientPacketListener == null) { return false; } - final ClientConnection connection = networkHandler.getConnection(); - if (connection.isLocal() || !(connection.getAddress() instanceof InetSocketAddress inetSocketAddress)) { + final Connection connection = clientPacketListener.getConnection(); + if (connection.isMemoryConnection() || !(connection.getRemoteAddress() instanceof InetSocketAddress inetSocketAddress)) { return false; } return isGrieferGamesHostName(inetSocketAddress.getHostName()); } /** - * Builds the new text including the radar prefix. + * Builds the new component including the radar prefix. * - * @param playerUuid The uuid of the player to get the text with the radar prefix for. - * @param oldNameTagText The old text that should be extended, if needed. - * @return The new text for the including the radar prefix. + * @param playerUuid The uuid of the player to get the component with the radar prefix for. + * @param oldNameTagComponent The old component that should be extended, if needed. + * @return The new component including the radar prefix. */ - public static Text includePrefixText(final @NotNull UUID playerUuid, final @NotNull Text oldNameTagText) { + public static Component includePrefixComponent(final @NotNull UUID playerUuid, final @NotNull Component oldNameTagComponent) { final String addonPrefix = CommunityRadarMod.getListManager() .getPrefix(playerUuid) .replace("&", "ยง"); if (!addonPrefix.isEmpty()) { - return Text.empty().append(addonPrefix + " ").append(oldNameTagText); + return Component.empty().append(addonPrefix + " ").append(oldNameTagComponent); } - return oldNameTagText; + return oldNameTagComponent; } /** diff --git a/src/main/resources/communityradar.mixins.json b/src/main/resources/communityradar.mixins.json index 6738157..aaf7e53 100644 --- a/src/main/resources/communityradar.mixins.json +++ b/src/main/resources/communityradar.mixins.json @@ -1,17 +1,17 @@ { - "required": true, - "package": "io.github.communityradargg.fabric.mixin", - "compatibilityLevel": "JAVA_21", - "injectors": { - "defaultRequire": 1 - }, + "required": true, + "package": "io.github.communityradargg.fabric.mixin", + "compatibilityLevel": "JAVA_21", + "injectors": { + "defaultRequire": 1 + }, "overwrites": { "requireAnnotations": true }, "client": [ - "ChatHudMixin", - "PlayerEntityRendererMixin", - "PlayerEntityRenderStateMixin", - "PlayerListHudMixin" - ] + "AvatarRendererMixin", + "AvatarRenderStateMixin", + "ChatComponentMixin", + "PlayerTabOverlayMixin" + ] }