mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-23 10:45:48 +01:00
Scratch at score api
This commit is contained in:
parent
1881507712
commit
8cf79471e0
12
api/src/main/java/net/md_5/bungee/api/score/DisplaySlot.java
Normal file
12
api/src/main/java/net/md_5/bungee/api/score/DisplaySlot.java
Normal file
@ -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;
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
@ -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<String, Objective> objectives = new HashMap<>();
|
||||
/**
|
||||
* Scores for this scoreboard.
|
||||
*/
|
||||
private final Map<String, Score> scores = new HashMap<>();
|
||||
/**
|
||||
* Teams on this board.
|
||||
*/
|
||||
private final Map<String, Team> teams = new HashMap<>();
|
||||
String getName();
|
||||
|
||||
public Collection<Objective> getObjectives()
|
||||
{
|
||||
return Collections.unmodifiableCollection( objectives.values() );
|
||||
}
|
||||
DisplaySlot getSlot();
|
||||
|
||||
public Collection<Score> getScores()
|
||||
{
|
||||
return Collections.unmodifiableCollection( scores.values() );
|
||||
}
|
||||
Objective getObjective(String name);
|
||||
|
||||
public Collection<Team> getTeams()
|
||||
{
|
||||
return Collections.unmodifiableCollection( teams.values() );
|
||||
}
|
||||
Collection<Objective> 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<Team> getTeams();
|
||||
|
||||
public Team getTeam(String name)
|
||||
{
|
||||
return teams.get( name );
|
||||
}
|
||||
Collection<Score> 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);
|
||||
}
|
||||
|
@ -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<String> 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<String> 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<ProxiedPlayer> 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);
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user