SPIGOT-4443: Scoreboard RenderType API

This commit is contained in:
md_5 2018-10-26 19:38:41 +11:00
parent 3359cb1998
commit a835b03538
3 changed files with 34 additions and 4 deletions

View File

@ -2,13 +2,13 @@ package org.bukkit.craftbukkit.scoreboard;
import net.minecraft.server.Scoreboard; import net.minecraft.server.Scoreboard;
import net.minecraft.server.ScoreboardObjective; import net.minecraft.server.ScoreboardObjective;
import net.minecraft.server.ScoreboardServer;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.RenderType;
import org.bukkit.scoreboard.Score; import org.bukkit.scoreboard.Score;
final class CraftObjective extends CraftScoreboardComponent implements Objective { final class CraftObjective extends CraftScoreboardComponent implements Objective {
@ -86,6 +86,21 @@ final class CraftObjective extends CraftScoreboardComponent implements Objective
return null; 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 { public Score getScore(OfflinePlayer player) throws IllegalArgumentException, IllegalStateException {
Validate.notNull(player, "Player cannot be null"); Validate.notNull(player, "Player cannot be null");
CraftScoreboard scoreboard = checkState(); CraftScoreboard scoreboard = checkState();

View File

@ -10,13 +10,13 @@ import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.RenderType;
import org.bukkit.scoreboard.Score; import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Team; import org.bukkit.scoreboard.Team;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import net.minecraft.server.IScoreboardCriteria;
import org.bukkit.craftbukkit.util.CraftChatMessage; import org.bukkit.craftbukkit.util.CraftChatMessage;
public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard { public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
@ -33,15 +33,21 @@ public final class CraftScoreboard implements org.bukkit.scoreboard.Scoreboard {
@Override @Override
public CraftObjective registerNewObjective(String name, String criteria, String displayName) throws IllegalArgumentException { 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(name, "Objective name cannot be null");
Validate.notNull(criteria, "Criteria cannot be null"); Validate.notNull(criteria, "Criteria cannot be null");
Validate.notNull(displayName, "Display name 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(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(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"); Validate.isTrue(board.getObjective(name) == null, "An objective of name '" + name + "' already exists");
CraftCriteria craftCriteria = CraftCriteria.getFromBukkit(criteria); 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); return new CraftObjective(this, objective);
} }

View File

@ -1,8 +1,10 @@
package org.bukkit.craftbukkit.scoreboard; package org.bukkit.craftbukkit.scoreboard;
import net.minecraft.server.IScoreboardCriteria;
import net.minecraft.server.Scoreboard; import net.minecraft.server.Scoreboard;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.RenderType;
import com.google.common.collect.ImmutableBiMap; import com.google.common.collect.ImmutableBiMap;
@ -23,4 +25,11 @@ class CraftScoreboardTranslations {
return Scoreboard.getSlotForName(SLOTS.get(slot)); 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());
}
} }