package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.scores.Objective;
import net.minecraft.world.scores.criteria.ObjectiveCriteria;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;

public class ClientboundSetObjectivePacket implements Packet<ClientGamePacketListener> {
    private String objectiveName;
    private Component displayName;
    private ObjectiveCriteria.RenderType renderType;
    private int method;
    
    public ClientboundSetObjectivePacket() {
    }
    
    public ClientboundSetObjectivePacket(final Objective dfj, final int integer) {
        this.objectiveName = dfj.getName();
        this.displayName = dfj.getDisplayName();
        this.renderType = dfj.getRenderType();
        this.method = integer;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.objectiveName = mg.readUtf(16);
        this.method = mg.readByte();
        if (this.method == 0 || this.method == 2) {
            this.displayName = mg.readComponent();
            this.renderType = mg.<ObjectiveCriteria.RenderType>readEnum(ObjectiveCriteria.RenderType.class);
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeUtf(this.objectiveName);
        mg.writeByte(this.method);
        if (this.method == 0 || this.method == 2) {
            mg.writeComponent(this.displayName);
            mg.writeEnum(this.renderType);
        }
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.handleAddObjective(this);
    }
    
    public String getObjectiveName() {
        return this.objectiveName;
    }
    
    public Component getDisplayName() {
        return this.displayName;
    }
    
    public int getMethod() {
        return this.method;
    }
    
    public ObjectiveCriteria.RenderType getRenderType() {
        return this.renderType;
    }
}
