-
Notifications
You must be signed in to change notification settings - Fork 8
Making plugins
In this step it's assumed you have a working clone of OnlineGuru with irclib.
First thing you need to do is make a new folder for your plugin. The folder must be located in
/src/main/java/no/ntnu/online/onlineguru/plugin/plugins
The folder should be in all lower case letters and be as short as possible while maintaining readability
Next you make a class in that directory, which needs to implement one of the Plugin interfaces. The only difference between them is that one of those interfaces supports using other Plugins as dependencies for your plugin. Just use the "Plugin" interface for now.
After inserting the methods from the interface, you should have 4 empty methods in your class.
public String getDescription();
This method should return a relatively short string describing the nature of your plugin.
public void incomingEvent(Event e);
The irclib which the bot is built on is Event-driven. This method is the receiving end of an observer-pattern.
The most commonly used event type is "PRIVMSG", and means all the messages sent by users to a channel or other users. Remember that Event is a superclass for all events, and you need to cast this to the correct event before using it in your plugin.
You can easily compare types of events by using the EventType enum in irclib. You can also see all available events in that enum.
public void addEventDistributor(EventDistributor eventDistributor);
This is the method where you select which events you are going to subscribe to. easily done by using the addListener method in eventDistributor;
eventDistributor.addListener(this, EventType.PRIVMSG);
public void addWand(Wand wand);
All this does is add the Wand to your plugin. this.wand = wand;
is all you need to do here.
The Wand contains all the methods you need to communicate back to the irclib, like sending messages or kicking someone.
When you are ready to try your plugin, you have to add it to the PluginManager. It is located in the control folder of the plugin directory.
The method which handles instantiation of plugins is called loadPlugins(). You should only add the plugin to the list like the other ones listed there. A new record for YourPlugin.java looks like this;
initiatePlugin(new YourPlugin());
The rest now is up to you.