|
|
|
@ -20,8 +20,11 @@ import xyz.soukup.ecoCraftCore.objects.Transaction; |
|
|
|
import xyz.soukup.ecoCraftCore.objects.VirtualChest; |
|
|
|
import xyz.soukup.ecoCraftCore.objects.VirtualChest; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.Converter; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.Converter; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.InventoryUtils; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.InventoryUtils; |
|
|
|
|
|
|
|
import xyz.soukup.ecoCraftCore.utilities.Messages; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.PDC; |
|
|
|
import xyz.soukup.ecoCraftCore.utilities.PDC; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
|
|
|
|
public class ShopLogic implements Listener { |
|
|
|
public class ShopLogic implements Listener { |
|
|
|
|
|
|
|
|
|
|
|
@EventHandler |
|
|
|
@EventHandler |
|
|
|
@ -52,12 +55,13 @@ public class ShopLogic implements Listener { |
|
|
|
|
|
|
|
|
|
|
|
event.setCancelled(true); |
|
|
|
event.setCancelled(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Player player = event.getPlayer(); |
|
|
|
|
|
|
|
|
|
|
|
if (VirtualChestLogic.openedChests.containsKey(shop.getVirtualChestID())){ |
|
|
|
if (VirtualChestLogic.openedChests.containsKey(shop.getVirtualChestID())){ |
|
|
|
event.getPlayer().sendPlainMessage("to by neslo"); |
|
|
|
Messages.send(player, "shop.error.chest-open"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Player player = event.getPlayer(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Gui gui = buildShopGui(player, shop); |
|
|
|
Gui gui = buildShopGui(player, shop); |
|
|
|
|
|
|
|
|
|
|
|
@ -78,18 +82,26 @@ public class ShopLogic implements Listener { |
|
|
|
int amount = shop.getAmount(); |
|
|
|
int amount = shop.getAmount(); |
|
|
|
|
|
|
|
|
|
|
|
if (buyPrice != 0){ |
|
|
|
if (buyPrice != 0){ |
|
|
|
|
|
|
|
HashMap<String, String> hashMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hashMap.put("amount", Integer.toString(amount)); |
|
|
|
|
|
|
|
hashMap.put("price", String.format("%.2f", buyPrice)); |
|
|
|
|
|
|
|
|
|
|
|
GuiItem one = ItemBuilder |
|
|
|
GuiItem one = ItemBuilder |
|
|
|
.from(Material.LIME_WOOL) |
|
|
|
.from(Material.LIME_WOOL) |
|
|
|
.name(Converter.toComponent("&aKoupit " + amount + "ks za " + String.format("%.2f", buyPrice))) |
|
|
|
.name(Messages.get("menu.shop.buy", hashMap)) |
|
|
|
.asGuiItem(); |
|
|
|
.asGuiItem(); |
|
|
|
one.setAction(event -> { |
|
|
|
one.setAction(event -> { |
|
|
|
event.setCancelled(true); |
|
|
|
event.setCancelled(true); |
|
|
|
ShopLogic.buy(shop, player, 1); |
|
|
|
ShopLogic.buy(shop, player, 1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hashMap.put("amount", Integer.toString(amount*8)); |
|
|
|
|
|
|
|
hashMap.put("price", String.format("%.2f", buyPrice*8)); |
|
|
|
|
|
|
|
|
|
|
|
GuiItem eight = ItemBuilder |
|
|
|
GuiItem eight = ItemBuilder |
|
|
|
.from(Material.LIME_WOOL) |
|
|
|
.from(Material.LIME_WOOL) |
|
|
|
.name(Converter.toComponent("&aKoupit " + amount*8 + "ks za " + String.format("%.2f", buyPrice*8))) |
|
|
|
.name(Messages.get("menu.shop.buy", hashMap)) |
|
|
|
.asGuiItem(); |
|
|
|
.asGuiItem(); |
|
|
|
eight.setAction(event -> { |
|
|
|
eight.setAction(event -> { |
|
|
|
event.setCancelled(true); |
|
|
|
event.setCancelled(true); |
|
|
|
@ -102,9 +114,14 @@ public class ShopLogic implements Listener { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (sellPrice != 0){ |
|
|
|
if (sellPrice != 0){ |
|
|
|
|
|
|
|
HashMap<String, String> hashMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hashMap.put("amount", Integer.toString(amount)); |
|
|
|
|
|
|
|
hashMap.put("price", String.format("%.2f", sellPrice)); |
|
|
|
|
|
|
|
|
|
|
|
GuiItem one = ItemBuilder |
|
|
|
GuiItem one = ItemBuilder |
|
|
|
.from(Material.YELLOW_WOOL) |
|
|
|
.from(Material.YELLOW_WOOL) |
|
|
|
.name(Converter.toComponent("&eProdat " + amount + "ks za " + String.format("%.2f", sellPrice))) |
|
|
|
.name(Messages.get("menu.shop.sell", hashMap)) |
|
|
|
.asGuiItem(); |
|
|
|
.asGuiItem(); |
|
|
|
|
|
|
|
|
|
|
|
one.setAction(event -> { |
|
|
|
one.setAction(event -> { |
|
|
|
@ -112,9 +129,13 @@ public class ShopLogic implements Listener { |
|
|
|
ShopLogic.sell(shop, player, 1); |
|
|
|
ShopLogic.sell(shop, player, 1); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hashMap.put("amount", Integer.toString(amount*8)); |
|
|
|
|
|
|
|
hashMap.put("price", String.format("%.2f", sellPrice*8)); |
|
|
|
|
|
|
|
|
|
|
|
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(Messages.get("menu.shop.sell", hashMap)) |
|
|
|
.asGuiItem(); |
|
|
|
.asGuiItem(); |
|
|
|
|
|
|
|
|
|
|
|
eight.setAction(event -> { |
|
|
|
eight.setAction(event -> { |
|
|
|
@ -140,7 +161,7 @@ public class ShopLogic implements Listener { |
|
|
|
public static void buy(Shop shop, Player player, int multiplier){ |
|
|
|
public static void buy(Shop shop, Player player, int multiplier){ |
|
|
|
|
|
|
|
|
|
|
|
if (VirtualChestLogic.openedChests.containsKey(shop.getVirtualChestID())){ |
|
|
|
if (VirtualChestLogic.openedChests.containsKey(shop.getVirtualChestID())){ |
|
|
|
player.sendPlainMessage("to by neslo"); |
|
|
|
Messages.send(player, "shop.error.chest-open"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -152,7 +173,7 @@ public class ShopLogic implements Listener { |
|
|
|
Account account = Account.getOrCreate(player); |
|
|
|
Account account = Account.getOrCreate(player); |
|
|
|
|
|
|
|
|
|
|
|
if (price > account.getBalance()){ |
|
|
|
if (price > account.getBalance()){ |
|
|
|
player.sendPlainMessage("nemaš dost mony"); |
|
|
|
Messages.send(player, "generic.error.no-money.self"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -165,12 +186,12 @@ public class ShopLogic implements Listener { |
|
|
|
Inventory playerInventory = player.getInventory(); |
|
|
|
Inventory playerInventory = player.getInventory(); |
|
|
|
|
|
|
|
|
|
|
|
if (InventoryUtils.getSpaceLeft(playerInventory, itemStack) < amount){ |
|
|
|
if (InventoryUtils.getSpaceLeft(playerInventory, itemStack) < amount){ |
|
|
|
player.sendPlainMessage("Nemáš dost místa v invu"); |
|
|
|
Messages.send(player, "generic.error.no-space.self"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!virtualChest.removeItem(itemStack)){ |
|
|
|
if (!virtualChest.removeItem(itemStack)){ |
|
|
|
player.sendPlainMessage("není dost věcí v chestce"); |
|
|
|
Messages.send(player, "generic.error.no-item.shop"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -182,12 +203,19 @@ public class ShopLogic implements Listener { |
|
|
|
|
|
|
|
|
|
|
|
transaction.process(); |
|
|
|
transaction.process(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HashMap<String, String> hashMap = new HashMap<>(); |
|
|
|
|
|
|
|
hashMap.put("count", Integer.toString(amount)); |
|
|
|
|
|
|
|
hashMap.put("price", String.format("%.2f", price)); |
|
|
|
|
|
|
|
hashMap.put("item", itemStack.displayName().toString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Messages.send(player, "shop.buy", hashMap); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void sell(Shop shop, Player player, int multiplier){ |
|
|
|
public static void sell(Shop shop, Player player, int multiplier){ |
|
|
|
|
|
|
|
|
|
|
|
if (VirtualChestLogic.openedChests.containsKey(shop.getVirtualChestID())){ |
|
|
|
if (VirtualChestLogic.openedChests.containsKey(shop.getVirtualChestID())){ |
|
|
|
player.sendPlainMessage("to by neslo"); |
|
|
|
Messages.send(player, "shop.error.chest-open"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -199,7 +227,7 @@ public class ShopLogic implements Listener { |
|
|
|
Account account = Account.getOrCreate(shop.getOwnerType(), shop.getOwner()); |
|
|
|
Account account = Account.getOrCreate(shop.getOwnerType(), shop.getOwner()); |
|
|
|
|
|
|
|
|
|
|
|
if (price > account.getBalance()){ |
|
|
|
if (price > account.getBalance()){ |
|
|
|
player.sendPlainMessage("shop nemá mony"); |
|
|
|
Messages.send(player, "generic.error.no-money.self"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -212,12 +240,12 @@ public class ShopLogic implements Listener { |
|
|
|
Inventory playerInventory = player.getInventory(); |
|
|
|
Inventory playerInventory = player.getInventory(); |
|
|
|
|
|
|
|
|
|
|
|
if (InventoryUtils.getCount(playerInventory, itemStack) < amount){ |
|
|
|
if (InventoryUtils.getCount(playerInventory, itemStack) < amount){ |
|
|
|
player.sendPlainMessage("nemáš prodejní itemy"); |
|
|
|
Messages.send(player, "generic.error.no-item.self"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!virtualChest.addItem(itemStack)){ |
|
|
|
if (!virtualChest.addItem(itemStack)){ |
|
|
|
player.sendPlainMessage("není dost místa v chestce"); |
|
|
|
Messages.send(player, "generic.error.no-space.shop"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -228,5 +256,12 @@ public class ShopLogic implements Listener { |
|
|
|
Transaction transaction = new Transaction(price, "player", shop.getOwner(), "player", player.getName(), "playerShop", shop.getItemName() ,Integer.toString(amount)); |
|
|
|
Transaction transaction = new Transaction(price, "player", shop.getOwner(), "player", player.getName(), "playerShop", shop.getItemName() ,Integer.toString(amount)); |
|
|
|
transaction.process(); |
|
|
|
transaction.process(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HashMap<String, String> hashMap = new HashMap<>(); |
|
|
|
|
|
|
|
hashMap.put("count", Integer.toString(amount)); |
|
|
|
|
|
|
|
hashMap.put("price", String.format("%.2f", price)); |
|
|
|
|
|
|
|
hashMap.put("item", itemStack.displayName().toString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Messages.send(player, "shop.sell", hashMap); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|