From a94277a18bfad743199689c808456bb82dba4c8b Mon Sep 17 00:00:00 2001 From: Parker Hawke Date: Sun, 16 Jul 2023 15:21:56 +1000 Subject: [PATCH] #1223: Remove non-existent scoreboard display name/prefix/suffix limits --- .../scoreboard/CraftObjective.java | 29 +++++----- .../craftbukkit/scoreboard/CraftScore.java | 6 +-- .../scoreboard/CraftScoreboard.java | 37 +++++++------ .../scoreboard/CraftScoreboardComponent.java | 4 +- .../scoreboard/CraftScoreboardManager.java | 2 +- .../craftbukkit/scoreboard/CraftTeam.java | 53 +++++++++---------- 6 files changed, 62 insertions(+), 69 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java index 8c7e0a6db..f8f1da9ae 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java @@ -26,51 +26,50 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective } @Override - public String getName() throws IllegalStateException { + public String getName() { checkState(); return objective.getName(); } @Override - public String getDisplayName() throws IllegalStateException { + public String getDisplayName() { checkState(); return CraftChatMessage.fromComponent(objective.getDisplayName()); } @Override - public void setDisplayName(String displayName) throws IllegalStateException, IllegalArgumentException { + public void setDisplayName(String displayName) { Preconditions.checkArgument(displayName != null, "Display name cannot be null"); - Preconditions.checkArgument(displayName.length() <= 128, "Display name '" + displayName + "' is longer than the limit of 128 characters"); checkState(); objective.setDisplayName(CraftChatMessage.fromString(displayName)[0]); // SPIGOT-4112: not nullable } @Override - public String getCriteria() throws IllegalStateException { + public String getCriteria() { checkState(); return criteria.bukkitName; } @Override - public Criteria getTrackedCriteria() throws IllegalStateException { + public Criteria getTrackedCriteria() { checkState(); return criteria; } @Override - public boolean isModifiable() throws IllegalStateException { + public boolean isModifiable() { checkState(); return !criteria.criteria.isReadOnly(); } @Override - public void setDisplaySlot(DisplaySlot slot) throws IllegalStateException { + public void setDisplaySlot(DisplaySlot slot) { CraftScoreboard scoreboard = checkState(); Scoreboard board = scoreboard.board; ScoreboardObjective objective = this.objective; @@ -87,7 +86,7 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective } @Override - public DisplaySlot getDisplaySlot() throws IllegalStateException { + public DisplaySlot getDisplaySlot() { CraftScoreboard scoreboard = checkState(); Scoreboard board = scoreboard.board; ScoreboardObjective objective = this.objective; @@ -101,7 +100,7 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective } @Override - public void setRenderType(RenderType renderType) throws IllegalStateException { + public void setRenderType(RenderType renderType) { Preconditions.checkArgument(renderType != null, "RenderType cannot be null"); checkState(); @@ -109,14 +108,14 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective } @Override - public RenderType getRenderType() throws IllegalStateException { + public RenderType getRenderType() { checkState(); return CraftScoreboardTranslations.toBukkitRender(this.objective.getRenderType()); } @Override - public Score getScore(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException { + public Score getScore(OfflinePlayer player) { Preconditions.checkArgument(player != null, "Player cannot be null"); checkState(); @@ -124,7 +123,7 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective } @Override - public Score getScore(String entry) throws IllegalArgumentException, IllegalStateException { + public Score getScore(String entry) { Preconditions.checkArgument(entry != null, "Entry cannot be null"); Preconditions.checkArgument(entry.length() <= Short.MAX_VALUE, "Score '" + entry + "' is longer than the limit of 32767 characters"); checkState(); @@ -133,14 +132,14 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective } @Override - public void unregister() throws IllegalStateException { + public void unregister() { CraftScoreboard scoreboard = checkState(); scoreboard.board.removeObjective(objective); } @Override - CraftScoreboard checkState() throws IllegalStateException { + CraftScoreboard checkState() { Preconditions.checkState(getScoreboard().board.getObjective(objective.getName()) != null, "Unregistered scoreboard component"); return getScoreboard(); diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScore.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScore.java index d0b0517b1..fe4164280 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScore.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScore.java @@ -40,7 +40,7 @@ final class CraftScore implements Score { } @Override - public int getScore() throws IllegalStateException { + public int getScore() { Scoreboard board = objective.checkState().board; if (board.getTrackedPlayers().contains(entry)) { // Lazy @@ -55,12 +55,12 @@ final class CraftScore implements Score { } @Override - public void setScore(int score) throws IllegalStateException { + public void setScore(int score) { objective.checkState().board.getOrCreatePlayerScore(entry, objective.getHandle()).setScore(score); } @Override - public boolean isScoreSet() throws IllegalStateException { + public boolean isScoreSet() { Scoreboard board = objective.checkState().board; return board.getTrackedPlayers().contains(entry) && board.getPlayerScores(entry).containsKey(objective.getHandle()); diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java index 1154ee199..b59d9ca42 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java @@ -25,33 +25,32 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public CraftObjective registerNewObjective(String name, String criteria) throws IllegalArgumentException { + public CraftObjective registerNewObjective(String name, String criteria) { return registerNewObjective(name, criteria, name); } @Override - public CraftObjective registerNewObjective(String name, String criteria, String displayName) throws IllegalArgumentException { + public CraftObjective registerNewObjective(String name, String criteria, String displayName) { return registerNewObjective(name, CraftCriteria.getFromBukkit(criteria), displayName, RenderType.INTEGER); } @Override - public CraftObjective registerNewObjective(String name, String criteria, String displayName, RenderType renderType) throws IllegalArgumentException { + public CraftObjective registerNewObjective(String name, String criteria, String displayName, RenderType renderType) { return registerNewObjective(name, CraftCriteria.getFromBukkit(criteria), displayName, renderType); } @Override - public CraftObjective registerNewObjective(String name, Criteria criteria, String displayName) throws IllegalArgumentException { + public CraftObjective registerNewObjective(String name, Criteria criteria, String displayName) { return registerNewObjective(name, criteria, displayName, RenderType.INTEGER); } @Override - public CraftObjective registerNewObjective(String name, Criteria criteria, String displayName, RenderType renderType) throws IllegalArgumentException { + public CraftObjective registerNewObjective(String name, Criteria criteria, String displayName, RenderType renderType) { Preconditions.checkArgument(name != null, "Objective name cannot be null"); Preconditions.checkArgument(criteria != null, "Criteria cannot be null"); Preconditions.checkArgument(displayName != null, "Display name cannot be null"); Preconditions.checkArgument(renderType != null, "RenderType cannot be null"); Preconditions.checkArgument(name.length() <= Short.MAX_VALUE, "The name '%s' is longer than the limit of 32767 characters (%s)", name, name.length()); - Preconditions.checkArgument(displayName.length() <= 128, "The display name '%s' is longer than the limit of 128 characters (%s)", displayName, displayName.length()); Preconditions.checkArgument(board.getObjective(name) == null, "An objective of name '%s' already exists", name); ScoreboardObjective objective = board.addObjective(name, ((CraftCriteria) criteria).criteria, CraftChatMessage.fromStringOrNull(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType)); @@ -59,14 +58,14 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public Objective getObjective(String name) throws IllegalArgumentException { + public Objective getObjective(String name) { Preconditions.checkArgument(name != null, "Objective name cannot be null"); ScoreboardObjective nms = board.getObjective(name); return nms == null ? null : new CraftObjective(this, nms); } @Override - public ImmutableSet getObjectivesByCriteria(String criteria) throws IllegalArgumentException { + public ImmutableSet getObjectivesByCriteria(String criteria) { Preconditions.checkArgument(criteria != null, "Criteria name cannot be null"); ImmutableSet.Builder objectives = ImmutableSet.builder(); @@ -80,7 +79,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public ImmutableSet getObjectivesByCriteria(Criteria criteria) throws IllegalArgumentException { + public ImmutableSet getObjectivesByCriteria(Criteria criteria) { Preconditions.checkArgument(criteria != null, "Criteria cannot be null"); ImmutableSet.Builder objectives = ImmutableSet.builder(); @@ -100,7 +99,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public Objective getObjective(DisplaySlot slot) throws IllegalArgumentException { + public Objective getObjective(DisplaySlot slot) { Preconditions.checkArgument(slot != null, "Display slot cannot be null"); ScoreboardObjective objective = board.getDisplayObjective(CraftScoreboardTranslations.fromBukkitSlot(slot)); if (objective == null) { @@ -110,14 +109,14 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public ImmutableSet getScores(OfflinePlayer player) throws IllegalArgumentException { + public ImmutableSet getScores(OfflinePlayer player) { Preconditions.checkArgument(player != null, "OfflinePlayer cannot be null"); return getScores(player.getName()); } @Override - public ImmutableSet getScores(String entry) throws IllegalArgumentException { + public ImmutableSet getScores(String entry) { Preconditions.checkArgument(entry != null, "Entry cannot be null"); ImmutableSet.Builder scores = ImmutableSet.builder(); @@ -128,14 +127,14 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public void resetScores(OfflinePlayer player) throws IllegalArgumentException { + public void resetScores(OfflinePlayer player) { Preconditions.checkArgument(player != null, "OfflinePlayer cannot be null"); resetScores(player.getName()); } @Override - public void resetScores(String entry) throws IllegalArgumentException { + public void resetScores(String entry) { Preconditions.checkArgument(entry != null, "Entry cannot be null"); for (ScoreboardObjective objective : this.board.getObjectives()) { @@ -144,7 +143,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public Team getPlayerTeam(OfflinePlayer player) throws IllegalArgumentException { + public Team getPlayerTeam(OfflinePlayer player) { Preconditions.checkArgument(player != null, "OfflinePlayer cannot be null"); ScoreboardTeam team = board.getPlayersTeam(player.getName()); @@ -152,7 +151,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public Team getEntryTeam(String entry) throws IllegalArgumentException { + public Team getEntryTeam(String entry) { Preconditions.checkArgument(entry != null, "Entry cannot be null"); ScoreboardTeam team = board.getPlayersTeam(entry); @@ -160,7 +159,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public Team getTeam(String teamName) throws IllegalArgumentException { + public Team getTeam(String teamName) { Preconditions.checkArgument(teamName != null, "Team name cannot be null"); ScoreboardTeam team = board.getPlayerTeam(teamName); @@ -173,7 +172,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public Team registerNewTeam(String name) throws IllegalArgumentException { + public Team registerNewTeam(String name) { Preconditions.checkArgument(name != null, "Team name cannot be null"); Preconditions.checkArgument(name.length() <= Short.MAX_VALUE, "Team name '%s' is longer than the limit of 32767 characters (%s)", name, name.length()); Preconditions.checkArgument(board.getPlayerTeam(name) == null, "Team name '%s' is already in use", name); @@ -200,7 +199,7 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { } @Override - public void clearSlot(DisplaySlot slot) throws IllegalArgumentException { + public void clearSlot(DisplaySlot slot) { Preconditions.checkArgument(slot != null, "Slot cannot be null"); board.setDisplayObjective(CraftScoreboardTranslations.fromBukkitSlot(slot), null); } diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardComponent.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardComponent.java index d26d09d41..5a5f03e0d 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardComponent.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardComponent.java @@ -7,11 +7,11 @@ abstract class CraftScoreboardComponent { this.scoreboard = scoreboard; } - abstract CraftScoreboard checkState() throws IllegalStateException; + abstract CraftScoreboard checkState(); public CraftScoreboard getScoreboard() { return scoreboard; } - abstract void unregister() throws IllegalStateException; + abstract void unregister(); } diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java index 230841a84..6c147a74b 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardManager.java @@ -53,7 +53,7 @@ public final class CraftScoreboardManager implements ScoreboardManager { } // CraftBukkit method - public void setPlayerBoard(CraftPlayer player, org.bukkit.scoreboard.Scoreboard bukkitScoreboard) throws IllegalArgumentException { + public void setPlayerBoard(CraftPlayer player, org.bukkit.scoreboard.Scoreboard bukkitScoreboard) { Preconditions.checkArgument(bukkitScoreboard instanceof CraftScoreboard, "Cannot set player scoreboard to an unregistered Scoreboard"); CraftScoreboard scoreboard = (CraftScoreboard) bukkitScoreboard; diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java index 8eeea7105..dbfbb9570 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftTeam.java @@ -22,64 +22,59 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { } @Override - public String getName() throws IllegalStateException { + public String getName() { checkState(); return team.getName(); } @Override - public String getDisplayName() throws IllegalStateException { + public String getDisplayName() { checkState(); return CraftChatMessage.fromComponent(team.getDisplayName()); } @Override - public void setDisplayName(String displayName) throws IllegalStateException { + public void setDisplayName(String displayName) { Preconditions.checkArgument(displayName != null, "Display name cannot be null"); - int lengthStripedDisplayName = ChatColor.stripColor(displayName).length(); - Preconditions.checkArgument(lengthStripedDisplayName <= 128, "Display name '%s' is longer than the limit of 128 characters (%s)", displayName, lengthStripedDisplayName); checkState(); team.setDisplayName(CraftChatMessage.fromString(displayName)[0]); // SPIGOT-4112: not nullable } @Override - public String getPrefix() throws IllegalStateException { + public String getPrefix() { checkState(); return CraftChatMessage.fromComponent(team.getPlayerPrefix()); } @Override - public void setPrefix(String prefix) throws IllegalStateException, IllegalArgumentException { + public void setPrefix(String prefix) { Preconditions.checkArgument(prefix != null, "Prefix cannot be null"); - int lengthStripedPrefix = ChatColor.stripColor(prefix).length(); - Preconditions.checkArgument(lengthStripedPrefix <= 64, "Prefix '%s' is longer than the limit of 64 characters (%s)", prefix, lengthStripedPrefix); checkState(); team.setPlayerPrefix(CraftChatMessage.fromStringOrNull(prefix)); } @Override - public String getSuffix() throws IllegalStateException { + public String getSuffix() { checkState(); return CraftChatMessage.fromComponent(team.getPlayerSuffix()); } @Override - public void setSuffix(String suffix) throws IllegalStateException, IllegalArgumentException { + public void setSuffix(String suffix) { Preconditions.checkArgument(suffix != null, "Suffix cannot be null"); - int lengthStripedSuffix = ChatColor.stripColor(suffix).length(); - Preconditions.checkArgument(lengthStripedSuffix <= 64, "Suffix '%s' is longer than the limit of 64 characters (%s)", suffix, lengthStripedSuffix); + checkState(); team.setPlayerSuffix(CraftChatMessage.fromStringOrNull(suffix)); } @Override - public ChatColor getColor() throws IllegalStateException { + public ChatColor getColor() { checkState(); return CraftChatMessage.getColor(team.getColor()); @@ -94,28 +89,28 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { } @Override - public boolean allowFriendlyFire() throws IllegalStateException { + public boolean allowFriendlyFire() { checkState(); return team.isAllowFriendlyFire(); } @Override - public void setAllowFriendlyFire(boolean enabled) throws IllegalStateException { + public void setAllowFriendlyFire(boolean enabled) { checkState(); team.setAllowFriendlyFire(enabled); } @Override - public boolean canSeeFriendlyInvisibles() throws IllegalStateException { + public boolean canSeeFriendlyInvisibles() { checkState(); return team.canSeeFriendlyInvisibles(); } @Override - public void setCanSeeFriendlyInvisibles(boolean enabled) throws IllegalStateException { + public void setCanSeeFriendlyInvisibles(boolean enabled) { checkState(); team.setSeeFriendlyInvisibles(enabled); @@ -136,7 +131,7 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { } @Override - public Set getPlayers() throws IllegalStateException { + public Set getPlayers() { checkState(); ImmutableSet.Builder players = ImmutableSet.builder(); @@ -147,7 +142,7 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { } @Override - public Set getEntries() throws IllegalStateException { + public Set getEntries() { checkState(); ImmutableSet.Builder entries = ImmutableSet.builder(); @@ -158,20 +153,20 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { } @Override - public int getSize() throws IllegalStateException { + public int getSize() { checkState(); return team.getPlayers().size(); } @Override - public void addPlayer(OfflinePlayer player) throws IllegalStateException, IllegalArgumentException { + public void addPlayer(OfflinePlayer player) { Preconditions.checkArgument(player != null, "OfflinePlayer cannot be null"); addEntry(player.getName()); } @Override - public void addEntry(String entry) throws IllegalStateException, IllegalArgumentException { + public void addEntry(String entry) { Preconditions.checkArgument(entry != null, "Entry cannot be null"); CraftScoreboard scoreboard = checkState(); @@ -179,13 +174,13 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { } @Override - public boolean removePlayer(OfflinePlayer player) throws IllegalStateException, IllegalArgumentException { + public boolean removePlayer(OfflinePlayer player) { Preconditions.checkArgument(player != null, "OfflinePlayer cannot be null"); return removeEntry(player.getName()); } @Override - public boolean removeEntry(String entry) throws IllegalStateException, IllegalArgumentException { + public boolean removeEntry(String entry) { Preconditions.checkArgument(entry != null, "Entry cannot be null"); CraftScoreboard scoreboard = checkState(); @@ -212,14 +207,14 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { } @Override - public void unregister() throws IllegalStateException { + public void unregister() { CraftScoreboard scoreboard = checkState(); scoreboard.board.removePlayerTeam(team); } @Override - public OptionStatus getOption(Option option) throws IllegalStateException { + public OptionStatus getOption(Option option) { checkState(); switch (option) { @@ -235,7 +230,7 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { } @Override - public void setOption(Option option, OptionStatus status) throws IllegalStateException { + public void setOption(Option option, OptionStatus status) { checkState(); switch (option) { @@ -284,7 +279,7 @@ final class CraftTeam extends CraftScoreboardComponent implements Team { } @Override - CraftScoreboard checkState() throws IllegalStateException { + CraftScoreboard checkState() { Preconditions.checkState(getScoreboard().board.getPlayerTeam(team.getName()) != null, "Unregistered scoreboard component"); return getScoreboard();