Skip to content

Commit

Permalink
Added bulk sell items for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jul 14, 2023
1 parent 314c8c2 commit 1ca9120
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -57,7 +57,7 @@ dependencies {
implementation 'com.bgsoftware.common.reflection:ReflectionUtils:1.0.2'
implementation 'com.bgsoftware.common.config:CommentedConfiguration:1.0.3'
implementation 'com.bgsoftware.common.updater:Updater:latest'
implementation 'com.bgsoftware.common.shopsbridge:ShopsBridge:b4:all@jar'
implementation 'com.bgsoftware.common.shopsbridge:ShopsBridge:b5:all@jar'

// Spigot jars
compileOnly "org.spigotmc:v1_8_R1:latest"
Expand Down
Expand Up @@ -124,12 +124,18 @@ public boolean withdrawPlayer(OfflinePlayer offlinePlayer, double money) {
public void startSellingTask(OfflinePlayer offlinePlayer) {
if (!pendingTransactions.containsKey(offlinePlayer.getUniqueId()))
pendingTransactions.put(offlinePlayer.getUniqueId(), new PendingTransaction());
if (this.pricesProvider instanceof PricesProvider_ShopsBridgeWrapper) {
((PricesProvider_ShopsBridgeWrapper) this.pricesProvider).startBulkTransaction();
}
}

public void stopSellingTask(OfflinePlayer offlinePlayer) {
PendingTransaction pendingTransaction = pendingTransactions.remove(offlinePlayer.getUniqueId());
if (pendingTransaction != null)
pendingTransaction.forEach(((depositMethod, value) -> depositPlayer(offlinePlayer, depositMethod, value)));
if (this.pricesProvider instanceof PricesProvider_ShopsBridgeWrapper) {
((PricesProvider_ShopsBridgeWrapper) this.pricesProvider).stopBulkTransaction();
}
}

public boolean depositPlayer(OfflinePlayer offlinePlayer, DepositMethod depositMethod, double money) {
Expand Down
@@ -1,5 +1,6 @@
package com.bgsoftware.wildchests.hooks;

import com.bgsoftware.common.shopsbridge.BulkTransaction;
import com.bgsoftware.common.shopsbridge.IShopsBridge;
import com.bgsoftware.common.shopsbridge.ShopsProvider;
import com.bgsoftware.wildchests.WildChestsPlugin;
Expand All @@ -10,6 +11,7 @@
public class PricesProvider_ShopsBridgeWrapper implements PricesProvider {

private final IShopsBridge shopsBridge;
private BulkTransaction bulkTransaction;

public PricesProvider_ShopsBridgeWrapper(ShopsProvider shopsProvider, IShopsBridge shopsBridge) {
WildChestsPlugin.log(" - Using " + shopsProvider.getPluginName() + " as PricesProvider.");
Expand All @@ -18,7 +20,15 @@ public PricesProvider_ShopsBridgeWrapper(ShopsProvider shopsProvider, IShopsBrid

@Override
public double getPrice(OfflinePlayer offlinePlayer, ItemStack itemStack) {
return this.shopsBridge.getSellPrice(offlinePlayer, itemStack).doubleValue();
return (this.bulkTransaction == null ? this.shopsBridge : this.bulkTransaction).getSellPrice(offlinePlayer, itemStack).doubleValue();
}

public void startBulkTransaction() {
this.bulkTransaction = this.shopsBridge.startBulkTransaction();
}

public void stopBulkTransaction() {
this.bulkTransaction = null;
}

}

0 comments on commit 1ca9120

Please sign in to comment.