Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Event Listeners

Joined
Feb 23, 2021
Messages
4
Hi,

For the life of me I cant get the EventListeners to work.

I found this post which I think steered me in right direction, but still I cant log out anything in the event methods and my debugger wont stick inside those methods either. But it did not seem to help me.
Resolved - Event listener not firing?

Any suggestions or examples on this matter?


This is my EventListener

Code:
@NoArgsConstructor
public class PrayerFlick implements EngineListener {

    @Override
    public void onCycleStart() {
        Environment.getBot().getLogger().info("Experience gained 1");
    }

    @Override
    public void onTickStart() {
        Environment.getBot().getLogger().info("Experience gained 2");
    }

    @Override
    public void onEngineStateChanged(EngineStateEvent event) {
        Environment.getBot().getLogger().info("Experience gained 3" + event.toString());
    }
}

And this is my Main bot
Code:
public class RunBot extends TreeBot {

    public PrayerFlick prayerFlick = new PrayerFlick();
    public EmptyRoot emptyRoot = new EmptyRoot();

    public void onStart(String... arguments) {
        this.getEventDispatcher().addListener(prayerFlick);
        Environment.getBot().getLogger().info("Done");
    }

    @Override
    public LeafTask createRootTask() {
        return emptyRoot;
    }
}
 
Last edited:
Hexis bots go brrr
Joined
Dec 9, 2016
Messages
4,635
Are you certain you're compiling and running the most recent version of the code? This all looks fine to me.
 
Joined
Feb 23, 2021
Messages
4
I am quite certain, because I see the onStart() method log with a message "Done" and now when I added a log saying "Started" at the beginning, I can also see that new log line after running the bot.

But maybe there is more definitive way to tell?
 
Bot Author
Joined
Jan 29, 2016
Messages
1,294
Firstly, you're using deprecated code so if you're looking to eventually publish this onto the bot store, it will automatically get rejected.

"But maybe there is more definitive way to tell?"

Yes. You could use a .getListeners and see if it was ever added.
 
Joined
Feb 23, 2021
Messages
4
I checked .getlisteners right away and it gets added.

Where do I get the "non" deprecated code? Or do you mean only the .getLogger is deprecated? If so, Its just there for debugging purposes.
 
Bot Author
Joined
Jan 29, 2016
Messages
1,294
I checked .getlisteners right away and it gets added.

Where do I get the "non" deprecated code? Or do you mean only the .getLogger is deprecated? If so, Its just there for debugging purposes.

Even for debugging purposes, you should really be using Log4j2, easily implemented. -> Saves you time writing all that bs code out too when you could just easily write log.debug(msg)
 
Joined
Feb 23, 2021
Messages
4
Yeah, you are absolutely right. Was just doing it for me at the moment not for the store, still trying to figure out the API. Never wrote a bot for a runescape with a API, wrote one with image recognizion in python about 10 years ago.

Coming back to the initial topic, any ideas on the Events not firing? Anything else I can try?
I am just out of ideas.
 
Top