use of io.github.nucleuspowered.nucleus.internal.annotations.command.NotifyIfAFK in project Nucleus by NucleusPowered.
the class AFKCommandInterceptor method onPostCommand.
@Override
public void onPostCommand(Class<? extends AbstractCommand<?>> commandClass, CommandSource source, CommandContext context, CommandResult result) {
if (this.send && result.getSuccessCount().orElse(0) > 0 && commandClass.isAnnotationPresent(NotifyIfAFK.class)) {
NotifyIfAFK annotation = commandClass.getAnnotation(NotifyIfAFK.class);
Cause cause = CauseStackHelper.createCause(source);
for (String key : annotation.value()) {
context.getAll(key).stream().filter(x -> x instanceof User).map(x -> ((User) x).getPlayer().orElse(null)).filter(Objects::nonNull).filter(this.handler::isAFK).forEach(x -> {
Text messageToSend = this.message == null ? null : message.getForCommandSource(x);
AFKEvents.Notify event = new AFKEvents.Notify(x, messageToSend, cause);
Sponge.getEventManager().post(event);
event.getMessage().ifPresent(source::sendMessage);
});
}
}
}
Aggregations