TeamCommand.java

net.minecraft.server.commands.TeamCommand

信息

  • 全限定名:net.minecraft.server.commands.TeamCommand
  • 类型:public class
  • 包:net.minecraft.server.commands
  • 源码路径:src/main/java/net/minecraft/server/commands/TeamCommand.java
  • 起始行号:L26
  • 职责:

    TODO

字段/常量

  • ERROR_TEAM_ALREADY_EXISTS

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L27
    • 说明:

      TODO

  • ERROR_TEAM_ALREADY_EMPTY

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L30
    • 说明:

      TODO

  • ERROR_TEAM_ALREADY_NAME

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L33
    • 说明:

      TODO

  • ERROR_TEAM_ALREADY_COLOR

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L36
    • 说明:

      TODO

  • ERROR_TEAM_ALREADY_FRIENDLYFIRE_ENABLED

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L39
    • 说明:

      TODO

  • ERROR_TEAM_ALREADY_FRIENDLYFIRE_DISABLED

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L42
    • 说明:

      TODO

  • ERROR_TEAM_ALREADY_FRIENDLYINVISIBLES_ENABLED

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L45
    • 说明:

      TODO

  • ERROR_TEAM_ALREADY_FRIENDLYINVISIBLES_DISABLED

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L48
    • 说明:

      TODO

  • ERROR_TEAM_NAMETAG_VISIBLITY_UNCHANGED

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L51
    • 说明:

      TODO

  • ERROR_TEAM_DEATH_MESSAGE_VISIBLITY_UNCHANGED

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L54
    • 说明:

      TODO

  • ERROR_TEAM_COLLISION_UNCHANGED

    • 类型: SimpleCommandExceptionType
    • 修饰符: private static final
    • 源码定位: L57
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

下面的方法块按源码顺序生成。

public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) @ L61

  • 方法名:register
  • 源码定位:L61
  • 返回类型:void
  • 修饰符:public static

参数:

  • dispatcher: CommandDispatcher
  • context: CommandBuildContext

说明:

TODO

private static Component getFirstMemberName(Collection<ScoreHolder> members) @ L267

  • 方法名:getFirstMemberName
  • 源码定位:L267
  • 返回类型:Component
  • 修饰符:private static

参数:

  • members: Collection

说明:

TODO

private static int leaveTeam(CommandSourceStack source, Collection<ScoreHolder> members) @ L271

  • 方法名:leaveTeam
  • 源码定位:L271
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • members: Collection

说明:

TODO

private static int joinTeam(CommandSourceStack source, PlayerTeam team, Collection<ScoreHolder> members) @ L287

  • 方法名:joinTeam
  • 源码定位:L287
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam
  • members: Collection

说明:

TODO

private static int setNametagVisibility(CommandSourceStack source, PlayerTeam team, Team.Visibility visibility) @ L305

  • 方法名:setNametagVisibility
  • 源码定位:L305
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam
  • visibility: Team.Visibility

说明:

TODO

private static int setDeathMessageVisibility(CommandSourceStack source, PlayerTeam team, Team.Visibility visibility) @ L318

  • 方法名:setDeathMessageVisibility
  • 源码定位:L318
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam
  • visibility: Team.Visibility

说明:

TODO

private static int setCollision(CommandSourceStack source, PlayerTeam team, Team.CollisionRule collision) @ L331

  • 方法名:setCollision
  • 源码定位:L331
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam
  • collision: Team.CollisionRule

说明:

TODO

private static int setFriendlySight(CommandSourceStack source, PlayerTeam team, boolean allowed) @ L343

  • 方法名:setFriendlySight
  • 源码定位:L343
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam
  • allowed: boolean

说明:

TODO

private static int setFriendlyFire(CommandSourceStack source, PlayerTeam team, boolean allowed) @ L360

  • 方法名:setFriendlyFire
  • 源码定位:L360
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam
  • allowed: boolean

说明:

TODO

private static int setDisplayName(CommandSourceStack source, PlayerTeam team, Component displayName) @ L376

  • 方法名:setDisplayName
  • 源码定位:L376
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam
  • displayName: Component

说明:

TODO

private static int setColor(CommandSourceStack source, PlayerTeam team, ChatFormatting color) @ L386

  • 方法名:setColor
  • 源码定位:L386
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam
  • color: ChatFormatting

说明:

TODO

private static int emptyTeam(CommandSourceStack source, PlayerTeam team) @ L396

  • 方法名:emptyTeam
  • 源码定位:L396
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam

说明:

TODO

private static int deleteTeam(CommandSourceStack source, PlayerTeam team) @ L411

  • 方法名:deleteTeam
  • 源码定位:L411
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam

说明:

TODO

private static int createTeam(CommandSourceStack source, String name) @ L418

  • 方法名:createTeam
  • 源码定位:L418
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • name: String

说明:

TODO

private static int createTeam(CommandSourceStack source, String name, Component displayName) @ L422

  • 方法名:createTeam
  • 源码定位:L422
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • name: String
  • displayName: Component

说明:

TODO

private static int listMembers(CommandSourceStack source, PlayerTeam team) @ L434

  • 方法名:listMembers
  • 源码定位:L434
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam

说明:

TODO

private static int listTeams(CommandSourceStack source) @ L450

  • 方法名:listTeams
  • 源码定位:L450
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack

说明:

TODO

private static int setPrefix(CommandSourceStack source, PlayerTeam team, Component prefix) @ L466

  • 方法名:setPrefix
  • 源码定位:L466
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam
  • prefix: Component

说明:

TODO

private static int setSuffix(CommandSourceStack source, PlayerTeam team, Component suffix) @ L472

  • 方法名:setSuffix
  • 源码定位:L472
  • 返回类型:int
  • 修饰符:private static

参数:

  • source: CommandSourceStack
  • team: PlayerTeam
  • suffix: Component

说明:

TODO

代码

public class TeamCommand {
    private static final SimpleCommandExceptionType ERROR_TEAM_ALREADY_EXISTS = new SimpleCommandExceptionType(
        Component.translatable("commands.team.add.duplicate")
    );
    private static final SimpleCommandExceptionType ERROR_TEAM_ALREADY_EMPTY = new SimpleCommandExceptionType(
        Component.translatable("commands.team.empty.unchanged")
    );
    private static final SimpleCommandExceptionType ERROR_TEAM_ALREADY_NAME = new SimpleCommandExceptionType(
        Component.translatable("commands.team.option.name.unchanged")
    );
    private static final SimpleCommandExceptionType ERROR_TEAM_ALREADY_COLOR = new SimpleCommandExceptionType(
        Component.translatable("commands.team.option.color.unchanged")
    );
    private static final SimpleCommandExceptionType ERROR_TEAM_ALREADY_FRIENDLYFIRE_ENABLED = new SimpleCommandExceptionType(
        Component.translatable("commands.team.option.friendlyfire.alreadyEnabled")
    );
    private static final SimpleCommandExceptionType ERROR_TEAM_ALREADY_FRIENDLYFIRE_DISABLED = new SimpleCommandExceptionType(
        Component.translatable("commands.team.option.friendlyfire.alreadyDisabled")
    );
    private static final SimpleCommandExceptionType ERROR_TEAM_ALREADY_FRIENDLYINVISIBLES_ENABLED = new SimpleCommandExceptionType(
        Component.translatable("commands.team.option.seeFriendlyInvisibles.alreadyEnabled")
    );
    private static final SimpleCommandExceptionType ERROR_TEAM_ALREADY_FRIENDLYINVISIBLES_DISABLED = new SimpleCommandExceptionType(
        Component.translatable("commands.team.option.seeFriendlyInvisibles.alreadyDisabled")
    );
    private static final SimpleCommandExceptionType ERROR_TEAM_NAMETAG_VISIBLITY_UNCHANGED = new SimpleCommandExceptionType(
        Component.translatable("commands.team.option.nametagVisibility.unchanged")
    );
    private static final SimpleCommandExceptionType ERROR_TEAM_DEATH_MESSAGE_VISIBLITY_UNCHANGED = new SimpleCommandExceptionType(
        Component.translatable("commands.team.option.deathMessageVisibility.unchanged")
    );
    private static final SimpleCommandExceptionType ERROR_TEAM_COLLISION_UNCHANGED = new SimpleCommandExceptionType(
        Component.translatable("commands.team.option.collisionRule.unchanged")
    );
 
    public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext context) {
        dispatcher.register(
            Commands.literal("team")
                .requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))
                .then(
                    Commands.literal("list")
                        .executes(c -> listTeams(c.getSource()))
                        .then(Commands.argument("team", TeamArgument.team()).executes(c -> listMembers(c.getSource(), TeamArgument.getTeam(c, "team"))))
                )
                .then(
                    Commands.literal("add")
                        .then(
                            Commands.argument("team", StringArgumentType.word())
                                .executes(c -> createTeam(c.getSource(), StringArgumentType.getString(c, "team")))
                                .then(
                                    Commands.argument("displayName", ComponentArgument.textComponent(context))
                                        .executes(
                                            c -> createTeam(
                                                c.getSource(),
                                                StringArgumentType.getString(c, "team"),
                                                ComponentArgument.getResolvedComponent(c, "displayName")
                                            )
                                        )
                                )
                        )
                )
                .then(
                    Commands.literal("remove")
                        .then(Commands.argument("team", TeamArgument.team()).executes(c -> deleteTeam(c.getSource(), TeamArgument.getTeam(c, "team"))))
                )
                .then(
                    Commands.literal("empty")
                        .then(Commands.argument("team", TeamArgument.team()).executes(c -> emptyTeam(c.getSource(), TeamArgument.getTeam(c, "team"))))
                )
                .then(
                    Commands.literal("join")
                        .then(
                            Commands.argument("team", TeamArgument.team())
                                .executes(
                                    c -> joinTeam(c.getSource(), TeamArgument.getTeam(c, "team"), Collections.singleton(c.getSource().getEntityOrException()))
                                )
                                .then(
                                    Commands.argument("members", ScoreHolderArgument.scoreHolders())
                                        .suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
                                        .executes(
                                            c -> joinTeam(
                                                c.getSource(), TeamArgument.getTeam(c, "team"), ScoreHolderArgument.getNamesWithDefaultWildcard(c, "members")
                                            )
                                        )
                                )
                        )
                )
                .then(
                    Commands.literal("leave")
                        .then(
                            Commands.argument("members", ScoreHolderArgument.scoreHolders())
                                .suggests(ScoreHolderArgument.SUGGEST_SCORE_HOLDERS)
                                .executes(c -> leaveTeam(c.getSource(), ScoreHolderArgument.getNamesWithDefaultWildcard(c, "members")))
                        )
                )
                .then(
                    Commands.literal("modify")
                        .then(
                            Commands.argument("team", TeamArgument.team())
                                .then(
                                    Commands.literal("displayName")
                                        .then(
                                            Commands.argument("displayName", ComponentArgument.textComponent(context))
                                                .executes(
                                                    c -> setDisplayName(
                                                        c.getSource(),
                                                        TeamArgument.getTeam(c, "team"),
                                                        ComponentArgument.getResolvedComponent(c, "displayName")
                                                    )
                                                )
                                        )
                                )
                                .then(
                                    Commands.literal("color")
                                        .then(
                                            Commands.argument("value", ColorArgument.color())
                                                .executes(c -> setColor(c.getSource(), TeamArgument.getTeam(c, "team"), ColorArgument.getColor(c, "value")))
                                        )
                                )
                                .then(
                                    Commands.literal("friendlyFire")
                                        .then(
                                            Commands.argument("allowed", BoolArgumentType.bool())
                                                .executes(
                                                    c -> setFriendlyFire(c.getSource(), TeamArgument.getTeam(c, "team"), BoolArgumentType.getBool(c, "allowed"))
                                                )
                                        )
                                )
                                .then(
                                    Commands.literal("seeFriendlyInvisibles")
                                        .then(
                                            Commands.argument("allowed", BoolArgumentType.bool())
                                                .executes(
                                                    c -> setFriendlySight(
                                                        c.getSource(), TeamArgument.getTeam(c, "team"), BoolArgumentType.getBool(c, "allowed")
                                                    )
                                                )
                                        )
                                )
                                .then(
                                    Commands.literal("nametagVisibility")
                                        .then(
                                            Commands.literal("never")
                                                .executes(c -> setNametagVisibility(c.getSource(), TeamArgument.getTeam(c, "team"), Team.Visibility.NEVER))
                                        )
                                        .then(
                                            Commands.literal("hideForOtherTeams")
                                                .executes(
                                                    c -> setNametagVisibility(
                                                        c.getSource(), TeamArgument.getTeam(c, "team"), Team.Visibility.HIDE_FOR_OTHER_TEAMS
                                                    )
                                                )
                                        )
                                        .then(
                                            Commands.literal("hideForOwnTeam")
                                                .executes(
                                                    c -> setNametagVisibility(c.getSource(), TeamArgument.getTeam(c, "team"), Team.Visibility.HIDE_FOR_OWN_TEAM)
                                                )
                                        )
                                        .then(
                                            Commands.literal("always")
                                                .executes(c -> setNametagVisibility(c.getSource(), TeamArgument.getTeam(c, "team"), Team.Visibility.ALWAYS))
                                        )
                                )
                                .then(
                                    Commands.literal("deathMessageVisibility")
                                        .then(
                                            Commands.literal("never")
                                                .executes(c -> setDeathMessageVisibility(c.getSource(), TeamArgument.getTeam(c, "team"), Team.Visibility.NEVER))
                                        )
                                        .then(
                                            Commands.literal("hideForOtherTeams")
                                                .executes(
                                                    c -> setDeathMessageVisibility(
                                                        c.getSource(), TeamArgument.getTeam(c, "team"), Team.Visibility.HIDE_FOR_OTHER_TEAMS
                                                    )
                                                )
                                        )
                                        .then(
                                            Commands.literal("hideForOwnTeam")
                                                .executes(
                                                    c -> setDeathMessageVisibility(
                                                        c.getSource(), TeamArgument.getTeam(c, "team"), Team.Visibility.HIDE_FOR_OWN_TEAM
                                                    )
                                                )
                                        )
                                        .then(
                                            Commands.literal("always")
                                                .executes(
                                                    c -> setDeathMessageVisibility(c.getSource(), TeamArgument.getTeam(c, "team"), Team.Visibility.ALWAYS)
                                                )
                                        )
                                )
                                .then(
                                    Commands.literal("collisionRule")
                                        .then(
                                            Commands.literal("never")
                                                .executes(c -> setCollision(c.getSource(), TeamArgument.getTeam(c, "team"), Team.CollisionRule.NEVER))
                                        )
                                        .then(
                                            Commands.literal("pushOwnTeam")
                                                .executes(c -> setCollision(c.getSource(), TeamArgument.getTeam(c, "team"), Team.CollisionRule.PUSH_OWN_TEAM))
                                        )
                                        .then(
                                            Commands.literal("pushOtherTeams")
                                                .executes(
                                                    c -> setCollision(c.getSource(), TeamArgument.getTeam(c, "team"), Team.CollisionRule.PUSH_OTHER_TEAMS)
                                                )
                                        )
                                        .then(
                                            Commands.literal("always")
                                                .executes(c -> setCollision(c.getSource(), TeamArgument.getTeam(c, "team"), Team.CollisionRule.ALWAYS))
                                        )
                                )
                                .then(
                                    Commands.literal("prefix")
                                        .then(
                                            Commands.argument("prefix", ComponentArgument.textComponent(context))
                                                .executes(
                                                    c -> setPrefix(
                                                        c.getSource(), TeamArgument.getTeam(c, "team"), ComponentArgument.getResolvedComponent(c, "prefix")
                                                    )
                                                )
                                        )
                                )
                                .then(
                                    Commands.literal("suffix")
                                        .then(
                                            Commands.argument("suffix", ComponentArgument.textComponent(context))
                                                .executes(
                                                    c -> setSuffix(
                                                        c.getSource(), TeamArgument.getTeam(c, "team"), ComponentArgument.getResolvedComponent(c, "suffix")
                                                    )
                                                )
                                        )
                                )
                        )
                )
        );
    }
 
    private static Component getFirstMemberName(Collection<ScoreHolder> members) {
        return members.iterator().next().getFeedbackDisplayName();
    }
 
    private static int leaveTeam(CommandSourceStack source, Collection<ScoreHolder> members) {
        Scoreboard scoreboard = source.getServer().getScoreboard();
 
        for (ScoreHolder member : members) {
            scoreboard.removePlayerFromTeam(member.getScoreboardName());
        }
 
        if (members.size() == 1) {
            source.sendSuccess(() -> Component.translatable("commands.team.leave.success.single", getFirstMemberName(members)), true);
        } else {
            source.sendSuccess(() -> Component.translatable("commands.team.leave.success.multiple", members.size()), true);
        }
 
        return members.size();
    }
 
    private static int joinTeam(CommandSourceStack source, PlayerTeam team, Collection<ScoreHolder> members) {
        Scoreboard scoreboard = source.getServer().getScoreboard();
 
        for (ScoreHolder member : members) {
            scoreboard.addPlayerToTeam(member.getScoreboardName(), team);
        }
 
        if (members.size() == 1) {
            source.sendSuccess(
                () -> Component.translatable("commands.team.join.success.single", getFirstMemberName(members), team.getFormattedDisplayName()), true
            );
        } else {
            source.sendSuccess(() -> Component.translatable("commands.team.join.success.multiple", members.size(), team.getFormattedDisplayName()), true);
        }
 
        return members.size();
    }
 
    private static int setNametagVisibility(CommandSourceStack source, PlayerTeam team, Team.Visibility visibility) throws CommandSyntaxException {
        if (team.getNameTagVisibility() == visibility) {
            throw ERROR_TEAM_NAMETAG_VISIBLITY_UNCHANGED.create();
        } else {
            team.setNameTagVisibility(visibility);
            source.sendSuccess(
                () -> Component.translatable("commands.team.option.nametagVisibility.success", team.getFormattedDisplayName(), visibility.getDisplayName()),
                true
            );
            return 0;
        }
    }
 
    private static int setDeathMessageVisibility(CommandSourceStack source, PlayerTeam team, Team.Visibility visibility) throws CommandSyntaxException {
        if (team.getDeathMessageVisibility() == visibility) {
            throw ERROR_TEAM_DEATH_MESSAGE_VISIBLITY_UNCHANGED.create();
        } else {
            team.setDeathMessageVisibility(visibility);
            source.sendSuccess(
                () -> Component.translatable("commands.team.option.deathMessageVisibility.success", team.getFormattedDisplayName(), visibility.getDisplayName()),
                true
            );
            return 0;
        }
    }
 
    private static int setCollision(CommandSourceStack source, PlayerTeam team, Team.CollisionRule collision) throws CommandSyntaxException {
        if (team.getCollisionRule() == collision) {
            throw ERROR_TEAM_COLLISION_UNCHANGED.create();
        } else {
            team.setCollisionRule(collision);
            source.sendSuccess(
                () -> Component.translatable("commands.team.option.collisionRule.success", team.getFormattedDisplayName(), collision.getDisplayName()), true
            );
            return 0;
        }
    }
 
    private static int setFriendlySight(CommandSourceStack source, PlayerTeam team, boolean allowed) throws CommandSyntaxException {
        if (team.canSeeFriendlyInvisibles() == allowed) {
            if (allowed) {
                throw ERROR_TEAM_ALREADY_FRIENDLYINVISIBLES_ENABLED.create();
            } else {
                throw ERROR_TEAM_ALREADY_FRIENDLYINVISIBLES_DISABLED.create();
            }
        } else {
            team.setSeeFriendlyInvisibles(allowed);
            source.sendSuccess(
                () -> Component.translatable("commands.team.option.seeFriendlyInvisibles." + (allowed ? "enabled" : "disabled"), team.getFormattedDisplayName()),
                true
            );
            return 0;
        }
    }
 
    private static int setFriendlyFire(CommandSourceStack source, PlayerTeam team, boolean allowed) throws CommandSyntaxException {
        if (team.isAllowFriendlyFire() == allowed) {
            if (allowed) {
                throw ERROR_TEAM_ALREADY_FRIENDLYFIRE_ENABLED.create();
            } else {
                throw ERROR_TEAM_ALREADY_FRIENDLYFIRE_DISABLED.create();
            }
        } else {
            team.setAllowFriendlyFire(allowed);
            source.sendSuccess(
                () -> Component.translatable("commands.team.option.friendlyfire." + (allowed ? "enabled" : "disabled"), team.getFormattedDisplayName()), true
            );
            return 0;
        }
    }
 
    private static int setDisplayName(CommandSourceStack source, PlayerTeam team, Component displayName) throws CommandSyntaxException {
        if (team.getDisplayName().equals(displayName)) {
            throw ERROR_TEAM_ALREADY_NAME.create();
        } else {
            team.setDisplayName(displayName);
            source.sendSuccess(() -> Component.translatable("commands.team.option.name.success", team.getFormattedDisplayName()), true);
            return 0;
        }
    }
 
    private static int setColor(CommandSourceStack source, PlayerTeam team, ChatFormatting color) throws CommandSyntaxException {
        if (team.getColor() == color) {
            throw ERROR_TEAM_ALREADY_COLOR.create();
        } else {
            team.setColor(color);
            source.sendSuccess(() -> Component.translatable("commands.team.option.color.success", team.getFormattedDisplayName(), color.getName()), true);
            return 0;
        }
    }
 
    private static int emptyTeam(CommandSourceStack source, PlayerTeam team) throws CommandSyntaxException {
        Scoreboard scoreboard = source.getServer().getScoreboard();
        Collection<String> members = Lists.newArrayList(team.getPlayers());
        if (members.isEmpty()) {
            throw ERROR_TEAM_ALREADY_EMPTY.create();
        } else {
            for (String member : members) {
                scoreboard.removePlayerFromTeam(member, team);
            }
 
            source.sendSuccess(() -> Component.translatable("commands.team.empty.success", members.size(), team.getFormattedDisplayName()), true);
            return members.size();
        }
    }
 
    private static int deleteTeam(CommandSourceStack source, PlayerTeam team) {
        Scoreboard scoreboard = source.getServer().getScoreboard();
        scoreboard.removePlayerTeam(team);
        source.sendSuccess(() -> Component.translatable("commands.team.remove.success", team.getFormattedDisplayName()), true);
        return scoreboard.getPlayerTeams().size();
    }
 
    private static int createTeam(CommandSourceStack source, String name) throws CommandSyntaxException {
        return createTeam(source, name, Component.literal(name));
    }
 
    private static int createTeam(CommandSourceStack source, String name, Component displayName) throws CommandSyntaxException {
        Scoreboard scoreboard = source.getServer().getScoreboard();
        if (scoreboard.getPlayerTeam(name) != null) {
            throw ERROR_TEAM_ALREADY_EXISTS.create();
        } else {
            PlayerTeam team = scoreboard.addPlayerTeam(name);
            team.setDisplayName(displayName);
            source.sendSuccess(() -> Component.translatable("commands.team.add.success", team.getFormattedDisplayName()), true);
            return scoreboard.getPlayerTeams().size();
        }
    }
 
    private static int listMembers(CommandSourceStack source, PlayerTeam team) {
        Collection<String> members = team.getPlayers();
        if (members.isEmpty()) {
            source.sendSuccess(() -> Component.translatable("commands.team.list.members.empty", team.getFormattedDisplayName()), false);
        } else {
            source.sendSuccess(
                () -> Component.translatable(
                    "commands.team.list.members.success", team.getFormattedDisplayName(), members.size(), ComponentUtils.formatList(members)
                ),
                false
            );
        }
 
        return members.size();
    }
 
    private static int listTeams(CommandSourceStack source) {
        Collection<PlayerTeam> teams = source.getServer().getScoreboard().getPlayerTeams();
        if (teams.isEmpty()) {
            source.sendSuccess(() -> Component.translatable("commands.team.list.teams.empty"), false);
        } else {
            source.sendSuccess(
                () -> Component.translatable(
                    "commands.team.list.teams.success", teams.size(), ComponentUtils.formatList(teams, PlayerTeam::getFormattedDisplayName)
                ),
                false
            );
        }
 
        return teams.size();
    }
 
    private static int setPrefix(CommandSourceStack source, PlayerTeam team, Component prefix) {
        team.setPlayerPrefix(prefix);
        source.sendSuccess(() -> Component.translatable("commands.team.option.prefix.success", prefix), false);
        return 1;
    }
 
    private static int setSuffix(CommandSourceStack source, PlayerTeam team, Component suffix) {
        team.setPlayerSuffix(suffix);
        source.sendSuccess(() -> Component.translatable("commands.team.option.suffix.success", suffix), false);
        return 1;
    }
}

引用的其他类

  • ChatFormatting

    • 引用位置: 参数
  • CommandBuildContext

    • 引用位置: 参数
  • CommandSourceStack

    • 引用位置: 参数
  • Commands

    • 引用位置: 方法调用
    • 关联成员: Commands.argument(), Commands.hasPermission(), Commands.literal()
  • ColorArgument

    • 引用位置: 方法调用
    • 关联成员: ColorArgument.color(), ColorArgument.getColor()
  • ComponentArgument

    • 引用位置: 方法调用
    • 关联成员: ComponentArgument.getResolvedComponent(), ComponentArgument.textComponent()
  • ScoreHolderArgument

    • 引用位置: 方法调用
    • 关联成员: ScoreHolderArgument.getNamesWithDefaultWildcard(), ScoreHolderArgument.scoreHolders()
  • TeamArgument

    • 引用位置: 方法调用
    • 关联成员: TeamArgument.getTeam(), TeamArgument.team()
  • Component

    • 引用位置: 参数/方法调用/返回值
    • 关联成员: Component.literal(), Component.translatable()
  • ComponentUtils

    • 引用位置: 方法调用
    • 关联成员: ComponentUtils.formatList()
  • PlayerTeam

    • 引用位置: 参数
  • ScoreHolder

    • 引用位置: 参数
  • Team

    • 引用位置: 参数