Still confused about the new cause system

Hello everyone,

I’m still a bit confused about the new event cause system.
I get that most points just omit the cause argument (and somehow still work :man_shrugging:) but let’s say I want to write custom events that trigger at some point (maybe from the scheduler and an admin command)
Let’s assume it’s a time-based rank event to “level up”:

public class LevelUpEvent extends AbstractEvent implements TargetWarCraftEvent, Cancellable {
  ...
  public LevelUpEvent(Profile target, int levels, Cause cause) {
  ...
}

How would I build the cause now form the scheduler with only the plugin and for the command containing the command sender as cause - or would that be more fitting for context? and how would I do that if so?

Maybe this was asked before and I’m horrible at searching, but I’m at least as horrible at code-surfing other project, and for anyone else I guess it would be a nice thing to have a topic for this until the docs get updated.

So thanks for any help and hints in advance :slight_smile:

Have a nice weekend,
DosMike

The cause object gets populated primarily from the current context. You can inspect and manipulate the context with CauseStackManager.
You can grab the current cause with getCurrentCause(), sponge will automatically add relevant objects to it (like the plugin that owns the task currently executing)

This is another part of sponge api which feels completly off. Dont use cause-contex until theres no other way. :^)