-
Notifications
You must be signed in to change notification settings - Fork 2
update to 26.1 (well snapshots at least) #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c201612
49118f5
53a59ed
c33b492
115d043
ca79ea0
983d2fc
7e81ed4
9c9244e
e3078ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,55 +1,78 @@ | ||||||||||||||||||||||||||||||
| 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.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; | ||||||||||||||||||||||||||||||
| import net.minecraft.ChatFormatting; | ||||||||||||||||||||||||||||||
| import net.minecraft.commands.Commands; | ||||||||||||||||||||||||||||||
| import net.minecraft.commands.arguments.EntityArgument; | ||||||||||||||||||||||||||||||
| 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; | ||||||||||||||||||||||||||||||
| 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() { | ||||||||||||||||||||||||||||||
| CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { | ||||||||||||||||||||||||||||||
| dispatcher.register(CommandManager.literal("findplayer") | ||||||||||||||||||||||||||||||
| .then(CommandManager.argument("player", StringArgumentType.string()) | ||||||||||||||||||||||||||||||
| .suggests(new PlayerSuggestionProvider()) | ||||||||||||||||||||||||||||||
| .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<World> playerDimension = targetPlayer.getEntityWorld().getRegistryKey(); | ||||||||||||||||||||||||||||||
| RegistryKey<World> sourceDimension = sourcePlayer.getEntityWorld().getRegistryKey(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| boolean isSameDimension = sourceDimension == playerDimension; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| context.getSource().sendFeedback(() -> (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)) | ||||||||||||||||||||||||||||||
| .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); | ||||||||||||||||||||||||||||||
| return 1; | ||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| LOGGER.info("PlayerFinder initialized!"); | ||||||||||||||||||||||||||||||
| // _ previously registryAccess, environment | ||||||||||||||||||||||||||||||
| CommandRegistrationCallback.EVENT.register((dispatcher, _, _) -> dispatcher.register(Commands.literal("findplayer") | ||||||||||||||||||||||||||||||
| .then(Commands.argument("player", EntityArgument.player()) | ||||||||||||||||||||||||||||||
| .executes(context -> { | ||||||||||||||||||||||||||||||
| 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().getServer().getPlayerList().getPlayer(context.getSource().getTextName()); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+35
|
||||||||||||||||||||||||||||||
| if (targetPlayer == null) { | ||||||||||||||||||||||||||||||
| context.getSource().sendSystemMessage(Component.literal("[PlayerFinder ERROR] Player " + playerName + " not found").withStyle(ChatFormatting.RED)); | ||||||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+39
|
||||||||||||||||||||||||||||||
| ServerPlayer targetPlayerName = EntityArgument.getPlayer(context, "player"); | |
| String playerName = targetPlayerName.getGameProfile().name(); | |
| ServerPlayer targetPlayer = context.getSource().getServer().getPlayerList().getPlayer(playerName); | |
| ServerPlayer sourcePlayer = context.getSource().getServer().getPlayerList().getPlayer(context.getSource().getTextName()); | |
| if (targetPlayer == null) { | |
| context.getSource().sendSystemMessage(Component.literal("[PlayerFinder ERROR] Player " + playerName + " not found").withStyle(ChatFormatting.RED)); | |
| return 0; | |
| } | |
| ServerPlayer targetPlayer = EntityArgument.getPlayer(context, "player"); | |
| String playerName = targetPlayer.getGameProfile().getName(); | |
| ServerPlayer sourcePlayer = context.getSource().getServer().getPlayerList().getPlayer(context.getSource().getTextName()); |
Copilot
AI
Mar 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dimension key retrieval uses targetPlayer.level().getLevel().dimension(). For a ServerPlayer, level() already returns the level instance; the extra getLevel() call is likely invalid and will not compile. Use the level API directly to get the dimension key (e.g., targetPlayer.level().dimension()).
| ResourceKey<Level> playerDimension = targetPlayer.level().getLevel().dimension(); | |
| ResourceKey<Level> sourceDimension = sourcePlayer.level().getLevel().dimension(); | |
| ResourceKey<Level> playerDimension = targetPlayer.level().dimension(); | |
| ResourceKey<Level> sourceDimension = sourcePlayer.level().dimension(); |
Copilot
AI
Mar 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isSameDimension compares ResourceKey instances with ==. Use .equals(...) to compare keys reliably, since reference equality is not guaranteed.
| boolean isSameDimension = sourceDimension == playerDimension; | |
| boolean isSameDimension = sourceDimension.equals(playerDimension); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,25 +1,26 @@ | ||||||||||||||||
| package me.imgalvin.playerfinder; | ||||||||||||||||
|
|
||||||||||||||||
| import net.minecraft.registry.RegistryKey; | ||||||||||||||||
| import net.minecraft.util.Formatting; | ||||||||||||||||
| import net.minecraft.util.math.BlockPos; | ||||||||||||||||
| import net.minecraft.world.World; | ||||||||||||||||
| import net.minecraft.ChatFormatting; | ||||||||||||||||
| 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 Formatting getDimensionColor(@NotNull RegistryKey<World> 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 ResourceKey<Level> 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 | ||||||||||||||||
|
Comment on lines
+11
to
+15
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| public String getDimensionText(@NotNull RegistryKey<World> playerDimension) { | ||||||||||||||||
| // note: this function only works for vanilla dimensions. custom dimensions will have a slight issue | ||||||||||||||||
| return playerDimension.getValue().toString().split(":")[1].replace("the_", ""); | ||||||||||||||||
| public String getDimensionText(@NotNull ResourceKey<Level> playerDimension) { | ||||||||||||||||
| return playerDimension.identifier().getPath().replace("the_", ""); | ||||||||||||||||
|
||||||||||||||||
| return playerDimension.identifier().getPath().replace("the_", ""); | |
| return playerDimension.location().getPath().replace("the_", ""); |
Copilot
AI
Mar 23, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The System.out.println in getDistance will spam stdout on every /findplayer call. Remove this debug print or route it through the mod logger at a debug level.
| 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)); | |
| 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) | |
| ); |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda parameters are named
_, but a single underscore is a reserved keyword in Java (since Java 9), so this will not compile. Rename these unused parameters to something likeregistryAccess/environmentorignoredRegistryAccess/ignoredEnvironment.