Skip to content

Commit

Permalink
Added preliminary 1.20.6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed May 4, 2024
1 parent 2829baf commit 6fd4eb7
Show file tree
Hide file tree
Showing 37 changed files with 1,213 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/java-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 17
java-version: 21

- name: Setup build cache
uses: actions/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
- name: Checkout latest code
uses: actions/checkout@v2

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 17
java-version: 21

- name: Setup build cache
uses: actions/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: 17
java-version: 21

- name: Setup build cache
uses: actions/[email protected]
Expand Down
13 changes: 11 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {

plugins {
id("java-library")
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.github.goooler.shadow") version "8.1.7"
id("maven-publish")
id("java")
kotlin("jvm") version "1.9.21"
Expand All @@ -30,13 +30,14 @@ dependencies {
implementation(project(path = ":eco-core:core-nms:v1_20_R1", configuration = "reobf"))
implementation(project(path = ":eco-core:core-nms:v1_20_R2", configuration = "reobf"))
implementation(project(path = ":eco-core:core-nms:v1_20_R3", configuration = "reobf"))
implementation(project(path = ":eco-core:core-nms:v1_20_6", configuration = "reobf"))
}

allprojects {
apply(plugin = "java")
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "io.github.goooler.shadow")
apply(plugin = "kotlin")

repositories {
Expand Down Expand Up @@ -208,5 +209,13 @@ allprojects {
}
}


// Root is Java 21 to support 1.20.6+, rest use Java 17
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
withSourcesJar()
}

group = "com.willfp"
version = findProperty("version")!!
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* @param version The extension version.
* @param name The extension name.
* @param author The extension's author.
* @param file The extension's file.
* @param minimumPluginVersion The minimum plugin version required for this extension.
*/
public record ExtensionMetadata(@NotNull String version,
@NotNull String name,
Expand Down
12 changes: 10 additions & 2 deletions eco-api/src/main/java/com/willfp/eco/core/fast/FastItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,23 @@ int getEnchantmentLevel(@NotNull Enchantment enchantment,
* The returned PersistentDataContainer will not modify the item until the tag is set.
*
* @return The base NBT tag.
* @deprecated Items are now component-based.
*/
PersistentDataContainer getBaseTag();
@Deprecated(forRemoval = true, since = "6.70.0")
default PersistentDataContainer getBaseTag() {
throw new UnsupportedOperationException("Not supported in 1.20.5+");
}

/**
* Set the base NBT tag (Not PublicBukkitValues, the base) from a PersistentDataContainer.
*
* @param container The PersistentDataContainer.
* @deprecated Items are now component-based.
*/
void setBaseTag(@Nullable PersistentDataContainer container);
@Deprecated(forRemoval = true, since = "6.70.0")
default void setBaseTag(@Nullable PersistentDataContainer container) {
throw new UnsupportedOperationException("Not supported in 1.20.5+");
}

/**
* Get the type of the item.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

/**
* Handles menu events.
*
* @param <T> The type of event to handle.x
*/
public abstract class MenuEventHandler<T extends MenuEvent> {
/**
Expand Down
7 changes: 7 additions & 0 deletions eco-api/src/main/java/com/willfp/eco/core/items/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.willfp.eco.core.recipe.parts.UnrestrictedMaterialTestableItem;
import com.willfp.eco.util.NamespacedKeyUtils;
import com.willfp.eco.util.NumberUtils;
import kotlin.Suppress;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
Expand Down Expand Up @@ -515,8 +516,11 @@ public static ItemMeta mergeFrom(@NotNull final ItemMeta from,
*
* @param itemStack The ItemStack.
* @return The base NBT.
* @deprecated Items are now component-based.
*/
@NotNull
@Deprecated(since = "6.70.0", forRemoval = true)
@SuppressWarnings("removal")
public static PersistentDataContainer getBaseNBT(@NotNull final ItemStack itemStack) {
return FastItemStack.wrap(itemStack).getBaseTag();
}
Expand All @@ -527,8 +531,11 @@ public static PersistentDataContainer getBaseNBT(@NotNull final ItemStack itemSt
* @param itemStack The ItemStack.
* @param container The base NBT tag.
* @return The ItemStack, modified. Not required to use, as this modifies the instance.¬
* @deprecated Items are now component-based.
*/
@NotNull
@Deprecated(since = "6.70.0", forRemoval = true)
@SuppressWarnings("removal")
public static ItemStack setBaseNBT(@NotNull final ItemStack itemStack,
@Nullable final PersistentDataContainer container) {
FastItemStack fis = FastItemStack.wrap(itemStack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public final class ProxyConstants {
"v1_19_R3",
"v1_20_R1",
"v1_20_R2",
"v1_20_R3"
"v1_20_R3",
"v1_20_6"
);

private ProxyConstants() {
Expand Down
4 changes: 4 additions & 0 deletions eco-api/src/main/kotlin/com/willfp/eco/core/items/Items.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ fun ItemMeta.mergeFrom(other: ItemMeta): ItemMeta =
* @see Items.getBaseNBT
* @see Items.setBaseNBT
*/
@Suppress("DEPRECATION")
@Deprecated("Not supported in 1.20.5+", level = DeprecationLevel.ERROR)
var ItemStack.baseNBT: PersistentDataContainer
get() = Items.getBaseNBT(this)
set(value) {
Items.setBaseNBT(this, value)
}

/** @see Items.setBaseNBT */
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("Not supported in 1.20.5+", level = DeprecationLevel.ERROR)
fun ItemStack.clearNBT() =
Items.setBaseNBT(this, null)

Expand Down
2 changes: 1 addition & 1 deletion eco-core/core-nms/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id("io.papermc.paperweight.userdev") version "1.5.3" apply false
id("io.papermc.paperweight.userdev") version "1.6.2" apply false
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.willfp.eco.internal.spigot.proxy.common.ai.EntityGoalFactory
import com.willfp.eco.internal.spigot.proxy.common.ai.TargetGoalFactory
import io.papermc.paper.adventure.PaperAdventure
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer
import net.minecraft.nbt.CompoundTag
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.level.ServerPlayer
Expand Down Expand Up @@ -74,6 +75,15 @@ fun Player.toNMS(): ServerPlayer =
fun Component.toNMS(): net.minecraft.network.chat.Component =
if (Prerequisite.HAS_PAPER.isMet) PaperAdventure.asVanilla(this) else impl.toNMS(this)

fun net.minecraft.network.chat.Component.toAdventure(): Component {
if (Prerequisite.HAS_PAPER.isMet) {
return PaperAdventure.asAdventure(this)
}

val json = net.minecraft.network.chat.Component.Serializer.toJson(this)
return GsonComponentSerializer.gson().deserialize(json)
}

interface CommonsProvider {
val nbtTagString: Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ import kotlin.experimental.and
import kotlin.experimental.inv
import kotlin.experimental.or

interface ImplementedFIS : FastItemStack {
fun apply()
}

@Suppress("UsePropertyAccessSyntax")
class EcoFastItemStack(
private val bukkit: org.bukkit.inventory.ItemStack
) : FastItemStack {
) : ImplementedFIS {
private val handle = bukkit.asNMSStack()
private val pdc = (if (handle.hasTag()) handle.getTag()!! else CompoundTag()).makePdc()

Expand Down Expand Up @@ -184,9 +188,11 @@ class EcoFastItemStack(
return this.flagBits and bitModifier == bitModifier
}

@Deprecated("Not supported in 1.20.5+")
override fun getBaseTag(): PersistentDataContainer =
(if (handle.hasTag()) handle.getTag()!! else CompoundTag()).makePdc(base = true)

@Deprecated("Not supported in 1.20.5+")
override fun setBaseTag(container: PersistentDataContainer?) {
(if (handle.hasTag()) handle.getTag()!! else CompoundTag()).setPdc(container, item = handle)
apply()
Expand Down Expand Up @@ -259,7 +265,7 @@ class EcoFastItemStack(
return handle.getTag()?.hashCode() ?: (0b00010101 * 31 + Item.getId(handle.getItem()))
}

internal fun apply() {
override fun apply() {
if (handle.hasTag()) {
handle.getTag()?.setPdc(this.pdc)
}
Expand All @@ -276,9 +282,9 @@ class EcoFastItemStack(
}
}

private class ContinuallyAppliedPersistentDataContainer(
class ContinuallyAppliedPersistentDataContainer(
val handle: PersistentDataContainer,
val fis: EcoFastItemStack
private val fis: ImplementedFIS
) : PersistentDataContainer by handle {
override fun <T : Any, Z : Any> set(key: NamespacedKey, type: PersistentDataType<T, Z>, value: Z) {
handle.set(key, type, value)
Expand Down
54 changes: 54 additions & 0 deletions eco-core/core-nms/v1_20_6/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
id("io.papermc.paperweight.userdev")
}

group = "com.willfp"
version = rootProject.version

dependencies {
implementation(project(":eco-core:core-nms:nms-common"))
paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT")

implementation("net.kyori:adventure-text-minimessage:4.11.0") {
version {
strictly("4.11.0")
}
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 {
build {
dependsOn(reobfJar)
}

reobfJar {
mustRunAfter(shadowJar)
}

shadowJar {
relocate(
"com.willfp.eco.internal.spigot.proxy.common",
"com.willfp.eco.internal.spigot.proxy.v1_20_6.common"
)
relocate(
"net.kyori.adventure.text.minimessage",
"com.willfp.eco.internal.spigot.proxy.v1_20_6.minimessage"
)
}

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
withSourcesJar()
}

compileKotlin {
kotlinOptions {
jvmTarget = "21"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.willfp.eco.internal.spigot.proxy.v1_20_6

import com.willfp.eco.core.command.PluginCommandBase
import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy
import org.bukkit.Bukkit
import org.bukkit.command.Command
import org.bukkit.command.SimpleCommandMap
import org.bukkit.craftbukkit.CraftServer
import java.lang.reflect.Field

class BukkitCommands : BukkitCommandsProxy {
private val knownCommandsField: Field by lazy {
SimpleCommandMap::class.java.getDeclaredField("knownCommands")
.apply {
isAccessible = true
}
}

@Suppress("UNCHECKED_CAST")
private val knownCommands: MutableMap<String, Command>
get() = knownCommandsField.get(getCommandMap()) as MutableMap<String, Command>

override fun getCommandMap(): SimpleCommandMap {
return (Bukkit.getServer() as CraftServer).commandMap
}

override fun syncCommands() {
(Bukkit.getServer() as CraftServer).syncCommands()
}

override fun unregisterCommand(command: PluginCommandBase) {
knownCommands.remove(command.name)
knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}")
}
}
Loading

0 comments on commit 6fd4eb7

Please sign in to comment.