package net.minecraft.world.scores; import com.mojang.serialization.Codec; import io.netty.buffer.ByteBuf; import java.util.Collection; import java.util.function.IntFunction; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.util.ByIdMap; import net.minecraft.util.StringRepresentable; import net.minecraft.util.ByIdMap.OutOfBoundsStrategy; import org.jetbrains.annotations.Nullable; public abstract class Team { /** * Same as == */ public boolean isAlliedTo(@Nullable Team other) { return other == null ? false : this == other; } /** * Retrieve the name by which this team is registered in the scoreboard */ public abstract String getName(); public abstract MutableComponent getFormattedName(Component formattedName); /** * Checks whether members of this team can see other members that are invisible. */ public abstract boolean canSeeFriendlyInvisibles(); /** * Checks whether friendly fire (PVP between members of the team) is allowed. */ public abstract boolean isAllowFriendlyFire(); /** * Gets the visibility flags for player name tags. */ public abstract Team.Visibility getNameTagVisibility(); /** * Gets the color for this team. The team color is used mainly for team kill objectives and team-specific setDisplay usage. It does _not_ affect all situations (for instance, the prefix is used for the glowing effect). */ public abstract ChatFormatting getColor(); /** * Gets a collection of all members of this team. */ public abstract Collection getPlayers(); /** * Gets the visibility flags for player death messages. */ public abstract Team.Visibility getDeathMessageVisibility(); /** * Gets the rule to be used for handling collisions with members of this team. */ public abstract Team.CollisionRule getCollisionRule(); public static enum CollisionRule implements StringRepresentable { ALWAYS("always", 0), NEVER("never", 1), PUSH_OTHER_TEAMS("pushOtherTeams", 2), PUSH_OWN_TEAM("pushOwnTeam", 3); public static final Codec CODEC = StringRepresentable.fromEnum(Team.CollisionRule::values); private static final IntFunction BY_ID = ByIdMap.continuous(collisionRule -> collisionRule.id, values(), OutOfBoundsStrategy.ZERO); public static final StreamCodec STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, collisionRule -> collisionRule.id); public final String name; public final int id; private CollisionRule(final String name, final int id) { this.name = name; this.id = id; } public Component getDisplayName() { return Component.translatable("team.collision." + this.name); } @Override public String getSerializedName() { return this.name; } } public static enum Visibility implements StringRepresentable { ALWAYS("always", 0), NEVER("never", 1), HIDE_FOR_OTHER_TEAMS("hideForOtherTeams", 2), HIDE_FOR_OWN_TEAM("hideForOwnTeam", 3); public static final Codec CODEC = StringRepresentable.fromEnum(Team.Visibility::values); private static final IntFunction BY_ID = ByIdMap.continuous(visibility -> visibility.id, values(), OutOfBoundsStrategy.ZERO); public static final StreamCodec STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, visibility -> visibility.id); public final String name; public final int id; private Visibility(final String name, final int id) { this.name = name; this.id = id; } public Component getDisplayName() { return Component.translatable("team.visibility." + this.name); } @Override public String getSerializedName() { return this.name; } } }