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