-
-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from garnesen/WarRevamp
Scoreboard 2.0
- Loading branch information
Showing
3 changed files
with
139 additions
and
78 deletions.
There are no files selected for viewing
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
179 changes: 104 additions & 75 deletions
179
src/com/palmergames/bukkit/towny/war/eventwar/WarHUD.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 |
---|---|---|
@@ -1,130 +1,159 @@ | ||
package com.palmergames.bukkit.towny.war.eventwar; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.ChatColor; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.scoreboard.DisplaySlot; | ||
import org.bukkit.scoreboard.Objective; | ||
import org.bukkit.scoreboard.Scoreboard; | ||
import org.bukkit.scoreboard.ScoreboardManager; | ||
import org.bukkit.scoreboard.Team; | ||
|
||
import com.palmergames.bukkit.towny.Towny; | ||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; | ||
import com.palmergames.bukkit.towny.object.Coord; | ||
import com.palmergames.bukkit.towny.object.Town; | ||
import com.palmergames.bukkit.towny.object.TownyUniverse; | ||
import com.palmergames.bukkit.towny.object.WorldCoord; | ||
import com.palmergames.util.KeyValue; | ||
|
||
public class WarHUD { | ||
|
||
Line R15 = new Line (" ", null, 15); | ||
Line HOMETOWN = new Line(ChatColor.GOLD + "", "", 14); | ||
Line SCORE = new Line (ChatColor.WHITE + "Points: ", "", 13); | ||
Line R12 = new Line (" ", null, 12); | ||
Line LOCATIONTITLE = new Line (ChatColor.GOLD + "" + ChatColor.BOLD + "Location", null, 11); | ||
Line NATION = new Line (ChatColor.WHITE + "Nation: " + ChatColor.YELLOW, "", 10); | ||
Line TOWN = new Line (ChatColor.WHITE + "Town: " + ChatColor.YELLOW, "", 9); | ||
Line HOME = new Line ("" + ChatColor.RED, "", 8); | ||
String WAR_HUD_TITLE = ChatColor.GOLD + "" + ChatColor.BOLD + "War"; | ||
|
||
ArrayList<Line> table = new ArrayList<Line>(); | ||
Team space1, town_title, town_score, space2, location_title, nation, town, health, home, space3, top_title, first, second, third; | ||
|
||
String space1_player = ChatColor.DARK_AQUA.toString(); | ||
String town_title_player = ChatColor.YELLOW + "" + ChatColor.UNDERLINE; | ||
String town_score_player = ChatColor.WHITE + "Score: " + ChatColor.GREEN; | ||
String space2_player = ChatColor.DARK_BLUE.toString(); | ||
String location_title_player = ChatColor.YELLOW + "" + ChatColor.UNDERLINE + "Location"; | ||
String nation_player = ChatColor.WHITE + "Nation: " + ChatColor.GREEN; | ||
String town_player = ChatColor.WHITE + "Town: " + ChatColor.GREEN; | ||
String health_player = ChatColor.WHITE + "Health: " + ChatColor.GREEN; | ||
String home_player = ChatColor.RED + ""; | ||
String space3_player = ChatColor.DARK_GREEN.toString(); | ||
String top_title_player = ChatColor.YELLOW + "" + ChatColor.UNDERLINE + "Top Towns"; | ||
String first_player = ChatColor.GOLD + ""; | ||
String second_player = ChatColor.GRAY + ""; | ||
String third_player = ChatColor.DARK_GRAY + ""; | ||
|
||
Scoreboard board; | ||
Objective obj; | ||
Objective buffer; | ||
Towny plugin; | ||
Player p; | ||
|
||
public WarHUD (Towny plugin, Player p) { | ||
this.plugin = plugin; | ||
this.p = p; | ||
ScoreboardManager manager = Bukkit.getScoreboardManager(); | ||
board = manager.getNewScoreboard(); | ||
obj = board.registerNewObjective("OBJ", "dummy"); | ||
buffer = board.registerNewObjective("BUFFER", "dummy"); | ||
updateHomeTown(false); | ||
updateScore(false); | ||
updateLocation(false); | ||
update(); | ||
init(); | ||
updateHomeTown(); | ||
updateScore(); | ||
updateLocation(); | ||
} | ||
|
||
@SuppressWarnings("deprecation") | ||
private void init() | ||
{ | ||
//init objective | ||
Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); | ||
Objective obj = board.registerNewObjective("WAR_HUD_OBJ", "dummy"); | ||
obj.setDisplaySlot(DisplaySlot.SIDEBAR); | ||
obj.setDisplayName(WAR_HUD_TITLE); | ||
//register teams | ||
space1 = board.registerNewTeam("space1"); | ||
town_title = board.registerNewTeam("town_title"); | ||
town_score = board.registerNewTeam("town_score"); | ||
space2 = board.registerNewTeam("space2"); | ||
location_title = board.registerNewTeam("location_title"); | ||
nation = board.registerNewTeam("nation"); | ||
town = board.registerNewTeam("town"); | ||
health = board.registerNewTeam("health"); | ||
home = board.registerNewTeam("home"); | ||
space3 = board.registerNewTeam("space3"); | ||
top_title = board.registerNewTeam("top_title"); | ||
first = board.registerNewTeam("first"); | ||
second = board.registerNewTeam("second"); | ||
third = board.registerNewTeam("third"); | ||
//register players | ||
space1.addPlayer(Bukkit.getOfflinePlayer(space1_player)); | ||
town_title.addPlayer(Bukkit.getOfflinePlayer(town_title_player)); | ||
town_score.addPlayer(Bukkit.getOfflinePlayer(town_score_player)); | ||
space2.addPlayer(Bukkit.getOfflinePlayer(space2_player)); | ||
location_title.addPlayer(Bukkit.getOfflinePlayer(location_title_player)); | ||
nation.addPlayer(Bukkit.getOfflinePlayer(nation_player)); | ||
town.addPlayer(Bukkit.getOfflinePlayer(town_player)); | ||
health.addPlayer(Bukkit.getOfflinePlayer(health_player)); | ||
home.addPlayer(Bukkit.getOfflinePlayer(home_player)); | ||
space3.addPlayer(Bukkit.getOfflinePlayer(space3_player)); | ||
top_title.addPlayer(Bukkit.getOfflinePlayer(top_title_player)); | ||
first.addPlayer(Bukkit.getOfflinePlayer(first_player)); | ||
second.addPlayer(Bukkit.getOfflinePlayer(second_player)); | ||
third.addPlayer(Bukkit.getOfflinePlayer(third_player)); | ||
//set scores for positioning | ||
obj.getScore(space1_player).setScore(14); | ||
obj.getScore(town_title_player).setScore(13); | ||
obj.getScore(town_score_player).setScore(12); | ||
obj.getScore(space2_player).setScore(11); | ||
obj.getScore(location_title_player).setScore(10); | ||
obj.getScore(nation_player).setScore(9); | ||
obj.getScore(town_player).setScore(8); | ||
obj.getScore(health_player).setScore(7); | ||
obj.getScore(home_player).setScore(6); | ||
obj.getScore(space3_player).setScore(5); | ||
obj.getScore(top_title_player).setScore(4); | ||
obj.getScore(first_player).setScore(3); | ||
obj.getScore(second_player).setScore(2); | ||
obj.getScore(third_player).setScore(1); | ||
//set the board | ||
p.setScoreboard(board); | ||
} | ||
|
||
public void updateHomeTown(boolean scoreboardUpdate) | ||
public void updateHomeTown() | ||
{ | ||
String homeTown; | ||
try { | ||
HOMETOWN.value = TownyUniverse.getDataSource().getResident(p.getName()).getTown().getName(); | ||
homeTown = TownyUniverse.getDataSource().getResident(p.getName()).getTown().getName(); | ||
} catch (NotRegisteredException e) { | ||
HOMETOWN.value = ""; | ||
homeTown = "Townless!"; | ||
} | ||
if (scoreboardUpdate) | ||
update(); | ||
town_title.setSuffix(homeTown); | ||
} | ||
|
||
public void updateScore(boolean scoreboardUpdate) | ||
public void updateScore() | ||
{ | ||
String score; | ||
try { | ||
Town home = TownyUniverse.getDataSource().getResident(p.getName()).getTown(); | ||
SCORE.value = plugin.getTownyUniverse().getWarEvent().getTownScores().get(home) + ""; | ||
score = plugin.getTownyUniverse().getWarEvent().getTownScores().get(home) + ""; | ||
} catch (NotRegisteredException e) { | ||
SCORE.value = ""; | ||
score = ""; | ||
} | ||
town_score.setSuffix(score); | ||
} | ||
|
||
/** | ||
* Update the location variables of the player. | ||
* | ||
* @param scoreboardUpdate If true, the score board will be rebuilt with the new data | ||
* @throws NotRegisteredException | ||
*/ | ||
public void updateLocation(boolean scoreboardUpdate) | ||
public void updateLocation() | ||
{ | ||
String nation_loc, town_loc, homeblock_loc; | ||
WorldCoord worldCoord = new WorldCoord(p.getWorld().getName(), Coord.parseCoord(p)); | ||
try { | ||
TOWN.value = worldCoord.getTownBlock().getTown().getName(); | ||
town_loc = worldCoord.getTownBlock().getTown().getName(); | ||
if (worldCoord.getTownBlock().isHomeBlock()) | ||
HOME.value = "HOME BLOCK"; | ||
homeblock_loc = "HOME BLOCK"; | ||
else | ||
HOME.value = ""; | ||
} catch (NotRegisteredException e) { TOWN.value = "Wilderness"; HOME.value = "";} | ||
homeblock_loc = ""; | ||
} catch (NotRegisteredException e) { town_loc = "Wilderness"; homeblock_loc = "";} | ||
try { | ||
NATION.value = worldCoord.getTownBlock().getTown().getNation().getName(); | ||
} catch (NotRegisteredException e) { NATION.value = ""; } | ||
if (scoreboardUpdate) | ||
update(); | ||
nation_loc = worldCoord.getTownBlock().getTown().getNation().getName(); | ||
} catch (NotRegisteredException e) { nation_loc = ""; } | ||
nation.setSuffix(nation_loc); | ||
town.setSuffix(town_loc); | ||
home.setSuffix(homeblock_loc); | ||
} | ||
|
||
public void update() | ||
public void updateTopThree(KeyValue<Town, Integer> f, KeyValue<Town, Integer> s, KeyValue<Town, Integer> t) | ||
{ | ||
buffer.unregister(); | ||
buffer = board.registerNewObjective("BUFFER", "dummy"); | ||
buffer.setDisplayName(ChatColor.GOLD + "WAR"); | ||
buffer.getScore(R15.label).setScore(R15.row); | ||
buffer.getScore(HOMETOWN.label).setScore(HOMETOWN.row); | ||
buffer.getScore(SCORE.label + SCORE.value).setScore(SCORE.row); | ||
buffer.getScore(R12.label).setScore(R12.row); | ||
buffer.getScore(LOCATIONTITLE.label).setScore(LOCATIONTITLE.row); | ||
buffer.getScore(NATION.label + NATION.value).setScore(NATION.row); | ||
buffer.getScore(TOWN.label + TOWN.value).setScore(TOWN.row); | ||
buffer.getScore(HOME.label + HOME.value).setScore(HOME.row); | ||
buffer.setDisplaySlot(DisplaySlot.SIDEBAR); | ||
Objective temp = obj; | ||
obj = buffer; | ||
buffer = temp; | ||
} | ||
|
||
static class Line { | ||
|
||
String label; | ||
String value; | ||
int row; | ||
|
||
public Line (String label, String value, int row) | ||
{ | ||
this.label = label; | ||
this.value = value; | ||
this.row = row; | ||
} | ||
first.setSuffix((f != null) ? (f.value + "-" + f.key.getName()) : "" ); | ||
second.setSuffix((s != null) ? (s.value + "-" + s.key.getName()) : "" ); | ||
third.setSuffix((t != null) ? (t.value + "-" + t.key.getName()) : "" ); | ||
} | ||
|
||
} |
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