diff options
author | md_5 <git@md-5.net> | 2018-10-26 19:38:41 +1100 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-10-26 19:38:41 +1100 |
commit | a835b035387ca35589e89a221bef88d6b255b046 (patch) | |
tree | 5bfc0e6abc2579b9ad7956885f019532bb3fbb72 | |
parent | 3359cb1998507ec5628957115568eaaf01d70ed0 (diff) | |
download | craftbukkit-a835b035387ca35589e89a221bef88d6b255b046.tar craftbukkit-a835b035387ca35589e89a221bef88d6b255b046.tar.gz craftbukkit-a835b035387ca35589e89a221bef88d6b255b046.tar.lz craftbukkit-a835b035387ca35589e89a221bef88d6b255b046.tar.xz craftbukkit-a835b035387ca35589e89a221bef88d6b255b046.zip |
SPIGOT-4443: Scoreboard RenderType API
3 files changed, 34 insertions, 4 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java index 0ef48af0..2b96d3c9 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftObjective.java @@ -2,13 +2,13 @@ package org.bukkit.craftbukkit.scoreboard; import net.minecraft.server.Scoreboard; import net.minecraft.server.ScoreboardObjective; -import net.minecraft.server.ScoreboardServer; import org.apache.commons.lang.Validate; import org.bukkit.OfflinePlayer; import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.RenderType; import org.bukkit.scoreboard.Score; final class CraftObjective extends CraftScoreboardComponent implements Objective { @@ -86,6 +86,21 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective return null; } + @Override + public void setRenderType(RenderType renderType) throws IllegalStateException { + Validate.notNull(renderType, "RenderType cannot be null"); + CraftScoreboard scoreboard = checkState(); + + this.objective.a(CraftScoreboardTranslations.fromBukkitRender(renderType)); + } + + @Override + public RenderType getRenderType() throws IllegalStateException { + CraftScoreboard scoreboard = checkState(); + + return CraftScoreboardTranslations.toBukkitRender(this.objective.f()); + } + public Score getScore(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException { Validate.notNull(player, "Player cannot be null"); CraftScoreboard scoreboard = checkState(); @@ -112,7 +127,7 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective if (getScoreboard().board.getObjective(objective.getName()) == null) { throw new IllegalStateException("Unregistered scoreboard component"); } - + return getScoreboard(); } diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java index 61c0a55c..7320f339 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboard.java @@ -10,13 +10,13 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.RenderType; import org.bukkit.scoreboard.Score; import org.bukkit.scoreboard.Team; import com.google.common.base.Function; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; -import net.minecraft.server.IScoreboardCriteria; import org.bukkit.craftbukkit.util.CraftChatMessage; public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { @@ -33,15 +33,21 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { @Override public CraftObjective registerNewObjective(String name, String criteria, String displayName) throws IllegalArgumentException { + return registerNewObjective(name, criteria, displayName, RenderType.INTEGER); + } + + @Override + public CraftObjective registerNewObjective(String name, String criteria, String displayName, RenderType renderType) throws IllegalArgumentException { Validate.notNull(name, "Objective name cannot be null"); Validate.notNull(criteria, "Criteria cannot be null"); Validate.notNull(displayName, "Display name cannot be null"); + Validate.notNull(renderType, "RenderType cannot be null"); Validate.isTrue(name.length() <= 16, "The name '" + name + "' is longer than the limit of 16 characters"); Validate.isTrue(displayName.length() <= 128, "The display name '" + displayName + "' is longer than the limit of 128 characters"); Validate.isTrue(board.getObjective(name) == null, "An objective of name '" + name + "' already exists"); CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria); - ScoreboardObjective objective = board.registerObjective(name, craftCriteria.criteria, CraftChatMessage.fromStringOrNull(displayName), IScoreboardCriteria.EnumScoreboardHealthDisplay.INTEGER); + ScoreboardObjective objective = board.registerObjective(name, craftCriteria.criteria, CraftChatMessage.fromStringOrNull(displayName), CraftScoreboardTranslations.fromBukkitRender(renderType)); return new CraftObjective(this, objective); } diff --git a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardTranslations.java b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardTranslations.java index d08e5a28..207ffdd2 100644 --- a/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardTranslations.java +++ b/src/main/java/org/bukkit/craftbukkit/scoreboard/CraftScoreboardTranslations.java @@ -1,8 +1,10 @@ package org.bukkit.craftbukkit.scoreboard; +import net.minecraft.server.IScoreboardCriteria; import net.minecraft.server.Scoreboard; import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.RenderType; import com.google.common.collect.ImmutableBiMap; @@ -23,4 +25,11 @@ class CraftScoreboardTranslations { return Scoreboard.getSlotForName(SLOTS.get(slot)); } + static RenderType toBukkitRender(IScoreboardCriteria.EnumScoreboardHealthDisplay display) { + return RenderType.valueOf(display.name()); + } + + static IScoreboardCriteria.EnumScoreboardHealthDisplay fromBukkitRender(RenderType render) { + return IScoreboardCriteria.EnumScoreboardHealthDisplay.valueOf(render.name()); + } } |