mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-24 17:17:49 +01:00
Fixed items incorrectly appearning in messages
This commit is contained in:
parent
30fa329645
commit
2cd4e7b914
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user