Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this code might or might not work as it is and is just a concept
- class TimerPlugin implements IPlugin {
- Timer timer;
- BotAccess botAccess;
- @Override
- public void onLoad(BotAccess botAccess) {
- this.botAccess = botAccess;
- botAccess.commandManager.registerHandler(Commands.class)
- timer = new Timer(
- botAccess.config.get("ssh", "sessionTimeout", 60000 /* 1 minute by default */, "The Timeout for a session").getInt(),
- botAccess.eventBus);
- botAccess.eventBus.register(this);
- }
- @Subscribe
- public void onRehash(RehashEvent event) {
- timer.stop(); // make sure to stop timer first
- timer = new Timer(
- botAccess.config.get("ssh", "sessionTimeout", 60000 /* 1 minute by default */, "The Timeout for a session").getInt(),
- botAccess.eventBus);
- }
- @Subscribe
- public void onSessionExpiery(TimerEvent event) {
- if (event.timer != timer) return;
- // Code to destroy session here
- }
- @Subscribe
- public void onTimerInterrupt(TimerInterruptedEvent event) {
- if (event.timer != timer) return;
- botAccess.eventBus.postLocal(new TimerEvent(event.timer)); //postLocal() makes it not dispatch events to other eventBusses
- }
- private class Commands extends CommandsHandler {
- @Command(name = "mcc", usage = "", help = "" /*[OPTIONAL], permission = "cmd.ssh.mcc" */)
- public void mcc() {
- timer.run(); // starts the timer, or if its already running resets the time
- }
- @Command(name = "destroysession", usage = "", help = "destroys a session")
- public void killsession() {
- timer.stop();
- }
- }
- @Override
- public void onUnload() {
- // No need to stop timer here because the plugin will always be disabled before unloading it
- }
- @Subscribe
- public void onDisable(DisableEvent event) {
- timer.stop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement