-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add sidebar to track game progression
- Loading branch information
1 parent
ddc42d3
commit 6506371
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/main/java/quarri6343/unredstone/common/ProgressionSidebar.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package quarri6343.unredstone.common; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.scoreboard.DisplaySlot; | ||
import org.bukkit.scoreboard.Objective; | ||
import org.bukkit.scoreboard.Score; | ||
import org.bukkit.scoreboard.Scoreboard; | ||
import quarri6343.unredstone.UnRedstone; | ||
import quarri6343.unredstone.common.data.URData; | ||
import quarri6343.unredstone.common.data.URTeam; | ||
|
||
/** | ||
* ゲームの進捗を表示するサイドバーを管理する | ||
*/ | ||
public class ProgressionSidebar { | ||
|
||
private static final String objectiveName = "progression"; | ||
private static Objective objective; | ||
|
||
public static void initialize(){ | ||
objective = getBoard().getObjective(objectiveName); | ||
if(objective == null) | ||
objective = getBoard().registerNewObjective(objectiveName, "dummy", ChatColor.RED + "ゴールまでの距離"); | ||
objective.setDisplaySlot(DisplaySlot.SIDEBAR); | ||
update(); | ||
} | ||
|
||
public static void update(){ | ||
for (int i = 0; i < getData().teams.getTeamsLength(); i++) { | ||
URTeam team = getData().teams.getTeam(i); | ||
if(team.getEndLocation() == null || team.locomotive == null) | ||
continue; | ||
|
||
Score score = objective.getScore(team.name); | ||
int distance = (int)team.getEndLocation().distance(team.locomotive.entity.getLocation()); | ||
score.setScore(distance); | ||
} | ||
} | ||
|
||
public static void destroy(){ | ||
if(objective == null) | ||
return; | ||
|
||
objective.unregister(); | ||
} | ||
|
||
private static Scoreboard getBoard() { | ||
return Bukkit.getScoreboardManager().getMainScoreboard(); | ||
} | ||
|
||
private static URData getData() { | ||
return UnRedstone.getInstance().getData(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters