Search in sources :

Example 1 with WarnUserDataModule

use of io.github.nucleuspowered.nucleus.modules.warn.datamodules.WarnUserDataModule in project Nucleus by NucleusPowered.

the class WarnHandler method addWarning.

public boolean addWarning(User user, WarnData warning) {
    Preconditions.checkNotNull(user);
    Preconditions.checkNotNull(warning);
    Optional<ModularUserService> optUserService = userDataManager.get(user);
    if (!optUserService.isPresent()) {
        return false;
    }
    WarnUserDataModule userService = optUserService.get().get(WarnUserDataModule.class);
    Optional<Duration> duration = warning.getTimeFromNextLogin();
    warning.nextLoginToTimestamp();
    userService.addWarning(warning);
    if (!warning.isExpired()) {
        Sponge.getEventManager().post(new WarnEvent.Warned(CauseStackHelper.createCause(warning.getWarner().orElse(Util.consoleFakeUUID)), user, warning.getReason(), duration.orElseGet(() -> warning.getRemainingTime().orElse(null))));
    }
    return true;
}
Also used : WarnEvent(io.github.nucleuspowered.nucleus.modules.warn.events.WarnEvent) WarnUserDataModule(io.github.nucleuspowered.nucleus.modules.warn.datamodules.WarnUserDataModule) Duration(java.time.Duration) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)

Aggregations

ModularUserService (io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)1 WarnUserDataModule (io.github.nucleuspowered.nucleus.modules.warn.datamodules.WarnUserDataModule)1 WarnEvent (io.github.nucleuspowered.nucleus.modules.warn.events.WarnEvent)1 Duration (java.time.Duration)1