use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData in project Nucleus by NucleusPowered.
the class JailModule method performEnableTasks.
@Override
public void performEnableTasks() {
createSeenModule(CheckJailCommand.class, (c, u) -> {
// If we have a ban service, then check for a ban.
JailHandler jh = Nucleus.getNucleus().getInternalServiceManager().getService(JailHandler.class).get();
if (jh.isPlayerJailed(u)) {
JailData jd = jh.getPlayerJailDataInternal(u).get();
Text.Builder m;
if (jd.getRemainingTime().isPresent()) {
m = NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("seen.isjailed.temp", Util.getTimeToNow(jd.getEndTimestamp().get())).toBuilder();
} else {
m = NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("seen.isjailed.perm").toBuilder();
}
return Lists.newArrayList(m.onClick(TextActions.runCommand("/checkjail " + u.getName())).onHover(TextActions.showText(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("standard.clicktoseemore"))).build(), NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("standard.reason", jd.getReason()));
}
return Lists.newArrayList(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("seen.notjailed"));
});
}
use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData in project Nucleus by NucleusPowered.
the class JailCommand method onJail.
private CommandResult onJail(CommandSource src, CommandContext args, User user) throws ReturnMessageException {
Optional<LocationData> owl = args.getOne(jailKey);
if (!owl.isPresent()) {
throw ReturnMessageException.fromKey("command.jail.jail.nojail");
}
// This might not be there.
Optional<Long> duration = args.getOne(durationKey);
String reason = args.<String>getOne(reasonKey).orElse(plugin.getMessageProvider().getMessageWithFormat("command.jail.reason"));
JailData jd;
Text message;
Text messageTo;
if (duration.isPresent()) {
if (user.isOnline()) {
jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, user.getPlayer().get().getLocation(), Instant.now().plusSeconds(duration.get()));
} else {
jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, null, Duration.of(duration.get(), ChronoUnit.SECONDS));
}
message = plugin.getMessageProvider().getTextMessageWithFormat("command.checkjail.jailedfor", user.getName(), jd.getJailName(), src.getName(), Util.getTimeStringFromSeconds(duration.get()));
messageTo = plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailedfor", owl.get().getName(), src.getName(), Util.getTimeStringFromSeconds(duration.get()));
} else {
jd = new JailData(Util.getUUID(src), owl.get().getName(), reason, user.getPlayer().map(Locatable::getLocation).orElse(null));
message = plugin.getMessageProvider().getTextMessageWithFormat("command.checkjail.jailedperm", user.getName(), owl.get().getName(), src.getName());
messageTo = plugin.getMessageProvider().getTextMessageWithFormat("command.jail.jailedperm", owl.get().getName(), src.getName());
}
if (handler.jailPlayer(user, jd)) {
MutableMessageChannel mc = new PermissionMessageChannel(permissions.getPermissionWithSuffix("notify")).asMutable();
mc.addMember(src);
mc.send(message);
mc.send(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", reason));
user.getPlayer().ifPresent(x -> {
x.sendMessage(messageTo);
x.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("standard.reasoncoloured", reason));
});
return CommandResult.success();
}
throw ReturnMessageException.fromKey("command.jail.error");
}
use of io.github.nucleuspowered.nucleus.modules.jail.data.JailData 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