use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp in project Nucleus by NucleusPowered.
the class SetDescriptionCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
String warpName = args.<Warp>getOne(warpKey).get().getName();
if (args.hasAny("r")) {
// Remove the desc.
if (handler.setWarpDescription(warpName, null)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.description.removed", warpName));
return CommandResult.success();
}
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.description.noremove", warpName));
}
// Add the category.
Text message = TextSerializers.FORMATTING_CODE.deserialize(args.<String>getOne(descriptionKey).get());
if (handler.setWarpDescription(warpName, message)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.warp.description.added", message, Text.of(warpName)));
return CommandResult.success();
}
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithTextFormat("command.warp.description.couldnotadd", Text.of(warpName)));
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp in project Nucleus by NucleusPowered.
the class WarpCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource source, CommandContext args) throws Exception {
Player player = this.getUserFromArgs(Player.class, source, playerKey, args);
boolean isOther = !(source instanceof Player) || !((Player) source).getUniqueId().equals(player.getUniqueId());
// Permission checks are done by the parser.
Warp wd = args.<Warp>getOne(warpNameArg).get();
// Load the world in question
if (!wd.getTransform().isPresent()) {
Sponge.getServer().loadWorld(wd.getWorldProperties().get().getUniqueId()).orElseThrow(() -> ReturnMessageException.fromKey("command.warp.worldnotloaded"));
}
UseWarpEvent event = CauseStackHelper.createFrameWithCausesWithReturn(c -> new UseWarpEvent(c, player, wd), source);
if (Sponge.getEventManager().post(event)) {
throw new ReturnMessageException(event.getCancelMessage().orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("nucleus.eventcancelled")));
}
Optional<Double> i = wd.getCost();
double cost = i.orElse(this.defaultCost);
boolean charge = false;
if (!isOther && plugin.getEconHelper().economyServiceExists() && !permissions.testCostExempt(source) && cost > 0) {
if (plugin.getEconHelper().withdrawFromPlayer(player, cost, false)) {
// only true for a warp by the current subject.
charge = true;
} else {
source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.nomoney", wd.getName(), plugin.getEconHelper().getCurrencySymbol(cost)));
return CommandResult.empty();
}
}
// We have a warp data, warp them.
if (isOther) {
source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.namedstart", plugin.getNameUtil().getSerialisedName(player), wd.getName()));
} else {
source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.start", wd.getName()));
}
// Warp them.
boolean isSafe = !args.getOne("f").isPresent() && this.isSafeTeleport;
NucleusTeleportHandler.TeleportResult result = plugin.getTeleportHandler().teleportPlayer(player, wd.getLocation().get(), wd.getRotation(), isSafe);
if (!result.isSuccess()) {
if (charge) {
plugin.getEconHelper().depositInPlayer(player, cost, false);
}
// Don't add the cooldown if enabled.
throw ReturnMessageException.fromKey(result == NucleusTeleportHandler.TeleportResult.FAILED_NO_LOCATION ? "command.warps.nosafe" : "command.warps.cancelled");
}
if (isOther) {
player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.warped", wd.getName()));
} else if (charge) {
source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.charged", plugin.getEconHelper().getCurrencySymbol(cost)));
}
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp in project Nucleus by NucleusPowered.
the class DeleteWarpCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Warp warp = args.<Warp>getOne(WarpCommand.warpNameArg).get();
NucleusWarpService qs = Sponge.getServiceManager().provideUnchecked(NucleusWarpService.class);
DeleteWarpEvent event = new DeleteWarpEvent(CauseStackHelper.createCause(src), warp);
if (Sponge.getEventManager().post(event)) {
throw new ReturnMessageException(event.getCancelMessage().orElseGet(() -> plugin.getMessageProvider().getTextMessageWithFormat("nucleus.eventcancelled")));
}
if (qs.removeWarp(warp.getName())) {
// Worked. Tell them.
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.del", warp.getName()));
return CommandResult.success();
}
// Didn't work. Tell them.
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.delerror"));
return CommandResult.empty();
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp in project Nucleus by NucleusPowered.
the class ListWarpCommand method createMain.
private void createMain(final CommandSource src, final Map<WarpCategory, List<Warp>> warps) {
List<Text> lt = warps.keySet().stream().filter(Objects::nonNull).sorted(Comparator.comparing(WarpCategory::getId)).map(s -> {
Text.Builder t = Text.builder("> ").color(TextColors.GREEN).style(TextStyles.ITALIC).append(s.getDisplayName()).onClick(TextActions.executeCallback(source -> createSub(source, s, warps)));
s.getDescription().ifPresent(x -> t.append(Text.of(" - ")).append(Text.of(TextColors.RESET, TextStyles.NONE, x)));
return t.build();
}).collect(Collectors.toList());
// Uncategorised
if (warps.containsKey(null)) {
lt.add(Text.builder("> " + this.defaultName).color(TextColors.GREEN).style(TextStyles.ITALIC).onClick(TextActions.executeCallback(source -> createSub(source, null, warps))).build());
}
MessageProvider messageProvider = plugin.getMessageProvider();
Util.getPaginationBuilder(src).header(messageProvider.getTextMessageWithFormat("command.warps.list.headercategory")).title(messageProvider.getTextMessageWithFormat("command.warps.list.maincategory")).padding(Text.of(TextColors.GREEN, "-")).contents(lt).sendTo(src);
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp in project Nucleus by NucleusPowered.
the class ListWarpCommand method createSub.
private void createSub(final CommandSource src, @Nullable final WarpCategory category, final Map<WarpCategory, List<Warp>> warpDataList) {
final boolean econExists = plugin.getEconHelper().economyServiceExists();
Text name = category == null ? Text.of(this.defaultName) : category.getDisplayName();
List<Text> lt = warpDataList.get(category).stream().sorted(Comparator.comparing(Warp::getName)).map(s -> createWarp(s, s.getName(), econExists, defaultCost)).collect(Collectors.toList());
Util.getPaginationBuilder(src).title(plugin.getMessageProvider().getTextMessageWithTextFormat("command.warps.list.category", name)).padding(Text.of(TextColors.GREEN, "-")).contents(lt).footer(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.list.back").toBuilder().onClick(TextActions.executeCallback(s -> createMain(s, warpDataList))).build()).sendTo(src);
}
Aggregations