crwdns19213:0crwdne19213:0

crwdns37068:0:javadoc:crwdne37068:0

crwdns19215:0:javadoc:crwdne19215:0

crwdns19216:0:javadoc:crwdne19216:0

crwdns41592:0crwdne41592:0

crwdns41593:0:javadoc:crwdne41593:0

  • crwdns41594:0crwdne41594:0
  • crwdns41595:0crwdne41595:0

crwdns41596:0:javadoc:crwdne41596:0

crwdns41597:0:javadoc:crwdne41597:0

crwdns41598:0crwdne41598:0

crwdns37069:0crwdne37069:0

Note

crwdns19219:0crwdne19219:0

crwdns19220:0:javadoc:crwdne19220:0

crwdns42588:0:javadoc:crwdne42588:0

@Listener
public void onEvent(ExampleCauseEvent event) {
    Cause cause = event.getCause(); // [Player, Entity]
    Optional<Player> firstPlayer = cause.first(Player.class); // 1
    Optional<Entity> firstEntity = cause.first(Entity.class); // 2
}

crwdns42589:0crwdne42589:0

crwdns19223:0:javadoc:crwdne19223:0

crwdns19224:0crwdne19224:0

crwdns19225:0:javadoc:crwdne19225:0

crwdns19226:0:javadoc:crwdne19226:0

crwdns41599:0crwdne41599:0

crwdns41600:0:javadoc:crwdnd41600:0:javadoc:crwdnd41600:0:javadoc:crwdnd41600:0:javadoc:crwdne41600:0

crwdns41601:0:javadoc:crwdne41601:0

crwdns41602:0crwdne41602:0

@Listener
public void onGrow(ChangeBlockEvent.Grow event) {
    Optional<User> notifier = event.getCause().getContext().get(EventContextKeys.NOTIFIER);
}

crwdns41603:0:javadoc:crwdnd41603:0:javadoc:crwdne41603:0

Note

crwdns41604:0crwdne41604:0

crwdns41605:0crwdne41605:0

crwdns41606:0crwdne41606:0

Note

crwdns19234:0crwdne19234:0

crwdns41607:0crwdne41607:0

Warning

crwdns41608:0crwdne41608:0

crwdns41609:0:javadoc:crwdnd41609:0:javadoc:crwdnd41609:0:javadoc:crwdnd41609:0:javadoc:crwdne41609:0

crwdns41610:0crwdne41610:0

Tip

crwdns41611:0crwdne41611:0

crwdns41612:0crwdne41612:0

crwdns41613:0crwdne41613:0

crwdns41614:0crwdne41614:0

crwdns41907:0:javadoc:crwdnd41907:0:javadoc:crwdne41907:0

CommandSource sourceRunningSudo = ...;
Player playerToSimulate = ...;
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {

  frame.pushCause(sourceRunningSudo);
  frame.pushCause(playerToSimulate);

  frame.addContext(EventContextKeys.PLAYER_SIMULATED, playerToSimulate.getProfile());

  Cause cause = frame.getCurrentCause();
}

crwdns41616:0crwdne41616:0

Tip

crwdns41617:0:javadoc:crwdne41617:0

crwdns41618:0crwdne41618:0

crwdns41619:0crwdne41619:0

crwdns41620:0:javadoc:crwdnd41620:0:javadoc:crwdne41620:0

crwdns41621:0:javadoc:crwdne41621:0

crwdns41622:0crwdne41622:0

crwdns41623:0crwdne41623:0

crwdns41624:0crwdne41624:0

CommandSource sourceRunningSudo = ...;
Player playerToSimulate = ...;
PluginContainer plugin = ...;

EventContext context = EventContext.builder()
  .add(EventContextKeys.PLAYER_SIMULATED, playerToSimulate.getProfile())
  .add(EventContextKeys.PLUGIN, plugin)
  .build();

Cause cause = Cause.builder()
  .append(playerToSimulate)
  .append(sourceRunningSudo)
  .append(plugin)
  .build(context);

crwdns41625:0crwdne41625:0