package net.minecraft.world.scores;

import net.minecraft.network.chat.Style;
import java.util.Collection;
import javax.annotation.Nullable;
import net.minecraft.network.chat.ComponentUtils;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.TextComponent;
import com.google.common.collect.Sets;
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;
    
    public PlayerTeam(final Scoreboard cwl, final String string) {
        this.players = Sets.newHashSet();
        this.playerPrefix = new TextComponent("");
        this.playerSuffix = new TextComponent("");
        this.allowFriendlyFire = true;
        this.seeFriendlyInvisibles = true;
        this.nameTagVisibility = Visibility.ALWAYS;
        this.deathMessageVisibility = Visibility.ALWAYS;
        this.color = ChatFormatting.RESET;
        this.collisionRule = CollisionRule.ALWAYS;
        this.scoreboard = cwl;
        this.name = string;
        this.displayName = new TextComponent(string);
    }
    
    @Override
    public String getName() {
        return this.name;
    }
    
    public Component getDisplayName() {
        return this.displayName;
    }
    
    public Component getFormattedDisplayName() {
        final HoverEvent hoverEvent;
        final Object o;
        final Component lf2 = ComponentUtils.wrapInSquareBrackets(this.displayName.deepCopy().withStyle(ln -> {
            ln.setInsertion(this.name);
            new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponent(this.name));
            ((Style)o).setHoverEvent(hoverEvent);
            return;
        }));
        final ChatFormatting g3 = this.getColor();
        if (g3 != ChatFormatting.RESET) {
            lf2.withStyle(g3);
        }
        return lf2;
    }
    
    public void setDisplayName(final Component lf) {
        if (lf == null) {
            throw new IllegalArgumentException("Name cannot be null");
        }
        this.displayName = lf;
        this.scoreboard.onTeamChanged(this);
    }
    
    public void setPlayerPrefix(@Nullable final Component lf) {
        this.playerPrefix = ((lf == null) ? new TextComponent("") : lf.deepCopy());
        this.scoreboard.onTeamChanged(this);
    }
    
    public Component getPlayerPrefix() {
        return this.playerPrefix;
    }
    
    public void setPlayerSuffix(@Nullable final Component lf) {
        this.playerSuffix = ((lf == null) ? new TextComponent("") : lf.deepCopy());
        this.scoreboard.onTeamChanged(this);
    }
    
    public Component getPlayerSuffix() {
        return this.playerSuffix;
    }
    
    @Override
    public Collection<String> getPlayers() {
        return this.players;
    }
    
    @Override
    public Component getFormattedName(final Component lf) {
        final Component lf2 = new TextComponent("").append(this.playerPrefix).append(lf).append(this.playerSuffix);
        final ChatFormatting g4 = this.getColor();
        if (g4 != ChatFormatting.RESET) {
            lf2.withStyle(g4);
        }
        return lf2;
    }
    
    public static Component formatNameForTeam(@Nullable final Team cwn, final Component lf) {
        if (cwn == null) {
            return lf.deepCopy();
        }
        return cwn.getFormattedName(lf);
    }
    
    @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 g) {
        this.color = g;
        this.scoreboard.onTeamChanged(this);
    }
    
    @Override
    public ChatFormatting getColor() {
        return this.color;
    }
}
