package net.minecraft.world.scores;

import net.minecraft.network.chat.Style;
import net.minecraft.network.chat.ComponentUtils;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.Component;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;

public class Objective {
    private final Scoreboard scoreboard;
    private final String name;
    private final ObjectiveCriteria criteria;
    private Component displayName;
    private Component formattedDisplayName;
    private ObjectiveCriteria.RenderType renderType;
    
    public Objective(final Scoreboard dfm, final String string, final ObjectiveCriteria dfp, final Component mr, final ObjectiveCriteria.RenderType a) {
        this.scoreboard = dfm;
        this.name = string;
        this.criteria = dfp;
        this.displayName = mr;
        this.formattedDisplayName = this.createFormattedDisplayName();
        this.renderType = a;
    }
    
    public Scoreboard getScoreboard() {
        return this.scoreboard;
    }
    
    public String getName() {
        return this.name;
    }
    
    public ObjectiveCriteria getCriteria() {
        return this.criteria;
    }
    
    public Component getDisplayName() {
        return this.displayName;
    }
    
    private Component createFormattedDisplayName() {
        final HoverEvent mv;
        return ComponentUtils.wrapInSquareBrackets(this.displayName.copy().withStyle(nb -> {
            new HoverEvent((HoverEvent.Action<TextComponent>)HoverEvent.Action.SHOW_TEXT, new TextComponent(this.name));
            return nb.withHoverEvent(mv);
        }));
    }
    
    public Component getFormattedDisplayName() {
        return this.formattedDisplayName;
    }
    
    public void setDisplayName(final Component mr) {
        this.displayName = mr;
        this.formattedDisplayName = this.createFormattedDisplayName();
        this.scoreboard.onObjectiveChanged(this);
    }
    
    public ObjectiveCriteria.RenderType getRenderType() {
        return this.renderType;
    }
    
    public void setRenderType(final ObjectiveCriteria.RenderType a) {
        this.renderType = a;
        this.scoreboard.onObjectiveChanged(this);
    }
}
