Search in sources :

Example 1 with Tag

use of com.iCo6.util.nbt.Tag in project Core by iConomy.

the class Status method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "status"))
        throw new InvalidUsage("You do not have permission to do that.");
    String name = arguments.get("name").getStringValue();
    String tag = template.color(Template.Node.TAG_MONEY);
    boolean self = false;
    if (!isConsole(sender))
        if (((Player) sender).getName().equalsIgnoreCase(name))
            self = true;
    if (name.equals("0"))
        throw new InvalidUsage("Missing <white>name<rose>: /money status <name> (new status)");
    if (!Accounts.exists(name)) {
        template.set(Template.Node.ERROR_ACCOUNT);
        template.add("name", name);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    Account account = new Account(name);
    if (arguments.get("status").getStringValue().equalsIgnoreCase("empty")) {
        int current = account.getStatus();
        if (self)
            template.set(Template.Node.PERSONAL_STATUS);
        else {
            template.set(Template.Node.PLAYER_STATUS);
            template.add("name", name);
        }
        template.add("status", current);
        Messaging.send(sender, tag + template.parse());
    } else {
        if (!hasPermissions(sender, "status+"))
            throw new InvalidUsage("You do not have permission to do that.");
        int status = arguments.get("status").getIntegerValue();
        account.setStatus(status);
        template.set(Template.Node.ACCOUNTS_STATUS);
        template.add("status", status);
        Messaging.send(sender, tag + template.parse());
    }
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) Account(com.iCo6.system.Account) Player(org.bukkit.entity.Player)

Example 2 with Tag

use of com.iCo6.util.nbt.Tag in project Core by iConomy.

the class Account method toString.

@Override
public String toString() {
    String tag = iConomy.Template.raw(Template.Node.TAG_MONEY);
    Template template = iConomy.Template;
    template.set(Template.Node.PLAYER_BALANCE);
    template.add("name", name);
    template.add("balance", getHoldings().getBalance());
    return tag + template.parseRaw();
}
Also used : Template(com.iCo6.util.Template)

Example 3 with Tag

use of com.iCo6.util.nbt.Tag in project Core by iConomy.

the class Holdings method showBalance.

public void showBalance(CommandSender to) {
    if (to != null) {
        String tag = iConomy.Template.raw(Template.Node.TAG_MONEY);
        Template template = iConomy.Template;
        template.set(Template.Node.PLAYER_BALANCE);
        template.add("name", name);
        template.add("balance", toString());
        Messaging.send(to, tag + template.parse());
        return;
    }
    Player player = iConomy.Server.getPlayer(name);
    String tag = iConomy.Template.color(Template.Node.TAG_MONEY);
    if (iConomy.Server.getPlayer(name) == null)
        return;
    Template template = iConomy.Template;
    template.set(Template.Node.PERSONAL_BALANCE);
    template.add("balance", toString());
    Messaging.send(player, tag + template.parse());
}
Also used : Player(org.bukkit.entity.Player) Template(com.iCo6.util.Template)

Example 4 with Tag

use of com.iCo6.util.nbt.Tag in project Core by iConomy.

the class Give method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "give"))
        throw new InvalidUsage("You do not have permission to do that.");
    String name = arguments.get("name").getStringValue();
    String tag = template.color(Template.Node.TAG_MONEY);
    Double amount;
    if (name.equals("0"))
        throw new InvalidUsage("Missing <white>name<rose>: /money give <name> <amount>");
    if (arguments.get("amount").getStringValue().equals("empty"))
        throw new InvalidUsage("Missing <white>amount<rose>: /money give <name> <amount>");
    try {
        amount = arguments.get("amount").getDoubleValue();
    } catch (NumberFormatException e) {
        throw new InvalidUsage("Invalid <white>amount<rose>, must be double.");
    }
    if (Double.isInfinite(amount) || Double.isNaN(amount))
        throw new InvalidUsage("Invalid <white>amount<rose>, must be double.");
    if (!Accounts.exists(name)) {
        template.set(Template.Node.ERROR_ACCOUNT);
        template.add("name", name);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    Account account = new Account(name);
    account.getHoldings().add(amount);
    template.set(Template.Node.PLAYER_CREDIT);
    template.add("name", name);
    template.add("amount", iConomy.format(amount));
    Messaging.send(sender, tag + template.parse());
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) Account(com.iCo6.system.Account)

Example 5 with Tag

use of com.iCo6.util.nbt.Tag in project Core by iConomy.

the class Money method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (Constants.Nodes.useHoldingsPermission.getBoolean())
        if (!hasPermissions(sender, "money"))
            throw new InvalidUsage("You do not have permission to do that.");
    String name = arguments.get("name").getStringValue();
    String tag = template.color(Template.Node.TAG_MONEY);
    if (name.equals("0")) {
        if (isConsole(sender)) {
            Messaging.send(sender, "`rCannot check money on non-living organism.");
            return false;
        }
        Player player = (Player) sender;
        if (player == null)
            return false;
        Account account = new Account(player.getName());
        account.getHoldings().showBalance(null);
        return false;
    }
    if (!hasPermissions(sender, "money+"))
        throw new InvalidUsage("You do not have permission to do that.");
    if (!Accounts.exists(name)) {
        template.set(Template.Node.ERROR_ACCOUNT);
        template.add("name", name);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    Account account = new Account(name);
    account.getHoldings().showBalance(sender);
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) Account(com.iCo6.system.Account) Player(org.bukkit.entity.Player)

Aggregations

InvalidUsage (com.iCo6.command.exceptions.InvalidUsage)10 Account (com.iCo6.system.Account)6 Player (org.bukkit.entity.Player)5 Template (com.iCo6.util.Template)3 ByteTag (com.iCo6.util.nbt.ByteTag)2 CompoundTag (com.iCo6.util.nbt.CompoundTag)2 ListTag (com.iCo6.util.nbt.ListTag)2 NBTInputStream (com.iCo6.util.nbt.NBTInputStream)2 ShortTag (com.iCo6.util.nbt.ShortTag)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 Holdings (com.iCo6.system.Holdings)1 NBTOutputStream (com.iCo6.util.nbt.NBTOutputStream)1 Tag (com.iCo6.util.nbt.Tag)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ItemStack (org.bukkit.inventory.ItemStack)1