use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService 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;
}
use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.
the class FlyListener method onPlayerTransferWorld.
// Only fire if there is no cancellation at the end.
@Listener(order = Order.LAST)
public void onPlayerTransferWorld(MoveEntityEvent.Teleport event, @Getter("getTargetEntity") Entity target, @Getter("getFromTransform") Transform<World> twfrom, @Getter("getToTransform") Transform<World> twto) {
if (!(target instanceof Player)) {
return;
}
Player pl = (Player) target;
if (shouldIgnoreFromGameMode(pl)) {
return;
}
ModularUserService uc;
try {
uc = Nucleus.getNucleus().getUserDataManager().getUnchecked(pl);
if (!uc.get(FlyUserDataModule.class).isFlying()) {
return;
}
} catch (Exception e) {
Nucleus.getNucleus().printStackTraceIfDebugMode(e);
return;
}
// If we have a subject, and this happens...
boolean isFlying = target.get(Keys.IS_FLYING).orElse(false);
// If we're moving world...
if (!twfrom.getExtent().getUniqueId().equals(twto.getExtent().getUniqueId())) {
// Next tick, they can fly... if they have permission to do so.
Sponge.getScheduler().createTaskBuilder().execute(() -> {
if (getFlyCommandHandler().testBase(pl)) {
target.offer(Keys.CAN_FLY, true);
if (isFlying) {
target.offer(Keys.IS_FLYING, true);
}
} else {
uc.get(FlyUserDataModule.class).setFlying(false);
target.offer(Keys.CAN_FLY, false);
target.offer(Keys.IS_FLYING, false);
}
}).submit(plugin);
}
}
use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.
the class CommandSpyCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
ModularUserService service = Nucleus.getNucleus().getUserDataManager().getUnchecked(src);
CommandSpyUserDataModule c = service.get(CommandSpyUserDataModule.class);
boolean to = args.<Boolean>getOne(truefalse).orElseGet(() -> !c.isCommandSpy());
c.setCommandSpy(to);
MessageProvider mp = plugin.getMessageProvider();
src.sendMessage(mp.getTextMessageWithFormat("command.commandspy.success", mp.getMessageWithFormat(to ? "standard.enabled" : "standard.disabled")));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.
the class UserDataManager method forceUnloadAndDelete.
public void forceUnloadAndDelete(UUID uuid) {
ModularUserService service = get(uuid).orElse(null);
this.invalidate(uuid, false);
if (service != null) {
service.delete();
}
}
use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.
the class JailHandler method unjailPlayer.
public boolean unjailPlayer(User user, Cause cause) {
final ModularUserService modularUserService = plugin.getUserDataManager().getUnchecked(user);
final JailUserDataModule jailUserDataModule = modularUserService.get(JailUserDataModule.class);
Optional<JailData> ojd = jailUserDataModule.getJailData();
if (!ojd.isPresent()) {
return false;
}
Optional<Location<World>> ow = ojd.get().getPreviousLocation();
jailDataCache.put(user.getUniqueId(), null);
if (user.isOnline()) {
Player player = user.getPlayer().get();
Sponge.getScheduler().createSyncExecutor(plugin).execute(() -> {
NucleusTeleportHandler.setLocation(player, ow.orElseGet(() -> player.getWorld().getSpawnLocation()));
player.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("jail.elapsed"));
// Remove after the teleport for the back data.
jailUserDataModule.removeJailData();
});
} else {
modularUserService.get(CoreUserDataModule.class).sendToLocationOnLogin(ow.orElseGet(() -> new Location<>(Sponge.getServer().getWorld(Sponge.getServer().getDefaultWorld().get().getUniqueId()).get(), Sponge.getServer().getDefaultWorld().get().getSpawnPosition())));
jailUserDataModule.removeJailData();
}
Sponge.getEventManager().post(new JailEvent.Unjailed(user, cause));
return true;
}
Aggregations