Package net.canarymod.api.inventory

Examples of net.canarymod.api.inventory.Item


        }
        int amount = 1;
        if (args[args.length - 2].matches("\\d+")) {
            amount = Integer.parseInt(args[args.length - 2]);
        }
        Item item = Canary.factory().getItemFactory().newItem(args[1]);
        if (item == null) {
            caller.notice(Translator.translateAndFormat("give invalid itemtype", args[1]));
            return;
        }
        item.setAmount(amount);
        Player target = Canary.getServer().matchPlayer(args[args.length - 1]);
        if (target == null) {
            caller.notice(Translator.translateAndFormat("unknown player", args[args.length - 1]));
            return;
        }
        target.giveItem(item);
        target.message(Colors.YELLOW + Translator.translateAndFormat("give received", item.getType().getDisplayName()));
        caller.notice(Translator.translateAndFormat("give success other", target.getName()));

    }
View Full Code Here


    }

    private void player(Player player, String[] args) {
        // Give to player
        if (args.length == 2) {
            Item item = makeItem(args[1], 1);
            if (item == null) {
                player.notice(Translator.translateAndFormat("give invalid itemtype", args[1]));
                return;
            }
            player.giveItem(item);
            player.message(Colors.YELLOW + Translator.translate("give success"));
        }
        // Give to player or other
        else if (args.length == 3) {
            if (args[2].matches("\\d+")) {
                Item item = makeItem(args[1], Integer.parseInt(args[2]));
                if (item == null) {
                    player.notice(Translator.translateAndFormat("give invalid itemtype", args[1]));
                    return;
                }
                player.giveItem(item);
                player.message(Colors.YELLOW + Translator.translate("give success"));
            }
            else {
                if (!player.hasPermission("canary.command.give.other")) {
                    player.notice(Translator.translate("give failed"));
                    return;
                }
                Player target = Canary.getServer().matchPlayer(args[2]);
                if (target == null) {
                    player.notice(Translator.translateAndFormat("unknown player", args[2]));
                    return;
                }
                Item item = makeItem(args[1], 1);
                if (item == null) { // NULL CHECK!
                    player.notice(Translator.translateAndFormat("give invalid itemtype", args[1]));
                    return;
                }
                target.giveItem(item);
                target.message(Colors.YELLOW + Translator.translateAndFormat("give received", item.getType().getDisplayName()));
                player.notice(Translator.translateAndFormat("give success other", target.getName()));
            }
        }
        // Give to other
        else if (args.length == 4) {
            if (!player.hasPermission("canary.command.give.other")) {
                player.notice(Translator.translate("give failed"));
                return;
            }
            int amount = 1;
            if (args[2].matches("\\d+")) {
                amount = Integer.parseInt(args[2]);
            }
            Item item = makeItem(args[1], amount);
            if (item == null) {
                player.notice(Translator.translateAndFormat("give invalid itemtype", args[1]));
                return;
            }
            Player target = Canary.getServer().matchPlayer(args[3]);
            if (target == null) {
                player.notice(Translator.translateAndFormat("unknown player", args[3]));
                return;
            }
            target.giveItem(item);
            target.message(Colors.YELLOW + Translator.translateAndFormat("give received", item.getType().getDisplayName()));
            player.notice(Translator.translateAndFormat("give success other", target.getName()));
        }
    }
View Full Code Here

     *         the amount to create
     *
     * @return the new {@link Item}
     */
    private Item makeItem(String input, int amount) {
        Item i = Canary.factory().getItemFactory().newItem(input);
        if (i == null) {
            return null;
        }
        i.setAmount(amount);
        return i;
    }
View Full Code Here

        }
        RecipeRow theRow = (RecipeRow) obj;
        Item[] rowItems = theRow.getItems();
        if (rowItems.length == items.length) {
            for (int index = 0; index < items.length; index++) {
                Item rowItem = rowItems[index];
                Item itemsItem = items[index];
                if (rowItem == null && itemsItem == null) {
                    continue;
                }
                else if ((rowItem == null && itemsItem != null) || rowItem != null && itemsItem == null) {
                    return false;
                }
                else if (rowItem.getType() != itemsItem.getType()) {
                    return false;
                }
            }
            return true;
        }
View Full Code Here

        ListTag<BaseTag> explosions = fireworkRocket.getDataTag().getCompoundTag("Fireworks").getListTag("Explosions");
        if (!explosions.isEmpty()) {
            ArrayList<Item> stars = new ArrayList<Item>();
            for (BaseTag explosion : explosions) {
                if (explosion instanceof CompoundTag) {
                    Item fireworkStar = fireworkStarBase.clone();
                    fireworkStar.getDataTag().put("Explosion", explosion);
                    stars.add(fireworkStar);
                }
            }
            return stars.toArray(new Item[stars.size()]);
        }
View Full Code Here

TOP

Related Classes of net.canarymod.api.inventory.Item

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.