Resolved Custom event

Discussion in 'Developer Support' started by TheVTM, Apr 12, 2016.

  1. TheVTM

    Joined:
    Mar 29, 2016
    Messages:
    52
    Likes Received:
    7
    I'm trying to use the EventDispatcher (com.runemate.game.api.script bot.framework.core.EventDispatcher) to fire a custom event I created.

    It's not working (its not dispaching) and I can't figure it out why.

    Custom Event:
    Code (Text):
    1. package com.TheVTM.bots.BonePrayer.Events;
    2.  
    3. import com.TheVTM.bots.BonePrayer.UserConfiguration;
    4.  
    5. import java.util.EventObject;
    6.  
    7. public class ConfigurationEvent extends EventObject {
    8.     public UserConfiguration userConfiguration;
    9.  
    10.     public ConfigurationEvent(Object source, UserConfiguration userConfiguration) {
    11.         super(source);
    12.         this.userConfiguration = userConfiguration;
    13.     }
    14. }
    15.  
    Event Listener Interface:
    Code (Text):
    1. package com.TheVTM.bots.BonePrayer.Events.Listeners;
    2.  
    3. import com.TheVTM.bots.BonePrayer.Events.ConfigurationEvent;
    4.  
    5. import java.util.EventListener;
    6.  
    7. public interface ConfigurationListener extends EventListener {
    8.     public void onConfiguration(ConfigurationEvent event);
    9. }
    10.  
    Usage:
    Code (Text):
    1.  
    2. public class Statistics implements ConfigurationListener {
    3. public Statistics() {
    4.   // Register Listeners
    5.   Environment.getScript().getEventDispatcher().addListener(this);
    6. }
    7.  
    8. @Override
    9. public void onConfiguration(ConfigurationEvent event) {
    10.   LOGGER.log(Level.CONFIG, "Configuring Statistics...");
    11.   // Initialize variables
    12.   initialLevel = Skill.PRAYER.getBaseLevel();
    13.   initialExperiece = Skill.PRAYER.getExperience();
    14.   bonesCounter = 0;
    15.   startTime = System.currentTimeMillis();
    16. }
    17. }
    18.  
    Fire Event:
    Code (Text):
    1. public class BonePrayer extends TaskScript {
    2.  
    3. @Override
    4. public void onStart(String...a) {
    5.   super.onStart(a);
    6.  
    7.   ConfigurationEvent configurationEvent = new ConfigurationEvent(this,
    8.    new UserConfiguration(Players.getLocal().getPosition(), 7));
    9.   getEventDispatcher().process(configurationEvent);
    10. }
    11.  
    12. }


     
  2. Best Answer:
    Post #4 by Arbiter, Apr 13, 2016
  3. Arbiter

    Arbiter Mod Automation

    Joined:
    Jul 26, 2013
    Messages:
    2,556
    Likes Received:
    1,079
    Are you adding whatever class implements ConfigurationListener as an event dispatcher?
     
  4. TheVTM

    Joined:
    Mar 29, 2016
    Messages:
    52
    Likes Received:
    7
    No, just as a listener.
    How do I do that?
     
  5. Arbiter

    Arbiter Mod Automation

    Joined:
    Jul 26, 2013
    Messages:
    2,556
    Likes Received:
    1,079
    Looking at the source code, the event dispatcher is not intended to be extended with custom listeners and events. You could always build your own async engine to achieve this result.
     
  6. TheVTM

    Joined:
    Mar 29, 2016
    Messages:
    52
    Likes Received:
    7
    Ok, thank you!!
     

Share This Page

Loading...