Guis
This commit is contained in:
parent
ab94e7f557
commit
9938367f72
11
pom.xml
11
pom.xml
|
@ -67,11 +67,16 @@
|
|||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>xyz.twovb.toolbox</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}.toolbox</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.github.stefvanschie.inventoryframework</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}.inventoryframework</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -159,7 +164,11 @@
|
|||
<artifactId>commons-io</artifactId>
|
||||
<version>2.16.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.stefvanschie.inventoryframework</groupId>
|
||||
<artifactId>IF</artifactId>
|
||||
<version>0.10.15</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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<String> 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);
|
||||
|
|
55
src/main/java/xyz/twovb/sgm/guis/InitGameGui.java
Normal file
55
src/main/java/xyz/twovb/sgm/guis/InitGameGui.java
Normal file
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
77
src/main/java/xyz/twovb/sgm/guis/MapGui.java
Normal file
77
src/main/java/xyz/twovb/sgm/guis/MapGui.java
Normal file
|
@ -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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
19
src/main/resources/guis/initgame.xml
Normal file
19
src/main/resources/guis/initgame.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!--
|
||||
~ Created by 2vb - 4/7/2024
|
||||
-->
|
||||
|
||||
<chestgui title="New Game" rows="3" onGlobalClick="globalClick">
|
||||
<outlinepane x="0" y="0" length="9" height="3" priority="lowest" repeat="true">
|
||||
<item id="black_stained_glass_pane">
|
||||
<displayname> </displayname>
|
||||
</item>
|
||||
</outlinepane>
|
||||
<outlinepane x="3" y="1" length="3" height="1" gap="1">
|
||||
<item id="nether_brick" onClick="initGame">
|
||||
<displayname>Capture The Brick</displayname>
|
||||
</item>
|
||||
<item id="command_block" onClick="initGame">
|
||||
<displayname>TestGame</displayname>
|
||||
</item>
|
||||
</outlinepane>
|
||||
</chestgui>
|
9
src/main/resources/guis/mapgui.xml
Normal file
9
src/main/resources/guis/mapgui.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<!--
|
||||
~ Created by 2vb - 4/7/2024
|
||||
-->
|
||||
|
||||
<chestgui title="Maps" rows="5" onGlobalClick="globalClick">
|
||||
<outlinepane x="0" y="0" length="9" height="5" priority="lowest" repeat="true">
|
||||
<item id="black_stained_glass_pane" />
|
||||
</outlinepane>
|
||||
</chestgui>
|
Loading…
Reference in New Issue
Block a user