From 3f637d17248df4fdec084d238b7eb4a1f6f15c1c Mon Sep 17 00:00:00 2001 From: mbax Date: Fri, 22 Mar 2013 11:08:41 -0400 Subject: [PATCH] Add ScoreboardServer from mc-dev for diff visibility --- .../minecraft/server/ScoreboardServer.java | 204 ++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 src/main/java/net/minecraft/server/ScoreboardServer.java diff --git a/src/main/java/net/minecraft/server/ScoreboardServer.java b/src/main/java/net/minecraft/server/ScoreboardServer.java new file mode 100644 index 0000000000..0f28b32838 --- /dev/null +++ b/src/main/java/net/minecraft/server/ScoreboardServer.java @@ -0,0 +1,204 @@ +package net.minecraft.server; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +public class ScoreboardServer extends Scoreboard { + + private final MinecraftServer a; + private final Set b = new HashSet(); + private ScoreboardSaveData c; + + public ScoreboardServer(MinecraftServer minecraftserver) { + this.a = minecraftserver; + } + + public void handleScoreChanged(ScoreboardScore scoreboardscore) { + super.handleScoreChanged(scoreboardscore); + if (this.b.contains(scoreboardscore.getObjective())) { + this.a.getPlayerList().sendAll(new Packet207SetScoreboardScore(scoreboardscore, 0)); + } + + this.b(); + } + + public void handlePlayerRemoved(String s) { + super.handlePlayerRemoved(s); + this.a.getPlayerList().sendAll(new Packet207SetScoreboardScore(s)); + this.b(); + } + + public void setDisplaySlot(int i, ScoreboardObjective scoreboardobjective) { + ScoreboardObjective scoreboardobjective1 = this.getObjectiveForSlot(i); + + super.setDisplaySlot(i, scoreboardobjective); + if (scoreboardobjective1 != scoreboardobjective && scoreboardobjective1 != null) { + if (this.h(scoreboardobjective1) > 0) { + this.a.getPlayerList().sendAll(new Packet208SetScoreboardDisplayObjective(i, scoreboardobjective)); + } else { + this.g(scoreboardobjective1); + } + } + + if (scoreboardobjective != null) { + if (this.b.contains(scoreboardobjective)) { + this.a.getPlayerList().sendAll(new Packet208SetScoreboardDisplayObjective(i, scoreboardobjective)); + } else { + this.e(scoreboardobjective); + } + } + + this.b(); + } + + public void addPlayerToTeam(String s, ScoreboardTeam scoreboardteam) { + super.addPlayerToTeam(s, scoreboardteam); + this.a.getPlayerList().sendAll(new Packet209SetScoreboardTeam(scoreboardteam, Arrays.asList(new String[] { s}), 3)); + this.b(); + } + + public void removePlayerFromTeam(String s, ScoreboardTeam scoreboardteam) { + super.removePlayerFromTeam(s, scoreboardteam); + this.a.getPlayerList().sendAll(new Packet209SetScoreboardTeam(scoreboardteam, Arrays.asList(new String[] { s}), 4)); + this.b(); + } + + public void handleObjectiveAdded(ScoreboardObjective scoreboardobjective) { + super.handleObjectiveAdded(scoreboardobjective); + this.b(); + } + + public void handleObjectiveChanged(ScoreboardObjective scoreboardobjective) { + super.handleObjectiveChanged(scoreboardobjective); + if (this.b.contains(scoreboardobjective)) { + this.a.getPlayerList().sendAll(new Packet206SetScoreboardObjective(scoreboardobjective, 2)); + } + + this.b(); + } + + public void handleObjectiveRemoved(ScoreboardObjective scoreboardobjective) { + super.handleObjectiveRemoved(scoreboardobjective); + if (this.b.contains(scoreboardobjective)) { + this.g(scoreboardobjective); + } + + this.b(); + } + + public void handleTeamAdded(ScoreboardTeam scoreboardteam) { + super.handleTeamAdded(scoreboardteam); + this.a.getPlayerList().sendAll(new Packet209SetScoreboardTeam(scoreboardteam, 0)); + this.b(); + } + + public void handleTeamChanged(ScoreboardTeam scoreboardteam) { + super.handleTeamChanged(scoreboardteam); + this.a.getPlayerList().sendAll(new Packet209SetScoreboardTeam(scoreboardteam, 2)); + this.b(); + } + + public void handleTeamRemoved(ScoreboardTeam scoreboardteam) { + super.handleTeamRemoved(scoreboardteam); + this.a.getPlayerList().sendAll(new Packet209SetScoreboardTeam(scoreboardteam, 1)); + this.b(); + } + + public void a(ScoreboardSaveData scoreboardsavedata) { + this.c = scoreboardsavedata; + } + + protected void b() { + if (this.c != null) { + this.c.c(); + } + } + + public List getScoreboardScorePacketsForObjective(ScoreboardObjective scoreboardobjective) { + ArrayList arraylist = new ArrayList(); + + arraylist.add(new Packet206SetScoreboardObjective(scoreboardobjective, 0)); + + for (int i = 0; i < 3; ++i) { + if (this.getObjectiveForSlot(i) == scoreboardobjective) { + arraylist.add(new Packet208SetScoreboardDisplayObjective(i, scoreboardobjective)); + } + } + + Iterator iterator = this.getScoresForObjective(scoreboardobjective).iterator(); + + while (iterator.hasNext()) { + ScoreboardScore scoreboardscore = (ScoreboardScore) iterator.next(); + + arraylist.add(new Packet207SetScoreboardScore(scoreboardscore, 0)); + } + + return arraylist; + } + + public void e(ScoreboardObjective scoreboardobjective) { + List list = this.getScoreboardScorePacketsForObjective(scoreboardobjective); + Iterator iterator = this.a.getPlayerList().players.iterator(); + + while (iterator.hasNext()) { + EntityPlayer entityplayer = (EntityPlayer) iterator.next(); + Iterator iterator1 = list.iterator(); + + while (iterator1.hasNext()) { + Packet packet = (Packet) iterator1.next(); + + entityplayer.playerConnection.sendPacket(packet); + } + } + + this.b.add(scoreboardobjective); + } + + public List f(ScoreboardObjective scoreboardobjective) { + ArrayList arraylist = new ArrayList(); + + arraylist.add(new Packet206SetScoreboardObjective(scoreboardobjective, 1)); + + for (int i = 0; i < 3; ++i) { + if (this.getObjectiveForSlot(i) == scoreboardobjective) { + arraylist.add(new Packet208SetScoreboardDisplayObjective(i, scoreboardobjective)); + } + } + + return arraylist; + } + + public void g(ScoreboardObjective scoreboardobjective) { + List list = this.f(scoreboardobjective); + Iterator iterator = this.a.getPlayerList().players.iterator(); + + while (iterator.hasNext()) { + EntityPlayer entityplayer = (EntityPlayer) iterator.next(); + Iterator iterator1 = list.iterator(); + + while (iterator1.hasNext()) { + Packet packet = (Packet) iterator1.next(); + + entityplayer.playerConnection.sendPacket(packet); + } + } + + this.b.remove(scoreboardobjective); + } + + public int h(ScoreboardObjective scoreboardobjective) { + int i = 0; + + for (int j = 0; j < 3; ++j) { + if (this.getObjectiveForSlot(j) == scoreboardobjective) { + ++i; + } + } + + return i; + } +}