/** Build and return a new {@link ItemStack}. */
  public ItemStack build() {

    ItemStack itemStack = new ItemStack(_materialData.getItemType());
    itemStack.setData(_materialData.clone());
    itemStack.setAmount(_amount);

    if (_durability != null) itemStack.setDurability(_durability);

    if (_display != null) ItemStackUtils.setDisplayName(itemStack, _display);

    if (_lore != null) ItemStackUtils.setLore(itemStack, _lore);

    if (_enchantments != null) {

      for (IEnchantmentLevel wrapper : _enchantments) {
        itemStack.addUnsafeEnchantment(wrapper.getEnchantment(), wrapper.getLevel());
      }
    }

    if (_color != null) {
      ItemStackUtils.setColor(itemStack, _color);
    }

    return itemStack;
  }
 public boolean giveItemDrop(String name, int id, int quant, int data) throws Exception {
   try {
     Player p = getPlayerExact(name);
     ItemStack stack = new ItemStack(id, quant);
     stack.setData(new MaterialData(id, Byte.valueOf(String.valueOf(data)).byteValue()));
     p.getWorld().dropItem(p.getLocation(), stack);
     p.saveData();
     return true;
   } catch (NullPointerException e) {
     return false;
   }
 }
Beispiel #3
0
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

    // Console ausschließen
    if (!(sender instanceof Player)) {
      sender.sendMessage(ChatColor.RED + "You have to be a player!");
      return false;
    }
    // beenden, wenn Argumente gegeben wurden
    if (args.length != 0) {
      return false;
    }

    Player player = (Player) sender;

    if (cmd.getName().equalsIgnoreCase("care-pack")) {

      if (player.hasPermission("CarePack.ever")) {

        PlayerInventory inventory = player.getInventory();
        // Steinschwert
        ItemStack item = new ItemStack(272, 1);
        inventory.addItem(item);
        // 10 Holz
        item.setTypeId(17);
        item.setData(new MaterialData(0));
        item.setAmount(10);
        inventory.addItem(item);
        // 4 Fackeln
        item.setTypeId(50);
        item.setAmount(4);
        inventory.addItem(item);
        // 1 Bett
        item.setTypeId(355);
        item.setAmount(1);
        inventory.addItem(item);
        // 2 Brot
        item.setTypeId(297);
        item.setAmount(2);
        inventory.addItem(item);
        // 1 Beef
        item.setTypeId(364);
        item.setAmount(1);
        inventory.addItem(item);
        return true;

      } else if ((player.getWorld().getTime() < 7000 && player.getWorld().getTime() > 22000)
          || player.getFoodLevel() < 6
          || player.getSaturation() < 6) {

        PlayerInventory inventory = player.getInventory();
        // Steinschwert
        ItemStack item = new ItemStack(272, 1);
        inventory.addItem(item);
        // 10 Holz
        item.setTypeId(17);
        item.setData(new MaterialData(0));
        item.setAmount(10);
        inventory.addItem(item);
        // 4 Fackeln
        item.setTypeId(50);
        item.setAmount(4);
        inventory.addItem(item);
        // 1 Bett
        item.setTypeId(355);
        item.setAmount(1);
        inventory.addItem(item);
        // 2 Brot
        item.setTypeId(297);
        item.setAmount(2);
        inventory.addItem(item);
        // 1 Beef
        item.setTypeId(364);
        item.setAmount(1);
        inventory.addItem(item);
        return true;

      } else {
        player.sendMessage(ChatColor.RED + "You can't use this command now!");
        return true;
      }
    }

    return false;
  }