package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.util.Objects;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import javax.annotation.Nullable;
import net.minecraft.world.scores.Objective;
import net.minecraft.network.protocol.Packet;

public class ClientboundSetDisplayObjectivePacket implements Packet<ClientGamePacketListener> {
    private int slot;
    private String objectiveName;
    
    public ClientboundSetDisplayObjectivePacket() {
    }
    
    public ClientboundSetDisplayObjectivePacket(final int integer, @Nullable final Objective cwi) {
        this.slot = integer;
        if (cwi == null) {
            this.objectiveName = "";
        }
        else {
            this.objectiveName = cwi.getName();
        }
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.slot = kv.readByte();
        this.objectiveName = kv.readUtf(16);
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeByte(this.slot);
        kv.writeUtf(this.objectiveName);
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleSetDisplayObjective(this);
    }
    
    public int getSlot() {
        return this.slot;
    }
    
    @Nullable
    public String getObjectiveName() {
        return Objects.equals(this.objectiveName, "") ? null : this.objectiveName;
    }
}
