1
1
package me .ricglz .discoords ;
2
2
3
+ import org .bukkit .ChatColor ;
3
4
import org .bukkit .Location ;
4
5
import org .bukkit .command .Command ;
5
6
import org .bukkit .command .CommandExecutor ;
@@ -15,28 +16,25 @@ public class DiscoordsCommandExecutor implements CommandExecutor {
15
16
this .channel = channel ;
16
17
}
17
18
19
+ private void sendError (CommandSender sender , String error ) {
20
+ sender .sendMessage (ChatColor .RED + String .format ("[Error] %s" , error ));
21
+ }
22
+
18
23
@ Override
19
24
public boolean onCommand (CommandSender sender , Command command , String label , String [] args ) {
20
- if (args .length > 1 ) {
21
- sender .sendMessage ("[Error] The command doesn't accept as many arguments" );
22
- return false ;
23
- }
24
25
if (!(sender instanceof Player )) {
25
- sender .sendMessage ("[Error] You must be a player!" );
26
- return true ;
26
+ sendError (sender , "You must be a player!" );
27
+ } else if (channel == null ) {
28
+ sendError (sender , "Discord is not available" );
29
+ } else {
30
+ Player player = (Player ) sender ;
31
+ Location loc = player .getLocation ();
32
+ String coordinateValues = String .join (" " , args );
33
+ String locString = String .format ("(%d, %d, %d)" , (int ) loc .getX (), (int ) loc .getY (), (int ) loc .getZ ());
34
+ String msg = coordinateValues .isEmpty () ? locString : String .format ("%s - %s" , locString , coordinateValues );
35
+ sender .sendMessage (msg );
36
+ sendLocation (msg , ChatColor .stripColor (player .getDisplayName ()));
27
37
}
28
- if (channel == null ) {
29
- sender .sendMessage ("[Error] Discoord is not available" );
30
- return true ;
31
- }
32
-
33
- Player player = (Player ) sender ;
34
- Location loc = player .getLocation ();
35
- String locString = String .format ("(%d, %d, %d)" , (int ) loc .getX (), (int ) loc .getY (), (int ) loc .getZ ());
36
- String msg = args .length == 0 ? locString : String .format ("%s - %s" , locString , args [0 ]);
37
- sender .sendMessage (msg );
38
- sendLocation (msg , player .getDisplayName ());
39
-
40
38
return true ;
41
39
}
42
40
0 commit comments