mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-08 19:51:05 +00:00
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:
parent
5e3cdca606
commit
2516f6e491
@ -2,7 +2,7 @@
|
||||
|
||||
name: ShopChest
|
||||
main: de.epiceric.shopchest.ShopChest
|
||||
version: 1.7.1
|
||||
version: 1.7.1.1
|
||||
author: EpicEric
|
||||
website: https://www.spigotmc.org/resources/shopchest.11431/
|
||||
depend: [Vault]
|
||||
|
@ -401,8 +401,6 @@ public class InteractShop implements Listener{
|
||||
|
||||
private void sell(Player executor, Shop shop) {
|
||||
|
||||
if (econ.getBalance(shop.getVendor()) >= shop.getSellPrice()) {
|
||||
|
||||
Block block = shop.getLocation().getBlock();
|
||||
Chest chest = (Chest) block.getState();
|
||||
|
||||
@ -432,64 +430,83 @@ public class InteractShop implements Listener{
|
||||
freeAmount += value;
|
||||
}
|
||||
|
||||
if (freeAmount >= leftAmount) {
|
||||
if (shop.getShopType() == ShopType.NORMAL) {
|
||||
|
||||
if (freeAmount >= leftAmount) {
|
||||
if (econ.getBalance(shop.getVendor()) >= shop.getSellPrice()) {
|
||||
EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
|
||||
EconomyResponse r2 = null;
|
||||
if (shop.getShopType() != ShopType.ADMIN) r2 = econ.withdrawPlayer(shop.getVendor(), shop.getSellPrice());
|
||||
EconomyResponse r2 = econ.withdrawPlayer(shop.getVendor(), shop.getSellPrice());
|
||||
|
||||
if (r.transactionSuccess()) {
|
||||
if (r2 != null) {
|
||||
if (r2.transactionSuccess()) {
|
||||
for (int slot : slotFree.keySet()) {
|
||||
int amountInSlot = product.getMaxStackSize() - slotFree.get(slot);
|
||||
|
||||
for (int i = amountInSlot; i < product.getMaxStackSize(); i++) {
|
||||
if (leftAmount > 0) {
|
||||
for (int i = leftAmount; i > 0; i--) {
|
||||
ItemStack soldProduct = new ItemStack(product.clone().getType(), 1, product.clone().getDurability());
|
||||
soldProduct.setItemMeta(product.clone().getItemMeta());
|
||||
if (shop.getShopType() == ShopType.NORMAL) inventory.addItem(soldProduct);
|
||||
inventory.addItem(soldProduct);
|
||||
executor.getInventory().removeItem(soldProduct);
|
||||
executor.updateInventory();
|
||||
leftAmount--;
|
||||
} else if (leftAmount == 0) {
|
||||
}
|
||||
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()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (shop.getVendor().isOnline()) shop.getVendor().getPlayer().sendMessage(Config.someone_sold(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), executor.getName()));
|
||||
} else {
|
||||
executor.sendMessage(Config.error_occurred(r2.errorMessage));
|
||||
}
|
||||
} else {
|
||||
for (int slot : slotFree.keySet()) {
|
||||
int amountInSlot = product.getMaxStackSize() - slotFree.get(slot);
|
||||
executor.sendMessage(Config.error_occurred(r.errorMessage));
|
||||
}
|
||||
|
||||
for (int i = amountInSlot; i < product.getMaxStackSize(); i++) {
|
||||
if (leftAmount > 0) {
|
||||
} 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();
|
||||
leftAmount--;
|
||||
} else if (leftAmount == 0) {
|
||||
executor.sendMessage(Config.sell_success_admin(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
executor.sendMessage(Config.error_occurred(r2.errorMessage));
|
||||
}
|
||||
} else {
|
||||
executor.sendMessage(Config.error_occurred(r.errorMessage));
|
||||
}
|
||||
} else {
|
||||
executor.sendMessage(Config.chest_not_enough_inventory_space());
|
||||
}
|
||||
} else {
|
||||
executor.sendMessage(Config.vendor_not_enough_money());
|
||||
}
|
||||
|
||||
|
||||
} else if (shop.getShopType() == ShopType.ADMIN) {
|
||||
|
||||
EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
|
||||
|
||||
if (r.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_admin(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice()));
|
||||
} else {
|
||||
executor.sendMessage(Config.error_occurred(r.errorMessage));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user