- Joined
- Apr 27, 2019
- Messages
- 11
- Thread Author
- #1
When you start a bot with the client logged out, upon logging in it will trigger the onItemAdded event for each item you have currently in your inventory. If the client is logged in already when the bot is started, this does not happen, nor does it happen if you later log the client out and back in again (as in with a break handler).
To me, this behavior seems a bit inconsistent. I feel like it should either:
A. Trigger onItemAdded every time you log the client in.
or
B. Never trigger onItemAdded when you log the client in.
My preference, and the most logical given the name of the event, would be option B. Currently, I've circumvented the behavior by delaying adding the listener until a second after the client has logged in, but I worry that on some laggy connections or slower computers, a second may be too short. On the other hand, raising this delay to cover this will make the bot seem to take an eternity to load for people with faster connections/better computers.
My current code looks (something) like this:
This doesn't feel optimal. It does work. Is there another method that I've missed along the way to prevent the firing of the onItemAdded event when the client first logs on, or does basically everyone do something like this? I assume this behaves in this manner because the RuneMate API loads the inventory prior to executing the onStart if the client is already logged in, but has to load it after the onStart if the client is not logged in, since it executes the login handler after the onStart method returns.
One potential "fix" for this, then, assuming my above assumptions are correct, would be to log the client in prior to executing the onStart method of the bot. While I don't have a great deal of botting experience, what little I do have suggests that most bots assume or desire that the client be logged in right at the start, then may log the client off for breaks later. A possible exception may be complex bots that take time to configure in a UI prior to starting execution, but even then they could disable the login handler and let the client time out if necessary (or allow them to disable the login handler, but handle the side effects of that behavior on their own).
Comments? Suggestions?
To me, this behavior seems a bit inconsistent. I feel like it should either:
A. Trigger onItemAdded every time you log the client in.
or
B. Never trigger onItemAdded when you log the client in.
My preference, and the most logical given the name of the event, would be option B. Currently, I've circumvented the behavior by delaying adding the listener until a second after the client has logged in, but I worry that on some laggy connections or slower computers, a second may be too short. On the other hand, raising this delay to cover this will make the bot seem to take an eternity to load for people with faster connections/better computers.
My current code looks (something) like this:
Code:
public ExecutorService executorService = Executors.newCachedThreadPool();
public LootWatcher loot;
@Override
public void onStart(String... arguments) {
loot = new LootWatcher(this);
executorService.execute(() -> {
while (!RuneScape.isLoggedIn()) {
Execution.delay(100);
}
Execution.delay(1000);
getEventDispatcher().addListener(loot);
});
}
This doesn't feel optimal. It does work. Is there another method that I've missed along the way to prevent the firing of the onItemAdded event when the client first logs on, or does basically everyone do something like this? I assume this behaves in this manner because the RuneMate API loads the inventory prior to executing the onStart if the client is already logged in, but has to load it after the onStart if the client is not logged in, since it executes the login handler after the onStart method returns.
One potential "fix" for this, then, assuming my above assumptions are correct, would be to log the client in prior to executing the onStart method of the bot. While I don't have a great deal of botting experience, what little I do have suggests that most bots assume or desire that the client be logged in right at the start, then may log the client off for breaks later. A possible exception may be complex bots that take time to configure in a UI prior to starting execution, but even then they could disable the login handler and let the client time out if necessary (or allow them to disable the login handler, but handle the side effects of that behavior on their own).
Comments? Suggestions?