From c32706860750fe3f7d2d3b3cdaec97a596005ac3 Mon Sep 17 00:00:00 2001 From: Boy Date: Fri, 26 Jan 2024 15:59:19 +0100 Subject: [PATCH] feat: prevent dismounting & entering vehicles when it puts you outside of the map --- .../deeperworld/listeners/PlayerListener.kt | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/mineinabyss/deeperworld/listeners/PlayerListener.kt b/src/main/kotlin/com/mineinabyss/deeperworld/listeners/PlayerListener.kt index 4353391..48619cb 100644 --- a/src/main/kotlin/com/mineinabyss/deeperworld/listeners/PlayerListener.kt +++ b/src/main/kotlin/com/mineinabyss/deeperworld/listeners/PlayerListener.kt @@ -1,21 +1,18 @@ package com.mineinabyss.deeperworld.listeners import com.mineinabyss.deeperworld.services.canMoveSections -import com.mineinabyss.deeperworld.world.section.correspondingSection -import com.mineinabyss.deeperworld.world.section.inSectionOverlap import com.mineinabyss.deeperworld.world.section.inSectionTransition import com.mineinabyss.deeperworld.world.section.section import com.mineinabyss.idofront.location.up -import com.mineinabyss.idofront.messaging.broadcastVal import com.mineinabyss.idofront.messaging.error import org.bukkit.GameMode.CREATIVE import org.bukkit.event.EventHandler import org.bukkit.event.Listener -import org.bukkit.event.entity.EntityDismountEvent import org.bukkit.event.player.PlayerTeleportEvent import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.ENDER_PEARL -import org.bukkit.event.vehicle.VehicleCreateEvent +import org.bukkit.event.vehicle.VehicleEnterEvent +import org.bukkit.event.vehicle.VehicleExitEvent object PlayerListener : Listener { @EventHandler @@ -34,12 +31,16 @@ object PlayerListener : Listener { } @EventHandler - fun EntityDismountEvent.onCreateVehicle() { - if (entity.location.up(1).section != null) return - entity.error("The Abyss prevents you from dismounting here...") + fun VehicleEnterEvent.onEnterVehicle() { + if (vehicle.location.up(1).section != null) return + entered.error("The Abyss prevents you from mounting here...") isCancelled = true } -} -//TODO move into idofront -private operator fun PlayerTeleportEvent.component4() = cause + @EventHandler + fun VehicleExitEvent.onExitVehicle() { + if (vehicle.location.up(1).section != null) return + exited.error("The Abyss prevents you from dismounting here...") + isCancelled = true + } +}