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