Scoreboards
This commit is contained in:
parent
27c61fa74b
commit
31eb8e1ccb
23
pom.xml
23
pom.xml
|
@ -77,6 +77,10 @@
|
||||||
<pattern>com.github.stefvanschie.inventoryframework</pattern>
|
<pattern>com.github.stefvanschie.inventoryframework</pattern>
|
||||||
<shadedPattern>${project.groupId}.${project.artifactId}.inventoryframework</shadedPattern>
|
<shadedPattern>${project.groupId}.${project.artifactId}.inventoryframework</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>net.megavex.scoreboardlibrary</pattern>
|
||||||
|
<shadedPattern>${project.groupId}.${project.artifactId}.scoreboardlibrary</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
@ -169,6 +173,25 @@
|
||||||
<artifactId>IF</artifactId>
|
<artifactId>IF</artifactId>
|
||||||
<version>0.10.15</version>
|
<version>0.10.15</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.megavex</groupId>
|
||||||
|
<artifactId>scoreboard-library-api</artifactId>
|
||||||
|
<version>2.1.10</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.megavex</groupId>
|
||||||
|
<artifactId>scoreboard-library-implementation</artifactId>
|
||||||
|
<version>2.1.10</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.megavex</groupId>
|
||||||
|
<artifactId>scoreboard-library-modern</artifactId>
|
||||||
|
<version>2.1.10</version>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
<!-- For a Mojang mapped variant, uncomment line below (only use if you know what you're doing!): -->
|
||||||
|
<!-- <classifier>mojmap</classifier> -->
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,10 @@ package xyz.twovb.sgm;
|
||||||
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;
|
||||||
|
import net.megavex.scoreboardlibrary.api.ScoreboardLibrary;
|
||||||
|
import net.megavex.scoreboardlibrary.api.exception.NoPacketAdapterAvailableException;
|
||||||
|
import net.megavex.scoreboardlibrary.api.noop.NoopScoreboardLibrary;
|
||||||
|
import net.megavex.scoreboardlibrary.api.team.TeamManager;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
@ -40,6 +44,11 @@ public final class SGM extends JavaPlugin {
|
||||||
@Getter
|
@Getter
|
||||||
private LevelManager levelManager;
|
private LevelManager levelManager;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private ScoreboardLibrary scoreboardLibrary;
|
||||||
|
@Getter
|
||||||
|
private TeamManager teamManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
|
@ -54,6 +63,7 @@ public final class SGM extends JavaPlugin {
|
||||||
BuildInfo.load(Objects.requireNonNull(this.getTextResource("build-info.yml")));
|
BuildInfo.load(Objects.requireNonNull(this.getTextResource("build-info.yml")));
|
||||||
} catch (IOException | InvalidConfigurationException ignored) {
|
} catch (IOException | InvalidConfigurationException ignored) {
|
||||||
}
|
}
|
||||||
|
loadScoreboard();
|
||||||
loadGuis();
|
loadGuis();
|
||||||
registerCommands();
|
registerCommands();
|
||||||
registerGames();
|
registerGames();
|
||||||
|
@ -61,9 +71,20 @@ public final class SGM extends JavaPlugin {
|
||||||
levelManager.loadLevels();
|
levelManager.loadLevels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadScoreboard() {
|
||||||
|
try {
|
||||||
|
scoreboardLibrary = ScoreboardLibrary.loadScoreboardLibrary(this);
|
||||||
|
} catch (NoPacketAdapterAvailableException e) {
|
||||||
|
// If no packet adapter was found, you can fallback to the no-op implementation:
|
||||||
|
scoreboardLibrary = new NoopScoreboardLibrary();
|
||||||
|
this.getCLogger().error("No scoreboard packet adapter found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadGuis() {
|
private void loadGuis() {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerPlaceholders() {
|
private void registerPlaceholders() {
|
||||||
|
|
|
@ -16,8 +16,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.guis.InitGameGui;
|
import xyz.twovb.sgm.guis.InitGameGui;
|
||||||
import xyz.twovb.toolbox.api.CustomPlayer;
|
import xyz.twovb.toolbox.api.CustomPlayer;
|
||||||
import xyz.twovb.toolbox.utils.ChatUtils;
|
import xyz.twovb.toolbox.utils.ChatUtils;
|
||||||
|
@ -59,6 +62,14 @@ public class GameCommand {
|
||||||
game.start();
|
game.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Execute(name = "team join")
|
||||||
|
@Permission("sgm.games.team")
|
||||||
|
void teamJoin(@Context Player player, @Arg("player") Optional<Player> target) {
|
||||||
|
// String name = LevelName.orElse(UUID.randomUUID().toString());
|
||||||
|
Player targetPlayer = target.orElse(player);
|
||||||
|
new TeamGui(targetPlayer).getGui().show(player);
|
||||||
|
}
|
||||||
|
|
||||||
// @Execute(name = "join")
|
// @Execute(name = "join")
|
||||||
// void join(@Context Player player) {
|
// void join(@Context Player player) {
|
||||||
//
|
//
|
||||||
|
|
|
@ -63,7 +63,6 @@ public interface Minigame extends Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum GameState {
|
enum GameState {
|
||||||
PRESTART, READY, STARTED, ENDING
|
PRESTART, READY, STARTED, ENDING
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,21 @@ package xyz.twovb.sgm.games.impl.capturethebrick;
|
||||||
* Created by 2vb - 5/7/2024
|
* Created by 2vb - 5/7/2024
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
import net.kyori.adventure.text.Component;
|
||||||
* Created by 2vb - 3/7/2024
|
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 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.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
@ -23,6 +34,8 @@ 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.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.scoreboard.Team;
|
||||||
|
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;
|
||||||
import xyz.twovb.sgm.games.Minigame;
|
import xyz.twovb.sgm.games.Minigame;
|
||||||
|
@ -38,8 +51,6 @@ public class CTB implements Minigame {
|
||||||
final static String name = "CaptureTheBrick";
|
final static String name = "CaptureTheBrick";
|
||||||
private final UUID uuid;
|
private final UUID uuid;
|
||||||
private final List<Player> players;
|
private final List<Player> players;
|
||||||
private List<Player> redTeam;
|
|
||||||
private List<Player> blueTeam;
|
|
||||||
private final ArrayList<Location> redBrickSpawns = new ArrayList<Location>();
|
private final ArrayList<Location> redBrickSpawns = new ArrayList<Location>();
|
||||||
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>();
|
||||||
|
@ -51,6 +62,15 @@ public class CTB implements Minigame {
|
||||||
private int boundsLevel;
|
private int boundsLevel;
|
||||||
private Location spawnLoc;
|
private Location spawnLoc;
|
||||||
private FileConfiguration messages;
|
private FileConfiguration messages;
|
||||||
|
private TeamManager teamManager;
|
||||||
|
private ScoreboardTeam redTeam;
|
||||||
|
private ScoreboardTeam blueTeam;
|
||||||
|
private Sidebar sb;
|
||||||
|
|
||||||
|
|
||||||
|
// private List<Player> redTeam = new ArrayList<Player>();
|
||||||
|
// private List<Player> blueTeam = new ArrayList<Player>();
|
||||||
|
// private Sidebar sb;
|
||||||
|
|
||||||
|
|
||||||
public CTB() {
|
public CTB() {
|
||||||
|
@ -65,15 +85,56 @@ public class CTB implements Minigame {
|
||||||
gameWorld = createGameWorld(world, uuid);
|
gameWorld = createGameWorld(world, uuid);
|
||||||
gameWorld.setAutoSave(false);
|
gameWorld.setAutoSave(false);
|
||||||
if (applyOptions(world)) {
|
if (applyOptions(world)) {
|
||||||
|
teamManager = SGM.getInstance().getScoreboardLibrary().createTeamManager();
|
||||||
|
sb = SGM.getInstance().getScoreboardLibrary().createSidebar();
|
||||||
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance());
|
Bukkit.getPluginManager().registerEvents(this, SGM.getInstance());
|
||||||
|
|
||||||
|
this.redTeam = teamManager.createIfAbsent("red_team");
|
||||||
|
this.blueTeam = teamManager.createIfAbsent("blue_team");
|
||||||
|
|
||||||
|
setupTeamDisplay(redTeam, "Red Team", NamedTextColor.RED);
|
||||||
|
setupTeamDisplay(blueTeam, "Blue Team", NamedTextColor.BLUE);
|
||||||
|
|
||||||
|
buildScoreboard();
|
||||||
|
// 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)));
|
||||||
} else {
|
} else {
|
||||||
owner.sendMessage(ChatUtils.translate(messages.getString("system.game.failed").replace("%cause%", "to load options.")));
|
owner.sendMessage(ChatUtils.translate(messages.getString("system.game.failed").replace("%cause%", "to load options.")));
|
||||||
Bukkit.getServer().unloadWorld(gameWorld, false);
|
this.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupTeamDisplay(ScoreboardTeam team, String displayName, NamedTextColor color) {
|
||||||
|
TeamDisplay display = team.defaultDisplay();
|
||||||
|
display.displayName(Component.text(displayName));
|
||||||
|
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 @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);
|
||||||
|
}
|
||||||
|
|
||||||
private Location parseString(String string) {
|
private Location parseString(String string) {
|
||||||
String[] coords = string.trim().split(",");
|
String[] coords = string.trim().split(",");
|
||||||
if (coords.length == 3) {
|
if (coords.length == 3) {
|
||||||
|
@ -169,6 +230,29 @@ public class CTB implements Minigame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPlayerToTeam(Player player, boolean isRedTeam) {
|
||||||
|
if (isRedTeam) {
|
||||||
|
redTeam.defaultDisplay().addEntry(player.getName());
|
||||||
|
} else {
|
||||||
|
blueTeam.defaultDisplay().addEntry(player.getName());
|
||||||
|
}
|
||||||
|
teamManager.addPlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removePlayerFromTeams(Player player) {
|
||||||
|
redTeam.defaultDisplay().removeEntry(player.getName());
|
||||||
|
blueTeam.defaultDisplay().removeEntry(player.getName());
|
||||||
|
teamManager.removePlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAlivePlayersCount() {
|
||||||
|
return (int) players.stream().filter(Player::isOnline).count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTeamSize(ScoreboardTeam team) {
|
||||||
|
return team.defaultDisplay().entries().size();
|
||||||
|
}
|
||||||
|
|
||||||
private void placeBrick(Location location, String team) {
|
private void placeBrick(Location location, String team) {
|
||||||
Block brick = location.getBlock();
|
Block brick = location.getBlock();
|
||||||
if (Objects.equals(team, "red")) {
|
if (Objects.equals(team, "red")) {
|
||||||
|
@ -197,11 +281,16 @@ public class CTB implements Minigame {
|
||||||
player.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
|
player.teleport(Bukkit.getServer().getWorlds().get(0).getSpawnLocation());
|
||||||
}
|
}
|
||||||
Bukkit.unloadWorld(gameWorld, false);
|
Bukkit.unloadWorld(gameWorld, false);
|
||||||
|
if (teamManager != null) {
|
||||||
|
teamManager.close();
|
||||||
|
}
|
||||||
|
sb.close();;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPlayer(Player player) {
|
public void addPlayer(Player player) {
|
||||||
players.add(player);
|
players.add(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()));
|
||||||
}
|
}
|
||||||
|
@ -244,6 +333,10 @@ 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;
|
||||||
|
@ -251,6 +344,7 @@ public class CTB implements Minigame {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTick() {
|
public void onTick() {
|
||||||
|
buildScoreboard();
|
||||||
if (state == GameState.STARTED && players.size() <= 1) {
|
if (state == GameState.STARTED && players.size() <= 1) {
|
||||||
this.stop();
|
this.stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package xyz.twovb.sgm.games.impl.capturethebrick.guis;
|
||||||
|
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
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 java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class TeamGui {
|
||||||
|
@Getter
|
||||||
|
private final ChestGui gui;
|
||||||
|
|
||||||
|
private Player target;
|
||||||
|
|
||||||
|
public TeamGui(Player player) {
|
||||||
|
ChestGui loadedGui = null;
|
||||||
|
try {
|
||||||
|
File guiFile = new File(SGM.getInstance().getDataFolder(), "guis/teampicker.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 teampicker.xml file.");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
SGM.getInstance().getLogger().log(Level.SEVERE, "Error loading teampicker.xml", e);
|
||||||
|
}
|
||||||
|
gui = loadedGui;
|
||||||
|
target = player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void globalClick(InventoryClickEvent event) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pickTeam(InventoryClickEvent event) {
|
||||||
|
Player player = (Player) event.getWhoClicked();
|
||||||
|
ItemStack clickedItem = event.getCurrentItem();
|
||||||
|
Minigame game = SGM.getInstance().getGameManager().findGame(player);
|
||||||
|
if (clickedItem.getType().equals(Material.RED_WOOL)) {
|
||||||
|
game.sendMessageToAllPlayers(target.getName() + " RED");
|
||||||
|
} else if (clickedItem.getType().equals(Material.BLUE_WOOL)) {
|
||||||
|
game.sendMessageToAllPlayers(target.getName() + " BLUE");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
//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);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//
|
|
@ -200,6 +200,7 @@ public class LevelManager {
|
||||||
|
|
||||||
// Load levels from levelPath
|
// Load levels from levelPath
|
||||||
loadWorldDir(levelPath, LevelType.LEVEL);
|
loadWorldDir(levelPath, LevelType.LEVEL);
|
||||||
|
loadWorldDir(mapPath, LevelType.MAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadWorldDir(String path, LevelType levelType) {
|
private void loadWorldDir(String path, LevelType levelType) {
|
||||||
|
@ -218,8 +219,10 @@ public class LevelManager {
|
||||||
if (enabledMaps.containsKey(game) && levelType == LevelType.MAP) {
|
if (enabledMaps.containsKey(game) && levelType == LevelType.MAP) {
|
||||||
enabledMaps.get(game).add(name);
|
enabledMaps.get(game).add(name);
|
||||||
}
|
}
|
||||||
// Load the world if sgm.yml exists
|
if (levelType == LevelType.LEVEL) {
|
||||||
loadWorld(file.getName(), levelType);
|
// Load the world if sgm.yml exists
|
||||||
|
loadWorld(file.getName(), levelType);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
SGM.getInstance().getCLogger().log("Skipping directory " + file.getName() + ": sgm.yml not found.");
|
SGM.getInstance().getCLogger().log("Skipping directory " + file.getName() + ": sgm.yml not found.");
|
||||||
}
|
}
|
||||||
|
|
17
src/main/resources/guis/teampicker.xml
Normal file
17
src/main/resources/guis/teampicker.xml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<!--
|
||||||
|
~ Created by 2vb - 4/7/2024
|
||||||
|
-->
|
||||||
|
|
||||||
|
<chestgui title="Teams" rows="3" onGlobalClick="globalClick">
|
||||||
|
<outlinepane x="0" y="0" length="9" height="3" priority="lowest" repeat="true">
|
||||||
|
<item id="black_stained_glass_pane" />
|
||||||
|
</outlinepane>
|
||||||
|
<outlinepane x="3" y="1" length="3" height="1" gap="1">
|
||||||
|
<item id="red_wool" onClick="pickTeam">
|
||||||
|
<displayname>Red Team</displayname>
|
||||||
|
</item>
|
||||||
|
<item id="blue_wool" onClick="pickTeam">
|
||||||
|
<displayname>Blue Team</displayname>
|
||||||
|
</item>
|
||||||
|
</outlinepane>
|
||||||
|
</chestgui>
|
Loading…
Reference in New Issue
Block a user