package net.minecraft.world.scores;

import java.util.Collection;
import javax.annotation.Nullable;
import net.minecraft.network.chat.ComponentUtils;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.TextComponent;
import com.google.common.collect.Sets;
import net.minecraft.network.chat.Style;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import java.util.Set;

public class PlayerTeam extends Team {
    private final Scoreboard scoreboard;
    private final String name;
    private final Set<String> players;
    private Component displayName;
    private Component playerPrefix;
    private Component playerSuffix;
    private boolean allowFriendlyFire;
    private boolean seeFriendlyInvisibles;
    private Visibility nameTagVisibility;
    private Visibility deathMessageVisibility;
    private ChatFormatting color;
    private CollisionRule collisionRule;
    private final Style displayNameStyle;
    
    public PlayerTeam(final Scoreboard dfm, final String string) {
        this.players = Sets.newHashSet();
        this.playerPrefix = TextComponent.EMPTY;
        this.playerSuffix = TextComponent.EMPTY;
        this.allowFriendlyFire = true;
        this.seeFriendlyInvisibles = true;
        this.nameTagVisibility = Visibility.ALWAYS;
        this.deathMessageVisibility = Visibility.ALWAYS;
        this.color = ChatFormatting.RESET;
        this.collisionRule = CollisionRule.ALWAYS;
        this.scoreboard = dfm;
        this.name = string;
        this.displayName = new TextComponent(string);
        this.displayNameStyle = Style.EMPTY.withInsertion(string).withHoverEvent(new HoverEvent((HoverEvent.Action<T>)HoverEvent.Action.SHOW_TEXT, (T)new TextComponent(string)));
    }
    
    @Override
    public String getName() {
        return this.name;
    }
    
    public Component getDisplayName() {
        return this.displayName;
    }
    
    public MutableComponent getFormattedDisplayName() {
        final MutableComponent mx2 = ComponentUtils.wrapInSquareBrackets(this.displayName.copy().withStyle(this.displayNameStyle));
        final ChatFormatting i3 = this.getColor();
        if (i3 != ChatFormatting.RESET) {
            mx2.withStyle(i3);
        }
        return mx2;
    }
    
    public void setDisplayName(final Component mr) {
        if (mr == null) {
            throw new IllegalArgumentException("Name cannot be null");
        }
        this.displayName = mr;
        this.scoreboard.onTeamChanged(this);
    }
    
    public void setPlayerPrefix(@Nullable final Component mr) {
        this.playerPrefix = ((mr == null) ? TextComponent.EMPTY : mr);
        this.scoreboard.onTeamChanged(this);
    }
    
    public Component getPlayerPrefix() {
        return this.playerPrefix;
    }
    
    public void setPlayerSuffix(@Nullable final Component mr) {
        this.playerSuffix = ((mr == null) ? TextComponent.EMPTY : mr);
        this.scoreboard.onTeamChanged(this);
    }
    
    public Component getPlayerSuffix() {
        return this.playerSuffix;
    }
    
    @Override
    public Collection<String> getPlayers() {
        return this.players;
    }
    
    @Override
    public MutableComponent getFormattedName(final Component mr) {
        final MutableComponent mx3 = new TextComponent("").append(this.playerPrefix).append(mr).append(this.playerSuffix);
        final ChatFormatting i4 = this.getColor();
        if (i4 != ChatFormatting.RESET) {
            mx3.withStyle(i4);
        }
        return mx3;
    }
    
    public static MutableComponent formatNameForTeam(@Nullable final Team dfo, final Component mr) {
        if (dfo == null) {
            return mr.copy();
        }
        return dfo.getFormattedName(mr);
    }
    
    @Override
    public boolean isAllowFriendlyFire() {
        return this.allowFriendlyFire;
    }
    
    public void setAllowFriendlyFire(final boolean boolean1) {
        this.allowFriendlyFire = boolean1;
        this.scoreboard.onTeamChanged(this);
    }
    
    @Override
    public boolean canSeeFriendlyInvisibles() {
        return this.seeFriendlyInvisibles;
    }
    
    public void setSeeFriendlyInvisibles(final boolean boolean1) {
        this.seeFriendlyInvisibles = boolean1;
        this.scoreboard.onTeamChanged(this);
    }
    
    @Override
    public Visibility getNameTagVisibility() {
        return this.nameTagVisibility;
    }
    
    @Override
    public Visibility getDeathMessageVisibility() {
        return this.deathMessageVisibility;
    }
    
    public void setNameTagVisibility(final Visibility b) {
        this.nameTagVisibility = b;
        this.scoreboard.onTeamChanged(this);
    }
    
    public void setDeathMessageVisibility(final Visibility b) {
        this.deathMessageVisibility = b;
        this.scoreboard.onTeamChanged(this);
    }
    
    @Override
    public CollisionRule getCollisionRule() {
        return this.collisionRule;
    }
    
    public void setCollisionRule(final CollisionRule a) {
        this.collisionRule = a;
        this.scoreboard.onTeamChanged(this);
    }
    
    public int packOptions() {
        int integer2 = 0;
        if (this.isAllowFriendlyFire()) {
            integer2 |= 0x1;
        }
        if (this.canSeeFriendlyInvisibles()) {
            integer2 |= 0x2;
        }
        return integer2;
    }
    
    public void unpackOptions(final int integer) {
        this.setAllowFriendlyFire((integer & 0x1) > 0);
        this.setSeeFriendlyInvisibles((integer & 0x2) > 0);
    }
    
    public void setColor(final ChatFormatting i) {
        this.color = i;
        this.scoreboard.onTeamChanged(this);
    }
    
    @Override
    public ChatFormatting getColor() {
        return this.color;
    }
}
