CommandListener almost done

This commit is contained in:
Norbi Peti 2016-10-22 01:59:58 +02:00
parent 441db0b6e6
commit 6ab6bc9fc6
3 changed files with 34 additions and 5 deletions

View file

@ -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 {
@Override
public void handle(MessageReceivedEvent event) {
System.out.println(event.getMessage().getContent());
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) {
if (!event.getMessage().getChannel().isPrivate())
return;
runCommand(event.getMessage());
}
} };
}
private static void runCommand(IMessage message) {
System.out.println(message.getContent()); // TODO: Resolve mentions
}
}

View file

@ -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);

View file

@ -0,0 +1,7 @@
package buttondevteam.discordplugin.commands;
public abstract class DiscordCommandBase {
public abstract String getCommandName();
public abstract void Run();
}