22
33import com .mojang .brigadier .builder .LiteralArgumentBuilder ;
44import com .mojang .brigadier .context .CommandContext ;
5- import dev .dfonline .flint .feature .trait .ChatListeningFeature ;
5+ import dev .dfonline .flint .Flint ;
6+ import dev .dfonline .flint .feature .impl .LocateFeature ;
67import dev .dfonline .flint .feature .trait .CommandFeature ;
7- import dev .dfonline .flint .util . result . ReplacementEventResult ;
8+ import dev .dfonline .flint .hypercube . Mode ;
89import net .fabricmc .fabric .api .client .command .v2 .FabricClientCommandSource ;
910import net .minecraft .command .CommandRegistryAccess ;
1011import net .minecraft .command .argument .EntityArgumentType ;
11- import net .minecraft .text .ClickEvent ;
12- import net .minecraft .text .Text ;
1312import org .zbinfinn .wecode .CommandSender ;
1413import org .zbinfinn .wecode .WeCode ;
1514import org .zbinfinn .wecode .helpers .NotificationHelper ;
1615
1716import static net .fabricmc .fabric .api .client .command .v2 .ClientCommandManager .argument ;
1817
19- public class PlayerJoinCommand implements CommandFeature , ChatListeningFeature {
18+ public class PlayerJoinCommand implements CommandFeature {
2019 private boolean locating = false ;
21- private long initialTime = 0 ;
2220
2321 @ Override
2422 public String commandName () {
@@ -44,50 +42,26 @@ private int playerJoin(CommandContext<FabricClientCommandSource> context) {
4442 return 0 ;
4543 }
4644
47- initialTime = System .currentTimeMillis ();
4845 locating = true ;
49- CommandSender .queue ("locate " + playerName );
50- return 0 ;
51- }
5246
53- @ Override
54- public ReplacementEventResult <Text > onChatMessage (Text text , boolean b ) {
55- if (!locating ) {
56- return ReplacementEventResult .pass ();
57- }
58-
59- if (System .currentTimeMillis () - initialTime > 1000 ) {
60- NotificationHelper .sendFailNotification ("/pjoin request timed out" , 3 );
47+ LocateFeature .requestLocate (playerName ).thenAccept (locate -> {
6148 locating = false ;
62- return ReplacementEventResult .pass ();
63- }
6449
65- String message = text .getString ();
66- String [] split = message .split ("\n " );
67- if (split .length == 4 ) {
68- String line2 = split [1 ];
69- if (line2 .matches ("[a-zA-Z0-9_\\ -]+ is currently at spawn" )) {
70- NotificationHelper .sendFailNotification ("That player isnt on any game" , 3 );
50+ if (locate == null ) {
51+ NotificationHelper .sendFailNotification ("Something went wrong" , 3 );
52+ return ;
7153 }
72- return ReplacementEventResult .pass ();
73- }
7454
75- if (split .length != 8 ) {
76- return ReplacementEventResult .pass ();
77- }
55+ if (locate .mode () == Mode .SPAWN ) {
56+ if (locate .node () != Flint .getUser ().getNode ())
57+ CommandSender .queue ("server " + locate .node ().getId ());
58+
59+ NotificationHelper .sendFailNotification ("That player is at spawn" , 3 );
60+ return ;
61+ }
7862
79- if (!split [1 ].matches ("[a-zA-Z0-9_\\ -]+ is currently playing on:" )) {
80- return ReplacementEventResult .pass ();
81- }
82- if (!split [3 ].startsWith ("→ " ) || !split [4 ].startsWith ("→ " ) || !split [5 ].startsWith ("→ " ) || !split [6 ].startsWith ("→ " )) {
83- return ReplacementEventResult .pass ();
84- }
85- ClickEvent event = text .getStyle ().getClickEvent ();
86- if (event .getAction () != (ClickEvent .Action .RUN_COMMAND )) {
87- return ReplacementEventResult .pass ();
88- }
89- CommandSender .queue (text .getStyle ().getClickEvent ().getValue ().substring (1 ));
90- locating = false ;
91- return ReplacementEventResult .cancel ();
63+ CommandSender .queue ("join " + locate .plot ().getId ());
64+ });
65+ return 0 ;
9266 }
9367}
0 commit comments