Use EconomyTransaction

This commit is contained in:
Ghost_chu committed 2021-06-12 12:57:34 +08:00
1 parent 6315c648a9
commit e5bb738c72
1 file changed
+22 -23
@@ -27,6 +27,7 @@ import org.bukkit.util.BlockIterator;
import org.jetbrains.annotations.NotNull;
import org.maxgamer.quickshop.QuickShop;
import org.maxgamer.quickshop.command.CommandProcesser;
import org.maxgamer.quickshop.economy.EconomyTransaction;
import org.maxgamer.quickshop.shop.ContainerShop;
import org.maxgamer.quickshop.shop.Shop;
import org.maxgamer.quickshop.util.MsgUtil;
@@ -34,7 +35,6 @@ import org.maxgamer.quickshop.util.Util;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.logging.Level;
@AllArgsConstructor
@@ -145,28 +145,28 @@ public class SubCommand_Price implements CommandProcesser {
MsgUtil.sendMessage(sender, MsgUtil.getMessage("no-price-change", sender));
return;
}
//TODO Use EconomyTransaction
if (fee > 0 && !plugin.getEconomy().withdraw(p.getUniqueId(), fee, shop.getLocation().getWorld(), shop.getCurrency())) {
MsgUtil.sendMessage(sender,
MsgUtil.getMessage(
"you-cant-afford-to-change-price", sender, plugin.getEconomy().format(fee, shop.getLocation().getWorld(), shop.getCurrency())));
return;
}
if (fee > 0) {
MsgUtil.sendMessage(sender,
MsgUtil.getMessage(
"fee-charged-for-price-change", sender, plugin.getEconomy().format(fee, shop.getLocation().getWorld(), shop.getCurrency())));
try {
plugin
.getEconomy()
.deposit(
plugin.getShopManager().getCacheTaxAccount(),
fee, shop.getLocation().getWorld(), shop.getCurrency());
} catch (Exception e) {
plugin.getLogger().log(Level.WARNING, "QuickShop can't pay taxes to the configured tax account! Please set the tax account name in the config.yml to an existing player!", e);
EconomyTransaction transaction = EconomyTransaction.builder()
.allowLoan(plugin.getConfig().getBoolean("shop.allow-economy-loan", false))
.core(plugin.getEconomy())
.from(p.getUniqueId())
.amount(fee)
.world(shop.getLocation().getWorld())
.currency(shop.getCurrency())
.build();
if (!transaction.failSafeCommit()) {
EconomyTransaction.TransactionSteps steps = transaction.getSteps();
if (steps == EconomyTransaction.TransactionSteps.CHECK) {
MsgUtil.sendMessage(sender,
MsgUtil.getMessage(
"you-cant-afford-to-change-price", sender, plugin.getEconomy().format(fee, shop.getLocation().getWorld(), shop.getCurrency())));
} else {
MsgUtil.sendMessage(sender,
MsgUtil.getMessage(
"fee-charged-for-price-change", sender, plugin.getEconomy().format(fee, shop.getLocation().getWorld(), shop.getCurrency())));
plugin.getLogger().log(Level.WARNING, "QuickShop can't pay taxes to the configured tax account! Please set the tax account name in the config.yml to an existing player: " + transaction.getLastError());
}
return;
}
}
// Update the shop
@@ -204,7 +204,6 @@ public class SubCommand_Price implements CommandProcesser {
return;
}
MsgUtil.sendMessage(sender, MsgUtil.getMessage("not-looking-at-shop", sender));
}