diff --git a/src/main/java/com/derongan/minecraft/deeperworld/DeeperWorld.kt b/src/main/java/com/derongan/minecraft/deeperworld/DeeperWorld.kt index 6ca32cc..7522247 100644 --- a/src/main/java/com/derongan/minecraft/deeperworld/DeeperWorld.kt +++ b/src/main/java/com/derongan/minecraft/deeperworld/DeeperWorld.kt @@ -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() @@ -75,4 +76,10 @@ class DeeperWorld : JavaPlugin() { } } } + + override fun onDisable() { + MovementListener.temporaryBedrock.forEach{ + it.type = Material.AIR + } + } } diff --git a/src/main/java/com/derongan/minecraft/deeperworld/listeners/MovementListener.kt b/src/main/java/com/derongan/minecraft/deeperworld/listeners/MovementListener.kt index 38c4ca0..964a7a2 100644 --- a/src/main/java/com/derongan/minecraft/deeperworld/listeners/MovementListener.kt +++ b/src/main/java/com/derongan/minecraft/deeperworld/listeners/MovementListener.kt @@ -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 @@ -34,6 +37,8 @@ import org.bukkit.event.vehicle.VehicleMoveEvent import org.bukkit.util.Vector object MovementListener : Listener { + val temporaryBedrock = mutableListOf() + @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW) fun PlayerMoveEvent.move() { if (player.hasPermission(Permissions.CHANGE_SECTION_PERMISSION) && player.canMoveSections) { @@ -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 @@ -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