Search in sources :

Example 6 with Tag

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

the class Purge method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "purge"))
        throw new InvalidUsage("You do not have permission to do that.");
    Accounts.purge();
    String tag = template.color(Template.Node.TAG_MONEY);
    template.set(Template.Node.ACCOUNTS_PURGE);
    Messaging.send(sender, tag + template.parse());
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage)

Example 7 with Tag

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

the class Remove method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "remove"))
        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"))
        throw new InvalidUsage("Missing <white>name<rose>: /money remove <name>");
    if (!Accounts.exists(name)) {
        template.set(Template.Node.ERROR_ACCOUNT);
        template.add("name", name);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    if (!Accounts.remove(name)) {
        template.set(Template.Node.ERROR_CREATE);
        template.add("name", name);
        Messaging.send(sender, tag + template.parse());
        return false;
    }
    template.set(Template.Node.ACCOUNTS_REMOVE);
    template.add("name", name);
    Messaging.send(sender, tag + template.parse());
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage)

Example 8 with Tag

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

the class InventoryDB method readInventory.

private ItemStack[] readInventory(String name) {
    try {
        NBTInputStream in = new NBTInputStream(new FileInputStream(new File(dataDir, name + ".dat")));
        CompoundTag tag = (CompoundTag) in.readTag();
        in.close();
        ListTag inventory = (ListTag) tag.getValue().get("Inventory");
        ItemStack[] stacks = new ItemStack[40];
        for (int i = 0; i < inventory.getValue().size(); ++i) {
            CompoundTag item = (CompoundTag) inventory.getValue().get(i);
            byte count = ((ByteTag) item.getValue().get("Count")).getValue();
            byte slot = ((ByteTag) item.getValue().get("Slot")).getValue();
            short damage = ((ShortTag) item.getValue().get("Damage")).getValue();
            short id = ((ShortTag) item.getValue().get("id")).getValue();
            stacks[slot] = new ItemStack(id, count, damage);
        }
        return stacks;
    } catch (IOException ex) {
        iConomy.Server.getLogger().log(Level.WARNING, "[iCo/InvDB] error reading inventory {0}: {1}", new Object[] { name, ex.getMessage() });
        return null;
    }
}
Also used : IOException(java.io.IOException) ListTag(com.iCo6.util.nbt.ListTag) FileInputStream(java.io.FileInputStream) ShortTag(com.iCo6.util.nbt.ShortTag) ByteTag(com.iCo6.util.nbt.ByteTag) NBTInputStream(com.iCo6.util.nbt.NBTInputStream) ItemStack(org.bukkit.inventory.ItemStack) File(java.io.File) CompoundTag(com.iCo6.util.nbt.CompoundTag)

Example 9 with Tag

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

the class InventoryDB method writeInventory.

private void writeInventory(String name, ItemStack[] stacks) {
    try {
        NBTInputStream in = new NBTInputStream(new FileInputStream(new File(dataDir, name + ".dat")));
        CompoundTag tag = (CompoundTag) in.readTag();
        in.close();
        ArrayList tagList = new ArrayList<Tag>();
        for (int i = 0; i < stacks.length; ++i) {
            if (stacks[i] == null)
                continue;
            ByteTag count = new ByteTag("Count", (byte) stacks[i].getAmount());
            ByteTag slot = new ByteTag("Slot", (byte) i);
            ShortTag damage = new ShortTag("Damage", stacks[i].getDurability());
            ShortTag id = new ShortTag("id", (short) stacks[i].getTypeId());
            HashMap<String, Tag> tagMap = new HashMap<String, Tag>();
            tagMap.put("Count", count);
            tagMap.put("Slot", slot);
            tagMap.put("Damage", damage);
            tagMap.put("id", id);
            tagList.add(new CompoundTag("", tagMap));
        }
        ListTag inventory = new ListTag("Inventory", CompoundTag.class, tagList);
        HashMap<String, Tag> tagCompound = new HashMap<String, Tag>(tag.getValue());
        tagCompound.put("Inventory", inventory);
        tag = new CompoundTag("Player", tagCompound);
        NBTOutputStream out = new NBTOutputStream(new FileOutputStream(new File(dataDir, name + ".dat")));
        out.writeTag(tag);
        out.close();
    } catch (IOException ex) {
        iConomy.Server.getLogger().log(Level.WARNING, "[iCo/InvDB] error writing inventory {0}: {1}", new Object[] { name, ex.getMessage() });
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ListTag(com.iCo6.util.nbt.ListTag) NBTOutputStream(com.iCo6.util.nbt.NBTOutputStream) FileInputStream(java.io.FileInputStream) ShortTag(com.iCo6.util.nbt.ShortTag) ByteTag(com.iCo6.util.nbt.ByteTag) FileOutputStream(java.io.FileOutputStream) NBTInputStream(com.iCo6.util.nbt.NBTInputStream) ShortTag(com.iCo6.util.nbt.ShortTag) Tag(com.iCo6.util.nbt.Tag) ListTag(com.iCo6.util.nbt.ListTag) CompoundTag(com.iCo6.util.nbt.CompoundTag) ByteTag(com.iCo6.util.nbt.ByteTag) File(java.io.File) CompoundTag(com.iCo6.util.nbt.CompoundTag)

Example 10 with Tag

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

the class Set method perform.

@Override
public boolean perform(CommandSender sender, LinkedHashMap<String, Argument> arguments) throws InvalidUsage {
    if (!hasPermissions(sender, "set"))
        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 set <name> <amount>");
    if (arguments.get("amount").getStringValue().equals("empty"))
        throw new InvalidUsage("Missing <white>amount<rose>: /money set <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().setBalance(amount);
    template.set(Template.Node.PLAYER_SET);
    template.add("name", name);
    template.add("amount", account.getHoldings().toString());
    Messaging.send(sender, tag + template.parse());
    return false;
}
Also used : InvalidUsage(com.iCo6.command.exceptions.InvalidUsage) Account(com.iCo6.system.Account)

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