mirror of
				https://github.com/GayPizzaSpecifications/foundation.git
				synced 2025-11-04 03:39:37 +00:00 
			
		
		
		
	Repair extension loading by placing them in common-plugin rather than foundation-shared.
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,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): Boolean =
 | 
			
		||||
  onlinePlayers.any { onlinePlayer -> onlinePlayer.name == player.name }
 | 
			
		||||
 | 
			
		||||
fun Server.allPlayerStatisticsOf(
 | 
			
		||||
  statistic: Statistic,
 | 
			
		||||
  material: Material? = null,
 | 
			
		||||
  entityType: EntityType? = null,
 | 
			
		||||
  order: SortOrder = SortOrder.Ascending
 | 
			
		||||
): List<Pair<OfflinePlayer, Int>> = 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
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,12 @@
 | 
			
		||||
package gay.pizza.foundation.common
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Location
 | 
			
		||||
import org.bukkit.World
 | 
			
		||||
import org.bukkit.entity.Entity
 | 
			
		||||
import org.bukkit.entity.Player
 | 
			
		||||
import kotlin.reflect.KClass
 | 
			
		||||
 | 
			
		||||
fun <T: Entity> World.spawn(location: Location, clazz: KClass<T>): T = spawn(location, clazz.java)
 | 
			
		||||
 | 
			
		||||
fun <T: Entity> Player.spawn(clazz: KClass<T>): T = spawn(clazz.java)
 | 
			
		||||
fun <T: Entity> Player.spawn(clazz: Class<T>): T = world.spawn(location, clazz)
 | 
			
		||||
		Reference in New Issue
	
	Block a user