Search in sources :

Example 1 with CoreUserDataModule

use of io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule 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 2 with CoreUserDataModule

use of io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule in project Nucleus by NucleusPowered.

the class CoreListener method onPlayerLoginLast.

/* (non-Javadoc)
     * We do this last to avoid interfering with other modules.
     */
@Listener(order = Order.LATE)
public void onPlayerLoginLast(final ClientConnectionEvent.Login event, @Getter("getProfile") GameProfile profile, @Getter("getTargetUser") User user) {
    Nucleus.getNucleus().getUserDataManager().get(profile.getUniqueId()).ifPresent(qsu -> {
        if (event.getFromTransform().equals(event.getToTransform())) {
            CoreUserDataModule c = qsu.get(CoreUserDataModule.class);
            // Check this
            NucleusOnLoginEvent onLoginEvent = CauseStackHelper.createFrameWithCausesWithReturn(cause -> new NucleusOnLoginEvent(cause, user, qsu, event.getFromTransform()), profile);
            Sponge.getEventManager().post(onLoginEvent);
            if (onLoginEvent.getTo().isPresent()) {
                event.setToTransform(onLoginEvent.getTo().get());
                c.removeLocationOnLogin();
                return;
            }
            // If we have a location to send them to in the config, send them there now!
            Optional<Location<World>> olw = c.getLocationOnLogin();
            olw.ifPresent(worldLocation -> {
                event.setToTransform(event.getFromTransform().setLocation(worldLocation));
                c.removeLocationOnLogin();
            });
        }
        plugin.getUserCacheService().updateCacheForPlayer(qsu);
    });
}
Also used : NucleusOnLoginEvent(io.github.nucleuspowered.nucleus.modules.core.events.NucleusOnLoginEvent) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) Location(org.spongepowered.api.world.Location) ServiceChangeListener(io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener) Listener(org.spongepowered.api.event.Listener)

Example 3 with CoreUserDataModule

use of io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule in project Nucleus by NucleusPowered.

the class CoreListener method onPlayerQuit.

private void onPlayerQuit(ModularUserService x, Player player) {
    final Location<World> location = player.getLocation();
    final InetAddress address = player.getConnection().getAddress().getAddress();
    try {
        CoreUserDataModule coreUserDataModule = x.get(CoreUserDataModule.class);
        coreUserDataModule.setLastIp(address);
        coreUserDataModule.setLastLogout(location);
        x.save();
        plugin.getUserCacheService().updateCacheForPlayer(x);
    } catch (Exception e) {
        Nucleus.getNucleus().printStackTraceIfDebugMode(e);
    }
}
Also used : World(org.spongepowered.api.world.World) InetAddress(java.net.InetAddress) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) MalformedURLException(java.net.MalformedURLException)

Example 4 with CoreUserDataModule

use of io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule 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

CoreUserDataModule (io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule)4 ModularUserService (io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService)2 ServiceChangeListener (io.github.nucleuspowered.nucleus.internal.permissions.ServiceChangeListener)2 MalformedURLException (java.net.MalformedURLException)2 Listener (org.spongepowered.api.event.Listener)2 Location (org.spongepowered.api.world.Location)2 MessageProvider (io.github.nucleuspowered.nucleus.internal.messages.MessageProvider)1 UniqueUserCountTransientModule (io.github.nucleuspowered.nucleus.modules.core.datamodules.UniqueUserCountTransientModule)1 NucleusOnLoginEvent (io.github.nucleuspowered.nucleus.modules.core.events.NucleusOnLoginEvent)1 InetAddress (java.net.InetAddress)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 JoinData (org.spongepowered.api.data.manipulator.mutable.entity.JoinData)1 Player (org.spongepowered.api.entity.living.player.Player)1 User (org.spongepowered.api.entity.living.player.User)1 PaginationService (org.spongepowered.api.service.pagination.PaginationService)1 Text (org.spongepowered.api.text.Text)1 World (org.spongepowered.api.world.World)1