SPIGOT-4015: Make CraftTeam tie into backing prefix/suffix

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2018-07-16 10:20:53 +10:00
parent c5cc779f03
commit 5d2f9be56c
2 changed files with 4 additions and 52 deletions

View file

@ -1,47 +0,0 @@
--- a/net/minecraft/server/ScoreboardTeam.java
+++ b/net/minecraft/server/ScoreboardTeam.java
@@ -36,7 +36,7 @@
}
public String getDisplayName() {
- return this.d;
+ return this.prefix + this.d + this.suffix; // CraftBukkit
}
public IChatBaseComponent d() {
@@ -165,4 +165,35 @@
public EnumChatFormat getColor() {
return this.k;
}
+
+ // CraftBukkit start
+ private String prefix = "";
+ private String suffix = "";
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public void setPrefix(String prefix) {
+ if (prefix == null) {
+ throw new IllegalArgumentException("Prefix cannot be null");
+ }
+
+ this.prefix = prefix;
+ this.a.handleTeamChanged(this);
+ }
+
+ public String getSuffix() {
+ return suffix;
+ }
+
+ public void setSuffix(String suffix) {
+ if (prefix == null) {
+ throw new IllegalArgumentException("Suffix cannot be null");
+ }
+
+ this.suffix = suffix;
+ this.a.handleTeamChanged(this);
+ }
+ // CraftBukkit end
}

View file

@ -47,7 +47,7 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
public String getPrefix() throws IllegalStateException { public String getPrefix() throws IllegalStateException {
CraftScoreboard scoreboard = checkState(); CraftScoreboard scoreboard = checkState();
return team.getPrefix(); return CraftChatMessage.fromComponent(team.e());
} }
public void setPrefix(String prefix) throws IllegalStateException, IllegalArgumentException { public void setPrefix(String prefix) throws IllegalStateException, IllegalArgumentException {
@ -55,13 +55,13 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
Validate.isTrue(prefix.length() <= 16, "Prefix '" + prefix + "' is longer than the limit of 16 characters"); Validate.isTrue(prefix.length() <= 16, "Prefix '" + prefix + "' is longer than the limit of 16 characters");
CraftScoreboard scoreboard = checkState(); CraftScoreboard scoreboard = checkState();
team.setPrefix(prefix); team.a(CraftChatMessage.fromStringOrNull(prefix));
} }
public String getSuffix() throws IllegalStateException { public String getSuffix() throws IllegalStateException {
CraftScoreboard scoreboard = checkState(); CraftScoreboard scoreboard = checkState();
return team.getSuffix(); return CraftChatMessage.fromComponent(team.f());
} }
public void setSuffix(String suffix) throws IllegalStateException, IllegalArgumentException { public void setSuffix(String suffix) throws IllegalStateException, IllegalArgumentException {
@ -69,7 +69,7 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
Validate.isTrue(suffix.length() <= 16, "Suffix '" + suffix + "' is longer than the limit of 16 characters"); Validate.isTrue(suffix.length() <= 16, "Suffix '" + suffix + "' is longer than the limit of 16 characters");
CraftScoreboard scoreboard = checkState(); CraftScoreboard scoreboard = checkState();
team.setSuffix(suffix); team.b(CraftChatMessage.fromStringOrNull(suffix));
} }
@Override @Override
@ -85,7 +85,6 @@ final class CraftTeam extends CraftScoreboardComponent implements Team {
CraftScoreboard scoreboard = checkState(); CraftScoreboard scoreboard = checkState();
team.setColor(CraftChatMessage.getColor(color)); team.setColor(CraftChatMessage.getColor(color));
scoreboard.board.handleTeamChanged(team); // SPIGOT-3684 - backing team fires this for prefix/suffix but not colour
} }
public boolean allowFriendlyFire() throws IllegalStateException { public boolean allowFriendlyFire() throws IllegalStateException {