use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class HomeOtherCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
// Get the home.
Home wl = args.<Home>getOne(home).get();
Sponge.getServer().loadWorld(wl.getWorldProperties().orElseThrow(() -> ReturnMessageException.fromKey("command.home.invalid", wl.getName())));
Location<World> targetLocation = wl.getLocation().orElseThrow(() -> ReturnMessageException.fromKey("command.home.invalid", wl.getName()));
UseHomeEvent event = CauseStackHelper.createFrameWithCausesWithReturn(c -> new UseHomeEvent(c, src, wl), src);
if (Sponge.getEventManager().post(event)) {
throw new ReturnMessageException(event.getCancelMessage().orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("nucleus.eventcancelled")));
}
// Warp to it safely.
if (plugin.getTeleportHandler().teleportPlayer(src, targetLocation, wl.getRotation(), this.isSafeTeleport).isSuccess()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.homeother.success", wl.getUser().getName(), wl.getName()));
return CommandResult.success();
} else {
throw ReturnMessageException.fromKey("command.homeother.fail", wl.getUser().getName(), wl.getName());
}
}
use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException 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();
}
use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class InfoCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Optional<InfoArgument.Result> oir = args.getOne(key);
if (infoConfig.isUseDefaultFile() && !oir.isPresent() && !args.hasAny("l")) {
// Do we have a default?
String def = infoConfig.getDefaultInfoSection();
Optional<TextFileController> list = infoHandler.getSection(def);
if (list.isPresent()) {
oir = Optional.of(new InfoArgument.Result(infoHandler.getInfoSections().stream().filter(def::equalsIgnoreCase).findFirst().get(), list.get()));
}
}
if (oir.isPresent()) {
TextFileController controller = oir.get().text;
Text def = TextSerializers.FORMATTING_CODE.deserialize(oir.get().name);
Text title = plugin.getMessageProvider().getTextMessageWithTextFormat("command.info.title.section", controller.getTitle(src).orElseGet(() -> Text.of(def)));
controller.sendToPlayer(src, title);
return CommandResult.success();
}
// Create a list of pages to load.
Set<String> sections = infoHandler.getInfoSections();
if (sections.isEmpty()) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.info.none"));
}
// Create the text.
List<Text> s = Lists.newArrayList();
sections.forEach(x -> {
Text.Builder tb = Text.builder().append(Text.builder(x).color(TextColors.GREEN).style(TextStyles.ITALIC).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("command.info.hover", x))).onClick(TextActions.runCommand("/info " + x)).build());
// If there is a title, then add it.
infoHandler.getSection(x).get().getTitle(src).ifPresent(sub -> tb.append(Text.of(TextColors.GOLD, " - ")).append(sub));
s.add(tb.build());
});
Util.getPaginationBuilder(src).contents().header(plugin.getMessageProvider().getTextMessageWithFormat("command.info.header.default")).title(plugin.getMessageProvider().getTextMessageWithFormat("command.info.title.default")).contents(s.stream().sorted(Comparator.comparing(Text::toPlain)).collect(Collectors.toList())).padding(Text.of(TextColors.GOLD, "-")).sendTo(src);
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class NicknameCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
User pl = this.getUserFromArgs(User.class, src, playerKey, args);
Text name = args.<String>getOne(nickName).map(TextSerializers.FORMATTING_CODE::deserialize).get();
try {
nicknameService.setNick(pl, src, name, false);
} catch (NicknameException e) {
throw new ReturnMessageException(e.getTextMessage());
}
if (!src.equals(pl)) {
src.sendMessage(Text.builder().append(plugin.getMessageProvider().getTextMessageWithFormat("command.nick.success.other", pl.getName())).append(Text.of(" - ", TextColors.RESET, name)).build());
}
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException in project Nucleus by NucleusPowered.
the class SocialSpyCommand method executeCommand.
@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
if (handler.forcedSocialSpyState(src).asBoolean()) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.socialspy.forced"));
}
boolean spy = args.<Boolean>getOne(arg).orElse(!handler.isSocialSpy(src));
if (handler.setSocialSpy(src, spy)) {
Text message = plugin.getMessageProvider().getTextMessageWithFormat(spy ? "command.socialspy.on" : "command.socialspy.off");
src.sendMessage(message);
return CommandResult.success();
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.socialspy.unable"));
return CommandResult.empty();
}
Aggregations