From 381cf0b94e5be693f7f9446ef8dcf21bb35e1d41 Mon Sep 17 00:00:00 2001 From: Gioth8281 Date: Wed, 25 Jun 2025 15:11:20 +0200 Subject: [PATCH 1/5] Added Gui Command --- .../xyz/soukup/ecoCraftCore/EcoCraftCore.java | 2 + .../ecoCraftCore/commands/GuiCommand.java | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java diff --git a/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java b/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java index b920bdc..4904361 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java @@ -9,6 +9,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; +import xyz.soukup.ecoCraftCore.commands.GuiCommand; import xyz.soukup.ecoCraftCore.commands.MoneyCommand; import xyz.soukup.ecoCraftCore.commands.RulerCommand; import xyz.soukup.ecoCraftCore.commands.ShopCommand; @@ -98,6 +99,7 @@ public final class EcoCraftCore extends JavaPlugin { lm.registerEventHandler(LifecycleEvents.COMMANDS, event -> event.registrar().register(ShopCommand.createCommand().build())); lm.registerEventHandler(LifecycleEvents.COMMANDS, event -> event.registrar().register(RulerCommand.createCommand().build())); lm.registerEventHandler(LifecycleEvents.COMMANDS, event -> event.registrar().register(MoneyCommand.createCommand().build())); + lm.registerEventHandler(LifecycleEvents.COMMANDS, event -> event.registrar().register(GuiCommand.createCommand().build())); } private void registerEvents(){ diff --git a/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java b/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java new file mode 100644 index 0000000..6b469c7 --- /dev/null +++ b/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java @@ -0,0 +1,37 @@ +package xyz.soukup.ecoCraftCore.commands; + +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 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; + +public class GuiCommand { + public static LiteralArgumentBuilder createCommand() { + return Commands.literal("gopen") + .executes(GuiCommand::obtainGui); + } + + private static int obtainGui(CommandContext context){ + + CommandSender commandSender = context.getSource().getSender(); + + if (!(commandSender instanceof Player)){ + Messages.send(commandSender, "generic.error.not-player"); + return 0; + } + + Gui gui = Gui.gui() + .title(Component.text("GUI Title!")) + .rows(6) + .create(); + + gui.open((Player) commandSender); + return 1; + } +} + -- 2.34.1 From 2411d6fe90f4fbf8b1859899ae6283d75e9561af Mon Sep 17 00:00:00 2001 From: Gioth8281 Date: Wed, 25 Jun 2025 15:57:08 +0200 Subject: [PATCH 2/5] Finished Gui Command Template --- .../ecoCraftCore/commands/GuiCommand.java | 74 +++++++++++++++++-- src/main/resources/messages.yml | 4 +- 2 files changed, 71 insertions(+), 7 deletions(-) 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 -- 2.34.1 From 3a7471e15022b902297b2aaeda09be30ff7ffdd1 Mon Sep 17 00:00:00 2001 From: Gioth8281 Date: Wed, 25 Jun 2025 15:57:53 +0200 Subject: [PATCH 3/5] Remove Unnecessary Variable in Gui Command --- src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java b/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java index 73bfa67..5778616 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java @@ -17,8 +17,6 @@ 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") .then(Commands.argument("id", StringArgumentType.string()) -- 2.34.1 From c9051407f003ad81ae4f0714c16c1b016856ed8b Mon Sep 17 00:00:00 2001 From: Gioth8281 Date: Wed, 25 Jun 2025 15:58:04 +0200 Subject: [PATCH 4/5] Remove Unnecessary Variable in Gui Command --- src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java b/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java index 5778616..7f7b8ef 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java @@ -5,8 +5,6 @@ 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; -- 2.34.1 From b03e2cd21028f2dbe3ae82a7b57fd9cf007ea121 Mon Sep 17 00:00:00 2001 From: Gioth8281 Date: Wed, 25 Jun 2025 20:06:36 +0200 Subject: [PATCH 5/5] Finished Shop Admin GUI template + 'might come hany' function in Messages.java --- .../xyz/soukup/ecoCraftCore/EcoCraftCore.java | 7 ++- .../ecoCraftCore/commands/GuiCommand.java | 47 ++++++++++++++----- .../events/InventoryActionCancel.java | 17 +++++++ .../ecoCraftCore/utilities/Messages.java | 4 ++ src/main/resources/messages.yml | 10 +++- 5 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 src/main/java/xyz/soukup/ecoCraftCore/events/InventoryActionCancel.java diff --git a/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java b/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java index 4904361..20a6fa8 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/EcoCraftCore.java @@ -13,10 +13,7 @@ import xyz.soukup.ecoCraftCore.commands.GuiCommand; import xyz.soukup.ecoCraftCore.commands.MoneyCommand; import xyz.soukup.ecoCraftCore.commands.RulerCommand; import xyz.soukup.ecoCraftCore.commands.ShopCommand; -import xyz.soukup.ecoCraftCore.events.PreparePlayer; -import xyz.soukup.ecoCraftCore.events.RulerMarking; -import xyz.soukup.ecoCraftCore.events.ShopLogic; -import xyz.soukup.ecoCraftCore.events.VirtualChestLogic; +import xyz.soukup.ecoCraftCore.events.*; import xyz.soukup.ecoCraftCore.objects.Account; import xyz.soukup.ecoCraftCore.objects.Shop; import xyz.soukup.ecoCraftCore.objects.Transaction; @@ -109,6 +106,8 @@ public final class EcoCraftCore extends JavaPlugin { pm.registerEvents(new VirtualChestLogic(), this); pm.registerEvents(new ShopLogic(), this); pm.registerEvents(new PreparePlayer(), this); + pm.registerEvents(new InventoryActionCancel(), this); + } diff --git a/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java b/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java index 7f7b8ef..20a69cd 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/commands/GuiCommand.java @@ -1,6 +1,8 @@ package xyz.soukup.ecoCraftCore.commands; import com.mojang.brigadier.arguments.StringArgumentType; +import dev.triumphteam.gui.builder.item.ItemBuilder; +import dev.triumphteam.gui.guis.GuiItem; import io.papermc.paper.command.brigadier.CommandSourceStack; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import io.papermc.paper.command.brigadier.Commands; @@ -10,6 +12,7 @@ import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; import dev.triumphteam.gui.guis.Gui; import org.bukkit.entity.Player; +import org.bukkit.Material; import java.util.HashMap; import java.util.Map; @@ -52,25 +55,43 @@ public class GuiCommand { // Mapa gui objektů Map guiMap = new HashMap<>(); - // Všechny gui objekty - Gui gui1 = Gui.gui() - .title(Component.text("Default GUI Title")) + // Default gui + Gui gui1 = Gui.gui() // U custom gui dávat vždycky "GUI -" -> ../events/InventoryActionCancel + .title(Component.text("GUI - Default")) .rows(6) .create(); - 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) + // Shop Admin gui + Gui shopAdminGui = Gui.gui() + .title(Messages.get("gui.shopadmin.title")) + .rows(3) .create(); + shopAdminGui.getFiller().fill(ItemBuilder.from(Material.BLACK_STAINED_GLASS_PANE) + .name(Messages.get("gui.shopadmin.items.background")).asGuiItem()); + GuiItem deleteShop = ItemBuilder.from(Material.BARRIER).name(Messages.get("gui.shopadmin.items.deleteshop")) + .asGuiItem(event -> { + // Zde delete shop + }); + GuiItem changeSellPrice = ItemBuilder.from(Material.OAK_SIGN).name(Messages.get("gui.shopadmin.items.changesellprice")) + .asGuiItem(event -> { + // Zde change sell price + }); + GuiItem changeBuyPrice = ItemBuilder.from(Material.DARK_OAK_SIGN).name(Messages.get("gui.shopadmin.items.changebuyprice")) + .asGuiItem(event -> { + // Zde change buy price + }); + GuiItem changeAmounts = ItemBuilder.from(Material.GOLD_BLOCK).name(Messages.get("gui.shopadmin.items.changeamounts")) + .asGuiItem(event -> { + // Zde change amounts + }); + + shopAdminGui.setItem(22, deleteShop); + shopAdminGui.setItem(15, changeBuyPrice); + shopAdminGui.setItem(11, changeSellPrice); + shopAdminGui.setItem(13, changeAmounts); guiMap.put("default", gui1); - guiMap.put("test1", gui2); - guiMap.put("test2", gui3); + guiMap.put("shop-admin", shopAdminGui); if (getAll){ printAll(guiMap, commandSender); diff --git a/src/main/java/xyz/soukup/ecoCraftCore/events/InventoryActionCancel.java b/src/main/java/xyz/soukup/ecoCraftCore/events/InventoryActionCancel.java new file mode 100644 index 0000000..6b77ec9 --- /dev/null +++ b/src/main/java/xyz/soukup/ecoCraftCore/events/InventoryActionCancel.java @@ -0,0 +1,17 @@ +package xyz.soukup.ecoCraftCore.events; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.event.inventory.InventoryClickEvent; + +public class InventoryActionCancel implements Listener { + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + if (event.getView().getTitle().contains("GUI -")) { + if (!ClickType.valueOf(event.getClick().name()).toString().isEmpty()) { + event.setCancelled(true); + } + } + } +} diff --git a/src/main/java/xyz/soukup/ecoCraftCore/utilities/Messages.java b/src/main/java/xyz/soukup/ecoCraftCore/utilities/Messages.java index 03bf012..8ec0439 100644 --- a/src/main/java/xyz/soukup/ecoCraftCore/utilities/Messages.java +++ b/src/main/java/xyz/soukup/ecoCraftCore/utilities/Messages.java @@ -40,6 +40,10 @@ public class Messages { return MiniMessage.miniMessage().deserialize(string); } + public static String getAsString(String key){ + return MiniMessage.miniMessage().serialize(Messages.get(key)); + } + public static Component get(String key, HashMap placeholders){ String string = getString(key); diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 867e8b7..2651e95 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -48,4 +48,12 @@ menu: buy: "Koupit ks za $" sell: "Prodat ks za $" gui: - all: "Seznam guis: <1>, <2>, <3>" \ No newline at end of file + all: "Seznam guis: <1>, <2>" + shopadmin: + title: "GUI - Shop Admin" + items: + background: " " + deleteshop: "Smazat Obchod" + changesellprice: "Změnit Prodávající Cenu" + changebuyprice: "Změnit Kupující Cenu" + changeamounts: "Změnit Množství Prodeje a Výkupu" -- 2.34.1