Search in sources :

Example 1 with NotifyIfAFK

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);
            });
        }
    }
}
Also used : NotifyIfAFK(io.github.nucleuspowered.nucleus.internal.annotations.command.NotifyIfAFK) AFKConfig(io.github.nucleuspowered.nucleus.modules.afk.config.AFKConfig) CommandResult(org.spongepowered.api.command.CommandResult) Nucleus(io.github.nucleuspowered.nucleus.Nucleus) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) CauseStackHelper(io.github.nucleuspowered.nucleus.util.CauseStackHelper) Sponge(org.spongepowered.api.Sponge) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) Objects(java.util.Objects) Cause(org.spongepowered.api.event.cause.Cause) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) NucleusTextTemplate(io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate) ICommandInterceptor(io.github.nucleuspowered.nucleus.internal.command.ICommandInterceptor) AFKHandler(io.github.nucleuspowered.nucleus.modules.afk.handlers.AFKHandler) AFKEvents(io.github.nucleuspowered.nucleus.modules.afk.events.AFKEvents) AFKConfigAdapter(io.github.nucleuspowered.nucleus.modules.afk.config.AFKConfigAdapter) Nullable(javax.annotation.Nullable) User(org.spongepowered.api.entity.living.player.User) Cause(org.spongepowered.api.event.cause.Cause) Objects(java.util.Objects) Text(org.spongepowered.api.text.Text) AFKEvents(io.github.nucleuspowered.nucleus.modules.afk.events.AFKEvents) NotifyIfAFK(io.github.nucleuspowered.nucleus.internal.annotations.command.NotifyIfAFK)

Aggregations

Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 NucleusTextTemplate (io.github.nucleuspowered.nucleus.api.text.NucleusTextTemplate)1 NotifyIfAFK (io.github.nucleuspowered.nucleus.internal.annotations.command.NotifyIfAFK)1 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)1 ICommandInterceptor (io.github.nucleuspowered.nucleus.internal.command.ICommandInterceptor)1 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)1 AFKConfig (io.github.nucleuspowered.nucleus.modules.afk.config.AFKConfig)1 AFKConfigAdapter (io.github.nucleuspowered.nucleus.modules.afk.config.AFKConfigAdapter)1 AFKEvents (io.github.nucleuspowered.nucleus.modules.afk.events.AFKEvents)1 AFKHandler (io.github.nucleuspowered.nucleus.modules.afk.handlers.AFKHandler)1 CauseStackHelper (io.github.nucleuspowered.nucleus.util.CauseStackHelper)1 Objects (java.util.Objects)1 Nullable (javax.annotation.Nullable)1 Sponge (org.spongepowered.api.Sponge)1 CommandResult (org.spongepowered.api.command.CommandResult)1 CommandSource (org.spongepowered.api.command.CommandSource)1 CommandContext (org.spongepowered.api.command.args.CommandContext)1 User (org.spongepowered.api.entity.living.player.User)1 Cause (org.spongepowered.api.event.cause.Cause)1 Text (org.spongepowered.api.text.Text)1