All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jglrxavpok.hephaistos.nbt.NBTString.kt Maven / Gradle / Ivy

There is a newer version: 2.6.1
Show newest version
package org.jglrxavpok.hephaistos.nbt

import java.io.DataInputStream
import java.io.DataOutputStream
import java.util.*

class NBTString constructor(val value: String): NBT {

    override val ID = NBTType.TAG_String

    override fun writeContents(destination: DataOutputStream) {
        destination.writeUTF(value)
    }

    override fun toSNBT(): String {
        val escaped = value.replace("\"", "\\\"")
        return "\"$escaped\""
    }

    override fun toString() = toSNBT()

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as NBTString

        if (value != other.value) return false

        return true
    }

    override fun hashCode(): Int {
        return Objects.hash(value)
    }

    companion object: NBTReaderCompanion {
        override fun readContents(source: DataInputStream): NBTString {
            return NBTString(source.readUTF())
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy