CommandListener almost done
This commit is contained in:
parent
441db0b6e6
commit
6ab6bc9fc6
3 changed files with 34 additions and 5 deletions
|
@ -1,13 +1,33 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import sx.blah.discord.api.events.IListener;
|
||||
import sx.blah.discord.handle.impl.events.MentionEvent;
|
||||
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
||||
import sx.blah.discord.handle.obj.IChannel;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
|
||||
public class CommandListener implements IListener<MessageReceivedEvent> {
|
||||
public class CommandListener {
|
||||
|
||||
public static IListener<?>[] getListeners() {
|
||||
return new IListener[] { new IListener<MentionEvent>() {
|
||||
@Override
|
||||
public void handle(MentionEvent event) {
|
||||
final IChannel channel = event.getMessage().getChannel();
|
||||
if (!channel.getID().equals(DiscordPlugin.botchannel.getID()) && !channel.isPrivate())
|
||||
return;
|
||||
runCommand(event.getMessage());
|
||||
}
|
||||
}, new IListener<MessageReceivedEvent>() {
|
||||
@Override
|
||||
public void handle(MessageReceivedEvent event) {
|
||||
System.out.println(event.getMessage().getContent());
|
||||
if (!event.getMessage().getChannel().isPrivate())
|
||||
return;
|
||||
runCommand(event.getMessage());
|
||||
}
|
||||
} };
|
||||
}
|
||||
|
||||
private static void runCommand(IMessage message) {
|
||||
System.out.println(message.getContent()); // TODO: Resolve mentions
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,9 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
cb.withToken(Files.readFirstLine(new File("TBMC", "Token.txt"), StandardCharsets.UTF_8));
|
||||
dc = cb.login();
|
||||
dc.getDispatcher().registerListener(this);
|
||||
dc.getDispatcher().registerListener(new CommandListener());
|
||||
for (IListener<?> listener : CommandListener.getListeners())
|
||||
dc.getDispatcher().registerListener(listener);
|
||||
Bukkit.getPluginManager().registerEvents(new MCListener(), this);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
public abstract class DiscordCommandBase {
|
||||
public abstract String getCommandName();
|
||||
|
||||
public abstract void Run();
|
||||
}
|
Loading…
Reference in a new issue