Skip to content

Commit

Permalink
Team Status
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamesuta committed Nov 7, 2020
1 parent 3115a5a commit 7b27134
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
if (e.mode.equals(currentMode))
return new ComponentBuilder(new TextComponent(new ComponentBuilder(
new TextComponent(
new ComponentBuilder("[]").color(ChatColor.GREEN).bold(true)
new ComponentBuilder("[]").color(ChatColor.GREEN).bold(true)
.append(e.mode.title()).color(ChatColor.YELLOW).bold(false)
.create()
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public boolean isGameOver(StateContainer state) {
@Override
public String getScoreBelowName(StateContainer state) {
return String.format(
"%,d円 (" + ChatColor.GREEN + "%d "
"%,d円 (" + ChatColor.GREEN + "%d "
+ ChatColor.RED + "✗%d" + ChatColor.WHITE + ")",
getDynamicScore(state),
state.clearCount,
Expand Down
67 changes: 45 additions & 22 deletions src/main/java/net/teamfruit/sushida/player/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import javax.annotation.Nullable;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

public class Group {
public PlayerData owner;
Expand All @@ -30,7 +29,11 @@ public class Group {
private ImmutableList<Map.Entry<String, String>> wordRequiredList;

private Scoreboard groupScoreboard;
private Team groupTeam;
private Team groupTeamTitle;

private Team groupTeamCountdownWait;
private Team groupTeamPlay;
private Team groupTeamResultWait;
private Objective scoreLeaderboard;
private Objective tabLeaderboard;

Expand Down Expand Up @@ -66,8 +69,20 @@ public boolean hasRanking() {
return ranking != null;
}

public Team getGroupTeam() {
return groupTeam;
public Team getGroupTeamTitle() {
return groupTeamTitle;
}

public Team getGroupTeamCountdownWait() {
return groupTeamCountdownWait;
}

public Team getGroupTeamPlay() {
return groupTeamPlay;
}

public Team getGroupTeamResultWait() {
return groupTeamResultWait;
}

public Scoreboard getGroupScoreboard() {
Expand Down Expand Up @@ -144,26 +159,34 @@ public ImmutableList<Map.Entry<String, String>> getWordList() {
return wordRequiredList;
}

private Team initTeam(String name, String prefix) {
Team team = groupScoreboard.getTeam(name);
if (team != null)
team.unregister();
team = groupScoreboard.registerNewTeam(name);
team.setPrefix(prefix);
team.setColor(ChatColor.AQUA);
return team;
}

private Objective initObjective(String name, String title, DisplaySlot slot) {
Objective objective = groupScoreboard.getObjective("score");
if (objective != null)
objective.unregister();
objective = groupScoreboard.registerNewObjective("score", "dummy", "スコア");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
return objective;
}

public void init() {
wordRequiredList = getMode().getWords(this);

groupTeam = groupScoreboard.getTeam("sushida");
if (this.groupTeam != null)
this.groupTeam.unregister();
this.groupTeam = groupScoreboard.registerNewTeam("sushida");
this.groupTeam.setPrefix(ChatColor.RED + "[␣]" + ChatColor.RESET);
this.groupTeam.setColor(ChatColor.WHITE);

this.scoreLeaderboard = groupScoreboard.getObjective("score");
if (this.scoreLeaderboard != null)
this.scoreLeaderboard.unregister();
this.scoreLeaderboard = groupScoreboard.registerNewObjective("score", "dummy", "スコア");
this.scoreLeaderboard.setDisplaySlot(DisplaySlot.SIDEBAR);

this.tabLeaderboard = groupScoreboard.getObjective("tab");
if (this.tabLeaderboard != null)
this.tabLeaderboard.unregister();
this.tabLeaderboard = groupScoreboard.registerNewObjective("tab", "dummy", "スコア");
this.tabLeaderboard.setDisplaySlot(DisplaySlot.PLAYER_LIST);
groupTeamTitle = initTeam("sushida.title", ChatColor.BLUE + "[␣]" + ChatColor.RESET);
groupTeamCountdownWait = initTeam("sushida.wait", ChatColor.GOLD + "[⏸]" + ChatColor.RESET);
groupTeamPlay = initTeam("sushida.play", ChatColor.RED + "[▶]" + ChatColor.RESET);
groupTeamResultWait = initTeam("sushida.goal", ChatColor.GREEN + "[✔]" + ChatColor.RESET);

this.scoreLeaderboard = initObjective("score", "スコア", DisplaySlot.SIDEBAR);
this.tabLeaderboard = initObjective("tab", "スコア", DisplaySlot.PLAYER_LIST);
}
}
10 changes: 6 additions & 4 deletions src/main/java/net/teamfruit/sushida/player/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scoreboard.Scoreboard;

import java.util.ArrayList;
import java.util.Optional;

public class PlayerData {
public Player player;
Expand Down Expand Up @@ -69,9 +69,8 @@ public boolean leave() {
return b;
}

public void joinScoreboard(Group group) {
public void joinScoreboard() {
player.setScoreboard(group.getGroupScoreboard());
group.getGroupTeam().addEntry(player.getName());
}

public void leaveScoreboard() {
Expand Down Expand Up @@ -105,7 +104,7 @@ public void run() {
}
}.runTaskLaterAsynchronously(Sushida.plugin, 40);

joinScoreboard(this.group);
joinScoreboard();
Sushida.belowName.spawn(this);
}

Expand All @@ -115,6 +114,9 @@ public void destroy() {
session.apply(StateContainer.supply(NoneState::new));
session = null;

// チームをリセット
Optional.ofNullable(group.getGroupScoreboard().getEntryTeam(player.getName())).ifPresent(e -> e.removeEntry(player.getName()));

if (this.group.getMembers().isEmpty())
leaveScoreboard();
Sushida.belowName.despawn(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class CountdownWaitState implements IState {
public IState onEnter(StateContainer state) {
Player player = state.data.player;

// チーム
state.data.getGroup().getGroupTeamCountdownWait().addEntry(player.getName());

// シングルプレイのときは飛ばす
if (state.data.getGroup().getMembers().isEmpty())
return new CountdownState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public class PlayState implements IState {

@Override
public IState onEnter(StateContainer state) {
Player player = state.data.player;

// チーム
state.data.getGroup().getGroupTeamPlay().addEntry(player.getName());

if (progressBar == null)
progressBar = Bukkit.getBossBar(state.progressKey);
if (progressBar == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class ResultWaitState implements IState {
public IState onEnter(StateContainer state) {
Player player = state.data.player;

// チーム
state.data.getGroup().getGroupTeamResultWait().addEntry(player.getName());

state.timer.pause();
state.realTimer.pause();
state.sushiTimer.pause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class TitleState implements IState {
public IState onEnter(StateContainer state) {
Player player = state.data.player;

// チーム
state.data.getGroup().getGroupTeamTitle().addEntry(player.getName());

IntStream.range(0, 9).forEachOrdered(e -> player.sendMessage(""));

TitleUtils.showTitle(player);
Expand Down

0 comments on commit 7b27134

Please sign in to comment.