package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import java.util.Objects;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.server.ServerScoreboard;
import javax.annotation.Nullable;
import net.minecraft.network.protocol.Packet;

public class ClientboundSetScorePacket implements Packet<ClientGamePacketListener> {
    private String owner;
    @Nullable
    private String objectiveName;
    private int score;
    private ServerScoreboard.Method method;
    
    public ClientboundSetScorePacket() {
        this.owner = "";
    }
    
    public ClientboundSetScorePacket(final ServerScoreboard.Method a, @Nullable final String string2, final String string3, final int integer) {
        this.owner = "";
        if (a != ServerScoreboard.Method.REMOVE && string2 == null) {
            throw new IllegalArgumentException("Need an objective name");
        }
        this.owner = string3;
        this.objectiveName = string2;
        this.score = integer;
        this.method = a;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.owner = mg.readUtf(40);
        this.method = mg.<ServerScoreboard.Method>readEnum(ServerScoreboard.Method.class);
        final String string3 = mg.readUtf(16);
        this.objectiveName = (Objects.equals(string3, "") ? null : string3);
        if (this.method != ServerScoreboard.Method.REMOVE) {
            this.score = mg.readVarInt();
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeUtf(this.owner);
        mg.writeEnum(this.method);
        mg.writeUtf((this.objectiveName == null) ? "" : this.objectiveName);
        if (this.method != ServerScoreboard.Method.REMOVE) {
            mg.writeVarInt(this.score);
        }
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.handleSetScore(this);
    }
    
    public String getOwner() {
        return this.owner;
    }
    
    @Nullable
    public String getObjectiveName() {
        return this.objectiveName;
    }
    
    public int getScore() {
        return this.score;
    }
    
    public ServerScoreboard.Method getMethod() {
        return this.method;
    }
}
