Esempio n. 1
0
  /**
   * Gets the missing items in newInv
   *
   * @param oldInv The compressed inventory to check against
   * @param newInv The compressed inventory to check for changes
   * @return Returns the missing items from newInv, and newly added items [missing, new]
   */
  public static List<ItemStack>[] getDifference(List<ItemStack> oldInv, List<ItemStack> newInv) {
    ArrayList<ItemStack> removedItems = new ArrayList<>();
    ArrayList<ItemStack> addedItems = new ArrayList<>();

    for (ItemStack oldItem : oldInv) {

      ItemStack newItem = findSimilarItemStack(newInv, oldItem);

      if (newItem != null) {

        int amountDif = oldItem.getAmount() - newItem.getAmount();

        if (amountDif > 0) {
          oldItem.setAmount(amountDif);
          removedItems.add(oldItem);
        } else if (amountDif < 0) {
          oldItem.setAmount(Math.abs(amountDif));
          addedItems.add(oldItem);
        }

        newInv.remove(newItem);

      } else {
        removedItems.add(oldItem);
      }
    }

    for (ItemStack newItem : newInv) {
      addedItems.add(newItem);
    }

    return (List<ItemStack>[]) new ArrayList<?>[] {removedItems, addedItems};
  }
Esempio n. 2
0
  @Override
  public boolean finalizeTransaction(TransactionInfo info) {
    String stock = info.getStock().name().toLowerCase();
    Player player = info.getPlayerParticipant();
    int amount = info.getAmount();

    boolean result = false;
    int endAmount = amount * this.amount;
    ItemStack clone = is.clone();
    clone.setAmount(endAmount);

    if (stock == "sell") {
      ItemStack[] contents = player.getInventory().getContents();
      for (int i = 0; i < contents.length && endAmount > 0; ++i) {
        ItemStack nItem = contents[i];
        if (nItem != null && nItem.isSimilar(clone)) {
          int diff = endAmount - nItem.getAmount();
          if (diff < 0) nItem.setAmount(-diff);
          else player.getInventory().setItem(i, null);
          endAmount = diff;
        }
      }
      result = true;
    } else if (stock == "buy") {
      player.getInventory().addItem(clone);
      result = true;
    }
    return result;
  }
 @Override
 protected void saveEditor(Inventory inventory, Player player) {
   for (int i = 0; i < 8; i++) {
     ItemStack item = inventory.getItem(i);
     if (item != null && item.getType() != Material.AIR) {
       ItemStack cost1 = null, cost2 = null;
       ItemStack item1 = inventory.getItem(i + 9);
       ItemStack item2 = inventory.getItem(i + 18);
       if (item1 != null && item1.getType() != Material.AIR) {
         cost1 = item1;
         if (item2 != null && item2.getType() != Material.AIR) {
           cost2 = item2;
         }
       } else if (item2 != null && item2.getType() != Material.AIR) {
         cost1 = item2;
       }
       if (cost1 != null) {
         Cost cost = new Cost();
         cost.amount = item.getAmount();
         cost.item1 = cost1;
         cost.item2 = cost2;
         ItemStack saleItem = item.clone();
         saleItem.setAmount(1);
         ((TradingPlayerShopkeeper) shopkeeper).costs.put(saleItem, cost);
       } else {
         ItemStack saleItem = item.clone();
         saleItem.setAmount(1);
         ((TradingPlayerShopkeeper) shopkeeper).costs.remove(saleItem);
       }
     }
   }
   ((TradingPlayerShopkeeper) shopkeeper).clickedItem = null;
 }
Esempio n. 4
0
 public ItemStack[] getCalculatedItem(Voter voter) {
   ItemStack item = this.clone();
   if (!hasVariableAmount()) return new ItemStack[] {item};
   int sum = this.getCalculatedAmount(voter);
   if (sum < 1) {
     item.setAmount(1);
   } else {
     if (VoteRoulette.HAS_ITEM_LIMIT) {
       if (sum > VoteRoulette.VARIABLE_ITEM_LIMIT) {
         item.setAmount(VoteRoulette.VARIABLE_ITEM_LIMIT);
         return new ItemStack[] {item};
       }
     }
     if (sum > 64) {
       List<ItemStack> items = new ArrayList<ItemStack>();
       while (sum > 64) {
         ItemStack newItem = item.clone();
         newItem.setAmount(64);
         items.add(newItem);
         sum -= 64;
       }
       if (sum > 0) {
         item.setAmount(sum);
         items.add(item);
       }
       ItemStack[] array = new ItemStack[items.size()];
       items.toArray(array);
       return array;
     } else {
       item.setAmount(sum);
     }
   }
   return new ItemStack[] {item};
 }
 @Override
 protected void onInventoryClick(InventoryClickEvent event, Player player) {
   event.setCancelled(true);
   final int slot = event.getRawSlot();
   if (slot >= 0 && slot <= 7) {
     // handle changing sell stack size
     ItemStack item = event.getCurrentItem();
     if (item != null && item.getType() != Material.AIR) {
       int amount = item.getAmount();
       amount = this.getNewAmountAfterEditorClick(event, amount);
       if (amount <= 0) amount = 1;
       if (amount > item.getMaxStackSize()) amount = item.getMaxStackSize();
       item.setAmount(amount);
     }
   } else if ((slot >= 9 && slot <= 16) || (slot >= 18 && slot <= 25)) {
     if (((TradingPlayerShopkeeper) shopkeeper).clickedItem != null) {
       // placing item
       final Inventory inventory = event.getInventory();
       Bukkit.getScheduler()
           .runTaskLater(
               ShopkeepersPlugin.getInstance(),
               new Runnable() {
                 public void run() {
                   inventory.setItem(slot, ((TradingPlayerShopkeeper) shopkeeper).clickedItem);
                   ((TradingPlayerShopkeeper) shopkeeper).clickedItem = null;
                 }
               },
               1);
     } else {
       // changing stack size
       ItemStack item = event.getCurrentItem();
       if (item != null && item.getType() != Material.AIR) {
         int amount = item.getAmount();
         amount = this.getNewAmountAfterEditorClick(event, amount);
         if (amount <= 0) {
           event.getInventory().setItem(slot, null);
         } else {
           if (amount > item.getMaxStackSize()) amount = item.getMaxStackSize();
           item.setAmount(amount);
         }
       }
     }
   } else if (slot >= 27) {
     // clicking in player inventory
     if (event.isShiftClick() || !event.isLeftClick()) {
       return;
     }
     ItemStack cursor = event.getCursor();
     if (cursor != null && cursor.getType() != Material.AIR) {
       return;
     }
     ItemStack current = event.getCurrentItem();
     if (current != null && current.getType() != Material.AIR) {
       ((TradingPlayerShopkeeper) shopkeeper).clickedItem = current.clone();
       ((TradingPlayerShopkeeper) shopkeeper).clickedItem.setAmount(1);
     }
   } else {
     super.onInventoryClick(event, player);
   }
 }
Esempio n. 6
0
  @Override
  public void onTick() {

    // make sure theres only one of an item in any slot
    SpoutItemStack nItem = new SpoutItemStack(needleSlot.getItem());
    if (nItem.getAmount() > 1) {

      ItemStack tossMe = nItem.clone();
      tossMe.setAmount(nItem.getAmount() - 1);
      tossItem(tossMe);

      nItem.setAmount(1);
      needleSlot.setItem(nItem);
    }

    SpoutItemStack rItem = new SpoutItemStack(recordSlot.getItem());
    if (rItem.getAmount() > 1) {

      ItemStack tossMe = rItem.clone();
      tossMe.setAmount(rItem.getAmount() - 1);
      tossItem(rItem);

      rItem.setAmount(1);
      recordSlot.setItem(rItem);
    }

    updatePlayerSlots();
    syncDataSlots();

    super.onTick();
  }
Esempio n. 7
0
  /*
   * (non-Javadoc)
   *
   * @see org.saga.buildings.signs.BuildingSign#onRightClick(org.saga.player.SagaPlayer)
   */
  @Override
  protected void onRightClick(SagaPlayer sagaPlayer) {

    // Create item:
    ItemStack item = this.item.createItem();

    // Available goods:
    if (stored < 1.0) {
      sagaPlayer.message(EconomyMessages.insufItems(item.getType()));
      return;
    }

    // Trim amount based on goods:
    if (item.getAmount() > stored) item.setAmount(stored.intValue());

    // Trim amount based on coins:
    double coins = EconomyDependency.getCoins(sagaPlayer);
    if (item.getAmount() * price > coins) item.setAmount((int) (coins / price));

    // Available coins:
    if (item.getAmount() < 1) {
      sagaPlayer.message(EconomyMessages.insufCoins());
      return;
    }

    // Take item:
    if (item.getAmount() < 1) {
      sagaPlayer.message(EconomyMessages.insufItems(item.getType()));
      return;
    }
    stored -= item.getAmount();

    // Finish transaction:
    Double cost = price * item.getAmount();
    EconomyDependency.removeCoins(sagaPlayer, cost);
    getBuilding().getSettlement().payCoins(cost);
    sagaPlayer.addItem(item);

    // Inform:
    sagaPlayer.message(EconomyMessages.bought(item.getType(), item.getAmount(), price));

    // Statistics:
    StatisticsManager.manager()
        .addBuy(sagaPlayer, item.getType(), item.getAmount(), price * item.getAmount());

    // Update sign:
    refresh();
  }
 @Override
 public List<ItemStack[]> getRecipes() {
   List<ItemStack[]> recipes = new ArrayList<ItemStack[]>();
   Map<ItemStack, Integer> chestItems = this.getItemsFromChest();
   for (ItemStack item : costs.keySet()) {
     if (chestItems.containsKey(item)) {
       Cost cost = costs.get(item);
       int chestAmt = chestItems.get(item);
       if (chestAmt >= cost.amount) {
         ItemStack[] recipe = new ItemStack[3];
         int slot = 0;
         if (cost.item1 != null
             && cost.item1.getType() != Material.AIR
             && cost.item1.getAmount() > 0) {
           recipe[slot++] = cost.item1;
         }
         if (cost.item2 != null
             && cost.item2.getType() != Material.AIR
             && cost.item2.getAmount() > 0) {
           recipe[slot] = cost.item2;
         }
         ItemStack saleItem = item.clone();
         saleItem.setAmount(cost.amount);
         recipe[2] = saleItem;
         recipes.add(recipe);
       }
     }
   }
   return recipes;
 }
Esempio n. 9
0
  /**
   * parse through dat to create a new item with enchantments, quantity, and damage value
   *
   * @param cfg to parse through
   * @return the new ItemStack
   */
  private ItemStack parseItem(ConfigurationSection cfg) {
    Map<String, Object> vals = cfg.getValues(true);
    ItemStack newItem;
    // check material
    newItem =
        new ItemStack(Material.getMaterial((cfg.getString("material", "stone")).toUpperCase()));

    // check damage value

    newItem.setDurability((short) (cfg.getInt("damage", 0)));

    // check quantity

    newItem.setAmount(cfg.getInt("amount", 1));

    // enchantment parsing
    for (String s : cfg.getStringList("enchantments")) {
      String[] parts = s.split(":");
      String enchant = parts[0];
      int level = 1;

      if (parts.length > 1) {
        level = Integer.parseInt(parts[1]);
      }
      newItem.addUnsafeEnchantment(Enchantment.getByName(enchant.toUpperCase()), level);
    }

    // System.out.println("Item: "+ newItem.toString());
    return newItem;

    // ItemStack is = new ItemStack(Material.);
  }
  /** 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;
  }
Esempio n. 11
0
  public static boolean removeItem(Inventory inv, Material mat, int data, int qty) {
    int remd = 0;

    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (int i = 0; i < inv.getSize(); i++) {
      ItemStack s = inv.getItem(i);

      if (s != null) {
        if (remd < qty) {
          if ((s.getType().equals(mat)) && ((data == -1) || (data == s.getData().getData()))) {
            int take = Math.min(s.getAmount(), qty - remd);
            map.put(Integer.valueOf(i), Integer.valueOf(take));
            remd += take;

            if (take == s.getAmount()) {
              inv.setItem(i, null);
            } else {
              s.setAmount(s.getAmount() - take);
            }
          }
        }
      }
    }
    if (remd != qty) {
      return false;
    }
    return true;
  }
Esempio n. 12
0
  @Override
  public void setAmountsInventory(Inventory inventory, TEntityStatus status, StockItem item) {
    Trader trader = tNpcManager.instance().getTraderRelation(player);

    // debug info
    dB.info("Setting inventory, status: ", TEntityStatus.SELL_AMOUNTS.name().toLowerCase());

    // clear the inventory
    inventory.clear();
    for (Integer amount : item.getAmounts()) {
      // set new amount
      List<String> lore = item.getDescription(status);
      lore = Limit.loreRequest(player.getName(), item, lore, status);
      lore.addAll(new ShopSession(trader, player).getDescription("sell", item, amount));

      ItemStack itemStack = item.getItem(false, lore);
      itemStack.setAmount(amount);

      // set the lore
      ItemMeta meta = itemStack.getItemMeta();

      meta.setLore(lore);

      itemStack.setItemMeta(meta);

      // set the item
      inventory.setItem(inventory.firstEmpty(), NBTUtils.markItem(itemStack));
    }
    setUi(inventory, null, TEntityStatus.SELL_AMOUNTS);
  }
 public boolean exorcise(Player player, Player victim) {
   SuperNPlayer snplayer = SuperNManager.get(player);
   SuperNPlayer snvictim = SuperNManager.get(victim);
   if (!SupernaturalsPlugin.instance.getPvP(victim)) {
     SuperNManager.sendMessage(snplayer, "Cannot cast in a non-PvP zone.");
     return false;
   }
   if (snplayer.getPower() > SNConfigHandler.priestPowerExorcise) {
     if (snvictim.isSuper()) {
       SuperNManager.alterPower(
           snplayer, -SNConfigHandler.priestPowerExorcise, "Exorcised " + victim.getName());
       SuperNManager.sendMessage(
           snvictim,
           "You were exorcised by " + ChatColor.WHITE + snplayer.getName() + ChatColor.RED + "!");
       SuperNManager.cure(snvictim);
       ItemStack item = player.getItemInHand();
       if (item.getAmount() == 1) {
         player.setItemInHand(null);
       } else {
         item.setAmount(player.getItemInHand().getAmount() - 1);
       }
       return true;
     } else {
       SuperNManager.sendMessage(snplayer, "Only supernatural players can be exorcised.");
       return false;
     }
   } else {
     SuperNManager.sendMessage(snplayer, "Not enough power to exorcise.");
     return false;
   }
 }
Esempio n. 14
0
  public void pay(Player p, double amt) {
    if (this.usingItemsForPayment()) {
      int amtNeeded = (int) Math.ceil(amt);

      for (int i = 0; i < p.getInventory().getSize(); i++) {
        ItemStack it = p.getInventory().getItem(i);

        // The item is either air or we doesn't match out needs
        if (it == null || it.getType() != this.item) continue;

        // If the itemstack has more than or equal to the amount
        // that we need, remove it and subject from the amt needed
        if (amtNeeded >= it.getAmount()) {
          amtNeeded -= it.getAmount();
          p.getInventory().clear(i);
        } else {
          // Otherwise, subject from the itemstack just the amount we need
          it.setAmount(it.getAmount() - amtNeeded);
          p.getInventory().setItem(i, it);
          amtNeeded = 0;
        }

        if (amtNeeded == 0) break;
      }
    } else {
      this.economy.withdrawPlayer(p, amt);
    }
  }
 public boolean banish(Player player, Player victim) {
   SuperNPlayer snplayer = SuperNManager.get(player);
   SuperNPlayer snvictim = SuperNManager.get(victim);
   if (!SupernaturalsPlugin.instance.getPvP(victim)) {
     SuperNManager.sendMessage(snplayer, "Cannot cast in a non-PvP zone.");
     return false;
   }
   if (snplayer.getPower() > SNConfigHandler.priestPowerBanish) {
     if (snvictim.isSuper()) {
       SuperNManager.alterPower(
           snplayer, -SNConfigHandler.priestPowerBanish, "Banished " + victim.getName());
       SuperNManager.sendMessage(
           snvictim,
           "You were banished by " + ChatColor.WHITE + snplayer.getName() + ChatColor.RED + "!");
       victim.teleport(SNConfigHandler.priestBanishLocation);
       ItemStack item = player.getItemInHand();
       if (item.getAmount() == 1) {
         player.setItemInHand(null);
       } else {
         item.setAmount(player.getItemInHand().getAmount() - 1);
       }
       return true;
     }
     SuperNManager.sendMessage(snplayer, "Can only banish supernatural players.");
     return false;
   } else {
     SuperNManager.sendMessage(snplayer, "Not enough power to banish.");
     return false;
   }
 }
 public boolean heal(Player player, Player victim) {
   SuperNPlayer snplayer = SuperNManager.get(player);
   SuperNPlayer snvictim = SuperNManager.get(victim);
   if (snplayer.getPower() > SNConfigHandler.priestPowerHeal) {
     if (!snvictim.isSuper() && victim.getHealth() < victim.getMaxHealth() && !victim.isDead()) {
       SuperNManager.alterPower(
           snplayer, -SNConfigHandler.priestPowerHeal, "Healed " + victim.getName());
       SuperNManager.sendMessage(
           snvictim,
           "You were healed by " + ChatColor.WHITE + snplayer.getName() + ChatColor.RED + "!");
       double health = victim.getHealth() + SNConfigHandler.priestHealAmount;
       if (health > victim.getMaxHealth()) {
         health = victim.getMaxHealth();
       }
       victim.setHealth(health);
       ItemStack item = player.getItemInHand();
       if (item.getAmount() == 1) {
         player.setItemInHand(null);
       } else {
         item.setAmount(player.getItemInHand().getAmount() - 1);
       }
       return true;
     } else {
       SuperNManager.sendMessage(snplayer, "Player cannot be healed.");
       return false;
     }
   } else {
     SuperNManager.sendMessage(snplayer, "Not enough power to heal.");
     return false;
   }
 }
 @SuppressWarnings("deprecation")
 public void remoteDonations(Player player) {
   SuperNPlayer snplayer = SuperNManager.get(player);
   PlayerInventory inv = player.getInventory();
   ItemStack[] items = inv.getContents();
   double delta = 0;
   invCheck:
   for (Material mat : SNConfigHandler.priestDonationMap.keySet()) {
     for (ItemStack itemStack : items) {
       if (itemStack != null) {
         if (itemStack.getType().equals(mat)) {
           delta = SNConfigHandler.priestDonationMap.get(mat);
           if (itemStack.getAmount() == 1) {
             inv.clear(inv.first(itemStack.getType()));
           } else {
             itemStack.setAmount(itemStack.getAmount() - 1);
           }
           break invCheck;
         }
       }
     }
   }
   if (delta == 0) {
     SuperNManager.sendMessage(
         snplayer, "The Church only accepts donations of Bread, Fish, Grilled Pork and Apples.");
   } else {
     player.updateInventory();
     SuperNManager.sendMessage(snplayer, "You receive some power for your remote donations.");
     SuperNManager.alterPower(snplayer, delta * .5, "Donations!");
   }
 }
 public boolean drainPower(Player player, Player victim) {
   SuperNPlayer snplayer = SuperNManager.get(player);
   SuperNPlayer snvictim = SuperNManager.get(victim);
   if (!SupernaturalsPlugin.instance.getPvP(victim)) {
     SuperNManager.sendMessage(snplayer, "Cannot cast in a non-PvP zone.");
     return false;
   }
   if (snplayer.getPower() > SNConfigHandler.priestPowerDrain) {
     if (snvictim.isSuper()) {
       double power = snvictim.getPower();
       power *= SNConfigHandler.priestDrainFactor;
       SuperNManager.alterPower(
           snplayer,
           -SNConfigHandler.priestPowerDrain,
           "Drained  " + snvictim.getName() + "'s power!");
       SuperNManager.alterPower(snvictim, -power, "Drained by " + snplayer.getName());
       ItemStack item = player.getItemInHand();
       if (item.getAmount() == 1) {
         player.setItemInHand(null);
       } else {
         item.setAmount(player.getItemInHand().getAmount() - 1);
       }
       return true;
     } else {
       SuperNManager.sendMessage(snplayer, "Only supernatural players can be power drained.");
       return false;
     }
   } else {
     SuperNManager.sendMessage(snplayer, "Not enough power to drain power.");
     return false;
   }
 }
Esempio n. 19
0
  @Override
  public boolean effect(Event event, Player player) {
    int slot = player.getInventory().getHeldItemSlot();

    ItemStack potion = player.getInventory().getItem(slot + 1);
    Location loc = player.getLocation();
    if (potion != null && potion.getType().toString().contains("POTION")) {
      ThrownPotion tp = player.launchProjectile(ThrownPotion.class);
      EffectManager.playSound(loc, "ENTITY_GENERIC_EXPLODE", 0.5f, 2f);

      try {
        tp.setItem(potion);
      } catch (IllegalArgumentException ex) {
        ItemStack pt = potion.clone();
        if (potion.getType().equals(Material.POTION)
            || potion.getType().equals(Material.LINGERING_POTION))
          pt.setType(Material.SPLASH_POTION);
        tp.setItem(pt);
      }

      tp.setBounce(false);
      tp.setVelocity(loc.getDirection().multiply(ProjectileSpeedMultiplier));
      if (!player.getGameMode().equals(GameMode.CREATIVE)) {
        potion.setAmount(potion.getAmount() - 1);
        player.getInventory().setItem(slot + 1, potion);
        player.updateInventory();
      }
      return true;
    } else {
      player.sendMessage(
          ChatColor.RED + "You need a Potion in the slot to the right of the Potion Launcher!");
      player.getWorld().playEffect(loc, Effect.CLICK1, 5);
    }
    return false;
  }
Esempio n. 20
0
  public static List<ItemStack> getIngredients(Recipe recipe) {
    List<ItemStack> ingredients = new ArrayList<ItemStack>();
    if ((recipe instanceof ShapedRecipe)) {
      ShapedRecipe sr = (ShapedRecipe) recipe;
      String[] shape = sr.getShape();

      for (String row : shape) {
        for (int i = 0; i < row.length(); i++) {
          ItemStack stack = (ItemStack) sr.getIngredientMap().get(Character.valueOf(row.charAt(i)));
          for (ItemStack ing : ingredients) {
            int mss = ing.getType().getMaxStackSize();
            if ((ing.isSimilar(stack)) && (ing.getAmount() < mss)) {
              int canAdd = mss - ing.getAmount();
              int add = Math.min(canAdd, stack.getAmount());
              ing.setAmount(ing.getAmount() + add);
              int remaining = stack.getAmount() - add;
              if (remaining >= 1) {
                stack.setAmount(remaining);
              } else {
                stack = null;
                break;
              }
            }
          }
          if ((stack != null) && (stack.getAmount() > 0)) ingredients.add(stack);
        }
      }
    } else if ((recipe instanceof ShapelessRecipe)) {
      for (ItemStack i : ((ShapelessRecipe) recipe).getIngredientList()) {
        for (ItemStack ing : ingredients) {
          int mss = ing.getType().getMaxStackSize();
          if ((ing.isSimilar(i)) && (ing.getAmount() < mss)) {
            int canAdd = mss - ing.getAmount();
            ing.setAmount(ing.getAmount() + Math.min(canAdd, i.getAmount()));
            int remaining = i.getAmount() - Math.min(canAdd, i.getAmount());
            if (remaining < 1) break;
            i.setAmount(remaining);
          }
        }

        if (i.getAmount() > 0) {
          ingredients.add(i);
        }
      }
    }
    return ingredients;
  }
 public boolean cure(Player player, Player victim, Material material) {
   SuperNPlayer snplayer = SuperNManager.get(player);
   SuperNPlayer snvictim = SuperNManager.get(victim);
   if (snplayer.getPower() > SNConfigHandler.priestPowerCure) {
     if (snvictim.isSuper()) {
       if (victim.getItemInHand().getType().equals(material)) {
         SuperNManager.alterPower(
             snplayer, -SNConfigHandler.priestPowerCure, "Cured " + victim.getName());
         SuperNManager.sendMessage(
             snvictim,
             ChatColor.WHITE + snplayer.getName() + ChatColor.RED + " has restored your humanity");
         SuperNManager.cure(snvictim);
         ItemStack item = player.getItemInHand();
         ItemStack item2 = victim.getItemInHand();
         if (item.getAmount() == 1) {
           player.setItemInHand(null);
         } else {
           item.setAmount(player.getItemInHand().getAmount() - 1);
         }
         if (item2.getAmount() == 1) {
           victim.setItemInHand(null);
         } else {
           item2.setAmount(victim.getItemInHand().getAmount() - 1);
         }
         return true;
       } else {
         SuperNManager.sendMessage(
             snplayer,
             ChatColor.WHITE
                 + snvictim.getName()
                 + ChatColor.RED
                 + " is not holding "
                 + ChatColor.WHITE
                 + material.toString()
                 + ChatColor.RED
                 + ".");
         return false;
       }
     } else {
       SuperNManager.sendMessage(snplayer, "You can only cure supernatural players.");
       return false;
     }
   } else {
     SuperNManager.sendMessage(snplayer, "Not enough power to cure.");
     return false;
   }
 }
Esempio n. 22
0
 public static void removeItem(ItemStack item, Player player) {
   if (item.getAmount() <= 1) {
     player.getInventory().removeItem(item);
   }
   if (item.getAmount() > 1) {
     item.setAmount(item.getAmount() - 1);
   }
 }
 @Override
 public void readData(SpoutInputStream input) throws IOException {
   super.readData(input);
   stack.setTypeId(input.readInt());
   stack.setAmount((int) input.readShort());
   stack.setDurability(input.readShort());
   depth = input.readInt();
   renderAmount = input.readBoolean();
 }
Esempio n. 24
0
 private void decrementInventory(final Player source, final ItemStack held) {
   // Remove item from inventory.
   if (source.getGameMode() != GameMode.CREATIVE) {
     held.setAmount(held.getAmount() - 1);
     if (held.getAmount() == 0) {
       Util.ReloadItemBar(source, new SpoutItemStack(source.getItemInHand()));
     }
   }
 }
Esempio n. 25
0
 public static ItemStack decreaseItemStack(ItemStack stack) {
   int amount = stack.getAmount() - 1;
   if (amount == 0) {
     stack = null;
   } else {
     stack.setAmount(amount);
   }
   return stack;
 }
Esempio n. 26
0
  protected static List<Entry<ItemStack, Integer>> getChangesClick(InventoryClickEvent event) {
    // Create
    List<Entry<ItemStack, Integer>> ret = new MassiveList<>();

    // Fill
    final InventoryAlter alter = InventoryUtil.getAlter(event);
    final InventoryAction action = event.getAction();
    ItemStack item;
    int amount;

    // Give
    if (alter.isGiving()) {
      // Special > MOVE_TO_OTHER_INVENTORY
      if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
        item = event.getCurrentItem();

        ItemStack compare = item.clone();
        compare.setAmount(1);
        amount = InventoryUtil.roomLeft(event.getInventory(), compare, item.getAmount());
      }
      // Special > HOTBAR_SWAP
      else if (action == InventoryAction.HOTBAR_SWAP) {
        item = event.getView().getBottomInventory().getItem(event.getHotbarButton());

        amount = item.getAmount();
      }
      // Normal
      else {
        item = event.getCursor();

        amount = item.getAmount();
        if (action == InventoryAction.PLACE_ONE) {
          amount = 1;
        } else if (action == InventoryAction.PLACE_SOME) {
          int max = event.getCurrentItem().getType().getMaxStackSize();
          amount = max - event.getCurrentItem().getAmount();
        }
      }

      amount *= -1;
      ret.add(new SimpleEntry<ItemStack, Integer>(item, amount));
    }

    // Take
    if (alter.isTaking()) {
      item = event.getCurrentItem();

      amount = item.getAmount();
      if (action == InventoryAction.PICKUP_ONE) amount = 1;
      if (action == InventoryAction.PICKUP_HALF) amount = (int) Math.ceil(amount / 2.0);

      ret.add(new SimpleEntry<ItemStack, Integer>(item, amount));
    }

    // Return
    return ret;
  }
Esempio n. 27
0
 private void dropItem(ItemStack itemStack, List<ItemStack> itemDrops) {
   if (itemStack == null) {
     plugin.logDebug("Ignoring null item");
     return;
   }
   plugin.logDebug("Dropping item " + itemStack.getType());
   itemDrops.add(itemStack.clone());
   itemStack.setAmount(0);
 }
  private boolean condenseStack(
      final User user, final ItemStack stack, final boolean validateReverse)
      throws ChargeException, MaxMoneyException {
    final SimpleRecipe condenseType = getCondenseType(stack);
    if (condenseType != null) {
      final ItemStack input = condenseType.getInput();
      final ItemStack result = condenseType.getResult();

      if (validateReverse) {
        boolean pass = false;
        for (Recipe revRecipe : ess.getServer().getRecipesFor(input)) {
          if (getStackOnRecipeMatch(revRecipe, result) != null) {
            pass = true;
            break;
          }
        }
        if (!pass) {
          return false;
        }
      }

      int amount = 0;

      for (final ItemStack contents : user.getBase().getInventory().getContents()) {
        if (contents != null && contents.isSimilar(stack)) {
          amount += contents.getAmount();
        }
      }

      int output = ((amount / input.getAmount()) * result.getAmount());
      amount -= amount % input.getAmount();

      if (amount > 0) {
        input.setAmount(amount);
        result.setAmount(output);
        final Trade remove = new Trade(input, ess);
        final Trade add = new Trade(result, ess);
        remove.charge(user);
        add.pay(user, OverflowType.DROP);
        return true;
      }
    }
    return false;
  }
Esempio n. 29
0
	public static ItemStack createItem(Material material, String name, List<String> lore, int amount) {
		ItemStack item = createItem(material, name);
		item.setAmount(amount);

		ItemMeta meta = item.getItemMeta();
		meta.setLore(lore);
		item.setItemMeta(meta);

		return item;
	}
Esempio n. 30
0
 protected final ItemStack getItemStack(
     final String itemName, final int quantity, final IEssentials ess) throws SignException {
   try {
     final ItemStack item = ess.getItemDb().get(itemName);
     item.setAmount(quantity);
     return item;
   } catch (Exception ex) {
     throw new SignException(ex.getMessage(), ex);
   }
 }