Search in sources :

Example 6 with ItemStack

use of org.bukkit.inventory.ItemStack in project TotalFreedomMod by TotalFreedom.

the class Command_enchant method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    if (args.length < 1) {
        return false;
    }
    ItemStack item = playerSender.getEquipment().getItemInMainHand();
    if (item == null || item.getType() == Material.AIR) {
        msg("You have to hold an item to enchant it");
        return true;
    }
    if (args[0].equalsIgnoreCase("list")) {
        boolean has_enchantments = false;
        StringBuilder possible_ench = new StringBuilder("Possible enchantments for held item: ");
        for (Enchantment ench : Enchantment.values()) {
            if (ench.canEnchantItem(item)) {
                has_enchantments = true;
                possible_ench.append(ench.getName()).append(", ");
            }
        }
        if (has_enchantments) {
            msg(possible_ench.toString());
        } else {
            msg("The held item has no enchantments.");
        }
    } else if (args[0].equalsIgnoreCase("addall")) {
        for (Enchantment ench : Enchantment.values()) {
            try {
                if (ench.canEnchantItem(item)) {
                    item.addEnchantment(ench, ench.getMaxLevel());
                }
            } catch (Exception ex) {
                msg("Could not add enchantment: " + ench.getName());
            }
        }
        msg("Added all possible enchantments for this item.");
    } else if (args[0].equalsIgnoreCase("reset")) {
        for (Enchantment ench : item.getEnchantments().keySet()) {
            item.removeEnchantment(ench);
        }
        msg("Removed all enchantments.");
    } else {
        if (args.length < 2) {
            return false;
        }
        Enchantment ench = null;
        try {
            ench = Enchantment.getByName(args[1]);
        } catch (Exception ex) {
        }
        if (ench == null) {
            msg(args[1] + " is an invalid enchantment for the held item. Type \"/enchant list\" for valid enchantments for this item.");
            return true;
        }
        if (args[0].equalsIgnoreCase("add")) {
            if (ench.canEnchantItem(item)) {
                item.addEnchantment(ench, ench.getMaxLevel());
                msg("Added enchantment: " + ench.getName());
            } else {
                msg("Can't use this enchantment on held item.");
            }
        } else if (args[0].equals("remove")) {
            item.removeEnchantment(ench);
            msg("Removed enchantment: " + ench.getName());
        }
    }
    return true;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment)

Example 7 with ItemStack

use of org.bukkit.inventory.ItemStack in project TotalFreedomMod by TotalFreedom.

the class Command_cake method run.

@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
    final StringBuilder output = new StringBuilder();
    final String[] words = CAKE_LYRICS.split(" ");
    for (final String word : words) {
        output.append(ChatColor.COLOR_CHAR).append(Integer.toHexString(1 + random.nextInt(14))).append(word).append(" ");
    }
    final ItemStack heldItem = new ItemStack(Material.CAKE);
    final ItemMeta heldItemMeta = heldItem.getItemMeta();
    heldItemMeta.setDisplayName((new StringBuilder()).append(ChatColor.WHITE).append("The ").append(ChatColor.DARK_GRAY).append("Lie").toString());
    heldItem.setItemMeta(heldItemMeta);
    for (final Player player : server.getOnlinePlayers()) {
        final int firstEmpty = player.getInventory().firstEmpty();
        if (firstEmpty >= 0) {
            player.getInventory().setItem(firstEmpty, heldItem);
        }
        player.awardAchievement(Achievement.BAKE_CAKE);
    }
    FUtil.bcastMsg(output.toString());
    return true;
}
Also used : Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 8 with ItemStack

use of org.bukkit.inventory.ItemStack in project GameCore by Warvale.

the class ClassSelect method openGUI.

private void openGUI(Player player) {
    inv = Bukkit.createInventory(null, 45, ChatColor.DARK_GRAY + "Select a class: ");
    Integer inventoryIndex = 0;
    for (Map.Entry<String, Class> clazzSet : ClassManager.classes.entrySet()) {
        Class clazz = clazzSet.getValue();
        ItemStack classStack = clazz.getItem();
        ItemMeta classMeta = classStack.getItemMeta();
        List<String> desc = new LinkedList<>(clazz.getDescription());
        desc.add(0, ChatColor.translateAlternateColorCodes('&', "&7PRICE: &e" + clazz.getPrice()));
        desc.add(1, ChatColor.GRAY + "ABILITY: " + ChatColor.YELLOW + clazz.getAbility());
        classMeta.setLore(desc);
        classMeta.setDisplayName(ChatColor.AQUA + clazz.getName());
        classStack.setItemMeta(classMeta);
        inv.setItem(inventoryIndex, classStack);
        slots.put(inventoryIndex, clazz);
        inventoryIndex = inventoryIndex + 1;
    }
    player.openInventory(inv);
}
Also used : Class(net.warvale.core.classes.Class) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 9 with ItemStack

use of org.bukkit.inventory.ItemStack in project GameCore by Warvale.

the class Preferences method onPlayerInteract.

@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
    Action a = event.getAction();
    ItemStack is = event.getItem();
    if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
        return;
    if (is.getType() == Material.REDSTONE_COMPARATOR)
        tsGUI(event.getPlayer());
    if (Main.getTeams().getSpectatorTeam().getEntries().contains(event.getPlayer().getName())) {
        event.getPlayer().playSound(event.getPlayer().getLocation(), Sound.BLOCK_ENDERCHEST_OPEN, 1, 1);
    }
}
Also used : Action(org.bukkit.event.block.Action) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 10 with ItemStack

use of org.bukkit.inventory.ItemStack in project GameCore by Warvale.

the class TeamSelect method tsGUI.

private void tsGUI(Player player) {
    inv = Bukkit.createInventory(null, 9, ChatColor.DARK_GRAY + "Select a team:");
    Wool wool_red = new Wool(DyeColor.RED);
    ItemStack itemtsred = wool_red.toItemStack(1);
    ItemMeta itemtsredmeta = itemtsred.getItemMeta();
    itemtsredmeta.setDisplayName(ChatColor.RED + "Red");
    itemtsred.setItemMeta(itemtsredmeta);
    Wool wool_cyan = new Wool(DyeColor.CYAN);
    ItemStack itemtscyan = wool_cyan.toItemStack(1);
    ItemMeta itemtscyanmeta = itemtscyan.getItemMeta();
    itemtscyanmeta.setDisplayName(ChatColor.DARK_AQUA + "Blue");
    itemtscyan.setItemMeta(itemtscyanmeta);
    ItemStack closemenu = new ItemStack(Material.BARRIER, 1);
    ItemMeta closemenumeta = closemenu.getItemMeta();
    closemenumeta.setDisplayName(ChatColor.DARK_RED + "Close selector");
    closemenu.setItemMeta(closemenumeta);
    inv.setItem(3, itemtsred);
    inv.setItem(4, closemenu);
    inv.setItem(5, itemtscyan);
    player.openInventory(inv);
}
Also used : Wool(org.bukkit.material.Wool) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)1282 Player (org.bukkit.entity.Player)262 EventHandler (org.bukkit.event.EventHandler)183 ItemMeta (org.bukkit.inventory.meta.ItemMeta)167 ArrayList (java.util.ArrayList)130 Inventory (org.bukkit.inventory.Inventory)115 Location (org.bukkit.Location)88 Material (org.bukkit.Material)87 PlayerInventory (org.bukkit.inventory.PlayerInventory)84 Entity (org.bukkit.entity.Entity)63 Block (org.bukkit.block.Block)52 TagCompound (de.keyle.knbt.TagCompound)47 Map (java.util.Map)44 LivingEntity (org.bukkit.entity.LivingEntity)44 HashMap (java.util.HashMap)40 Mage (com.elmakers.mine.bukkit.api.magic.Mage)39 Enchantment (org.bukkit.enchantments.Enchantment)38 SkullMeta (org.bukkit.inventory.meta.SkullMeta)38 Vector (org.bukkit.util.Vector)35 Test (org.junit.Test)32