From c2016120162f8c160679d4ae97ee21788ee0d16b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Jan 2026 18:10:05 +0000 Subject: [PATCH 1/9] Initial plan From 49118f523b1ca6d85680dfabf5d3f57e5b6cea9a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Jan 2026 18:14:13 +0000 Subject: [PATCH 2/9] Update fabric build config for 26.1 Co-authored-by: GalvinPython <77013913+GalvinPython@users.noreply.github.com> --- .github/workflows/build.yml | 32 ++++++++++++++++++++++++++++---- build.gradle | 15 +++++++-------- gradle.properties | 3 +-- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b01da52..ce75afa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,31 @@ # against bad commits. name: build -on: [pull_request, push] +on: + pull_request: + paths: + - '.github/workflows/build.yml' + - 'build.gradle' + - 'gradle.properties' + - 'gradle/**' + - 'gradlew' + - 'gradlew.bat' + - 'settings.gradle' + - 'src/**' + push: + paths: + - '.github/workflows/build.yml' + - 'build.gradle' + - 'gradle.properties' + - 'gradle/**' + - 'gradlew' + - 'gradlew.bat' + - 'settings.gradle' + - 'src/**' + +concurrency: + group: "java-build-${{ github.ref }}" + cancel-in-progress: true jobs: build: @@ -12,7 +36,7 @@ jobs: matrix: # Use these Java versions java: [ - 21, # Current Java LTS + 25, # Current Java LTS ] runs-on: ubuntu-22.04 steps: @@ -30,8 +54,8 @@ jobs: - name: build run: ./gradlew build - name: capture build artifacts - if: ${{ matrix.java == '21' }} # Only upload artifacts built from latest java + if: ${{ matrix.java == '25' }} # Only upload artifacts built from latest java uses: actions/upload-artifact@v4 with: name: Artifacts - path: build/libs/ \ No newline at end of file + path: build/libs/ diff --git a/build.gradle b/build.gradle index a86e80a..253bd8a 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version "${loom_version}" + id 'net.fabricmc.fabric-loom' version "${loom_version}" id 'maven-publish' } @@ -21,11 +21,10 @@ repositories { dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + implementation "net.fabricmc:fabric-loader:${project.loader_version}" // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + implementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" } @@ -38,7 +37,7 @@ processResources { } tasks.withType(JavaCompile).configureEach { - it.options.release = 21 + it.options.release = 25 } java { @@ -47,8 +46,8 @@ java { // If you remove this line, sources will not be generated. withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = JavaVersion.VERSION_25 + targetCompatibility = JavaVersion.VERSION_25 } jar { @@ -75,4 +74,4 @@ publishing { // The repositories here will be used for publishing your artifact, not for // retrieving dependencies. } -} \ No newline at end of file +} diff --git a/gradle.properties b/gradle.properties index 114e481..1bf326a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,6 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop minecraft_version=1.21.11 -yarn_mappings=1.21.11+build.3 loader_version=0.18.4 loom_version=1.14-SNAPSHOT @@ -15,4 +14,4 @@ maven_group=me.imgalvin.playerfinder archives_base_name=player-finder # Dependencies -fabric_version=0.140.2+1.21.11 \ No newline at end of file +fabric_api_version=0.140.2+1.21.11 From 53a59ed1cd7ade19558ae2d28d51ddba35f75d7f Mon Sep 17 00:00:00 2001 From: Galvin Date: Mon, 19 Jan 2026 18:32:20 +0000 Subject: [PATCH 3/9] update gradle properties --- gradle.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1bf326a..5787095 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,14 +4,14 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop -minecraft_version=1.21.11 +minecraft_version=26.1-snapshot-3 loader_version=0.18.4 loom_version=1.14-SNAPSHOT # Mod Properties -mod_version=1.0.4+1.21.11 +mod_version=1.0.5-beta+26.1-snapshots maven_group=me.imgalvin.playerfinder archives_base_name=player-finder # Dependencies -fabric_api_version=0.140.2+1.21.11 +fabric_api_version=0.142.0+26.1 From c33b492ae1e464325edc12c5f52cc1302c66f54c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 19 Jan 2026 19:17:51 +0000 Subject: [PATCH 4/9] Remove pull_request path filters Co-authored-by: GalvinPython <77013913+GalvinPython@users.noreply.github.com> --- .github/workflows/build.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ce75afa..c60810c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,15 +6,6 @@ name: build on: pull_request: - paths: - - '.github/workflows/build.yml' - - 'build.gradle' - - 'gradle.properties' - - 'gradle/**' - - 'gradlew' - - 'gradlew.bat' - - 'settings.gradle' - - 'src/**' push: paths: - '.github/workflows/build.yml' From 115d043a07fd47c191001126144e9066f04a6d62 Mon Sep 17 00:00:00 2001 From: Galvin Date: Mon, 19 Jan 2026 19:31:08 +0000 Subject: [PATCH 5/9] chore: i hate workflows --- .github/workflows/build.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c60810c..d7e8f1b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,10 +4,10 @@ # against bad commits. name: build + on: pull_request: - push: - paths: + paths: &build_paths - '.github/workflows/build.yml' - 'build.gradle' - 'gradle.properties' @@ -17,6 +17,10 @@ on: - 'settings.gradle' - 'src/**' + push: + branches: [main] + paths: *build_paths + concurrency: group: "java-build-${{ github.ref }}" cancel-in-progress: true From 983d2fcf0af1bc3caea5490af08aa9b620e81e63 Mon Sep 17 00:00:00 2001 From: GalvinPython Date: Mon, 19 Jan 2026 21:17:44 +0000 Subject: [PATCH 6/9] refactor: change Formatting and Commands arguments changed Formatting to ChatFormatting and Command arguments has its own built-in entities suggestions --- .../PlayerSuggestionProvider.java | 29 ------------------- 1 file changed, 29 deletions(-) delete mode 100644 src/main/java/me/imgalvin/playerfinder/PlayerSuggestionProvider.java diff --git a/src/main/java/me/imgalvin/playerfinder/PlayerSuggestionProvider.java b/src/main/java/me/imgalvin/playerfinder/PlayerSuggestionProvider.java deleted file mode 100644 index f904e36..0000000 --- a/src/main/java/me/imgalvin/playerfinder/PlayerSuggestionProvider.java +++ /dev/null @@ -1,29 +0,0 @@ -package me.imgalvin.playerfinder; - -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.brigadier.suggestion.SuggestionProvider; -import com.mojang.brigadier.suggestion.Suggestions; -import com.mojang.brigadier.suggestion.SuggestionsBuilder; -import net.minecraft.server.command.ServerCommandSource; - -import java.util.Collection; -import java.util.concurrent.CompletableFuture; - -public class PlayerSuggestionProvider implements SuggestionProvider { - @Override - public CompletableFuture getSuggestions(CommandContext context, SuggestionsBuilder builder) throws CommandSyntaxException { - ServerCommandSource source = context.getSource(); - - // Thankfully, the ServerCommandSource has a method to get a list of player names. - Collection playerNames = source.getPlayerNames(); - - // Add all player names to the builder. - for (String playerName : playerNames) { - builder.suggest(playerName); - } - - // Lock the suggestions after we've modified them. - return builder.buildFuture(); - } -} From 7e81ed42ddb1f2cde5fda426ebe6a8683d1a377b Mon Sep 17 00:00:00 2001 From: GalvinPython Date: Mon, 19 Jan 2026 21:21:59 +0000 Subject: [PATCH 7/9] refactor: change Formatting and Commands arguments (forgot to add this) changed Formatting to ChatFormatting and Command arguments has its own built-in entities suggestions --- .../me/imgalvin/playerfinder/PlayerFinder.java | 15 ++++++++------- .../imgalvin/playerfinder/PlayerFinderUtils.java | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java b/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java index 61b9f19..2f2e906 100644 --- a/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java +++ b/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java @@ -3,11 +3,13 @@ import com.mojang.brigadier.arguments.StringArgumentType; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.ChatFormatting; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.registry.RegistryKey; import net.minecraft.server.command.CommandManager; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -17,9 +19,8 @@ public class PlayerFinder implements ModInitializer { @Override public void onInitialize() { CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - dispatcher.register(CommandManager.literal("findplayer") - .then(CommandManager.argument("player", StringArgumentType.string()) - .suggests(new PlayerSuggestionProvider()) + dispatcher.register(Commands.literal("findplayer") + .then(Commands.argument("player", EntityArgument.entity()) .executes(context -> { String playerName = StringArgumentType.getString(context, "player"); PlayerEntity targetPlayer = context.getSource().getServer().getPlayerManager().getPlayer(playerName); @@ -35,17 +36,17 @@ public void onInitialize() { boolean isSameDimension = sourceDimension == playerDimension; - context.getSource().sendFeedback(() -> (Text) Text.literal(playerName + " is at ") + context.getSource().sendChatMessage(() -> (Text) Text.literal(playerName + " is at ") .append(Text.literal(targetBlockPos.getX() + ", " + targetBlockPos.getY() + ", " + targetBlockPos.getZ()) .formatted(utils.getDimensionColor(playerDimension))) .append(Text.literal(" in the ") - .formatted(Formatting.WHITE)) + .formatted(ChatFormatting.WHITE)) .append(Text.literal(utils.getDimensionText(playerDimension)) .formatted(utils.getDimensionColor(playerDimension))) .append(Text.literal(isSameDimension ? " (" + utils.getDistance(sourceBlockPos, targetBlockPos) + " blocks away)" : " (Player is in a different dimension)") - .formatted(isSameDimension ? Formatting.GREEN : Formatting.RED)), false); + .formatted(isSameDimension ? ChatFormatting.GREEN : ChatFormatting.RED)), false); return 1; }) ) diff --git a/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java b/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java index 5ce7a0c..90a72d7 100644 --- a/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java +++ b/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java @@ -1,17 +1,17 @@ package me.imgalvin.playerfinder; +import net.minecraft.ChatFormatting; import net.minecraft.registry.RegistryKey; -import net.minecraft.util.Formatting; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; public class PlayerFinderUtils { - public Formatting getDimensionColor(@NotNull RegistryKey playerDimension) { - return playerDimension.equals(World.OVERWORLD) ? Formatting.GREEN : - playerDimension.equals(World.NETHER) ? Formatting.RED : - playerDimension.equals(World.END) ? Formatting.LIGHT_PURPLE : - Formatting.GRAY; // Fallback color for custom or unknown dimensions + public ChatFormatting getDimensionColor(@NotNull RegistryKey playerDimension) { + return playerDimension.equals(World.OVERWORLD) ? ChatFormatting.GREEN : + playerDimension.equals(World.NETHER) ? ChatFormatting.RED : + playerDimension.equals(World.END) ? ChatFormatting.LIGHT_PURPLE : + ChatFormatting.GRAY; // Fallback colour for custom or unknown dimensions } public String getDimensionText(@NotNull RegistryKey playerDimension) { From 9c9244e734c760c02b5e89eb70dfdd2d879a5a7b Mon Sep 17 00:00:00 2001 From: GalvinPython Date: Fri, 23 Jan 2026 19:39:17 +0000 Subject: [PATCH 8/9] mod compiles, but does not work :( --- .github/workflows/build.yml | 4 +- .../imgalvin/playerfinder/PlayerFinder.java | 81 ++++++++++--------- .../playerfinder/PlayerFinderUtils.java | 19 ++--- src/main/resources/fabric.mod.json | 4 +- 4 files changed, 55 insertions(+), 53 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d7e8f1b..6f7c668 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,7 +33,7 @@ jobs: java: [ 25, # Current Java LTS ] - runs-on: ubuntu-22.04 + runs-on: ubuntu-latest steps: - name: checkout repository uses: actions/checkout@v4 @@ -49,7 +49,7 @@ jobs: - name: build run: ./gradlew build - name: capture build artifacts - if: ${{ matrix.java == '25' }} # Only upload artifacts built from latest java + if: ${{ matrix.java == '25' }} # Only upload artefacts built from latest java uses: actions/upload-artifact@v4 with: name: Artifacts diff --git a/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java b/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java index 2f2e906..715ce59 100644 --- a/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java +++ b/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java @@ -6,51 +6,52 @@ import net.minecraft.ChatFormatting; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.registry.RegistryKey; -import net.minecraft.server.command.CommandManager; -import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.level.Level; public class PlayerFinder implements ModInitializer { PlayerFinderUtils utils = new PlayerFinderUtils(); @Override public void onInitialize() { - CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { - dispatcher.register(Commands.literal("findplayer") - .then(Commands.argument("player", EntityArgument.entity()) - .executes(context -> { - String playerName = StringArgumentType.getString(context, "player"); - PlayerEntity targetPlayer = context.getSource().getServer().getPlayerManager().getPlayer(playerName); - PlayerEntity sourcePlayer = context.getSource().getPlayer(); - - assert targetPlayer != null; - assert sourcePlayer != null; - - BlockPos targetBlockPos = targetPlayer.getBlockPos(); - BlockPos sourceBlockPos = sourcePlayer.getBlockPos(); - RegistryKey playerDimension = targetPlayer.getEntityWorld().getRegistryKey(); - RegistryKey sourceDimension = sourcePlayer.getEntityWorld().getRegistryKey(); - - boolean isSameDimension = sourceDimension == playerDimension; - - context.getSource().sendChatMessage(() -> (Text) Text.literal(playerName + " is at ") - .append(Text.literal(targetBlockPos.getX() + ", " + targetBlockPos.getY() + ", " + targetBlockPos.getZ()) - .formatted(utils.getDimensionColor(playerDimension))) - .append(Text.literal(" in the ") - .formatted(ChatFormatting.WHITE)) - .append(Text.literal(utils.getDimensionText(playerDimension)) - .formatted(utils.getDimensionColor(playerDimension))) - .append(Text.literal(isSameDimension - ? " (" + utils.getDistance(sourceBlockPos, targetBlockPos) + " blocks away)" - : " (Player is in a different dimension)") - .formatted(isSameDimension ? ChatFormatting.GREEN : ChatFormatting.RED)), false); - return 1; - }) - ) - ); - }); + // _ previously registryAccess, environment + CommandRegistrationCallback.EVENT.register((dispatcher, _, _) -> dispatcher.register(Commands.literal("findplayer") + .then(Commands.argument("player", EntityArgument.entity()) + .executes(context -> { + String playerName = StringArgumentType.getString(context, "player"); + ServerPlayer targetPlayer = context.getSource().getServer().getPlayerList().getPlayer(playerName); + ServerPlayer sourcePlayer = context.getSource().getPlayer(); + + assert targetPlayer != null; + assert sourcePlayer != null; + + BlockPos targetBlockPos = targetPlayer.blockPosition(); + BlockPos sourceBlockPos = sourcePlayer.blockPosition(); + ResourceKey playerDimension = targetPlayer.level().getLevel().dimension(); + ResourceKey sourceDimension = sourcePlayer.level().getLevel().dimension(); + + boolean isSameDimension = sourceDimension == playerDimension; + + Component message = Component.literal(playerName + " is at ") + .append(Component.literal(targetBlockPos.getX() + ", " + targetBlockPos.getY() + ", " + targetBlockPos.getZ()) + .withStyle(utils.getDimensionColor(playerDimension))) + .append(Component.literal(" in the ").withStyle(ChatFormatting.WHITE)) + .append(Component.literal(utils.getDimensionText(playerDimension)) + .withStyle(utils.getDimensionColor(playerDimension))) + .append(Component.literal(isSameDimension + ? " (" + utils.getDistance(sourceBlockPos, targetBlockPos) + " blocks away)" + : " (Player is in a different dimension)") + .withStyle(isSameDimension ? ChatFormatting.GREEN : ChatFormatting.RED)); + + // Send it as a system message to the source + context.getSource().sendSystemMessage(message); + + return 1; + }) + ) + )); } } \ No newline at end of file diff --git a/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java b/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java index 90a72d7..86e929e 100644 --- a/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java +++ b/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java @@ -1,22 +1,23 @@ package me.imgalvin.playerfinder; import net.minecraft.ChatFormatting; -import net.minecraft.registry.RegistryKey; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.core.BlockPos; +import net.minecraft.resources.ResourceKey; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; public class PlayerFinderUtils { - public ChatFormatting getDimensionColor(@NotNull RegistryKey playerDimension) { - return playerDimension.equals(World.OVERWORLD) ? ChatFormatting.GREEN : - playerDimension.equals(World.NETHER) ? ChatFormatting.RED : - playerDimension.equals(World.END) ? ChatFormatting.LIGHT_PURPLE : + public ChatFormatting getDimensionColor(@NotNull ResourceKey playerDimension) { + return playerDimension.equals(ServerLevel.OVERWORLD) ? ChatFormatting.GREEN : + playerDimension.equals(ServerLevel.NETHER) ? ChatFormatting.RED : + playerDimension.equals(ServerLevel.END) ? ChatFormatting.LIGHT_PURPLE : ChatFormatting.GRAY; // Fallback colour for custom or unknown dimensions } - public String getDimensionText(@NotNull RegistryKey playerDimension) { + public String getDimensionText(@NotNull ResourceKey playerDimension) { // note: this function only works for vanilla dimensions. custom dimensions will have a slight issue - return playerDimension.getValue().toString().split(":")[1].replace("the_", ""); + return playerDimension.toString().split(":")[1].replace("the_", ""); } public int getDistance(@NotNull BlockPos playerPos, @NotNull BlockPos targetPos) { diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 41abbd6..7053f6a 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -21,8 +21,8 @@ }, "depends": { "fabricloader": ">=0.17.3", - "minecraft": "1.21.11", - "java": ">=21", + "minecraft": "26.1-alpha.3", + "java": ">=25", "fabric-api": ">=0.139.5" } } \ No newline at end of file From e3078ec665d48e129e16ee8c1b5a09b3a23f6065 Mon Sep 17 00:00:00 2001 From: GalvinPython Date: Fri, 23 Jan 2026 20:57:24 +0000 Subject: [PATCH 9/9] yeah that explains it --- .../imgalvin/playerfinder/PlayerFinder.java | 33 +++++++++++++++---- .../playerfinder/PlayerFinderUtils.java | 4 +-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java b/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java index 715ce59..20d8dad 100644 --- a/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java +++ b/src/main/java/me/imgalvin/playerfinder/PlayerFinder.java @@ -1,6 +1,5 @@ package me.imgalvin.playerfinder; -import com.mojang.brigadier.arguments.StringArgumentType; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.minecraft.ChatFormatting; @@ -11,28 +10,50 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PlayerFinder implements ModInitializer { PlayerFinderUtils utils = new PlayerFinderUtils(); + public static final Logger LOGGER = LoggerFactory.getLogger("PlayerFinder"); + @Override public void onInitialize() { + LOGGER.info("PlayerFinder initialized!"); // _ previously registryAccess, environment CommandRegistrationCallback.EVENT.register((dispatcher, _, _) -> dispatcher.register(Commands.literal("findplayer") - .then(Commands.argument("player", EntityArgument.entity()) + .then(Commands.argument("player", EntityArgument.player()) .executes(context -> { - String playerName = StringArgumentType.getString(context, "player"); + LOGGER.info("Executing /findplayer command"); + + ServerPlayer targetPlayerName = EntityArgument.getPlayer(context, "player"); + String playerName = targetPlayerName.getGameProfile().name(); + ServerPlayer targetPlayer = context.getSource().getServer().getPlayerList().getPlayer(playerName); - ServerPlayer sourcePlayer = context.getSource().getPlayer(); + ServerPlayer sourcePlayer = context.getSource().getServer().getPlayerList().getPlayer(context.getSource().getTextName()); - assert targetPlayer != null; - assert sourcePlayer != null; + if (targetPlayer == null) { + context.getSource().sendSystemMessage(Component.literal("[PlayerFinder ERROR] Player " + playerName + " not found").withStyle(ChatFormatting.RED)); + return 0; + } + if (sourcePlayer == null) { + context.getSource().sendSystemMessage(Component.literal("[PlayerFinder ERROR] Could not determine command source player").withStyle(ChatFormatting.RED)); + return 0; + } BlockPos targetBlockPos = targetPlayer.blockPosition(); BlockPos sourceBlockPos = sourcePlayer.blockPosition(); + + LOGGER.info("Target player position: {}", targetBlockPos); + LOGGER.info("Source player position: {}", sourceBlockPos); + ResourceKey playerDimension = targetPlayer.level().getLevel().dimension(); ResourceKey sourceDimension = sourcePlayer.level().getLevel().dimension(); + LOGGER.info("Target player dimension: {}", playerDimension); + LOGGER.info("Source player dimension: {}", sourceDimension); + boolean isSameDimension = sourceDimension == playerDimension; Component message = Component.literal(playerName + " is at ") diff --git a/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java b/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java index 86e929e..68d964d 100644 --- a/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java +++ b/src/main/java/me/imgalvin/playerfinder/PlayerFinderUtils.java @@ -16,11 +16,11 @@ public ChatFormatting getDimensionColor(@NotNull ResourceKey playerDimens } public String getDimensionText(@NotNull ResourceKey playerDimension) { - // note: this function only works for vanilla dimensions. custom dimensions will have a slight issue - return playerDimension.toString().split(":")[1].replace("the_", ""); + return playerDimension.identifier().getPath().replace("the_", ""); } public int getDistance(@NotNull BlockPos playerPos, @NotNull BlockPos targetPos) { + System.out.println("Calculating distance between " + playerPos + " and " + targetPos); return (int) Math.sqrt(Math.pow(playerPos.getX() - targetPos.getX(), 2) + Math.pow(playerPos.getY() - targetPos.getY(), 2) + Math.pow(playerPos.getZ() - targetPos.getZ(), 2)); } }