Search in sources :

Example 1 with FeatureValue

use of com.nextplugins.economy.configuration.FeatureValue in project NextEconomy by NextPlugins.

the class CheckUtil method createCheck.

public static ItemStack createCheck(double checkValue) {
    val checkSection = FeatureValue.get(FeatureValue::checkItem);
    List<String> lore = new ArrayList<>();
    for (String line : checkSection.getStringList("lore")) {
        String colored = ColorUtil.colored(line);
        String amount = colored.replace("$amount", NumberUtils.format(checkValue));
        lore.add(amount);
    }
    val checkItem = new ItemBuilder(Material.valueOf(checkSection.getString("material")), checkSection.getInt("data")).name(ColorUtil.colored(checkSection.getString("display-name"))).setLore(lore).wrap();
    val nbtItem = new NBTItem(checkItem);
    nbtItem.setDouble("value", checkValue);
    return nbtItem.getItem();
}
Also used : lombok.val(lombok.val) ArrayList(java.util.ArrayList) NBTItem(de.tr7zw.changeme.nbtapi.NBTItem) FeatureValue(com.nextplugins.economy.configuration.FeatureValue)

Example 2 with FeatureValue

use of com.nextplugins.economy.configuration.FeatureValue in project NextEconomy by NextPlugins.

the class CheckCommand method createCheckCommand.

@Command(name = "check.create", aliases = { "criar" }, description = "Crie um cheque com um certo valor.", permission = "nexteconomy.command.check", usage = "/cheque criar (valor) [jogador]", target = CommandTarget.PLAYER, async = true)
public void createCheckCommand(Context<Player> context, String value, @Optional Player target) {
    val player = context.getSender();
    val amount = NumberUtils.parse(value);
    val minValue = FeatureValue.get(FeatureValue::checkMinimumValue);
    if (amount < minValue) {
        player.sendMessage(MessageValue.get(MessageValue::checkMinimumValue).replace("$amount", NumberUtils.format(minValue)));
        return;
    }
    val account = accountStorage.findAccount(player);
    if (!account.hasAmount(amount)) {
        player.sendMessage(MessageValue.get(MessageValue::checkInsufficientValue));
        return;
    }
    val response = account.createTransaction(Transaction.builder().player(player).owner("Cheque").amount(amount).amountWithoutPurse(0).transactionType(TransactionType.WITHDRAW).build());
    if (!response.transactionSuccess()) {
        player.sendMessage(MessageValue.get(MessageValue::checkMinimumValue).replace("$amount", NumberUtils.format(minValue)));
        return;
    }
    player.sendMessage(MessageValue.get(MessageValue::checkCreated).replace("$checkValue", NumberUtils.format(amount)));
    val checkItem = CheckUtil.createCheck(amount);
    if (target != null) {
        target.sendMessage(MessageValue.get(MessageValue::checkReceived).replace("$checkValue", NumberUtils.format(amount)).replace("$sender", player.getName()));
        dropItem(target, target.getInventory().addItem(checkItem));
        return;
    }
    dropItem(player, player.getInventory().addItem(checkItem));
}
Also used : lombok.val(lombok.val) MessageValue(com.nextplugins.economy.configuration.MessageValue) FeatureValue(com.nextplugins.economy.configuration.FeatureValue) Command(me.saiintbrisson.minecraft.command.annotation.Command)

Example 3 with FeatureValue

use of com.nextplugins.economy.configuration.FeatureValue in project NextEconomy by NextPlugins.

the class CommandRegistry method register.

public void register() {
    try {
        BukkitFrame bukkitFrame = new BukkitFrame(plugin);
        bukkitFrame.registerCommands(new MoneyCommand(plugin, plugin.getAccountStorage(), plugin.getLocationManager()), new NextEconomyCommand(plugin.getBackupManager(), plugin.getRankingStorage(), plugin.getAccountStorage(), plugin.getConversorManager()));
        if (FeatureValue.get(FeatureValue::checkSystemEnabled)) {
            bukkitFrame.registerCommands(new CheckCommand(plugin.getAccountStorage()));
        }
        if (PurseValue.get(PurseValue::enable)) {
            bukkitFrame.registerCommands(new PurseCommand());
        }
        MessageHolder messageHolder = bukkitFrame.getMessageHolder();
        messageHolder.setMessage(MessageType.ERROR, MessageValue.get(MessageValue::error));
        messageHolder.setMessage(MessageType.INCORRECT_TARGET, MessageValue.get(MessageValue::incorrectTarget));
        messageHolder.setMessage(MessageType.INCORRECT_USAGE, MessageValue.get(MessageValue::incorrectUsage));
        messageHolder.setMessage(MessageType.NO_PERMISSION, MessageValue.get(MessageValue::noPermission));
        plugin.getLogger().info("Comandos registrados com sucesso.");
    } catch (Throwable t) {
        t.printStackTrace();
        plugin.getLogger().severe("Não foi possível registrar os comandos.");
    }
}
Also used : BukkitFrame(me.saiintbrisson.bukkit.command.BukkitFrame) CheckCommand(com.nextplugins.economy.command.bukkit.CheckCommand) MessageHolder(me.saiintbrisson.minecraft.command.message.MessageHolder) MoneyCommand(com.nextplugins.economy.command.bukkit.MoneyCommand) NextEconomyCommand(com.nextplugins.economy.command.bukkit.NextEconomyCommand) PurseCommand(com.nextplugins.economy.command.bukkit.PurseCommand) FeatureValue(com.nextplugins.economy.configuration.FeatureValue) PurseValue(com.nextplugins.economy.configuration.PurseValue)

Example 4 with FeatureValue

use of com.nextplugins.economy.configuration.FeatureValue in project NextEconomy by NextPlugins.

the class TransactionRequestListener method onRequest.

@EventHandler(priority = EventPriority.MONITOR)
public void onRequest(TransactionRequestEvent event) {
    if (event.isCancelled())
        return;
    val player = event.getPlayer();
    val target = event.getTarget();
    val targetAccount = event.getAccount();
    val amount = event.getAmount();
    if (target.equals(player)) {
        player.sendMessage(MessageValue.get(MessageValue::isYourself));
        return;
    }
    val account = accountStorage.findAccount(player);
    if (NumberUtils.isInvalid(amount)) {
        player.sendMessage(MessageValue.get(MessageValue::invalidMoney));
        return;
    }
    val minValue = FeatureValue.get(FeatureValue::minTransactionValue);
    if (amount < minValue) {
        player.sendMessage(MessageValue.get(MessageValue::minValueNecessary).replace("$amount", NumberUtils.format(minValue)));
        return;
    }
    if (!account.hasAmount(amount)) {
        player.sendMessage(MessageValue.get(MessageValue::insufficientAmount));
        return;
    }
    targetAccount.createTransaction(Transaction.builder().player(target.isOnline() ? target.getPlayer() : null).owner(player.getName()).amount(event.getAmount()).transactionType(TransactionType.DEPOSIT).build());
    account.createTransaction(Transaction.builder().player(player).owner(target.getName()).amount(event.getAmount()).transactionType(TransactionType.WITHDRAW).build());
    player.sendMessage(MessageValue.get(MessageValue::paid).replace("$player", target.getName()).replace("$amount", NumberUtils.format(amount)));
    if (target.isOnline()) {
        target.getPlayer().sendMessage(MessageValue.get(MessageValue::received).replace("$player", player.getName()).replace("$amount", NumberUtils.format(amount)));
    }
}
Also used : lombok.val(lombok.val) MessageValue(com.nextplugins.economy.configuration.MessageValue) FeatureValue(com.nextplugins.economy.configuration.FeatureValue) EventHandler(org.bukkit.event.EventHandler)

Aggregations

FeatureValue (com.nextplugins.economy.configuration.FeatureValue)4 lombok.val (lombok.val)3 MessageValue (com.nextplugins.economy.configuration.MessageValue)2 CheckCommand (com.nextplugins.economy.command.bukkit.CheckCommand)1 MoneyCommand (com.nextplugins.economy.command.bukkit.MoneyCommand)1 NextEconomyCommand (com.nextplugins.economy.command.bukkit.NextEconomyCommand)1 PurseCommand (com.nextplugins.economy.command.bukkit.PurseCommand)1 PurseValue (com.nextplugins.economy.configuration.PurseValue)1 NBTItem (de.tr7zw.changeme.nbtapi.NBTItem)1 ArrayList (java.util.ArrayList)1 BukkitFrame (me.saiintbrisson.bukkit.command.BukkitFrame)1 Command (me.saiintbrisson.minecraft.command.annotation.Command)1 MessageHolder (me.saiintbrisson.minecraft.command.message.MessageHolder)1 EventHandler (org.bukkit.event.EventHandler)1