ScoreboardCommand.java
net.minecraft.server.commands.ScoreboardCommand
信息
- 全限定名:net.minecraft.server.commands.ScoreboardCommand
- 类型:public class
- 包:net.minecraft.server.commands
- 源码路径:src/main/java/net/minecraft/server/commands/ScoreboardCommand.java
- 起始行号:L48
- 职责:
TODO
字段/常量
-
ERROR_OBJECTIVE_ALREADY_EXISTS- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L49 - 说明:
TODO
- 类型:
-
ERROR_DISPLAY_SLOT_ALREADY_EMPTY- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L52 - 说明:
TODO
- 类型:
-
ERROR_DISPLAY_SLOT_ALREADY_SET- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L55 - 说明:
TODO
- 类型:
-
ERROR_TRIGGER_ALREADY_ENABLED- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L58 - 说明:
TODO
- 类型:
-
ERROR_NOT_TRIGGER- 类型:
SimpleCommandExceptionType - 修饰符:
private static final - 源码定位:
L61 - 说明:
TODO
- 类型:
-
ERROR_NO_VALUE- 类型:
Dynamic2CommandExceptionType - 修饰符:
private static final - 源码定位:
L64 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.server.commands.ScoreboardCommand.NumberFormatCommandExecutor- 类型:
interface - 修饰符:
public - 源码定位:
L889 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) @ L68
- 方法名:register
- 源码定位:L68
- 返回类型:void
- 修饰符:public static
参数:
- dispatcher: CommandDispatcher
- context: CommandBuildContext
说明:
TODO
private static ArgumentBuilder<CommandSourceStack,?> addNumberFormats(CommandBuildContext context, ArgumentBuilder<CommandSourceStack,?> top, ScoreboardCommand.NumberFormatCommandExecutor callback) @ L382
- 方法名:addNumberFormats
- 源码定位:L382
- 返回类型:ArgumentBuilder<CommandSourceStack,?>
- 修饰符:private static
参数:
- context: CommandBuildContext
- top: ArgumentBuilder<CommandSourceStack,?>
- callback: ScoreboardCommand.NumberFormatCommandExecutor
说明:
TODO
private static LiteralArgumentBuilder<CommandSourceStack> createRenderTypeModify() @ L397
- 方法名:createRenderTypeModify
- 源码定位:L397
- 返回类型:LiteralArgumentBuilder
- 修饰符:private static
参数:
- 无
说明:
TODO
private static CompletableFuture<Suggestions> suggestTriggers(CommandSourceStack source, Collection<ScoreHolder> targets, SuggestionsBuilder builder) @ L409
- 方法名:suggestTriggers
- 源码定位:L409
- 返回类型:CompletableFuture
- 修饰符:private static
参数:
- source: CommandSourceStack
- targets: Collection
- builder: SuggestionsBuilder
说明:
TODO
private static int getScore(CommandSourceStack source, ScoreHolder target, Objective objective) @ L434
- 方法名:getScore
- 源码定位:L434
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- target: ScoreHolder
- objective: Objective
说明:
TODO
private static Component getFirstTargetName(Collection<ScoreHolder> names) @ L450
- 方法名:getFirstTargetName
- 源码定位:L450
- 返回类型:Component
- 修饰符:private static
参数:
- names: Collection
说明:
TODO
private static int performOperation(CommandSourceStack source, Collection<ScoreHolder> targets, Objective targetObjective, OperationArgument.Operation operation, Collection<ScoreHolder> sources, Objective sourceObjective) @ L454
- 方法名:performOperation
- 源码定位:L454
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- targets: Collection
- targetObjective: Objective
- operation: OperationArgument.Operation
- sources: Collection
- sourceObjective: Objective
说明:
TODO
private static int enableTrigger(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective) @ L496
- 方法名:enableTrigger
- 源码定位:L496
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- names: Collection
- objective: Objective
说明:
TODO
private static int resetScores(CommandSourceStack source, Collection<ScoreHolder> names) @ L533
- 方法名:resetScores
- 源码定位:L533
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- names: Collection
说明:
TODO
private static int resetScore(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective) @ L549
- 方法名:resetScore
- 源码定位:L549
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- names: Collection
- objective: Objective
说明:
TODO
private static int setScore(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective, int value) @ L572
- 方法名:setScore
- 源码定位:L572
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- names: Collection
- objective: Objective
- value: int
说明:
TODO
private static int setScoreDisplay(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective, Component display) @ L596
- 方法名:setScoreDisplay
- 源码定位:L596
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- names: Collection
- objective: Objective
- display: Component
说明:
TODO
private static int setScoreNumberFormat(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective, NumberFormat numberFormat) @ L638
- 方法名:setScoreNumberFormat
- 源码定位:L638
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- names: Collection
- objective: Objective
- numberFormat: NumberFormat
说明:
TODO
private static int addScore(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective, int value) @ L680
- 方法名:addScore
- 源码定位:L680
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- names: Collection
- objective: Objective
- value: int
说明:
TODO
private static int removeScore(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective, int value) @ L708
- 方法名:removeScore
- 源码定位:L708
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- names: Collection
- objective: Objective
- value: int
说明:
TODO
private static int listTrackedPlayers(CommandSourceStack source) @ L736
- 方法名:listTrackedPlayers
- 源码定位:L736
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
说明:
TODO
private static int listTrackedPlayerScores(CommandSourceStack source, ScoreHolder entity) @ L752
- 方法名:listTrackedPlayerScores
- 源码定位:L752
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- entity: ScoreHolder
说明:
TODO
private static int clearDisplaySlot(CommandSourceStack source, DisplaySlot slot) @ L774
- 方法名:clearDisplaySlot
- 源码定位:L774
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- slot: DisplaySlot
说明:
TODO
private static int setDisplaySlot(CommandSourceStack source, DisplaySlot slot, Objective objective) @ L785
- 方法名:setDisplaySlot
- 源码定位:L785
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- slot: DisplaySlot
- objective: Objective
说明:
TODO
private static int setDisplayName(CommandSourceStack source, Objective objective, Component displayName) @ L798
- 方法名:setDisplayName
- 源码定位:L798
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- objective: Objective
- displayName: Component
说明:
TODO
private static int setDisplayAutoUpdate(CommandSourceStack source, Objective objective, boolean displayAutoUpdate) @ L810
- 方法名:setDisplayAutoUpdate
- 源码定位:L810
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- objective: Objective
- displayAutoUpdate: boolean
说明:
TODO
private static int setObjectiveFormat(CommandSourceStack source, Objective objective, NumberFormat numberFormat) @ L833
- 方法名:setObjectiveFormat
- 源码定位:L833
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- objective: Objective
- numberFormat: NumberFormat
说明:
TODO
private static int setRenderType(CommandSourceStack source, Objective objective, ObjectiveCriteria.RenderType renderType) @ L844
- 方法名:setRenderType
- 源码定位:L844
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- objective: Objective
- renderType: ObjectiveCriteria.RenderType
说明:
TODO
private static int removeObjective(CommandSourceStack source, Objective objective) @ L853
- 方法名:removeObjective
- 源码定位:L853
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- objective: Objective
说明:
TODO
private static int addObjective(CommandSourceStack source, String name, ObjectiveCriteria criteria, Component displayName) @ L860
- 方法名:addObjective
- 源码定位:L860
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
- name: String
- criteria: ObjectiveCriteria
- displayName: Component
说明:
TODO
private static int listObjectives(CommandSourceStack source) @ L872
- 方法名:listObjectives
- 源码定位:L872
- 返回类型:int
- 修饰符:private static
参数:
- source: CommandSourceStack
说明:
TODO
代码
public class ScoreboardCommand {
private static final SimpleCommandExceptionType ERROR_OBJECTIVE_ALREADY_EXISTS = new SimpleCommandExceptionType(
Component.translatable("commands.scoreboard.objectives.add.duplicate")
);
private static final SimpleCommandExceptionType ERROR_DISPLAY_SLOT_ALREADY_EMPTY = new SimpleCommandExceptionType(
Component.translatable("commands.scoreboard.objectives.display.alreadyEmpty")
);
private static final SimpleCommandExceptionType ERROR_DISPLAY_SLOT_ALREADY_SET = new SimpleCommandExceptionType(
Component.translatable("commands.scoreboard.objectives.display.alreadySet")
);
private static final SimpleCommandExceptionType ERROR_TRIGGER_ALREADY_ENABLED = new SimpleCommandExceptionType(
Component.translatable("commands.scoreboard.players.enable.failed")
);
private static final SimpleCommandExceptionType ERROR_NOT_TRIGGER = new SimpleCommandExceptionType(
Component.translatable("commands.scoreboard.players.enable.invalid")
);
private static final Dynamic2CommandExceptionType ERROR_NO_VALUE = new Dynamic2CommandExceptionType(
(objective, target) -> Component.translatableEscape("commands.scoreboard.players.get.null", objective, target)
);
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) {
dispatcher.register(
Commands.literal("scoreboard")
.requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
.then(
Commands.literal("objectives")
.then(Commands.literal("list").executes(c -> listObjectives(c.getSource())))
.then(
Commands.literal("add")
.then(
Commands.argument("objective", StringArgumentType.word())
.then(
Commands.argument("criteria", ObjectiveCriteriaArgument.criteria())
.executes(
c -> addObjective(
c.getSource(),
StringArgumentType.getString(c, "objective"),
ObjectiveCriteriaArgument.getCriteria(c, "criteria"),
Component.literal(StringArgumentType.getString(c, "objective"))
)
)
.then(
Commands.argument("displayName", ComponentArgument.textComponent(context))
.executes(
c -> addObjective(
c.getSource(),
StringArgumentType.getString(c, "objective"),
ObjectiveCriteriaArgument.getCriteria(c, "criteria"),
ComponentArgument.getResolvedComponent(c, "displayName")
)
)
)
)
)
)
.then(
Commands.literal("modify")
.then(
Commands.argument("objective", ObjectiveArgument.objective())
.then(
Commands.literal("displayname")
.then(
Commands.argument("displayName", ComponentArgument.textComponent(context))
.executes(
c -> setDisplayName(
c.getSource(),
ObjectiveArgument.getObjective(c, "objective"),
ComponentArgument.getResolvedComponent(c, "displayName")
)
)
)
)
.then(createRenderTypeModify())
.then(
Commands.literal("displayautoupdate")
.then(
Commands.argument("value", BoolArgumentType.bool())
.executes(
c -> setDisplayAutoUpdate(
c.getSource(),
ObjectiveArgument.getObjective(c, "objective"),
BoolArgumentType.getBool(c, "value")
)
)
)
)
.then(
addNumberFormats(
context,
Commands.literal("numberformat"),
(c, numberFormat) -> setObjectiveFormat(
c.getSource(), ObjectiveArgument.getObjective(c, "objective"), numberFormat
)
)
)
)
)
.then(
Commands.literal("remove")
.then(
Commands.argument("objective", ObjectiveArgument.objective())
.executes(c -> removeObjective(c.getSource(), ObjectiveArgument.getObjective(c, "objective")))
)
)
.then(
Commands.literal("setdisplay")
.then(
Commands.argument("slot", ScoreboardSlotArgument.displaySlot())
.executes(c -> clearDisplaySlot(c.getSource(), ScoreboardSlotArgument.getDisplaySlot(c, "slot")))
.then(
Commands.argument("objective", ObjectiveArgument.objective())
.executes(
c -> setDisplaySlot(
c.getSource(),
ScoreboardSlotArgument.getDisplaySlot(c, "slot"),
ObjectiveArgument.getObjective(c, "objective")
)
)
)
)
)
)
.then(
Commands.literal("players")
.then(
Commands.literal("list")
.executes(c -> listTrackedPlayers(c.getSource()))
.then(
Commands.argument("target", ScoreHolderArgument.scoreHolder())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.executes(c -> listTrackedPlayerScores(c.getSource(), ScoreHolderArgument.getName(c, "target")))
)
)
.then(
Commands.literal("set")
.then(
Commands.argument("targets", ScoreHolderArgument.scoreHolders())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.then(
Commands.argument("objective", ObjectiveArgument.objective())
.then(
Commands.argument("score", IntegerArgumentType.integer())
.executes(
c -> setScore(
c.getSource(),
ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets"),
ObjectiveArgument.getWritableObjective(c, "objective"),
IntegerArgumentType.getInteger(c, "score")
)
)
)
)
)
)
.then(
Commands.literal("get")
.then(
Commands.argument("target", ScoreHolderArgument.scoreHolder())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.then(
Commands.argument("objective", ObjectiveArgument.objective())
.executes(
c -> getScore(
c.getSource(), ScoreHolderArgument.getName(c, "target"), ObjectiveArgument.getObjective(c, "objective")
)
)
)
)
)
.then(
Commands.literal("add")
.then(
Commands.argument("targets", ScoreHolderArgument.scoreHolders())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.then(
Commands.argument("objective", ObjectiveArgument.objective())
.then(
Commands.argument("score", IntegerArgumentType.integer(0))
.executes(
c -> addScore(
c.getSource(),
ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets"),
ObjectiveArgument.getWritableObjective(c, "objective"),
IntegerArgumentType.getInteger(c, "score")
)
)
)
)
)
)
.then(
Commands.literal("remove")
.then(
Commands.argument("targets", ScoreHolderArgument.scoreHolders())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.then(
Commands.argument("objective", ObjectiveArgument.objective())
.then(
Commands.argument("score", IntegerArgumentType.integer(0))
.executes(
c -> removeScore(
c.getSource(),
ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets"),
ObjectiveArgument.getWritableObjective(c, "objective"),
IntegerArgumentType.getInteger(c, "score")
)
)
)
)
)
)
.then(
Commands.literal("reset")
.then(
Commands.argument("targets", ScoreHolderArgument.scoreHolders())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.executes(c -> resetScores(c.getSource(), ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets")))
.then(
Commands.argument("objective", ObjectiveArgument.objective())
.executes(
c -> resetScore(
c.getSource(),
ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets"),
ObjectiveArgument.getObjective(c, "objective")
)
)
)
)
)
.then(
Commands.literal("enable")
.then(
Commands.argument("targets", ScoreHolderArgument.scoreHolders())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.then(
Commands.argument("objective", ObjectiveArgument.objective())
.suggests(
(c, p) -> suggestTriggers(c.getSource(), ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets"), p)
)
.executes(
c -> enableTrigger(
c.getSource(),
ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets"),
ObjectiveArgument.getObjective(c, "objective")
)
)
)
)
)
.then(
Commands.literal("display")
.then(
Commands.literal("name")
.then(
Commands.argument("targets", ScoreHolderArgument.scoreHolders())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.then(
Commands.argument("objective", ObjectiveArgument.objective())
.then(
Commands.argument("name", ComponentArgument.textComponent(context))
.executes(
c -> setScoreDisplay(
c.getSource(),
ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets"),
ObjectiveArgument.getObjective(c, "objective"),
ComponentArgument.getResolvedComponent(c, "name")
)
)
)
.executes(
c -> setScoreDisplay(
c.getSource(),
ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets"),
ObjectiveArgument.getObjective(c, "objective"),
null
)
)
)
)
)
.then(
Commands.literal("numberformat")
.then(
Commands.argument("targets", ScoreHolderArgument.scoreHolders())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.then(
addNumberFormats(
context,
Commands.argument("objective", ObjectiveArgument.objective()),
(c, format) -> setScoreNumberFormat(
c.getSource(),
ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets"),
ObjectiveArgument.getObjective(c, "objective"),
format
)
)
)
)
)
)
.then(
Commands.literal("operation")
.then(
Commands.argument("targets", ScoreHolderArgument.scoreHolders())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.then(
Commands.argument("targetObjective", ObjectiveArgument.objective())
.then(
Commands.argument("operation", OperationArgument.operation())
.then(
Commands.argument("source", ScoreHolderArgument.scoreHolders())
.suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
.then(
Commands.argument("sourceObjective", ObjectiveArgument.objective())
.executes(
c -> performOperation(
c.getSource(),
ScoreHolderArgument.getNamesWithDefaultWildcard(c, "targets"),
ObjectiveArgument.getWritableObjective(c, "targetObjective"),
OperationArgument.getOperation(c, "operation"),
ScoreHolderArgument.getNamesWithDefaultWildcard(c, "source"),
ObjectiveArgument.getObjective(c, "sourceObjective")
)
)
)
)
)
)
)
)
)
);
}
private static ArgumentBuilder<CommandSourceStack, ?> addNumberFormats(
CommandBuildContext context, ArgumentBuilder<CommandSourceStack, ?> top, ScoreboardCommand.NumberFormatCommandExecutor callback
) {
return top.then(Commands.literal("blank").executes(c -> callback.run(c, BlankFormat.INSTANCE)))
.then(Commands.literal("fixed").then(Commands.argument("contents", ComponentArgument.textComponent(context)).executes(c -> {
Component contents = ComponentArgument.getResolvedComponent(c, "contents");
return callback.run(c, new FixedFormat(contents));
})))
.then(Commands.literal("styled").then(Commands.argument("style", StyleArgument.style(context)).executes(c -> {
Style style = StyleArgument.getStyle(c, "style");
return callback.run(c, new StyledFormat(style));
})))
.executes(c -> callback.run(c, null));
}
private static LiteralArgumentBuilder<CommandSourceStack> createRenderTypeModify() {
LiteralArgumentBuilder<CommandSourceStack> result = Commands.literal("rendertype");
for (ObjectiveCriteria.RenderType renderType : ObjectiveCriteria.RenderType.values()) {
result.then(
Commands.literal(renderType.getId()).executes(c -> setRenderType(c.getSource(), ObjectiveArgument.getObjective(c, "objective"), renderType))
);
}
return result;
}
private static CompletableFuture<Suggestions> suggestTriggers(CommandSourceStack source, Collection<ScoreHolder> targets, SuggestionsBuilder builder) {
List<String> result = Lists.newArrayList();
Scoreboard scoreboard = source.getServer().getScoreboard();
for (Objective objective : scoreboard.getObjectives()) {
if (objective.getCriteria() == ObjectiveCriteria.TRIGGER) {
boolean available = false;
for (ScoreHolder name : targets) {
ReadOnlyScoreInfo scoreInfo = scoreboard.getPlayerScoreInfo(name, objective);
if (scoreInfo == null || scoreInfo.isLocked()) {
available = true;
break;
}
}
if (available) {
result.add(objective.getName());
}
}
}
return SharedSuggestionProvider.suggest(result, builder);
}
private static int getScore(CommandSourceStack source, ScoreHolder target, Objective objective) throws CommandSyntaxException {
Scoreboard scoreboard = source.getServer().getScoreboard();
ReadOnlyScoreInfo score = scoreboard.getPlayerScoreInfo(target, objective);
if (score == null) {
throw ERROR_NO_VALUE.create(objective.getName(), target.getFeedbackDisplayName());
} else {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.get.success", target.getFeedbackDisplayName(), score.value(), objective.getFormattedDisplayName()
),
false
);
return score.value();
}
}
private static Component getFirstTargetName(Collection<ScoreHolder> names) {
return names.iterator().next().getFeedbackDisplayName();
}
private static int performOperation(
CommandSourceStack source,
Collection<ScoreHolder> targets,
Objective targetObjective,
OperationArgument.Operation operation,
Collection<ScoreHolder> sources,
Objective sourceObjective
) throws CommandSyntaxException {
Scoreboard scoreboard = source.getServer().getScoreboard();
int result = 0;
for (ScoreHolder target : targets) {
ScoreAccess score = scoreboard.getOrCreatePlayerScore(target, targetObjective);
for (ScoreHolder from : sources) {
ScoreAccess sourceScore = scoreboard.getOrCreatePlayerScore(from, sourceObjective);
operation.apply(score, sourceScore);
}
result += score.get();
}
if (targets.size() == 1) {
int finalResult = result;
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.operation.success.single", targetObjective.getFormattedDisplayName(), getFirstTargetName(targets), finalResult
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.operation.success.multiple", targetObjective.getFormattedDisplayName(), targets.size()
),
true
);
}
return result;
}
private static int enableTrigger(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective) throws CommandSyntaxException {
if (objective.getCriteria() != ObjectiveCriteria.TRIGGER) {
throw ERROR_NOT_TRIGGER.create();
} else {
Scoreboard scoreboard = source.getServer().getScoreboard();
int count = 0;
for (ScoreHolder name : names) {
ScoreAccess score = scoreboard.getOrCreatePlayerScore(name, objective);
if (score.locked()) {
score.unlock();
count++;
}
}
if (count == 0) {
throw ERROR_TRIGGER_ALREADY_ENABLED.create();
} else {
if (names.size() == 1) {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.enable.success.single", objective.getFormattedDisplayName(), getFirstTargetName(names)
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable("commands.scoreboard.players.enable.success.multiple", objective.getFormattedDisplayName(), names.size()),
true
);
}
return count;
}
}
}
private static int resetScores(CommandSourceStack source, Collection<ScoreHolder> names) {
Scoreboard scoreboard = source.getServer().getScoreboard();
for (ScoreHolder name : names) {
scoreboard.resetAllPlayerScores(name);
}
if (names.size() == 1) {
source.sendSuccess(() -> Component.translatable("commands.scoreboard.players.reset.all.single", getFirstTargetName(names)), true);
} else {
source.sendSuccess(() -> Component.translatable("commands.scoreboard.players.reset.all.multiple", names.size()), true);
}
return names.size();
}
private static int resetScore(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective) {
Scoreboard scoreboard = source.getServer().getScoreboard();
for (ScoreHolder name : names) {
scoreboard.resetSinglePlayerScore(name, objective);
}
if (names.size() == 1) {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.reset.specific.single", objective.getFormattedDisplayName(), getFirstTargetName(names)
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable("commands.scoreboard.players.reset.specific.multiple", objective.getFormattedDisplayName(), names.size()), true
);
}
return names.size();
}
private static int setScore(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective, int value) {
Scoreboard scoreboard = source.getServer().getScoreboard();
for (ScoreHolder name : names) {
scoreboard.getOrCreatePlayerScore(name, objective).set(value);
}
if (names.size() == 1) {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.set.success.single", objective.getFormattedDisplayName(), getFirstTargetName(names), value
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable("commands.scoreboard.players.set.success.multiple", objective.getFormattedDisplayName(), names.size(), value),
true
);
}
return value * names.size();
}
private static int setScoreDisplay(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective, @Nullable Component display) {
Scoreboard scoreboard = source.getServer().getScoreboard();
for (ScoreHolder name : names) {
scoreboard.getOrCreatePlayerScore(name, objective).display(display);
}
if (display == null) {
if (names.size() == 1) {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.display.name.clear.success.single", getFirstTargetName(names), objective.getFormattedDisplayName()
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.display.name.clear.success.multiple", names.size(), objective.getFormattedDisplayName()
),
true
);
}
} else if (names.size() == 1) {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.display.name.set.success.single", display, getFirstTargetName(names), objective.getFormattedDisplayName()
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.display.name.set.success.multiple", display, names.size(), objective.getFormattedDisplayName()
),
true
);
}
return names.size();
}
private static int setScoreNumberFormat(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective, @Nullable NumberFormat numberFormat) {
Scoreboard scoreboard = source.getServer().getScoreboard();
for (ScoreHolder name : names) {
scoreboard.getOrCreatePlayerScore(name, objective).numberFormatOverride(numberFormat);
}
if (numberFormat == null) {
if (names.size() == 1) {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.display.numberFormat.clear.success.single", getFirstTargetName(names), objective.getFormattedDisplayName()
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.display.numberFormat.clear.success.multiple", names.size(), objective.getFormattedDisplayName()
),
true
);
}
} else if (names.size() == 1) {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.display.numberFormat.set.success.single", getFirstTargetName(names), objective.getFormattedDisplayName()
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.display.numberFormat.set.success.multiple", names.size(), objective.getFormattedDisplayName()
),
true
);
}
return names.size();
}
private static int addScore(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective, int value) {
Scoreboard scoreboard = source.getServer().getScoreboard();
int result = 0;
for (ScoreHolder name : names) {
ScoreAccess score = scoreboard.getOrCreatePlayerScore(name, objective);
score.set(score.get() + value);
result += score.get();
}
if (names.size() == 1) {
int finalResult = result;
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.add.success.single", value, objective.getFormattedDisplayName(), getFirstTargetName(names), finalResult
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable("commands.scoreboard.players.add.success.multiple", value, objective.getFormattedDisplayName(), names.size()),
true
);
}
return result;
}
private static int removeScore(CommandSourceStack source, Collection<ScoreHolder> names, Objective objective, int value) {
Scoreboard scoreboard = source.getServer().getScoreboard();
int result = 0;
for (ScoreHolder name : names) {
ScoreAccess score = scoreboard.getOrCreatePlayerScore(name, objective);
score.set(score.get() - value);
result += score.get();
}
if (names.size() == 1) {
int finalResult = result;
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.remove.success.single", value, objective.getFormattedDisplayName(), getFirstTargetName(names), finalResult
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable("commands.scoreboard.players.remove.success.multiple", value, objective.getFormattedDisplayName(), names.size()),
true
);
}
return result;
}
private static int listTrackedPlayers(CommandSourceStack source) {
Collection<ScoreHolder> entities = source.getServer().getScoreboard().getTrackedPlayers();
if (entities.isEmpty()) {
source.sendSuccess(() -> Component.translatable("commands.scoreboard.players.list.empty"), false);
} else {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.list.success", entities.size(), ComponentUtils.formatList(entities, ScoreHolder::getFeedbackDisplayName)
),
false
);
}
return entities.size();
}
private static int listTrackedPlayerScores(CommandSourceStack source, ScoreHolder entity) {
Object2IntMap<Objective> scores = source.getServer().getScoreboard().listPlayerScores(entity);
if (scores.isEmpty()) {
source.sendSuccess(() -> Component.translatable("commands.scoreboard.players.list.entity.empty", entity.getFeedbackDisplayName()), false);
} else {
source.sendSuccess(
() -> Component.translatable("commands.scoreboard.players.list.entity.success", entity.getFeedbackDisplayName(), scores.size()), false
);
Object2IntMaps.fastForEach(
scores,
entry -> source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.players.list.entity.entry", ((Objective)entry.getKey()).getFormattedDisplayName(), entry.getIntValue()
),
false
)
);
}
return scores.size();
}
private static int clearDisplaySlot(CommandSourceStack source, DisplaySlot slot) throws CommandSyntaxException {
Scoreboard scoreboard = source.getServer().getScoreboard();
if (scoreboard.getDisplayObjective(slot) == null) {
throw ERROR_DISPLAY_SLOT_ALREADY_EMPTY.create();
} else {
scoreboard.setDisplayObjective(slot, null);
source.sendSuccess(() -> Component.translatable("commands.scoreboard.objectives.display.cleared", slot.getSerializedName()), true);
return 0;
}
}
private static int setDisplaySlot(CommandSourceStack source, DisplaySlot slot, Objective objective) throws CommandSyntaxException {
Scoreboard scoreboard = source.getServer().getScoreboard();
if (scoreboard.getDisplayObjective(slot) == objective) {
throw ERROR_DISPLAY_SLOT_ALREADY_SET.create();
} else {
scoreboard.setDisplayObjective(slot, objective);
source.sendSuccess(
() -> Component.translatable("commands.scoreboard.objectives.display.set", slot.getSerializedName(), objective.getDisplayName()), true
);
return 0;
}
}
private static int setDisplayName(CommandSourceStack source, Objective objective, Component displayName) {
if (!objective.getDisplayName().equals(displayName)) {
objective.setDisplayName(displayName);
source.sendSuccess(
() -> Component.translatable("commands.scoreboard.objectives.modify.displayname", objective.getName(), objective.getFormattedDisplayName()),
true
);
}
return 0;
}
private static int setDisplayAutoUpdate(CommandSourceStack source, Objective objective, boolean displayAutoUpdate) {
if (objective.displayAutoUpdate() != displayAutoUpdate) {
objective.setDisplayAutoUpdate(displayAutoUpdate);
if (displayAutoUpdate) {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.objectives.modify.displayAutoUpdate.enable", objective.getName(), objective.getFormattedDisplayName()
),
true
);
} else {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.objectives.modify.displayAutoUpdate.disable", objective.getName(), objective.getFormattedDisplayName()
),
true
);
}
}
return 0;
}
private static int setObjectiveFormat(CommandSourceStack source, Objective objective, @Nullable NumberFormat numberFormat) {
objective.setNumberFormat(numberFormat);
if (numberFormat != null) {
source.sendSuccess(() -> Component.translatable("commands.scoreboard.objectives.modify.objectiveFormat.set", objective.getName()), true);
} else {
source.sendSuccess(() -> Component.translatable("commands.scoreboard.objectives.modify.objectiveFormat.clear", objective.getName()), true);
}
return 0;
}
private static int setRenderType(CommandSourceStack source, Objective objective, ObjectiveCriteria.RenderType renderType) {
if (objective.getRenderType() != renderType) {
objective.setRenderType(renderType);
source.sendSuccess(() -> Component.translatable("commands.scoreboard.objectives.modify.rendertype", objective.getFormattedDisplayName()), true);
}
return 0;
}
private static int removeObjective(CommandSourceStack source, Objective objective) {
Scoreboard scoreboard = source.getServer().getScoreboard();
scoreboard.removeObjective(objective);
source.sendSuccess(() -> Component.translatable("commands.scoreboard.objectives.remove.success", objective.getFormattedDisplayName()), true);
return scoreboard.getObjectives().size();
}
private static int addObjective(CommandSourceStack source, String name, ObjectiveCriteria criteria, Component displayName) throws CommandSyntaxException {
Scoreboard scoreboard = source.getServer().getScoreboard();
if (scoreboard.getObjective(name) != null) {
throw ERROR_OBJECTIVE_ALREADY_EXISTS.create();
} else {
scoreboard.addObjective(name, criteria, displayName, criteria.getDefaultRenderType(), false, null);
Objective objective = scoreboard.getObjective(name);
source.sendSuccess(() -> Component.translatable("commands.scoreboard.objectives.add.success", objective.getFormattedDisplayName()), true);
return scoreboard.getObjectives().size();
}
}
private static int listObjectives(CommandSourceStack source) {
Collection<Objective> objectives = source.getServer().getScoreboard().getObjectives();
if (objectives.isEmpty()) {
source.sendSuccess(() -> Component.translatable("commands.scoreboard.objectives.list.empty"), false);
} else {
source.sendSuccess(
() -> Component.translatable(
"commands.scoreboard.objectives.list.success", objectives.size(), ComponentUtils.formatList(objectives, Objective::getFormattedDisplayName)
),
false
);
}
return objectives.size();
}
@FunctionalInterface
public interface NumberFormatCommandExecutor {
int run(CommandContext<CommandSourceStack> context, @Nullable NumberFormat format) throws CommandSyntaxException;
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Commands.argument(), Commands.hasPermission(), Commands.literal()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SharedSuggestionProvider.suggest()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ComponentArgument.getResolvedComponent(), ComponentArgument.textComponent()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ObjectiveArgument.getObjective(), ObjectiveArgument.getWritableObjective(), ObjectiveArgument.objective()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ObjectiveCriteriaArgument.criteria(), ObjectiveCriteriaArgument.getCriteria()
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
OperationArgument.getOperation(), OperationArgument.operation()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ScoreHolderArgument.getName(), ScoreHolderArgument.getNamesWithDefaultWildcard(), ScoreHolderArgument.scoreHolder(), ScoreHolderArgument.scoreHolders()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ScoreboardSlotArgument.displaySlot(), ScoreboardSlotArgument.getDisplaySlot()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
StyleArgument.getStyle(), StyleArgument.style()
- 引用位置:
-
- 引用位置:
参数/方法调用/返回值 - 关联成员:
Component.literal(), Component.translatable(), Component.translatableEscape()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ComponentUtils.formatList()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
FixedFormat()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
StyledFormat()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
ObjectiveCriteria.RenderType.values()
- 引用位置: