From 5f9afca2860b58852814a88d7e78387ec77d759a Mon Sep 17 00:00:00 2001 From: jakub Date: Wed, 1 May 2024 10:05:06 +0200 Subject: [PATCH] shopaholic code --- .../mineconomiacore/commands/shop.java | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/main/java/xyz/mineconomia/mineconomiacore/commands/shop.java diff --git a/src/main/java/xyz/mineconomia/mineconomiacore/commands/shop.java b/src/main/java/xyz/mineconomia/mineconomiacore/commands/shop.java new file mode 100644 index 0000000..bbfd33c --- /dev/null +++ b/src/main/java/xyz/mineconomia/mineconomiacore/commands/shop.java @@ -0,0 +1,115 @@ +package xyz.mineconomia.mineconomiacore.commands; + +import com.arangodb.ArangoCollection; +import com.arangodb.entity.BaseDocument; +import com.arangodb.entity.BaseEdgeDocument; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.Container; +import org.bukkit.block.Sign; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import xyz.mineconomia.mineconomiacore.events.specialEvents; + +import java.util.List; + +import static xyz.mineconomia.mineconomiacore.config.config; +import static xyz.mineconomia.mineconomiacore.database.database; + +public class shop implements TabExecutor { + @Override + public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] args) { + if (args.length != 3){ + commandSender.sendMessage(ChatColor.RED + "Špatné množství argumentů"); + return false; + } + if (!(commandSender instanceof Player player)){ + commandSender.sendMessage(ChatColor.RED + "Musíš být hráč"); + return false; + } + if (!(specialEvents.specialPreLocations.get(player).size() < 2)){ + commandSender.sendMessage(ChatColor.RED + "Musíš mít označenou cedulku a úložiště"); + return false; + } + Block block1 = specialEvents.specialPreLocations.get(player).get("loc1").getBlock(); + Block block2 = specialEvents.specialPreLocations.get(player).get("loc2").getBlock(); + + Container container; + if (block1 instanceof Container){ + container = (Container) block1; + } else if (block2 instanceof Container) { + container = (Container) block2; + }else { + commandSender.sendMessage(ChatColor.RED + "Nemáš ozačené úložiště"); + return false; + } + Sign sign; + if (block1 instanceof Sign){ + sign = (Sign) block1; + } else if (block2 instanceof Sign) { + sign = (Sign) block2; + }else { + commandSender.sendMessage(ChatColor.RED + "Nemáš označenou cedulku"); + return false; + } + ItemStack handyItem = player.getInventory().getItemInMainHand(); + if (handyItem.getType() == Material.AIR){ + commandSender.sendMessage(ChatColor.RED + "Nemáš v ruce item, který chceš prodávat"); + return false; + } + if (handyItem == config.get("special.item")){ + commandSender.sendMessage(ChatColor.RED + "Nemůžeš prodat pravítko. nečekaně..."); + return false; + } + if (!isDouble(args[1]) || !isDouble(args[2])){ + commandSender.sendMessage(ChatColor.RED + "Cena a počet kusů musí být čísla!"); + return false; + } + BaseDocument shopDocument = new BaseDocument(); + String shopRegime; + switch (args[0]){ + case "buy": + case "prodej": + shopRegime = "buy"; + break; + case "sell": + case "výkup": + shopRegime = "sell"; + break; + default: + commandSender.sendMessage(ChatColor.RED + "Neplatný režim obchodu"); + return false; + } + shopDocument.addAttribute("signLocation", sign.getLocation()); + shopDocument.addAttribute("storageLocation", container.getLocation()); + shopDocument.addAttribute("count", args[1]); + shopDocument.addAttribute("type", "playerLimited"); + shopDocument.addAttribute("regime", shopRegime); + BaseEdgeDocument ownershipEdge = new BaseEdgeDocument(); + ArangoCollection playersCollection = database.collection("shops"); + return true; + + } + + @Nullable + @Override + public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) { + return List.of(); + } + + public boolean isDouble(String input ) { + try { + Double.parseDouble(input); + return true; + } + catch( Exception e ) { + return false; + } + } +}