|
|
|
@ -44,6 +44,11 @@ public class ShopLogic implements Listener { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (VirtualChestLogic.openedChests.containsKey(id)){ |
|
|
|
|
|
|
|
event.getPlayer().sendPlainMessage("to by neslo"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Shop shop = Shop.findById(id); |
|
|
|
Shop shop = Shop.findById(id); |
|
|
|
|
|
|
|
|
|
|
|
if (shop == null){ |
|
|
|
if (shop == null){ |
|
|
|
@ -102,11 +107,21 @@ public class ShopLogic implements Listener { |
|
|
|
.name(Converter.toComponent("&eProdat " + amount + "ks za " + String.format("%.2f", sellPrice))) |
|
|
|
.name(Converter.toComponent("&eProdat " + amount + "ks za " + String.format("%.2f", sellPrice))) |
|
|
|
.asGuiItem(); |
|
|
|
.asGuiItem(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
one.setAction(event -> { |
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
|
|
|
ShopLogic.sell(shop, player, 1); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
GuiItem eight = ItemBuilder |
|
|
|
GuiItem eight = ItemBuilder |
|
|
|
.from(Material.YELLOW_WOOL) |
|
|
|
.from(Material.YELLOW_WOOL) |
|
|
|
.name(Converter.toComponent("&eProdat " + amount*8 + "ks za " + String.format("%.2f", sellPrice*8))) |
|
|
|
.name(Converter.toComponent("&eProdat " + amount*8 + "ks za " + String.format("%.2f", sellPrice*8))) |
|
|
|
.asGuiItem(); |
|
|
|
.asGuiItem(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eight.setAction(event -> { |
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
|
|
|
|
ShopLogic.sell(shop, player, 8); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
gui.setItem(7, one); |
|
|
|
gui.setItem(7, one); |
|
|
|
gui.setItem(8, eight); |
|
|
|
gui.setItem(8, eight); |
|
|
|
|
|
|
|
|
|
|
|
@ -153,10 +168,54 @@ public class ShopLogic implements Listener { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
playerInventory.addItem(itemStack); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
virtualChest.save(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Transaction transaction = new Transaction(price, "player", player.getName(), "player", shop.getOwner(), "playerShop", shop.getItemName() ,Integer.toString(amount)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transaction.process(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void sell(Shop shop, Player player, int multiplier){ |
|
|
|
|
|
|
|
int amount = shop.getAmount() * multiplier; |
|
|
|
|
|
|
|
float price = shop.getPriceSell() * multiplier; |
|
|
|
|
|
|
|
ItemStack itemStack = shop.getItemStack(); |
|
|
|
|
|
|
|
itemStack.setAmount(amount); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Account account = Account.getOrCreate(shop.getOwnerType(), shop.getOwner()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (price > account.getBalance()){ |
|
|
|
|
|
|
|
player.sendPlainMessage("shop nemá mony"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VirtualChest virtualChest = VirtualChest.findById(shop.getVirtualChestID()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (virtualChest == null){ |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inventory playerInventory = player.getInventory(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (InventoryUtils.getCount(playerInventory, itemStack) < amount){ |
|
|
|
|
|
|
|
player.sendPlainMessage("nemáš prodejní itemy"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!virtualChest.addItem(itemStack)){ |
|
|
|
|
|
|
|
player.sendPlainMessage("není dost místa v chestce"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
playerInventory.removeItem(itemStack); |
|
|
|
playerInventory.removeItem(itemStack); |
|
|
|
|
|
|
|
|
|
|
|
new Transaction(price, "player", player.getName(), "player", shop.getOwner(), "playerShop", shop.getItemName() ,Integer.toString(amount)); |
|
|
|
virtualChest.save(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Transaction transaction = new Transaction(price, "player", shop.getOwner(), "player", player.getName(), "playerShop", shop.getItemName() ,Integer.toString(amount)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
transaction.process(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|