Skip to content

Commit 772b525

Browse files
committed
Use async teleport
1 parent b8fb73b commit 772b525

File tree

6 files changed

+47
-40
lines changed

6 files changed

+47
-40
lines changed

build.gradle.kts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ repositories {
2121
maven("https://repo.mineinabyss.com/releases")
2222
maven("https://papermc.io/repo/repository/maven-public/") //Paper
2323
maven("https://repo.codemc.org/repository/maven-public/")
24+
// maven("https://mvn.intellectualsites.com/content/repositories/releases/") // FAWE
2425
maven("https://jitpack.io")
2526
}
2627

@@ -29,7 +30,7 @@ val kotlinVersion: String by project
2930

3031
dependencies {
3132
compileOnly("com.destroystokyo.paper:paper-api:$serverVersion")
32-
compileOnly("io.papermc:paperlib:1.0.6")
33+
// compileOnly("com.intellectualsites.fawe:FAWE-Bukkit:1.16-637")
3334
compileOnly(kotlin("stdlib-jdk8"))
3435

3536
kotlinSpice("$kotlinVersion+")
@@ -38,7 +39,7 @@ dependencies {
3839
compileOnly("nl.rutgerkok:blocklocker:1.9.2")
3940
compileOnly("com.comphenix.protocol:ProtocolLib:4.5.0")
4041

41-
implementation("com.mineinabyss:idofront:0.5.8")
42+
implementation("com.mineinabyss:idofront:0.6.13")
4243

4344
testImplementation("junit:junit:4.12")
4445
}
@@ -59,4 +60,4 @@ publishing {
5960
mineInAbyss(project) {
6061
from(components["java"])
6162
}
62-
}
63+
}

src/main/java/com/derongan/minecraft/deeperworld/extensions/DeeperWorldExtensions.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal fun Player.getLeashedEntities(): List<LivingEntity> {
3434
.filter { it.isLeashed && it.leashHolder == this }
3535
}
3636

37-
internal fun Player.teleportWithSpectator(loc: Location) {
37+
internal fun Player.teleportWithSpectatorsAsync(loc: Location, thenRun: (Boolean) -> Unit) {
3838
val nearbySpectators = getNearbyEntities(5.0, 5.0, 5.0)
3939
.filterIsInstance<Player>()
4040
.filter { it.spectatorTarget == this }
@@ -43,10 +43,12 @@ internal fun Player.teleportWithSpectator(loc: Location) {
4343
it.spectatorTarget = null
4444
}
4545

46-
teleport(loc)
47-
48-
nearbySpectators.forEach {
49-
it.teleport(loc)
50-
it.spectatorTarget = this
46+
teleportAsync(loc).thenAccept { success ->
47+
if (!success) return@thenAccept
48+
nearbySpectators.forEach {
49+
it.teleport(loc)
50+
it.spectatorTarget = this
51+
}
52+
thenRun(success)
5153
}
52-
}
54+
}

src/main/java/com/derongan/minecraft/deeperworld/listeners/MovementListener.kt

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import com.derongan.minecraft.deeperworld.event.PlayerDescendEvent
1212
import com.derongan.minecraft.deeperworld.extensions.getLeashedEntities
1313
import com.derongan.minecraft.deeperworld.extensions.getPassengersRecursive
1414
import com.derongan.minecraft.deeperworld.extensions.getRootVehicle
15-
import com.derongan.minecraft.deeperworld.extensions.teleportWithSpectator
15+
import com.derongan.minecraft.deeperworld.extensions.teleportWithSpectatorsAsync
1616
import com.derongan.minecraft.deeperworld.services.WorldManager
1717
import com.derongan.minecraft.deeperworld.services.canMoveSections
1818
import com.derongan.minecraft.deeperworld.world.section.*
1919
import com.mineinabyss.idofront.destructure.component1
2020
import com.mineinabyss.idofront.events.call
2121
import com.mineinabyss.idofront.messaging.color
22+
import com.mineinabyss.idofront.messaging.info
2223
import com.okkero.skedule.schedule
2324
import org.bukkit.GameMode
2425
import org.bukkit.Location
@@ -164,36 +165,37 @@ object MovementListener : Listener {
164165
deeperWorld.schedule {
165166
waitFor(1)
166167

167-
player.teleportWithSpectator(newLoc)
168-
169-
protocolManager.addPacketListener(
170-
SectionTeleportPacketAdapter(
171-
player,
172-
oldLeashedEntities,
173-
oldFallDistance,
174-
oldVelocity,
175-
vehicleTree
168+
player.teleportWithSpectatorsAsync(newLoc) {
169+
protocolManager.addPacketListener(
170+
SectionTeleportPacketAdapter(
171+
player,
172+
oldLeashedEntities,
173+
oldFallDistance,
174+
oldVelocity,
175+
vehicleTree
176+
)
176177
)
177-
)
178+
}
179+
178180
}
179181
} else {
180182
val oldFallDistance = player.fallDistance
181183
val oldVelocity = player.velocity
182184

183-
player.teleportWithSpectator(newLoc)
184-
185-
player.fallDistance = oldFallDistance
186-
player.velocity = oldVelocity
187-
188-
if (oldLeashedEntities.isNotEmpty()) {
189-
protocolManager.addPacketListener(
190-
SectionTeleportPacketAdapter(
191-
player,
192-
oldLeashedEntities,
193-
oldFallDistance,
194-
oldVelocity
185+
player.teleportWithSpectatorsAsync(newLoc) {
186+
player.fallDistance = oldFallDistance
187+
player.velocity = oldVelocity
188+
189+
if (oldLeashedEntities.isNotEmpty()) {
190+
protocolManager.addPacketListener(
191+
SectionTeleportPacketAdapter(
192+
player,
193+
oldLeashedEntities,
194+
oldFallDistance,
195+
oldVelocity
196+
)
195197
)
196-
)
198+
}
197199
}
198200
}
199201
}

src/main/java/com/derongan/minecraft/deeperworld/synchronization/ContainerSyncListener.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.derongan.minecraft.deeperworld.world.section.*
66
import com.mineinabyss.idofront.destructure.component1
77
import com.mineinabyss.idofront.messaging.color
88
import com.mineinabyss.idofront.messaging.info
9-
import io.papermc.lib.PaperLib
109
import nl.rutgerkok.blocklocker.BlockLockerAPIv2
1110
import nl.rutgerkok.blocklocker.SearchMode
1211
import org.bukkit.Chunk
@@ -39,11 +38,12 @@ object ContainerSyncListener : Listener {
3938
val loc = clicked.location
4039
val container = clicked.state
4140
val (player) = event
41+
4242
if (container is Container && event.action == Action.RIGHT_CLICK_BLOCK && !player.isSneaking) {
4343
val section = loc.section ?: return
4444
val linkedSection = loc.correspondingSection ?: return
4545
val linkedBlock = loc.getCorrespondingLocation(section, linkedSection)?.block ?: return
46-
// PaperLib.getBlockState()
46+
4747
if (DeeperContext.isBlockLockerLoaded) {
4848
updateProtection(linkedBlock)
4949
updateProtection(clicked)

src/main/java/com/derongan/minecraft/deeperworld/synchronization/Updaters.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ internal fun Collection<ItemStack?>.dropItems(loc: Location, noVelocity: Boolean
5252
filterNotNull().forEach {
5353
loc.world?.dropItem(spawnLoc, it).apply { if (noVelocity) this?.velocity = Vector(0, 0, 0) }
5454
}
55-
}
55+
}

src/main/java/com/derongan/minecraft/deeperworld/world/section/SectionUtils.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package com.derongan.minecraft.deeperworld.world.section
55

66
import com.derongan.minecraft.deeperworld.MinecraftConstants
77
import com.derongan.minecraft.deeperworld.services.WorldManager
8+
import com.mineinabyss.idofront.operators.minus
9+
import com.mineinabyss.idofront.operators.plus
810
import org.bukkit.Location
911
import kotlin.math.max
1012
import kotlin.math.min
@@ -57,8 +59,8 @@ fun Location.getCorrespondingLocation(sectionA: Section, sectionB: Section): Loc
5759

5860
// fromX + n = toX
5961
// toX - fromX = n
60-
val delta = toSectionLoc.toVector().subtract(fromSectionLoc.toVector())
61-
val newLoc = clone().add(delta)
62+
val delta = toSectionLoc.toVector() - (fromSectionLoc.toVector())
63+
val newLoc = clone() + delta
6264
newLoc.world = sectionB.world
6365
return newLoc
6466
}
@@ -92,4 +94,4 @@ fun Section.overlapWith(other: Section): Int? {
9294
fun Section.isOnTopOf(other: Section) = key == other.aboveKey
9395

9496
/** Whether a section is adjacent to another */
95-
fun Section.isAdjacentTo(other: Section) = this.isOnTopOf(other) || other.isOnTopOf(this)
97+
fun Section.isAdjacentTo(other: Section) = this.isOnTopOf(other) || other.isOnTopOf(this)

0 commit comments

Comments
 (0)