Skip to content

Commit

Permalink
1.20.6 Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed May 6, 2024
1 parent a8d6aaa commit 2500258
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
12 changes: 10 additions & 2 deletions eco-api/src/main/java/com/willfp/eco/core/Prerequisite.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,27 @@ 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+"
);

/**
* 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+"
);

Expand Down
3 changes: 0 additions & 3 deletions eco-core/core-nms/v1_20_6/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -87,7 +95,16 @@ class FastItemStackFactory : FastItemStackFactoryProxy {
if (lore == null) {
handle.set<ItemLore>(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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2500258

Please sign in to comment.