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 cwi, final int integer) {
        this.objectiveName = cwi.getName();
        this.displayName = cwi.getDisplayName();
        this.renderType = cwi.getRenderType();
        this.method = integer;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.objectiveName = kv.readUtf(16);
        this.method = kv.readByte();
        if (this.method == 0 || this.method == 2) {
            this.displayName = kv.readComponent();
            this.renderType = kv.<ObjectiveCriteria.RenderType>readEnum(ObjectiveCriteria.RenderType.class);
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeUtf(this.objectiveName);
        kv.writeByte(this.method);
        if (this.method == 0 || this.method == 2) {
            kv.writeComponent(this.displayName);
            kv.writeEnum(this.renderType);
        }
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.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;
    }
}
