Achievement Events

I’m trying to give money to player every time he got achievement. So I’m trying to use GrantAchievementEvent and GrantAchievementEvent.TargetPlayer - but neither is called. So, any other idea? Is it bug?

Did you include the @Listener annotation above your method?

That was the first thing I checked. I already tried to listen to all events but there’s no event when I got achievement…

Is the listener outside of your main class? If so you have to register it: Event Listeners — Sponge 7.2.0 documentation

The GrantAchievementEvent is definitely called by SpongeCommon as of late december of 2016:

Perhaps you’re running an out of date version of SpongeCommon?

Yep, it is. I tried to make listener for all Events, it worked and printed out all events. But there were no events of Achievement when I got it. Using SpongeForge.

Is your project open source? I couldn’t find any sponge plugins on your github.

Nope, it’s not.

Basically - any other event listener in same class works well. But this:

public void onPlayerAchievement(GrantAchievementEvent.TargetPlayer e){

just doesn’t work…

Is the event cancelled? I know GrantAchievementEvent implements MessageEvent and MessageChannelEvent.

If not, then perhaps the event isn’t being fired from Sponge.

Check to see if the event was cancelled.

@Listener(order = Order.POST) // not sure on the syntax exactly at the moment
public void onGrantPlayerAchievement(GrantAchievementEvent.TargetPlayer event) {
    plugin.getLogger().info("GameAchievementEvent isCancelled(): " + (event.isCancelled() ? "true", "false"));

Nope, as I found it’s not implemented in SpongeForge yet. Well, that’s great…

If there isn’t an issue about it on GitHub, you should open one :slight_smile:

1 Like