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; | package xyz.twovb.sgm; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  |  * Created by 2vb - 5/7/2024 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
| import dev.rollczi.litecommands.bukkit.LiteBukkitMessages; | import dev.rollczi.litecommands.bukkit.LiteBukkitMessages; | ||||||
| import dev.rollczi.litecommands.bukkit.LiteCommandsBukkit; | import dev.rollczi.litecommands.bukkit.LiteCommandsBukkit; | ||||||
| import lombok.Getter; | import lombok.Getter; | ||||||
|  | @ -85,6 +90,8 @@ public final class SGM extends JavaPlugin { | ||||||
|         saveResource("guis/initgame.xml", false); |         saveResource("guis/initgame.xml", false); | ||||||
|         saveResource("guis/mapgui.xml", false); |         saveResource("guis/mapgui.xml", false); | ||||||
|         saveResource("guis/teampicker.xml", false); |         saveResource("guis/teampicker.xml", false); | ||||||
|  |         saveResource("guis/activegames.xml", false); | ||||||
|  |         saveResource("guis/joingame.xml", false); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void registerPlaceholders() { |     private void registerPlaceholders() { | ||||||
|  |  | ||||||
|  | @ -1,6 +1,12 @@ | ||||||
| package xyz.twovb.sgm.commands.impl; | package xyz.twovb.sgm.commands.impl; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  |  * Created by 2vb - 5/7/2024 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| /* | /* | ||||||
|  * 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 dev.rollczi.litecommands.annotations.permission.Permission; | ||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| import org.bukkit.scoreboard.Scoreboard; |  | ||||||
| import org.bukkit.scoreboard.Team; |  | ||||||
| import xyz.twovb.sgm.SGM; | import xyz.twovb.sgm.SGM; | ||||||
| import xyz.twovb.sgm.games.Minigame; | import xyz.twovb.sgm.games.Minigame; | ||||||
| import xyz.twovb.sgm.games.impl.capturethebrick.guis.TeamGui; | import xyz.twovb.sgm.games.impl.capturethebrick.guis.TeamGui; | ||||||
| import xyz.twovb.sgm.guis.InitGameGui; | import xyz.twovb.sgm.guis.InitGameGui; | ||||||
|  | import xyz.twovb.sgm.guis.JoinGameGui; | ||||||
| import xyz.twovb.toolbox.api.CustomPlayer; | import xyz.twovb.toolbox.api.CustomPlayer; | ||||||
| import xyz.twovb.toolbox.utils.ChatUtils; | import xyz.twovb.toolbox.utils.ChatUtils; | ||||||
| 
 | 
 | ||||||
|  | @ -70,10 +75,10 @@ public class GameCommand { | ||||||
|         new TeamGui(targetPlayer).getGui().show(player); |         new TeamGui(targetPlayer).getGui().show(player); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| //    @Execute(name = "join") |     @Execute(name = "testjoin") | ||||||
| //    void join(@Context Player player) { |     void testjoin(@Context Player player) { | ||||||
| // |         new JoinGameGui().getGui().show(player); | ||||||
| //    } |     } | ||||||
| 
 | 
 | ||||||
|     @Execute(name = "join") |     @Execute(name = "join") | ||||||
|     void join(@Context Player player, @Arg("id") String id) { |     void join(@Context Player player, @Arg("id") String id) { | ||||||
|  |  | ||||||
|  | @ -1,5 +1,10 @@ | ||||||
| package xyz.twovb.sgm.games; | package xyz.twovb.sgm.games; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  |  * Created by 2vb - 5/7/2024 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
| /* | /* | ||||||
|  * Created by 2vb - 4/6/2024 |  * Created by 2vb - 4/6/2024 | ||||||
|  */ |  */ | ||||||
|  | @ -9,7 +14,6 @@ import org.bukkit.NamespacedKey; | ||||||
| import org.bukkit.World; | import org.bukkit.World; | ||||||
| import org.bukkit.WorldCreator; | import org.bukkit.WorldCreator; | ||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.configuration.file.FileConfiguration; |  | ||||||
| import org.bukkit.entity.Player; | import org.bukkit.entity.Player; | ||||||
| import org.bukkit.event.Listener; | import org.bukkit.event.Listener; | ||||||
| import xyz.twovb.sgm.SGM; | import xyz.twovb.sgm.SGM; | ||||||
|  | @ -43,6 +47,8 @@ public interface Minigame extends Listener { | ||||||
| 
 | 
 | ||||||
|     GameState getState(); |     GameState getState(); | ||||||
| 
 | 
 | ||||||
|  |     World getWorld(); | ||||||
|  | 
 | ||||||
|     default void sendMessageToAllPlayers(String message) { |     default void sendMessageToAllPlayers(String message) { | ||||||
|         for (Player player : getPlayers()) { |         for (Player player : getPlayers()) { | ||||||
|             CustomPlayer cPlayer = new CustomPlayer(player); |             CustomPlayer cPlayer = new CustomPlayer(player); | ||||||
|  |  | ||||||
|  | @ -1,5 +1,10 @@ | ||||||
| package xyz.twovb.sgm.games.impl; | package xyz.twovb.sgm.games.impl; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  |  * Created by 2vb - 5/7/2024 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
| /* | /* | ||||||
|  * Created by 2vb - 26/6/2024 |  * Created by 2vb - 26/6/2024 | ||||||
|  */ |  */ | ||||||
|  | @ -117,6 +122,12 @@ public class TestGame implements Minigame { | ||||||
|         return state; |         return state; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public World getWorld() { | ||||||
|  |         return gameWorld; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void onTick() { |     public void onTick() { | ||||||
|         if (state == GameState.STARTED && players.size() <= 1) { |         if (state == GameState.STARTED && players.size() <= 1) { | ||||||
|  |  | ||||||
|  | @ -1,6 +1,12 @@ | ||||||
| package xyz.twovb.sgm.games.impl.capturethebrick; | package xyz.twovb.sgm.games.impl.capturethebrick; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  |  * Created by 2vb - 5/7/2024 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| /* | /* | ||||||
|  * 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.SidebarComponent; | ||||||
| import net.megavex.scoreboardlibrary.api.sidebar.component.animation.CollectionSidebarAnimation; | import net.megavex.scoreboardlibrary.api.sidebar.component.animation.CollectionSidebarAnimation; | ||||||
| import net.megavex.scoreboardlibrary.api.sidebar.component.animation.SidebarAnimation; | 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.TeamDisplay; | ||||||
| import net.megavex.scoreboardlibrary.api.team.TeamManager; | import net.megavex.scoreboardlibrary.api.team.TeamManager; | ||||||
| import net.megavex.scoreboardlibrary.api.team.ScoreboardTeam; |  | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.Location; | import org.bukkit.Location; | ||||||
| import org.bukkit.Material; | import org.bukkit.Material; | ||||||
|  | @ -33,8 +39,9 @@ import org.bukkit.entity.Player; | ||||||
| import org.bukkit.event.EventHandler; | import org.bukkit.event.EventHandler; | ||||||
| import org.bukkit.event.HandlerList; | import org.bukkit.event.HandlerList; | ||||||
| import org.bukkit.event.entity.PlayerDeathEvent; | import org.bukkit.event.entity.PlayerDeathEvent; | ||||||
|  | import org.bukkit.event.player.PlayerChangedWorldEvent; | ||||||
| import org.bukkit.event.player.PlayerQuitEvent; | import org.bukkit.event.player.PlayerQuitEvent; | ||||||
| import org.bukkit.scoreboard.Team; | import org.bukkit.scheduler.BukkitTask; | ||||||
| import org.jetbrains.annotations.NotNull; | import org.jetbrains.annotations.NotNull; | ||||||
| import xyz.twovb.sgm.SGM; | import xyz.twovb.sgm.SGM; | ||||||
| import xyz.twovb.sgm.games.GameManager; | 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> blueBrickSpawns = new ArrayList<Location>(); | ||||||
|     private final ArrayList<Location> redSpawnArea = new ArrayList<Location>(); |     private final ArrayList<Location> redSpawnArea = new ArrayList<Location>(); | ||||||
|     private final ArrayList<Location> blueSpawnArea = new ArrayList<Location>(); |     private final ArrayList<Location> blueSpawnArea = new ArrayList<Location>(); | ||||||
|  |     private final FileConfiguration messages; | ||||||
|     private World gameWorld; |     private World gameWorld; | ||||||
|     private GameState state; |     private GameState state; | ||||||
|     private int bricks; |     private int bricks; | ||||||
|     private int territoryLevel; |     private int territoryLevel; | ||||||
|     private int boundsLevel; |     private int boundsLevel; | ||||||
|     private Location spawnLoc; |     private Location spawnLoc; | ||||||
|     private FileConfiguration messages; |  | ||||||
|     private TeamManager teamManager; |     private TeamManager teamManager; | ||||||
|     private ScoreboardTeam redTeam; |     private ScoreboardTeam redTeam; | ||||||
|     private ScoreboardTeam blueTeam; |     private ScoreboardTeam blueTeam; | ||||||
|     private Sidebar sb; |     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> redTeam = new ArrayList<Player>(); | ||||||
| //    private List<Player> blueTeam = new ArrayList<Player>(); | //    private List<Player> blueTeam = new ArrayList<Player>(); | ||||||
|  | @ -86,16 +97,23 @@ public class CTB implements Minigame { | ||||||
|         gameWorld.setAutoSave(false); |         gameWorld.setAutoSave(false); | ||||||
|         if (applyOptions(world)) { |         if (applyOptions(world)) { | ||||||
|             teamManager = SGM.getInstance().getScoreboardLibrary().createTeamManager(); |             teamManager = SGM.getInstance().getScoreboardLibrary().createTeamManager(); | ||||||
|             sb = SGM.getInstance().getScoreboardLibrary().createSidebar(); |  | ||||||
|             Bukkit.getPluginManager().registerEvents(this, SGM.getInstance()); |  | ||||||
| 
 |  | ||||||
|             this.redTeam = teamManager.createIfAbsent("red_team"); |             this.redTeam = teamManager.createIfAbsent("red_team"); | ||||||
|             this.blueTeam = teamManager.createIfAbsent("blue_team"); |             this.blueTeam = teamManager.createIfAbsent("blue_team"); | ||||||
|  |             Bukkit.getPluginManager().registerEvents(this, SGM.getInstance()); | ||||||
| 
 | 
 | ||||||
|             setupTeamDisplay(redTeam, "Red Team", NamedTextColor.RED); |             setupTeamDisplay(redTeam, "Red Team", NamedTextColor.RED); | ||||||
|             setupTeamDisplay(blueTeam, "Blue Team", NamedTextColor.BLUE); |             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 |             // Ready | ||||||
|             state = GameState.READY; |             state = GameState.READY; | ||||||
|             owner.sendMessage(ChatUtils.translate(messages.getString("system.game.ready").replace("%game%", name))); |             owner.sendMessage(ChatUtils.translate(messages.getString("system.game.ready").replace("%game%", name))); | ||||||
|  | @ -111,27 +129,31 @@ public class CTB implements Minigame { | ||||||
|         display.playerColor(color); |         display.playerColor(color); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private void buildScoreboard() { | //    private void buildScoreboard() { | ||||||
|         @NotNull SidebarAnimation<Component> titleAnimation = createGradientAnimation(Component.text("Capture The Brick", Style.style(TextDecoration.BOLD))); | //        titleAnimation = createGradientAnimation(Component.text("Capture The Brick", Style.style(TextDecoration.BOLD))); | ||||||
|         var title = SidebarComponent.animatedLine(titleAnimation); | //        title = SidebarComponent.animatedLine(titleAnimation); | ||||||
|         SidebarComponent lines = SidebarComponent.builder() | //        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(); | ||||||
|                 .addDynamicLine(() -> Component.text("Red Team: " + redTeam.teamManager().players().size(), NamedTextColor.RED)) | //        layout = new ComponentSidebarLayout(title, lines); | ||||||
|                 .addDynamicLine(() -> Component.text("Blue Team: " + blueTeam.teamManager().players().size(), NamedTextColor.BLUE)) | //        layout.apply(sb); | ||||||
|                 .addDynamicLine(() -> Component.text("Bricks Remaining: " + bricks, NamedTextColor.GREEN)) | //    } | ||||||
|                 .build(); |  | ||||||
|         ComponentSidebarLayout layout = new ComponentSidebarLayout(title, lines); |  | ||||||
|         layout.apply(sb); |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     private @NotNull SidebarAnimation<Component> createGradientAnimation(@NotNull Component text) { |     private @NotNull SidebarAnimation<Component> createGradientAnimation(@NotNull Component text) { | ||||||
|         float step = 1f / 8f; |         float step = 1f / 8f; | ||||||
|         TagResolver.Single textPlaceholder = Placeholder.component("text", text); |         TagResolver.Single textPlaceholder = Placeholder.component("text", text); | ||||||
|         List<Component> frames = new ArrayList<>((int) (2f / step)); |         List<Component> frames = new ArrayList<>((int) (2f / step)); | ||||||
|         float phase = -1f; |         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; |             phase += step; | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         SGM.getInstance().getCLogger().log("Total frames: " + frames.size()); | ||||||
|         return new CollectionSidebarAnimation<>(frames); |         return new CollectionSidebarAnimation<>(frames); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -217,6 +239,7 @@ public class CTB implements Minigame { | ||||||
|             sendMessageToAllPlayers("The game has started!"); |             sendMessageToAllPlayers("The game has started!"); | ||||||
|             for (Player player : players) { |             for (Player player : players) { | ||||||
|                 player.teleport(this.spawnLoc); |                 player.teleport(this.spawnLoc); | ||||||
|  |                 sb.addPlayer(player); | ||||||
|             } |             } | ||||||
|             for (int i = 0; i <= bricks; i++) { |             for (int i = 0; i <= bricks; i++) { | ||||||
|                 for (Location brickLoc : redBrickSpawns) { |                 for (Location brickLoc : redBrickSpawns) { | ||||||
|  | @ -226,11 +249,13 @@ public class CTB implements Minigame { | ||||||
|                     placeBrick(brickLoc, "blue"); |                     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) { |     public void addPlayerToTeam(Player player, boolean isRedTeam) { | ||||||
|  |         //TODO: make this shit fuckin better bor | ||||||
|         if (isRedTeam) { |         if (isRedTeam) { | ||||||
|             redTeam.defaultDisplay().addEntry(player.getName()); |             redTeam.defaultDisplay().addEntry(player.getName()); | ||||||
|         } else { |         } else { | ||||||
|  | @ -284,13 +309,16 @@ public class CTB implements Minigame { | ||||||
|         if (teamManager != null) { |         if (teamManager != null) { | ||||||
|             teamManager.close(); |             teamManager.close(); | ||||||
|         } |         } | ||||||
|         sb.close();; |         if (sb != null) { | ||||||
|  |             sb.close(); | ||||||
|  |         } | ||||||
|  |         Bukkit.getScheduler().cancelTask(this.taskId); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void addPlayer(Player player) { |     public void addPlayer(Player player) { | ||||||
|         players.add(player); |         players.add(player); | ||||||
|         sb.addPlayer(player); | //        sb.addPlayer(player); | ||||||
|         player.teleport(this.spawnLoc); |         player.teleport(this.spawnLoc); | ||||||
|         sendMessageToAllPlayers(messages.getString("system.player.join").replace("%player%", player.getName())); |         sendMessageToAllPlayers(messages.getString("system.player.join").replace("%player%", player.getName())); | ||||||
|     } |     } | ||||||
|  | @ -298,6 +326,8 @@ public class CTB implements Minigame { | ||||||
|     @Override |     @Override | ||||||
|     public void removePlayer(Player player) { |     public void removePlayer(Player player) { | ||||||
|         players.remove(player); |         players.remove(player); | ||||||
|  |         sb.removePlayer(player); | ||||||
|  |         sendMessageToAllPlayers(messages.getString("system.player.left").replace("%player%", player.getName())); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @EventHandler |     @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 |     @EventHandler | ||||||
|     void onPlayerDeath(PlayerDeathEvent event) { |     void onPlayerDeath(PlayerDeathEvent event) { | ||||||
|         Player player = event.getPlayer(); |         Player player = event.getPlayer(); | ||||||
|  | @ -333,21 +371,31 @@ public class CTB implements Minigame { | ||||||
|         return uuid; |         return uuid; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public ScoreboardTeam getRedTeam() { |  | ||||||
|         return redTeam; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Override |     @Override | ||||||
|     public GameState getState() { |     public GameState getState() { | ||||||
|         return state; |         return state; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     @Override | ||||||
|  |     public World getWorld() { | ||||||
|  |         return gameWorld; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public void onTick() { |     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) { |         if (state == GameState.STARTED && players.size() <= 1) { | ||||||
|             this.stop(); |             this.stop(); | ||||||
|         } |         } | ||||||
|  |         try { | ||||||
|  |             titleAnimation.nextFrame(); | ||||||
|  |             layout.apply(sb); | ||||||
|  |         } catch (IllegalStateException ignored) { | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | @ -1,5 +1,10 @@ | ||||||
| package xyz.twovb.sgm.games.impl.capturethebrick.guis; | package xyz.twovb.sgm.games.impl.capturethebrick.guis; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  |  * Created by 2vb - 5/7/2024 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
| import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; | import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; | ||||||
| import lombok.Getter; | import lombok.Getter; | ||||||
| import org.bukkit.Material; | import org.bukkit.Material; | ||||||
|  | @ -7,8 +12,7 @@ import org.bukkit.entity.Player; | ||||||
| import org.bukkit.event.inventory.InventoryClickEvent; | import org.bukkit.event.inventory.InventoryClickEvent; | ||||||
| import org.bukkit.inventory.ItemStack; | import org.bukkit.inventory.ItemStack; | ||||||
| import xyz.twovb.sgm.SGM; | import xyz.twovb.sgm.SGM; | ||||||
| import xyz.twovb.sgm.games.Minigame; | import xyz.twovb.sgm.games.impl.capturethebrick.CTB; | ||||||
| import xyz.twovb.sgm.guis.MapGui; |  | ||||||
| 
 | 
 | ||||||
| import java.io.ByteArrayInputStream; | import java.io.ByteArrayInputStream; | ||||||
| import java.io.File; | import java.io.File; | ||||||
|  | @ -47,10 +51,12 @@ public class TeamGui { | ||||||
|     public void pickTeam(InventoryClickEvent event) { |     public void pickTeam(InventoryClickEvent event) { | ||||||
|         Player player = (Player) event.getWhoClicked(); |         Player player = (Player) event.getWhoClicked(); | ||||||
|         ItemStack clickedItem = event.getCurrentItem(); |         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)) { |         if (clickedItem.getType().equals(Material.RED_WOOL)) { | ||||||
|  |             game.addPlayerToTeam(target, true); | ||||||
|             game.sendMessageToAllPlayers(target.getName() + " RED"); |             game.sendMessageToAllPlayers(target.getName() + " RED"); | ||||||
|         } else if (clickedItem.getType().equals(Material.BLUE_WOOL)) { |         } else if (clickedItem.getType().equals(Material.BLUE_WOOL)) { | ||||||
|  |             game.addPlayerToTeam(target, false); | ||||||
|             game.sendMessageToAllPlayers(target.getName() + " BLUE"); |             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; | package xyz.twovb.sgm.levels; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | /* | ||||||
|  |  * Created by 2vb - 5/7/2024 | ||||||
|  |  */ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| /* | /* | ||||||
|  * 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"); |                 File yamlFile = new File(path, "sgm.yml"); | ||||||
|                 try (FileWriter writer = new FileWriter(yamlFile)) { |                 try (FileWriter writer = new FileWriter(yamlFile)) { | ||||||
|                     yaml.dump(data, writer); |                     yaml.dump(data, writer); | ||||||
|  |                     this.cancel(); | ||||||
|                 } catch (IOException e) { |                 } catch (IOException e) { | ||||||
|                     SGM.getInstance().getCLogger().error("Error writing data file: " + e.getMessage()); |                     SGM.getInstance().getCLogger().error("Error writing data file: " + e.getMessage()); | ||||||
|                 } |                 } | ||||||
|  | @ -144,7 +151,10 @@ public class LevelManager { | ||||||
|                 YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); |                 YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); | ||||||
|                 String gameIntName = config.getString("game"); |                 String gameIntName = config.getString("game"); | ||||||
|                 if (SGM.getInstance().getGameManager().getRegisteredGames().contains(gameIntName)) { |                 if (SGM.getInstance().getGameManager().getRegisteredGames().contains(gameIntName)) { | ||||||
|                     enabledMaps.get(gameIntName).add(name); |                     List<String> maps = enabledMaps.get(gameIntName); | ||||||
|  |                     if (!maps.contains(name)) { | ||||||
|  |                         enabledMaps.get(gameIntName).add(name); | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|                 FileUtils.copyDirectory(levelDir, mapDir); |                 FileUtils.copyDirectory(levelDir, mapDir); | ||||||
|                 FileUtils.delete(new File(mapDir + "/uid.dat")); |                 FileUtils.delete(new File(mapDir + "/uid.dat")); | ||||||
|  |  | ||||||
							
								
								
									
										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