use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData in project Nucleus by NucleusPowered.
the class CheckJailCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User user = args.<User>getOne(playerKey).get();
Optional<JailData> jail = handler.getPlayerJailDataInternal(user);
MessageProvider mp = this.plugin.getMessageProvider();
if (!jail.isPresent()) {
throw ReturnMessageException.fromKey("command.checkjail.nojail", user.getName());
}
JailData md = jail.get();
String name;
if (md.getJailerInternal().equals(Util.consoleFakeUUID)) {
name = Sponge.getServer().getConsole().getName();
} else {
name = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(md.getJailerInternal()).map(User::getName).orElseGet(() -> mp.getMessageWithFormat("standard.unknown"));
}
if (md.getRemainingTime().isPresent()) {
src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.jailedfor", user.getName(), md.getJailName(), name, Util.getTimeStringFromSeconds(md.getRemainingTime().get().getSeconds())));
} else {
src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.jailedperm", user.getName(), md.getJailName(), name));
}
if (md.getCreationTime() > 0) {
src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.created", Util.FULL_TIME_FORMATTER.withLocale(src.getLocale()).format(Instant.ofEpochSecond(md.getCreationTime()))));
} else {
src.sendMessage(mp.getTextMessageWithFormat("command.checkjail.created", mp.getMessageWithFormat("standard.unknown")));
}
src.sendMessage(mp.getTextMessageWithFormat("standard.reasoncoloured", md.getReason()));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData 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;
}
use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData in project Nucleus by NucleusPowered.
the class JailHandler method jailPlayer.
@Override
public boolean jailPlayer(User victim, String jail, CommandSource jailer, String reason) throws NoSuchLocationException {
Preconditions.checkNotNull(victim);
Preconditions.checkNotNull(jail);
Preconditions.checkNotNull(jailer);
Preconditions.checkNotNull(reason);
NamedLocation location = getJail(jail).orElseThrow(NoSuchLocationException::new);
return jailPlayer(victim, new JailData(Util.getUUID(jailer), location.getName(), reason, victim.getPlayer().map(Locatable::getLocation).orElse(null)));
}
use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData in project Nucleus by NucleusPowered.
the class JailListener method onPlayerLogin.
@Listener
public void onPlayerLogin(final NucleusOnLoginEvent event, @Getter("getTargetUser") User user, @Getter("getUserService") ModularUserService qs) {
JailUserDataModule userDataModule = qs.get(JailUserDataModule.class);
// Jailing the subject if we need to.
if (userDataModule.jailOnNextLogin() && userDataModule.getJailData().isPresent()) {
Optional<NamedLocation> owl = handler.getWarpLocation(user);
if (!owl.isPresent()) {
new PermissionMessageChannel(notify).send(Text.of(TextColors.RED, "WARNING: No jail is defined. Jailed players are going free!"));
handler.unjailPlayer(user);
return;
}
JailData jd = userDataModule.getJailData().get();
jd.setPreviousLocation(event.getFrom().getLocation());
userDataModule.setJailData(jd);
event.setTo(owl.get().getTransform().get());
}
}
use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData 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);
}
Aggregations