Skip to content

Commit

Permalink
Merge pull request #72 from Norazan/getting-stuck-fix
Browse files Browse the repository at this point in the history
Fix getting stuck on down section transition
  • Loading branch information
0ffz authored Aug 2, 2021
2 parents 1913cc0 + 277ebd3 commit 3208c2c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.mineinabyss.idofront.plugin.registerEvents
import com.mineinabyss.idofront.plugin.registerService
import com.mineinabyss.idofront.slimjar.LibraryLoaderInjector
import com.okkero.skedule.schedule
import org.bukkit.Material
import org.bukkit.plugin.java.JavaPlugin

val protocolManager: ProtocolManager = ProtocolLibrary.getProtocolManager()
Expand Down Expand Up @@ -75,4 +76,10 @@ class DeeperWorld : JavaPlugin() {
}
}
}

override fun onDisable() {
MovementListener.temporaryBedrock.forEach{
it.type = Material.AIR
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ import com.derongan.minecraft.deeperworld.services.WorldManager
import com.derongan.minecraft.deeperworld.services.canMoveSections
import com.derongan.minecraft.deeperworld.world.section.*
import com.mineinabyss.idofront.events.call
import com.mineinabyss.idofront.location.up
import com.mineinabyss.idofront.messaging.color
import com.okkero.skedule.schedule
import org.bukkit.GameMode
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.attribute.Attribute
import org.bukkit.block.Block
import org.bukkit.entity.LivingEntity
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
Expand All @@ -34,6 +37,8 @@ import org.bukkit.event.vehicle.VehicleMoveEvent
import org.bukkit.util.Vector

object MovementListener : Listener {
val temporaryBedrock = mutableListOf<Block>()

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
fun PlayerMoveEvent.move() {
if (player.hasPermission(Permissions.CHANGE_SECTION_PERMISSION) && player.canMoveSections) {
Expand Down Expand Up @@ -70,7 +75,7 @@ object MovementListener : Listener {
return
}

if(!player.location.inSectionOverlap) return;
if(!player.location.inSectionOverlap) return

val changeY = to.y - from.y
if (changeY == 0.0) return
Expand All @@ -90,7 +95,32 @@ object MovementListener : Listener {
if (!toSection.region.contains(correspondingPos.blockX, correspondingPos.blockZ)
|| !inSpectator && correspondingPos.block.type.isSolid
) {
player.teleport(from)
if(current.isOnTopOf(toSection)){
from.block.type = Material.BEDROCK
val spawnedBedrock = from.block
temporaryBedrock.add(spawnedBedrock)

// Keep bedrock spawned if there are players within a 1.5 radius (regular jump height).
// If no players are in this radius, destroy the bedrock.
deeperWorld.schedule{
this.repeating(1)
while(spawnedBedrock.location.up(1).getNearbyPlayers(1.5).isNotEmpty()){
yield()
}
spawnedBedrock.type = Material.AIR
temporaryBedrock.remove(spawnedBedrock)
}

val oldFallDistance = player.fallDistance
val oldVelocity = player.velocity

player.teleport(from.up(1))

player.fallDistance = oldFallDistance
player.velocity = oldVelocity
}else{
player.teleport(from)
}
player.sendMessage("&cThere is no where for you to teleport".color())
}
else
Expand Down

0 comments on commit 3208c2c

Please sign in to comment.