use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp in project Nucleus by NucleusPowered.
the class SetCategoryCommand 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 category.
if (handler.setWarpCategory(warpName, null)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.removed", warpName));
return CommandResult.success();
}
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.noremove", warpName));
}
Optional<Tuple<String, Boolean>> categoryOp = args.getOne(categoryKey);
if (!categoryOp.isPresent()) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.required"));
}
Tuple<String, Boolean> category = categoryOp.get();
if (!args.hasAny("n") && !category.getSecond()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.requirenew", category.getFirst()).toBuilder().onClick(TextActions.runCommand("/warp setcategory -n " + warpName + " " + category.getFirst())).build());
return CommandResult.empty();
}
// Add the category.
if (handler.setWarpCategory(warpName, category.getFirst())) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.category.added", category.getFirst(), warpName));
return CommandResult.success();
}
WarpCategory c = handler.getWarpCategoryOrDefault(category.getFirst());
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithTextFormat("command.warp.category.couldnotadd", c.getDisplayName(), Text.of(warpName)));
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp in project Nucleus by NucleusPowered.
the class SetCostCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Warp warpData = args.<Warp>getOne(warpKey).get();
double cost = args.<Double>getOne(costKey).get();
if (cost < -1) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.costset.arg"));
return CommandResult.empty();
}
if (cost == -1 && warpHandler.setWarpCost(warpData.getName(), -1)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.costset.reset", warpData.getName(), String.valueOf(this.defaultCost)));
return CommandResult.success();
} else if (warpHandler.setWarpCost(warpData.getName(), cost)) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.costset.success", warpData.getName(), String.valueOf(cost)));
return CommandResult.success();
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.warp.costset.failed", warpData.getName()));
return CommandResult.empty();
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Warp 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;
}
Aggregations