crwdns118215:0crwdne118215:0

crwdns118217:0:javadoc:crwdne118217:0

crwdns118219:0:javadoc:crwdne118219:0

crwdns118221:0:javadoc:crwdne118221:0

crwdns118223:0crwdne118223:0

crwdns118225:0:javadoc:crwdne118225:0

  • crwdns118227:0crwdne118227:0

  • crwdns118229:0crwdne118229:0

crwdns118231:0:javadoc:crwdne118231:0

crwdns118233:0:javadoc:crwdne118233:0

crwdns118235:0crwdne118235:0

crwdns118237:0crwdne118237:0

Note

crwdns118239:0crwdne118239:0

crwdns118241:0:javadoc:crwdne118241:0

crwdns118243:0:javadoc:crwdne118243: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
}

crwdns118245:0crwdne118245:0

crwdns118247:0:javadoc:crwdne118247:0

crwdns118249:0crwdne118249:0

crwdns118251:0:javadoc:crwdne118251:0

crwdns118253:0:javadoc:crwdne118253:0

crwdns118255:0crwdne118255:0

crwdns118257:0:javadoc:crwdnd118257:0:javadoc:crwdnd118257:0:javadoc:crwdnd118257:0:javadoc:crwdne118257:0

crwdns118259:0:javadoc:crwdne118259:0

crwdns118261:0crwdne118261:0

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

crwdns118263:0:javadoc:crwdnd118263:0:javadoc:crwdne118263:0

Note

crwdns118265:0crwdne118265:0

crwdns118267:0crwdne118267:0

crwdns118269:0crwdne118269:0

Note

crwdns118271:0crwdne118271:0

crwdns118273:0crwdne118273:0

Warning

crwdns118275:0crwdne118275:0

crwdns118277:0:javadoc:crwdnd118277:0:javadoc:crwdnd118277:0:javadoc:crwdnd118277:0:javadoc:crwdne118277:0

crwdns118279:0crwdne118279:0

Tip

crwdns118281:0crwdne118281:0

crwdns118283:0crwdne118283:0

crwdns118285:0crwdne118285:0

crwdns118287:0crwdne118287:0

crwdns118289:0:javadoc:crwdnd118289:0:javadoc:crwdne118289: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();
}

crwdns118291:0crwdne118291:0

Tip

crwdns118293:0:javadoc:crwdne118293:0

crwdns118295:0crwdne118295:0

crwdns118297:0crwdne118297:0

crwdns118299:0:javadoc:crwdnd118299:0:javadoc:crwdne118299:0

crwdns118301:0:javadoc:crwdne118301:0

crwdns118303:0crwdne118303:0

crwdns118305:0crwdne118305:0

crwdns118307:0crwdne118307: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);

crwdns118309:0crwdne118309:0