From fd062503e1ca4402dcd528bfcc98e554223167f8 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 23 Mar 2013 20:41:35 +1100 Subject: [PATCH] Skeleton team object. TODO: Make @mbax come and show me how to rewrite entire API. Also interface --- .../md_5/bungee/api/scoreboard/Objective.java | 2 +- .../net/md_5/bungee/api/scoreboard/Score.java | 4 +-- .../bungee/api/scoreboard/Scoreboard.java | 33 ++++++++++++++++--- .../net/md_5/bungee/api/scoreboard/Team.java | 24 ++++++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 api/src/main/java/net/md_5/bungee/api/scoreboard/Team.java diff --git a/api/src/main/java/net/md_5/bungee/api/scoreboard/Objective.java b/api/src/main/java/net/md_5/bungee/api/scoreboard/Objective.java index a884d02b..5b0ef6a7 100644 --- a/api/src/main/java/net/md_5/bungee/api/scoreboard/Objective.java +++ b/api/src/main/java/net/md_5/bungee/api/scoreboard/Objective.java @@ -16,5 +16,5 @@ public class Objective /** * Value of the objective. */ - private final String value; + private final String value; // displayName } diff --git a/api/src/main/java/net/md_5/bungee/api/scoreboard/Score.java b/api/src/main/java/net/md_5/bungee/api/scoreboard/Score.java index 685fbbd3..88c3e954 100644 --- a/api/src/main/java/net/md_5/bungee/api/scoreboard/Score.java +++ b/api/src/main/java/net/md_5/bungee/api/scoreboard/Score.java @@ -12,11 +12,11 @@ public class Score /** * Name to be displayed in the list. */ - private final String itemName; + private final String itemName; // Player /** * Unique name of the score. */ - private final String scoreName; + private final String scoreName; // Score /** * Value of the score. */ diff --git a/api/src/main/java/net/md_5/bungee/api/scoreboard/Scoreboard.java b/api/src/main/java/net/md_5/bungee/api/scoreboard/Scoreboard.java index b0510d1d..e7c01f03 100644 --- a/api/src/main/java/net/md_5/bungee/api/scoreboard/Scoreboard.java +++ b/api/src/main/java/net/md_5/bungee/api/scoreboard/Scoreboard.java @@ -24,13 +24,15 @@ public class Scoreboard /** * Objectives for this scoreboard. */ - @Getter(AccessLevel.NONE) private final Map objectives = new HashMap<>(); /** * Scores for this scoreboard. */ - @Getter(AccessLevel.NONE) private final Map scores = new HashMap<>(); + /** + * Teams on this board. + */ + private final Map teams = new HashMap<>(); public Collection getObjectives() { @@ -42,18 +44,36 @@ public class Scoreboard return Collections.unmodifiableCollection( scores.values() ); } + public Collection getTeams() + { + return Collections.unmodifiableCollection( teams.values() ); + } + public void addObjective(Objective objective) { - Preconditions.checkArgument( !objectives.containsKey( objective.getName() ), "Objective %s already exists in this scoreboard", objective ); + Preconditions.checkNotNull( objective, "objective" ); + Preconditions.checkArgument( !objectives.containsKey( objective.getName() ), "Objective %s already exists in this scoreboard", objective.getName() ); objectives.put( objective.getName(), objective ); } public void addScore(Score score) { - Preconditions.checkArgument( !scores.containsKey( score.getItemName() ), "Score %s already exists in this scoreboard", score ); + Preconditions.checkNotNull( score, "score" ); + Preconditions.checkArgument( !scores.containsKey( score.getItemName() ), "Score %s already exists in this scoreboard", score.getItemName() ); scores.put( score.getItemName(), score ); } + public void addTeam(Team team) + { + Preconditions.checkNotNull( team, "team" ); + Preconditions.checkArgument( !teams.containsKey( team.getName() ), "Team %s already exists in this scoreboard", team.getName() ); + } + + public Team getTeam(String name) + { + return teams.get( name ); + } + public void removeObjective(String objectiveName) { objectives.remove( objectiveName ); @@ -63,4 +83,9 @@ public class Scoreboard { scores.remove( scoreName ); } + + public void removeTeam(String teamName) + { + teams.remove( teamName ); + } } diff --git a/api/src/main/java/net/md_5/bungee/api/scoreboard/Team.java b/api/src/main/java/net/md_5/bungee/api/scoreboard/Team.java new file mode 100644 index 00000000..cf63a875 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/scoreboard/Team.java @@ -0,0 +1,24 @@ +package net.md_5.bungee.api.scoreboard; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import lombok.Data; + +@Data +public class Team +{ + + private final String name; + private String displayName; + private String prefix; + private String suffix; + private byte friendlyMode; + private Set players = new HashSet<>(); + + public Collection getPlayers() + { + return Collections.unmodifiableSet( players ); + } +}