@Override
 public String getValue(String playerID) {
   Player player = PlayerConverter.getPlayer(playerID);
   int playersAmount = 0;
   for (ItemStack item : player.getInventory().getContents()) {
     if (item == null) {
       continue;
     }
     if (!questItem.equalsI(item)) {
       continue;
     }
     playersAmount += item.getAmount();
   }
   List<ItemStack> backpackItems = BetonQuest.getInstance().getDBHandler(playerID).getBackpack();
   for (ItemStack item : backpackItems) {
     if (item == null) {
       continue;
     }
     if (!questItem.equalsI(item)) {
       continue;
     }
     playersAmount += item.getAmount();
   }
   switch (type) {
     case AMOUNT:
       return Integer.toString(playersAmount);
     case LEFT:
       return Integer.toString(amount - playersAmount);
     default:
       return "";
   }
 }
Beispiel #2
0
 @Override
 public void run(String playerID) {
   Player player = PlayerConverter.getPlayer(playerID);
   for (Item theItem : questItems) {
     QuestItem questItem = theItem.getItem();
     int amount = theItem.getAmount();
     if (notify) {
       Config.sendMessage(
           playerID,
           "items_given",
           new String[] {
             (questItem.getName() != null)
                 ? questItem.getName()
                 : questItem.getMaterial().toString().toLowerCase().replace("_", " "),
             String.valueOf(amount)
           });
     }
     while (amount > 0) {
       int stackSize;
       if (amount > 64) {
         stackSize = 64;
       } else {
         stackSize = amount;
       }
       ItemStack item = questItem.generateItem(stackSize);
       HashMap<Integer, ItemStack> left = player.getInventory().addItem(item);
       for (Integer leftNumber : left.keySet()) {
         ItemStack itemStack = left.get(leftNumber);
         if (Utils.isQuestItem(itemStack)) {
           BetonQuest.getInstance().getDBHandler(playerID).addItem(itemStack, stackSize);
         } else {
           player.getWorld().dropItem(player.getLocation(), itemStack);
         }
       }
       amount = amount - stackSize;
     }
   }
 }