use of io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule 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.datamodules.JailUserDataModule 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.datamodules.JailUserDataModule 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.modules.jail.datamodules.JailUserDataModule in project Nucleus by NucleusPowered.
the class JailHandler method jailPlayer.
public boolean jailPlayer(User user, JailData data) {
ModularUserService modularUserService = plugin.getUserDataManager().getUnchecked(user);
JailUserDataModule jailUserDataModule = modularUserService.get(JailUserDataModule.class);
if (jailUserDataModule.getJailData().isPresent()) {
return false;
}
// Get the jail.
Optional<NamedLocation> owl = getJail(data.getJailName());
NamedLocation wl = owl.filter(x -> x.getLocation().isPresent()).orElseGet(() -> {
if (!getJails().isEmpty()) {
return null;
}
return getJails().entrySet().stream().findFirst().get().getValue();
});
if (wl == null) {
return false;
}
jailUserDataModule.setJailData(data);
if (user.isOnline()) {
Sponge.getScheduler().createSyncExecutor(plugin).execute(() -> {
Player player = user.getPlayer().get();
plugin.getTeleportHandler().teleportPlayer(player, owl.get().getLocation().get(), owl.get().getRotation(), NucleusTeleportHandler.StandardTeleportMode.NO_CHECK, Sponge.getCauseStackManager().getCurrentCause());
modularUserService.get(FlyUserDataModule.class).setFlying(false);
});
} else {
jailUserDataModule.setJailOnNextLogin(true);
}
this.jailDataCache.put(user.getUniqueId(), new Context(NucleusJailService.JAIL_CONTEXT, data.getJailName()));
Sponge.getEventManager().post(new JailEvent.Jailed(user, CauseStackHelper.createCause(Util.getObjectFromUUID(data.getJailerInternal())), data.getJailName(), TextSerializers.FORMATTING_CODE.deserialize(data.getReason()), data.getRemainingTime().orElse(null)));
return true;
}
Aggregations