Skip to content

Commit 913dae5

Browse files
committed
chore: code cleanup
1 parent e18fa05 commit 913dae5

6 files changed

Lines changed: 14 additions & 23 deletions

File tree

src/main/kotlin/com/mineinabyss/deeperworld/extensions/DeeperWorldExtensions.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ package com.mineinabyss.deeperworld.extensions
22

33
import org.bukkit.entity.Entity
44

5-
internal fun Entity.getRootVehicle(): Entity? {
5+
internal fun Entity.rootVehicle(): Entity? {
66
var currentVehicle = vehicle ?: return null
7-
while (currentVehicle.isInsideVehicle) {
8-
currentVehicle = currentVehicle.vehicle!!
9-
}
7+
while (currentVehicle.isInsideVehicle) currentVehicle = currentVehicle.vehicle!!
108

119
return currentVehicle
1210
}
1311

14-
internal fun Entity.getPassengersRecursive(): List<Entity> {
15-
return passengers.plus(passengers.flatMap { it.getPassengersRecursive() })
12+
internal fun Entity.passengersRecursive(): List<Entity> {
13+
return passengers.plus(passengers.flatMap { it.passengersRecursive() })
1614
}

src/main/kotlin/com/mineinabyss/deeperworld/listeners/MovementListener.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mineinabyss.deeperworld.listeners
22

33
import com.mineinabyss.deeperworld.Permissions
4-
import com.mineinabyss.deeperworld.extensions.getPassengersRecursive
4+
import com.mineinabyss.deeperworld.extensions.passengersRecursive
55
import com.mineinabyss.deeperworld.movement.MovementHandler
66
import com.mineinabyss.deeperworld.services.canMoveSections
77
import io.papermc.paper.event.entity.EntityMoveEvent
@@ -24,15 +24,14 @@ object MovementListener : Listener {
2424

2525
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOW)
2626
fun VehicleMoveEvent.move() {
27-
val players = vehicle.getPassengersRecursive().filterIsInstance<Player>()
27+
val players = vehicle.passengersRecursive().filterIsInstance<Player>()
2828

2929
val teleportEntity = players.firstOrNull { it.hasPermission(Permissions.ADMIN_PERMISSION) && it.canMoveSections } ?: vehicle
3030
MovementHandler.handleMovement(teleportEntity, from, to)
3131
}
3232

3333
@EventHandler
3434
fun EntityMoveEvent.entityMove() {
35-
if (!hasExplicitlyChangedPosition()) return
36-
MovementHandler.handleMovement(entity, from, to)
35+
if (hasExplicitlyChangedPosition()) MovementHandler.handleMovement(entity, from, to)
3736
}
3837
}

src/main/kotlin/com/mineinabyss/deeperworld/movement/transition/ConfigSectionChecker.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@ object ConfigSectionChecker : SectionChecker {
2424
fromSection != toSection -> to
2525
else -> null
2626
} ?: return null
27+
val kind = if (to.y < from.y) TransitionKind.DESCEND else TransitionKind.ASCEND
2728

2829
return corrLoc.section?.let {
29-
SectionTransition(
30-
from,
31-
corrLoc,
32-
fromSection,
33-
it,
34-
if (to.y < from.y) TransitionKind.DESCEND else TransitionKind.ASCEND,
35-
teleportUnnecessary = fromSection != toSection
36-
)
30+
SectionTransition(from, corrLoc, fromSection, it, kind, fromSection != toSection)
3731
}
3832
}
3933
}

src/main/kotlin/com/mineinabyss/deeperworld/player/FallingDamageManager.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package com.mineinabyss.deeperworld.player
22

33
import com.mineinabyss.deeperworld.deeperWorld
4-
import com.mineinabyss.deeperworld.extensions.getRootVehicle
4+
import com.mineinabyss.deeperworld.extensions.rootVehicle
55
import org.bukkit.GameMode.ADVENTURE
66
import org.bukkit.GameMode.SURVIVAL
77
import org.bukkit.Particle
88
import org.bukkit.entity.Player
99

1010
internal object FallingDamageManager {
1111
fun updateFallingDamage(player: Player) {
12-
val actualFallDistance = player.getRootVehicle()?.fallDistance ?: player.fallDistance
12+
val actualFallDistance = player.rootVehicle()?.fallDistance ?: player.fallDistance
1313

1414
if (actualFallDistance > deeperWorld.config.fall.maxSafeDist
1515
&& !player.isGliding

src/main/kotlin/com/mineinabyss/deeperworld/synchronization/ContainerSyncListener.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ object ContainerSyncListener : Listener {
4242
updateProtection(block)
4343

4444
//allow chest protection signs to be placed
45-
if (player.inventory.itemInMainHand.type.name.contains("SIGN")
45+
if ("SIGN" in player.inventory.itemInMainHand.type.name
4646
|| !BlockLockerAPIv2.isAllowed(player, block, true)
4747
|| !BlockLockerAPIv2.isAllowed(player, linkedBlock, true)
4848
) return
4949
}
5050

5151
if (container is Lidded) {
52-
(linkedBlock.state as Lidded).open()
52+
(linkedBlock.state as? Lidded)?.open()
5353
if (!section.isOnTopOf(linkedSection)) container.open()
5454
}
5555

src/main/kotlin/com/mineinabyss/deeperworld/synchronization/Updaters.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal inline fun Location.sync(updater: (original: Block, corresponding: Bloc
3838
internal fun signUpdater(lines: MutableList<Component>? = null) = { original: Block, corresponding: Block ->
3939
copyBlockData(original, corresponding)
4040
val sign = original.state
41-
if (sign is Sign) for (side in Side.values()) {
41+
if (sign is Sign) for (side in Side.entries) {
4242
val readLines = lines ?: sign.getSide(side).lines()
4343
val corrSign = corresponding.state
4444
if (corrSign is Sign && !corrSign.getSide(side).lines().containsAll(readLines)) {

0 commit comments

Comments
 (0)