Skip to content

Commit 63d0bc1

Browse files
committed
chore: Remove redundant compatibility layers
1 parent 1bc9ffe commit 63d0bc1

File tree

4 files changed

+5
-39
lines changed

4 files changed

+5
-39
lines changed

mimic-bukkit/src/main/kotlin/impl/vanilla/MinecraftItemsRegistry.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import org.bukkit.inventory.ItemStack
2424
import org.bukkit.inventory.meta.Damageable
2525
import org.bukkit.inventory.meta.ItemMeta
2626
import ru.endlesscode.mimic.internal.Log
27-
import ru.endlesscode.mimic.internal.callCompat
2827
import ru.endlesscode.mimic.items.BukkitItemsRegistry
2928

3029
/**
@@ -73,7 +72,7 @@ public class MinecraftItemsRegistry : BukkitItemsRegistry {
7372
// Apply damage and custom model data
7473
isUnbreakable = payload.isUnbreakable
7574
(this as? Damageable)?.damage = payload.damage
76-
if (payload.customModelData != null) trySetCustomModelData(payload.customModelData)
75+
if (payload.customModelData != null) setCustomModelData(payload.customModelData)
7776

7877
// Apply enchants and item flags
7978
payload.enchantments.forEach { (enchant, level) -> addEnchant(enchant, level, true) }
@@ -82,14 +81,6 @@ public class MinecraftItemsRegistry : BukkitItemsRegistry {
8281
return this
8382
}
8483

85-
private fun ItemMeta.trySetCustomModelData(data: Int) {
86-
callCompat(
87-
"ItemMeta.setCustomModelData",
88-
block = { setCustomModelData(data) },
89-
compat = { Log.w("Payload field 'custom-model-data' supported only since Minecraft 1.14") },
90-
)
91-
}
92-
9384
public companion object {
9485
public const val ID: String = "minecraft"
9586
}

mimic-bukkit/src/main/kotlin/internal/Compat.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ru.endlesscode.mimic.internal
22

33
private val notSupportedCalls = mutableSetOf<String>()
44

5+
@Suppress("unused") // Reserved for further compatibility calls
56
internal inline fun <T> callCompat(
67
key: String,
78
block: () -> T,

mimic-bukkit/src/main/kotlin/internal/Configuration.kt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,15 @@ package ru.endlesscode.mimic.internal
33
import org.bukkit.configuration.Configuration
44
import org.bukkit.configuration.file.FileConfigurationOptions
55

6-
@Suppress("DEPRECATION") // Changed in 1.18.1
76
internal fun FileConfigurationOptions.setHeader(vararg lines: String) {
8-
callCompat(
9-
"FileConfigurationOptions.setHeader",
10-
block = { setHeader(lines.asList()) },
11-
compat = { header(lines.joinToString("\n")) },
12-
)
7+
setHeader(lines.asList())
138
}
149

1510
internal fun Configuration.applyDefaults() {
1611
val defaults = defaults ?: return
1712
for (key in defaults.getKeys(true)) set(key, get(key))
1813
}
1914

20-
// Added in 1.18.1
2115
internal fun Configuration.setComments(path: String, vararg comments: String?) {
22-
callCompat(
23-
"Configuration.setComments",
24-
block = { setComments(path, comments.asList()) },
25-
compat = { /* no-op */ },
26-
)
16+
setComments(path, comments.asList())
2717
}

mimic-bukkit/src/main/kotlin/internal/NamespacedKey.kt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,4 @@ package ru.endlesscode.mimic.internal
22

33
import org.bukkit.NamespacedKey
44

5-
internal fun namespacedKeyOf(key: String): NamespacedKey? {
6-
return callCompat(
7-
"NamespacedKey.fromString",
8-
block = { NamespacedKey.fromString(key) },
9-
compat = { namespacedKeyCompat(key) },
10-
)
11-
}
12-
13-
@Suppress("DEPRECATION")
14-
private fun namespacedKeyCompat(string: String): NamespacedKey? {
15-
val components = string.split(":", limit = 3)
16-
return when (components.size) {
17-
1 -> NamespacedKey.minecraft(components.first())
18-
2 -> NamespacedKey(components.first(), components.last())
19-
else -> null
20-
}
21-
}
5+
internal fun namespacedKeyOf(key: String): NamespacedKey? = NamespacedKey.fromString(key)

0 commit comments

Comments
 (0)