Skip to content

Commit

Permalink
Support to dynamic prices and stocks for EconomyShopGUI (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Dec 21, 2024
1 parent 124a231 commit 5326898
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dependencies {
implementation 'com.bgsoftware.common.reflection:ReflectionUtils:b5'
implementation 'com.bgsoftware.common.config:CommentedConfiguration:b1'
implementation 'com.bgsoftware.common.updater:Updater:b1'
implementation 'com.bgsoftware.common.shopsbridge:ShopsBridge:b16:all@jar'
implementation 'com.bgsoftware.common.shopsbridge:ShopsBridge:b17:all@jar'
implementation 'com.bgsoftware.common.dependencies:DependenciesManager:b2'
implementation 'com.bgsoftware.common.nmsloader:NMSLoader:b9'

Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/bgsoftware/wildchests/utils/ChestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,24 @@ public static void trySellChest(Chest chest) {
plugin.getProviders().startSellingTask(player);
for (Inventory inventory : chest.getPages()) {
for (int i = 0; i < inventory.getSize(); i++) {
if (trySellItem(player, chest, inventory.getItem(i)))
inventory.setItem(i, new ItemStack(Material.AIR));
ItemStack itemStack = inventory.getItem(i);
Counter itemCount = new Counter();
if (trySellItem(player, chest, itemStack, itemCount)) {
if (itemCount.get() <= 0) {
inventory.setItem(i, new ItemStack(Material.AIR));
} else {
itemStack.setAmount((int) itemCount.get());
inventory.setItem(i, itemStack);
}
}
}
}
} finally {
plugin.getProviders().stopSellingTask(player);
}
}

public static boolean trySellItem(OfflinePlayer player, Chest chest, ItemStack toSell) {
public static boolean trySellItem(OfflinePlayer player, Chest chest, ItemStack toSell, Counter newItemAmount) {
if (toSell == null || toSell.getType() == Material.AIR)
return false;

Expand Down Expand Up @@ -179,8 +187,12 @@ public static boolean trySellItem(OfflinePlayer player, Chest chest, ItemStack t

if (successDeposit) {
NotifierTask.addTransaction(player.getUniqueId(), toSell, toSell.getAmount(), finalPrice);
if (transactionResult.getTransaction() != null)
if (transactionResult.getTransaction() != null) {
ItemStack transactItem = transactionResult.getTransaction().getItem();
if (transactItem != toSell)
newItemAmount.increase(toSell.getAmount() - transactItem.getAmount());
transactionResult.getTransaction().onTransact();
}
}

return successDeposit;
Expand Down

0 comments on commit 5326898

Please sign in to comment.