commit
d881cade87
5 changed files with 153 additions and 5 deletions
@ -0,0 +1,116 @@ |
|||||||
|
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; |
||||||
|
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; |
||||||
|
import org.bukkit.Material; |
||||||
|
|
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
public class GuiCommand { |
||||||
|
public static LiteralArgumentBuilder<CommandSourceStack> createCommand() { |
||||||
|
return Commands.literal("gopen") |
||||||
|
.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; |
||||||
|
} |
||||||
|
|
||||||
|
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)){ |
||||||
|
Messages.send(commandSender, "generic.error.not-player"); |
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
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<>(); |
||||||
|
|
||||||
|
// Default gui
|
||||||
|
Gui gui1 = Gui.gui() // U custom gui dávat vždycky "GUI -" -> ../events/InventoryActionCancel
|
||||||
|
.title(Component.text("GUI - Default")) |
||||||
|
.rows(6) |
||||||
|
.create(); |
||||||
|
|
||||||
|
// 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("shop-admin", shopAdminGui); |
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue