Implement Scoreboard API. Adds BUKKIT-3776

This implementation facilitates the correspondence of the Bukkit Scoreboard
API to the internal minecraft implementation.

When the first scoreboard is loaded, the scoreboard manager will be created.
It uses the newly added WeakCollection for handling plugin scoreboard
references to update the respective objectives. When a scoreboard contains no
more active references, it should be garbage collected.

An active reference can be held by a still registered objective, team, and
transitively a score for a still registered objective. An internal reference
will also be kept if a player's specific scoreboard has been set, and will
remain persistent until that player logs out.

A player's specific scoreboard becomes the scoreboard used when determining
team structure for the player's attacking damage and the player's vision.
This commit is contained in:
mbax
2013-03-22 17:21:33 -04:00
committed by Wesley Wolfe
parent 5634d9f701
commit d95a4705cb
15 changed files with 756 additions and 32 deletions

View File

@@ -436,11 +436,13 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
public void c(Entity entity, int i) {
this.addScore(i);
Collection collection = this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.e);
// CraftBukkit - Get our scores instead
Collection<ScoreboardScore> collection = this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.e, this.getLocalizedName(), new java.util.ArrayList<ScoreboardScore>());
if (entity instanceof EntityHuman) {
this.a(StatisticList.A, 1);
collection.addAll(this.getScoreboard().getObjectivesForCriteria(IScoreboardCriteria.d));
// CraftBukkit - Get our scores instead
this.world.getServer().getScoreboardManager().getScoreboardScores(IScoreboardCriteria.d, this.getLocalizedName(), collection);
} else {
this.a(StatisticList.z, 1);
}
@@ -448,8 +450,7 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
ScoreboardObjective scoreboardobjective = (ScoreboardObjective) iterator.next();
ScoreboardScore scoreboardscore = this.getScoreboard().getPlayerScoreForObjective(this.getLocalizedName(), scoreboardobjective);
ScoreboardScore scoreboardscore = (ScoreboardScore) iterator.next(); // CraftBukkit - Use our scores instead
scoreboardscore.incrementScore();
}
@@ -687,10 +688,28 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
}
public boolean a(EntityHuman entityhuman) {
ScoreboardTeam scoreboardteam = this.getScoreboardTeam();
ScoreboardTeam scoreboardteam1 = entityhuman.getScoreboardTeam();
// CraftBukkit start - Change to check player's scoreboard team according to API reference to this (or main) scoreboard
org.bukkit.scoreboard.Team team;
if (this instanceof EntityPlayer) {
EntityPlayer thisPlayer = (EntityPlayer) this;
team = thisPlayer.getBukkitEntity().getScoreboard().getPlayerTeam(thisPlayer.getBukkitEntity());
if (team == null || team.allowFriendlyFire()) {
return true;
}
} else {
// This should never be called, but is implemented anyway
org.bukkit.OfflinePlayer thisPlayer = this.world.getServer().getOfflinePlayer(this.name);
team = this.world.getServer().getScoreboardManager().getMainScoreboard().getPlayerTeam(thisPlayer);
if (team == null || team.allowFriendlyFire()) {
return true;
}
}
return scoreboardteam != scoreboardteam1 ? true : (scoreboardteam != null ? scoreboardteam.allowFriendlyFire() : true);
if (entityhuman instanceof EntityPlayer) {
return team.hasPlayer(((EntityPlayer) entityhuman).getBukkitEntity());
}
return team.hasPlayer(this.world.getServer().getOfflinePlayer(entityhuman.name));
// CraftBukkit end
}
protected void a(EntityLiving entityliving, boolean flag) {
@@ -1494,6 +1513,7 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
}
public String getScoreboardDisplayName() {
// TODO: fun
return ScoreboardTeam.getPlayerDisplayName(this.getScoreboardTeam(), this.name);
}
}