Skip to content

Commit

Permalink
Merge branch 'main' into paper-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Jul 17, 2023
2 parents 3e6d5ee + 1b01de8 commit 82aa7f8
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 24 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version = 0.14.3
version = 0.14.4
kotlin.daemon.jvmargs=-Xmx2g
org.gradle.jvmargs=-Xmx2g
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package xyz.xenondevs.nova.data.serialization.cbf

import net.minecraft.nbt.ByteArrayTag
import net.minecraft.nbt.ByteTag
import net.minecraft.nbt.NbtAccounter
import net.minecraft.nbt.StreamTagVisitor
import net.minecraft.nbt.StringTag
Expand All @@ -10,8 +12,14 @@ import xyz.xenondevs.cbf.CBF
import xyz.xenondevs.cbf.io.ByteReader
import java.io.DataInput
import java.io.DataOutput
import java.util.*
import java.util.function.Consumer
import java.util.function.IntFunction
import java.util.function.Predicate
import java.util.function.UnaryOperator
import java.util.stream.Stream

internal object CBFCompoundTagType : TagType.VariableSize<CBFCompoundTag> {
internal object CBFCompoundTagType : TagType.VariableSize<ByteArrayTag> {

override fun load(input: DataInput, i: Int, tracker: NbtAccounter): CBFCompoundTag {
val reader = ByteReader.fromDataInput(input)
Expand Down Expand Up @@ -41,48 +49,177 @@ internal object CBFCompoundTagType : TagType.VariableSize<CBFCompoundTag> {

}

internal class CBFCompoundTag(val compound: NamespacedCompound) : Tag {
@Suppress("OVERRIDE_DEPRECATION")
internal class CBFCompoundTag(val compound: NamespacedCompound) : ByteArrayTag(byteArrayOf()) {

constructor() : this(NamespacedCompound())

override fun getId(): Byte = 7 // byte array
override fun getType(): TagType<CBFCompoundTag> = CBFCompoundTagType

override fun copy(): Tag {
return CBFCompoundTag(compound.copy())
}
override fun getType(): TagType<ByteArrayTag> = CBFCompoundTagType
override fun copy(): Tag = CBFCompoundTag(compound.copy())
override fun getAsByteArray(): ByteArray = CBF.write(compound)
override fun accept(visitor: StreamTagVisitor): StreamTagVisitor.ValueResult = visitor.visit(compound.toString())
override fun accept(visitor: TagVisitor) = visitor.visitString(StringTag.valueOf(compound.toString())) // TODO
override fun acceptAsRoot(visitor: StreamTagVisitor) = throw UnsupportedOperationException() // TODO

override fun write(out: DataOutput) {
val bytes = CBF.write(compound)
out.writeInt(bytes.size)
out.write(bytes)
}

// also accessed via reflection
fun compoundToByteArray(): ByteArray {
return CBF.write(compound)
override fun equals(other: Any?): Boolean {
if (other === this)
return true

return other is CBFCompoundTag && asByteArray.contentEquals(other.asByteArray)
}

override fun accept(visitor: StreamTagVisitor): StreamTagVisitor.ValueResult {
return visitor.visit(compound.toString())
override fun hashCode(): Int = asByteArray.contentHashCode()

//<editor-fold desc="unsupported methods", defaultstate="collapsed">
override val size: Int
get() = throw UnsupportedOperationException()

override fun sizeInBytes(): Int {
throw UnsupportedOperationException()
}

override fun accept(visitor: TagVisitor) {
visitor.visitString(StringTag.valueOf(compound.toString())) // TODO
override fun get(index: Int): ByteTag {
throw UnsupportedOperationException()
}

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

return other is CBFCompoundTag && compoundToByteArray().contentEquals(other.compoundToByteArray())
override fun set(index: Int, element: ByteTag): ByteTag {
throw UnsupportedOperationException()
}

override fun hashCode(): Int =
compoundToByteArray().contentHashCode()
override fun add(index: Int, element: ByteTag) {
throw UnsupportedOperationException()
}

override fun sizeInBytes(): Int {
override fun add(element: ByteTag?): Boolean {
throw UnsupportedOperationException()
}

override fun setTag(index: Int, element: Tag): Boolean {
throw UnsupportedOperationException()
}

override fun addTag(index: Int, element: Tag): Boolean {
throw UnsupportedOperationException()
}

override fun remove(element: ByteTag?): Boolean {
throw UnsupportedOperationException()
}

override fun addAll(index: Int, elements: Collection<ByteTag>): Boolean {
throw UnsupportedOperationException()
}

override fun addAll(elements: Collection<ByteTag>): Boolean {
throw UnsupportedOperationException()
}

override fun clear() {
throw UnsupportedOperationException()
}

override fun iterator(): MutableIterator<ByteTag> {
throw UnsupportedOperationException()
}

override fun removeAll(elements: Collection<ByteTag>): Boolean {
throw UnsupportedOperationException()
}

override fun retainAll(elements: Collection<ByteTag>): Boolean {
throw UnsupportedOperationException()
}

override fun contains(element: ByteTag?): Boolean {
throw UnsupportedOperationException()
}

override fun containsAll(elements: Collection<ByteTag>): Boolean {
throw UnsupportedOperationException()
}

override fun isEmpty(): Boolean {
throw UnsupportedOperationException()
}

override fun forEach(action: Consumer<in ByteTag>?) {
throw UnsupportedOperationException()
}

override fun spliterator(): Spliterator<ByteTag> {
throw UnsupportedOperationException()
}

override fun toArray(): Array<Any> {
throw UnsupportedOperationException()
}

override fun <T : Any?> toArray(a: Array<out T>): Array<T> {
throw UnsupportedOperationException()
}

override fun <T : Any?> toArray(generator: IntFunction<Array<T>>?): Array<T> {
throw UnsupportedOperationException()
}

override fun removeIf(filter: Predicate<in ByteTag>): Boolean {
throw UnsupportedOperationException()
}

override fun stream(): Stream<ByteTag> {
throw UnsupportedOperationException()
}

override fun parallelStream(): Stream<ByteTag> {
throw UnsupportedOperationException()
}

override fun listIterator(): MutableListIterator<ByteTag> {
throw UnsupportedOperationException()
}

override fun listIterator(index: Int): MutableListIterator<ByteTag> {
throw UnsupportedOperationException()
}

override fun removeAt(i: Int): ByteTag {
throw UnsupportedOperationException()
}

override fun subList(fromIndex: Int, toIndex: Int): MutableList<ByteTag> {
throw UnsupportedOperationException()
}

override fun indexOf(element: ByteTag?): Int {
throw UnsupportedOperationException()
}

override fun lastIndexOf(element: ByteTag?): Int {
throw UnsupportedOperationException()
}

override fun replaceAll(operator: UnaryOperator<ByteTag>) {
throw UnsupportedOperationException()
}

override fun sort(c: Comparator<in ByteTag>?) {
throw UnsupportedOperationException()
}

override fun removeRange(fromIndex: Int, toIndex: Int) {
throw UnsupportedOperationException()
}

override fun getElementType(): Byte {
throw UnsupportedOperationException()
}
//</editor-fold>

}
18 changes: 18 additions & 0 deletions nova/src/main/kotlin/xyz/xenondevs/nova/util/FakeOnlinePlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ import org.jetbrains.annotations.Contract
import xyz.xenondevs.nova.integration.permission.PermissionManager
import java.net.InetAddress
import java.net.InetSocketAddress
import java.time.Duration
import java.time.Instant
import java.util.*

/**
Expand Down Expand Up @@ -182,6 +184,14 @@ class FakeOnlinePlayer(
throw UnsupportedOperationException("Player is not online")
}

override fun ban(reason: String?, expires: Instant?, source: String?, kickPlayer: Boolean): BanEntry<PlayerProfile>? {
throw UnsupportedOperationException("Player is not online")
}

override fun ban(reason: String?, expires: Duration?, source: String?, kickPlayer: Boolean): BanEntry<PlayerProfile>? {
throw UnsupportedOperationException("Player is not online")
}

override fun getName(): String {
return offlinePlayer.name ?: "OfflinePlayer"
}
Expand Down Expand Up @@ -298,6 +308,14 @@ class FakeOnlinePlayer(
throw UnsupportedOperationException("Player is not online")
}

override fun banIp(reason: String?, expires: Instant?, source: String?, kickPlayer: Boolean): BanEntry<InetAddress>? {
throw UnsupportedOperationException("Player is not online")
}

override fun banIp(reason: String?, expires: Duration?, source: String?, kickPlayer: Boolean): BanEntry<InetAddress>? {
throw UnsupportedOperationException("Player is not online")
}

override fun chat(msg: String) {
throw UnsupportedOperationException("Player is not online")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object NBTUtils {
}

internal fun reserializeCBFCompoundTag(cbfTag: Any): CBFCompoundTag {
val toByteArrayMethod = cbfTag::class.java.getMethod("compoundToByteArray")
val toByteArrayMethod = cbfTag::class.java.getMethod("getAsByteArray")
val serializedCBFCompound = toByteArrayMethod.invoke(cbfTag) as ByteArray
return CBFCompoundTag(CBF.read<NamespacedCompound>(serializedCBFCompound)!!)
}
Expand Down

0 comments on commit 82aa7f8

Please sign in to comment.