Search in sources :

Example 6 with ModularUserService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.

the class JailListener method onPlayerJoin.

/**
 * At the time the subject joins, check to see if the subject is muted.
 *
 * @param event The event.
 */
@Listener(order = Order.LATE)
public void onPlayerJoin(final ClientConnectionEvent.Join event) {
    final Player user = event.getTargetEntity();
    Optional<ModularUserService> oqs = Nucleus.getNucleus().getUserDataManager().get(user);
    if (!oqs.isPresent()) {
        return;
    }
    JailUserDataModule qs = oqs.get().get(JailUserDataModule.class);
    // Jailing the subject if we need to.
    Optional<JailData> data = handler.getPlayerJailDataInternal(user);
    if (qs.jailOnNextLogin() && data.isPresent()) {
        // It exists.
        NamedLocation owl = handler.getWarpLocation(user).get();
        JailData jd = data.get();
        Optional<Duration> timeLeft = jd.getRemainingTime();
        Text message;
        message = timeLeft.map(duration -> plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailed", owl.getName(), plugin.getNameUtil().getNameFromUUID(jd.getJailerInternal()), plugin.getMessageProvider().getMessageWithFormat("standard.for"), Util.getTimeStringFromSeconds(duration.getSeconds()))).orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailed", owl.getName(), plugin.getNameUtil().getNameFromUUID(jd.getJailerInternal()), "", ""));
        oqs.get().get(FlyUserDataModule.class).setFlying(false);
        user.sendMessage(message);
        user.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", jd.getReason()));
    }
    qs.setJailOnNextLogin(false);
    // Kick off a scheduled task.
    Sponge.getScheduler().createTaskBuilder().async().delay(500, TimeUnit.MILLISECONDS).execute(() -> {
        Optional<JailData> omd = qs.getJailData();
        if (omd.isPresent()) {
            JailData md = omd.get();
            md.nextLoginToTimestamp();
            omd = Util.testForEndTimestamp(qs.getJailData(), () -> handler.unjailPlayer(user));
            if (omd.isPresent()) {
                md = omd.get();
                handler.onJail(md, event.getTargetEntity());
            }
        }
    }).submit(plugin);
}
Also used : FlyUserDataModule(io.github.nucleuspowered.nucleus.modules.fly.datamodules.FlyUserDataModule) Player(org.spongepowered.api.entity.living.player.Player) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation) Optional(java.util.Optional) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) Duration(java.time.Duration) Text(org.spongepowered.api.text.Text) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) JailUserDataModule(io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule) Listener(org.spongepowered.api.event.Listener)

Example 7 with ModularUserService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.

the class MuteHandler method mutePlayer.

public boolean mutePlayer(User user, MuteData data, Cause cause) {
    Preconditions.checkNotNull(user);
    Preconditions.checkNotNull(data);
    Optional<ModularUserService> nu = ucl.get(user);
    if (!nu.isPresent()) {
        return false;
    }
    Instant time = Instant.now();
    ModularUserService u = nu.get();
    final Duration d = data.getRemainingTime().orElse(null);
    if (user.isOnline() && data.getTimeFromNextLogin().isPresent() && !data.getEndTimestamp().isPresent()) {
        data.setEndtimestamp(time.plus(data.getTimeFromNextLogin().get()));
    }
    u.get(MuteUserDataModule.class).setMuteData(data);
    this.muteContextCache.put(u.getUniqueId(), true);
    Sponge.getEventManager().post(new MuteEvent.Muted(cause, user, d, Text.of(data.getReason())));
    return true;
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) MuteUserDataModule(io.github.nucleuspowered.nucleus.modules.mute.datamodules.MuteUserDataModule) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) MuteEvent(io.github.nucleuspowered.nucleus.modules.mute.events.MuteEvent)

Example 8 with ModularUserService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.

the class SeenCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    User user = args.<User>getOne(uuid).isPresent() ? args.<User>getOne(uuid).get() : args.<User>getOne(playerKey).get();
    if (user.isOnline()) {
        // Get the player in case the User is displaying the wrong name.
        user = user.getPlayer().get();
    }
    ModularUserService iqsu = Nucleus.getNucleus().getUserDataManager().getUnchecked(user);
    CoreUserDataModule coreUserDataModule = iqsu.get(CoreUserDataModule.class);
    List<Text> messages = new ArrayList<>();
    final MessageProvider messageProvider = plugin.getMessageProvider();
    // Everyone gets the last online time.
    if (user.isOnline()) {
        messages.add(messageProvider.getTextMessageWithFormat("command.seen.iscurrently.online", user.getName()));
        coreUserDataModule.getLastLogin().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.loggedon", Util.getTimeToNow(x))));
    } else {
        messages.add(messageProvider.getTextMessageWithFormat("command.seen.iscurrently.offline", user.getName()));
        coreUserDataModule.getLastLogout().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.loggedoff", Util.getTimeToNow(x))));
    }
    messages.add(messageProvider.getTextMessageWithFormat("command.seen.displayname", TextSerializers.FORMATTING_CODE.serialize(plugin.getNameUtil().getName(user))));
    if (permissions.testSuffix(src, EXTENDED_SUFFIX)) {
        messages.add(notEmpty);
        messages.add(messageProvider.getTextMessageWithFormat("command.seen.uuid", user.getUniqueId().toString()));
        if (user.isOnline()) {
            Player pl = user.getPlayer().get();
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.ipaddress", pl.getConnection().getAddress().getAddress().toString()));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(pl.getJoinData().firstPlayed().get())));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.speed.walk", String.valueOf(Math.round(pl.get(Keys.WALKING_SPEED).orElse(0.1d) * SpeedCommand.multiplier))));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.speed.fly", String.valueOf(Math.round(pl.get(Keys.FLYING_SPEED).orElse(0.05d) * SpeedCommand.multiplier))));
            messages.add(getLocationString("command.seen.currentlocation", pl.getLocation(), src));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.canfly", getYesNo(pl.get(Keys.CAN_FLY).orElse(false))));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.isflying", getYesNo(pl.get(Keys.IS_FLYING).orElse(false))));
            messages.add(messageProvider.getTextMessageWithFormat("command.seen.gamemode", pl.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL).getName()));
        } else {
            coreUserDataModule.getLastIp().ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.lastipaddress", x)));
            Optional<Instant> i = user.get(Keys.FIRST_DATE_PLAYED);
            if (!i.isPresent()) {
                i = coreUserDataModule.getFirstJoin();
            }
            i.ifPresent(x -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(x))));
            Optional<Location<World>> olw = coreUserDataModule.getLogoutLocation();
            olw.ifPresent(worldLocation -> messages.add(getLocationString("command.seen.lastlocation", worldLocation, src)));
            user.get(JoinData.class).ifPresent(x -> {
                Optional<Instant> oi = x.firstPlayed().getDirect();
                oi.ifPresent(instant -> messages.add(messageProvider.getTextMessageWithFormat("command.seen.firstplayed", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(src.getLocale()).withZone(ZoneId.systemDefault()).format(instant))));
            });
        }
    }
    // Add the extra module information.
    messages.addAll(seenHandler.buildInformation(src, user));
    PaginationService ps = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
    ps.builder().contents(messages).padding(Text.of(TextColors.GREEN, "-")).title(messageProvider.getTextMessageWithFormat("command.seen.title", user.getName())).sendTo(src);
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) User(org.spongepowered.api.entity.living.player.User) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Instant(java.time.Instant) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) JoinData(org.spongepowered.api.data.manipulator.mutable.entity.JoinData) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Location(org.spongepowered.api.world.Location)

Example 9 with ModularUserService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.

the class UserDataManager method getNew.

@Override
public Optional<ModularUserService> getNew(UUID uuid, DataProvider<ConfigurationNode> dataProvider) throws Exception {
    // Does the user exist?
    Optional<User> user = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(uuid);
    if (user.isPresent()) {
        int trace = Nucleus.getNucleus().traceUserCreations();
        if (trace > 0) {
            boolean t = trace >= 2 || !Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(uuid).isPresent() || Sponge.getServer().getPlayer(uuid).map(x -> x.getClass().getSimpleName().toLowerCase().contains("fakeplayer")).orElse(true);
            if (t) {
                Logger logger = Nucleus.getNucleus().getLogger();
                logger.info("Creating user: " + uuid.toString());
                Sponge.getServer().getPlayer(uuid).ifPresent(x -> logger.info("Player Class: " + x.getClass().getName()));
                logger.info("THIS IS NOT AN ERROR", new Throwable());
            }
        }
        ModularUserService m = new ModularUserService(dataProvider, user.get().getUniqueId());
        m.loadInternal();
        return Optional.of(m);
    }
    return Optional.empty();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) User(org.spongepowered.api.entity.living.player.User) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) Logger(org.slf4j.Logger)

Example 10 with ModularUserService

use of io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService in project Nucleus by NucleusPowered.

the class CoreListener method onPlayerJoinFirst.

/* (non-Javadoc)
     * We do this first to try to get the first play status as quick as possible.
     */
@Listener(order = Order.FIRST)
public void onPlayerJoinFirst(final ClientConnectionEvent.Join event, @Getter("getTargetEntity") final Player player) {
    try {
        ModularUserService qsu = Nucleus.getNucleus().getUserDataManager().getUnchecked(player);
        CoreUserDataModule c = qsu.get(CoreUserDataModule.class);
        c.setLastLogin(Instant.now());
        // If in the cache, unset it too.
        c.setFirstPlay(c.isStartedFirstJoin() && !c.getLastLogout().isPresent());
        if (c.isFirstPlay()) {
            plugin.getGeneralService().getTransient(UniqueUserCountTransientModule.class).resetUniqueUserCount();
        }
        c.setFirstJoin(player.getJoinData().firstPlayed().get());
        if (this.plugin.isServer()) {
            c.setLastIp(player.getConnection().getAddress().getAddress());
        }
        // We'll do this bit shortly - after the login events have resolved.
        final String name = player.getName();
        Task.builder().execute(() -> c.setLastKnownName(name)).delayTicks(20L).submit(plugin);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UniqueUserCountTransientModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.UniqueUserCountTransientModule) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) MalformedURLException(java.net.MalformedURLException) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Listener(org.spongepowered.api.event.Listener)

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