diff --git a/pom.xml b/pom.xml
index 0ce1bf7..34d32e6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,11 +67,16 @@
+ ${project.build.directory}/dependency-reduced-pom.xml
xyz.twovb.toolbox
${project.groupId}.${project.artifactId}.toolbox
+
+ com.github.stefvanschie.inventoryframework
+ ${project.groupId}.${project.artifactId}.inventoryframework
+
@@ -159,7 +164,11 @@
commons-io
2.16.1
-
+
+ com.github.stefvanschie.inventoryframework
+ IF
+ 0.10.15
+
diff --git a/src/main/java/xyz/twovb/sgm/SGM.java b/src/main/java/xyz/twovb/sgm/SGM.java
index c07d7d6..b2b21cc 100644
--- a/src/main/java/xyz/twovb/sgm/SGM.java
+++ b/src/main/java/xyz/twovb/sgm/SGM.java
@@ -40,7 +40,6 @@ public final class SGM extends JavaPlugin {
@Getter
private LevelManager levelManager;
-
@Override
public void onEnable() {
instance = this;
@@ -55,12 +54,18 @@ public final class SGM extends JavaPlugin {
BuildInfo.load(Objects.requireNonNull(this.getTextResource("build-info.yml")));
} catch (IOException | InvalidConfigurationException ignored) {
}
+ loadGuis();
registerCommands();
registerGames();
registerPlaceholders();
levelManager.loadLevels();
}
+ private void loadGuis() {
+ saveResource("guis/initgame.xml", false);
+ saveResource("guis/mapgui.xml", false);
+ }
+
private void registerPlaceholders() {
PlaceholderManager pm = new PlaceholderManager();
pm.registerPlaceholder("%commit.id%", BuildInfo.getString("commit.id"));
diff --git a/src/main/java/xyz/twovb/sgm/commands/impl/GameCommand.java b/src/main/java/xyz/twovb/sgm/commands/impl/GameCommand.java
index d9a9b60..15af353 100644
--- a/src/main/java/xyz/twovb/sgm/commands/impl/GameCommand.java
+++ b/src/main/java/xyz/twovb/sgm/commands/impl/GameCommand.java
@@ -4,6 +4,7 @@ package xyz.twovb.sgm.commands.impl;
* Created by 2vb - 2/7/2024
*/
+import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
@@ -11,13 +12,16 @@ import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.permission.Permission;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.InventoryClickEvent;
import xyz.twovb.sgm.SGM;
import xyz.twovb.sgm.games.Minigame;
import xyz.twovb.sgm.games.impl.TestGame;
import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
+import xyz.twovb.sgm.guis.InitGameGui;
import xyz.twovb.toolbox.api.CustomPlayer;
import xyz.twovb.toolbox.utils.ChatUtils;
+import java.util.Optional;
import java.util.UUID;
@Command(name = "game")
@@ -40,9 +44,10 @@ public class GameCommand {
@Execute(name = "init")
@Permission("sgm.games.init")
- void init(@Context Player player, @Arg("name") String name) {
+ void init(@Context Player player, @Arg("name") Optional map) {
CustomPlayer cPlayer = new CustomPlayer(player);
- SGM.getInstance().getGameManager().initGame(new CTB(), player, name);
+ new InitGameGui().getGui().show(player);
+// SGM.getInstance().getGameManager().initGame(new CTB(), player, name);
}
@Execute(name = "start")
@@ -53,6 +58,11 @@ public class GameCommand {
game.start();
}
+// @Execute(name = "join")
+// void join(@Context Player player) {
+//
+// }
+
@Execute(name = "join")
void join(@Context Player player, @Arg("id") String id) {
CustomPlayer cPlayer = new CustomPlayer(player);
diff --git a/src/main/java/xyz/twovb/sgm/guis/InitGameGui.java b/src/main/java/xyz/twovb/sgm/guis/InitGameGui.java
new file mode 100644
index 0000000..460389e
--- /dev/null
+++ b/src/main/java/xyz/twovb/sgm/guis/InitGameGui.java
@@ -0,0 +1,55 @@
+package xyz.twovb.sgm.guis;
+/*
+ * Created by 2vb - 4/7/2024
+ */
+
+import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
+import lombok.Getter;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import xyz.twovb.sgm.SGM;
+import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.util.logging.Level;
+
+public class InitGameGui {
+
+ @Getter
+ private final ChestGui gui;
+
+ public InitGameGui() {
+ ChestGui loadedGui = null;
+ try {
+ File guiFile = new File(SGM.getInstance().getDataFolder(), "guis/initgame.xml");
+ if (guiFile.exists()) {
+ byte[] fileContent = Files.readAllBytes(guiFile.toPath());
+ InputStream inputStream = new ByteArrayInputStream(fileContent);
+ loadedGui = ChestGui.load(this, inputStream);
+ } else {
+ SGM.getInstance().getLogger().log(Level.WARNING, "Could not find initgame.xml file.");
+ }
+ } catch (Exception e) {
+ SGM.getInstance().getLogger().log(Level.SEVERE, "Error loading initgame.xml", e);
+ }
+ gui = loadedGui;
+ }
+
+ public void globalClick(InventoryClickEvent event) {
+ event.setCancelled(true);
+ }
+
+ public void initGame(InventoryClickEvent event) {
+ Player player = (Player) event.getWhoClicked();
+ String itemName = event.getCurrentItem().getItemMeta().getDisplayName().replaceAll("\\W+", "");
+ player.closeInventory();
+ if (SGM.getInstance().getGameManager().getRegisteredGames().contains(itemName.toLowerCase())) {
+ new MapGui(itemName.toLowerCase()).getGui().show(player);
+ } else {
+ player.sendMessage("Please check xml");
+ }
+ }
+}
diff --git a/src/main/java/xyz/twovb/sgm/guis/MapGui.java b/src/main/java/xyz/twovb/sgm/guis/MapGui.java
new file mode 100644
index 0000000..19705ad
--- /dev/null
+++ b/src/main/java/xyz/twovb/sgm/guis/MapGui.java
@@ -0,0 +1,77 @@
+package xyz.twovb.sgm.guis;
+
+import com.github.stefvanschie.inventoryframework.gui.GuiItem;
+import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
+import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
+import lombok.Getter;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+import xyz.twovb.sgm.SGM;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.util.List;
+import java.util.logging.Level;
+
+public class MapGui {
+
+ @Getter
+ private final ChestGui gui;
+
+ private final String game;
+ private OutlinePane mapPane;
+
+ public MapGui(String game) {
+ this.game = game;
+ ChestGui loadedGui = null;
+ try {
+ File guiFile = new File(SGM.getInstance().getDataFolder(), "guis/mapgui.xml");
+ if (guiFile.exists()) {
+ byte[] fileContent = Files.readAllBytes(guiFile.toPath());
+ InputStream inputStream = new ByteArrayInputStream(fileContent);
+ loadedGui = ChestGui.load(this, inputStream);
+ mapPane = new OutlinePane(1, 1, 7, 1); // Define your pane layout
+ loadedGui.addPane(mapPane);
+ addMaps();
+ } else {
+ SGM.getInstance().getLogger().log(Level.WARNING, "Could not find mapgui.xml file.");
+ }
+ } catch (Exception e) {
+ SGM.getInstance().getLogger().log(Level.SEVERE, "Error loading mapgui.xml", e);
+ }
+ gui = loadedGui;
+ }
+
+ public void globalClick(InventoryClickEvent event) {
+ event.setCancelled(true);
+// event.getWhoClicked().sendMessage(this.game);
+// gui.getInventory().clear();
+ }
+
+ public void addMaps() {
+ List enabledMaps = SGM.getInstance().getLevelManager().enabledMaps.get(this.game);
+ if (enabledMaps != null) {
+ for (String mapName : enabledMaps) {
+ // Create button for each map
+ ItemStack mapItem = new ItemStack(Material.MAP);
+ ItemMeta mapMeta = mapItem.getItemMeta();
+ mapMeta.setDisplayName(mapName);
+ mapItem.setItemMeta(mapMeta);
+
+ mapPane.addItem(new GuiItem(mapItem, event -> {
+ // Handle click event if needed
+ // Example: navigate to the map or show map details
+ Player player = (Player) event.getWhoClicked();
+ player.sendMessage("Clicked on map: " + mapName);
+ }));
+ }
+ } else {
+ SGM.getInstance().getLogger().log(Level.WARNING, "No maps found for game: " + game);
+ }
+ }
+}
diff --git a/src/main/java/xyz/twovb/sgm/levels/LevelManager.java b/src/main/java/xyz/twovb/sgm/levels/LevelManager.java
index 1eb845b..8ccaee1 100644
--- a/src/main/java/xyz/twovb/sgm/levels/LevelManager.java
+++ b/src/main/java/xyz/twovb/sgm/levels/LevelManager.java
@@ -135,6 +135,12 @@ public class LevelManager {
if (mapDir.exists()) {
FileUtils.deleteDirectory(mapDir);
}
+ File configFile = new File(levelDir + "/sgm.yml");
+ YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
+ String gameIntName = config.getString("game");
+ if (SGM.getInstance().getGameManager().getRegisteredGames().contains(gameIntName)) {
+ enabledMaps.get(gameIntName).add(name);
+ }
FileUtils.copyDirectory(levelDir, mapDir);
FileUtils.delete(new File(mapDir + "/uid.dat"));
loadWorld(name, LevelType.LEVEL);
diff --git a/src/main/resources/guis/initgame.xml b/src/main/resources/guis/initgame.xml
new file mode 100644
index 0000000..f6ff7ed
--- /dev/null
+++ b/src/main/resources/guis/initgame.xml
@@ -0,0 +1,19 @@
+
+
+
+
+ -
+
+
+
+
+ -
+ Capture The Brick
+
+ -
+ TestGame
+
+
+
\ No newline at end of file
diff --git a/src/main/resources/guis/mapgui.xml b/src/main/resources/guis/mapgui.xml
new file mode 100644
index 0000000..8374ed4
--- /dev/null
+++ b/src/main/resources/guis/mapgui.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
\ No newline at end of file