mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-26 04:12:22 +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
|
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]
|
||||||
|
@ -401,8 +401,6 @@ 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) {
|
||||||
|
|
||||||
|
if (freeAmount >= leftAmount) {
|
||||||
|
if (econ.getBalance(shop.getVendor()) >= shop.getSellPrice()) {
|
||||||
EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
|
EconomyResponse r = econ.depositPlayer(executor, shop.getSellPrice());
|
||||||
EconomyResponse r2 = null;
|
EconomyResponse r2 = econ.withdrawPlayer(shop.getVendor(), shop.getSellPrice());
|
||||||
if (shop.getShopType() != ShopType.ADMIN) r2 = econ.withdrawPlayer(shop.getVendor(), shop.getSellPrice());
|
|
||||||
|
|
||||||
if (r.transactionSuccess()) {
|
if (r.transactionSuccess()) {
|
||||||
if (r2 != null) {
|
|
||||||
if (r2.transactionSuccess()) {
|
if (r2.transactionSuccess()) {
|
||||||
for (int slot : slotFree.keySet()) {
|
for (int i = leftAmount; i > 0; i--) {
|
||||||
int amountInSlot = product.getMaxStackSize() - slotFree.get(slot);
|
|
||||||
|
|
||||||
for (int i = amountInSlot; i < product.getMaxStackSize(); i++) {
|
|
||||||
if (leftAmount > 0) {
|
|
||||||
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.getBuyPrice(), executor.getName()));
|
if (shop.getVendor().isOnline()) shop.getVendor().getPlayer().sendMessage(Config.someone_sold(product.getAmount(), ItemNames.lookup(product), shop.getSellPrice(), executor.getName()));
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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);
|
}
|
||||||
|
|
||||||
for (int i = amountInSlot; i < product.getMaxStackSize(); i++) {
|
} else {
|
||||||
if (leftAmount > 0) {
|
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());
|
ItemStack soldProduct = new ItemStack(product.clone().getType(), 1, product.clone().getDurability());
|
||||||
soldProduct.setItemMeta(product.clone().getItemMeta());
|
soldProduct.setItemMeta(product.clone().getItemMeta());
|
||||||
executor.getInventory().removeItem(soldProduct);
|
executor.getInventory().removeItem(soldProduct);
|
||||||
executor.updateInventory();
|
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 {
|
} 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 {
|
} else {
|
||||||
executor.sendMessage(Config.vendor_not_enough_money());
|
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