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;
}
Aggregations