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();
}
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));
}
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.");
}
}
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)));
}
}
Aggregations