[Solved] Trouble Using Economy API

Hi, I am just starting to code with Sponge and I am loving it so far. I recently have been trying to make my plugin interface with another economy plugin. So far, I have tried narrowing down the issue and have found that the event for Loading the EconomyService is not run, which might be causing the error.

Here is my Main Class

Here is my BlockPlaceListener Class

Here is my error that occurs when I place a block. No other errors related to this plugin show up on startup:
(RIP, new users can only put 2 links, I put the error I get when placing the block at the end of my BlockPlaceListener class for you to get to it if you need)

Any help is greatly appreciated, thank you for reading :smiley:

Edit: I have the plugin TotalEconomy for Sponge installed, it works fine and all of it’s commands function in game.

Edit 2: Better formatting

Edit 3: It seems that the plugin is not registering the onChangeServiceProvider Event or it doesn’t exist. It is never run and does not set the private EconomyService variable which line 32 uses, so I think my issue is that that @Listener is not being called at all. Also I am using the most recent Bleeding Edge version of Sponge to develop on and run sponge on.

In the BlockPlaceListener, Instead of doing event.getNewProviderRegistration().getProvider(); why don’t you use event.getService()?

Hmm, I am purely going off of this documentation. I will try what you said.

Edit: Doing that comes with this error: Cannot cast from Class<capture#2-of ?> to EconomyService in eclipse.

Ah, I see. Disregard my comment in that case. Can you post the error the occurs when you run using your original code?

I put it at the end of my second link in the original post, but here it is. I only get the error on block place, as if the ChangeServiceProviderEvent is never run.

Well, it’s more of when you register the listener. You’re registering it after TotalEconomy has changed the service, so the event was posted, you just weren’t listening for it at the time.

Consider using Sponge.getServiceManager().provide(EconomyService.class); to get the economy service instead the first time you fire the BlockPlaceListener, and store it then. I’d keep the other listener just in case it changes for some reason.

1 Like

Sorry for flagging your posts as Spam, sometimes the forums software produces false positives (it automatically blocks posts by new users with many links in it) :confused:
Hope it didn’t cause you any trouble.

Thank you, I understand why that happened and am fine with it, thanks.

This is what I have tried and I still get the same error at Sponge.getServiceManager().provide(EconomyService.class); instead of at economyService.getOrCreateAccount(ply.getUniqueId());

Edit 1: This seems to have replied to the wrong person, sorry lol

I think i unhid all of your posts. If i missed one, just let me know.
Sorry again for causing you trouble :slight_smile:

1 Like

It’s all good, thanks for the quick support :smiley:

1 Like

Hmm, I’m not sure I understand exactly how to do that. In my accidental reply to Tzk I showed what I tried but it failed.

Can you post the new stack trace when using this listener? http://pastebin.com/PwqEbFN4

What dualspiral was saying is if economyService is null (the first time you use it it will be null, since your economy listener doesn’t fire) use Sponge.getServiceManager().provide(EconomyService.class) to set it.

This is the stack trace: Here

It just started working properly, I think i forgot to export the last changes. Thank you everyone.

No problem glad it worked! Would have been very confused if the service manager itself was null. :slight_smile:

Am I soposed to change the title to [Solved] or something like that now?

Edit 1: I’ll do that i guess.

That or mark a post as the “solution”, I haven’t created a thread yet not sure how it works sorry.