use of io.github.nucleuspowered.nucleus.configurate.datatypes.ItemDataNode in project Nucleus by NucleusPowered.
the class ClearItemAliasesCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
CatalogType al = args.<CatalogType>getOne(item).get();
String id = al.getId().toLowerCase();
ItemDataNode node = itemDataService.getDataForItem(id);
node.clearAliases();
itemDataService.setDataForItem(id, node);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.removeitemalias.cleared", id));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.configurate.datatypes.ItemDataNode in project Nucleus by NucleusPowered.
the class SetItemAliasCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
// Do we have an item or blockstate?
String a = args.<String>getOne(alias).get().toLowerCase();
if (itemDataService.getIdFromAlias(a).isPresent()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.setitemalias.inuse", a));
return CommandResult.empty();
}
if (!ItemDataNode.ALIAS_PATTERN.matcher(a).matches()) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.setitemalias.notvalid", a));
return CommandResult.empty();
}
CatalogType type = getCatalogTypeFromHandOrArgs(src, item, args);
// Set the alias.
String id = type.getId().toLowerCase();
ItemDataNode idn = itemDataService.getDataForItem(id);
idn.addAlias(a);
itemDataService.setDataForItem(id, idn);
// Tell the user
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.setitemalias.success", a, id));
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.configurate.datatypes.ItemDataNode in project Nucleus by NucleusPowered.
the class BuyCommand method executeCommand.
@Override
public CommandResult executeCommand(final Player src, CommandContext args) throws Exception {
CatalogType ct = args.<CatalogType>getOne(itemKey).get();
int amount = args.<Integer>getOne(amountKey).get();
ItemDataNode node = itemDataService.getDataForItem(ct.getId());
if (node.getServerBuyPrice() < 0) {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.itembuy.notforsale"));
return CommandResult.empty();
}
if (amount > max) {
amount = max;
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.itembuy.maximum", String.valueOf(amount)));
}
final ItemStack created;
if (ct instanceof ItemType) {
created = ItemStack.of((ItemType) ct, amount);
} else {
created = ItemStack.builder().fromBlockState((BlockState) ct).quantity(amount).build();
}
// Get the cost.
final double perUnitCost = node.getServerBuyPrice();
final int unitCount = amount;
final double overallCost = perUnitCost * unitCount;
src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itembuy.summary", Text.of(String.valueOf(amount)), Text.of(created), Text.of(econHelper.getCurrencySymbol(overallCost))));
if (args.hasAny("y")) {
new BuyCallback(src, overallCost, created, unitCount, perUnitCost).accept(src);
} else {
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.itembuy.clickhere").toBuilder().onClick(TextActions.executeCallback(new BuyCallback(src, overallCost, created, unitCount, perUnitCost))).build());
}
return CommandResult.success();
}
use of io.github.nucleuspowered.nucleus.configurate.datatypes.ItemDataNode in project Nucleus by NucleusPowered.
the class SellAllCommand method executeCommand.
@Override
public CommandResult executeCommand(final Player src, CommandContext args) throws Exception {
boolean accepted = args.hasAny("a");
CatalogType ct = getCatalogTypeFromHandOrArgs(src, itemKey, args);
String id = ct.getId();
ItemStack query;
if (ct instanceof BlockState) {
query = ItemStack.builder().fromBlockState((BlockState) ct).quantity(1).build();
// Yeah...
query.setQuantity(-1);
} else {
// Having a quantity of -1 causes an IllegalArgumentException here...
query = ItemStack.of((ItemType) ct, 1);
// and doesn't care here...
query.setQuantity(-1);
}
ItemDataNode node = itemDataService.getDataForItem(id);
final double sellPrice = node.getServerSellPrice();
if (sellPrice < 0) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.itemsell.notforselling"));
}
Iterable<Slot> slots = Util.getStandardInventory(src).query(query).slots();
List<ItemStack> itemsToSell = StreamSupport.stream(Util.getStandardInventory(src).query(query).slots().spliterator(), false).map(Inventory::peek).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
// Get the cost.
final int amt = itemsToSell.stream().mapToInt(ItemStack::getQuantity).sum();
if (amt <= 0) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsellall.none", Text.of(query)));
}
final double overallCost = sellPrice * amt;
if (accepted) {
if (econHelper.depositInPlayer(src, overallCost, false)) {
slots.forEach(Inventory::clear);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsell.summary", Text.of(amt), Text.of(query), Text.of(econHelper.getCurrencySymbol(overallCost))));
return CommandResult.success();
}
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsell.error", Text.of(query)));
}
src.sendMessage(plugin.getMessageProvider().getTextMessageWithTextFormat("command.itemsellall.summary", Text.of(amt), Text.of(query), Text.of(econHelper.getCurrencySymbol(overallCost)), Text.of(id)).toBuilder().onClick(TextActions.runCommand("/nucleus:itemsellall -a " + id)).build());
return CommandResult.success();
}
Aggregations