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 dfj) {
        this.slot = integer;
        if (dfj == null) {
            this.objectiveName = "";
        }
        else {
            this.objectiveName = dfj.getName();
        }
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.slot = mg.readByte();
        this.objectiveName = mg.readUtf(16);
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeByte(this.slot);
        mg.writeUtf(this.objectiveName);
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.handleSetDisplayObjective(this);
    }
    
    public int getSlot() {
        return this.slot;
    }
    
    @Nullable
    public String getObjectiveName() {
        return Objects.equals(this.objectiveName, "") ? null : this.objectiveName;
    }
}
