@@ -55,6 +55,18 @@ public class HungerGame extends AbstractGame {
5555
5656 private BukkitTask borderTask ;
5757
58+ private final List <ChatColor > colors = List .of (
59+ ChatColor .RED ,
60+ ChatColor .BLUE ,
61+ ChatColor .AQUA ,
62+ ChatColor .YELLOW ,
63+ ChatColor .GOLD ,
64+ ChatColor .GREEN ,
65+ ChatColor .LIGHT_PURPLE ,
66+ ChatColor .WHITE ,
67+ ChatColor .GRAY
68+ );
69+
5870 public HungerGame () {
5971 scoreboard = Bukkit .getScoreboardManager ().getMainScoreboard ();
6072 border = new GameBorder (this );
@@ -70,6 +82,30 @@ public void join(GameUser user) {
7082 public void leave (GameUser user ) {
7183 super .leave (user );
7284 bossBar .removePlayer (user );
85+ getUserTeam (user ).ifPresent (team -> team .removeEntry (user .getUsername ()));
86+ }
87+
88+
89+ public void createTeams (int count ) {
90+ final AtomicInteger colorIndex = new AtomicInteger ();
91+ int teamSize = Math .round (12 /count );
92+
93+ // 既存のチームを削除
94+ scoreboard .getTeams ().forEach (Team ::unregister );
95+ // 人数に応じてチームを作る
96+ for (int i = 0 ; i < teamSize ; i ++) {
97+ if (colorIndex .get () < colors .size ()) {
98+ final ChatColor color = colors .get (colorIndex .get ());
99+ final String teamName = scoreboard .getTeam (color .name ()) != null ? UUID .randomUUID ().toString ().substring (0 , 6 ) : color .name ();
100+ final Team team = scoreboard .registerNewTeam (teamName );
101+
102+ team .setColor (color );
103+ team .setOption (Team .Option .NAME_TAG_VISIBILITY , Team .OptionStatus .FOR_OWN_TEAM );
104+ colorIndex .incrementAndGet ();
105+ continue ;
106+ }
107+ colorIndex .set (0 );
108+ }
73109 }
74110
75111 public void randomTeam () {
0 commit comments