Skip to content

Commit 6450fc2

Browse files
committed
Teleport player to the nearest available cubby when they try to claim one
1 parent 592b892 commit 6450fc2

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/main/kotlin/org/trackedout/citadel/commands/CubbyManagementCommand.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ class CubbyManagementCommand(
5151
player.sendGreenMessage("This cubby is now yours!")
5252
} else {
5353
player.sendRedMessage("You need to be in a cubby to claim it")
54+
55+
// Find nearest available cubby
56+
val allCubbies = player.world.regions()?.filter { it.id.startsWith(CUBBY_PREFIX) }
57+
val availableCubbies = allCubbies?.filter { it.members.players.isEmpty() }
58+
59+
if (!availableCubbies.isNullOrEmpty()) {
60+
availableCubbies.minBy { it.getCenterLocation(player.world).distance(player.location) }.let {
61+
player.sendGreenMessage("Nearest available cubby is located at ${it.minimumPoint}, ${it.maximumPoint}. Teleporting you to it now")
62+
player.teleport(it.getCenterLocation(player.world))
63+
}
64+
} else {
65+
player.sendRedMessage("No available cubbies found! Please contact a moderator to create more cubbies")
66+
}
5467
}
5568
}
5669
}

0 commit comments

Comments
 (0)