From a1dc7c6f422c3e680021a0e8ccab45b5ec917ed6 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Fri, 24 Sep 2021 02:13:06 +0200 Subject: [PATCH] Add names to portals --- src/main/kotlin/Portal.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/Portal.kt b/src/main/kotlin/Portal.kt index 8621033..cc8ae04 100644 --- a/src/main/kotlin/Portal.kt +++ b/src/main/kotlin/Portal.kt @@ -72,6 +72,7 @@ class Portal( var pitch: Float, private var flags: Byte, link: UUID?, + var name: String, val accessExclusions: SortedList ) { init { @@ -120,6 +121,16 @@ class Portal( } } + fun unlink() { + link = null + } + + fun link(portal: Portal): Boolean { + if (this == portal) return false + link = portal.id + return true + } + fun toCompressedString(worldMapper: MapFunction, playerMapper: MapFunction): String { val buffer = threadLocalInputBuffer.get() buffer.position = 0 @@ -139,6 +150,9 @@ class Portal( buffer.long = link.mostSignificantBits buffer.long = link.leastSignificantBits } + + buffer.putString(name) + if (accessExclusions.size > 0) { for (player in accessExclusions) buffer.packedUInt = playerMapper(player) @@ -185,9 +199,10 @@ fun readCompressedPortal( }, if (PortalFlag.LINKED.isFlagSet(flags)) UUID(inputBuffer.long, inputBuffer.long) else null, - if (PortalFlag.NO_EXCLUSIONS.isFlagSet(flags)) SortedList(comparator = PLAYER_COMPARATOR) + inputBuffer.getString(), + if (PortalFlag.NO_EXCLUSIONS.isFlagSet(flags)) SortedList(comparator = COMPARATOR_PLAYER) else run { - val collect = SortedList(comparator = PLAYER_COMPARATOR) + val collect = SortedList(comparator = COMPARATOR_PLAYER) while (inputBuffer.position < dataLen) collect += playerMapper(inputBuffer.packedUInt) ?: continue return@run collect