Search in sources :

Example 1 with ModularUserService

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

Example 2 with ModularUserService

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);
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) Listener(org.spongepowered.api.event.Listener)

Example 3 with ModularUserService

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();
}
Also used : MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) CommandSpyUserDataModule(io.github.nucleuspowered.nucleus.modules.commandspy.datamodules.CommandSpyUserDataModule) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)

Example 4 with ModularUserService

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();
    }
}
Also used : ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)

Example 5 with ModularUserService

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;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) JailEvent(io.github.nucleuspowered.nucleus.modules.jail.events.JailEvent) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) JailUserDataModule(io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) Location(org.spongepowered.api.world.Location) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)

Aggregations

ModularUserService (io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)17 CoreUserDataModule (io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule)6 User (org.spongepowered.api.entity.living.player.User)5 Player (org.spongepowered.api.entity.living.player.Player)4 Listener (org.spongepowered.api.event.Listener)4 Text (org.spongepowered.api.text.Text)4 NamedLocation (io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)3 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)3 JailData (io.github.nucleuspowered.nucleus.modules.jail.data.JailData)3 JailUserDataModule (io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule)3 Duration (java.time.Duration)3 Instant (java.time.Instant)3 ServiceChangeListener (io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener)2 FlyUserDataModule (io.github.nucleuspowered.nucleus.modules.fly.datamodules.FlyUserDataModule)2 JailEvent (io.github.nucleuspowered.nucleus.modules.jail.events.JailEvent)2 NicknameUserDataModule (io.github.nucleuspowered.nucleus.modules.nickname.datamodules.NicknameUserDataModule)2 Optional (java.util.Optional)2 Subject (org.spongepowered.api.service.permission.Subject)2 UserStorageService (org.spongepowered.api.service.user.UserStorageService)2 Location (org.spongepowered.api.world.Location)2