Creation price should only be withdrawn if the shop is created successfully

This commit is contained in:
Eric 2016-07-01 14:33:13 +02:00
parent 8f75f9f90d
commit 57c6955d6a
2 changed files with 8 additions and 8 deletions

View File

@ -13,7 +13,6 @@ import de.epiceric.shopchest.utils.ShopUtils;
import de.epiceric.shopchest.utils.UpdateChecker;
import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult;
import de.epiceric.shopchest.utils.Utils;
import net.milkbowl.vault.economy.EconomyResponse;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -316,13 +315,7 @@ public class Commands extends BukkitCommand {
double creationPrice = (shopType == ShopType.NORMAL) ? Config.shop_creation_price_normal : Config.shop_creation_price_admin;
if (creationPrice > 0) {
if (plugin.getEconomy().getBalance(p) >= creationPrice) {
EconomyResponse r = plugin.getEconomy().withdrawPlayer(p, creationPrice);
if (!r.transactionSuccess()) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Regex.ERROR, r.errorMessage)));
return;
}
} else {
if (plugin.getEconomy().getBalance(p) < creationPrice) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_CREATE_NOT_ENOUGH_MONEY, new LocalizedMessage.ReplacedRegex(Regex.CREATION_PRICE, String.valueOf(creationPrice))));
return;
}

View File

@ -242,6 +242,13 @@ public class ShopInteractListener implements Listener {
return;
}
double creationPrice = (shopType == ShopType.NORMAL) ? Config.shop_creation_price_normal : Config.shop_creation_price_admin;
EconomyResponse r = plugin.getEconomy().withdrawPlayer(executor, creationPrice);
if (!r.transactionSuccess()) {
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedRegex(Regex.ERROR, r.errorMessage)));
return;
}
Shop shop = new Shop(id, plugin, executor, product, location, buyPrice, sellPrice, shopType);
ShopUtils.addShop(shop, true);