Package org.bukkit.inventory

Examples of org.bukkit.inventory.PlayerInventory


    return true;
  }
 
  private static void smeltItems(Player player, int amount){
    ItemStack itemHand = player.getItemInHand();
    PlayerInventory inv = player.getInventory();
   
    // Get the output if that item was smelted
    ItemStack result = null;
    Iterator<Recipe> iter = Bukkit.recipeIterator();
    while (iter.hasNext()){
      Recipe recipe = iter.next();
      if (recipe instanceof FurnaceRecipe){
        if (((FurnaceRecipe) recipe).getInput().getType() == player.getItemInHand().getType()){
          result = recipe.getResult();
        }
      }
    }
   
    if (result != null){
      // Check that the player has the correct amount of items
      if (inv.contains(itemHand.getTypeId())){
        // Remove the item using the type id, amount and durability (damage value)
        inv.removeItem(new ItemStack(itemHand.getTypeId(), amount, itemHand.getDurability()));
        inv.addItem(new ItemStack(result.getTypeId(), amount));
        LogHelper.showInfo("smeltSuccess#####[ " + Utils.userFriendlyNames(itemHand.getType().name()), player, ChatColor.GREEN);
      } else {
        LogHelper.showInfo("smeltNotEnough#####[ " + Utils.userFriendlyNames(itemHand.getType().name()), player, ChatColor.RED);
      }
    } else {
View Full Code Here


    if(PlayerHelper.checkIsPlayer(sender)) {
   
      // Variables
      Player player = (Player)sender;
      ItemStack hand = player.getItemInHand();
      PlayerInventory inv = player.getInventory();
      ItemStack head = inv.getHelmet();
      int handAmount = hand.getAmount();
      Material handID = Material.getMaterial(hand.getTypeId());
      ItemStack forHead = new ItemStack(handID, 1);
     
      // Check that head is empty
      if(head != null) {
        LogHelper.showWarning("hatHeadFull", sender);
        return true;
      }

      // Make sure the block going onto the players head is a block
      if(!forHead.getType().isBlock()){
        LogHelper.showInfo("hatNotBlock", sender, ChatColor.RED);
        return true;
      }

      // Check for item in hand
      if(hand.getTypeId() == 0) {
        LogHelper.showWarning("hatHandEmpty", sender);
        return true;
      }
     
      // Get new hand amount
      if(handAmount > 1) {
        int handAmountNEW = handAmount - 1;
        hand.setAmount(handAmountNEW);
      } else {
        inv.setItemInHand(null);
      }
     
      // Check for anything that has a damage value (durability)
      if (hand.getDurability() != 0) {
              short handDurability = hand.getDurability();
              forHead = new ItemStack(handID, 1, handDurability);
          }
     
      // HELMET THEM UP
      inv.setHelmet(forHead);
     
      // Send message
      LogHelper.showInfo("hatNew", sender);
     
      // done.
View Full Code Here

    }
  }

  public void resetInventory(Team team, Player player, Map<Integer, ItemStack> loadout) {
    // Reset inventory to loadout
    PlayerInventory playerInv = player.getInventory();
    playerInv.clear();
    playerInv.clear(playerInv.getSize() + 0);
    playerInv.clear(playerInv.getSize() + 1);
    playerInv.clear(playerInv.getSize() + 2);
    playerInv.clear(playerInv.getSize() + 3); // helmet/blockHead
    for (Integer slot : loadout.keySet()) {
      if (slot == 100) {
        playerInv.setBoots(loadout.get(slot).clone());
      } else if (slot == 101) {
        playerInv.setLeggings(loadout.get(slot).clone());
      } else if (slot == 102) {
        playerInv.setChestplate(loadout.get(slot).clone());
      } else if (slot == 103) {
        playerInv.setHelmet(loadout.get(slot).clone());
      } else {
        ItemStack item = loadout.get(slot);
        if (item != null) {
          playerInv.addItem(item.clone());
        }
      }
    }
    if (this.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
      playerInv.setHelmet(team.getKind().getHat());
    }
  }
View Full Code Here

  public boolean hasPlayerState(String playerName) {
    return this.playerStates.containsKey(playerName);
  }

  public void keepPlayerState(Player player) {
    PlayerInventory inventory = player.getInventory();
    ItemStack[] contents = inventory.getContents();
   
    String playerTitle = player.getName();
    if (War.war.isSpoutServer()) {
      playerTitle = SpoutManager.getPlayer(player).getTitle();
    }
   
    this.playerStates.put(
        player.getName(),
        new PlayerState(player.getGameMode(), contents, inventory
            .getHelmet(), inventory.getChestplate(), inventory
            .getLeggings(), inventory.getBoots(), player
            .getHealth(), player.getExhaustion(), player
            .getSaturation(), player.getFoodLevel(), player
            .getActivePotionEffects(), playerTitle, player
            .getLevel(), player.getExp(), player.getAllowFlight()));
  }
View Full Code Here

            .getLevel(), player.getExp(), player.getAllowFlight()));
  }

  public void restorePlayerState(Player player) {
    PlayerState originalState = this.playerStates.remove(player.getName());
    PlayerInventory playerInv = player.getInventory();
    if (originalState != null) {
      // prevent item hacking thru CRAFTING personal inventory slots
      this.preventItemHackingThroughOpenedInventory(player);
     
      this.playerInvFromInventoryStash(playerInv, originalState);
View Full Code Here

      return;
    }
    for (Warzone zone : War.war.getWarzones()) {
      for (Team team : zone.getTeams()) {
        for (Player player : team.getPlayers()) {
          PlayerInventory playerInv = player.getInventory();
          Material teamBlockMaterial;
         
          if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
            teamBlockMaterial = team.getKind().getMaterial();
            // 1) Replace missing block head
            if (playerInv.getHelmet() == null || playerInv.getHelmet().getType() != Material.LEATHER_HELMET) {
              playerInv.setHelmet(team.getKind().getHat());
            }
           
            // 2) Get rid of extra blocks in inventory: only keep one
            HashMap<Integer, ? extends ItemStack> blocks = playerInv.all(teamBlockMaterial);
            if (blocks.size() > 1 || (blocks.size() == 1 && blocks.get(blocks.keySet().iterator().next()).getAmount() > 1)) {
              int i = 0;
              int removed = 0;
              for (ItemStack item : playerInv.getContents()) {
                // remove only same colored wool
                if (item != null && item.getType() == teamBlockMaterial && item.getData() == team.getKind().getBlockData()) {
                  playerInv.clear(i);
                  removed++;
                }
                i++;
              }
             
              int firstEmpty = playerInv.firstEmpty();
              if (firstEmpty > 0) {
                playerInv.setItem(firstEmpty, team.getKind().getBlockHead());
              }
             
              if (removed > 1) {
                War.war.badMsg(player, "All that " + team.getName() + " wool must have been heavy!");
              }
View Full Code Here

    /**
     * Clear a player's inventory completely.
     * @param p a player
     */
    public void clearInventory(Player p) {
        PlayerInventory inv = p.getInventory();
        inv.clear();
        inv.setHelmet(null);
        inv.setChestplate(null);
        inv.setLeggings(null);
        inv.setBoots(null);
        InventoryView view = p.getOpenInventory();
        if (view != null) {
            view.setCursor(null);
            Inventory i = view.getTopInventory();
            if (i != null) {
View Full Code Here

    }

    private void repairArmor(Player p) {
        ArenaClass ac = arena.getArenaPlayer(p).getArenaClass();
        if (ac != null && ac.hasUnbreakableArmor()) {
            PlayerInventory inv = p.getInventory();
            repair(inv.getHelmet());
            repair(inv.getChestplate());
            repair(inv.getLeggings());
            repair(inv.getBoots());
        }
    }
View Full Code Here

     * appropriate slots. If any specific armor slots are specified, they
     * will overwrite any items in the armor list.
     * @param p a player
     */
    public void grantItems(Player p) {
        PlayerInventory inv = p.getInventory();

        // Fork over the items.
        for (ItemStack stack : items) {
            inv.addItem(stack);
        }
       
        // Check for legacy armor-node items
        if (!armor.isEmpty()) {
            for (ItemStack piece : armor) {
                ArmorType type = ArmorType.getType(piece);
                if (type == null) continue;
               
                switch (type) {
                    case HELMET:
                        inv.setHelmet(piece);
                        break;
                    case CHESTPLATE:
                        inv.setChestplate(piece);
                        break;
                    case LEGGINGS:
                        inv.setLeggings(piece);
                        break;
                    case BOOTS:
                        inv.setBoots(piece);
                        break;
                    default:
                        break;
                }
            }
        }
       
        // Check type specifics.
        if (helmet     != null) inv.setHelmet(helmet);
        if (chestplate != null) inv.setChestplate(chestplate);
        if (leggings   != null) inv.setLeggings(leggings);
        if (boots      != null) inv.setBoots(boots);
    }
View Full Code Here

      if (!b.hasTitle() || !b.hasAuthor())
        return;
      if (b.getTitle().contains("Identity Tome")
          && findColor(b.getAuthor()).equals(ChatColor.MAGIC)) {
        Player p = e.getPlayer();
        PlayerInventory pi = p.getInventory();
        p.updateInventory();
        Iterator<ItemStack> itis = pi.iterator();
        while (itis.hasNext()) {
          ItemStack tool = itis.next();
          if ((tool == null)
              || !plugin.getDropAPI().canBeItem(tool.getType())) {
            continue;
          }
          ItemMeta meta;
          if (tool.hasItemMeta())
            meta = tool.getItemMeta();
          else
            meta = plugin.getServer().getItemFactory()
                .getItemMeta(tool.getType());
          String name;
          if (meta.hasDisplayName())
            name = meta.getDisplayName();
          else
            name = tool.getType().name();
          if ((ChatColor.getLastColors(name) == null || (!ChatColor
              .getLastColors(name).equalsIgnoreCase(
                  ChatColor.MAGIC.name()) && !ChatColor
              .getLastColors(name).equalsIgnoreCase(
                  ChatColor.MAGIC.toString()))
              && (!name.contains(ChatColor.MAGIC.name()) && !name
                  .contains(ChatColor.MAGIC.toString())))) {
            continue;
          }
          IdentifyItemEvent iie = new IdentifyItemEvent(tool);
          plugin.getServer().getPluginManager().callEvent(iie);
          if (iie.isCancelled()) {
            p.sendMessage(ChatColor.RED
                + "You are unable to identify right now.");
            p.closeInventory();
            e.setUseItemInHand(Result.DENY);
            e.setCancelled(true);
            return;
          }
          pi.setItemInHand(null);
          ItemStack item = plugin.getDropAPI().getItem(tool);
          while ((item == null)
              || !item.hasItemMeta()
              || !item.getItemMeta().hasDisplayName()
              || item.getItemMeta().getDisplayName()
                  .contains(ChatColor.MAGIC.toString())) {
            item = plugin.getDropAPI().getItem(tool);
          }
          pi.removeItem(tool);
          pi.addItem(item);
          p.sendMessage(ChatColor.GREEN
              + "You have identified an item!");
          p.updateInventory();
          e.setUseItemInHand(Result.DENY);
          e.setCancelled(true);
View Full Code Here

TOP

Related Classes of org.bukkit.inventory.PlayerInventory

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.