Search in sources :

Example 6 with VaultController

use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.

the class Messages method describeCurrency.

@Override
public String describeCurrency(double amount) {
    VaultController vault = VaultController.getInstance();
    if (vault == null)
        return Integer.toString((int) amount);
    String formatted = vault.format(amount);
    if (!VaultController.hasEconomy()) {
        formatted = get("costs.currency_amount").replace("$amount", formatted);
    }
    return formatted;
}
Also used : VaultController(com.elmakers.mine.bukkit.integration.VaultController)

Example 7 with VaultController

use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.

the class CitizensTrait method configure.

public void configure(CommandSender sender, String key, String value) {
    if (key == null) {
        return;
    }
    if (key.equalsIgnoreCase("permission")) {
        permissionNode = value;
        if (value == null) {
            sender.sendMessage(ChatColor.RED + "Cleared permission node");
        } else {
            sender.sendMessage(ChatColor.DARK_PURPLE + "Set required permission to: " + ChatColor.LIGHT_PURPLE + permissionNode);
        }
    } else if (key.equalsIgnoreCase("invisible")) {
        if (value == null || !value.equalsIgnoreCase("true")) {
            sender.sendMessage(ChatColor.DARK_PURPLE + "Set NPC visible");
            invisible = false;
        } else {
            invisible = true;
            sender.sendMessage(ChatColor.DARK_PURPLE + "Set NPC invisible");
        }
        updateEntity();
    } else if (key.equalsIgnoreCase("cost")) {
        if (value == null) {
            sender.sendMessage(ChatColor.DARK_PURPLE + "Cleared cost");
            cost = 0;
        } else {
            try {
                cost = Double.parseDouble(value);
                if (VaultController.hasEconomy()) {
                    VaultController vault = VaultController.getInstance();
                    sender.sendMessage(ChatColor.DARK_PURPLE + "Set cost to: " + ChatColor.GOLD + vault.format(cost));
                } else {
                    sender.sendMessage(ChatColor.DARK_PURPLE + "Set cost to " + value);
                }
            } catch (Exception ex) {
                sender.sendMessage(ChatColor.RED + "Invalid cost: " + value);
            }
        }
    } else if (key.equalsIgnoreCase("requires")) {
        if (value == null) {
            sender.sendMessage(ChatColor.DARK_PURPLE + "Cleared item requirement");
            cost = 0;
        } else {
            try {
                requireItem = api.createItem(value);
                sender.sendMessage(ChatColor.DARK_PURPLE + "Set item requirement to " + api.describeItem(requireItem));
            } catch (Exception ex) {
                sender.sendMessage(ChatColor.RED + "Invalid item: " + value);
            }
        }
    } else if (key.equalsIgnoreCase("hat")) {
        hatItem = api.createItem(value);
        if (hatItem == null) {
            sender.sendMessage(ChatColor.DARK_PURPLE + "removed hat");
            Entity entity = null;
            try {
                entity = npc.getEntity();
            } catch (Exception ignored) {
            }
            LivingEntity li = entity instanceof LivingEntity ? (LivingEntity) entity : null;
            if (li != null) {
                li.getEquipment().setHelmet(hatItem);
            }
        } else {
            try {
                hatItem = api.createItem(value);
                sender.sendMessage(ChatColor.DARK_PURPLE + "Set hat to " + api.describeItem(hatItem));
                updateEntity();
            } catch (Exception ex) {
                sender.sendMessage(ChatColor.RED + "Invalid item: " + value);
            }
        }
    } else {
        sender.sendMessage(ChatColor.RED + "Not a valid configuration option- use the <tab> key for help");
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) VaultController(com.elmakers.mine.bukkit.integration.VaultController)

Example 8 with VaultController

use of com.elmakers.mine.bukkit.integration.VaultController in project MagicPlugin by elBukkit.

the class CitizensTrait method onClick.

@EventHandler
public void onClick(net.citizensnpcs.api.event.NPCRightClickEvent event) {
    if (event.getNPC() != this.getNPC())
        return;
    CommandSender sender = event.getClicker();
    Player player = event.getClicker();
    if (permissionNode != null && !player.hasPermission(permissionNode)) {
        return;
    }
    if (cost > 0) {
        if (!VaultController.hasEconomy()) {
            sender.sendMessage(api.getMessages().get("economy.missing"));
            return;
        }
        VaultController vault = VaultController.getInstance();
        if (!vault.has(player, cost)) {
            sender.sendMessage(api.getMessages().get("economy.insufficient").replace("$cost", vault.format(cost)));
            return;
        }
    }
    if (requireItem != null && !api.hasItem(player, requireItem)) {
        sender.sendMessage(api.getMessages().get("economy.requires").replace("$cost", api.describeItem(requireItem)));
        return;
    }
    boolean result = perform(event);
    if (result && cost > 0) {
        VaultController vault = VaultController.getInstance();
        sender.sendMessage(api.getMessages().get("economy.deducted").replace("$cost", vault.format(cost)));
        vault.withdrawPlayer(player, cost);
    }
    if (result && requireItem != null) {
        sender.sendMessage(api.getMessages().get("economy.deducted").replace("$cost", api.describeItem(requireItem)));
        api.takeItem(player, requireItem);
    }
}
Also used : Player(org.bukkit.entity.Player) CommandSender(org.bukkit.command.CommandSender) VaultController(com.elmakers.mine.bukkit.integration.VaultController) EventHandler(org.bukkit.event.EventHandler)

Aggregations

VaultController (com.elmakers.mine.bukkit.integration.VaultController)8 LivingEntity (org.bukkit.entity.LivingEntity)2 Player (org.bukkit.entity.Player)2 ItemStack (org.bukkit.inventory.ItemStack)2 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 TreeMap (java.util.TreeMap)1 DyeColor (org.bukkit.DyeColor)1 Material (org.bukkit.Material)1 TreeSpecies (org.bukkit.TreeSpecies)1 CommandSender (org.bukkit.command.CommandSender)1 Entity (org.bukkit.entity.Entity)1 EventHandler (org.bukkit.event.EventHandler)1 PlayerInventory (org.bukkit.inventory.PlayerInventory)1