package ru.dbotthepony.kstarbound.network.packets.clientbound

import ru.dbotthepony.kstarbound.client.ClientConnection
import ru.dbotthepony.kstarbound.network.IClientPacket
import java.io.DataInputStream
import java.io.DataOutputStream

class UpdateDungeonProtectionPacket(val id: Int, val isProtected: Boolean) : IClientPacket {
	constructor(stream: DataInputStream, isLegacy: Boolean) : this(stream.readUnsignedShort(), stream.readBoolean())

	override fun write(stream: DataOutputStream, isLegacy: Boolean) {
		stream.writeShort(id)
		stream.writeBoolean(isProtected)
	}

	override fun play(connection: ClientConnection) {
		connection.enqueue {
			world?.switchDungeonIDProtection(this@UpdateDungeonProtectionPacket.id, isProtected)
		}
	}
}
