diff --git a/src/main/kotlin/me/iru/process/JoinProcess.kt b/src/main/kotlin/me/iru/process/JoinProcess.kt index 9ea2670..bcbc498 100644 --- a/src/main/kotlin/me/iru/process/JoinProcess.kt +++ b/src/main/kotlin/me/iru/process/JoinProcess.kt @@ -3,9 +3,10 @@ package me.iru.process import me.iru.Authy import me.iru.PrefixType import me.iru.data.migration.Migration -import me.iru.utils.TeleportUtil import me.iru.utils.hasValidName import org.bukkit.Location +import org.bukkit.Material +import org.bukkit.block.BlockFace import org.bukkit.entity.Player import org.bukkit.potion.PotionEffect import org.bukkit.potion.PotionEffectType @@ -28,7 +29,7 @@ class JoinProcess(private val player: Player) { if(session.tryAutoLogin(player)) return joinTeleports() - TeleportUtil.teleportToValidPlace(player) + teleportToValidPlace() // Place premium check here @@ -57,6 +58,25 @@ class JoinProcess(private val player: Player) { } } + private fun teleportToValidPlace() { + val invalidBlocks = mutableListOf(Material.NETHER_PORTAL) + val loc = player.location + if(!invalidBlocks.contains(loc.block.type)) return + + var b = loc.block + for(x in 2 downTo -2 step 1) { + for(z in 2 downTo -2 step 1) { + if(invalidBlocks.contains(b.type) && !(b.type.isSolid && b.getRelative(BlockFace.UP).type.isSolid)) { + b = b.getRelative(x, 0, z) + } else { + player.teleport(b.location) + return + } + } + } + return + } + private fun check() { lateinit var messageTask : BukkitTask messageTask = authy.server.scheduler.runTaskTimer(authy, Runnable { diff --git a/src/main/kotlin/me/iru/utils/TeleportUtil.kt b/src/main/kotlin/me/iru/utils/TeleportUtil.kt deleted file mode 100644 index e02a8c9..0000000 --- a/src/main/kotlin/me/iru/utils/TeleportUtil.kt +++ /dev/null @@ -1,64 +0,0 @@ -package me.iru.utils - -import me.iru.Authy -import org.bukkit.Material -import org.bukkit.block.BlockFace -import org.bukkit.entity.Player -import org.bukkit.scheduler.BukkitTask - -object TeleportUtil { - - private val invalidBlocks = mutableListOf(Material.NETHER_PORTAL) - - fun teleportToValidPlace(player: Player) { - teleportOutInvalidBlocks(player) - teleportToGround(player) - } - - private fun teleportOutInvalidBlocks(player: Player) { - val loc = player.location - if(!invalidBlocks.contains(loc.block.type)) return - - var b = loc.block - for(x in 2 downTo -2 step 1) { - for(z in 2 downTo -2 step 1) { - if(invalidBlocks.contains(b.type) && !(b.type.isSolid && b.getRelative(BlockFace.UP).type.isSolid)) { - b = b.getRelative(x, 0, z) - } else { - player.teleport(b.location) - return - } - } - } - return - } - - private fun teleportToGround(player: Player) { - val authy = Authy.instance - - var loc = player.location - if(loc.block.getRelative(BlockFace.DOWN).type.isSolid) return - - val mh = loc.world?.minHeight ?: 0 - - lateinit var task : BukkitTask - task = authy.server.scheduler.runTaskTimer(authy, Runnable { - if(!Authy.loginProcess.contains(player)) { - task.cancel() - } - - if(loc.y < mh) { - task.cancel() - player.teleport(loc) - } - - val under = loc.block.getRelative(BlockFace.DOWN) - if(!under.type.isSolid) { - loc = under.location - } else { - task.cancel() - player.teleport(loc) - } - }, 0L, 0L) - } -} \ No newline at end of file