Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
- Fixes for errors during trade and destruction of iTrade shops
- Removed old shulker code
  • Loading branch information
KillerOfPie committed Nov 4, 2020
1 parent 1643b5a commit 686e4da
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,19 @@ private boolean tradeAllItems(Shop shop, int multiplier, Action action, Player b

if (shop.getShopType() == ShopType.ITRADE && action.equals(Action.RIGHT_CLICK_BLOCK)) { //ITrade trade

//Method to find Cost items in player inventory and add to cost array
costItems = getItems(playerInventory, shop.getCost(), multiplier);
if (costItems.get(0) == null) {
ItemStack item = costItems.get(1);
buyer.sendMessage(Message.INSUFFICIENT_ITEMS.getPrefixed()
.replace("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString())
.replace("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
return false;
}

for (ItemStack item : costItems) {
playerInventory.removeItem(item);
if (!shop.getCost().isEmpty()) {
costItems = getItems(playerInventory, shop.getCost(), multiplier);
if (costItems.get(0) == null) {
ItemStack item = costItems.get(1);
buyer.sendMessage(Message.INSUFFICIENT_ITEMS.getPrefixed()
.replace("{ITEM}", item.hasItemMeta() && item.getItemMeta().hasDisplayName() ? item.getItemMeta().getDisplayName() : item.getType().toString())
.replace("{AMOUNT}", String.valueOf(item.getAmount() * multiplier)));
return false;
}

for (ItemStack item : costItems) {
playerInventory.removeItem(item);
}
}

for (ShopItemStack item : shop.getProduct()) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/shanerx/tradeshop/objects/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -987,8 +987,10 @@ public ShopRole checkRole(UUID uuidToCheck) {
* Updates the number of trades the shop can make
*/
public void updateFullTradeCount() {
if (!hasStorage() || !hasProduct())
if (!hasStorage() || !hasProduct()) {
availableTrades = 0;
return;
}

Inventory shopInventory = hasStorage() ? getChestAsSC().getInventory() : null;

Expand Down
87 changes: 16 additions & 71 deletions src/main/java/org/shanerx/tradeshop/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,64 +485,29 @@ public ArrayList<ItemStack> getItems(Inventory inventory, List<ShopItemStack> it

for (ShopItemStack item : items) {
totalCount += item.getItemStack().getAmount() * multiplier;
/*
if (item.getItemStack().getType().name().endsWith("SHULKER_BOX")) {
for (ItemStack itm : clone.getStorageContents()) {
if (itm != null && itm.getType().name().endsWith("SHULKER_BOX")) {
debugger.log("ShopTradeListener > Type of Item: " + itm.getType(), DebugLevels.TRADE);
debugger.log("ShopTradeListener > Amount of Item: " + itm.getAmount(), DebugLevels.TRADE);
//StringBuilder contents = new StringBuilder();
//Arrays.stream(clone.getContents()).forEach(a -> contents.append(a != null ? a.getType().toString() : "Empty").append("|"));
//debugger.log("ShopTradeListener > clone Contents: " + contents.toString(), DebugLevels.TRADE);
if (compareShulkers(itm, item.getItemStack())) {
clone.removeItem(itm);
ret.add(itm);
currentCount++;
}
debugger.log("ShopTradeListener > CurrentCount: " + currentCount, DebugLevels.TRADE);
}
if (currentCount >= totalCount) break;
}
} else {
*/
int count = item.getItemStack().getAmount() * multiplier, traded;

debugger.log("ShopTradeListener > Item Material Being Searched for: " + item.getItemStack().getType().name(), DebugLevels.TRADE);
debugger.log("ShopTradeListener > Item count: " + count, DebugLevels.TRADE);

for (ItemStack storageItem : clone.getStorageContents()) {
// Skips empty slots
if (storageItem != null) {
int count = item.getItemStack().getAmount() * multiplier, traded;

debugger.log("ShopTradeListener > Type of Item: " + storageItem.getType(), DebugLevels.TRADE);
debugger.log("ShopTradeListener > Amount of Item: " + storageItem.getAmount(), DebugLevels.TRADE);
debugger.log("ShopTradeListener > Item Material Being Searched for: " + item.getItemStack().getType().name(), DebugLevels.TRADE);
debugger.log("ShopTradeListener > Item count: " + count, DebugLevels.TRADE);

boolean isSimilar = item.isSimilar(storageItem);
debugger.log("ShopTradeListener > Location Similar: " + isSimilar, DebugLevels.TRADE);
for (ItemStack storageItem : clone.getStorageContents()) {
if (storageItem != null && item.isSimilar(storageItem)) {

if (isSimilar) {
traded = Math.min(Math.min(storageItem.getAmount(), item.getItemStack().getMaxStackSize()), count);

traded = Math.min(Math.min(storageItem.getAmount(), item.getItemStack().getMaxStackSize()), count);
storageItem.setAmount(traded);

storageItem.setAmount(traded);
clone.removeItem(storageItem);
ret.add(storageItem);
debugger.log("ShopTradeListener > Item traded: " + traded, DebugLevels.TRADE);

clone.removeItem(storageItem);
ret.add(storageItem);
debugger.log("ShopTradeListener > Item traded: " + traded, DebugLevels.TRADE);

count -= traded;
currentCount += traded;

debugger.log("ShopTradeListener > Item new count: " + count, DebugLevels.TRADE);
}
}
count -= traded;
currentCount += traded;
debugger.log("ShopTradeListener > Item new count: " + count, DebugLevels.TRADE);
}

if (currentCount >= totalCount) break;
}
//}
if (currentCount >= totalCount) break;
}

if (currentCount < totalCount) {
debugger.log("ShopTradeListener > TotalCount: " + totalCount, DebugLevels.TRADE);
Expand All @@ -556,24 +521,4 @@ public ArrayList<ItemStack> getItems(Inventory inventory, List<ShopItemStack> it

return ret;
}

/* public boolean compareShulkers(ItemStack item1, ItemStack item2) {
if (item1 == null || item2 == null)
return false;
try {
ArrayList<ItemStack> contents1 = Lists.newArrayList(((ShulkerBox) ((BlockStateMeta) item1.clone().getItemMeta()).getBlockState()).getInventory().getContents());
ShulkerBox shulker2 = (ShulkerBox) ((BlockStateMeta) item2.clone().getItemMeta()).getBlockState();
for (ItemStack itm : shulker2.getInventory().getContents()) {
contents1.remove(itm);
}
return contents1.isEmpty();
} catch (ClassCastException ex) {
return false;
}
}*/
}

0 comments on commit 686e4da

Please sign in to comment.