diff --git a/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java b/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java index 6b469c7..73bfa67 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java @@ -1,23 +1,46 @@ package xyz.soukup.ecoCraftCore.commands; +import com.mojang.brigadier.arguments.StringArgumentType; import io.papermc.paper.command.brigadier.CommandSourceStack; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import io.papermc.paper.command.brigadier.Commands; import com.mojang.brigadier.context.CommandContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import xyz.soukup.ecoCraftCore.utilities.Messages; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; import dev.triumphteam.gui.guis.Gui; import org.bukkit.entity.Player; +import java.util.HashMap; +import java.util.Map; + public class GuiCommand { + private static final Logger log = LoggerFactory.getLogger(GuiCommand.class); + public static LiteralArgumentBuilder createCommand() { return Commands.literal("gopen") - .executes(GuiCommand::obtainGui); + .then(Commands.argument("id", StringArgumentType.string()) + .executes(GuiCommand::openGui)) + .executes(GuiCommand::getAll); } - private static int obtainGui(CommandContext context){ + private static int openGui(CommandContext context){ + CommandSender commandSender = context.getSource().getSender(); + String guiId = context.getArgument("id", String.class); + + if (!(commandSender instanceof Player)){ + Messages.send(commandSender, "generic.error.not-player"); + return 0; + } + + Gui gui = getGui(guiId, false, commandSender); // Pokud najdeme gui vrátíme ho, pokud ne vrátíme default gui + gui.open((Player) commandSender); + return 1; + } + private static int getAll(CommandContext context){ CommandSender commandSender = context.getSource().getSender(); if (!(commandSender instanceof Player)){ @@ -25,13 +48,52 @@ public class GuiCommand { return 0; } - Gui gui = Gui.gui() - .title(Component.text("GUI Title!")) + getGui("", true, commandSender); // Pokud najdeme gui vrátíme ho, pokud ne vrátíme default gui + return 1; + } + + private static Gui getGui(String guiId, Boolean getAll, CommandSender commandSender){ + // Mapa gui objektů + Map guiMap = new HashMap<>(); + + // Všechny gui objekty + Gui gui1 = Gui.gui() + .title(Component.text("Default GUI Title")) .rows(6) .create(); - gui.open((Player) commandSender); - return 1; + Gui gui2 = Gui.gui() + .title(Component.text("GUI Title 1")) + .rows(6) + .create(); + + Gui gui3 = Gui.gui() + .title(Component.text("GUI Title 2")) + .rows(6) + .create(); + + guiMap.put("default", gui1); + guiMap.put("test1", gui2); + guiMap.put("test2", gui3); + + if (getAll){ + printAll(guiMap, commandSender); + } + + return guiMap.getOrDefault(guiId, gui1); + } + + private static void printAll(Map guiMap, CommandSender commandSender){ + HashMap stringGuis = new HashMap<>(); + int index = 1; + + for (Map.Entry entry : guiMap.entrySet()) { + String guiName = entry.getKey(); + stringGuis.put(String.valueOf(index), guiName); + index++; // Každý číslo je placeholder v messages, pokud se změní počet gui musí se editnout i messages.yml + } + + Messages.send(commandSender, "gui.all", stringGuis); } } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 3479051..867e8b7 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -46,4 +46,6 @@ marker: menu: shop: buy: "Koupit ks za $" - sell: "Prodat ks za $" \ No newline at end of file + sell: "Prodat ks za $" +gui: + all: "Seznam guis: <1>, <2>, <3>" \ No newline at end of file