6
6
import net .dv8tion .jda .api .JDABuilder ;
7
7
import net .dv8tion .jda .api .entities .TextChannel ;
8
8
9
- import org .bukkit .Location ;
10
- import org .bukkit .command .Command ;
11
- import org .bukkit .command .CommandSender ;
12
- import org .bukkit .entity .Player ;
13
9
import org .bukkit .plugin .java .JavaPlugin ;
14
10
15
11
/**
@@ -28,54 +24,17 @@ public void onEnable() {
28
24
try {
29
25
jda = JDABuilder .createDefault (token ).build ().awaitReady ();
30
26
channel = jda .getTextChannelById (channelID );
31
- if (channel == null ) {
32
- getLogger ().warning ("The channel id is incorrect" );
33
- return ;
34
- }
35
- channel .sendMessage (welcomeMessage ).queue ();
36
27
} catch (LoginException | InterruptedException e ) {
37
28
getLogger ().warning ("There was a problem building the bot. It may be due to the token" );
38
29
if (e instanceof InterruptedException ) {
39
30
Thread .currentThread ().interrupt ();
40
31
}
41
32
}
42
- }
43
-
44
- @ Override
45
- public boolean onCommand (CommandSender sender , Command cmd , String label , String [] args ) {
46
- if (cmd .getName ().equalsIgnoreCase ("discoords" )) {
47
- if (args .length > 1 ) {
48
- sender .sendMessage ("The command doesn't accept as many arguments" );
49
- return false ;
50
- }
51
- if (jda == null || channel == null ) {
52
- sender .sendMessage ("Discoord is not available" );
53
- return true ;
54
- }
55
- if (sender instanceof Player ) {
56
- Player player = (Player ) sender ;
57
- Location loc = player .getLocation ();
58
- String locString = String .format ("(%d, %d, %d)" , (int ) loc .getX (), (int ) loc .getY (), (int ) loc .getZ ());
59
- String msg = args .length == 0 ? locString : String .format ("%s - %s" , locString , args [0 ]);
60
- sender .sendMessage (msg );
61
- sendLocation (msg , player .getDisplayName ());
62
- } else {
63
- sender .sendMessage ("You must be a player!" );
64
- }
65
- return true ;
33
+ if (channel == null ) {
34
+ getLogger ().warning ("The channel id is incorrect" );
35
+ return ;
66
36
}
67
- return true ;
68
- }
69
-
70
- /**
71
- * Sends a mesage about the current location and the player name to the
72
- * designated discord channel
73
- *
74
- * @param sentMessage Message that was sent to the player in Minecraft
75
- * @param playerName Name of the player who executed the command
76
- */
77
- private void sendLocation (String sentMessage , String playerName ) {
78
- String msg = String .format ("%s - by %s" , sentMessage , playerName );
79
- channel .sendMessage (msg ).queue ();
37
+ channel .sendMessage (welcomeMessage ).queue ();
38
+ this .getCommand ("discoords" ).setExecutor (new DiscoordsCommandExecutor (channel ));
80
39
}
81
40
}
0 commit comments