use of io.github.nucleuspowered.nucleus.api.nucleusdata.Kit in project Nucleus by NucleusPowered.
the class KitAddCommandCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
String c = args.<String>getOne(command).get().replace(" {player} ", " {{player}} ");
kitInfo.addCommand(c);
KIT_HANDLER.saveKit(kitInfo);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.command.add.command", c, kitInfo.getName()));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Kit in project Nucleus by NucleusPowered.
the class KitRemoveCommandCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
List<String> commands = kitInfo.getCommands();
String cmd;
if (args.hasAny(index)) {
int idx = args.<Integer>getOne(index).get();
if (idx == 0) {
throw ReturnMessageException.fromKey("command.kit.command.remove.onebased");
}
if (idx > commands.size()) {
throw ReturnMessageException.fromKey("command.kit.command.remove.overidx", String.valueOf(commands.size()), kitInfo.getName());
}
cmd = commands.remove(idx - 1);
} else {
cmd = args.<String>getOne(command).get().replace(" {player} ", " {{player}} ");
if (!commands.remove(cmd)) {
throw ReturnMessageException.fromKey("command.kit.command.remove.noexist", cmd, kitInfo.getName());
}
}
kitInfo.setCommands(commands);
KIT_HANDLER.saveKit(kitInfo);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.command.remove.success", cmd, kitInfo.getName()));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Kit in project Nucleus by NucleusPowered.
the class KitAutoRedeemCommand method executeCommand.
@Override
public CommandResult executeCommand(final CommandSource player, CommandContext args) throws Exception {
Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
boolean b = args.<Boolean>getOne(toggle).get();
// This Kit is a reference back to the version in list, so we don't need
// to update it explicitly
kitInfo.setAutoRedeem(b);
KIT_HANDLER.saveKit(kitInfo);
player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat(b ? "command.kit.autoredeem.on" : "command.kit.autoredeem.off", kitInfo.getName()));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.api.nucleusdata.Kit in project Nucleus by NucleusPowered.
the class KitCommand method executeCommand.
@Override
public CommandResult executeCommand(Player player, CommandContext args) throws ReturnMessageException {
Kit kit = args.<Kit>getOne(KIT_PARAMETER).get();
EconHelper econHelper = Nucleus.getNucleus().getEconHelper();
double cost = econHelper.economyServiceExists() ? kit.getCost() : 0;
if (permissions.testCostExempt(player)) {
// If exempt - no cost.
cost = 0;
}
// If we have a cost for the kit, check we have funds.
if (cost > 0 && !econHelper.hasBalance(player, cost)) {
throw ReturnMessageException.fromKey("command.kit.notenough", kit.getName(), econHelper.getCurrencySymbol(cost));
}
try {
NucleusKitService.RedeemResult redeemResult = KIT_HANDLER.redeemKit(kit, player, true, this.mustGetAll);
if (!redeemResult.rejected().isEmpty()) {
// If we drop them, tell the user
if (this.isDrop) {
player.sendMessage(this.plugin.getMessageProvider().getTextMessageWithFormat("command.kit.itemsdropped"));
redeemResult.rejected().forEach(x -> Util.dropItemOnFloorAtLocation(x, player.getLocation()));
} else {
player.sendMessage(this.plugin.getMessageProvider().getTextMessageWithFormat("command.kit.fullinventory"));
}
}
if (kit.isDisplayMessageOnRedeem()) {
player.sendMessage(this.plugin.getMessageProvider().getTextMessageWithFormat("command.kit.spawned", kit.getName()));
}
// Charge, if necessary
if (cost > 0 && econHelper.economyServiceExists()) {
econHelper.withdrawFromPlayer(player, cost);
}
return CommandResult.success();
} catch (KitRedeemException ex) {
switch(ex.getReason()) {
case ALREADY_REDEEMED:
throw ReturnMessageException.fromKey("command.kit.onetime.alreadyredeemed", kit.getName());
case COOLDOWN_NOT_EXPIRED:
KitRedeemException.Cooldown kre = (KitRedeemException.Cooldown) ex;
throw ReturnMessageException.fromKey("command.kit.cooldown", Util.getTimeStringFromSeconds(kre.getTimeLeft().getSeconds()), kit.getName());
case PRE_EVENT_CANCELLED:
KitRedeemException.PreCancelled krepe = (KitRedeemException.PreCancelled) ex;
throw new ReturnMessageException(krepe.getCancelMessage().orElseGet(() -> (Nucleus.getNucleus().getMessageProvider().getTextMessageWithFormat("command.kit.cancelledpre", kit.getName()))));
case NO_SPACE:
throw ReturnMessageException.fromKey("command.kit.fullinventorynosave", kit.getName());
case UNKNOWN:
default:
throw ReturnMessageException.fromKey("command.kit.fail", kit.getName());
}
}
}
Aggregations