diff --git a/api/src/main/java/net/md_5/bungee/api/score/DisplaySlot.java b/api/src/main/java/net/md_5/bungee/api/score/DisplaySlot.java new file mode 100644 index 000000000..9ae0ae627 --- /dev/null +++ b/api/src/main/java/net/md_5/bungee/api/score/DisplaySlot.java @@ -0,0 +1,12 @@ +package net.md_5.bungee.api.score; + +/** + * Locations for displaying scoreboards to the player. + */ +public enum DisplaySlot +{ + + BELOW_NAME, + PLAYER_LIST, + SIDEBAR; +} diff --git a/api/src/main/java/net/md_5/bungee/api/score/Objective.java b/api/src/main/java/net/md_5/bungee/api/score/Objective.java index 07a4d4a5b..5aecedba7 100644 --- a/api/src/main/java/net/md_5/bungee/api/score/Objective.java +++ b/api/src/main/java/net/md_5/bungee/api/score/Objective.java @@ -1,20 +1,49 @@ package net.md_5.bungee.api.score; -import lombok.Data; - /** - * Represents an objective entry. + * An objective on a scoreboard that can show scores specific to players. This + * objective is only relevant to the {@link Scoreboard} which it is associated + * with. */ -@Data -public class Objective +public interface Objective { /** - * Name of the objective. + * Gets the name of this objective. It must be unique amongst all objectives + * registered with any one {@link Scoreboard}. + * + * @return the identifying name of this objective */ - private final String name; + String getName(); + /** - * Value of the objective. + * Gets the name of this objective as it will be displayed to players. + * + * @return the friendly name of this objective */ - private final String value; // displayName + String getDisplayName(); + + /** + * Sets the name displayed to players for this objective. This must not be + * longer than 32 characters. + * + * @param displayName the friendly name to set + */ + void setDisplayName(String displayName); + + /** + * Gets the scoreboard to which this objective is attached. + * + * @return the owning scoreboard + */ + Scoreboard getScoreboard(); + + /** + * Gets the {@link Score} corresponding to this objective, in the context of + * the specified target, ie: their score. + * + * @param target the target to lookup + * @return the targets score data + */ + Score getScore(String target); } diff --git a/api/src/main/java/net/md_5/bungee/api/score/Position.java b/api/src/main/java/net/md_5/bungee/api/score/Position.java deleted file mode 100644 index e68d06671..000000000 --- a/api/src/main/java/net/md_5/bungee/api/score/Position.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.md_5.bungee.api.score; - -/** - * Represents locations for a scoreboard to be displayed. - */ -public enum Position -{ - - LIST, SIDEBAR, BELOW; -} diff --git a/api/src/main/java/net/md_5/bungee/api/score/Score.java b/api/src/main/java/net/md_5/bungee/api/score/Score.java index cb906ddd0..1242b641a 100644 --- a/api/src/main/java/net/md_5/bungee/api/score/Score.java +++ b/api/src/main/java/net/md_5/bungee/api/score/Score.java @@ -1,24 +1,43 @@ package net.md_5.bungee.api.score; -import lombok.Data; - /** - * Represents a scoreboard score entry. + * A score entry for an item and its corresponding {@link Objective}. */ -@Data -public class Score +public interface Score { /** - * Name to be displayed in the list. + * Gets the name of item being being tracked by this Score + * + * @return this tracked item */ - private final String itemName; // Player + String getItem(); + /** - * Unique name of the score. + * Gets the {@link Objective} being tracked by this Score + * + * @return the tracked {@link Objective} */ - private final String scoreName; // Score + Objective getObjective(); + /** - * Value of the score. + * Gets the current score + * + * @return the current score */ - private final int value; + int getScore(); + + /** + * Sets the current score. + * + * @param score the new score + */ + void setScore(int score); + + /** + * Gets the scoreboard which displays this score. + * + * @return the {@link Scoreboard} which owns this score + */ + Scoreboard getScoreboard(); } diff --git a/api/src/main/java/net/md_5/bungee/api/score/Scoreboard.java b/api/src/main/java/net/md_5/bungee/api/score/Scoreboard.java index de82b2475..53a4e2b7c 100644 --- a/api/src/main/java/net/md_5/bungee/api/score/Scoreboard.java +++ b/api/src/main/java/net/md_5/bungee/api/score/Scoreboard.java @@ -1,100 +1,26 @@ package net.md_5.bungee.api.score; -import com.google.common.base.Preconditions; import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import lombok.Data; -import lombok.NoArgsConstructor; +import net.md_5.bungee.api.connection.ProxiedPlayer; -@Data -@NoArgsConstructor -public class Scoreboard +public interface Scoreboard { - /** - * Unique name for this scoreboard. - */ - private String name; - /** - * Position of this scoreboard. - */ - private Position position; - /** - * Objectives for this scoreboard. - */ - private final Map objectives = new HashMap<>(); - /** - * Scores for this scoreboard. - */ - private final Map scores = new HashMap<>(); - /** - * Teams on this board. - */ - private final Map teams = new HashMap<>(); + String getName(); - public Collection getObjectives() - { - return Collections.unmodifiableCollection( objectives.values() ); - } + DisplaySlot getSlot(); - public Collection getScores() - { - return Collections.unmodifiableCollection( scores.values() ); - } + Objective getObjective(String name); - public Collection getTeams() - { - return Collections.unmodifiableCollection( teams.values() ); - } + Collection getObjectives(); - public void addObjective(Objective 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 ); - } + Team getTeam(String name); - public void addScore(Score score) - { - Preconditions.checkNotNull( score, "score" ); - scores.put( score.getItemName(), score ); - } + Team getTeam(ProxiedPlayer player); - public void addTeam(Team team) - { - Preconditions.checkNotNull( team, "team" ); - Preconditions.checkArgument( !teams.containsKey( team.getName() ), "Team %s already exists in this scoreboard", team.getName() ); - teams.put( team.getName(), team ); - } + Collection getTeams(); - public Team getTeam(String name) - { - return teams.get( name ); - } + Collection getScores(ProxiedPlayer player); - public void removeObjective(String objectiveName) - { - objectives.remove( objectiveName ); - } - - public void removeScore(String scoreName) - { - scores.remove( scoreName ); - } - - public void removeTeam(String teamName) - { - teams.remove( teamName ); - } - - public void clear() - { - name = null; - position = null; - objectives.clear(); - scores.clear(); - teams.clear(); - } + void remove(ProxiedPlayer player); } diff --git a/api/src/main/java/net/md_5/bungee/api/score/Team.java b/api/src/main/java/net/md_5/bungee/api/score/Team.java index 3b9b0c892..88a2bb4cb 100644 --- a/api/src/main/java/net/md_5/bungee/api/score/Team.java +++ b/api/src/main/java/net/md_5/bungee/api/score/Team.java @@ -1,36 +1,125 @@ package net.md_5.bungee.api.score; import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import lombok.Data; -import lombok.NonNull; +import net.md_5.bungee.api.connection.ProxiedPlayer; -@Data -public class Team +/** + * Represents a collection of players on a {@link Scoreboard} with properties. + */ +public interface Team { - @NonNull - private final String name; - private String displayName; - private String prefix; - private String suffix; - private boolean friendlyFire; - private Set players = new HashSet<>(); + /** + * Gets the name of this team. It must be unique amongst all teams + * registered with any one {@link Scoreboard}. + * + * @return the identifying name of this team + */ + String getName(); - public Collection getPlayers() - { - return Collections.unmodifiableSet( players ); - } + /** + * Gets the name of this team as it will be displayed to players. + * + * @return the friendly name of this objective + */ + String getDisplayName(); - public void addPlayer(String name) - { - players.add( name ); - } + /** + * Sets the name displayed to players for this team. This must not be longer + * than 32 characters. + * + * @param displayName the friendly name to set + */ + void setDisplayName(String displayName); - public void removePlayer(String name) - { - players.remove( name ); - } + /** + * Gets the prefix which will be prepended to the names of all players on + * this team. + * + * @return this teams prefix + */ + String getPrefix(); + + /** + * Sets the prefix to be prepended to to the names of all players on this + * team. + * + * @param prefix the prefix to set + */ + void setPrefix(String prefix); + + /** + * Sets the suffix appended to the names of all players on this team. + * + * @return this teams suffix + */ + String getSuffix(); + + /** + * Sets the suffix to be appended to to the names of all players on this + * team. + * + * @param suffix the suffix to set + */ + void setSuffix(String suffix); + + /** + * Gets whether members of this team may harm each other. + * + * @return whether or not friendly fire is enabled for this team + */ + boolean friendlyFire(); + + /** + * Sets whether members of this team may harm each other. + * + * @param enabled whether or not to enable friendly fire + */ + void friendlyFire(boolean enabled); + + /** + * Sets whether members of this team can see other members, even when they + * are disguised with a potion of invisibility. + * + * @return whether invisible team members can be seen + */ + boolean friendlyInvisibles(); + + /** + * Sets whether members of this team can see other members, even when they + * are disguised with a potion of invisibility. + * + * @param enabled whether to enable this attribute or not + */ + void friendlyInvisibles(boolean enabled); + + /** + * Gets all players present on this team. + * + * @return the members of this team + */ + Collection getPlayers(); + + /** + * Gets the scoreboard to which this team is attached. + * + * @return the owning scoreboard + */ + Scoreboard getScoreboard(); + + /** + * Adds a player to this team. This will remove the player from all other + * teams. + * + * @param player the player to add + */ + void addPlayer(ProxiedPlayer player); + + /** + * Removes a player from this team. + * + * @param player the player to remove + * @return if this player was successfully removed + */ + boolean removePlayer(ProxiedPlayer player); } diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java index c305c794f..d5f8c468a 100644 --- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java +++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java @@ -16,7 +16,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.ServerKickEvent; import net.md_5.bungee.api.score.Objective; -import net.md_5.bungee.api.score.Position; +import net.md_5.bungee.api.score.DisplaySlot; import net.md_5.bungee.api.score.Score; import net.md_5.bungee.api.score.Scoreboard; import net.md_5.bungee.api.score.Team; @@ -132,7 +132,7 @@ public class DownstreamBridge extends PacketHandler { Scoreboard serverScoreboard = con.getServerSentScoreboard(); serverScoreboard.setName( displayScoreboard.getName() ); - serverScoreboard.setPosition( Position.values()[displayScoreboard.getPosition()] ); + serverScoreboard.setPosition( DisplaySlot.values()[displayScoreboard.getPosition()] ); } @Override