diff --git a/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java b/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java index a197e99a5..db791784f 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java +++ b/eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java @@ -37,11 +37,19 @@ public class Prerequisite { "Requires server to have ProtocolLib" ); + /** + * Requires the server to be running 1.20.5. + */ + public static final Prerequisite HAS_1_20_5 = new Prerequisite( + () -> ProxyConstants.NMS_VERSION.contains("1_20_") && !ProxyConstants.NMS_VERSION.contains("R"), + "Requires server to be running 1.20.5+" + ); + /** * Requires the server to be running 1.20.3. */ public static final Prerequisite HAS_1_20_3 = new Prerequisite( - () -> ProxyConstants.NMS_VERSION.contains("20_R3"), + () -> ProxyConstants.NMS_VERSION.contains("20_R3") || HAS_1_20_5.isMet(), "Requires server to be running 1.20.3+" ); @@ -49,7 +57,7 @@ public class Prerequisite { * Requires the server to be running 1.20. */ public static final Prerequisite HAS_1_20 = new Prerequisite( - () -> ProxyConstants.NMS_VERSION.contains("20"), + () -> ProxyConstants.NMS_VERSION.contains("20") || HAS_1_20_3.isMet(), "Requires server to be running 1.20+" ); diff --git a/eco-core/core-nms/v1_20_6/build.gradle.kts b/eco-core/core-nms/v1_20_6/build.gradle.kts index 4e5b4dd81..5f11cfbff 100644 --- a/eco-core/core-nms/v1_20_6/build.gradle.kts +++ b/eco-core/core-nms/v1_20_6/build.gradle.kts @@ -15,9 +15,6 @@ dependencies { } exclude(group = "net.kyori", module = "adventure-api") } - - // I know this is the wrong version, but org.bukkit.Material refused to work - compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT") } tasks { diff --git a/eco-core/core-nms/v1_20_6/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_6/FastItemStackFactory.kt b/eco-core/core-nms/v1_20_6/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_6/FastItemStackFactory.kt index a52e113d8..b159e80c8 100644 --- a/eco-core/core-nms/v1_20_6/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_6/FastItemStackFactory.kt +++ b/eco-core/core-nms/v1_20_6/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_20_6/FastItemStackFactory.kt @@ -16,6 +16,7 @@ import com.willfp.eco.util.StringUtils import com.willfp.eco.util.toComponent import com.willfp.eco.util.toLegacy import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.TextDecoration import net.minecraft.core.component.DataComponentType import net.minecraft.core.component.DataComponents import net.minecraft.nbt.CompoundTag @@ -31,6 +32,10 @@ import org.bukkit.inventory.ItemStack import org.bukkit.persistence.PersistentDataContainer import kotlin.math.max +private val unstyledComponent = Component.empty().style { + it.color(null).decoration(TextDecoration.ITALIC, false) +} + class FastItemStackFactory : FastItemStackFactoryProxy { override fun create(itemStack: ItemStack): FastItemStack { return NewEcoFastItemStack(itemStack) @@ -40,7 +45,10 @@ class FastItemStackFactory : FastItemStackFactoryProxy { class NewEcoFastItemStack( private val bukkit: ItemStack ) : ImplementedFIS { + // Cast is there because, try as I might, I can't get IntellIJ to recognise half the classes in the dev bundle + @Suppress("USELESS_CAST") private val handle = bukkit.asNMSStack() as net.minecraft.world.item.ItemStack + private val pdc = if (handle.has(DataComponents.CUSTOM_DATA)) { handle.get(DataComponents.CUSTOM_DATA)!!.copyTag().makePdc() } else { @@ -87,7 +95,16 @@ class FastItemStackFactory : FastItemStackFactoryProxy { if (lore == null) { handle.set(DataComponents.LORE, null) } else { - handle.set(DataComponents.LORE, ItemLore(lore.map { it.toNMS() })) + val components = lore + .map { unstyledComponent.append(it) } + .map { it.toNMS() } + + handle.set( + DataComponents.LORE, ItemLore( + components, + components + ) + ) } apply() @@ -359,11 +376,11 @@ class FastItemStackFactory : FastItemStackFactoryProxy { } override fun apply() { - handle.update(DataComponents.CUSTOM_DATA, CustomData.of(CompoundTag())) { - it.apply { - @Suppress("DEPRECATION") - unsafe.setPdc(pdc) - } + val customData = handle.get(DataComponents.CUSTOM_DATA) + if (customData != null) { + val tag = customData.copyTag() + tag.setPdc(pdc) + handle.set(DataComponents.CUSTOM_DATA, CustomData.of(tag)) } bukkit.mergeIfNeeded(handle)