mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 20:16:19 +01:00
SPIGOT-4443: Scoreboard RenderType API
This commit is contained in:
parent
3359cb1998
commit
a835b03538
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user