@@ -55,13 +55,15 @@ Commands.literal("flyspeed")
55
55
.then(Commands . argument(" speed" , FloatArgumentType . floatArg(0 , 1.0f ))
56
56
.executes(ctx - > {
57
57
float speed = ctx. getArgument(" speed" , float . class); // Retrieve the speed argument
58
+ // highlight-next-line
58
59
CommandSender sender = ctx. getSource(). getSender(); // Retrieve the command sender
60
+ // highlight-next-line
59
61
Entity executor = ctx. getSource(). getExecutor(); // Retrieve the command executor, which may or may not be the same as the sender
60
62
61
63
// Check whether the executor is a player, as you can only set a player's flight speed
62
64
if (! (executor instanceof Player player)) {
63
65
// If a non-player tried to set their own flight speed
64
- sender. sendMessage (" Only players can fly!" );
66
+ sender. sendPlainMessage (" Only players can fly!" );
65
67
return Command . SINGLE_SUCCESS ;
66
68
}
67
69
@@ -70,12 +72,12 @@ Commands.literal("flyspeed")
70
72
71
73
if (sender == executor) {
72
74
// If the player executed the command themselves
73
- player. sendMessage( Component . text( " Successfully set your flight speed to " + speed) );
75
+ player. sendPlainMessage( " Successfully set your flight speed to " + speed);
74
76
}
75
77
else {
76
78
// If the speed was set by a different sender (Like using /execute)
77
79
sender. sendRichMessage(" Successfully set <playername>'s flight speed to " + speed, Placeholder . component(" playername" , player. name()));
78
- player. sendMessage( Component . text( " Your flight speed has been set to " + speed) );
80
+ player. sendPlainMessage( " Your flight speed has been set to " + speed);
79
81
}
80
82
81
83
return Command . SINGLE_SUCCESS ;
@@ -133,23 +135,28 @@ public class FlightSpeedCommand {
133
135
}
134
136
135
137
private static int runFlySpeedLogic (CommandContext<CommandSourceStack > ctx ) {
136
- float speed = ctx. getArgument(" speed" , float . class);
137
- CommandSender sender = ctx. getSource(). getSender();
138
- Entity executor = ctx. getSource(). getExecutor();
138
+ float speed = ctx. getArgument(" speed" , float . class); // Retrieve the speed argument
139
+ CommandSender sender = ctx. getSource(). getSender(); // Retrieve the command sender
140
+ Entity executor = ctx. getSource(). getExecutor(); // Retrieve the command executor, which may or may not be the same as the sender
141
+
142
+ // Check whether the executor is a player, as you can only set a player's flight speed
143
+ if (! (executor instanceof Player player)) {
144
+ // If a non-player tried to set their own flight speed
145
+ sender. sendPlainMessage(" Only players can fly!" );
146
+ return Command . SINGLE_SUCCESS ;
147
+ }
139
148
140
- if (executor instanceof Player player) {
141
- player. setFlySpeed(speed);
149
+ // Set the player's speed
150
+ player. setFlySpeed(speed);
142
151
143
- if (sender == executor) {
144
- player. sendMessage(" Successfully set your flight speed to " + speed);
145
- }
146
- else {
147
- sender. sendMessage(" Successfully set " + player. getName() + " 's flight speed to " + speed);
148
- player. sendMessage(" Your flight speed has been set to " + speed);
149
- }
152
+ if (sender == executor) {
153
+ // If the player executed the command themselves
154
+ player. sendPlainMessage(" Successfully set your flight speed to " + speed);
150
155
}
151
156
else {
152
- sender. sendMessage(" Consoles can't fly!" );
157
+ // If the speed was set by a different sender (Like using /execute)
158
+ sender. sendRichMessage(" Successfully set <playername>'s flight speed to " + speed, Placeholder . component(" playername" , player. name()));
159
+ player. sendPlainMessage(" Your flight speed has been set to " + speed);
153
160
}
154
161
155
162
return Command . SINGLE_SUCCESS ;
0 commit comments