1+ package com .nerds .addon .commands ;
2+
3+ import com .mojang .brigadier .arguments .StringArgumentType ;
4+ import com .mojang .brigadier .builder .LiteralArgumentBuilder ;
5+ import com .mojang .brigadier .suggestion .SuggestionProvider ;
6+ import meteordevelopment .meteorclient .commands .Command ;
7+ import net .minecraft .client .network .AbstractClientPlayerEntity ;
8+ import net .minecraft .command .CommandSource ;
9+
10+ import static com .mojang .brigadier .Command .SINGLE_SUCCESS ;
11+ import static meteordevelopment .meteorclient .MeteorClient .mc ;
12+
13+ public class Coords extends Command {
14+
15+ private static final SuggestionProvider <CommandSource > PLAYER_SUGGESTIONS = (context , builder ) -> {
16+ if (mc .world == null ) return builder .buildFuture ();
17+
18+ String remaining = builder .getRemaining ().toLowerCase ();
19+
20+ for (AbstractClientPlayerEntity player : mc .world .getPlayers ()) {
21+ String name = player .getGameProfile ().name ();
22+ if (name .toLowerCase ().startsWith (remaining )) {
23+ builder .suggest (name );
24+ }
25+ }
26+
27+ return builder .buildFuture ();
28+ };
29+
30+ public Coords () {
31+ super ("coords" , "copies your (or another player's) coordinates to your clipboard." );
32+ }
33+
34+ @ Override
35+ public void build (LiteralArgumentBuilder <CommandSource > builder ) {
36+ builder .executes (context -> {
37+ if (mc .player == null ) return SINGLE_SUCCESS ;
38+ copyCoords (mc .player .getGameProfile ().name (), mc .player .getX (), mc .player .getY (), mc .player .getZ ());
39+ return SINGLE_SUCCESS ;
40+ });
41+
42+ builder .then (argument ("player" , StringArgumentType .word ())
43+ .suggests (PLAYER_SUGGESTIONS )
44+ .executes (context -> {
45+ if (mc .world == null ) return SINGLE_SUCCESS ;
46+
47+ String targetName = StringArgumentType .getString (context , "player" );
48+ AbstractClientPlayerEntity target = null ;
49+
50+ for (AbstractClientPlayerEntity player : mc .world .getPlayers ()) {
51+ if (player .getGameProfile ().name ().equalsIgnoreCase (targetName )) {
52+ target = player ;
53+ break ;
54+ }
55+ }
56+
57+ if (target == null ) {
58+ error ("player \" " + targetName + "\" not found." );
59+ return SINGLE_SUCCESS ;
60+ }
61+
62+ copyCoords (target .getGameProfile ().name (), target .getX (), target .getY (), target .getZ ());
63+ return SINGLE_SUCCESS ;
64+ })
65+ );
66+ }
67+
68+ private void copyCoords (String name , double x , double y , double z ) {
69+ String text = "x: " + (int ) Math .floor (x ) + " y: " + (int ) Math .floor (y ) + " z: " + (int ) Math .floor (z );
70+ mc .keyboard .setClipboard (text );
71+ boolean isSelf = mc .player != null && name .equals (mc .player .getGameProfile ().name ());
72+ info ("successfully copied " + (isSelf ? "your" : name + "'s" ) + " coordinates: \n " + text );
73+ }
74+ }
0 commit comments