Search in sources :

Example 1 with Warp

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)));
}
Also used : Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) Text(org.spongepowered.api.text.Text) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)

Example 2 with Warp

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();
}
Also used : Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) NucleusTeleportHandler(io.github.nucleuspowered.nucleus.internal.teleport.NucleusTeleportHandler) Player(org.spongepowered.api.entity.living.player.Player) UseWarpEvent(io.github.nucleuspowered.nucleus.modules.warp.event.UseWarpEvent) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)

Example 3 with Warp

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();
}
Also used : Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) DeleteWarpEvent(io.github.nucleuspowered.nucleus.modules.warp.event.DeleteWarpEvent) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) NucleusWarpService(io.github.nucleuspowered.nucleus.api.service.NucleusWarpService)

Example 4 with Warp

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);
}
Also used : RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) WarpHandler(io.github.nucleuspowered.nucleus.modules.warp.handlers.WarpHandler) WarpCategory(io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory) WarpConfigAdapter(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfigAdapter) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Location(org.spongepowered.api.world.Location) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) WarpConfig(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfig) Set(java.util.Set) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) Objects(java.util.Objects) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Comparator(java.util.Comparator) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) Text(org.spongepowered.api.text.Text)

Example 5 with Warp

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);
}
Also used : RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) GenericArguments(org.spongepowered.api.command.args.GenericArguments) RunAsync(io.github.nucleuspowered.nucleus.internal.annotations.RunAsync) Warp(io.github.nucleuspowered.nucleus.api.nucleusdata.Warp) PermissionRegistry(io.github.nucleuspowered.nucleus.internal.PermissionRegistry) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) WarpHandler(io.github.nucleuspowered.nucleus.modules.warp.handlers.WarpHandler) WarpCategory(io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory) WarpConfigAdapter(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfigAdapter) Map(java.util.Map) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) CommandResult(org.spongepowered.api.command.CommandResult) TextActions(org.spongepowered.api.text.action.TextActions) Location(org.spongepowered.api.world.Location) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) WarpConfig(io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfig) Set(java.util.Set) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) Reloadable(io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable) Objects(java.util.Objects) List(java.util.List) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) MessageProvider(io.github.nucleuspowered.nucleus.internal.messages.MessageProvider) World(org.spongepowered.api.world.World) Optional(java.util.Optional) Comparator(java.util.Comparator) Text(org.spongepowered.api.text.Text)

Aggregations

Warp (io.github.nucleuspowered.nucleus.api.nucleusdata.Warp)8 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)5 Text (org.spongepowered.api.text.Text)4 WarpCategory (io.github.nucleuspowered.nucleus.api.nucleusdata.WarpCategory)3 PermissionRegistry (io.github.nucleuspowered.nucleus.internal.PermissionRegistry)3 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)3 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)3 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)3 Reloadable (io.github.nucleuspowered.nucleus.internal.interfaces.Reloadable)3 SuggestedLevel (io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel)3 WarpConfig (io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfig)3 WarpConfigAdapter (io.github.nucleuspowered.nucleus.modules.warp.config.WarpConfigAdapter)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 CommandResult (org.spongepowered.api.command.CommandResult)3 CommandSource (org.spongepowered.api.command.CommandSource)3 CommandContext (org.spongepowered.api.command.args.CommandContext)3 CommandElement (org.spongepowered.api.command.args.CommandElement)3 GenericArguments (org.spongepowered.api.command.args.GenericArguments)3