Admin Shop: Vendor doesn't need enough money, Chest doesn't need space

Infinite Shops also don't need free space when someone wants to sell
something.

Fixes #3
This commit is contained in:
Eric 2016-04-15 15:32:10 +02:00
parent 5e3cdca606
commit 2516f6e491
2 changed files with 69 additions and 52 deletions

View File

@ -2,7 +2,7 @@
name: ShopChest name: ShopChest
main: de.epiceric.shopchest.ShopChest main: de.epiceric.shopchest.ShopChest
version: 1.7.1 version: 1.7.1.1
author: EpicEric author: EpicEric
website: https://www.spigotmc.org/resources/shopchest.11431/ website: https://www.spigotmc.org/resources/shopchest.11431/
depend: [Vault] depend: [Vault]

View File

@ -400,9 +400,7 @@ public class InteractShop implements Listener{
} }
private void sell(Player executor, Shop shop) { private void sell(Player executor, Shop shop) {
if (econ.getBalance(shop.getVendor()) >= shop.getSellPrice()) {
Block block = shop.getLocation().getBlock(); Block block = shop.getLocation().getBlock();
Chest chest = (Chest) block.getState(); Chest chest = (Chest) block.getState();
@ -432,64 +430,83 @@ public class InteractShop implements Listener{
freeAmount += value; freeAmount += value;
} }
if (freeAmount >= leftAmount) { if (shop.getShopType() == ShopType.NORMAL) {
EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
EconomyResponse r2 = null;
if (shop.getShopType() != ShopType.ADMIN) r2 = econ.withdrawPlayer(shop.getVendor(), shop.getSellPrice());
if (r.transactionSuccess()) { if (freeAmount >= leftAmount) {
if (r2 != null) { if (econ.getBalance(shop.getVendor()) >= shop.getSellPrice()) {
if (r2.transactionSuccess()) { EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
for (int slot : slotFree.keySet()) { EconomyResponse r2 = econ.withdrawPlayer(shop.getVendor(), shop.getSellPrice());
int amountInSlot = product.getMaxStackSize() - slotFree.get(slot);
if (r.transactionSuccess()) {
for (int i = amountInSlot; i < product.getMaxStackSize(); i++) { if (r2.transactionSuccess()) {
if (leftAmount > 0) { for (int i = leftAmount; i > 0; i--) {
ItemStack soldProduct = new ItemStack(product.clone().getType(), 1, product.clone().getDurability()); ItemStack soldProduct = new ItemStack(product.clone().getType(), 1, product.clone().getDurability());
soldProduct.setItemMeta(product.clone().getItemMeta()); soldProduct.setItemMeta(product.clone().getItemMeta());
if (shop.getShopType() == ShopType.NORMAL) inventory.addItem(soldProduct); inventory.addItem(soldProduct);
executor.getInventory().removeItem(soldProduct); executor.getInventory().removeItem(soldProduct);
executor.updateInventory(); executor.updateInventory();
leftAmount--; }
} else if (leftAmount == 0) { executor.sendMessage(Config.sell_success(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), shop.getVendor().getName()));
executor.sendMessage(Config.sell_success(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), shop.getVendor().getName())); if (shop.getVendor().isOnline()) shop.getVendor().getPlayer().sendMessage(Config.someone_sold(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), executor.getName()));
if (shop.getVendor().isOnline()) shop.getVendor().getPlayer().sendMessage(Config.someone_sold(product.getAmount(), ItemNames.lookup(product), shop.getBuyPrice(), executor.getName())); } else {
return; executor.sendMessage(Config.error_occurred(r2.errorMessage));
}
}
} }
} else {
executor.sendMessage(Config.error_occurred(r.errorMessage));
}
} else {
executor.sendMessage(Config.vendor_not_enough_money());
}
} else {
executor.sendMessage(Config.chest_not_enough_inventory_space());
}
} else if (shop.getShopType() == ShopType.INFINITE) {
if (econ.getBalance(shop.getVendor()) >= shop.getSellPrice()) {
EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
EconomyResponse r2 = econ.withdrawPlayer(shop.getVendor(), shop.getSellPrice());
if (r.transactionSuccess()) {
if (r2.transactionSuccess()) {
for (int i = leftAmount; i > 0; i--) {
ItemStack soldProduct = new ItemStack(product.clone().getType(), 1, product.clone().getDurability());
soldProduct.setItemMeta(product.clone().getItemMeta());
executor.getInventory().removeItem(soldProduct);
executor.updateInventory();
}
executor.sendMessage(Config.sell_success(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), shop.getVendor().getName()));
if (shop.getVendor().isOnline()) shop.getVendor().getPlayer().sendMessage(Config.someone_sold(product.getAmount(), ItemNames.lookup(product), shop.getBuyPrice(), executor.getName()));
} else { } else {
executor.sendMessage(Config.error_occurred(r2.errorMessage)); executor.sendMessage(Config.error_occurred(r2.errorMessage));
} }
} else { } else {
for (int slot : slotFree.keySet()) { executor.sendMessage(Config.error_occurred(r.errorMessage));
int amountInSlot = product.getMaxStackSize() - slotFree.get(slot); }
} else {
for (int i = amountInSlot; i < product.getMaxStackSize(); i++) { executor.sendMessage(Config.vendor_not_enough_money());
if (leftAmount > 0) { }
ItemStack soldProduct = new ItemStack(product.clone().getType(), 1, product.clone().getDurability());
soldProduct.setItemMeta(product.clone().getItemMeta());
executor.getInventory().removeItem(soldProduct); } else if (shop.getShopType() == ShopType.ADMIN) {
executor.updateInventory();
leftAmount--; EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
} else if (leftAmount == 0) {
executor.sendMessage(Config.sell_success_admin(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice())); if (r.transactionSuccess()) {
return; for (int i = leftAmount; i > 0; i--) {
} ItemStack soldProduct = new ItemStack(product.clone().getType(), 1, product.clone().getDurability());
} soldProduct.setItemMeta(product.clone().getItemMeta());
} executor.getInventory().removeItem(soldProduct);
executor.updateInventory();
} }
executor.sendMessage(Config.sell_success_admin(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice()));
} else { } else {
executor.sendMessage(Config.error_occurred(r.errorMessage)); executor.sendMessage(Config.error_occurred(r.errorMessage));
} }
} else {
executor.sendMessage(Config.chest_not_enough_inventory_space()); }
}
} else {
executor.sendMessage(Config.vendor_not_enough_money());
}
} }
} }