use of org.spongepowered.api.command.CommandSource 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);
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class WarpCommand method preProcessChecks.
@Override
protected ContinueMode preProcessChecks(final CommandSource source, CommandContext args) {
if (args.<Player>getOne(playerKey).map(x -> !(source instanceof Player) || x.getUniqueId().equals(((Player) source).getUniqueId())).orElse(false)) {
// Bypass cooldowns
args.putArg(NoModifiersArgument.NO_COOLDOWN_ARGUMENT, true);
return ContinueMode.CONTINUE;
}
if (!plugin.getEconHelper().economyServiceExists() || permissions.testCostExempt(source) || args.hasAny("y")) {
return ContinueMode.CONTINUE;
}
Warp wd = args.<Warp>getOne(warpNameArg).get();
Optional<Double> i = wd.getCost();
double cost = i.orElse(this.defaultCost);
if (cost <= 0) {
return ContinueMode.CONTINUE;
}
String costWithUnit = plugin.getEconHelper().getCurrencySymbol(cost);
if (plugin.getEconHelper().hasBalance((Player) source, cost)) {
String command = String.format("/warp -y %s", wd.getName());
source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.details", wd.getName(), costWithUnit));
source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.clickaccept").toBuilder().onClick(TextActions.runCommand(command)).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.clickhover", command))).append(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.alt")).build());
} else {
source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.cost.nomoney", wd.getName(), costWithUnit));
}
return ContinueMode.STOP;
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class IfConditionElseArgumentTests method process.
private boolean process(BiPredicate<CommandSource, CommandContext> cond) throws Exception {
// Get the element
CommandSource source = Mockito.mock(CommandSource.class);
CommandArgs args = new CommandArgs("", Lists.newArrayList());
CommandContext context = new CommandContext();
new IfConditionElseArgument(new TrueArgument(), new FalseArgument(), cond).parse(source, args, context);
return context.<Boolean>getOne("key").orElseThrow(NullPointerException::new);
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class NicknameArgumentTests method mockSource.
private CommandSource mockSource() {
CommandSource mock = Mockito.mock(CommandSource.class);
Mockito.when(mock.hasPermission(Mockito.any())).thenReturn(true);
return mock;
}
use of org.spongepowered.api.command.CommandSource in project Nucleus by NucleusPowered.
the class NoCostArgumentTests method getNoCostArgument.
private CommandContext getNoCostArgument(CommandElement toWrap, CommandContext cc) throws ArgumentParseException {
CommandSource s = Mockito.mock(Player.class);
CommandArgs ca = new CommandArgs("", new ArrayList<>());
NoModifiersArgument<?> nca = new NoModifiersArgument<>(toWrap, (c, o) -> true);
nca.parse(s, ca, cc);
return cc;
}
Aggregations