|
|
|
|
@ -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<CommandSourceStack> createCommand() { |
|
|
|
|
return Commands.literal("gopen") |
|
|
|
|
.executes(GuiCommand::obtainGui); |
|
|
|
|
.then(Commands.argument("id", StringArgumentType.string()) |
|
|
|
|
.executes(GuiCommand::openGui)) |
|
|
|
|
.executes(GuiCommand::getAll); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static int openGui(CommandContext<CommandSourceStack> 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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static int obtainGui(CommandContext<CommandSourceStack> context){ |
|
|
|
|
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<CommandSourceStack> 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<String, Gui> 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<String, Gui> guiMap, CommandSender commandSender){ |
|
|
|
|
HashMap<String, String> stringGuis = new HashMap<>(); |
|
|
|
|
int index = 1; |
|
|
|
|
|
|
|
|
|
for (Map.Entry<String, Gui> 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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|