Fixed items incorrectly appearning in messages

This commit is contained in:
Acrobot 2012-08-10 22:25:08 +02:00
parent 30fa329645
commit 2cd4e7b914
3 changed files with 39 additions and 15 deletions

View File

@ -45,6 +45,8 @@ public class ItemManager implements Listener {
}
private static void addItems(Inventory inventory, ItemStack[] items) {
inventory.addItem(items);
for (ItemStack item : items) {
inventory.addItem(item.clone());
}
}
}

View File

@ -1,5 +1,6 @@
package com.Acrobot.ChestShop.Listeners.PostTransaction;
import com.Acrobot.Breeze.Utils.MaterialUtil;
import com.Acrobot.ChestShop.Config.Config;
import com.Acrobot.ChestShop.Config.Language;
import com.Acrobot.ChestShop.Economy.Economy;
@ -11,8 +12,8 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.LinkedList;
import java.util.List;
import static com.Acrobot.ChestShop.Config.Language.*;
import static com.Acrobot.ChestShop.Config.Property.SHOW_TRANSACTION_INFORMATION_CLIENT;
@ -78,24 +79,28 @@ public class TransactionMessageSender implements Listener {
}
private static String parseItemInformation(ItemStack[] items) {
Map<String, Integer> itemMap = new HashMap<String, Integer>();
List<ItemStack> stock = new LinkedList<ItemStack>();
for (ItemStack item : items) {
String matName = item.getType().name();
boolean added = false;
if (itemMap.containsKey(matName)) {
int curAmount = itemMap.get(matName);
for (ItemStack iStack : stock) {
if (MaterialUtil.equals(item, iStack)) {
iStack.setAmount(iStack.getAmount() + item.getAmount());
added = true;
break;
}
}
itemMap.put(matName, curAmount + item.getAmount());
} else {
itemMap.put(matName, item.getAmount());
if (!added) {
stock.add(item);
}
}
StringBuilder message = new StringBuilder(15);
for (Map.Entry<String, Integer> item : itemMap.entrySet()) {
message.append(item.getValue()).append(' ').append(item.getKey());
for (ItemStack item : stock) {
message.append(item.getType().name()).append(' ').append(item.getAmount());
}
return message.toString();

View File

@ -139,6 +139,7 @@ public class PartialTransactionModule implements Listener {
if (MaterialUtil.equals(item, needed)) {
needed.setAmount(needed.getAmount() + item.getAmount());
itemAdded = true;
break;
}
}
@ -152,8 +153,8 @@ public class PartialTransactionModule implements Listener {
for (ItemStack item : neededItems) {
int amount = InventoryUtil.getAmount(item, inventory);
ItemStack clone = item.clone();
ItemStack clone = item.clone();
clone.setAmount(amount > item.getAmount() ? item.getAmount() : amount);
toReturn.add(clone);
@ -168,17 +169,33 @@ public class PartialTransactionModule implements Listener {
for (ItemStack stack : stock) {
int count = stack.getAmount();
ItemStack toAdd;
if (left > count) {
stacks.add(stack);
toAdd = stack;
left -= count;
} else {
ItemStack clone = stack.clone();
clone.setAmount(left);
stacks.add(clone);
toAdd = clone;
left = 0;
}
boolean added = false;
for (ItemStack iStack : stacks) {
if (MaterialUtil.equals(toAdd, iStack)) {
iStack.setAmount(iStack.getAmount() + toAdd.getAmount());
added = true;
break;
}
}
if (!added) {
stacks.add(toAdd);
}
if (left <= 0) {
break;
}