can i finally start working on the actual game T-T
This commit is contained in:
parent
31eb8e1ccb
commit
11d883ac65
|
@ -1,5 +1,10 @@
|
|||
package xyz.twovb.sgm;
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
import dev.rollczi.litecommands.bukkit.LiteBukkitMessages;
|
||||
import dev.rollczi.litecommands.bukkit.LiteCommandsBukkit;
|
||||
import lombok.Getter;
|
||||
|
@ -85,6 +90,8 @@ public final class SGM extends JavaPlugin {
|
|||
saveResource("guis/initgame.xml", false);
|
||||
saveResource("guis/mapgui.xml", false);
|
||||
saveResource("guis/teampicker.xml", false);
|
||||
saveResource("guis/activegames.xml", false);
|
||||
saveResource("guis/joingame.xml", false);
|
||||
}
|
||||
|
||||
private void registerPlaceholders() {
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
package xyz.twovb.sgm.commands.impl;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
@ -16,12 +22,11 @@ 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.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.guis.TeamGui;
|
||||
import xyz.twovb.sgm.guis.InitGameGui;
|
||||
import xyz.twovb.sgm.guis.JoinGameGui;
|
||||
import xyz.twovb.toolbox.api.CustomPlayer;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
|
@ -70,10 +75,10 @@ public class GameCommand {
|
|||
new TeamGui(targetPlayer).getGui().show(player);
|
||||
}
|
||||
|
||||
// @Execute(name = "join")
|
||||
// void join(@Context Player player) {
|
||||
//
|
||||
// }
|
||||
@Execute(name = "testjoin")
|
||||
void testjoin(@Context Player player) {
|
||||
new JoinGameGui().getGui().show(player);
|
||||
}
|
||||
|
||||
@Execute(name = "join")
|
||||
void join(@Context Player player, @Arg("id") String id) {
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package xyz.twovb.sgm.games;
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 4/6/2024
|
||||
*/
|
||||
|
@ -9,7 +14,6 @@ import org.bukkit.NamespacedKey;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
|
@ -43,6 +47,8 @@ public interface Minigame extends Listener {
|
|||
|
||||
GameState getState();
|
||||
|
||||
World getWorld();
|
||||
|
||||
default void sendMessageToAllPlayers(String message) {
|
||||
for (Player player : getPlayers()) {
|
||||
CustomPlayer cPlayer = new CustomPlayer(player);
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
package xyz.twovb.sgm.games.impl;
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 26/6/2024
|
||||
*/
|
||||
|
@ -117,6 +122,12 @@ public class TestGame implements Minigame {
|
|||
return state;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return gameWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
if (state == GameState.STARTED && players.size() <= 1) {
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
package xyz.twovb.sgm.games.impl.capturethebrick;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
@ -17,9 +23,9 @@ import net.megavex.scoreboardlibrary.api.sidebar.component.ComponentSidebarLayou
|
|||
import net.megavex.scoreboardlibrary.api.sidebar.component.SidebarComponent;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.component.animation.CollectionSidebarAnimation;
|
||||
import net.megavex.scoreboardlibrary.api.sidebar.component.animation.SidebarAnimation;
|
||||
import net.megavex.scoreboardlibrary.api.team.ScoreboardTeam;
|
||||
import net.megavex.scoreboardlibrary.api.team.TeamDisplay;
|
||||
import net.megavex.scoreboardlibrary.api.team.TeamManager;
|
||||
import net.megavex.scoreboardlibrary.api.team.ScoreboardTeam;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
@ -33,8 +39,9 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.GameManager;
|
||||
|
@ -55,18 +62,22 @@ public class CTB implements Minigame {
|
|||
private final ArrayList<Location> blueBrickSpawns = new ArrayList<Location>();
|
||||
private final ArrayList<Location> redSpawnArea = new ArrayList<Location>();
|
||||
private final ArrayList<Location> blueSpawnArea = new ArrayList<Location>();
|
||||
private final FileConfiguration messages;
|
||||
private World gameWorld;
|
||||
private GameState state;
|
||||
private int bricks;
|
||||
private int territoryLevel;
|
||||
private int boundsLevel;
|
||||
private Location spawnLoc;
|
||||
private FileConfiguration messages;
|
||||
private TeamManager teamManager;
|
||||
private ScoreboardTeam redTeam;
|
||||
private ScoreboardTeam blueTeam;
|
||||
private Sidebar sb;
|
||||
private SidebarAnimation<Component> titleAnimation;
|
||||
// private @NotNull SidebarComponent title;
|
||||
private ComponentSidebarLayout layout;
|
||||
|
||||
private int taskId;
|
||||
|
||||
// private List<Player> redTeam = new ArrayList<Player>();
|
||||
// private List<Player> blueTeam = new ArrayList<Player>();
|
||||
|
@ -86,16 +97,23 @@ public class CTB implements Minigame {
|
|||
gameWorld.setAutoSave(false);
|
||||
if (applyOptions(world)) {
|
||||
teamManager = SGM.getInstance().getScoreboardLibrary().createTeamManager();
|
||||
sb = SGM.getInstance().getScoreboardLibrary().createSidebar();
|
||||
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance());
|
||||
|
||||
this.redTeam = teamManager.createIfAbsent("red_team");
|
||||
this.blueTeam = teamManager.createIfAbsent("blue_team");
|
||||
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance());
|
||||
|
||||
setupTeamDisplay(redTeam, "Red Team", NamedTextColor.RED);
|
||||
setupTeamDisplay(blueTeam, "Blue Team", NamedTextColor.BLUE);
|
||||
|
||||
buildScoreboard();
|
||||
this.sb = SGM.getInstance().getScoreboardLibrary().createSidebar();
|
||||
this.titleAnimation = createGradientAnimation(Component.text("Capture The Brick", Style.style(TextDecoration.BOLD)));
|
||||
var title = SidebarComponent.animatedLine(titleAnimation);
|
||||
|
||||
SidebarComponent gameInfo = SidebarComponent.builder().addDynamicLine(() -> Component.text("Players Alive: " + getAlivePlayersCount(), NamedTextColor.YELLOW)).addDynamicLine(() -> Component.text("Red Team: " + getTeamSize(redTeam), NamedTextColor.RED)).addDynamicLine(() -> Component.text("Blue Team: " + getTeamSize(blueTeam), NamedTextColor.BLUE)).addDynamicLine(() -> Component.text("Bricks Remaining: " + bricks, NamedTextColor.GREEN)).build();
|
||||
|
||||
this.layout = new ComponentSidebarLayout(title, gameInfo);
|
||||
layout.apply(sb);
|
||||
|
||||
// buildScoreboard();
|
||||
// Ready
|
||||
state = GameState.READY;
|
||||
owner.sendMessage(ChatUtils.translate(messages.getString("system.game.ready").replace("%game%", name)));
|
||||
|
@ -111,27 +129,31 @@ public class CTB implements Minigame {
|
|||
display.playerColor(color);
|
||||
}
|
||||
|
||||
private void buildScoreboard() {
|
||||
@NotNull SidebarAnimation<Component> titleAnimation = createGradientAnimation(Component.text("Capture The Brick", Style.style(TextDecoration.BOLD)));
|
||||
var title = SidebarComponent.animatedLine(titleAnimation);
|
||||
SidebarComponent lines = SidebarComponent.builder()
|
||||
.addDynamicLine(() -> Component.text("Red Team: " + redTeam.teamManager().players().size(), NamedTextColor.RED))
|
||||
.addDynamicLine(() -> Component.text("Blue Team: " + blueTeam.teamManager().players().size(), NamedTextColor.BLUE))
|
||||
.addDynamicLine(() -> Component.text("Bricks Remaining: " + bricks, NamedTextColor.GREEN))
|
||||
.build();
|
||||
ComponentSidebarLayout layout = new ComponentSidebarLayout(title, lines);
|
||||
layout.apply(sb);
|
||||
}
|
||||
// private void buildScoreboard() {
|
||||
// titleAnimation = createGradientAnimation(Component.text("Capture The Brick", Style.style(TextDecoration.BOLD)));
|
||||
// title = SidebarComponent.animatedLine(titleAnimation);
|
||||
// SidebarComponent lines = SidebarComponent.builder().addDynamicLine(() -> Component.text("Red Team: " + redTeam.teamManager().players().size(), NamedTextColor.RED)).addDynamicLine(() -> Component.text("Blue Team: " + blueTeam.teamManager().players().size(), NamedTextColor.BLUE)).addDynamicLine(() -> Component.text("Bricks Remaining: " + bricks, NamedTextColor.GREEN)).build();
|
||||
// layout = new ComponentSidebarLayout(title, lines);
|
||||
// layout.apply(sb);
|
||||
// }
|
||||
|
||||
private @NotNull SidebarAnimation<Component> createGradientAnimation(@NotNull Component text) {
|
||||
float step = 1f / 8f;
|
||||
TagResolver.Single textPlaceholder = Placeholder.component("text", text);
|
||||
List<Component> frames = new ArrayList<>((int) (2f / step));
|
||||
float phase = -1f;
|
||||
while (phase < 1) {
|
||||
frames.add(MiniMessage.miniMessage().deserialize("<gradient:yellow:gold:" + phase + "><text>", textPlaceholder));
|
||||
|
||||
SGM.getInstance().getCLogger().log("Creating gradient animation");
|
||||
|
||||
while (phase <= 1) {
|
||||
String gradientTag = String.format("<gradient:yellow:gold:%.2f>", phase);
|
||||
Component frame = MiniMessage.miniMessage().deserialize(gradientTag + "<text>", textPlaceholder);
|
||||
frames.add(frame);
|
||||
SGM.getInstance().getCLogger().log("Phase: " + phase + ", Tag: " + gradientTag);
|
||||
phase += step;
|
||||
}
|
||||
|
||||
SGM.getInstance().getCLogger().log("Total frames: " + frames.size());
|
||||
return new CollectionSidebarAnimation<>(frames);
|
||||
}
|
||||
|
||||
|
@ -217,6 +239,7 @@ public class CTB implements Minigame {
|
|||
sendMessageToAllPlayers("The game has started!");
|
||||
for (Player player : players) {
|
||||
player.teleport(this.spawnLoc);
|
||||
sb.addPlayer(player);
|
||||
}
|
||||
for (int i = 0; i <= bricks; i++) {
|
||||
for (Location brickLoc : redBrickSpawns) {
|
||||
|
@ -226,11 +249,13 @@ public class CTB implements Minigame {
|
|||
placeBrick(brickLoc, "blue");
|
||||
}
|
||||
}
|
||||
Bukkit.getScheduler().runTaskTimer(SGM.getInstance(), this::onTick, 0L, 1L);
|
||||
BukkitTask task = Bukkit.getScheduler().runTaskTimer(SGM.getInstance(), this::onTick, 0L, 1L);
|
||||
this.taskId = task.getTaskId();
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayerToTeam(Player player, boolean isRedTeam) {
|
||||
//TODO: make this shit fuckin better bor
|
||||
if (isRedTeam) {
|
||||
redTeam.defaultDisplay().addEntry(player.getName());
|
||||
} else {
|
||||
|
@ -284,13 +309,16 @@ public class CTB implements Minigame {
|
|||
if (teamManager != null) {
|
||||
teamManager.close();
|
||||
}
|
||||
sb.close();;
|
||||
if (sb != null) {
|
||||
sb.close();
|
||||
}
|
||||
Bukkit.getScheduler().cancelTask(this.taskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(Player player) {
|
||||
players.add(player);
|
||||
sb.addPlayer(player);
|
||||
// sb.addPlayer(player);
|
||||
player.teleport(this.spawnLoc);
|
||||
sendMessageToAllPlayers(messages.getString("system.player.join").replace("%player%", player.getName()));
|
||||
}
|
||||
|
@ -298,6 +326,8 @@ public class CTB implements Minigame {
|
|||
@Override
|
||||
public void removePlayer(Player player) {
|
||||
players.remove(player);
|
||||
sb.removePlayer(player);
|
||||
sendMessageToAllPlayers(messages.getString("system.player.left").replace("%player%", player.getName()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -308,6 +338,14 @@ public class CTB implements Minigame {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onWorldChange(PlayerChangedWorldEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (players.contains(player)) {
|
||||
removePlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onPlayerDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
@ -333,21 +371,31 @@ public class CTB implements Minigame {
|
|||
return uuid;
|
||||
}
|
||||
|
||||
public ScoreboardTeam getRedTeam() {
|
||||
return redTeam;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return gameWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick() {
|
||||
buildScoreboard();
|
||||
for (Player player : gameWorld.getPlayers()) {
|
||||
if (!players.contains(player)) {
|
||||
sendMessageToAllPlayers(player.getName() + " IS A IMPOSTER");
|
||||
}
|
||||
}
|
||||
if (state == GameState.STARTED && players.size() <= 1) {
|
||||
this.stop();
|
||||
}
|
||||
try {
|
||||
titleAnimation.nextFrame();
|
||||
layout.apply(sb);
|
||||
} catch (IllegalStateException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,10 @@
|
|||
package xyz.twovb.sgm.games.impl.capturethebrick.guis;
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
|
@ -7,8 +12,7 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xyz.twovb.sgm.SGM;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
import xyz.twovb.sgm.guis.MapGui;
|
||||
import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
|
@ -47,10 +51,12 @@ public class TeamGui {
|
|||
public void pickTeam(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
ItemStack clickedItem = event.getCurrentItem();
|
||||
Minigame game = SGM.getInstance().getGameManager().findGame(player);
|
||||
CTB game = (CTB) SGM.getInstance().getGameManager().findGame(player);
|
||||
if (clickedItem.getType().equals(Material.RED_WOOL)) {
|
||||
game.addPlayerToTeam(target, true);
|
||||
game.sendMessageToAllPlayers(target.getName() + " RED");
|
||||
} else if (clickedItem.getType().equals(Material.BLUE_WOOL)) {
|
||||
game.addPlayerToTeam(target, false);
|
||||
game.sendMessageToAllPlayers(target.getName() + " BLUE");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
//package xyz.twovb.sgm.games.impl.capturethebrick.scoreboards;
|
||||
//
|
||||
//import net.kyori.adventure.text.Component;
|
||||
//import net.kyori.adventure.text.format.NamedTextColor;
|
||||
//import net.kyori.adventure.text.format.Style;
|
||||
//import net.kyori.adventure.text.format.TextDecoration;
|
||||
//import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
//import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
//import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
//import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
|
||||
//import net.megavex.scoreboardlibrary.api.sidebar.component.ComponentSidebarLayout;
|
||||
//import net.megavex.scoreboardlibrary.api.sidebar.component.SidebarComponent;
|
||||
//import net.megavex.scoreboardlibrary.api.sidebar.component.animation.CollectionSidebarAnimation;
|
||||
//import net.megavex.scoreboardlibrary.api.sidebar.component.animation.SidebarAnimation;
|
||||
//import org.bukkit.plugin.Plugin;
|
||||
//import org.jetbrains.annotations.NotNull;
|
||||
//import xyz.twovb.sgm.games.impl.capturethebrick.CTB;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//public class CTBSidebar {
|
||||
// private final Sidebar sidebar;
|
||||
// private final ComponentSidebarLayout componentSidebar;
|
||||
// private final SidebarAnimation<Component> titleAnimation;
|
||||
// private final CTB minigame;
|
||||
//
|
||||
// public CTBSidebar(@NotNull Plugin plugin, @NotNull Sidebar sidebar, @NotNull CTB minigame) {
|
||||
// this.sidebar = sidebar;
|
||||
// this.minigame = minigame;
|
||||
//
|
||||
// this.titleAnimation = createGradientAnimation(Component.text("Capture The Brick", Style.style(TextDecoration.BOLD)));
|
||||
// var title = SidebarComponent.animatedLine(titleAnimation);
|
||||
//
|
||||
// SidebarComponent gameInfo = SidebarComponent.builder()
|
||||
// .addDynamicLine(() -> Component.text("Players Alive: " + getAlivePlayersCount(), NamedTextColor.YELLOW))
|
||||
// .addDynamicLine(() -> Component.text("Red Team: " + getTeamSize(minigame.g), NamedTextColor.RED))
|
||||
// .addDynamicLine(() -> Component.text("Blue Team: " + getTeamSize(minigame.blueTeam), NamedTextColor.BLUE))
|
||||
// .addDynamicLine(() -> Component.text("Bricks Remaining: " + minigame.bricks, NamedTextColor.GREEN))
|
||||
// .build();
|
||||
//
|
||||
// this.componentSidebar = new ComponentSidebarLayout(title, gameInfo);
|
||||
// }
|
||||
//
|
||||
// public void onTick() {
|
||||
// titleAnimation.nextFrame();
|
||||
// componentSidebar.apply(sidebar);
|
||||
// }
|
||||
//
|
||||
// private int getAlivePlayersCount() {
|
||||
// return (int) minigame.players.stream().filter(Player::isOnline).count();
|
||||
// }
|
||||
//
|
||||
// private int getTeamSize(ScoreboardTeam team) {
|
||||
// return team.defaultDisplay().entries().size();
|
||||
// }
|
||||
//
|
||||
// private @NotNull SidebarAnimation<Component> createGradientAnimation(@NotNull Component text) {
|
||||
// float step = 1f / 8f;
|
||||
// TagResolver.Single textPlaceholder = Placeholder.component("text", text);
|
||||
// List<Component> frames = new ArrayList<>((int) (2f / step));
|
||||
// float phase = -1f;
|
||||
// while (phase < 1) {
|
||||
// frames.add(MiniMessage.miniMessage().deserialize("<gradient:yellow:gold:" + phase + "><text>", textPlaceholder));
|
||||
// phase += step;
|
||||
// }
|
||||
// return new CollectionSidebarAnimation<>(frames);
|
||||
// }
|
||||
//}
|
||||
//
|
110
src/main/java/xyz/twovb/sgm/guis/ActiveGamesGui.java
Normal file
110
src/main/java/xyz/twovb/sgm/guis/ActiveGamesGui.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
package xyz.twovb.sgm.guis;
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
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 net.kyori.adventure.text.Component;
|
||||
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 xyz.twovb.sgm.games.GameManager;
|
||||
import xyz.twovb.sgm.games.Minigame;
|
||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ActiveGamesGui {
|
||||
|
||||
@Getter
|
||||
private final ChestGui gui;
|
||||
|
||||
private final String game;
|
||||
private OutlinePane mapPane;
|
||||
|
||||
public ActiveGamesGui(String game) {
|
||||
this.game = game;
|
||||
ChestGui loadedGui = null;
|
||||
try {
|
||||
File guiFile = new File(SGM.getInstance().getDataFolder(), "guis/activegames.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 activegames.xml file.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SGM.getInstance().getLogger().log(Level.SEVERE, "Error loading activegames.xml", e);
|
||||
}
|
||||
gui = loadedGui;
|
||||
}
|
||||
|
||||
public void globalClick(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void addMaps() {
|
||||
for (Minigame game : GameManager.getActiveGames().values()) {
|
||||
// SGM.getInstance().getCLogger().log(game.getName());
|
||||
// SGM.getInstance().getCLogger().log(this.game);
|
||||
Material itemType;
|
||||
switch (game.getState()) {
|
||||
case PRESTART:
|
||||
// mapItem.setType(Material.YELLOW_WOOL);
|
||||
itemType = Material.YELLOW_WOOL;
|
||||
break;
|
||||
case READY:
|
||||
// mapItem.setType(Material.LIME_WOOL);
|
||||
itemType = Material.LIME_WOOL;
|
||||
break;
|
||||
case STARTED:
|
||||
case ENDING:
|
||||
default:
|
||||
// mapItem.setType(Material.RED_WOOL);
|
||||
itemType = Material.RED_WOOL;
|
||||
break;
|
||||
}
|
||||
ItemStack joinItem = new ItemStack(itemType);
|
||||
ItemMeta meta = joinItem.getItemMeta();
|
||||
meta.displayName(ChatUtils.translate(game.getName()));
|
||||
List<Component> lore = new ArrayList<Component>();
|
||||
lore.add(0, ChatUtils.translate("&r&7" + game.getGameId().toString()));
|
||||
if (!game.getPlayers().isEmpty()) {
|
||||
lore.add(ChatUtils.translate("&r&7Players:"));
|
||||
for (Player player : game.getPlayers()) {
|
||||
lore.add(ChatUtils.translate("&r&a" + player.getName()));
|
||||
}
|
||||
}
|
||||
meta.lore(lore);
|
||||
joinItem.setItemMeta(meta);
|
||||
mapPane.addItem(new GuiItem(joinItem, event -> {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (game.getState() == Minigame.GameState.READY) {
|
||||
SGM.getInstance().getGameManager().addPlayerToGame(player, game.getGameId());
|
||||
}
|
||||
player.closeInventory();
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
59
src/main/java/xyz/twovb/sgm/guis/JoinGameGui.java
Normal file
59
src/main/java/xyz/twovb/sgm/guis/JoinGameGui.java
Normal file
|
@ -0,0 +1,59 @@
|
|||
package xyz.twovb.sgm.guis;
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/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 java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class JoinGameGui {
|
||||
|
||||
@Getter
|
||||
private final ChestGui gui;
|
||||
|
||||
public JoinGameGui() {
|
||||
ChestGui loadedGui = null;
|
||||
try {
|
||||
File guiFile = new File(SGM.getInstance().getDataFolder(), "guis/joingame.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 joingame.xml file.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SGM.getInstance().getLogger().log(Level.SEVERE, "Error loading joingame.xml", e);
|
||||
}
|
||||
gui = loadedGui;
|
||||
}
|
||||
|
||||
public void globalClick(InventoryClickEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void joinGame(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 ActiveGamesGui(itemName).getGui().show(player);
|
||||
} else {
|
||||
player.sendMessage("Please check xml");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,12 @@
|
|||
package xyz.twovb.sgm.levels;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Created by 2vb - 5/7/2024
|
||||
*/
|
||||
|
@ -113,6 +119,7 @@ public class LevelManager {
|
|||
File yamlFile = new File(path, "sgm.yml");
|
||||
try (FileWriter writer = new FileWriter(yamlFile)) {
|
||||
yaml.dump(data, writer);
|
||||
this.cancel();
|
||||
} catch (IOException e) {
|
||||
SGM.getInstance().getCLogger().error("Error writing data file: " + e.getMessage());
|
||||
}
|
||||
|
@ -144,8 +151,11 @@ public class LevelManager {
|
|||
YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile);
|
||||
String gameIntName = config.getString("game");
|
||||
if (SGM.getInstance().getGameManager().getRegisteredGames().contains(gameIntName)) {
|
||||
List<String> maps = enabledMaps.get(gameIntName);
|
||||
if (!maps.contains(name)) {
|
||||
enabledMaps.get(gameIntName).add(name);
|
||||
}
|
||||
}
|
||||
FileUtils.copyDirectory(levelDir, mapDir);
|
||||
FileUtils.delete(new File(mapDir + "/uid.dat"));
|
||||
loadWorld(name, LevelType.LEVEL);
|
||||
|
|
13
src/main/resources/guis/activegames.xml
Normal file
13
src/main/resources/guis/activegames.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!--
|
||||
~ Created by 2vb - 5/7/2024
|
||||
-->
|
||||
|
||||
<!--
|
||||
~ Created by 2vb - 5/7/2024
|
||||
-->
|
||||
|
||||
<chestgui title="Active Games" 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>
|
23
src/main/resources/guis/joingame.xml
Normal file
23
src/main/resources/guis/joingame.xml
Normal file
|
@ -0,0 +1,23 @@
|
|||
<!--
|
||||
~ Created by 2vb - 5/7/2024
|
||||
-->
|
||||
|
||||
<!--
|
||||
~ Created by 2vb - 5/7/2024
|
||||
-->
|
||||
|
||||
<chestgui title="Join 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="joinGame">
|
||||
<displayname>Capture The Brick</displayname>
|
||||
</item>
|
||||
<item id="command_block" onClick="joinGame">
|
||||
<displayname>TestGame</displayname>
|
||||
</item>
|
||||
</outlinepane>
|
||||
</chestgui>
|
Loading…
Reference in New Issue
Block a user