parent
fa9494724b
commit
5f9afca286
1 changed files with 115 additions and 0 deletions
@ -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<String> 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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue