Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: CampaignEventListener not being called  (Read 2162 times)

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
CampaignEventListener not being called
« on: November 16, 2018, 06:50:50 PM »

For some reason, reportPlayerEngagement() and reportPlayerMarketTransaction() aren't being called for my campaign event listener. Those are the only two listener methods I'm using, so I'm not sure if the others are affected.

The listener is being registered with
Code: java
        Global.getSector().addTransientScript(saver);
        Global.getSector().getListenerManager().addListener(saver, true);

And the source of the listener itself is here. ListenerManagerAPI.getListeners() shows it's been registered, but the listener's methods are never called.
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: CampaignEventListener not being called
« Reply #1 on: November 16, 2018, 06:55:01 PM »

Those are CampaignEventListener methods, so that's only going to get called if you add it via SectorAPI.addListener().

ListenerManager supports the interfaces in the com.fs.starfarer.api.campaign.listeners package.
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: CampaignEventListener not being called
« Reply #2 on: November 16, 2018, 07:08:39 PM »

Ah, my mistake. And I just remembered that you actually mentioned the new listener system in a PM you sent me a while back. Sorry about that! :-[
« Last Edit: November 16, 2018, 07:37:49 PM by LazyWizard »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: CampaignEventListener not being called
« Reply #3 on: November 16, 2018, 07:09:18 PM »

No worries :) I can see how that might be unclear.
Logged

Nick XR

  • Admiral
  • *****
  • Posts: 712
    • View Profile
Re: CampaignEventListener not being called
« Reply #4 on: November 17, 2018, 03:12:56 PM »

If I register my plugin via:

Code
        Global.getSector().getListenerManager().addListener(new BaseCampaignEventListener(false) {
            public void reportPlayerEngagement(EngagementResultAPI result) {
                log.debug("reportPlayerEngagement " + result);
            }
        }, true);

the 'reportPlayerEngagement' doesn't get invoked at the end of combat.  I see that addListener takes an object, should I be implementing a different class?
« Last Edit: November 17, 2018, 03:22:15 PM by Nick XR »
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: CampaignEventListener not being called
« Reply #5 on: November 17, 2018, 09:37:53 PM »

If you're extending BaseCampaignEventListener, you need to add the plugin using SectorAPI.getListener().

Basically:
Those are CampaignEventListener methods, so that's only going to get called if you add it via SectorAPI.addListener().

ListenerManager supports the interfaces in the com.fs.starfarer.api.campaign.listeners package.
Logged

Nick XR

  • Admiral
  • *****
  • Posts: 712
    • View Profile
Re: CampaignEventListener not being called
« Reply #6 on: November 18, 2018, 02:13:36 PM »

Those are CampaignEventListener methods, so that's only going to get called if you add it via SectorAPI.addListener().

ListenerManager supports the interfaces in the com.fs.starfarer.api.campaign.listeners package.

Ok. Apologies for not reading your first post carefully.

I think part of my confusion was/is SectorAPI.addListener(CampaignEventListener listener) is @Deprecated and the comment says to use getListenerManager instead.   :-\

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23986
    • View Profile
Re: CampaignEventListener not being called
« Reply #7 on: November 18, 2018, 02:44:00 PM »

... well, when you put it that way.

That's actually not even accurate, since a few callbacks don't have corresponding ListenerManager-used interfaces. Let me undeprecate those, not sure what I was thinking.
Logged