Skip to content

Commit

Permalink
Update to Kotlin 1.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Jul 15, 2023
1 parent 25182eb commit 080ec5c
Show file tree
Hide file tree
Showing 37 changed files with 71 additions and 62 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ format.version = "1.1"
[versions]
cbf = "0.7"
invui = "1.12"
kotlin = "1.8.22"
kotlin = "1.9.0"
ktor = "2.3.1"
spigot = "1.20.1-R0.1-SNAPSHOT"
xenondevs-commons = "1.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ internal class NovaShapedRecipe private constructor(
}

private fun matchesAt(container: CraftingContainer, x: Int, y: Int, horizontalFlip: Boolean): Boolean {
for (absX in 0 until container.width)
for (absY in 0 until container.height) {
for (absX in 0..<container.width)
for (absY in 0..<container.height) {
// relX and relY is the position relative to the recipe shape
val relX = absX - x
val relY = absY - y
val item = container.getItem(absX + absY * container.width)
// If relX and relY are in the shape, it will be the RecipeChoice at that position, or null otherwise
val choice = if (relX in (0 until width) && relY in (0 until height)) {
val choice = if (relX in (0..<width) && relY in (0..<height)) {
getChoice(if (horizontalFlip) width - relX - 1 else relX, relY)
} else null
// If choice is null, treat it as an air RecipeChoice.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ object RecipeManager : Listener {
val inventory = player.inventory
if (inventory.containsAll(recipe.requiredChoices)) {
// fill inventory
for (x in 0 until recipe.width) {
for (y in 0 until recipe.height) {
for (x in 0..<recipe.width) {
for (y in 0..<recipe.height) {
val choice = recipe.getChoice(x, y) ?: continue

val item = inventory.takeFirstOccurrence(choice)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal class BitmapFontGenerator(
.forEach { (i, entry) ->
codePoints[i] = entry.intKey
val glyphRaster = entry.value
for (y in 0 until GLYPH_HEIGHT) {
for (y in 0..<GLYPH_HEIGHT) {
System.arraycopy(glyphRaster, y * width, raster, y * rasterWidth + i * width, width)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal class FancyPantsArmorFileMerger(basePacks: BasePacks) : FileMerger(base
var currentArmor: ArmorData? = null

// loop over all armor sections
for (armorSection in 0 until armorSections) {
for (armorSection in 0..<armorSections) {
val sectionImage = image.getSubimage(armorSection * textureWidth, 0, textureWidth, height)

if (currentArmor == null) { // new armor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ internal class ModelFileMerger(basePacks: BasePacks) : FileInDirectoryMerger(bas

private fun processOverrides(file: Path, array: JsonArray): JsonArray {
val matName = file.nameWithoutExtension.uppercase()
val material = Material.values().firstOrNull { it.name == matName } ?: return array
val material = Material.entries.firstOrNull { it.name == matName } ?: return array

val overrides = TreeMap<Int, String>()
val occupiedModelData = basePacks.occupiedModelData.getOrPut(material, ::HashSet)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface BitmapGlyphImageType<T> {
// TODO: consider moving these to ImageUtils as well?
override fun findRightBorder(image: IntArray, width: Int, height: Int): Int? {
fun isColumnEmpty(x: Int): Boolean {
for (y in 0 until height) {
for (y in 0..<height) {
if (image[y * width + x] ushr 24 != 0)
return false
}
Expand All @@ -48,7 +48,7 @@ interface BitmapGlyphImageType<T> {

override fun findHorizontalBorders(image: IntArray, width: Int, height: Int): Pair<Int, Int>? {
fun isRowEmpty(y: Int): Boolean {
for (x in 0 until width) {
for (x in 0..<width) {
if (image[y * width + x] ushr 24 != 0)
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ abstract class BitmapProvider<T> internal constructor() : FontProvider() {
val height = height
val ascent = ascent

for (x in 0 until codePointGrid.width) {
for (y in 0 until codePointGrid.height) {
for (x in 0..<codePointGrid.width) {
for (y in 0..<codePointGrid.height) {
val codePoint = codePointGrid[x, y]
if (codePoint != 0) {
val glyph = glyphGrid[x, y]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class ArrayCodePointGrid(private var grid: Array<IntArray>) : MutableCodePointGr
field = value

val newGrid = grid.copyOf(value)
for (i in grid.size until newGrid.size)
for (i in grid.size..<newGrid.size)
newGrid[i] = IntArray(height)
}

Expand Down Expand Up @@ -166,9 +166,9 @@ class ArrayCodePointGrid(private var grid: Array<IntArray>) : MutableCodePointGr

override fun toStringList(): List<String> {
val rows = ArrayList<String>()
for (y in 0 until height) {
for (y in 0..<height) {
val builder = StringBuilder()
for (x in 0 until width) {
for (x in 0..<width) {
builder.appendCodePoint(grid[y][x])
}
rows += builder.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class ReferenceGlyphGrid(
field = value

val newGrid = grid.copyOf(value)
for (i in grid.size until newGrid.size)
for (i in grid.size..<newGrid.size)
newGrid[i] = arrayOfNulls(gridHeight)
}

Expand Down Expand Up @@ -209,8 +209,8 @@ class ReferenceGlyphGrid(
val image = BufferedImage(gridWidth * glyphWidth, gridHeight * glyphHeight, BufferedImage.TYPE_INT_ARGB)
val graphics = image.graphics

for (x in 0 until gridWidth) {
for (y in 0 until gridHeight) {
for (x in 0..<gridWidth) {
for (y in 0..<gridHeight) {
val glyph = grid[x][y] ?: continue

if (glyph.width != glyphWidth || glyph.height != glyphHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class EnchantmentContent(builder: ResourcePackBuilder) : PackTaskHolder {

val offset = Font.findFirstUnoccupiedRange(codePoints, Font.PRIVATE_USE_AREA, TOOLTIP_OVERLAY_CHAR_AMOUNT).first
backgroundCharOffset = offset
for (i in 0 until TOOLTIP_OVERLAY_CHAR_AMOUNT) {
for (i in 0..<TOOLTIP_OVERLAY_CHAR_AMOUNT) {
val width = 2.0.pow(i).toInt()
val img = BufferedImage(width, TOOLTIP_OVERLAY_CHAR_HEIGHT, BufferedImage.TYPE_INT_ARGB)

Expand Down Expand Up @@ -115,7 +115,7 @@ class EnchantmentContent(builder: ResourcePackBuilder) : PackTaskHolder {

val novaEnchTranslation = languageContent.getTranslation(lang, novaEnch.localizedName)
val vanillaLevels = IntArray(novaEnch.maxLevel)
for (novaLevel in 0 until novaEnch.maxLevel) {
for (novaLevel in 0..<novaEnch.maxLevel) {
vanillaLevels[novaLevel] = ++vanillaLevel
languageContent.setTranslation(lang, "enchantment.level.$vanillaLevel", createLevelOverrideTranslation(overlayBoxStr, novaEnchTranslation, novaLevel))
}
Expand All @@ -135,7 +135,7 @@ class EnchantmentContent(builder: ResourcePackBuilder) : PackTaskHolder {
val minusOne = MoveCharacters.getMovingString(-1f)

append(minusLength)
for (bit in 0 until TOOLTIP_OVERLAY_CHAR_AMOUNT) {
for (bit in 0..<TOOLTIP_OVERLAY_CHAR_AMOUNT) {
if (length and (1 shl bit) != 0) {
appendCodePoint(backgroundCharOffset + bit)
append(minusOne)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ class ArmorContent internal constructor(private val builder: ResourcePackBuilder
val height = image.height

val newImage = BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)
for (x in 0 until width) {
for (y in 0 until height) {
for (x in 0..<width) {
for (y in 0..<height) {
val color = Color(image.getRGB(x, y), true)
val newAlpha = (color.red + color.green + color.blue) * color.alpha / 255 / 3
newImage.setRGB(x, y, Color(255, 255, 255, newAlpha).rgb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class MoveCharactersContent(private val builder: ResourcePackBuilder) : PackTask

val advances = Int2FloatOpenHashMap()
// -.25, -.5, ..., -8192
for (i in 0 until SIZE) advances[range[i]] = -2.0.pow(i - EXP_SHIFT).toFloat()
for (i in 0..<SIZE) advances[range[i]] = -2.0.pow(i - EXP_SHIFT).toFloat()
// .25, .5, ..., 8192
for (i in 0 until SIZE) advances[range[i + SIZE]] = 2.0.pow(i - EXP_SHIFT).toFloat()
for (i in 0..<SIZE) advances[range[i + SIZE]] = 2.0.pow(i - EXP_SHIFT).toFloat()

val moveFontId = ResourcePath("nova", "move")
val spaceFont = Font(moveFontId, listOf(SpaceProvider(advances)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ internal enum class BlockDirection(val char: Char, val x: Int, val y: Int) {

fun of(s: String): List<BlockDirection> {
if (s.equals("all", true))
return values().toList()
return entries

return s.toCharArray().map { c -> BlockDirection.values().first { it.char == c } }
return s.toCharArray().map { c -> entries.first { it.char == c } }
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ internal class ItemModelInformation(
val material: Material? = null
) : ModelInformation {

fun toBlockInfo() = BlockModelInformation(id, BlockModelType.DEFAULT, null, models, BlockDirection.values().toList(), 0)
fun toBlockInfo() = BlockModelInformation(id, BlockModelType.DEFAULT, null, models, BlockDirection.entries, 0)

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal data class NoteBlockStateConfig(

override fun of(id: Int): NoteBlockStateConfig {
return NoteBlockStateConfig(
Instrument.values()[id / POWERED_BASE / NOTE_BASE % INSTRUMENT_BASE],
Instrument.entries[id / POWERED_BASE / NOTE_BASE % INSTRUMENT_BASE],
id / POWERED_BASE % NOTE_BASE,
id % POWERED_BASE == 1
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.bukkit.Sound
import org.bukkit.entity.Player
import org.bukkit.event.block.Action
import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.inventory.EquipmentSlot
import xyz.xenondevs.commons.collections.enumMap
import xyz.xenondevs.commons.provider.Provider
import xyz.xenondevs.commons.provider.immutable.orElse
Expand Down Expand Up @@ -173,9 +174,9 @@ sealed interface Wearable {

companion object {

val ARMOR_MODIFIER_UUIDS: Map<BukkitEquipmentSlot, UUID> = BukkitEquipmentSlot.values().associateWithTo(enumMap()) { UUID.randomUUID() }
val ARMOR_TOUGHNESS_MODIFIER_UUIDS: Map<BukkitEquipmentSlot, UUID> = BukkitEquipmentSlot.values().associateWithTo(enumMap()) { UUID.randomUUID() }
val KNOCKBACK_RESISTANCE_MODIFIER_UUIDS: Map<BukkitEquipmentSlot, UUID> = BukkitEquipmentSlot.values().associateWithTo(enumMap()) { UUID.randomUUID() }
val ARMOR_MODIFIER_UUIDS: Map<BukkitEquipmentSlot, UUID> = EquipmentSlot.entries.associateWithTo(enumMap()) { UUID.randomUUID() }
val ARMOR_TOUGHNESS_MODIFIER_UUIDS: Map<BukkitEquipmentSlot, UUID> = EquipmentSlot.entries.associateWithTo(enumMap()) { UUID.randomUUID() }
val KNOCKBACK_RESISTANCE_MODIFIER_UUIDS: Map<BukkitEquipmentSlot, UUID> = EquipmentSlot.entries.associateWithTo(enumMap()) { UUID.randomUUID() }

/**
* Checks whether the specified [itemStack] is wearable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ internal class ItemLogic internal constructor(holders: List<ItemBehaviorHolder>)
section.getKeys(false)
.forEach { key ->
try {
val slot = EquipmentSlot.values().firstOrNull { it.name == key.uppercase() }
val slot = EquipmentSlot.entries.firstOrNull { it.name == key.uppercase() }
?: throw IllegalArgumentException("Unknown equipment slot: $key")
val attributeSections = section.getConfigurationSectionList(key).takeUnlessEmpty()
?: throw IllegalArgumentException("No attribute modifiers defined for slot $key")
Expand All @@ -204,7 +204,7 @@ internal class ItemLogic internal constructor(holders: List<ItemBehaviorHolder>)

val attribute = BuiltInRegistries.ATTRIBUTE.get(ResourceLocation(attributeStr))
?: throw IllegalArgumentException("Unknown attribute: $attributeStr")
val operation = Operation.values().firstOrNull { it.name == operationStr.uppercase() }
val operation = Operation.entries.firstOrNull { it.name == operationStr.uppercase() }
?: throw IllegalArgumentException("Unknown operation: $operationStr")

modifiers += AttributeModifier(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ internal object PacketItems : Listener {
val hasCustomModifiers = itemStack.tag?.contains("AttributeModifiers", Tag.TAG_LIST.toInt()) == true

val lore = ArrayList<Component>()
EquipmentSlot.values().forEach { slot ->
EquipmentSlot.entries.forEach { slot ->
val modifiers: List<AttributeModifier>
if (hasCustomModifiers) {
// use custom attribute modifiers from nbt data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ object VanillaToolCategories {
specialMultipliers: Map<Material, Map<Predicate<Material>, Double>>
): VanillaToolCategory {
val flatSpecialMultipliers = specialMultipliers.mapValuesTo(enumMapOf()) { (_, map) ->
Material.values()
Material.entries
.filter { it.isBlock && !it.isLegacy }
.associateWithNotNullTo(enumMapOf()) { material ->
map.entries.firstOrNull { it.key.test(material) }?.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ class AttributeModifier(
val operation: Operation,
val value: Double,
val showInLore: Boolean,
vararg slots: EquipmentSlot
val slots: List<EquipmentSlot> = EquipmentSlot.entries
) {

val slots = if (slots.isEmpty()) EquipmentSlot.values() else slots
constructor(
uuid: UUID,
name: String,
attribute: Attribute,
operation: Operation,
value: Double,
showInLore: Boolean,
vararg slots: EquipmentSlot
) : this(uuid, name, attribute, operation, value, showInLore, slots.asList())

constructor(name: String, attribute: Attribute, operation: Operation, value: Double, showInLore: Boolean, vararg slots: EquipmentSlot) :
this(UUID.nameUUIDFromBytes(name.toByteArray()), name, attribute, operation, value, showInLore, *slots)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ abstract class NetworkedTileEntity(blockState: NovaTileEntityState) : TileEntity

private fun emptyBucket(holder: NovaFluidHolder, player: Player, hand: EquipmentSlot): Boolean {
val bucket = player.inventory.getItem(hand)
val type = FluidType.values().first { bucket?.isSimilar(it.bucket) ?: false }
val type = FluidType.entries.first { bucket?.isSimilar(it.bucket) ?: false }

val container = holder.availableContainers.values.firstOrNull { it.accepts(type, 1000) && holder.allowedConnectionTypes[it]!!.insert }
if (container != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ enum class NetworkConnectionType(val insert: Boolean, val extract: Boolean, incl
companion object {

fun of(insert: Boolean, extract: Boolean): NetworkConnectionType =
values().first { it.insert == insert && it.extract == extract }
entries.first { it.insert == insert && it.extract == extract }

fun of(types: Iterable<NetworkConnectionType>): NetworkConnectionType {
var insert = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ internal class NetworkedRangedBukkitInventory(
val amount = tempInventory.addItem(null, item) // add item to the temp inventory

// copy items from temp inv to real inv
for (slot in 0 until size) {
for (slot in 0..<size) {
inventory.setItem(slots[slot], tempInventory.getItem(slot))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal abstract class VanillaTileEntity internal constructor(val blockState: V
companion object {

fun of(block: Block): Type? =
Type.values().firstOrNull { it.requirement(block) }
entries.firstOrNull { it.requirement(block) }

}

Expand All @@ -56,7 +56,7 @@ internal abstract class VanillaTileEntity internal constructor(val blockState: V
internal companion object {

fun of(blockState: VanillaTileEntityState): VanillaTileEntity? {
val type = Type.values().firstOrNull { it.id == blockState.id.toString() } ?: return null
val type = Type.entries.firstOrNull { it.id == blockState.id.toString() } ?: return null
if (type.requirement(blockState.pos.block)) {
return type.constructor(blockState)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ internal class WatchedArmorList(player: Player) : NonNullList<ItemStack>(
else -> EquipAction.CHANGE
}

val equipEvent = ArmorEquipEvent(player.bukkitEntity, EquipmentSlot.values()[index + 2], equipAction, previous.bukkitCopy, item.bukkitCopy)
val equipEvent = ArmorEquipEvent(player.bukkitEntity, EquipmentSlot.entries[index + 2], equipAction, previous.bukkitCopy, item.bukkitCopy)
Bukkit.getPluginManager().callEvent(equipEvent)

if (equipEvent.isCancelled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ object BossBarOverlayManager : Listener {
@PacketHandler(ignoreIfCancelled = true)
private fun handleBossBar(event: ClientboundBossEventPacketEvent) {
val id = event.id
if (id.leastSignificantBits != 0L || id.mostSignificantBits !in 0 until BAR_AMOUNT) {
if (id.leastSignificantBits != 0L || id.mostSignificantBits !in 0..<BAR_AMOUNT) {
event.isCancelled = true

val player = event.player
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object MoveCharacters {

val num = abs((distance * MoveCharactersContent.PRECISION).roundToInt())
val buffer = StringBuffer()
for (bit in 0 until MoveCharactersContent.SIZE)
for (bit in 0..<MoveCharactersContent.SIZE)
if (num and (1 shl bit) != 0)
buffer.appendCodePoint(start + bit)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum class BlockSide(private val rotation: Int, val blockFace: BlockFace) {
if (rotation == -1) return blockFace

val rot = ((yaw / 90.0).roundToInt() + rotation).mod(4)
return values()[rot].blockFace
return entries[rot].blockFace
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fun Location.isBetweenXZ(min: Location, max: Location): Boolean =
*/
fun Location.isInsideWorldRestrictions(): Boolean {
val world = world!!
return world.worldBorder.isInside(this) && blockY in world.minHeight until world.maxHeight
return world.worldBorder.isInside(this) && blockY in world.minHeight..<world.maxHeight
}
//</editor-fold>

Expand Down
Loading

0 comments on commit 080ec5c

Please sign in to comment.