use of io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation in project Nucleus by NucleusPowered.
the class CheckJailedCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// Using the cache, tell us who is jailed.
MessageProvider provider = plugin.getMessageProvider();
Optional<NamedLocation> jail = args.getOne(jailNameKey);
List<UUID> usersInJail = jail.map(x -> plugin.getUserCacheService().getJailedIn(x.getName())).orElseGet(() -> plugin.getUserCacheService().getJailed());
String jailName = jail.map(NamedLocation::getName).orElseGet(() -> provider.getMessageWithFormat("standard.alljails"));
if (usersInJail.isEmpty()) {
src.sendMessage(provider.getTextMessageWithFormat("command.checkjailed.none", jailName));
return CommandResult.success();
}
// Get the users in this jail, or all jails
Util.getPaginationBuilder(src).title(provider.getTextMessageWithFormat("command.checkjailed.header", jailName)).contents(usersInJail.stream().map(x -> {
Text name = plugin.getNameUtil().getName(x).orElseGet(() -> Text.of("unknown: ", x.toString()));
return name.toBuilder().onHover(TextActions.showText(provider.getTextMessageWithFormat("command.checkjailed.hover"))).onClick(TextActions.runCommand("/nucleus:checkjail " + x.toString())).build();
}).collect(Collectors.toList())).sendTo(src);
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation 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.api.nucleusdata.NamedLocation 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.api.nucleusdata.NamedLocation 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.api.nucleusdata.NamedLocation in project Nucleus by NucleusPowered.
the class ListHomeCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// args.getOne(subject);
User user = this.getUserFromArgs(User.class, src, player, args);
Text header;
boolean other = src instanceof User && !((User) src).getUniqueId().equals(user.getUniqueId());
if (other && user.hasPermission(this.exempt)) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.listhome.exempt"));
}
List<Home> msw = homeHandler.getHomes(user);
if (msw.isEmpty()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.home.nohomes"));
return CommandResult.empty();
}
if (other) {
header = plugin.getMessageProvider().getTextMessageWithFormat("home.title.name", user.getName());
} else {
header = plugin.getMessageProvider().getTextMessageWithFormat("home.title.normal");
}
List<Text> lt = msw.stream().sorted(Comparator.comparing(NamedLocation::getName)).map(x -> {
Optional<Location<World>> olw = x.getLocation();
if (!olw.isPresent()) {
return Text.builder().append(Text.builder(x.getName()).color(TextColors.RED).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("home.warphoverinvalid", x.getName()))).build()).build();
} else {
final Location<World> lw = olw.get();
return Text.builder().append(Text.builder(x.getName()).color(TextColors.GREEN).style(TextStyles.UNDERLINE).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("home.warphover", x.getName()))).onClick(TextActions.runCommand(other ? "/homeother " + user.getName() + " " + x.getName() : "/home " + x.getName())).build()).append(plugin.getMessageProvider().getTextMessageWithFormat("home.location", lw.getExtent().getName(), String.valueOf(lw.getBlockX()), String.valueOf(lw.getBlockY()), String.valueOf(lw.getBlockZ()))).build();
}
}).collect(Collectors.toList());
PaginationList.Builder pb = Util.getPaginationBuilder(src).title(Text.of(TextColors.YELLOW, header)).padding(Text.of(TextColors.GREEN, "-")).contents(lt);
pb.sendTo(src);
return CommandResult.success();
}
Aggregations