mirror of
https://github.com/GayPizzaSpecifications/foundation.git
synced 2025-08-03 13:31:32 +00:00
Move some code to common-plugin.
This commit is contained in:
@ -0,0 +1,7 @@
|
||||
package gay.pizza.foundation.common
|
||||
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
fun Player.chat(vararg messages: String): Unit = messages.forEach { message ->
|
||||
chat(message)
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package gay.pizza.foundation.common
|
||||
|
||||
fun <T, R : Comparable<R>> Collection<T>.sortedBy(order: SortOrder, selector: (T) -> R?): List<T> =
|
||||
if (order == SortOrder.Ascending) {
|
||||
sortedBy(selector)
|
||||
} else {
|
||||
sortedByDescending(selector)
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package gay.pizza.foundation.common
|
||||
|
||||
object Platform {
|
||||
private val os: String? = System.getProperty("os.name")
|
||||
|
||||
fun isWindows(): Boolean = os != null && os.lowercase().startsWith("windows")
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package gay.pizza.foundation.common
|
||||
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.OfflinePlayer
|
||||
import org.bukkit.Server
|
||||
import org.bukkit.Statistic
|
||||
import org.bukkit.entity.EntityType
|
||||
|
||||
val Server.allPlayers: List<OfflinePlayer>
|
||||
get() = listOf(onlinePlayers, offlinePlayers.filter { !isPlayerOnline(it) }.toList()).flatten()
|
||||
|
||||
fun Server.isPlayerOnline(player: OfflinePlayer) =
|
||||
onlinePlayers.any { onlinePlayer -> onlinePlayer.name == player.name }
|
||||
|
||||
fun Server.allPlayerStatisticsOf(
|
||||
statistic: Statistic,
|
||||
material: Material? = null,
|
||||
entityType: EntityType? = null,
|
||||
order: SortOrder = SortOrder.Ascending
|
||||
) = allPlayers.map { player ->
|
||||
player to if (material != null) {
|
||||
player.getStatistic(statistic, material)
|
||||
} else if (entityType != null) {
|
||||
player.getStatistic(statistic, entityType)
|
||||
} else {
|
||||
player.getStatistic(statistic)
|
||||
}
|
||||
}.sortedBy(order) { it.second }
|
@ -0,0 +1,6 @@
|
||||
package gay.pizza.foundation.common
|
||||
|
||||
enum class SortOrder {
|
||||
Ascending,
|
||||
Descending
|
||||
}
|
Reference in New Issue
Block a user