From 010b54e9edaaa3695112e3c49159358aec201502 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 23 Apr 2026 13:01:00 +0200 Subject: [PATCH 01/41] initial 1.21 transition --- build.gradle.kts | 2 +- gradle.properties | 2 +- nms/v1_17R1/.gitignore | 1 - nms/v1_17R1/build.gradle.kts | 35 ------------------- .../packet/versions/V1_17R1_PacketManager.kt | 33 ----------------- nms/v1_18R1/.gitignore | 1 - nms/v1_18R1/build.gradle.kts | 35 ------------------- .../packet/versions/V1_18R1_PacketManager.kt | 33 ----------------- nms/v1_18R2/.gitignore | 1 - nms/v1_18R2/build.gradle.kts | 35 ------------------- .../packet/versions/V1_18R2_PacketManager.kt | 33 ----------------- nms/v1_19R1/.gitignore | 1 - nms/v1_19R1/build.gradle.kts | 35 ------------------- .../packet/versions/V1_19R1_PacketManager.kt | 33 ----------------- nms/v1_19R2/.gitignore | 1 - nms/v1_19R2/build.gradle.kts | 35 ------------------- .../packet/versions/V1_19R2_PacketManager.kt | 33 ----------------- nms/v1_19R3/.gitignore | 1 - nms/v1_19R3/build.gradle.kts | 35 ------------------- .../packet/versions/V1_19R3_PacketManager.kt | 33 ----------------- nms/v1_20R1/.gitignore | 1 - nms/v1_20R1/build.gradle.kts | 35 ------------------- .../packet/versions/V1_20R1_PacketManager.kt | 33 ----------------- nms/v1_20R2/.gitignore | 1 - nms/v1_20R2/build.gradle.kts | 35 ------------------- .../packet/versions/V1_20R2_PacketManager.kt | 33 ----------------- nms/v1_20R3/.gitignore | 1 - nms/v1_20R3/build.gradle.kts | 35 ------------------- .../packet/versions/V1_20R3_PacketManager.kt | 33 ----------------- nms/v1_20R4/.gitignore | 1 - nms/v1_20R4/build.gradle.kts | 35 ------------------- .../packet/versions/V1_20R4_PacketManager.kt | 33 ----------------- .../settings/EnchantSelectSettingGui.java | 4 +-- .../settings/GroupSelectSettingGui.java | 4 +-- .../cuanvil/command/DiagnosticExecutor.kt | 7 ++-- 35 files changed, 10 insertions(+), 699 deletions(-) delete mode 100644 nms/v1_17R1/.gitignore delete mode 100644 nms/v1_17R1/build.gradle.kts delete mode 100644 nms/v1_17R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_17R1_PacketManager.kt delete mode 100644 nms/v1_18R1/.gitignore delete mode 100644 nms/v1_18R1/build.gradle.kts delete mode 100644 nms/v1_18R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R1_PacketManager.kt delete mode 100644 nms/v1_18R2/.gitignore delete mode 100644 nms/v1_18R2/build.gradle.kts delete mode 100644 nms/v1_18R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R2_PacketManager.kt delete mode 100644 nms/v1_19R1/.gitignore delete mode 100644 nms/v1_19R1/build.gradle.kts delete mode 100644 nms/v1_19R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R1_PacketManager.kt delete mode 100644 nms/v1_19R2/.gitignore delete mode 100644 nms/v1_19R2/build.gradle.kts delete mode 100644 nms/v1_19R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R2_PacketManager.kt delete mode 100644 nms/v1_19R3/.gitignore delete mode 100644 nms/v1_19R3/build.gradle.kts delete mode 100644 nms/v1_19R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R3_PacketManager.kt delete mode 100644 nms/v1_20R1/.gitignore delete mode 100644 nms/v1_20R1/build.gradle.kts delete mode 100644 nms/v1_20R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R1_PacketManager.kt delete mode 100644 nms/v1_20R2/.gitignore delete mode 100644 nms/v1_20R2/build.gradle.kts delete mode 100644 nms/v1_20R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R2_PacketManager.kt delete mode 100644 nms/v1_20R3/.gitignore delete mode 100644 nms/v1_20R3/build.gradle.kts delete mode 100644 nms/v1_20R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R3_PacketManager.kt delete mode 100644 nms/v1_20R4/.gitignore delete mode 100644 nms/v1_20R4/build.gradle.kts delete mode 100644 nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R4_PacketManager.kt diff --git a/build.gradle.kts b/build.gradle.kts index 4436e29e..bc335718 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -55,7 +55,7 @@ val reobfNMS = providers.gradleProperty("subprojects.reobfnms") dependencies { // Spigot api - compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT") // fast stats implementation("dev.faststats.metrics:bukkit:0.27.0") diff --git a/gradle.properties b/gradle.properties index 4397d2e8..8bf9e80a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ signing.secretKeyRingFile=~/.gnupg/secring.gpg kotlin.daemon.jvmargs=-Xmx8G # list of nms -subprojects.reobfnms=v1_17R1,v1_18R1,v1_18R2,v1_19R1,v1_19R2,v1_19R3,v1_20R1,v1_20R2,v1_20R3,v1_20R4,v1_21R1,v1_21R2,v1_21R3,v1_21R4,v1_21R5,v1_21R6,v1_21R7 +subprojects.reobfnms=v1_21R1,v1_21R2,v1_21R3,v1_21R4,v1_21R5,v1_21R6,v1_21R7 # list of version for hangar release paperVersion=1.18-26.2 diff --git a/nms/v1_17R1/.gitignore b/nms/v1_17R1/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_17R1/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_17R1/build.gradle.kts b/nms/v1_17R1/build.gradle.kts deleted file mode 100644 index c354b1ce..00000000 --- a/nms/v1_17R1/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.17.1-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "16" - targetCompatibility = "16" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_16) - } -} diff --git a/nms/v1_17R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_17R1_PacketManager.kt b/nms/v1_17R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_17R1_PacketManager.kt deleted file mode 100644 index c820eabf..00000000 --- a/nms/v1_17R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_17R1_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_17R1_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_18R1/.gitignore b/nms/v1_18R1/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_18R1/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_18R1/build.gradle.kts b/nms/v1_18R1/build.gradle.kts deleted file mode 100644 index 44873d5a..00000000 --- a/nms/v1_18R1/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.18.1-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "17" - targetCompatibility = "17" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/nms/v1_18R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R1_PacketManager.kt b/nms/v1_18R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R1_PacketManager.kt deleted file mode 100644 index 71df5c72..00000000 --- a/nms/v1_18R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R1_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_18R1_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_18R2/.gitignore b/nms/v1_18R2/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_18R2/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_18R2/build.gradle.kts b/nms/v1_18R2/build.gradle.kts deleted file mode 100644 index cf349ec6..00000000 --- a/nms/v1_18R2/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.18.2-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "17" - targetCompatibility = "17" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/nms/v1_18R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R2_PacketManager.kt b/nms/v1_18R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R2_PacketManager.kt deleted file mode 100644 index ee442f5e..00000000 --- a/nms/v1_18R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R2_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_18R2_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_19R1/.gitignore b/nms/v1_19R1/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_19R1/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_19R1/build.gradle.kts b/nms/v1_19R1/build.gradle.kts deleted file mode 100644 index 9791b9b9..00000000 --- a/nms/v1_19R1/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.19.2-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "17" - targetCompatibility = "17" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/nms/v1_19R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R1_PacketManager.kt b/nms/v1_19R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R1_PacketManager.kt deleted file mode 100644 index 7a057fcc..00000000 --- a/nms/v1_19R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R1_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_19R1_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_19R2/.gitignore b/nms/v1_19R2/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_19R2/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_19R2/build.gradle.kts b/nms/v1_19R2/build.gradle.kts deleted file mode 100644 index 88f1a8ad..00000000 --- a/nms/v1_19R2/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.19.3-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "17" - targetCompatibility = "17" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/nms/v1_19R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R2_PacketManager.kt b/nms/v1_19R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R2_PacketManager.kt deleted file mode 100644 index 0d04cd1f..00000000 --- a/nms/v1_19R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R2_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_19R2_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_19R3/.gitignore b/nms/v1_19R3/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_19R3/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_19R3/build.gradle.kts b/nms/v1_19R3/build.gradle.kts deleted file mode 100644 index 3d609af4..00000000 --- a/nms/v1_19R3/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "17" - targetCompatibility = "17" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/nms/v1_19R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R3_PacketManager.kt b/nms/v1_19R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R3_PacketManager.kt deleted file mode 100644 index 7c727912..00000000 --- a/nms/v1_19R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R3_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_19R3_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_20R1/.gitignore b/nms/v1_20R1/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_20R1/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_20R1/build.gradle.kts b/nms/v1_20R1/build.gradle.kts deleted file mode 100644 index 67b46b5e..00000000 --- a/nms/v1_20R1/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "18" - targetCompatibility = "18" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_18) - } -} diff --git a/nms/v1_20R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R1_PacketManager.kt b/nms/v1_20R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R1_PacketManager.kt deleted file mode 100644 index 1fbac836..00000000 --- a/nms/v1_20R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R1_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_20R1_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_20R2/.gitignore b/nms/v1_20R2/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_20R2/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_20R2/build.gradle.kts b/nms/v1_20R2/build.gradle.kts deleted file mode 100644 index e8417cd8..00000000 --- a/nms/v1_20R2/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "18" - targetCompatibility = "18" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_18) - } -} diff --git a/nms/v1_20R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R2_PacketManager.kt b/nms/v1_20R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R2_PacketManager.kt deleted file mode 100644 index a2db371b..00000000 --- a/nms/v1_20R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R2_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_20R2_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_20R3/.gitignore b/nms/v1_20R3/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_20R3/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_20R3/build.gradle.kts b/nms/v1_20R3/build.gradle.kts deleted file mode 100644 index c49ff48d..00000000 --- a/nms/v1_20R3/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "18" - targetCompatibility = "18" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_18) - } -} diff --git a/nms/v1_20R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R3_PacketManager.kt b/nms/v1_20R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R3_PacketManager.kt deleted file mode 100644 index 51c2ecb6..00000000 --- a/nms/v1_20R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R3_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_20R3_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_20R4/.gitignore b/nms/v1_20R4/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_20R4/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_20R4/build.gradle.kts b/nms/v1_20R4/build.gradle.kts deleted file mode 100644 index 3b98361e..00000000 --- a/nms/v1_20R4/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "18" - targetCompatibility = "18" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0) - jvmTarget.set(JvmTarget.JVM_18) - } -} diff --git a/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R4_PacketManager.kt b/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R4_PacketManager.kt deleted file mode 100644 index ac1e504d..00000000 --- a/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R4_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_20R4_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java index 176da55b..ab32531c 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java @@ -141,10 +141,10 @@ public class EnchantSelectSettingGui extends SettingGuiListConfigGui Date: Wed, 3 Jun 2026 04:25:10 +0200 Subject: [PATCH 02/41] progress on 1.21 transition --- .github/workflows/gradle.yml | 2 +- README.md | 7 +- defaultconfigs/1.18/README.md | 6 - defaultconfigs/1.18/config.yml | 472 ------------------ defaultconfigs/1.18/custom_recipes.yml | 5 - defaultconfigs/1.18/enchant_conflict.yml | 247 --------- defaultconfigs/1.18/item_groups.yml | 210 -------- defaultconfigs/1.18/unit_repair_item.yml | 190 ------- defaultconfigs/README.md | 1 - impl/LegacyEcoEnchant/build.gradle.kts | 2 +- nms/nms-common/build.gradle.kts | 6 +- nms/nms-paper/build.gradle.kts | 6 +- .../dependency/datapack/DataPackTester.kt | 26 +- .../cuanvil/enchant/EnchantmentRarity.java | 2 +- .../cuanvil/command/DiagnosticExecutor.kt | 35 +- .../cuanvil/dependency/DependencyManager.kt | 25 +- .../dependency/MinecraftVersionUtil.kt | 27 +- .../plugins/DisenchantmentDependency.kt | 18 +- .../dependency/plugins/HavenBagsDependency.kt | 10 +- .../cuanvil/listener/AnvilCloseListener.kt | 4 +- src/main/resources/enchant_conflict.yml | 3 - src/main/resources/item_groups.yml | 1 - src/main/resources/plugin.yml | 2 +- 23 files changed, 62 insertions(+), 1245 deletions(-) delete mode 100644 defaultconfigs/1.18/README.md delete mode 100644 defaultconfigs/1.18/config.yml delete mode 100644 defaultconfigs/1.18/custom_recipes.yml delete mode 100644 defaultconfigs/1.18/enchant_conflict.yml delete mode 100644 defaultconfigs/1.18/item_groups.yml delete mode 100644 defaultconfigs/1.18/unit_repair_item.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index a50cacd8..befd5102 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -26,7 +26,7 @@ jobs: contents: write env: - MODRINTH_VERSIONS: '["1.18.x", "1.19.x", "1.20.x", "1.21.x", "26.1.x", "26.2.x"]' + MODRINTH_VERSIONS: '["1.21.x", "26.1.x", "26.2.x"]' MODRINTH_PLATFORMS: '["spigot", "paper", "purpur", "folia"]' steps: diff --git a/README.md b/README.md index 9d9e678e..49895bbb 100644 --- a/README.md +++ b/README.md @@ -72,10 +72,9 @@ See the [Compatibility list](https://github.com/alexcrea/CustomAnvil/blob/v1.x.x One of the configurations allow displaying price about 40 and removing Too Expensive. \ By how the minecraft client work: price above 40 can only be displayed green, even if the player does not own enough experience level. -spigot version 1.18 to 1.21.11 do not need any ProtocoLib dependency. (26.1.0 or above requires it) \ -Any recent paper version also are supported for this feature. -But you should wait for update for new version containing new enchantable item or new enchantments if any of this got added. -Else it is, likely, fine to use the current version you are ussing on a new paper version +You do not need Protocolib unless you are using spigot above in 26.1 or above \ + +But you should wait for update or announcement for new version containing new enchantable item or new enchantments. ### For custom enchantment plugin developers For information about the API, please refer to [the Wiki](https://github.com/alexcrea/CustomAnvil/wiki) \ diff --git a/defaultconfigs/1.18/README.md b/defaultconfigs/1.18/README.md deleted file mode 100644 index d390f3f5..00000000 --- a/defaultconfigs/1.18/README.md +++ /dev/null @@ -1,6 +0,0 @@ -### Default Plugin's Configurations For 1.18 to 1.20.6 -- [config.yml](https://github.com/alexcrea/CustomAnvil/blob/master/defaultconfigs/1.18/config.yml) -- [enchant_conflict.yml](https://github.com/alexcrea/CustomAnvil/blob/master/defaultconfigs/1.18/enchant_conflict.yml) -- [item_groups.yml](https://github.com/alexcrea/CustomAnvil/blob/master/defaultconfigs/1.18/item_groups.yml) -- [unit_repair_item.yml](https://github.com/alexcrea/CustomAnvil/blob/master/defaultconfigs/1.18/unit_repair_item.yml) -- [custom_recipes.yml](https://github.com/alexcrea/CustomAnvil/blob/master/defaultconfigs/1.18/custom_recipes.yml) diff --git a/defaultconfigs/1.18/config.yml b/defaultconfigs/1.18/config.yml deleted file mode 100644 index 4e08ca20..00000000 --- a/defaultconfigs/1.18/config.yml +++ /dev/null @@ -1,472 +0,0 @@ -# -# It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! -# - -# What service of metric should custom anvil use -# Custom anvil collect generic information like server minecraft version, type, etc... -# It can also collect error information if error is happening (currently faststats only) -# It can also be disabled -# Please refer to README for public metric link -# Possible options: auto, bstat, faststats, disabled (auto by default) -metric_type: auto - -# Allow to report errors made caused by this plugin (only for faststats) -# This allows me to fix potentials issue that I'm not aware of -# Accept true or false (true by default) -metric_collect_errors: true - -# All anvil cost will be capped to limit_repair_value if enabled. -# -# In other words: -# For any anvil cost greater than limit_repair_value, Cost will be set to limit_repair_value. -limit_repair_cost: false - -# Max cost value the Anvil can get to. -# -# Valid values include 0 to 1000. -# Cost will be displayed as "Too Expensive": -# - If Cost is above 39 -# - And replace_too_expensive is disabled (false) -limit_repair_value: 39 - -# Whether the anvil's cost limit should be removed entirely. -# -# The anvil will still visually display "Too Expensive" if "replace_too_expensive" is disabled -# However, the action will be completable if xp requirement is meet. -remove_repair_limit: false - -# Whenever anvil cost is above 39 should display the true price and not "Too Expensive". -# -# However, when bypassing "Too Expensive", anvil price will be displayed as Green. -# If the action is not completable, the cost will still be displayed as "Too expensive". -# That mean you also need to change other settings like remove_repair_limit or limit_repair_cost. -# -# Require ProtocoLib. -replace_too_expensive: false - -# XP Level amount added to the anvil when the item is repaired by another item of the same type -# -# Valid values include 0 to 1000 -item_repair_cost: 2 - -# XP Level amount added to the anvil when the item is renamed -# -# Valid values include 0 to 1000 -item_rename_cost: 1 - -# XP Level amount added to the anvil when the item is repaired by an "unit" -# For example: a Diamond on a Diamond Sword -# What's considered unit for what can be edited on the unit repair configuration. -# -# Valid values include 0 to 1000 -unit_repair_cost: 1 - -# XP Level amount added to the anvil when a sacrifice enchantment -# conflict with one of the left item enchantment -# -# Valid values include 0 to 1000 -sacrifice_illegal_enchant_cost: 1 - -# Allow using color code and hexadecimal color. -# -# Color code are prefixed by "&" and hexadecimal color by "#". -# Color code will not be applied if it colors nothing. "&&" can be used to write "&". -# For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ -allow_color_code: false -allow_hexadecimal_color: false -allow_minimessage: false - -# This enables restricting color code for player having specific permission -# It requires allow_color_code enabled for... obvious reasons -# -# For example: if player want to use "&aHello" it will be required that the player has -# the permission "ca.color.code.a" as he used the color code "a" -# In general permission to give to the player is "ca.color.code.[code]" -# where [code] is the color code you wish to allow the player -# -# It is kinda of useless when minimessage is supported as players would be able to bypass -# that using the equivalent minimessage tag -per_color_code_permission: false - -# Toggle if color should only be applicable if the player a certain permission. -# -# permission are "ca.color.code" for use of color code and "ca.color.hex" for use of hexadecimal color. -permission_needed_for_color: true - -# Xp cost if the player use color in the items name on rename. -# -# Valid values include 0 to 1000. -use_of_color_cost: 0 - -# Dialogue rename menu make use of dialog menu to allow bigger rename -# You can also change the maximum size and set it to -1 or less for maximum -# -# This feature only work on paper 1.21.7 or later -# -# At the moment only english is available for this menu... sorry ! -# -# CustomAnvil use "ca.rename.dialog" when permission -enable_dialog_rename: false -dialog_rename_max_size: 256 -permission_needed_for_dialog_rename: false - -# This allows custom anvil to not "guess" the text used for rename but store it in the item -# It will make item stackable only and only if it had used the same rename text -# -# For practical reason. this only work when dialog rename is enabled -dialog_rename_keep_user_text: true - -# Also count left item enchantments for the final price -include_left_enchantment_for_cost: false - -# Override limits for specific enchants -# -# Enchantments not listed here will use the value of default_limit -# -# Overrides provided default from aqua_affinity to depth_strider won't change effect with extra levels -# -# Valid range of 0 - 255 for each enchantment -# -1 mean keep default -enchant_limits: - minecraft:aqua_affinity: 1 - minecraft:binding_curse: 1 - minecraft:channeling: 1 - minecraft:flame: 1 - minecraft:infinity: 1 - minecraft:mending: 1 - minecraft:multishot: 1 - minecraft:silk_touch: 1 - minecraft:vanishing_curse: 1 - minecraft:depth_strider: 3 # anything more than 3 is treated as 3 by the game - minecraft:protection: 4 - minecraft:fire_protection: 4 - minecraft:blast_protection: 4 - minecraft:projectile_protection: 4 - minecraft:feather_falling: 4 - minecraft:thorns: 3 - minecraft:respiration: 3 - minecraft:sharpness: 5 - minecraft:smite: 5 - minecraft:bane_of_arthropods: 5 - minecraft:knockback: 2 - minecraft:fire_aspect: 2 - minecraft:looting: 3 - minecraft:sweeping: 3 - minecraft:sweeping_edge: 3 - minecraft:efficiency: 5 - minecraft:unbreaking: 3 - minecraft:fortune: 3 - minecraft:power: 5 - minecraft:punch: 2 - minecraft:luck_of_the_sea: 3 - minecraft:lure: 3 - minecraft:frost_walker: 2 - minecraft:impaling: 5 - minecraft:riptide: 3 - minecraft:loyalty: 3 - minecraft:piercing: 4 - minecraft:quick_charge: 3 - minecraft:soul_speed: 3 - minecraft:swift_sneak: 3 - -# Multipliers used to calculate the enchantment's value in repair/combining -# -# Values here are pulled from the minecraft wiki: -# https://minecraft.wiki/w/Anvil_mechanics#Costs_for_combining_enchantments -# -# If an enchantment is missing values here, or is less than 0, it will default to 0 -# -# Calculated as: [Enchantment lvl] * [multiplier] -# -# With default values protection 4 would have a value of 4 when -# coming from either a book (4 * 1) or an item (4 * 1) -enchant_values: - minecraft:aqua_affinity: - item: 4 - book: 2 - minecraft:bane_of_arthropods: - item: 2 - book: 1 - minecraft:binding_curse: - item: 8 - book: 4 - minecraft:blast_protection: - item: 4 - book: 2 - minecraft:channeling: - item: 8 - book: 4 - minecraft:depth_strider: - item: 4 - book: 2 - minecraft:efficiency: - item: 1 - book: 1 - minecraft:flame: - item: 4 - book: 2 - minecraft:feather_falling: - item: 2 - book: 1 - minecraft:fire_aspect: - item: 4 - book: 2 - minecraft:fire_protection: - item: 2 - book: 1 - minecraft:fortune: - item: 4 - book: 2 - minecraft:frost_walker: - item: 4 - book: 2 - minecraft:impaling: - item: 4 - book: 2 - minecraft:infinity: - item: 8 - book: 4 - minecraft:knockback: - item: 2 - book: 1 - minecraft:looting: - item: 4 - book: 2 - minecraft:loyalty: - item: 1 - book: 1 - minecraft:luck_of_the_sea: - item: 4 - book: 2 - minecraft:lure: - item: 4 - book: 2 - minecraft:mending: - item: 4 - book: 2 - minecraft:multishot: - item: 4 - book: 2 - minecraft:piercing: - item: 1 - book: 1 - minecraft:power: - item: 1 - book: 1 - minecraft:projectile_protection: - item: 2 - book: 1 - minecraft:protection: - item: 1 - book: 1 - minecraft:punch: - item: 4 - book: 2 - minecraft:quick_charge: - item: 2 - book: 1 - minecraft:respiration: - item: 4 - book: 2 - minecraft:riptide: - item: 4 - book: 2 - minecraft:silk_touch: - item: 8 - book: 4 - minecraft:sharpness: - item: 1 - book: 1 - minecraft:smite: - item: 2 - book: 1 - minecraft:soul_speed: - item: 8 - book: 4 - minecraft:swift_sneak: - item: 8 - book: 4 - minecraft:sweeping: - item: 4 - book: 2 - minecraft:sweeping_edge: - item: 4 - book: 2 - minecraft:thorns: - item: 8 - book: 4 - minecraft:unbreaking: - item: 2 - book: 1 - minecraft:vanishing_curse: - item: 8 - book: 4 - -# Disable enchantment merging for level above the set value -# Enchantment merging is when, for example, 2 unbreaking II book combine to give sharpness III -# But Enchantment above this value can still be applied. following the previous example, we could still apply a unbreaking III book to a sword -# Even if disable-merge-over of unbreaking is set to 2 -# -1 mean enchantment merge for this enchantment is not disabled. default to -1 if absent. -disable-merge-over: - # Sharpness is set to -1. it equivalent to it not being set to anything (and work as vanilla on default configuration) - minecraft:sharpness: -1 - # If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied - #minecraft:unbreaking: 2 - -# The maximum number of enchantment an item can get. -1 for infinity -# Use eco enchant enchant_limit if present by default unless "default" is not equal to -1 -enchantment_count_limit: - default: -1 - # Limit for specific items. example bellow is an example with stick - # Per item enchantment limit override eco enchant enchant_limit and default limit - items: - stick: -1 - -# Settings for lore modification -lore_edit: - book_and_quil: - # Permission is ca.lore_edit.book - use_permission: true - append: - # If adding lore using book & quil is enabled - enabled: false - # Cost used every time - fixed_cost: 1 - # Cost used for every lore line added - per_line_cost: 0 - # Use left item vanilla cost penalty if any - shared_increase: false - # Increase shared left item cost penalty - shared_additive: false - # If adding the lore consume the book & quil - do_consume: false - # Allow using color code and hexadecimal color when editing lore via book & quil - # - # Color code are prefixed by "&" and hexadecimal color by "#" - # Color code will not be applied if it colors nothing. "&&" can be used to write "&" - # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ - # - # Note that currently minimessage would disable hex code when adding color - allow_color_code: true - allow_hexadecimal_color: false - allow_minimessage: true - - remove: - # If removing lore using book & quil is enabled - enabled: false - # Cost used every time - fixed_cost: 1 - # Cost used for every lore line removed - per_line_cost: 0 - # Use left item vanilla cost penalty if any - shared_increase: false - # Increase shared left item cost penalty - shared_additive: false - # If removing the lore consume the book & quil - do_consume: false - # Cost of replacing colors - remove_color_cost: 0 - # Allowed some color and tags to be reverted to plain text - # Custom anvil will prioritise format that result is a smaller resulting text - # Note that not allowing certain format will lead to some lost of color or tags. - # If configuration are exact as append appending this book should result in the exact same color - # - # Color code will be prefixed by "&" and hexadecimal color by "#". - # If color code is allowed, "&" in the text will get converted to "&&" - # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ - allow_color_code: true - allow_hexadecimal_color: false - allow_minimessage: true - - paper: - # Permission is ca.lore_edit.paper - use_permission: true - # what order should the lines should get added/removed (start/end, if invalid or not present will be end) - order: end - - append_line: - # If adding lore line using paper is enabled - enabled: false - # Cost used every time - fixed_cost: 1 - # Use left item vanilla cost penalty if any - shared_increase: false - # Increase shared left item cost penalty - shared_additive: false - # If adding the lore line consume the paper - do_consume: false - # Allow using color code and hexadecimal color when editing lore via book & quil - # - # Color code are prefixed by "&" and hexadecimal color by "#" - # Color code will not be applied if it colors nothing. "&&" can be used to write "&" - # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ - # - # Note that currently minimessage would disable hex code when adding color - allow_color_code: true - allow_hexadecimal_color: false - allow_minimessage: true - color_use_cost: 0 - - remove_line: - # If removing lore line using paper is enabled - enabled: false - # Cost used every time - fixed_cost: 1 - # Use left item vanilla cost penalty if any - shared_increase: false - # Increase shared left item cost penalty - shared_additive: false - # If removing the lore line consume the paper - do_consume: false - # Cost of replacing colors - remove_color_cost: 0 - # Allowed some color and tags to be reverted to plain text - # Custom anvil will prioritise format that result is a smaller resulting text - # Note that not allowing certain format will lead to some lost of color or tags. - # If configuration are exact as append appending this paper should result in the exact same color - # - # Color code will be prefixed by "&" and hexadecimal color by "#". - # If color code is allowed, "&" in the text will get converted to "&&" - # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ - allow_color_code: true - allow_hexadecimal_color: false - allow_minimessage: true - -# Allow to replace the xp cost by a monetary cost -# If enabled it will not be bound to the experience level limits -# -# It also requires to enable dialog rename (set "enable_dialog_rename: false" a bit higher) -# If dialog rename permission is enabled and player do not have the permission merge will fall back to vanilla xp cost -# -# If you are using custom craft I recommend using Linear Xp Cost with Exact Linear Xp as normal Xp Cost will act "weird" -# But Linear Xp will act as 1$ time global multiplier. In other word: like you expect -# -# As this feature require dialog rename, it can only be enabled starting with paper 1.21.6 and later -monetary_cost: - enabled: false - # If using vault unlocked this allow to specify what currency should be used for anvil usage - # default being the default currency - currency: default - # multiply the anvil cost by a value to allow to have price a big bigger than like 40 - multipliers: - # global multipliers. all usage type will be multiplied by this value - global: 1.0 - # usage specific type. it will only apply for specific xp "reason" - enchantment: 1.0 # related to enchantments level - repair: 1.0 # for repairing via unit repair (per unit) - rename: 1.0 # for renaming the item - lore_edit: 1.0 # for changing the lore of the item (only if lore edit is enabled) - work_penalty: 1.0 # for work penalty (aka use penalty) - recipe: 1.0 # for custom anvil recipe cost - -# Whether to show debug logging -debug_log: false - -# Whether to show verbose debug logging -debug_log_verbose: false - -# Whether to show inside the console or require to run /ca debug get -display_debug_in_console: false - -configVersion: 1.11.0 diff --git a/defaultconfigs/1.18/custom_recipes.yml b/defaultconfigs/1.18/custom_recipes.yml deleted file mode 100644 index 57c2220c..00000000 --- a/defaultconfigs/1.18/custom_recipes.yml +++ /dev/null @@ -1,5 +0,0 @@ -# ---------------------------------------------------- -# This config file is to store custom craft -# It is recommended to use the in game config editor for this configuration. -# /customanvilconfig With ca.config.edit permission -# ---------------------------------------------------- diff --git a/defaultconfigs/1.18/enchant_conflict.yml b/defaultconfigs/1.18/enchant_conflict.yml deleted file mode 100644 index 45d62c34..00000000 --- a/defaultconfigs/1.18/enchant_conflict.yml +++ /dev/null @@ -1,247 +0,0 @@ -# -# It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! -# - -# material conflicts -# -# If you want to edit this file: -# - A conflict will apply to every item except if in one of the notAffectedGroups group -# - the conflict will count only if the user try to combine at least as -# many conflicting enchantment as "maxEnchantmentBeforeConflict" -# -# -# ---------------------------------------------------- -# These restriction are about not allowing enchantment -# on illegal items -# ---------------------------------------------------- - -restriction_aqua_affinity: - enchantments: [ minecraft:aqua_affinity ] - notAffectedGroups: [ enchanted_book, helmets ] - -restriction_bane_of_arthropods: - enchantments: [ minecraft:bane_of_arthropods ] - notAffectedGroups: [ enchanted_book, melee_weapons ] - -restriction_blast_protection: - enchantments: [ minecraft:blast_protection ] - notAffectedGroups: [ enchanted_book, armors ] - -restriction_channeling: - enchantments: [ minecraft:channeling ] - notAffectedGroups: [ enchanted_book, trident ] - -restriction_binding_curse: - enchantments: [ minecraft:binding_curse ] - notAffectedGroups: [ enchanted_book, wearable ] - -restriction_vanishing_curse: - enchantments: [ minecraft:vanishing_curse ] - notAffectedGroups: [ enchanted_book, can_vanish ] - -restriction_depth_strider: - enchantments: [ minecraft:depth_strider ] - notAffectedGroups: [ enchanted_book, boots ] - -restriction_efficiency: - enchantments: [ minecraft:efficiency ] - notAffectedGroups: [ enchanted_book, tools, shears ] - -restriction_feather_falling: - enchantments: [ minecraft:feather_falling ] - notAffectedGroups: [ enchanted_book, boots ] - -restriction_fire_aspect: - enchantments: [ minecraft:fire_aspect ] - notAffectedGroups: [ enchanted_book, swords ] - -restriction_fire_protection: - enchantments: [ minecraft:fire_protection ] - notAffectedGroups: [ enchanted_book, armors ] - -restriction_flame: - enchantments: [ minecraft:flame ] - notAffectedGroups: [ enchanted_book, bow ] - -restriction_fortune: - enchantments: [ minecraft:fortune ] - notAffectedGroups: [ enchanted_book, tools ] - -restriction_frost_walker: - enchantments: [ minecraft:frost_walker ] - notAffectedGroups: [ enchanted_book, boots ] - -restriction_impaling: - enchantments: [ minecraft:impaling ] - notAffectedGroups: [ enchanted_book, trident ] - -restriction_infinity: - enchantments: [ minecraft:infinity ] - notAffectedGroups: [ enchanted_book, bow ] - -restriction_knockback: - enchantments: [ minecraft:knockback ] - notAffectedGroups: [ enchanted_book, swords ] - -restriction_looting: - enchantments: [ minecraft:looting ] - notAffectedGroups: [ enchanted_book, swords ] - -restriction_loyalty: - enchantments: [ minecraft:loyalty ] - notAffectedGroups: [ enchanted_book, trident ] - -restriction_luck_of_the_sea: - enchantments: [ minecraft:luck_of_the_sea ] - notAffectedGroups: [ enchanted_book, fishing_rod ] - -restriction_lure: - enchantments: [ minecraft:lure ] - notAffectedGroups: [ enchanted_book, fishing_rod ] - -restriction_mending: - enchantments: [ minecraft:mending ] - notAffectedGroups: [ enchanted_book, can_unbreak ] - -restriction_minecraft_multishot: - enchantments: [ minecraft:multishot ] - notAffectedGroups: [ enchanted_book, crossbow ] - -restriction_piercing: - enchantments: [ minecraft:piercing ] - notAffectedGroups: [ enchanted_book, crossbow ] - -restriction_power: - enchantments: [ minecraft:power ] - notAffectedGroups: [ enchanted_book, bow ] - -restriction_projectile_protection: - enchantments: [ minecraft:projectile_protection ] - notAffectedGroups: [ enchanted_book, armors ] - -restriction_protection: - enchantments: [ minecraft:protection ] - notAffectedGroups: [ enchanted_book, armors ] - -restriction_punch: - enchantments: [ minecraft:punch ] - notAffectedGroups: [ enchanted_book, bow ] - -restriction_quick_charge: - enchantments: [ minecraft:quick_charge ] - notAffectedGroups: [ enchanted_book, crossbow ] - -restriction_respiration: - enchantments: [ minecraft:respiration ] - notAffectedGroups: [ enchanted_book, helmets ] - -restriction_riptide: - enchantments: [ minecraft:riptide ] - notAffectedGroups: [ enchanted_book, trident ] - -restriction_sharpness: - enchantments: [ minecraft:sharpness ] - notAffectedGroups: [ enchanted_book, melee_weapons ] - -restriction__silk_touch: - enchantments: [ minecraft:silk_touch ] - notAffectedGroups: [ enchanted_book, tools ] - -restriction_smite: - enchantments: [ minecraft:smite ] - notAffectedGroups: [ enchanted_book, melee_weapons ] - -restriction_soul_speed: - enchantments: [ minecraft:soul_speed ] - notAffectedGroups: [ enchanted_book, boots ] - -restriction_sweeping_edge: - enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ] - notAffectedGroups: [ enchanted_book, swords ] - -# Do not exist in 1.18, that mean useInFuture will be set to true -# useInFuture set to true also mean it will not warn if there is an issue -restriction_swift_sneak: - useInFuture: true - enchantments: [ minecraft:swift_sneak ] - notAffectedGroups: [ enchanted_book, leggings ] - -restriction_thorns: - enchantments: [ minecraft:thorns ] - notAffectedGroups: [ enchanted_book, armors ] - -restriction__unbreaking: - enchantments: [ minecraft:unbreaking ] - notAffectedGroups: [ enchanted_book, can_unbreak ] - -# ---------------------------------------------------- -# Now we have conflicts about enchantment Incompatibility -# We just filtered what item enchantments can be applied -# notAffectedGroups is empty as we don't want anything to not respect theses rules -# maxEnchantmentBeforeConflict is set to 1 to only have 1 on those enchantment available -# ---------------------------------------------------- - -sword_enchant_conflict: - enchantments: - - minecraft:bane_of_arthropods - - minecraft:smite - - minecraft:sharpness - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -protection_enchant_conflict: - enchantments: - - minecraft:blast_protection - - minecraft:fire_protection - - minecraft:projectile_protection - - minecraft:protection - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -trident_conflict1: - enchantments: - - minecraft:channeling - - minecraft:riptide - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -trident_conflict2: - enchantments: - - minecraft:loyalty - - minecraft:riptide - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -boot_conflict: - enchantments: - - minecraft:depth_strider - - minecraft:frost_walker - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -tool_conflict: - enchantments: - - minecraft:fortune - - minecraft:silk_touch - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -bow_conflict: - enchantments: - - minecraft:mending - - minecraft:infinity - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -crossbow_conflict: - enchantments: - - minecraft:multishot - - minecraft:piercing - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -# ---------------------------------------------------- -# Bellow is for custom conflicts. -# This is also where conflict create from the gui will be placed. -# ---------------------------------------------------- diff --git a/defaultconfigs/1.18/item_groups.yml b/defaultconfigs/1.18/item_groups.yml deleted file mode 100644 index 3c1eb5d0..00000000 --- a/defaultconfigs/1.18/item_groups.yml +++ /dev/null @@ -1,210 +0,0 @@ -# -# It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! -# - -# Please note this config use spigot material names. -# It should match minecraft name in most case, maybe every case, but I can't be sure -# In case there an issue with material name, you can found them here: -# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html - -# An empty Exclude group exclude nothing, so it contain everything -everything: - type: exclude - -# An empty include group will include nothing -nothing: - type: include - -# This group is an example of a group including only stone and polished granite -example_include: - type: include - items: - - stone - - polished_granite - -# This group contain everything except polished granite and elements of example_include -example_exclude: - type: exclude - items: - - polished_granite - groups: - - example_include - -# Default configuration should be vanilla enchantment conflict group -# there may have error, if you find one you can fix it ! -# https://minecraft.fandom.com/wiki/Enchanting - -swords: - type: include - items: - - wooden_sword - - stone_sword - - iron_sword - - diamond_sword - - golden_sword - - netherite_sword - -axes: - type: include - items: - - wooden_axe - - stone_axe - - iron_axe - - diamond_axe - - golden_axe - - netherite_axe - -melee_weapons: - type: include - groups: - - swords - - axes - -helmets: - type: include - items: - - leather_helmet - - chainmail_helmet - - iron_helmet - - diamond_helmet - - golden_helmet - - netherite_helmet - - turtle_helmet - -chestplate: - type: include - items: - - leather_chestplate - - chainmail_chestplate - - iron_chestplate - - diamond_chestplate - - golden_chestplate - - netherite_chestplate - -leggings: - type: include - items: - - leather_leggings - - chainmail_leggings - - iron_leggings - - diamond_leggings - - golden_leggings - - netherite_leggings - -boots: - type: include - items: - - leather_boots - - chainmail_boots - - iron_boots - - diamond_boots - - golden_boots - - netherite_boots - -armors: - type: include - groups: - - helmets - - chestplate - - leggings - - boots - -wearable: - type: include - items: - - elytra - - carved_pumpkin - - skeleton_skull - - wither_skeleton_skull - - zombie_head - - player_head - - creeper_head - - dragon_head - # do not exist in 1.18 but exist in future update - - piglin_head - groups: - - armors - -tools: - type: include - items: - - wooden_pickaxe - - stone_pickaxe - - iron_pickaxe - - diamond_pickaxe - - golden_pickaxe - - netherite_pickaxe - - wooden_shovel - - stone_shovel - - iron_shovel - - diamond_shovel - - golden_shovel - - netherite_shovel - - wooden_hoe - - stone_hoe - - iron_hoe - - diamond_hoe - - golden_hoe - - netherite_hoe - groups: - - axes - -enchanted_book: - type: include - items: - - enchanted_book - -trident: - type: include - items: - - trident - -bow: - type: include - items: - - bow - -crossbow: - type: include - items: - - crossbow - -fishing_rod: - type: include - items: - - fishing_rod - -shears: - type: include - items: - - shears - -can_unbreak: - type: include - items: - - elytra - - flint_and_steel - - shield - - carrot_on_a_stick - - warped_fungus_on_a_stick - # do not exist in 1.18 but exist in future update - - brush - groups: - - melee_weapons - - tools - - armors - - trident - - bow - - crossbow - - fishing_rod - - shears - -can_vanish: - type: include - items: - - compass - groups: - - wearable - - can_unbreak - diff --git a/defaultconfigs/1.18/unit_repair_item.yml b/defaultconfigs/1.18/unit_repair_item.yml deleted file mode 100644 index 2902cce4..00000000 --- a/defaultconfigs/1.18/unit_repair_item.yml +++ /dev/null @@ -1,190 +0,0 @@ -# -# It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! -# - -# Unit repair configuration -# -# This configuration is to make custom unit repair -# A unit repair is, for example, a diamond to repair a diamond sword -# In vanilla, a unit repair 25% of object durability -# you can make a custom value here -# -# Item name should NOT combine caps and no caps (example: Stone) - -# Default value if the config is an invalid value (value <= 0 ) -# If value > 1 it will be treated as being = 1 -default_repair_amount: 0.25 - -# You can add custom unit repair -# The example bellow make a shield repaired by 10% by sticks - -#stick: -# shield: 0.10 - - -# Vanilla unit repair group is bellow -diamond: - diamond_helmet: 0.25 - diamond_chestplate: 0.25 - diamond_leggings: 0.25 - diamond_boots: 0.25 - diamond_sword: 0.25 - diamond_pickaxe: 0.25 - diamond_axe: 0.25 - diamond_shovel: 0.25 - diamond_hoe: 0.25 - -netherite_ingot: - netherite_helmet: 0.25 - netherite_chestplate: 0.25 - netherite_leggings: 0.25 - netherite_boots: 0.25 - netherite_sword: 0.25 - netherite_pickaxe: 0.25 - netherite_axe: 0.25 - netherite_shovel: 0.25 - netherite_hoe: 0.25 - -gold_ingot: - golden_helmet: 0.25 - golden_chestplate: 0.25 - golden_leggings: 0.25 - golden_boots: 0.25 - golden_sword: 0.25 - golden_pickaxe: 0.25 - golden_axe: 0.25 - golden_shovel: 0.25 - golden_hoe: 0.25 - -iron_ingot: - iron_helmet: 0.25 - iron_chestplate: 0.25 - iron_leggings: 0.25 - iron_boots: 0.25 - iron_sword: 0.25 - iron_pickaxe: 0.25 - iron_axe: 0.25 - iron_shovel: 0.25 - iron_hoe: 0.25 - -cobblestone: - stone_sword: 0.25 - stone_pickaxe: 0.25 - stone_axe: 0.25 - stone_shovel: 0.25 - stone_hoe: 0.25 - -cobbled_deepslate: - stone_sword: 0.25 - stone_pickaxe: 0.25 - stone_axe: 0.25 - stone_shovel: 0.25 - stone_hoe: 0.25 - -blackstone: - stone_sword: 0.25 - stone_pickaxe: 0.25 - stone_axe: 0.25 - stone_shovel: 0.25 - stone_hoe: 0.25 - -leather: - leather_helmet: 0.25 - leather_chestplate: 0.25 - leather_leggings: 0.25 - leather_boots: 0.25 - -phantom_membrane: - elytra: 0.25 - -scute: - turtle_helmet: 0.25 - -oak_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -spruce_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -birch_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -jungle_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -acacia_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -dark_oak_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -mangrove_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -cherry_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -bamboo_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -crimson_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -warped_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 diff --git a/defaultconfigs/README.md b/defaultconfigs/README.md index daa20882..e4f40d22 100644 --- a/defaultconfigs/README.md +++ b/defaultconfigs/README.md @@ -1,5 +1,4 @@ ### Default Plugin's Configurations -From 1.18 to 1.20.6 use [1.18 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.18) \ From 1.21 to 1.21.8 use [1.21 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21) \ From 1.21.9 to 1.21.10 use [1.21.9 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21.9) \ From 1.21.11 use [1.21.11 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21.11) diff --git a/impl/LegacyEcoEnchant/build.gradle.kts b/impl/LegacyEcoEnchant/build.gradle.kts index 83057a73..3c3f1aeb 100644 --- a/impl/LegacyEcoEnchant/build.gradle.kts +++ b/impl/LegacyEcoEnchant/build.gradle.kts @@ -8,6 +8,6 @@ plugins { // Imitate needed class and method to support legacy version of EcoEnchant dependencies { // Spigot api - compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/nms/nms-common/build.gradle.kts b/nms/nms-common/build.gradle.kts index 950d8072..46f684d7 100644 --- a/nms/nms-common/build.gradle.kts +++ b/nms/nms-common/build.gradle.kts @@ -21,8 +21,8 @@ repositories { // Set target version tasks.withType().configureEach { - sourceCompatibility = "16" - targetCompatibility = "16" + sourceCompatibility = "21" + targetCompatibility = "21" options.encoding = "UTF-8" } @@ -30,6 +30,6 @@ tasks.withType().configureEach { kotlin { compilerOptions { apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_16) + jvmTarget.set(JvmTarget.JVM_21) } } diff --git a/nms/nms-paper/build.gradle.kts b/nms/nms-paper/build.gradle.kts index d0e12a76..19033be7 100644 --- a/nms/nms-paper/build.gradle.kts +++ b/nms/nms-paper/build.gradle.kts @@ -21,8 +21,8 @@ repositories { // Set target version tasks.withType().configureEach { - sourceCompatibility = "18" - targetCompatibility = "18" + sourceCompatibility = "21" + targetCompatibility = "21" options.encoding = "UTF-8" } @@ -30,6 +30,6 @@ tasks.withType().configureEach { kotlin { compilerOptions { apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_18) + jvmTarget.set(JvmTarget.JVM_21) } } diff --git a/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/datapack/DataPackTester.kt b/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/datapack/DataPackTester.kt index 9003fdf4..221dd2fa 100644 --- a/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/datapack/DataPackTester.kt +++ b/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/datapack/DataPackTester.kt @@ -2,37 +2,19 @@ package xyz.alexcrea.cuanvil.dependency.datapack import io.papermc.paper.datapack.Datapack import org.bukkit.Bukkit -import org.bukkit.packs.DataPack import java.util.* object DataPackTester { - val legacyNames: List - get() = Bukkit.getDataPackManager().dataPacks - .stream().filter { obj -> obj.isEnabled } - .map { pack -> pack.key.key } - .toList() val enabledPacks: List get() { - try { - // will throw error if do not exist - Bukkit::class.java.getDeclaredMethod("getDatapackManager") - - return Bukkit.getDatapackManager().enabledPacks + return try { + Bukkit.getDatapackManager().enabledPacks .stream().map { obj: Datapack -> obj.name } .toList() - } catch (e: NoSuchMethodException) { - try { - DataPack::class.java.getDeclaredMethod("getKey") - } catch (e: NoSuchMethodException) { - System.err.println("Could not find compatible datapack manager") - System.err.println("If you are using a datapack that should be compatible with CustomAnvil. It will not get detected...") - return emptyList() - } - return legacyNames - } catch (e: Exception){ + } catch (_: Exception){ // Assume cause UnimplementedOperationException on mock server - return Collections.emptyList() + Collections.emptyList() } } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentRarity.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentRarity.java index 3718f39b..7ad3269e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentRarity.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentRarity.java @@ -1,6 +1,6 @@ package xyz.alexcrea.cuanvil.enchant; -// because spigot (1.18) do not look like to provide access to enchantment rarity I need to do it myself... +// because spigot (1.21) do not look like to provide access to enchantment rarity I need to do it myself... public class EnchantmentRarity { public static final EnchantmentRarity NO_RARITY = new EnchantmentRarity(0, 0); diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt index e4e197ee..f0775241 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.command -import com.github.stefvanschie.inventoryframework.inventoryview.interface_.InventoryViewUtil import io.delilaheve.CustomAnvil import net.md_5.bungee.api.chat.ClickEvent import net.md_5.bungee.api.chat.HoverEvent @@ -16,8 +15,6 @@ import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryType import org.bukkit.event.inventory.PrepareAnvilEvent -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Damageable import org.bukkit.inventory.meta.EnchantmentStorageMeta @@ -263,7 +260,7 @@ class DiagnosticExecutor: CASubCommand() { } fun simulateAnvil(player: Player, stb: StringBuilder, left: ItemStack?, right: ItemStack?, result: ItemStack?) { - var invView: InventoryView + var invView: AnvilView var event: PrepareAnvilEvent try { val fakeInv = Bukkit.createInventory(player, InventoryType.ANVIL) @@ -275,42 +272,40 @@ class DiagnosticExecutor: CASubCommand() { val anvilTypeField = menuTypeClazz.getField("ANVIL") val anvilType = anvilTypeField.get(null) val createMethod = anvilType.javaClass.getMethod("create", HumanEntity::class.java) - invView = createMethod.invoke(anvilType, player) as InventoryView + invView = createMethod.invoke(anvilType, player) as AnvilView player.openInventory(invView) - val anvilViewClass = Class.forName("org.bukkit.inventory.view.AnvilView") - val constructor = PrepareAnvilEvent::class.java.getConstructor(anvilViewClass, ItemStack::class.java) + val constructor = PrepareAnvilEvent::class.java.getConstructor(AnvilView::class.java, ItemStack::class.java) event = constructor.newInstance(invView, result) } - val fakeInv = InventoryViewUtil.getInstance().getTopInventory(invView) as AnvilInventory - fakeInv.setItem(0, left) - fakeInv.setItem(1, right) + invView.setItem(0, left) + invView.setItem(1, right) - val xp = fakeInv.repairCost - val maxXp = fakeInv.maximumRepairCost - val mergeResult = fakeInv.getItem(2) + val xp = invView.repairCost + val maxXp = invView.maximumRepairCost + val mergeResult = invView.getItem(2) stb.append("\n${if(result == mergeResult) "E" else "Une"}xpected Result") PrepareAnvilListener().anvilCombineCheck(event) // Now we check if item and xp same stb.append("\nXP/Max XP: ") - .append(if(fakeInv.repairCost == xp) "Correct" else "Incorrect") + .append(if(invView.repairCost == xp) "Correct" else "Incorrect") .append("/") - .append(if(fakeInv.maximumRepairCost == maxXp) "Correct" else "Incorrect") - .append(" (${fakeInv.repairCost} $xp|${fakeInv.maximumRepairCost} $maxXp)") + .append(if(invView.maximumRepairCost == maxXp) "Correct" else "Incorrect") + .append(" (${invView.repairCost} $xp|${invView.maximumRepairCost} $maxXp)") .append("\nMerge result: ") - .append(if(fakeInv.getItem(2) == mergeResult) "Correct" else "Incorrect") + .append(if(invView.getItem(2) == mergeResult) "Correct" else "Incorrect") PrepareAnvilListener.IS_EMPTY_TEST = true Bukkit.getPluginManager().callEvent(event) stb.append("\nNull result test: ") .append(if(event.result == null) "Correct" else "Incorrect") - fakeInv.setItem(0, null) - fakeInv.setItem(1, null) - fakeInv.setItem(2, null) + invView.setItem(0, null) + invView.setItem(1, null) + invView.setItem(2, null) player.closeInventory() } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index b730a0ee..6a6950cc 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -15,6 +15,7 @@ import org.bukkit.inventory.Inventory import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import xyz.alexcrea.cuanvil.anvil.AnvilCost +import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.anvil.AnvilUseType import xyz.alexcrea.cuanvil.api.event.listener.CAClickResultBypassEvent import xyz.alexcrea.cuanvil.api.event.listener.CAEarlyPreAnvilBypassEvent @@ -164,9 +165,9 @@ object DependencyManager { ) } - private fun logExceptionAndClear(target: CommandSender, inventory: Inventory, e: Exception) { + private fun logExceptionAndClear(target: CommandSender, view: AnvilView, e: Exception) { // Just in case to avoid illegal items - inventory.setItem(ANVIL_OUTPUT_SLOT, null) + view.setItem(ANVIL_OUTPUT_SLOT, null) logException(target, e) } @@ -177,7 +178,7 @@ object DependencyManager { try { return earlyUnsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.inventory, e) + logExceptionAndClear(event.view.player, event.view, e) return true } } @@ -203,7 +204,7 @@ object DependencyManager { try { return unsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.inventory, e) + logExceptionAndClear(event.view.player, event.view, e) return true } } @@ -257,16 +258,16 @@ object DependencyManager { } // Return true if should bypass (either by a dependency or error) - fun tryClickAnvilResultBypass(event: InventoryClickEvent, inventory: AnvilInventory): Boolean { + fun tryClickAnvilResultBypass(event: InventoryClickEvent, view: AnvilView): Boolean { try { - return unsafeTryClickAnvilResultBypass(event, inventory) + return unsafeTryClickAnvilResultBypass(event, view) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.inventory, e) + logExceptionAndClear(event.view.player, event.view, e) return true } } - private fun unsafeTryClickAnvilResultBypass(event: InventoryClickEvent, inventory: AnvilInventory): Boolean { + private fun unsafeTryClickAnvilResultBypass(event: InventoryClickEvent, view: AnvilView): Boolean { // Run the event val bypassEvent = CAClickResultBypassEvent(event) Bukkit.getPluginManager().callEvent(bypassEvent) @@ -274,10 +275,10 @@ object DependencyManager { var bypass = bypassEvent.isCancelled // Test if disenchantment used event click - if (!bypass && (disenchantmentCompatibility?.testAnvilResult(event, inventory) == true)) bypass = true + if (!bypass && (disenchantmentCompatibility?.testAnvilResult(event, view) == true)) bypass = true // Test if haven bag used event click - if (!bypass && (havenBagsCompatibility?.testAnvilResult(event, inventory) == true)) bypass = true + if (!bypass && (havenBagsCompatibility?.testAnvilResult(event, view) == true)) bypass = true // Test if disenchantment used event click if (!bypass && (excellentEnchantsCompatibility?.testAnvilResult(event) == true)) bypass = true @@ -287,10 +288,10 @@ object DependencyManager { } // Test if the inventory is a gui(version specific) - if (!bypass && externGuiTester.testIfGui(event.view)) bypass = true + if (!bypass && externGuiTester.testIfGui(view)) bypass = true // Test if in an ax player warp rating gui - if (!bypass && (axPlayerWarpsCompatibility?.testIfGui(event.view.player) == true)) bypass = true + if (!bypass && (axPlayerWarpsCompatibility?.testIfGui(view.player) == true)) bypass = true return bypass } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt index cbd22095..3e9f2ac4 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt @@ -10,32 +10,6 @@ object MinecraftVersionUtil { if (version.major != 1) return null return when (version.minor) { - 17 -> when (version.patch) { - 0, 1 -> "1_17R1" - else -> null - } - - 18 -> when (version.patch) { - 0, 1 -> "1_18R1" - 2 -> "1_18R2" - else -> null - } - - 19 -> when (version.patch) { - 0, 1, 2 -> "1_19R1" - 3 -> "1_19R2" - 4 -> "1_19R3" - else -> null - } - - 20 -> when (version.patch) { - 0, 1 -> "1_20R1" - 2 -> "1_20R2" - 3, 4 -> "1_20R3" - 5, 6 -> "1_20R4" - else -> null - } - 21 -> when (version.patch) { 0, 1 -> "1_21R1" 2, 3 -> "1_21R2" @@ -46,6 +20,7 @@ object MinecraftVersionUtil { 11 -> "1_21R7" else -> null } + //TODO need to continue updating that for anvil gui test dependency.... else -> null } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt index 690b3846..8b9e78ef 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt @@ -12,8 +12,8 @@ import org.bukkit.entity.Player import org.bukkit.event.Listener import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.PrepareAnvilEvent -import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.anvil.AnvilCost import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError @@ -59,14 +59,14 @@ class DisenchantmentDependency { DisenchantEvent.onEvent(event) if (event.result != null) { CustomAnvil.log("Detected pre anvil item extract bypass.") - AnvilXpUtil.setAnvilInvCost(event.inventory, event.view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(event.view, player, AnvilCost(event.view.repairCost)) return true } ShatterEvent.onEvent(event) if (event.result != null) { CustomAnvil.log("Detected pre anvil split enchant bypass.") - AnvilXpUtil.setAnvilInvCost(event.inventory, event.view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(event.view, player, AnvilCost(event.view.repairCost)) return true } @@ -74,18 +74,18 @@ class DisenchantmentDependency { return false } - fun testAnvilResult(event: InventoryClickEvent, inventory: AnvilInventory): Boolean { - val previousResultSlot = inventory.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)?.clone() + fun testAnvilResult(event: InventoryClickEvent, view: AnvilView): Boolean { + val previousResultSlot = view.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)?.clone() // Test event if change the result DisenchantClickEvent.onEvent(event) - if (!testAnvilInventoryChange(inventory, previousResultSlot) || event.isCancelled) { + if (!testAnvilChange(view, previousResultSlot) || event.isCancelled) { CustomAnvil.log("Detected anvil click item extract bypass.") return true } ShatterClickEvent.onEvent(event) - if (!testAnvilInventoryChange(inventory, previousResultSlot) || event.isCancelled) { + if (!testAnvilChange(view, previousResultSlot) || event.isCancelled) { CustomAnvil.log("Detected anvil click split enchant bypass.") return true } @@ -93,8 +93,8 @@ class DisenchantmentDependency { return false } - private fun testAnvilInventoryChange(inventory: AnvilInventory, previous: ItemStack?): Boolean { - val currentResult = inventory.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT) + private fun testAnvilChange(view: AnvilView, previous: ItemStack?): Boolean { + val currentResult = view.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT) return currentResult == previous } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt index 6f304973..b9c3ce68 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt @@ -4,7 +4,7 @@ import io.delilaheve.CustomAnvil import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.PrepareAnvilEvent -import org.bukkit.inventory.AnvilInventory +import org.bukkit.inventory.view.AnvilView import org.bukkit.plugin.RegisteredListener import valorless.havenbags.HavenBags import valorless.havenbags.features.BagSkin @@ -54,14 +54,14 @@ class HavenBagsDependency { bagSkin.onPrepareAnvil(event) if (event.result != null) { CustomAnvil.log("Detected pre anvil heaven bag anvil skin.") - AnvilXpUtil.setAnvilInvCost(event.inventory, event.view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(event.view, player, AnvilCost(event.view.repairCost)) return true } bagUpgrade.onPrepareAnvil(event) if (event.result != null) { CustomAnvil.log("Detected pre anvil heaven bag anvil upgrade.") - AnvilXpUtil.setAnvilInvCost(event.inventory, event.view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(event.view, player, AnvilCost(event.view.repairCost)) return true } @@ -69,8 +69,8 @@ class HavenBagsDependency { return false } - fun testAnvilResult(event: InventoryClickEvent, inventory: AnvilInventory): Boolean { - val result = inventory.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)?.clone() + fun testAnvilResult(event: InventoryClickEvent, view: AnvilView): Boolean { + val result = view.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)?.clone() if (HavenBags.IsBag(result)) { CustomAnvil.log("Detected anvil click haven bag bypass.") diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt index d707b562..85b9414e 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt @@ -5,7 +5,7 @@ import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.inventory.InventoryCloseEvent -import org.bukkit.inventory.AnvilInventory +import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.dependency.packet.PacketManager import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil @@ -14,7 +14,7 @@ class AnvilCloseListener(private val packetManager: PacketManager) : Listener { @EventHandler fun onAnvilClose(event: InventoryCloseEvent){ val player = event.player - if(event.inventory !is AnvilInventory) return + if(event.view !is AnvilView) return if(player is Player && GameMode.CREATIVE != player.gameMode){ packetManager.setInstantBuild(player, false) } diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml index 45d62c34..479273ee 100644 --- a/src/main/resources/enchant_conflict.yml +++ b/src/main/resources/enchant_conflict.yml @@ -160,10 +160,7 @@ restriction_sweeping_edge: enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ] notAffectedGroups: [ enchanted_book, swords ] -# Do not exist in 1.18, that mean useInFuture will be set to true -# useInFuture set to true also mean it will not warn if there is an issue restriction_swift_sneak: - useInFuture: true enchantments: [ minecraft:swift_sneak ] notAffectedGroups: [ enchanted_book, leggings ] diff --git a/src/main/resources/item_groups.yml b/src/main/resources/item_groups.yml index 8a62f3dc..0f3cd06f 100644 --- a/src/main/resources/item_groups.yml +++ b/src/main/resources/item_groups.yml @@ -121,7 +121,6 @@ wearable: - player_head - creeper_head - dragon_head - # do not exist in 1.18 but exist in future update - piglin_head groups: - armors diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index dab9997b..9ee330f5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ prefix: "Custom Anvil" version: ${version} folia-supported: true description: Allow to customise anvil mechanics -api-version: 1.16 +api-version: 1.21 load: POSTWORLD authors: [ DelilahEve, alexcrea ] libraries: [${libraries}] From 4e8acef7c35aa7253eefa572bfd4ab4865813f41 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Sat, 23 May 2026 18:30:14 +0200 Subject: [PATCH 03/41] fix from rebase --- src/main/kotlin/io/delilaheve/util/ItemUtil.kt | 11 +---------- .../cuanvil/dependency/DependencyManager.kt | 13 ++++++------- .../dependency/plugins/SuperEnchantDependency.kt | 8 +++++++- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/util/ItemUtil.kt b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt index bf075231..4ed9753a 100644 --- a/src/main/kotlin/io/delilaheve/util/ItemUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt @@ -4,9 +4,7 @@ import org.bukkit.Material.ENCHANTED_BOOK import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Damageable import xyz.alexcrea.cuanvil.enchant.CAEnchantment -import xyz.alexcrea.cuanvil.update.UpdateUtils import xyz.alexcrea.cuanvil.util.MaterialUtil.customType -import xyz.alexcrea.cuanvil.util.MaxDamageCheckerUtil import kotlin.math.ceil import kotlin.math.max import kotlin.math.min @@ -21,13 +19,6 @@ object ItemUtil { */ fun ItemStack.isEnchantedBook() = type == ENCHANTED_BOOK - private fun maxDamage(damageable: Damageable): Int { - val ver = UpdateUtils.currentMinecraftVersion() - if(ver.major <= 1 && ver.minor <= 20 && ver.patch < 5) return Integer.MAX_VALUE - - return MaxDamageCheckerUtil.getMaxDamage(damageable) - } - /** * Set this [ItemStack]s durability from a combination of the * [first] and [second] item's durability values @@ -47,8 +38,8 @@ object ItemUtil { val secondDurability = durability - secondDamage val combinedDurability = firstDurability + secondDurability val newDurability = min(combinedDurability, durability) + val maxDamage = if(it.hasMaxDamage()) it.maxDamage else Int.MAX_VALUE - val maxDamage = maxDamage(it) it.damage = min(durability - newDurability, maxDamage) itemMeta = it return true diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index 6a6950cc..a76c4a79 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.dependency -import com.maddoxh.superEnchants.SuperEnchants import io.delilaheve.CustomAnvil import net.kyori.adventure.text.Component import org.bukkit.Bukkit @@ -118,7 +117,7 @@ object DependencyManager { genericDependencies.add(GenericPluginDependency(pluginManager.getPlugin("ItemsAdder")!!)) if (pluginManager.isPluginEnabled("SuperEnchants")){ - val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!! as SuperEnchants) + val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!!) if(compatibility.registerEnchantments()) genericDependencies.add(compatibility) } @@ -165,11 +164,11 @@ object DependencyManager { ) } - private fun logExceptionAndClear(target: CommandSender, view: AnvilView, e: Exception) { + private fun logExceptionAndClear(view: AnvilView, e: Exception) { // Just in case to avoid illegal items view.setItem(ANVIL_OUTPUT_SLOT, null) - logException(target, e) + logException(view.player, e) } // Return true if should bypass (either by a dependency or error) @@ -178,7 +177,7 @@ object DependencyManager { try { return earlyUnsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.view, e) + logExceptionAndClear(event.view, e) return true } } @@ -204,7 +203,7 @@ object DependencyManager { try { return unsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.view, e) + logExceptionAndClear(event.view, e) return true } } @@ -262,7 +261,7 @@ object DependencyManager { try { return unsafeTryClickAnvilResultBypass(event, view) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.view, e) + logExceptionAndClear(view, e) return true } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt index 11622f92..8676b4cd 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt @@ -8,17 +8,23 @@ import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.plugin.Plugin import org.bukkit.plugin.RegisteredListener import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.enchant.bulk.SuperEnchantBulkOperation import xyz.alexcrea.cuanvil.enchant.wrapped.CASuperEnchantEnchantment import java.util.logging.Level -class SuperEnchantDependency(override val plugin: SuperEnchants): GenericPluginDependency(plugin, false) { +class SuperEnchantDependency: GenericPluginDependency { + override val plugin: SuperEnchants lateinit var enchManager: EnchantManager val enchantments = ArrayList() + constructor(plugin: Plugin) : super(plugin) { + this.plugin = plugin as SuperEnchants + } + fun registerEnchantments(): Boolean{ CustomAnvil.instance.logger.info("Preparing Super Enchant compatibility...") From 9acf9a62d26b380620be354d75a83fcbf16b421a Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 3 Jun 2026 17:53:17 +0200 Subject: [PATCH 04/41] 1.21 cleanup and fix also random cleanup --- .../alexcrea/cuanvil/anvil/AnvilMergeLogic.kt | 12 ++- .../alexcrea/cuanvil/command/CASubCommand.kt | 16 +-- .../cuanvil/command/CustomAnvilCommand.kt | 19 ++-- .../cuanvil/command/DiagnosticExecutor.kt | 63 ++++++------ .../cuanvil/command/EditConfigExecutor.kt | 14 +-- .../alexcrea/cuanvil/command/HelpExecutor.kt | 14 +-- .../cuanvil/command/ReloadExecutor.kt | 11 ++- .../cuanvil/dependency/DependencyManager.kt | 9 +- .../dependency/MinecraftVersionUtil.kt | 8 +- .../dependency/gui/GenericExternGuiTester.kt | 4 +- .../packet/PacketManagerSelector.kt | 2 +- .../plugins/DisenchantmentDependency.kt | 1 + .../plugins/EnchantmentSquaredDependency.kt | 34 ++++--- .../plugins/ExcellentEnchantsDependency.kt | 6 +- .../plugins/GenericPluginDependency.kt | 9 +- .../dependency/plugins/HavenBagsDependency.kt | 1 + .../plugins/ItemsAdderDependency.kt | 8 +- .../plugins/SuperEnchantDependency.kt | 8 +- .../dependency/plugins/ToolStatsDependency.kt | 1 - .../cuanvil/group/EnchantConflictGroup.kt | 15 +-- .../cuanvil/group/EnchantConflictManager.kt | 1 - .../alexcrea/cuanvil/group/ExcludeGroup.kt | 1 - .../alexcrea/cuanvil/group/IncludeGroup.kt | 2 - .../cuanvil/group/ItemGroupManager.kt | 11 +-- .../cuanvil/group/NegativeMaterialSet.kt | 2 +- .../cuanvil/listener/AnvilCloseListener.kt | 7 +- .../cuanvil/listener/AnvilResultListener.kt | 98 +++++++++---------- .../cuanvil/listener/ChatEventListener.kt | 7 +- .../cuanvil/listener/PrepareAnvilListener.kt | 28 +++--- .../xyz/alexcrea/cuanvil/util/MaterialUtil.kt | 1 - .../cuanvil/util/anvil/AnvilXpUtil.kt | 37 +++---- 31 files changed, 231 insertions(+), 219 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt index fd7055ed..80f8f053 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt @@ -14,6 +14,7 @@ import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.ItemMeta +import org.bukkit.inventory.view.AnvilView import org.bukkit.persistence.PersistentDataType import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.dependency.DependencyManager @@ -31,6 +32,7 @@ import xyz.alexcrea.cuanvil.util.anvil.AnvilXpUtil import xyz.alexcrea.cuanvil.util.config.LoreEditType import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil +@Suppress("UnstableApiUsage") object AnvilMergeLogic { open class AnvilResult { @@ -103,7 +105,7 @@ object AnvilMergeLogic { ): AnvilResult { val resultItem = DependencyManager.cloneItem(player, first) val cost = AnvilCost() - cost.rename = handleRename(resultItem, inventory, player) + cost.rename = handleRename(resultItem, view, player) // Test/stop if nothing changed. if (first == resultItem) { @@ -136,9 +138,9 @@ object AnvilMergeLogic { } } - private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory, player: HumanEntity): Int { + private fun handleRename(resultItem: ItemStack, view: AnvilView, player: HumanEntity): Int { // Can be null - var renameText = ChatColor.stripColor(inventory.renameText) + var renameText = ChatColor.stripColor(view.renameText) var sumCost = 0 var useColor = false @@ -219,7 +221,7 @@ object AnvilMergeLogic { // As calculatePenalty edit result, we need to calculate penalty after checking equality cost.workPenalty = AnvilXpUtil.calculatePenalty(first, second, resultItem, AnvilUseType.MERGE) // Calculate rename cost - cost.rename = handleRename(resultItem, inventory, player) + cost.rename = handleRename(resultItem, view, player) val result = DependencyManager.tryTreatAnvilResult(view, inventory, player, resultItem, AnvilUseType.MERGE, cost) @@ -288,7 +290,7 @@ object AnvilMergeLogic { ): UnitRepairResult { val resultItem = DependencyManager.cloneItem(player, first) val cost = AnvilCost() - cost.rename = handleRename(resultItem, inventory, player) + cost.rename = handleRename(resultItem, view, player) val repairAmount = resultItem.unitRepair(second.amount, unitRepairAmount) if (repairAmount > 0) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt index 4c71c68b..5df484ee 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt @@ -5,7 +5,7 @@ import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender -abstract class CASubCommand: CommandExecutor { +abstract class CASubCommand : CommandExecutor { private var alreadySaid = false; override fun onCommand( @@ -14,9 +14,11 @@ abstract class CASubCommand: CommandExecutor { cmdstr: String, args: Array ): Boolean { - if(!alreadySaid){ - sender.sendMessage(ChatColor.RED.toString() + - "Please not that this command will be replaced as a subcommand of `/customanvil` or `/ca`") + if (!alreadySaid) { + sender.sendMessage( + ChatColor.RED.toString() + + "Please not that this command will be replaced as a subcommand of `/customanvil` or `/ca`" + ) alreadySaid = true } @@ -27,7 +29,8 @@ abstract class CASubCommand: CommandExecutor { sender: CommandSender, cmd: Command, cmdstr: String, - args: Array): Boolean + args: Array + ): Boolean open fun allowed(sender: CommandSender): Boolean { return true @@ -36,7 +39,8 @@ abstract class CASubCommand: CommandExecutor { open fun tabCompleter( sender: CommandSender, args: Array, - list: MutableList) { + list: MutableList + ) { } open fun description(): String { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt index 8bd1d827..ca635a03 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt @@ -7,7 +7,6 @@ import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import org.bukkit.command.TabCompleter import xyz.alexcrea.cuanvil.util.MetricsUtil -import java.util.ArrayList class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { @@ -43,15 +42,15 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { // Find sub command to execute based on the provided command name val subcmd: CASubCommand? val newargs: Array - if(args.isEmpty()) { + if (args.isEmpty()) { subcmd = editConfigCommand newargs = args - }else { + } else { subcmd = commands[args[0].lowercase()] newargs = args.copyOfRange(1, args.size) } - if(subcmd == null || !subcmd.allowed(sender)) { + if (subcmd == null || !subcmd.allowed(sender)) { sender.sendMessage("Invalid subcommand. run `$cmdstr help` to see available commands") return true } @@ -72,17 +71,17 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { args: Array ): MutableList { val result = ArrayList() - if(args.size < 2) { - for ((key, cmd) in commands) { - if(!cmd.allowed(sender)) continue - result.add(key) + if (args.size < 2) { + for ((key, cmd) in commands) { + if (!cmd.allowed(sender)) continue + result.add(key) } } else { val subcmd = commands[args[0].lowercase()] - if(subcmd != null) { + if (subcmd != null) { val newArgs = args.copyOfRange(1, args.size) - if(!subcmd.allowed(sender)) return result + if (!subcmd.allowed(sender)) return result subcmd.tabCompleter(sender, newArgs, result) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt index f0775241..b7bb1dd9 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt @@ -31,9 +31,9 @@ import java.util.* import java.util.stream.Collectors -class DiagnosticExecutor: CASubCommand() { +class DiagnosticExecutor : CASubCommand() { - companion object{ + companion object { const val NO_DIAG_PERM = "You do not have permission to diagnostic this server" fun fetchNMSType(): String { @@ -41,7 +41,7 @@ class DiagnosticExecutor: CASubCommand() { val packetManagerClass = packetManager.javaClass val className = packetManagerClass.name - val result = if(className.contains("PaperPacket")) { + val result = if (className.contains("PaperPacket")) { "Paper" } else { when (packetManagerClass) { @@ -52,7 +52,7 @@ class DiagnosticExecutor: CASubCommand() { } - return "$result ${if(packetManager.canSetInstantBuild) '✅' else '❌'}" + return "$result ${if (packetManager.canSetInstantBuild) '✅' else '❌'}" } } @@ -73,7 +73,7 @@ class DiagnosticExecutor: CASubCommand() { } for (param in DiagParams.entries) { - if(argSet.contains(param.value)) + if (argSet.contains(param.value)) result.add(param) } @@ -83,12 +83,13 @@ class DiagnosticExecutor: CASubCommand() { override fun tabCompleter( sender: CommandSender, args: Array, - list: MutableList) { - if(!allowed(sender)) return + list: MutableList + ) { + if (!allowed(sender)) return val map = fetchParameters(args) for (param in DiagParams.entries) { - if(!map.contains(param)) + if (!map.contains(param)) list.add(param.value) } @@ -110,7 +111,7 @@ class DiagnosticExecutor: CASubCommand() { var hasError = false try { diagnostic(sender, stb, params) - } catch(e: Throwable){ + } catch (e: Throwable) { stb.append("\n\nError happened trying to get diagnostic data:\n") .append(e.message).append("\n") .append(e.stackTrace.joinToString("\n")) @@ -121,8 +122,9 @@ class DiagnosticExecutor: CASubCommand() { stb.append("\n```") if (sender is HumanEntity) { - if(hasError) - sender.spigot().sendMessage(TextComponent(ChatColor.RED.toString() + "There was an error running the diagnostic")) + if (hasError) + sender.spigot() + .sendMessage(TextComponent(ChatColor.RED.toString() + "There was an error running the diagnostic")) val message = TextComponent(ChatColor.GREEN.toString() + "Click to copy diagnostic data") message.clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stb.toString()) @@ -140,41 +142,41 @@ class DiagnosticExecutor: CASubCommand() { return sender.hasPermission(CustomAnvil.diagnosticPermission) } - fun diagnostic(sender: CommandSender, stb: StringBuilder, params: Set){ + fun diagnostic(sender: CommandSender, stb: StringBuilder, params: Set) { stb.append("Server Info\n") val version = CustomAnvil.instance.description.version stb.append("\nPlugin Version: ").append(version) - if(version.contains("dev")) stb.append(" (alpha)") + if (version.contains("dev")) stb.append(" (alpha)") stb.append("\nLatest Update: ").append(CustomAnvil.latestVer) stb.append("\nServer Version: ").append(Bukkit.getVersion()).append(" (").append(Bukkit.getName()).append(')') - stb.append("\nPlugin Enabled: ").append(if(CustomAnvil.instance.isEnabled) "Yes" else "No") + stb.append("\nPlugin Enabled: ").append(if (CustomAnvil.instance.isEnabled) "Yes" else "No") stb.append("\nNMS type: ").append(fetchNMSType()) - if(!params.contains(DiagParams.OS_PRIVACY)) { + if (!params.contains(DiagParams.OS_PRIVACY)) { stb.append("\nJava Version: ").append(System.getProperty("java.version")) stb.append("\nOS: ").append(System.getProperty("os.name")).append(" ") .append(System.getProperty("os.version")) .append(System.getProperty("os.arch")) } - stb.append("\nHad detect error: ").append(if(MetricsUtil.lastError != null) "Yes" else "No") + stb.append("\nHad detect error: ").append(if (MetricsUtil.lastError != null) "Yes" else "No") - if(!params.contains(DiagParams.PLUGIN_PRIVACY)) { + if (!params.contains(DiagParams.PLUGIN_PRIVACY)) { pluginListDiag(sender, stb) } prepareAnvilListeners(stb) - if(!params.contains(DiagParams.NO_MERGE_TEST)){ - if(sender is Player) testMerge(sender, stb) + if (!params.contains(DiagParams.NO_MERGE_TEST)) { + if (sender is Player) testMerge(sender, stb) } stb.append("\n\nEnchantments data:") partialEnchantmentData(stb) - if(params.contains(DiagParams.FULL_ENCHANTMENT_DATA)){ + if (params.contains(DiagParams.FULL_ENCHANTMENT_DATA)) { fullEnchantmentData(stb) } - if(params.contains(DiagParams.INCLUDE_LAST_ERROR)){ + if (params.contains(DiagParams.INCLUDE_LAST_ERROR)) { includeLastError(stb) } } @@ -286,22 +288,22 @@ class DiagnosticExecutor: CASubCommand() { val xp = invView.repairCost val maxXp = invView.maximumRepairCost val mergeResult = invView.getItem(2) - stb.append("\n${if(result == mergeResult) "E" else "Une"}xpected Result") + stb.append("\n${if (result == mergeResult) "E" else "Une"}xpected Result") PrepareAnvilListener().anvilCombineCheck(event) // Now we check if item and xp same stb.append("\nXP/Max XP: ") - .append(if(invView.repairCost == xp) "Correct" else "Incorrect") + .append(if (invView.repairCost == xp) "Correct" else "Incorrect") .append("/") - .append(if(invView.maximumRepairCost == maxXp) "Correct" else "Incorrect") + .append(if (invView.maximumRepairCost == maxXp) "Correct" else "Incorrect") .append(" (${invView.repairCost} $xp|${invView.maximumRepairCost} $maxXp)") .append("\nMerge result: ") - .append(if(invView.getItem(2) == mergeResult) "Correct" else "Incorrect") + .append(if (invView.getItem(2) == mergeResult) "Correct" else "Incorrect") PrepareAnvilListener.IS_EMPTY_TEST = true Bukkit.getPluginManager().callEvent(event) stb.append("\nNull result test: ") - .append(if(event.result == null) "Correct" else "Incorrect") + .append(if (event.result == null) "Correct" else "Incorrect") invView.setItem(0, null) invView.setItem(1, null) @@ -323,11 +325,13 @@ class DiagnosticExecutor: CASubCommand() { map[enchant.key.namespace] = map.getOrDefault(enchant.key.namespace, 0) + 1 } - stb.append("\nNamespaces: ${ + stb.append( + "\nNamespaces: ${ map.entries.stream() .map { (key, value) -> "$key ($value)" } .reduce { a, b -> "$a, $b" }.get() - }") + }" + ) } @@ -337,7 +341,6 @@ class DiagnosticExecutor: CASubCommand() { stb.append("\n\nLast stack trace: ${e.stackTraceToString()}") - } - + } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index fba89b71..8ff662f9 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -8,19 +8,21 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil import xyz.alexcrea.cuanvil.gui.config.MainConfigGui import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions -class EditConfigExecutor: CASubCommand() { +class EditConfigExecutor : CASubCommand() { - override fun executeCommand(sender: CommandSender, - cmd: Command, - cmdstr: String, - args: Array): Boolean { + override fun executeCommand( + sender: CommandSender, + cmd: Command, + cmdstr: String, + args: Array + ): Boolean { if (sender !is HumanEntity) return false if (!allowed(sender)) { sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM) return false } - if(PlatformUtil.isFolia){ + if (PlatformUtil.isFolia) { sender.sendMessage("§cIt look like you are using Folia. Sadly Custom Anvil do not support Config gui for Folia.") sender.sendMessage("§eIt is may come in a future version.") sender.sendMessage("") diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt index 697f1ee2..1314d0ec 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt @@ -4,18 +4,20 @@ import com.google.common.collect.ImmutableMap import org.bukkit.command.Command import org.bukkit.command.CommandSender -class HelpExecutor: CASubCommand() { +class HelpExecutor : CASubCommand() { lateinit var commands: ImmutableMap - override fun executeCommand(sender: CommandSender, - cmd: Command, - cmdstr: String, - args: Array): Boolean { + override fun executeCommand( + sender: CommandSender, + cmd: Command, + cmdstr: String, + args: Array + ): Boolean { val stb = StringBuilder("List of available commands:") for ((key, cmd) in commands) { - if(!cmd.allowed(sender)) continue + if (!cmd.allowed(sender)) continue stb.append("\n- $key: ").append(cmd.description()) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt index ef23e7d6..ab832c4f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt @@ -3,7 +3,6 @@ package xyz.alexcrea.cuanvil.command import io.delilaheve.CustomAnvil import org.bukkit.Bukkit import org.bukkit.command.Command -import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent import xyz.alexcrea.cuanvil.config.ConfigHolder @@ -13,10 +12,12 @@ import xyz.alexcrea.cuanvil.update.UpdateHandler class ReloadExecutor : CASubCommand() { - override fun executeCommand(sender: CommandSender, - cmd: Command, - cmdstr: String, - args: Array): Boolean { + override fun executeCommand( + sender: CommandSender, + cmd: Command, + cmdstr: String, + args: Array + ): Boolean { if (!allowed(sender)) { sender.sendMessage("§cYou do not have permission to reload the config") return false diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index a76c4a79..3139fc51 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -35,6 +35,7 @@ import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError import java.util.logging.Level +@Suppress("UnstableApiUsage") object DependencyManager { lateinit var scheduler: TaskScheduler @@ -103,7 +104,7 @@ object DependencyManager { axPlayerWarpsCompatibility = AxPlayerWarpsDependency() } - if (pluginManager.isPluginEnabled("ItemsAdder")){ + if (pluginManager.isPluginEnabled("ItemsAdder")) { val dependency = ItemsAdderDependency(pluginManager.getPlugin("ItemsAdder")!!) itemsAdderCompatibility = dependency genericDependencies.add(dependency) @@ -116,9 +117,9 @@ object DependencyManager { if (pluginManager.isPluginEnabled("ItemsAdder")) genericDependencies.add(GenericPluginDependency(pluginManager.getPlugin("ItemsAdder")!!)) - if (pluginManager.isPluginEnabled("SuperEnchants")){ + if (pluginManager.isPluginEnabled("SuperEnchants")) { val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!!) - if(compatibility.registerEnchantments()) + if (compatibility.registerEnchantments()) genericDependencies.add(compatibility) } @@ -307,7 +308,7 @@ object DependencyManager { private fun unsafeCloneItem(item: ItemStack): ItemStack { val cloned = itemsAdderCompatibility?.tryClone(item) - if(cloned != null) return cloned + if (cloned != null) return cloned return item.clone() } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt index 3e9f2ac4..7813cb4e 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt @@ -26,8 +26,10 @@ object MinecraftVersionUtil { } } - val isTooNewForSpigot: Boolean get() { - return UpdateUtils.currentMinecraftVersion().major != 1 - } + val isTooNewForSpigot: Boolean + get() { + + return UpdateUtils.currentMinecraftVersion().major != 1 + } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/GenericExternGuiTester.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/GenericExternGuiTester.kt index 4046f4ab..b9410886 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/GenericExternGuiTester.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/GenericExternGuiTester.kt @@ -64,11 +64,11 @@ class GenericExternGuiTester { } // Try if were in another plugin anvil inventory - fun testIfGui(inventory: InventoryView): Boolean { + fun testIfGui(view: InventoryView): Boolean { // In case we are in a test environment if(isInTest()) return false - val clazz = getContainerClass(inventory) ?: return false + val clazz = getContainerClass(view) ?: return false val clazzName = clazz.name if(!PlatformUtil.isPaper){ diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt index d74ef089..e21a66ed 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt @@ -3,7 +3,7 @@ package xyz.alexcrea.cuanvil.dependency.packet import org.bukkit.Bukkit import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.dependency.MinecraftVersionUtil -import xyz.alexcrea.cuanvil.dependency.packet.versions.* +import xyz.alexcrea.cuanvil.dependency.packet.versions.PaperPacketManager import xyz.alexcrea.cuanvil.update.UpdateUtils object PacketManagerSelector { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt index 8b9e78ef..ba0b330b 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt @@ -21,6 +21,7 @@ import xyz.alexcrea.cuanvil.util.anvil.AnvilXpUtil import java.util.logging.Level import kotlin.reflect.KClass +@Suppress("UnstableApiUsage") class DisenchantmentDependency { init { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EnchantmentSquaredDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EnchantmentSquaredDependency.kt index d769986b..72c8fbab 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EnchantmentSquaredDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EnchantmentSquaredDependency.kt @@ -30,28 +30,29 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) "disable_anvil, " + "incompatible_vanilla_enchantments, " + "incompatible_custom_enchantments and max_level " + - "configuration values.") + "configuration values." + ) } - fun disableAnvilListener(){ + fun disableAnvilListener() { PrepareAnvilEvent.getHandlerList().unregister(this.enchantmentSquaredPlugin) // Find the anvil click event var toRemove: AnvilListener? = null for (registered in InventoryClickEvent.getHandlerList().registeredListeners) { val listener = registered.listener - if(listener is AnvilListener) { + if (listener is AnvilListener) { toRemove = listener break } } - if(toRemove != null) + if (toRemove != null) InventoryClickEvent.getHandlerList().unregister(toRemove) } - fun registerEnchantments(){ + fun registerEnchantments() { CustomAnvil.instance.logger.info("Preparing Enchantment Squared compatibility...") // Register enchantments @@ -69,20 +70,21 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) fun getEnchantmentsSquared(item: ItemStack, enchantments: MutableMap) { val customEnchants = CustomEnchantManager.getInstance().getItemsEnchantsFromPDC(item) - customEnchants.forEach{ - (enchantment, level ) -> enchantments[getWrappedEnchant(enchantment)] = level + customEnchants.forEach { (enchantment, level) -> + enchantments[getWrappedEnchant(enchantment)] = level } } - fun getKeyFromEnchant(enchant: CustomEnchant): NamespacedKey{ + fun getKeyFromEnchant(enchant: CustomEnchant): NamespacedKey { return NamespacedKey.fromString(enchant.type.lowercase(Locale.getDefault()), this.enchantmentSquaredPlugin)!! } + private fun getWrappedEnchant(enchant: CustomEnchant): CAEnchantment { return CAEnchantment.getByKey(getKeyFromEnchant(enchant))!! } - fun registerPluginConfiguration(){ + fun registerPluginConfiguration() { CustomAnvil.instance.logger.info("Preparing Enchantment Squared config...") // Prepare enchantments @@ -99,7 +101,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) CustomAnvil.instance.logger.info("Enchantment Squared should now work as expected !") } - private fun writeMissingGroups(){ + private fun writeMissingGroups() { // Write group that do not exist on custom anvil. val shield = IncludeGroup("shield") shield.addToPolicy(Material.SHIELD.key) @@ -114,7 +116,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) MaterialGroupApi.addMaterialGroup(trinkets) } - private fun writeMaterialRestriction(esEnchantments: List){ + private fun writeMaterialRestriction(esEnchantments: List) { for (enchantment in esEnchantments) { val conflict = ConflictBuilder("restriction_${enchantment.key.key}", CustomAnvil.instance) conflict.addEnchantment(enchantment) @@ -125,7 +127,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) // Get allowed groups for (esGroup in enchantment.enchant.compatibleItems) { val caGroup = esGroupToCAGroup(esGroup) - if(caGroup == null){ + if (caGroup == null) { CustomAnvil.instance.logger.info("Could not find equivalent custom anvil group for $esGroup") continue } @@ -136,7 +138,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) } } - private fun writeEnchantmentConflicts(esEnchantments: List){ + private fun writeEnchantmentConflicts(esEnchantments: List) { val otherEnchants = ArrayList() otherEnchants.addAll(CAEnchantmentRegistry.getInstance().values()) @@ -145,14 +147,14 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) // find conflicting enchantment. for (otherEnchant in otherEnchants) { - if(enchantment.enchant.conflictsWithEnchantment(otherEnchant.name)){ + if (enchantment.enchant.conflictsWithEnchantment(otherEnchant.name)) { writeConflict(enchantment, otherEnchant) } } } } - private fun writeConflict(enchantment1: CAEnchantment, enchantment2: CAEnchantment){ + private fun writeConflict(enchantment1: CAEnchantment, enchantment2: CAEnchantment) { val conflict = ConflictBuilder("${enchantment1.name}_with_${enchantment2.name}_conflict", CustomAnvil.instance) conflict.addEnchantment(enchantment1).addEnchantment(enchantment2) @@ -165,7 +167,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) * Transform an Enchantment Squared group to a Custom Anvil group */ private fun esGroupToCAGroup(esGroup: String): String? { - return when(esGroup){ + return when (esGroup) { "SWORDS" -> "swords" "BOWS" -> "bow" "CROSSBOWS" -> "crossbow" diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt index 816a4dfe..d3d46ccc 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt @@ -17,10 +17,10 @@ import java.lang.reflect.Constructor import java.lang.reflect.Method import su.nightexpress.excellentenchants.api.EnchantRegistry as V5EnchantRegistry import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant as LegacyCurseOfFragilityEnchant -import su.nightexpress.excellentenchants.manager.listener.AnvilListener as V5AnvilListener import su.nightexpress.excellentenchants.enchantment.listener.AnvilListener as PreV5AnvilListener import su.nightexpress.excellentenchants.enchantment.listener.EnchantAnvilListener as LegacyAnvilListener import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry as LegacyEnchantRegistry +import su.nightexpress.excellentenchants.manager.listener.AnvilListener as V5AnvilListener import su.nightexpress.excellentenchants.registry.EnchantRegistry as PreV5EnchantRegistry // I don't like that I need to support older version. if I could just drop older support it would be sooo nice @@ -53,7 +53,7 @@ class ExcellentEnchantsDependency { if (listenerVersion == null) { CustomAnvil.instance.logger.severe("Found issue with listener of Excellent Enchants. compatiblity is broken. please contact CustomAnvil devs") - } else{ + } else { CustomAnvil.log("Support version: " + listenerVersion.name) } @@ -173,6 +173,7 @@ class ExcellentEnchantsDependency { ListenerVersion.V5, ListenerVersion.V5_4, -> this.usedAnvilListener = v5AnvilListener!! + ListenerVersion.PRE_V5 -> this.usedAnvilListener = preV5AnvilListener!! ListenerVersion.LEGACY -> this.usedAnvilListener = legacyAnvilListener!! null -> {} @@ -240,6 +241,7 @@ class ExcellentEnchantsDependency { ListenerVersion.V5_3, ListenerVersion.V5_4, -> v5AnvilListener!!.onClickAnvil(event) + ListenerVersion.PRE_V5 -> preV5AnvilListener!!.onClickAnvil(event) ListenerVersion.LEGACY -> legacyAnvilListener!!.onClickAnvil(event) null -> {} diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/GenericPluginDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/GenericPluginDependency.kt index 62dae9ba..8bfd98ea 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/GenericPluginDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/GenericPluginDependency.kt @@ -24,7 +24,7 @@ open class GenericPluginDependency(protected open val plugin: Plugin, private va } } - open fun fillPreAnvil(preAnvil: ArrayList){ + open fun fillPreAnvil(preAnvil: ArrayList) { // get PreAnvil and PostAnvil listeners for (registeredListener in PrepareAnvilEvent.getHandlerList().registeredListeners) { @@ -35,12 +35,13 @@ open class GenericPluginDependency(protected open val plugin: Plugin, private va protected open fun fillPostAnvil( postAnvil: ArrayList, - preAnvil: ArrayList) { + preAnvil: ArrayList + ) { } open fun testPrepareAnvil(event: PrepareAnvilEvent): Boolean { - if(!testPrepare) return false + if (!testPrepare) return false val previousResult = event.result event.result = null @@ -61,7 +62,7 @@ open class GenericPluginDependency(protected open val plugin: Plugin, private va } open fun testAnvilResult(event: InventoryClickEvent): Boolean { - if(!testPrepare) return false + if (!testPrepare) return false for (registeredListener in postAnvil) { // We do not want error from another plugin to be our fault diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt index b9c3ce68..23a8544d 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt @@ -13,6 +13,7 @@ import xyz.alexcrea.cuanvil.anvil.AnvilCost import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener import xyz.alexcrea.cuanvil.util.anvil.AnvilXpUtil +@Suppress("UnstableApiUsage") class HavenBagsDependency { init { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt index 7f977e18..9f366b20 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt @@ -17,19 +17,19 @@ class ItemsAdderDependency(plugin: Plugin) : GenericPluginDependency(plugin) { } fun tryClone(item: ItemStack): ItemStack? { - if(!isLoaded) return null + if (!isLoaded) return null val customItem = CustomStack.byItemStack(item) ?: return null return CustomStack.getInstance(customItem.namespacedID)?.itemStack } fun fromKey(key: NamespacedKey): ItemStack? { - if(!isLoaded) return null + if (!isLoaded) return null return CustomStack.getInstance(key.toString())?.itemStack } - fun getKey(item: ItemStack) : NamespacedKey? { - if(!isLoaded) return null + fun getKey(item: ItemStack): NamespacedKey? { + if (!isLoaded) return null val customItem = CustomStack.byItemStack(item) ?: return null return NamespacedKey.fromString(customItem.namespacedID) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt index 8676b4cd..6b9d6fd7 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt @@ -15,7 +15,7 @@ import xyz.alexcrea.cuanvil.enchant.bulk.SuperEnchantBulkOperation import xyz.alexcrea.cuanvil.enchant.wrapped.CASuperEnchantEnchantment import java.util.logging.Level -class SuperEnchantDependency: GenericPluginDependency { +class SuperEnchantDependency : GenericPluginDependency { override val plugin: SuperEnchants lateinit var enchManager: EnchantManager @@ -25,11 +25,11 @@ class SuperEnchantDependency: GenericPluginDependency { this.plugin = plugin as SuperEnchants } - fun registerEnchantments(): Boolean{ + fun registerEnchantments(): Boolean { CustomAnvil.instance.logger.info("Preparing Super Enchant compatibility...") val field = SuperEnchants::class.java.getDeclaredField("enchantManager") - if(field == null) { + if (field == null) { CustomAnvil.instance.logger.log(Level.SEVERE, "Failed to initialize Super Enchant compatibility") return false } @@ -67,7 +67,7 @@ class SuperEnchantDependency: GenericPluginDependency { reload?.setExecutor(ReloadInterceptor(reload.executor)) } - inner class ReloadInterceptor(val other: CommandExecutor): CommandExecutor { + inner class ReloadInterceptor(val other: CommandExecutor) : CommandExecutor { override fun onCommand( sender: CommandSender, diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ToolStatsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ToolStatsDependency.kt index 255f7373..f1193d17 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ToolStatsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ToolStatsDependency.kt @@ -5,7 +5,6 @@ import lol.hyper.toolstats.tools.ItemChecker import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.ItemStack import org.bukkit.plugin.Plugin -import org.bukkit.plugin.RegisteredListener import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener import java.lang.reflect.Method diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt index 59841ac6..2957e324 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt @@ -18,18 +18,19 @@ class EnchantConflictGroup( fun addEnchantment(enchant: CAEnchantment) { enchantments.add(enchant) } + fun addEnchantments(enchants: List) { enchantments.addAll(enchants) } private fun canBypassByBeforeLevel(enchants: Map): Boolean { // Either there no "conflict after" - if(conflictsAfterLevel.isEmpty()) return false + if (conflictsAfterLevel.isEmpty()) return false // Or we check if any conflict after enchantment is true for (entry in conflictsAfterLevel) { val current = enchants.getOrDefault(entry.key, 0) - if(current > entry.value) + if (current > entry.value) return false } @@ -38,12 +39,12 @@ class EnchantConflictGroup( private fun canBypassByAfterLevel(enchants: Map): Boolean { // Either there no "conflict after" - if(conflictsBeforeLevel.isEmpty()) return false + if (conflictsBeforeLevel.isEmpty()) return false // Or we check if any conflict after enchantment is true for (entry in conflictsBeforeLevel) { val current = enchants.getOrDefault(entry.key, 0) - if(current < entry.value) + if (current < entry.value) return false } @@ -64,7 +65,7 @@ class EnchantConflictGroup( return true // If empty we skip. else we - if(canBypassConflictByLevel(enchants)) + if (canBypassConflictByLevel(enchants)) return true // Count the amount of enchantment that are in the list @@ -102,7 +103,7 @@ class EnchantConflictGroup( fun putConflictAfterLevel(enchantment: CAEnchantment, level: Int): Boolean { return null != ( - if(level < 0) conflictsAfterLevel.remove(enchantment) + if (level < 0) conflictsAfterLevel.remove(enchantment) else conflictsAfterLevel.put(enchantment, level)) } @@ -117,7 +118,7 @@ class EnchantConflictGroup( fun putConflictsBeforeLevel(enchantment: CAEnchantment, level: Int): Boolean { return null != ( - if(level < 0) conflictsBeforeLevel.remove(enchantment) + if (level < 0) conflictsBeforeLevel.remove(enchantment) else conflictsBeforeLevel.put(enchantment, level)) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index 5b256dd8..88757c70 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -11,7 +11,6 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.util.MaterialUtil.customType import java.util.* -import kotlin.collections.set class EnchantConflictManager { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt index d752db5b..4b1a31bb 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt @@ -1,7 +1,6 @@ package xyz.alexcrea.cuanvil.group import org.bukkit.NamespacedKey -import java.util.* class ExcludeGroup(name: String) : AbstractMaterialGroup(name) { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/IncludeGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/IncludeGroup.kt index fc9614b7..f4076350 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/IncludeGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/IncludeGroup.kt @@ -1,8 +1,6 @@ package xyz.alexcrea.cuanvil.group -import org.bukkit.Material import org.bukkit.NamespacedKey -import java.util.* class IncludeGroup(name: String) : AbstractMaterialGroup(name) { override fun createDefaultSet(): MutableSet { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt index 348d0fff..7a9c388b 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt @@ -41,7 +41,7 @@ class ItemGroupManager { fun createGroup( config: ConfigurationSection, name: String - ): AbstractMaterialGroup{ + ): AbstractMaterialGroup { return createGroup(config, groupMap.keys, name) } @@ -109,11 +109,10 @@ class ItemGroupManager { } // Get other group or create it if not yet created val otherGroup = - if (!groupMap.containsKey(groupName)) { - if(!config.isConfigurationSection(groupName)) continue - createGroup(config, keys, groupName) - } - else groupMap[groupName]!! + if (!groupMap.containsKey(groupName)) { + if (!config.isConfigurationSection(groupName)) continue + createGroup(config, keys, groupName) + } else groupMap[groupName]!! // Avoid self reference or it will create an infinite loop if (otherGroup.isReferencing(group)) { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt index d87004d4..ef442e57 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt @@ -4,7 +4,7 @@ import org.bukkit.NamespacedKey import xyz.alexcrea.cuanvil.util.MaterialUtil import xyz.alexcrea.cuanvil.util.NegativeSet -class NegativeMaterialSet: NegativeSet() { +class NegativeMaterialSet : NegativeSet() { override fun iterator(): MutableIterator { val materials = MaterialUtil.getMaterials() diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt index 85b9414e..b73effe1 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt @@ -9,13 +9,14 @@ import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.dependency.packet.PacketManager import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil +@Suppress("UnstableApiUsage") class AnvilCloseListener(private val packetManager: PacketManager) : Listener { @EventHandler - fun onAnvilClose(event: InventoryCloseEvent){ + fun onAnvilClose(event: InventoryCloseEvent) { val player = event.player - if(event.view !is AnvilView) return - if(player is Player && GameMode.CREATIVE != player.gameMode){ + if (event.view !is AnvilView) return + if (player is Player && GameMode.CREATIVE != player.gameMode) { packetManager.setInstantBuild(player, false) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index e9290ac9..09fad8ce 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -11,10 +11,9 @@ import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.inventory.ClickType import org.bukkit.event.inventory.InventoryClickEvent -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.BookMeta +import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.anvil.AnvilCost import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.AnvilResult @@ -37,6 +36,7 @@ import java.util.* import java.util.concurrent.atomic.AtomicReference import kotlin.math.min +@Suppress("UnstableApiUsage") class AnvilResultListener : Listener { companion object { @@ -51,7 +51,7 @@ class AnvilResultListener : Listener { @EventHandler(ignoreCancelled = true) fun anvilExtractionCheck(event: InventoryClickEvent) { val player = event.whoClicked as? Player ?: return - val inventory = event.inventory as? AnvilInventory ?: return + val view = event.view as? AnvilView ?: return val view = event.view if (event.rawSlot != ANVIL_OUTPUT_SLOT) { @@ -59,17 +59,17 @@ class AnvilResultListener : Listener { } // Test if the event should bypass custom anvil. - if (DependencyManager.tryClickAnvilResultBypass(event, inventory)) return + if (DependencyManager.tryClickAnvilResultBypass(event, view)) return if (!player.hasPermission(CustomAnvil.affectedByPluginPermission)) return - val output = inventory.getItem(ANVIL_OUTPUT_SLOT) ?: return - val leftItem = inventory.getItem(ANVIL_INPUT_LEFT) ?: return - val rightItem = inventory.getItem(ANVIL_INPUT_RIGHT) + val output = view.getItem(ANVIL_OUTPUT_SLOT) ?: return + val leftItem = view.getItem(ANVIL_INPUT_LEFT) ?: return + val rightItem = view.getItem(ANVIL_INPUT_RIGHT) // Deny by default. allow if working event.result = Event.Result.DENY - if (GameMode.CREATIVE != player.gameMode && inventory.repairCost >= inventory.maximumRepairCost) { + if (GameMode.CREATIVE != player.gameMode && view.repairCost >= view.maximumRepairCost) { return } @@ -77,14 +77,14 @@ class AnvilResultListener : Listener { val customRecipeResult = AnvilMergeLogic.testCustomRecipe(view, inventory, player, leftItem, rightItem) if (!customRecipeResult.isEmpty()) { onCustomCraft( - event, player, inventory, + event, player, view, leftItem, rightItem, customRecipeResult ) return } // Do not continue if there was no change - if ((output == inventory.getItem(ANVIL_INPUT_LEFT))) { + if ((output == view.getItem(ANVIL_INPUT_LEFT))) { return } @@ -94,7 +94,7 @@ class AnvilResultListener : Listener { if (result.isEmpty()) return extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, null, 0, result @@ -108,7 +108,7 @@ class AnvilResultListener : Listener { val result = AnvilMergeLogic.doMerge(view, inventory, player, leftItem, rightItem) val worked = extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, null, 0, result @@ -128,7 +128,7 @@ class AnvilResultListener : Listener { ) if (!unitRepairResult.isEmpty()) { onUnitRepairExtract( - rightItem, event, player, inventory, + rightItem, event, player, view, unitRepairResult ) return @@ -138,9 +138,9 @@ class AnvilResultListener : Listener { val loreResult = AnvilMergeLogic.testLoreEdit(player, leftItem, rightItem) if (!loreResult.isEmpty()) { if (loreResult.type.isBook) - handleBookLoreEdit(event, inventory, player, leftItem, rightItem, loreResult) + handleBookLoreEdit(event, view, player, leftItem, rightItem, loreResult) else - handlePaperLoreEdit(event, inventory, player, leftItem, rightItem, loreResult) + handlePaperLoreEdit(event, view, player, leftItem, rightItem, loreResult) return } } @@ -148,7 +148,7 @@ class AnvilResultListener : Listener { private fun onCustomCraft( event: InventoryClickEvent, player: Player, - inventory: AnvilInventory, + view: AnvilView, leftItem: ItemStack, rightItem: ItemStack?, result: CustomCraftResult, @@ -186,7 +186,7 @@ class AnvilResultListener : Listener { if (event.click != ClickType.MIDDLE && !handleCustomCraftClick( event, - inventory, + view, player, leftItem, rightItem, @@ -204,7 +204,7 @@ class AnvilResultListener : Listener { private fun handleCustomCraftClick( event: InventoryClickEvent, - inventory: AnvilInventory, player: Player, + view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack?, result: CustomCraftResult ): Boolean { @@ -216,11 +216,11 @@ class AnvilResultListener : Listener { if (recipe.rightItem == null) return false// in case it changed rightItem.amount -= amount * recipe.rightItem!!.amount - inventory.setItem(ANVIL_INPUT_RIGHT, rightItem) + view.setItem(ANVIL_INPUT_RIGHT, rightItem) } leftItem.amount -= amount * recipe.leftItem!!.amount - inventory.setItem(ANVIL_INPUT_LEFT, leftItem) + view.setItem(ANVIL_INPUT_LEFT, leftItem) removeCustomCraftCost(player, result) @@ -229,17 +229,15 @@ class AnvilResultListener : Listener { CustomAnvil.verboseLog("new amount is $newAmount") if (newAmount <= 0 || recipe.exactCount) { - inventory.setItem(ANVIL_OUTPUT_SLOT, null) + view.setItem(ANVIL_OUTPUT_SLOT, null) } else { val resultItem: ItemStack = recipe.resultItem!!.clone() resultItem.amount *= newAmount val newXp = newAmount * newAmount - inventory.repairCost = newXp - event.view.setProperty(InventoryView.Property.REPAIR_COST, newXp) - - inventory.setItem(ANVIL_OUTPUT_SLOT, resultItem) + view.repairCost = newXp + view.setItem(ANVIL_OUTPUT_SLOT, resultItem) player.updateInventory() } @@ -305,7 +303,7 @@ class AnvilResultListener : Listener { private fun extractAnvilResult( event: InventoryClickEvent, player: Player, - inventory: AnvilInventory, + view: AnvilView, leftItem: ItemStack?, leftRemoveCount: Int, rightItem: ItemStack?, @@ -322,7 +320,7 @@ class AnvilResultListener : Listener { event.isCancelled = true val cost = result.cost - processCost(inventory, player, cost) + processCost(view, player, cost) if (!cost.valid && player.gameMode != GameMode.CREATIVE) { CustomAnvil.verboseLog("Player cannot afford the cost") return false @@ -338,12 +336,12 @@ class AnvilResultListener : Listener { // We remove what should be removed if (leftItem != null) leftItem.amount -= leftRemoveCount - inventory.setItem(ANVIL_INPUT_LEFT, leftItem) + view.setItem(ANVIL_INPUT_LEFT, leftItem) if (rightItem != null) rightItem.amount -= rightRemoveCount - inventory.setItem(ANVIL_INPUT_RIGHT, rightItem) + view.setItem(ANVIL_INPUT_RIGHT, rightItem) - inventory.setItem(ANVIL_OUTPUT_SLOT, null) + view.setItem(ANVIL_OUTPUT_SLOT, null) } @@ -358,7 +356,7 @@ class AnvilResultListener : Listener { return true } - private fun processCost(inventory: AnvilInventory, player: Player, cost: AnvilCost) { + private fun processCost(view: AnvilView, player: Player, cost: AnvilCost) { var sum = cost.repair if ( @@ -376,7 +374,7 @@ class AnvilResultListener : Listener { if (!EconomyManager.economy!!.has(player, cost.asMonetaryCost())) cost.valid = false } else { - if ((inventory.maximumRepairCost <= sum) + if ((view.maximumRepairCost <= sum) || (player.level < sum) ) cost.valid = false } @@ -386,12 +384,12 @@ class AnvilResultListener : Listener { rightItem: ItemStack, event: InventoryClickEvent, player: Player, - inventory: AnvilInventory, + view: AnvilView, result: UnitRepairResult, ) { // We give the item manually extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, rightItem, result.repairAmount, result @@ -400,21 +398,21 @@ class AnvilResultListener : Listener { private fun handleBookLoreEdit( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack, result: LoreEditResult ) { if (result.type.isAppend) - handleBookLoreAppend(event, inventory, player, rightItem, result) + handleBookLoreAppend(event, view, player, rightItem, result) else - handleBookLoreRemove(event, inventory, player, leftItem, rightItem, result) + handleBookLoreRemove(event, view, player, leftItem, rightItem, result) } private fun handleBookLoreAppend( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, rightItem: ItemStack, result: LoreEditResult @@ -432,7 +430,7 @@ class AnvilResultListener : Listener { } extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, clearedBook, 0, result @@ -441,7 +439,7 @@ class AnvilResultListener : Listener { private fun handleBookLoreRemove( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack, @@ -477,7 +475,7 @@ class AnvilResultListener : Listener { } extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, rightCopy, 0, result @@ -486,21 +484,21 @@ class AnvilResultListener : Listener { private fun handlePaperLoreEdit( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack, result: LoreEditResult ) { if (result.type.isAppend) - handlePaperLoreAppend(event, inventory, player, rightItem, result) + handlePaperLoreAppend(event, view, player, rightItem, result) else - handlePaperLoreRemove(event, inventory, player, leftItem, rightItem, result) + handlePaperLoreRemove(event, view, player, leftItem, rightItem, result) } private fun handlePaperLoreAppend( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, rightItem: ItemStack, result: LoreEditResult @@ -525,14 +523,14 @@ class AnvilResultListener : Listener { if (rightItem.amount > 1) { extractAnvilResult( - event, player, inventory, + event, player, view, paperCopy, 0, rightItem, 1, result ) } else { extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, paperCopy, 0, result @@ -542,7 +540,7 @@ class AnvilResultListener : Listener { private fun handlePaperLoreRemove( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack, @@ -577,14 +575,14 @@ class AnvilResultListener : Listener { if (rightItem.amount > 1) { extractAnvilResult( - event, player, inventory, + event, player, view, rightClone, 0, rightItem, 1, result ) } else { extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, rightClone, 0, result diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/ChatEventListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/ChatEventListener.kt index f166fa39..f2a68cb0 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/ChatEventListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/ChatEventListener.kt @@ -41,9 +41,10 @@ class ChatEventListener : Listener { // sync callback with default server thread DependencyManager.scheduler.scheduleOnEntity( CustomAnvil.instance, player, - Runnable { - eventCallback.accept(event.message) - }, 0L) + { + eventCallback.accept(event.message) + }, 0L + ) } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt index c0fe939b..ce263613 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.listener -import com.github.stefvanschie.inventoryframework.util.InventoryViewUtil import io.delilaheve.CustomAnvil import io.delilaheve.util.ConfigOptions import io.delilaheve.util.ItemUtil.canMergeWith @@ -16,6 +15,7 @@ import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.EnchantmentStorageMeta import org.bukkit.inventory.meta.ItemMeta import xyz.alexcrea.cuanvil.anvil.AnvilCost +import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.AnvilResult import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.doMerge import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.doRenaming @@ -30,6 +30,7 @@ import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil /** * Listener for anvil events */ +@Suppress("UnstableApiUsage") class PrepareAnvilListener : Listener { companion object { @@ -48,24 +49,23 @@ class PrepareAnvilListener : Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) fun anvilCombineCheck(event: PrepareAnvilEvent) { val view = event.view - val inventory = event.inventory + val player = view.player - val player = InventoryViewUtil.getInstance().getPlayer(view) - if(player !is Player) return + if (player !is Player) return tryRenameDialog(player, event) // Test if custom anvil is bypassed before immutability test if (DependencyManager.earlyTryEventPreAnvilBypass(event, player)) { // even if we got bypassed we still want to set price - AnvilXpUtil.setAnvilInvCost(inventory, view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(view, player, AnvilCost(view.repairCost)) return } - val first = inventory.getItem(ANVIL_INPUT_LEFT) - val second = inventory.getItem(ANVIL_INPUT_RIGHT) + val first = view.getItem(ANVIL_INPUT_LEFT) + val second = view.getItem(ANVIL_INPUT_RIGHT) - if(IS_EMPTY_TEST) { + if (IS_EMPTY_TEST) { IS_EMPTY_TEST = false applyResult(event, player, AnvilResult.EMPTY) return @@ -86,7 +86,7 @@ class PrepareAnvilListener : Listener { // Test if the event should bypass custom anvil. if (DependencyManager.tryEventPreAnvilBypass(event, player)) { // even if we got bypassed we still want to set price - AnvilXpUtil.setAnvilInvCost(inventory, view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(view, player, AnvilCost(view.repairCost)) return } @@ -100,9 +100,9 @@ class PrepareAnvilListener : Listener { view: InventoryView, //TODO use anvil view inventory: AnvilInventory, player: Player, - first: ItemStack?, second: ItemStack?) : AnvilResult - { - if(first == null) + first: ItemStack?, second: ItemStack? + ): AnvilResult { + if (first == null) return AnvilResult.EMPTY // Test custom recipe @@ -137,7 +137,7 @@ class PrepareAnvilListener : Listener { player: HumanEntity, event: PrepareAnvilEvent ) { - if(!ConfigOptions.canUseDialogRename(player)) return + if (!ConfigOptions.canUseDialogRename(player)) return AnvilRenameDialogUtil.anvilRenameDialog.tryShowDialog(player, event) } @@ -171,7 +171,7 @@ class PrepareAnvilListener : Listener { private fun applyResult(event: PrepareAnvilEvent, player: Player, result: AnvilResult) { event.result = result.item - AnvilXpUtil.setAnvilResult(event.inventory, event.view, player, result) + AnvilXpUtil.setAnvilResult(event.view, player, result) } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt index 6b55662f..10190591 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.util -import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.inventory.ItemStack diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index 9d2f5420..f3131dbf 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -8,10 +8,10 @@ import org.bukkit.GameMode import org.bukkit.NamespacedKey import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player -import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Repairable +import org.bukkit.inventory.view.AnvilView import org.bukkit.persistence.PersistentDataType import xyz.alexcrea.cuanvil.anvil.AnvilCost import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.AnvilResult @@ -24,6 +24,7 @@ import xyz.alexcrea.cuanvil.group.ConflictType import xyz.alexcrea.cuanvil.util.AnvilTitleUtil import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil +@Suppress("UnstableApiUsage") object AnvilXpUtil { const val EXCLUSIVE_PENALTY_PREFIX = "repair_cost" @@ -48,17 +49,16 @@ object AnvilXpUtil { * Display the required cost (either as xp or as money) */ fun setAnvilInvCost( - inventory: AnvilInventory, - view: InventoryView, + view: AnvilView, player: Player, cost: AnvilCost, ignoreRules: Boolean = false ) { if (ConfigOptions.shouldUseMoney(player)) { cost.isMonetary = true - setAnvilPrice(inventory, view, player, cost) + setAnvilPrice(view, player, cost) } else - setAnvilInvXp(inventory, view, player, cost.filteredXpCost(ignoreRules), ignoreRules) + setAnvilInvXp(view, player, cost.filteredXpCost(ignoreRules), ignoreRules) } fun maximumXpCost(ignoreRules: Boolean = false): Int { @@ -73,8 +73,7 @@ object AnvilXpUtil { * Display xp needed for the work on the anvil inventory */ private fun setAnvilInvXp( - inventory: AnvilInventory, - view: InventoryView, + view: AnvilView, player: HumanEntity, anvilCost: Int, ignoreRules: Boolean = false @@ -82,8 +81,8 @@ object AnvilXpUtil { val maximumRepairCost = maximumXpCost(ignoreRules) // Try first just in case another plugin, or the test need this - inventory.maximumRepairCost = maximumRepairCost - inventory.repairCost = anvilCost + view.maximumRepairCost = maximumRepairCost + view.repairCost = anvilCost // TODO for 2.x.x use anvil view & set directly there /* Because Minecraft likes to have the final say in the repair cost displayed @@ -93,16 +92,15 @@ object AnvilXpUtil { CustomAnvil.instance, player ) { // retry after a tick - inventory.maximumRepairCost = maximumRepairCost - inventory.repairCost = anvilCost - // TODO for 2.x.x use anvil view & set directly there + view.maximumRepairCost = maximumRepairCost + view.repairCost = anvilCost if (player !is Player) return@scheduleOnEntity if (player.gameMode != GameMode.CREATIVE) { val bypassToExpensive = (ConfigOptions.doReplaceTooExpensive) && (anvilCost >= 40) && - anvilCost < inventory.maximumRepairCost + anvilCost < view.maximumRepairCost DependencyManager.packetManager.setInstantBuild(player, bypassToExpensive) } @@ -115,8 +113,7 @@ object AnvilXpUtil { * Display monetary cost needed for the work on the anvil inventory */ private fun setAnvilPrice( - inventory: AnvilInventory, - view: InventoryView, + view: AnvilView, player: Player, cost: AnvilCost, ) { @@ -134,22 +131,20 @@ object AnvilXpUtil { CustomAnvil.instance ) - clearAnvilXpCost(inventory, view, player) + clearAnvilXpCost(view, player) } private fun clearAnvilXpCost( - inventory: AnvilInventory, - view: InventoryView, + view: AnvilView, player: HumanEntity, ) { - // TODO for 2.x.x use anvil view & set directly there - inventory.repairCost = 0 + view.repairCost = 0 // retry after a tick DependencyManager.scheduler.scheduleOnEntity( CustomAnvil.instance, player ) { - inventory.repairCost = 0 + view.repairCost = 0 if (player !is Player) return@scheduleOnEntity player.updateInventory() From f8622e98670cec5f227fee3e4054e8b2ac972d4d Mon Sep 17 00:00:00 2001 From: alexcrea Date: Fri, 12 Jun 2026 19:58:46 +0200 Subject: [PATCH 05/41] rebase on new update --- .../cuanvil/util/MaxDamageCheckerUtil.kt | 18 ------------- .../listener/CATreatAnvilResult2Event.java | 19 +++++-------- .../alexcrea/cuanvil/anvil/AnvilMergeLogic.kt | 27 +++++++------------ .../cuanvil/dependency/DependencyManager.kt | 10 +++---- .../cuanvil/listener/AnvilResultListener.kt | 11 +++----- .../cuanvil/listener/PrepareAnvilListener.kt | 15 +++++------ .../cuanvil/util/anvil/AnvilXpUtil.kt | 3 ++- 7 files changed, 32 insertions(+), 71 deletions(-) delete mode 100644 nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt diff --git a/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt b/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt deleted file mode 100644 index b3ce0ff6..00000000 --- a/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt +++ /dev/null @@ -1,18 +0,0 @@ -package xyz.alexcrea.cuanvil.util - -import org.bukkit.inventory.meta.Damageable - -// I LOVE support of old versions and needing to do modules like that -// That truly is my favorite activity -// TODO clean this one of legacy removal branch -object MaxDamageCheckerUtil { - - /** - * @return max damage or int max if not set - */ - fun getMaxDamage(meta: Damageable): Int { - if(!meta.hasMaxDamage()) return Integer.MAX_VALUE - return meta.maxDamage - } - -} \ No newline at end of file diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java index 30c53806..5d534d91 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java @@ -5,6 +5,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.view.AnvilView; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -21,7 +22,7 @@ import xyz.alexcrea.cuanvil.anvil.AnvilUseType; *

* A null result will cancel this event */ -@SuppressWarnings("unused") +@SuppressWarnings({"unused", "UnstableApiUsage"}) public class CATreatAnvilResult2Event extends Event { private static final HandlerList HANDLERS = new HandlerList(); @@ -36,7 +37,7 @@ public class CATreatAnvilResult2Event extends Event { } @NotNull - private final InventoryView view; + private final AnvilView view; private final AnvilUseType useType; @@ -50,32 +51,26 @@ public class CATreatAnvilResult2Event extends Event { private final AnvilCost cost; - @ApiStatus.Internal public CATreatAnvilResult2Event( - @NotNull InventoryView view, - Inventory inv, + @NotNull AnvilView view, AnvilUseType useType, @Nullable ItemStack result, AnvilCost cost) { this.view = view; this.useType = useType; - this.left = inv.getItem(0); // TODO use view here - this.right = inv.getItem(1); + this.left = view.getItem(0); + this.right = view.getItem(1); this.result = result; this.cost = cost; } /** * Get the bukkit inventory view. - *

- * Temporarily marked as internal as it will get changed to anvil view on legacy removal - * so signature will change * * @return The inventory view of this event. */ - @ApiStatus.Internal - public @NotNull InventoryView getView() { + public @NotNull AnvilView getView() { return view; } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt index 80f8f053..e5e5bc7f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt @@ -10,8 +10,6 @@ import org.bukkit.ChatColor import org.bukkit.Material import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.ItemMeta import org.bukkit.inventory.view.AnvilView @@ -99,8 +97,7 @@ object AnvilMergeLogic { } fun doRenaming( - view: InventoryView, //TODO use anvil view - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack ): AnvilResult { val resultItem = DependencyManager.cloneItem(player, first) @@ -115,7 +112,7 @@ object AnvilMergeLogic { cost.workPenalty = AnvilXpUtil.calculatePenalty(first, null, resultItem, AnvilUseType.RENAME_ONLY) val result = - DependencyManager.tryTreatAnvilResult(view, inventory, player, resultItem, AnvilUseType.RENAME_ONLY, cost) + DependencyManager.tryTreatAnvilResult(view, player, resultItem, AnvilUseType.RENAME_ONLY, cost) return AnvilResult(result, cost) } @@ -185,8 +182,7 @@ object AnvilMergeLogic { } fun doMerge( - view: InventoryView, //TODO use anvil view instead - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack, second: ItemStack ): AnvilResult { @@ -224,7 +220,7 @@ object AnvilMergeLogic { cost.rename = handleRename(resultItem, view, player) val result = - DependencyManager.tryTreatAnvilResult(view, inventory, player, resultItem, AnvilUseType.MERGE, cost) + DependencyManager.tryTreatAnvilResult(view, player, resultItem, AnvilUseType.MERGE, cost) return AnvilResult(result, cost) } @@ -243,8 +239,7 @@ object AnvilMergeLogic { // return true if a custom recipe exist with these ingredients fun testCustomRecipe( - view: InventoryView, //TODO use anvil view instead - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack, second: ItemStack? ): CustomCraftResult { @@ -266,24 +261,22 @@ object AnvilMergeLogic { else AnvilXpUtil.calculateLevelForXp(xpCost) val result = - DependencyManager.tryTreatAnvilResult(view, inventory, player, resultItem, AnvilUseType.CUSTOM_CRAFT, cost) + DependencyManager.tryTreatAnvilResult(view, player, resultItem, AnvilUseType.CUSTOM_CRAFT, cost) return CustomCraftResult(result, cost, amount, recipe) } fun testUnitRepair( - view: InventoryView, //TODO use anvil view - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack, second: ItemStack ): UnitRepairResult { val unitRepairAmount = first.getRepair(second) ?: return UnitRepairResult.EMPTY - return testUnitRepair(view, inventory, player, first, second, unitRepairAmount) + return testUnitRepair(view, player, first, second, unitRepairAmount) } fun testUnitRepair( - view: InventoryView, //TODO use anvil view instead - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack, second: ItemStack, unitRepairAmount: Double @@ -306,7 +299,7 @@ object AnvilMergeLogic { } val result = - DependencyManager.tryTreatAnvilResult(view, inventory, player, resultItem, AnvilUseType.UNIT_REPAIR, cost) + DependencyManager.tryTreatAnvilResult(view, player, resultItem, AnvilUseType.UNIT_REPAIR, cost) return UnitRepairResult(result, cost, repairAmount) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index 3139fc51..3558bcf0 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -9,9 +9,6 @@ import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.PrepareAnvilEvent -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.Inventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import xyz.alexcrea.cuanvil.anvil.AnvilCost import org.bukkit.inventory.view.AnvilView @@ -234,19 +231,18 @@ object DependencyManager { // Return null if there was an issue fun tryTreatAnvilResult( - view: InventoryView, - inventory: Inventory, // TODO REMOVE, use view instead on legacy removal + view: AnvilView, player: HumanEntity, result: ItemStack, useType: AnvilUseType, cost: AnvilCost ): ItemStack? { - val treatEvent = CATreatAnvilResult2Event(view, inventory, useType, result, cost) + val treatEvent = CATreatAnvilResult2Event(view, useType, result, cost) try { unsafeTryTreatAnvilResult(treatEvent) return treatEvent.result } catch (e: Exception) { - logExceptionAndClear(player, inventory, e) + logExceptionAndClear(view, e) return null } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index 09fad8ce..7d750d06 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -52,7 +52,6 @@ class AnvilResultListener : Listener { fun anvilExtractionCheck(event: InventoryClickEvent) { val player = event.whoClicked as? Player ?: return val view = event.view as? AnvilView ?: return - val view = event.view if (event.rawSlot != ANVIL_OUTPUT_SLOT) { return @@ -74,7 +73,7 @@ class AnvilResultListener : Listener { } // Test custom recipe - val customRecipeResult = AnvilMergeLogic.testCustomRecipe(view, inventory, player, leftItem, rightItem) + val customRecipeResult = AnvilMergeLogic.testCustomRecipe(view, player, leftItem, rightItem) if (!customRecipeResult.isEmpty()) { onCustomCraft( event, player, view, @@ -90,7 +89,7 @@ class AnvilResultListener : Listener { // Rename if (rightItem == null) { - val result = AnvilMergeLogic.doRenaming(view, inventory, player, leftItem) + val result = AnvilMergeLogic.doRenaming(view, player, leftItem) if (result.isEmpty()) return extractAnvilResult( @@ -105,7 +104,7 @@ class AnvilResultListener : Listener { // Merge val canMerge = leftItem.canMergeWith(rightItem) if (canMerge) { - val result = AnvilMergeLogic.doMerge(view, inventory, player, leftItem, rightItem) + val result = AnvilMergeLogic.doMerge(view, player, leftItem, rightItem) val worked = extractAnvilResult( event, player, view, @@ -123,7 +122,7 @@ class AnvilResultListener : Listener { // Unit repair val unitRepairResult = AnvilMergeLogic.testUnitRepair( - view, inventory, player, + view, player, leftItem, rightItem ) if (!unitRepairResult.isEmpty()) { @@ -185,7 +184,6 @@ class AnvilResultListener : Listener { // Handle not creative middle click... if (event.click != ClickType.MIDDLE && !handleCustomCraftClick( - event, view, player, leftItem, @@ -203,7 +201,6 @@ class AnvilResultListener : Listener { } private fun handleCustomCraftClick( - event: InventoryClickEvent, view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack?, result: CustomCraftResult diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt index ce263613..eda35fc6 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt @@ -9,8 +9,6 @@ import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.Listener import org.bukkit.event.inventory.PrepareAnvilEvent -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.EnchantmentStorageMeta import org.bukkit.inventory.meta.ItemMeta @@ -92,13 +90,12 @@ class PrepareAnvilListener : Listener { if (!player.hasPermission(CustomAnvil.affectedByPluginPermission)) return - val result = getResult(view, inventory, player, first, second) + val result = getResult(view, player, first, second) applyResult(event, player, result) } fun getResult( - view: InventoryView, //TODO use anvil view - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack?, second: ItemStack? ): AnvilResult { @@ -106,7 +103,7 @@ class PrepareAnvilListener : Listener { return AnvilResult.EMPTY // Test custom recipe - var result: AnvilResult = testCustomRecipe(view, inventory, player, first, second) + var result: AnvilResult = testCustomRecipe(view, player, first, second) if (!result.isEmpty()) return result @@ -114,14 +111,14 @@ class PrepareAnvilListener : Listener { val shouldTryRename = second.isAir CustomAnvil.verboseLog("checking air in main logic: $shouldTryRename") if (shouldTryRename) - return doRenaming(view, inventory, player, first) + return doRenaming(view, player, first) // Test for merge if (first.canMergeWith(second!!)) - return doMerge(view, inventory, player, first, second) + return doMerge(view, player, first, second) // Test for unit repair - result = testUnitRepair(view, inventory, player, first, second) + result = testUnitRepair(view, player, first, second) if (!result.isEmpty()) return result diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index f3131dbf..84171574 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -8,6 +8,7 @@ import org.bukkit.GameMode import org.bukkit.NamespacedKey import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player +import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Repairable @@ -197,7 +198,7 @@ object AnvilXpUtil { return resultSum } - fun onNoResult(player: HumanEntity, view: InventoryView) { + fun onNoResult(player: HumanEntity, view: AnvilView) { if (ConfigOptions.shouldUseMoney(player)) AnvilTitleUtil.rename( view, "Repair & Name", From dbdce37c743de31668c4c4a094ab65dc8f13b145 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Mon, 22 Jun 2026 03:44:18 +0200 Subject: [PATCH 06/41] prepare for v2 --- .github/workflows/gradle.yml | 4 +- build.gradle.kts | 2 +- .../cuanvil/api/AnvilRecipeBuilder.java | 23 --- .../alexcrea/cuanvil/api/ConflictBuilder.java | 2 +- .../alexcrea/cuanvil/api/EnchantmentApi.java | 17 +- .../listener/CAClickResultBypassEvent.java | 2 +- .../listener/CAEarlyPreAnvilBypassEvent.java | 2 +- .../event/listener/CAPreAnvilBypassEvent.java | 2 +- .../listener/CATreatAnvilResult2Event.java | 191 ------------------ .../listener/CATreatAnvilResultEvent.java | 100 ++++----- .../cuanvil/enchant/CAEnchantment.java | 17 +- .../enchant/CAEnchantmentRegistry.java | 18 +- .../cuanvil/dependency/DependencyManager.kt | 8 +- .../dependency/economy/VaultEconomyManager.kt | 2 + .../plugins/ExcellentEnchantsDependency.kt | 4 +- .../cuanvil/group/EnchantConflictManager.kt | 2 +- .../cuanvil/util/anvil/AnvilXpUtil.kt | 3 - .../cuanvil/util/AnvilFuseTestUtil.java | 2 +- 18 files changed, 64 insertions(+), 337 deletions(-) delete mode 100644 src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index befd5102..663bb9b3 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -9,9 +9,9 @@ name: Java CI with Gradle on: push: - branches: [ "v1.x.x", "v2.x.x" ] + branches: [ "v1.x.x", "v2.x.x", "v3.x.x" ] pull_request: - branches: [ "v1.x.x", "v2.x.x" ] + branches: [ "v1.x.x", "v2.x.x", "v3.x.x" ] release: types: [published] diff --git a/build.gradle.kts b/build.gradle.kts index bc335718..214a49f9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.17.6" +version = "2.0.0" val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true" diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/AnvilRecipeBuilder.java b/src/main/java/xyz/alexcrea/cuanvil/api/AnvilRecipeBuilder.java index 4292fa01..c4a52daf 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/AnvilRecipeBuilder.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/AnvilRecipeBuilder.java @@ -90,29 +90,6 @@ public class AnvilRecipeBuilder { return this; } - /** - * Get the xp level cost per craft. (default 0) - * - * @return The xp level cost per craft - * @deprecated use {@link #getLevelCostPerCraft() getLevelCostPerCraft} instead - */ - @Deprecated(since = "1.13.0") - public int getXpCostPerCraft() { - return getLevelCostPerCraft(); - } - - /** - * Sets the xp level cost per craft. - * - * @param xpCostPerCraft The xp level cost per craft - * @return This recipe builder instance. - * @deprecated use {@link #setLevelCostPerCraft(int) setLevelCostPerCraft} instead - */ - @Deprecated(since = "1.13.0") - public AnvilRecipeBuilder setXpCostPerCraft(int xpCostPerCraft) { - return setLevelCostPerCraft(xpCostPerCraft); - } - /** * Get the xp level cost per craft. (default 0) * diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/ConflictBuilder.java b/src/main/java/xyz/alexcrea/cuanvil/api/ConflictBuilder.java index 14607664..df0ccfbf 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/ConflictBuilder.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/ConflictBuilder.java @@ -387,7 +387,7 @@ public class ConflictBuilder { */ protected void appendEnchantments(@NotNull EnchantConflictGroup conflict) { for (String enchantmentName : getEnchantmentNames()) { - if (appendEnchantments(conflict, EnchantmentApi.getListByName(enchantmentName)) == 0) { + if (appendEnchantments(conflict, EnchantmentApi.getByName(enchantmentName)) == 0) { CustomAnvil.instance.getLogger().warning("Could not find enchantment " + enchantmentName + " for conflict " + getName()); ConflictAPI.logConflictOrigin(this); } diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java b/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java index 965d7495..c0a5ff2b 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java @@ -132,27 +132,14 @@ public class EnchantmentApi { return CAEnchantment.getByKey(key); } - /** - * Get by name an enchantment. - * - * @param name The name used to fetch - * @return The custom anvil enchantment of this name. null if not found. - * @deprecated use {@link #getListByName(String)} - */ - @Deprecated(since = "1.6.3") - @Nullable - public static CAEnchantment getByName(@NotNull String name) { - return CAEnchantment.getByName(name); - } - /** * Get list of enchantment using the provided name. * * @param name The name used to fetch * @return List of custom anvil enchantments of this name. May be empty if not found. */ - public static List getListByName(@NotNull String name) { - return CAEnchantment.getListByName(name); + public static List getByName(@NotNull String name) { + return CAEnchantment.getByName(name); } /** diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java index fe5e1993..a27c65e4 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java @@ -17,7 +17,7 @@ import org.jetbrains.annotations.NotNull; * Most of the time you would likely need {@link CAPreAnvilBypassEvent} or {@link CAEarlyPreAnvilBypassEvent} * for this event to be useful. *

- * There is also {@link CATreatAnvilResult2Event} that may be better for some use case. + * There is also {@link CATreatAnvilResultEvent} that may be better for some use case. */ public class CAClickResultBypassEvent extends Event implements Cancellable { diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java index e92b4cdb..2fbd275d 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java @@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull; *

* You should also use {@link CAClickResultBypassEvent} if you want to use this event for something useful. *

- * It is also recommended that you read about {@link CAPreAnvilBypassEvent} and {@link CATreatAnvilResult2Event} + * It is also recommended that you read about {@link CAPreAnvilBypassEvent} and {@link CATreatAnvilResultEvent} * as your use case may be more prone to use theses. */ public class CAEarlyPreAnvilBypassEvent extends Event implements Cancellable { diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java index 9103a4b2..18334e36 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java @@ -18,7 +18,7 @@ import org.jetbrains.annotations.NotNull; *

* You should also use {@link CAClickResultBypassEvent} if you want to use this event for something useful. *

- * It is also recommended that you read about {@link CAEarlyPreAnvilBypassEvent} and {@link CATreatAnvilResult2Event} + * It is also recommended that you read about {@link CAEarlyPreAnvilBypassEvent} and {@link CATreatAnvilResultEvent} * as your use case may be more prone to use theses. */ public class CAPreAnvilBypassEvent extends Event implements Cancellable { diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java deleted file mode 100644 index 5d534d91..00000000 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java +++ /dev/null @@ -1,191 +0,0 @@ -package xyz.alexcrea.cuanvil.api.event.listener; - -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryView; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.view.AnvilView; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import xyz.alexcrea.cuanvil.anvil.AnvilCost; -import xyz.alexcrea.cuanvil.anvil.AnvilUseType; - -/** - * Called after custom anvil processed the click on the result on the anvil inventory. - * This event should be used to modify the result of an anvil use. - *

- * You may also want to check {@link CAClickResultBypassEvent}, - * {@link CAPreAnvilBypassEvent} - * and {@link CAEarlyPreAnvilBypassEvent} for your use case - *

- * A null result will cancel this event - */ -@SuppressWarnings({"unused", "UnstableApiUsage"}) -public class CATreatAnvilResult2Event extends Event { - - private static final HandlerList HANDLERS = new HandlerList(); - - public static HandlerList getHandlerList() { - return HANDLERS; - } - - @Override - public @NotNull HandlerList getHandlers() { - return HANDLERS; - } - - @NotNull - private final AnvilView view; - - private final AnvilUseType useType; - - @Nullable - private final ItemStack left; - @Nullable - private final ItemStack right; - - @Nullable - private ItemStack result; - - private final AnvilCost cost; - - public CATreatAnvilResult2Event( - @NotNull AnvilView view, - AnvilUseType useType, - @Nullable ItemStack result, - AnvilCost cost) { - this.view = view; - this.useType = useType; - - this.left = view.getItem(0); - this.right = view.getItem(1); - this.result = result; - this.cost = cost; - } - - /** - * Get the bukkit inventory view. - * - * @return The inventory view of this event. - */ - public @NotNull AnvilView getView() { - return view; - } - - - /** - * Get the type of use source of the result. - * - * @return The craft use type. - */ - public AnvilUseType getUseType() { - return useType; - } - - /** - * Get the left item of the anvil use - * - * @return the left item - */ - public @Nullable ItemStack getLeftItem() { - return left; - } - - /** - * Get the right item of the anvil use - * - * @return the right item - */ - public @Nullable ItemStack getRightItem() { - return right; - } - - /** - * Get the current result - *

- * note that it will not be null unless another listener previously set it to null. - * - * @return The current result. - */ - public @Nullable ItemStack getResult() { - return result; - } - - /** - * Set the current result - *

- * note that a null result will cancel this anvil use. - * - * @param result The new result - */ - public void setResult(@Nullable ItemStack result) { - this.result = result; - } - - /** - * Get the level cost displayed on the anvil. - *

Important note:

- * the final price are re calculated on click for the following use case: - *
    - *
  • Custom craft
  • - *
  • Unit repair
  • - *
  • Lore edit
  • - *
- * This value will be used as final price for: - *
  • Item merge
  • - *
  • Item rename
  • - * - * - * @return The current cost. - * @deprecated use #{@link #getCost()} instead - */ - @Deprecated(forRemoval = true, since = "1.17.0") - public int getLevelCost() { - return cost.asXpCost(); - } - - /** - * Set the level cost displayed on the anvil. - *

    Important note:

    - * the final price are re calculated on click for the following use case: - *
      - *
    • Custom craft
    • - *
    • Unit repair
    • - *
    • Lore edit
    • - *
    - * This value will be used as final price for: - *
  • Item merge
  • - *
  • Item rename
  • - * - * - * @param levelCost The new cost. - * @deprecated use #{@link #getCost()} and set value on this instead - */ - @Deprecated(forRemoval = true, since = "1.17.0") - public void setLevelCost(int levelCost) { - cost.setGeneric(levelCost - cost.getGeneric() - cost.asXpCost()); - } - - /** - * Allow access to the current cost of the event - * Note that modifying this object will change the event resulting cost - * - *

    Important note:

    - * the final price are re calculated on click for the following use case: - *
      - *
    • Custom craft
    • - *
    • Unit repair
    • - *
    • Lore edit
    • - *
    - * This value will be used as final price for: - *
  • Item merge
  • - *
  • Item rename
  • - * - * @return the current anvil cost - */ - public AnvilCost getCost() { - return cost; - } -} diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java index 80965b57..703a2829 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java @@ -2,8 +2,8 @@ package xyz.alexcrea.cuanvil.api.event.listener; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.bukkit.event.inventory.PrepareAnvilEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.view.AnvilView; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.anvil.AnvilCost; @@ -17,13 +17,9 @@ import xyz.alexcrea.cuanvil.anvil.AnvilUseType; * {@link CAPreAnvilBypassEvent} * and {@link CAEarlyPreAnvilBypassEvent} for your use case *

    - * A null result will cancel this pre anvil event - * - * @deprecated Prepare anvil Event cannot be provided as it can be called on result and therefore not have prepared anvil event - * use {@link CATreatAnvilResult2Event} instead + * A null result will cancel this event */ -@SuppressWarnings("unused") -@Deprecated(forRemoval = true, since = "1.17.0") +@SuppressWarnings({"unused", "UnstableApiUsage"}) public class CATreatAnvilResultEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); @@ -38,31 +34,44 @@ public class CATreatAnvilResultEvent extends Event { } @NotNull - private final PrepareAnvilEvent event; + private final AnvilView view; private final AnvilUseType useType; + @Nullable + private final ItemStack left; + @Nullable + private final ItemStack right; + @Nullable private ItemStack result; private final AnvilCost cost; - public CATreatAnvilResultEvent(@NotNull PrepareAnvilEvent event, AnvilUseType useType, @Nullable ItemStack result, AnvilCost cost) { - this.event = event; + public CATreatAnvilResultEvent( + @NotNull AnvilView view, + AnvilUseType useType, + @Nullable ItemStack result, + AnvilCost cost) { + this.view = view; this.useType = useType; + + this.left = view.getItem(0); + this.right = view.getItem(1); this.result = result; this.cost = cost; } /** - * Get the bukkit inventory click event causing to this event. + * Get the bukkit inventory view. * - * @return The click event causing to this event. + * @return The inventory view of this event. */ - public @NotNull PrepareAnvilEvent getEvent() { - return event; + public @NotNull AnvilView getView() { + return view; } + /** * Get the type of use source of the result. * @@ -72,6 +81,24 @@ public class CATreatAnvilResultEvent extends Event { return useType; } + /** + * Get the left item of the anvil use + * + * @return the left item + */ + public @Nullable ItemStack getLeftItem() { + return left; + } + + /** + * Get the right item of the anvil use + * + * @return the right item + */ + public @Nullable ItemStack getRightItem() { + return right; + } + /** * Get the current result *

    @@ -94,50 +121,6 @@ public class CATreatAnvilResultEvent extends Event { this.result = result; } - /** - * Get the level cost displayed on the anvil. - *

    Important note:

    - * the final price are re calculated on click for the following use case: - *
      - *
    • Custom craft
    • - *
    • Unit repair
    • - *
    • Lore edit
    • - *
    - * This value will be used as final price for: - *
  • Item merge
  • - *
  • Item rename
  • - * - * - * @return The current cost. - * @deprecated use #{@link #getCost()} instead - */ - @Deprecated(forRemoval = true, since = "1.17.0") - public int getLevelCost() { - return cost.asXpCost(); - } - - /** - * Set the level cost displayed on the anvil. - *

    Important note:

    - * the final price are re calculated on click for the following use case: - *
      - *
    • Custom craft
    • - *
    • Unit repair
    • - *
    • Lore edit
    • - *
    - * This value will be used as final price for: - *
  • Item merge
  • - *
  • Item rename
  • - * - * - * @param levelCost The new cost. - * @deprecated use #{@link #getCost()} and set value on this instead - */ - @Deprecated(forRemoval = true, since = "1.17.0") - public void setLevelCost(int levelCost) { - cost.setGeneric(levelCost - cost.getGeneric() - cost.asXpCost()); - } - /** * Allow access to the current cost of the event * Note that modifying this object will change the event resulting cost @@ -158,5 +141,4 @@ public class CATreatAnvilResultEvent extends Event { public AnvilCost getCost() { return cost; } - } diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java index ea657ace..5c747faf 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java @@ -225,25 +225,14 @@ public interface CAEnchantment { return CAEnchantmentRegistry.getInstance().getByKey(key); } - /** - * Gets the enchantment by the provided name. - * @param name Name to fetch. - * @return Registered enchantment. null if absent. - * - * @deprecated use {@link #getListByName(String)} - */ - @Deprecated(since = "1.6.3") - static @Nullable CAEnchantment getByName(@NotNull String name){ - return CAEnchantmentRegistry.getInstance().getByName(name); - } - /** * Gets list of enchantment using the provided name. + * * @param name Name to fetch. * @return List of registered enchantment. */ - static List getListByName(@NotNull String name){ - return CAEnchantmentRegistry.getInstance().getListByName(name); + static List getByName(@NotNull String name){ + return CAEnchantmentRegistry.getInstance().getByName(name); } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantmentRegistry.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantmentRegistry.java index 854ed55c..ec83616d 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantmentRegistry.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantmentRegistry.java @@ -155,22 +155,6 @@ public class CAEnchantmentRegistry { return byKeyMap.get(key); } - /** - * Gets the enchantment by the provided name. - * - * @param name Name to fetch. - * @return Registered enchantment. null if absent. - * @deprecated use {@link #getListByName(String)} - */ - @Deprecated(since = "1.6.3") - @Nullable - public CAEnchantment getByName(@NotNull String name) { - List enchantments = getListByName(name); - if (enchantments.isEmpty()) return null; - - return enchantments.get(0); - } - /** * Gets list of enchantment using the provided name. * @@ -178,7 +162,7 @@ public class CAEnchantmentRegistry { * @return List of registered enchantment. */ @NotNull - public List getListByName(@NotNull String name) { + public List getByName(@NotNull String name) { return byNameMap.getOrDefault(name, Collections.emptyList()); } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index 3558bcf0..50743d81 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -10,13 +10,13 @@ import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.inventory.ItemStack -import xyz.alexcrea.cuanvil.anvil.AnvilCost import org.bukkit.inventory.view.AnvilView +import xyz.alexcrea.cuanvil.anvil.AnvilCost import xyz.alexcrea.cuanvil.anvil.AnvilUseType import xyz.alexcrea.cuanvil.api.event.listener.CAClickResultBypassEvent import xyz.alexcrea.cuanvil.api.event.listener.CAEarlyPreAnvilBypassEvent import xyz.alexcrea.cuanvil.api.event.listener.CAPreAnvilBypassEvent -import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResult2Event +import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResultEvent import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.dependency.datapack.DataPackDependency import xyz.alexcrea.cuanvil.dependency.gui.GenericExternGuiTester @@ -237,7 +237,7 @@ object DependencyManager { useType: AnvilUseType, cost: AnvilCost ): ItemStack? { - val treatEvent = CATreatAnvilResult2Event(view, useType, result, cost) + val treatEvent = CATreatAnvilResultEvent(view, useType, result, cost) try { unsafeTryTreatAnvilResult(treatEvent) return treatEvent.result @@ -247,7 +247,7 @@ object DependencyManager { } } - private fun unsafeTryTreatAnvilResult(event: CATreatAnvilResult2Event) { + private fun unsafeTryTreatAnvilResult(event: CATreatAnvilResultEvent) { Bukkit.getPluginManager().callEvent(event) excellentEnchantsCompatibility?.treatAnvilResult(event) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/economy/VaultEconomyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/economy/VaultEconomyManager.kt index 058485e2..23d22b52 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/economy/VaultEconomyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/economy/VaultEconomyManager.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package xyz.alexcrea.cuanvil.dependency.economy import net.milkbowl.vault.economy.Economy diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt index d3d46ccc..9370decd 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt @@ -8,7 +8,7 @@ import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.inventory.ItemStack import org.bukkit.plugin.RegisteredListener import xyz.alexcrea.cuanvil.api.EnchantmentApi -import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResult2Event +import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResultEvent import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEPreV5Enchantment import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5Enchantment import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5_4Enchantment @@ -222,7 +222,7 @@ class ExcellentEnchantsDependency { return handleRechargeMethod.invoke(this.usedAnvilListener, event, first, second) as Boolean } - fun treatAnvilResult(event: CATreatAnvilResult2Event) { + fun treatAnvilResult(event: CATreatAnvilResultEvent) { val result = event.result ?: return val first: ItemStack = treatInput(event.leftItem) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index 88757c70..d1a49856 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -179,7 +179,7 @@ class EnchantConflictManager { } } - return CAEnchantment.getListByName(enchantName) + return CAEnchantment.getByName(enchantName) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index 84171574..55847180 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -8,8 +8,6 @@ import org.bukkit.GameMode import org.bukkit.NamespacedKey import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Repairable import org.bukkit.inventory.view.AnvilView @@ -84,7 +82,6 @@ object AnvilXpUtil { // Try first just in case another plugin, or the test need this view.maximumRepairCost = maximumRepairCost view.repairCost = anvilCost - // TODO for 2.x.x use anvil view & set directly there /* Because Minecraft likes to have the final say in the repair cost displayed * we need to wait for the event to end before overriding it, this ensures that diff --git a/src/test/java/xyz/alexcrea/cuanvil/util/AnvilFuseTestUtil.java b/src/test/java/xyz/alexcrea/cuanvil/util/AnvilFuseTestUtil.java index fefec130..75af4db3 100644 --- a/src/test/java/xyz/alexcrea/cuanvil/util/AnvilFuseTestUtil.java +++ b/src/test/java/xyz/alexcrea/cuanvil/util/AnvilFuseTestUtil.java @@ -71,7 +71,7 @@ public class AnvilFuseTestUtil { List enchantments = new ArrayList<>(); for (String enchantmentName : enchantmentNames) { - List enchantmentList = CAEnchantment.getListByName(enchantmentName); + List enchantmentList = CAEnchantment.getByName(enchantmentName); Assertions.assertNotEquals(0, enchantmentList.size(), "Could not find enchantment \"" + enchantmentName + "\""); From 2bf913293b927c435b0df172720fb43c2fc87733 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 30 Jun 2026 23:35:00 +0200 Subject: [PATCH 07/41] rebase on news update --- .../xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt | 2 +- .../kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index 7d750d06..2bfc97d0 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -115,7 +115,7 @@ class AnvilResultListener : Listener { if(!worked) { CustomAnvil.verboseLog("Merge extract failed. reset the displayed price") // Reset the price - AnvilXpUtil.setAnvilResult(inventory, view, player, result) + AnvilXpUtil.setAnvilResult(view, player, result) } return } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index 55847180..ae8a8035 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -32,8 +32,7 @@ object AnvilXpUtil { * Display the required cost (either as xp or as money) or reset anvil price depending on result */ fun setAnvilResult( - inventory: AnvilInventory, - view: InventoryView, + view: AnvilView, player: Player, result: AnvilResult) { if(result.item == null) { @@ -41,7 +40,7 @@ object AnvilXpUtil { return } - setAnvilInvCost(inventory, view, player, result.cost, result.ignoreXpRules) + setAnvilInvCost(view, player, result.cost, result.ignoreXpRules) } /** From 26bba65a9ddb68f81a5894669853f13a331729c4 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 30 Jun 2026 23:47:16 +0200 Subject: [PATCH 08/41] remove legacy command --- src/main/kotlin/io/delilaheve/CustomAnvil.kt | 12 +----- .../alexcrea/cuanvil/command/CASubCommand.kt | 37 +++---------------- .../cuanvil/command/DebugToggleExecutor.kt | 2 +- .../cuanvil/command/DiagnosticExecutor.kt | 11 +++--- .../cuanvil/command/EditConfigExecutor.kt | 9 ++++- .../alexcrea/cuanvil/command/HelpExecutor.kt | 13 ++++++- .../cuanvil/command/ReloadExecutor.kt | 9 ++++- src/main/resources/plugin.yml | 12 ------ 8 files changed, 41 insertions(+), 64 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 321165e5..5abf1719 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -142,7 +142,7 @@ open class CustomAnvil : JavaPlugin() { // Add commands try { - prepareCommand() + CustomAnvilCommand(this) } catch (e: Exception) { logger.log(Level.SEVERE, "error trying to register commands", e) MetricsUtil.trackError(e) @@ -326,14 +326,4 @@ open class CustomAnvil : JavaPlugin() { return yamlConfig } - fun prepareCommand() { - var command = getCommand(commandReloadName) - command?.setExecutor(ReloadExecutor()) - - command = getCommand(commandConfigName) - command?.setExecutor(EditConfigExecutor()) - - CustomAnvilCommand(this) - } - } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt index 5df484ee..e76009ad 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt @@ -1,50 +1,25 @@ package xyz.alexcrea.cuanvil.command -import org.bukkit.ChatColor import org.bukkit.command.Command -import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender -abstract class CASubCommand : CommandExecutor { +interface CASubCommand { - private var alreadySaid = false; - override fun onCommand( - sender: CommandSender, - cmd: Command, - cmdstr: String, - args: Array - ): Boolean { - if (!alreadySaid) { - sender.sendMessage( - ChatColor.RED.toString() + - "Please not that this command will be replaced as a subcommand of `/customanvil` or `/ca`" - ) - alreadySaid = true - } - - return executeCommand(sender, cmd, cmdstr, args) - } - - abstract fun executeCommand( + fun executeCommand( sender: CommandSender, cmd: Command, cmdstr: String, args: Array ): Boolean - open fun allowed(sender: CommandSender): Boolean { - return true - } + fun allowed(sender: CommandSender): Boolean - open fun tabCompleter( + fun tabCompleter( sender: CommandSender, args: Array, list: MutableList - ) { - } + ) - open fun description(): String { - return "no description" - } + fun description(): String } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt index c668e6e0..302ff782 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt @@ -12,7 +12,7 @@ import org.bukkit.command.CommandSender import org.bukkit.entity.Player import xyz.alexcrea.cuanvil.command.DiagnosticExecutor.Companion.NO_DIAG_PERM -class DebugToggleExecutor : CASubCommand() { +class DebugToggleExecutor : CASubCommand { override fun description(): String { return "Used to toggle debug logs and retrieve it" diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt index b7bb1dd9..efbf2902 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt @@ -30,8 +30,7 @@ import xyz.alexcrea.cuanvil.util.MetricsUtil import java.util.* import java.util.stream.Collectors - -class DiagnosticExecutor : CASubCommand() { +class DiagnosticExecutor : CASubCommand { companion object { const val NO_DIAG_PERM = "You do not have permission to diagnostic this server" @@ -327,10 +326,10 @@ class DiagnosticExecutor : CASubCommand() { stb.append( "\nNamespaces: ${ - map.entries.stream() - .map { (key, value) -> "$key ($value)" } - .reduce { a, b -> "$a, $b" }.get() - }" + map.entries.stream() + .map { (key, value) -> "$key ($value)" } + .reduce { a, b -> "$a, $b" }.get() + }" ) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index 8ff662f9..53608818 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -8,7 +8,7 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil import xyz.alexcrea.cuanvil.gui.config.MainConfigGui import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions -class EditConfigExecutor : CASubCommand() { +class EditConfigExecutor : CASubCommand { override fun executeCommand( sender: CommandSender, @@ -40,6 +40,13 @@ class EditConfigExecutor : CASubCommand() { return sender.hasPermission(CustomAnvil.editConfigPermission) } + override fun tabCompleter( + sender: CommandSender, + args: Array, + list: MutableList + ) { + } + override fun description(): String { return "Gui to edit the plugin's config" } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt index 1314d0ec..c6c4d08c 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt @@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableMap import org.bukkit.command.Command import org.bukkit.command.CommandSender -class HelpExecutor : CASubCommand() { +class HelpExecutor : CASubCommand { lateinit var commands: ImmutableMap @@ -27,6 +27,17 @@ class HelpExecutor : CASubCommand() { return true } + override fun allowed(sender: CommandSender): Boolean { + return true + } + + override fun tabCompleter( + sender: CommandSender, + args: Array, + list: MutableList + ) { + } + override fun description(): String { return "Help command" } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt index ab832c4f..d3df341a 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt @@ -10,7 +10,7 @@ import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.gui.config.global.* import xyz.alexcrea.cuanvil.update.UpdateHandler -class ReloadExecutor : CASubCommand() { +class ReloadExecutor : CASubCommand { override fun executeCommand( sender: CommandSender, @@ -40,6 +40,13 @@ class ReloadExecutor : CASubCommand() { return sender.hasPermission(CustomAnvil.commandReloadPermission) } + override fun tabCompleter( + sender: CommandSender, + args: Array, + list: MutableList + ) { + } + override fun description(): String { return "Reload the configuration of this plugin" } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9ee330f5..199e0e51 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -14,18 +14,6 @@ commands: description: Generic command for custom anvil aliases: - ca - anvilconfigreload: - description: Reload every config of this plugin - permission: ca.command.reload - aliases: - #- acreload # anvil config reload - #- careload # custom anvil reload - - carl # custom anvil reload - customanvilconfig: - description: open a menu for administrator to edit plugin's config in game - permission: ca.config.edit - aliases: - - configanvil permissions: ca.affected: From 45dd92e0f4a2286380efb0d5292d8694de7498bd Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 10:15:34 +0200 Subject: [PATCH 09/41] prefer /ca reload over /configanvilreload --- COMPATIBILITY.md | 2 +- defaultconfigs/1.18/config.yml | 2 +- defaultconfigs/1.18/enchant_conflict.yml | 2 +- defaultconfigs/1.18/item_groups.yml | 2 +- defaultconfigs/1.18/unit_repair_item.yml | 2 +- defaultconfigs/1.21.11/config.yml | 2 +- defaultconfigs/1.21.11/enchant_conflict.yml | 2 +- defaultconfigs/1.21.11/item_groups.yml | 2 +- defaultconfigs/1.21.11/unit_repair_item.yml | 4 ++-- defaultconfigs/1.21.9/config.yml | 2 +- defaultconfigs/1.21.9/enchant_conflict.yml | 2 +- defaultconfigs/1.21.9/item_groups.yml | 2 +- defaultconfigs/1.21.9/unit_repair_item.yml | 4 ++-- defaultconfigs/1.21/config.yml | 2 +- defaultconfigs/1.21/enchant_conflict.yml | 5 +---- defaultconfigs/1.21/item_groups.yml | 2 +- defaultconfigs/1.21/unit_repair_item.yml | 4 ++-- .../xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt | 2 +- src/main/resources/config.yml | 2 +- src/main/resources/enchant_conflict.yml | 2 +- src/main/resources/item_groups.yml | 2 +- src/main/resources/unit_repair_item.yml | 2 +- 22 files changed, 25 insertions(+), 28 deletions(-) diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 9d37521c..d3cfd8b3 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -17,7 +17,7 @@ These plugins have compatibility handled by custom anvil. seek help on custom an Also use ExcellentEnchant max enchant limit - [EcoEnchant](https://www.spigotmc.org/resources/ecoenchants-%E2%AD%95-250-enchantments-%E2%9C%85-create-custom-enchants-%E2%9C%A8-essentials-cmi-support.79573/) by Auxilor: - Need to use /anvilconfigreload or a server restart to add newly added enchantment. + Need to use /ca reload or a server restart to add newly added enchantment. Use EcoEnchant restriction system but new restriction can be added in custom anvil - [Enchantment²](https://www.spigotmc.org/resources/enchants-squared-the-enchantsplus-rewrite-custom-enchantments-that-act-like-vanilla-ones.86747/) by Athlaeos: diff --git a/defaultconfigs/1.18/config.yml b/defaultconfigs/1.18/config.yml index 4e08ca20..377b3499 100644 --- a/defaultconfigs/1.18/config.yml +++ b/defaultconfigs/1.18/config.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # What service of metric should custom anvil use diff --git a/defaultconfigs/1.18/enchant_conflict.yml b/defaultconfigs/1.18/enchant_conflict.yml index 45d62c34..31506d2b 100644 --- a/defaultconfigs/1.18/enchant_conflict.yml +++ b/defaultconfigs/1.18/enchant_conflict.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # material conflicts diff --git a/defaultconfigs/1.18/item_groups.yml b/defaultconfigs/1.18/item_groups.yml index 3c1eb5d0..6963d2e4 100644 --- a/defaultconfigs/1.18/item_groups.yml +++ b/defaultconfigs/1.18/item_groups.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Please note this config use spigot material names. diff --git a/defaultconfigs/1.18/unit_repair_item.yml b/defaultconfigs/1.18/unit_repair_item.yml index 2902cce4..98fd0bec 100644 --- a/defaultconfigs/1.18/unit_repair_item.yml +++ b/defaultconfigs/1.18/unit_repair_item.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Unit repair configuration diff --git a/defaultconfigs/1.21.11/config.yml b/defaultconfigs/1.21.11/config.yml index 98f9a94d..c756ad11 100644 --- a/defaultconfigs/1.21.11/config.yml +++ b/defaultconfigs/1.21.11/config.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # What service of metric should custom anvil use diff --git a/defaultconfigs/1.21.11/enchant_conflict.yml b/defaultconfigs/1.21.11/enchant_conflict.yml index 3d62daeb..874698ca 100644 --- a/defaultconfigs/1.21.11/enchant_conflict.yml +++ b/defaultconfigs/1.21.11/enchant_conflict.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # material conflicts diff --git a/defaultconfigs/1.21.11/item_groups.yml b/defaultconfigs/1.21.11/item_groups.yml index 9f2a877e..5d24cacf 100644 --- a/defaultconfigs/1.21.11/item_groups.yml +++ b/defaultconfigs/1.21.11/item_groups.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Please note this config use spigot material names. diff --git a/defaultconfigs/1.21.11/unit_repair_item.yml b/defaultconfigs/1.21.11/unit_repair_item.yml index ed981b18..d742a056 100644 --- a/defaultconfigs/1.21.11/unit_repair_item.yml +++ b/defaultconfigs/1.21.11/unit_repair_item.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Unit repair configuration @@ -104,7 +104,7 @@ leather: phantom_membrane: elytra: 0.25 -scute: +turtle_scute: turtle_helmet: 0.25 oak_planks: diff --git a/defaultconfigs/1.21.9/config.yml b/defaultconfigs/1.21.9/config.yml index 7b3afce1..55431386 100644 --- a/defaultconfigs/1.21.9/config.yml +++ b/defaultconfigs/1.21.9/config.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # What service of metric should custom anvil use diff --git a/defaultconfigs/1.21.9/enchant_conflict.yml b/defaultconfigs/1.21.9/enchant_conflict.yml index 9205061e..4db5c912 100644 --- a/defaultconfigs/1.21.9/enchant_conflict.yml +++ b/defaultconfigs/1.21.9/enchant_conflict.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # material conflicts diff --git a/defaultconfigs/1.21.9/item_groups.yml b/defaultconfigs/1.21.9/item_groups.yml index 2dbd5db6..f7a00bcc 100644 --- a/defaultconfigs/1.21.9/item_groups.yml +++ b/defaultconfigs/1.21.9/item_groups.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Please note this config use spigot material names. diff --git a/defaultconfigs/1.21.9/unit_repair_item.yml b/defaultconfigs/1.21.9/unit_repair_item.yml index 0ce2bce5..122b9657 100644 --- a/defaultconfigs/1.21.9/unit_repair_item.yml +++ b/defaultconfigs/1.21.9/unit_repair_item.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Unit repair configuration @@ -98,7 +98,7 @@ leather: phantom_membrane: elytra: 0.25 -scute: +turtle_scute: turtle_helmet: 0.25 oak_planks: diff --git a/defaultconfigs/1.21/config.yml b/defaultconfigs/1.21/config.yml index cb7e382b..5b23efbf 100644 --- a/defaultconfigs/1.21/config.yml +++ b/defaultconfigs/1.21/config.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # What service of metric should custom anvil use diff --git a/defaultconfigs/1.21/enchant_conflict.yml b/defaultconfigs/1.21/enchant_conflict.yml index 45d62c34..0af1be6e 100644 --- a/defaultconfigs/1.21/enchant_conflict.yml +++ b/defaultconfigs/1.21/enchant_conflict.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # material conflicts @@ -160,10 +160,7 @@ restriction_sweeping_edge: enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ] notAffectedGroups: [ enchanted_book, swords ] -# Do not exist in 1.18, that mean useInFuture will be set to true -# useInFuture set to true also mean it will not warn if there is an issue restriction_swift_sneak: - useInFuture: true enchantments: [ minecraft:swift_sneak ] notAffectedGroups: [ enchanted_book, leggings ] diff --git a/defaultconfigs/1.21/item_groups.yml b/defaultconfigs/1.21/item_groups.yml index 3c1eb5d0..6963d2e4 100644 --- a/defaultconfigs/1.21/item_groups.yml +++ b/defaultconfigs/1.21/item_groups.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Please note this config use spigot material names. diff --git a/defaultconfigs/1.21/unit_repair_item.yml b/defaultconfigs/1.21/unit_repair_item.yml index 2902cce4..b7873a12 100644 --- a/defaultconfigs/1.21/unit_repair_item.yml +++ b/defaultconfigs/1.21/unit_repair_item.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Unit repair configuration @@ -98,7 +98,7 @@ leather: phantom_membrane: elytra: 0.25 -scute: +turtle_scute: turtle_helmet: 0.25 oak_planks: diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index fba89b71..d26db8c2 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -25,7 +25,7 @@ class EditConfigExecutor: CASubCommand() { sender.sendMessage("§eIt is may come in a future version.") sender.sendMessage("") sender.sendMessage("§eCurrently you need to edit manually the config or copy from another server (spigot or better)") - sender.sendMessage("§eThen /anvilconfigreload after config file is edited") + sender.sendMessage("§eThen /ca reload after config file is edited") return false } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c8fefb53..0a0c5664 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit most of these config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # What service of metric should custom anvil use diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml index 45d62c34..31506d2b 100644 --- a/src/main/resources/enchant_conflict.yml +++ b/src/main/resources/enchant_conflict.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # material conflicts diff --git a/src/main/resources/item_groups.yml b/src/main/resources/item_groups.yml index 8a62f3dc..f2042f03 100644 --- a/src/main/resources/item_groups.yml +++ b/src/main/resources/item_groups.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Please note this config use spigot material names. diff --git a/src/main/resources/unit_repair_item.yml b/src/main/resources/unit_repair_item.yml index 2902cce4..98fd0bec 100644 --- a/src/main/resources/unit_repair_item.yml +++ b/src/main/resources/unit_repair_item.yml @@ -1,6 +1,6 @@ # # It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /anvilconfigreload after you changes ! +# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! # # Unit repair configuration From f1c3cf46e16919e386d0840dc6dc2162cc8a09f5 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 12:13:13 +0200 Subject: [PATCH 10/41] fix turtle scule unit repair and force migratation of sweeping edge --- build.gradle.kts | 2 +- defaultconfigs/1.21.11/config.yml | 6 +- defaultconfigs/1.21.11/enchant_conflict.yml | 1 - defaultconfigs/1.21.9/config.yml | 4 - defaultconfigs/1.21.9/enchant_conflict.yml | 1 - defaultconfigs/1.21/config.yml | 4 - defaultconfigs/1.21/enchant_conflict.yml | 2 +- .../cuanvil/update/UpdateHandler.java | 9 +- .../alexcrea/cuanvil/update/UpdateUtils.java | 17 ++++ .../update/minecraft/Update_1_20_5.java | 98 +++++++++++++++++++ .../cuanvil/update/plugin/PUpdate_1_17_7.java | 21 ++++ 11 files changed, 143 insertions(+), 22 deletions(-) create mode 100644 src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_20_5.java create mode 100644 src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java diff --git a/build.gradle.kts b/build.gradle.kts index 4436e29e..76ab4c00 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.17.6" +version = "1.17.7" val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true" diff --git a/defaultconfigs/1.21.11/config.yml b/defaultconfigs/1.21.11/config.yml index c756ad11..8b5747b1 100644 --- a/defaultconfigs/1.21.11/config.yml +++ b/defaultconfigs/1.21.11/config.yml @@ -154,7 +154,6 @@ enchant_limits: minecraft:knockback: 2 minecraft:fire_aspect: 2 minecraft:looting: 3 - minecraft:sweeping: 3 minecraft:sweeping_edge: 3 minecraft:efficiency: 5 minecraft:unbreaking: 3 @@ -293,9 +292,6 @@ enchant_values: minecraft:swift_sneak: item: 8 book: 4 - minecraft:sweeping: - item: 4 - book: 2 minecraft:sweeping_edge: item: 4 book: 2 @@ -489,5 +485,5 @@ debug_log_verbose: false # Whether to show inside the console or require to run /ca debug get display_debug_in_console: false -configVersion: 1.15.5 +configVersion: 1.17.7 lowMinecraftVersion: 1.21.11 diff --git a/defaultconfigs/1.21.11/enchant_conflict.yml b/defaultconfigs/1.21.11/enchant_conflict.yml index 874698ca..18341d36 100644 --- a/defaultconfigs/1.21.11/enchant_conflict.yml +++ b/defaultconfigs/1.21.11/enchant_conflict.yml @@ -270,7 +270,6 @@ restriction_soul_speed: restriction_sweeping_edge: enchantments: - - minecraft:sweeping - minecraft:sweeping_edge notAffectedGroups: - enchanted_book diff --git a/defaultconfigs/1.21.9/config.yml b/defaultconfigs/1.21.9/config.yml index 55431386..c7700969 100644 --- a/defaultconfigs/1.21.9/config.yml +++ b/defaultconfigs/1.21.9/config.yml @@ -152,7 +152,6 @@ enchant_limits: minecraft:knockback: 2 minecraft:fire_aspect: 2 minecraft:looting: 3 - minecraft:sweeping: 3 minecraft:sweeping_edge: 3 minecraft:efficiency: 5 minecraft:unbreaking: 3 @@ -290,9 +289,6 @@ enchant_values: minecraft:swift_sneak: item: 8 book: 4 - minecraft:sweeping: - item: 4 - book: 2 minecraft:sweeping_edge: item: 4 book: 2 diff --git a/defaultconfigs/1.21.9/enchant_conflict.yml b/defaultconfigs/1.21.9/enchant_conflict.yml index 4db5c912..8ab9e3bc 100644 --- a/defaultconfigs/1.21.9/enchant_conflict.yml +++ b/defaultconfigs/1.21.9/enchant_conflict.yml @@ -267,7 +267,6 @@ restriction_soul_speed: restriction_sweeping_edge: enchantments: - - minecraft:sweeping - minecraft:sweeping_edge notAffectedGroups: - enchanted_book diff --git a/defaultconfigs/1.21/config.yml b/defaultconfigs/1.21/config.yml index 5b23efbf..1ef0d102 100644 --- a/defaultconfigs/1.21/config.yml +++ b/defaultconfigs/1.21/config.yml @@ -152,7 +152,6 @@ enchant_limits: minecraft:knockback: 2 minecraft:fire_aspect: 2 minecraft:looting: 3 - minecraft:sweeping: 3 minecraft:sweeping_edge: 3 minecraft:efficiency: 5 minecraft:unbreaking: 3 @@ -287,9 +286,6 @@ enchant_values: minecraft:swift_sneak: item: 8 book: 4 - minecraft:sweeping: - item: 4 - book: 2 minecraft:sweeping_edge: item: 4 book: 2 diff --git a/defaultconfigs/1.21/enchant_conflict.yml b/defaultconfigs/1.21/enchant_conflict.yml index 0af1be6e..d3b5d33c 100644 --- a/defaultconfigs/1.21/enchant_conflict.yml +++ b/defaultconfigs/1.21/enchant_conflict.yml @@ -157,7 +157,7 @@ restriction_soul_speed: notAffectedGroups: [ enchanted_book, boots ] restriction_sweeping_edge: - enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ] + enchantments: [ minecraft:sweeping_edge ] notAffectedGroups: [ enchanted_book, swords ] restriction_swift_sneak: diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java index 660accb0..c548f228 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java @@ -2,10 +2,7 @@ package xyz.alexcrea.cuanvil.update; import io.delilaheve.CustomAnvil; import xyz.alexcrea.cuanvil.config.ConfigHolder; -import xyz.alexcrea.cuanvil.update.minecraft.MCUpdate; -import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21; -import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21_11; -import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21_9; +import xyz.alexcrea.cuanvil.update.minecraft.*; import xyz.alexcrea.cuanvil.update.plugin.*; import javax.annotation.Nonnull; @@ -32,10 +29,12 @@ public class UpdateHandler { new Version(1, 8, 0), PUpdate_1_8_0::handleUpdate, new Version(1, 11, 0), PUpdate_1_11_0::handleUpdate, new Version(1, 15, 5), PUpdate_1_15_5::handleUpdate, - new Version(1, 15, 6), PUpdate_1_15_6::handleUpdate + new Version(1, 15, 6), PUpdate_1_15_6::handleUpdate, + new Version(1, 17, 7), PUpdate_1_17_7::handleUpdate ); private static final List mcUpdateMap = List.of( + new Update_1_20_5(), new Update_1_21(), new Update_1_21_9(), new Update_1_21_11() diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java index 2907fefb..4577b7a5 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.update; import org.bukkit.Bukkit; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import java.util.ArrayList; @@ -33,4 +34,20 @@ public class UpdateUtils { } + public static boolean removeFromList(FileConfiguration config, String path, String toRemove) { + List groups = new ArrayList<>(config.getStringList(path)); + if (!groups.remove(toRemove)) return false; + + config.set(path, groups); + return true; + } + + public static void mergeSections(ConfigurationSection source, ConfigurationSection target) { + for (String key : source.getKeys(false)) { + if(target.contains(key)) continue; + target.set(key, source.get(key)); + } + } + + } diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_20_5.java b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_20_5.java new file mode 100644 index 00000000..53b996a6 --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_20_5.java @@ -0,0 +1,98 @@ +package xyz.alexcrea.cuanvil.update.minecraft; + +import org.bukkit.configuration.file.FileConfiguration; +import org.jetbrains.annotations.NotNull; +import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.update.Version; + +import java.util.HashSet; +import java.util.Set; + +import static xyz.alexcrea.cuanvil.update.UpdateUtils.*; + +public class Update_1_20_5 extends MCUpdate { + + public Update_1_20_5() { + super(new Version(1, 20, 5)); + } + + @Override + protected void doUpdate() { + var tosave = new HashSet(); + updateName(tosave); + + for (ConfigHolder holder : tosave) { + holder.saveToDisk(true); + } + } + + private static String SWEEPING_ENCHANTS = "restriction_sweeping_edge.enchantments"; + + public static void updateName(@NotNull Set tosave) { + var config = ConfigHolder.DEFAULT_CONFIG.getConfig(); + var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); + var conflict = ConfigHolder.CONFLICT_HOLDER.getConfig(); + + // Rename sweeping to sweeping_edge + migrateEnchantLimit(config, "minecraft:sweeping"); + migrateEnchantLimit(config, "sweeping"); + + migrateEnchantValues(config, "minecraft:sweeping"); + migrateEnchantValues(config, "sweeping"); + + if (removeFromList(conflict, SWEEPING_ENCHANTS, "minecraft:sweeping")) + addAbsentToList(conflict, SWEEPING_ENCHANTS, "minecraft:sweeping_edge"); + if (removeFromList(conflict, SWEEPING_ENCHANTS, "sweeping")) + addAbsentToList(conflict, SWEEPING_ENCHANTS, "minecraft:sweeping_edge"); + + // Rename scute to turtle_scute + migrateUnitRepair(unitConfig, "minecraft:scute"); + migrateUnitRepair(unitConfig, "scute"); + + ConfigHolder.ITEM_GROUP_HOLDER.reload(); + + tosave.add(ConfigHolder.DEFAULT_CONFIG); + tosave.add(ConfigHolder.UNIT_REPAIR_HOLDER); + tosave.add(ConfigHolder.CONFLICT_HOLDER); + } + + private static void migrateEnchantLimit(FileConfiguration config, String path) { + var finalPath = "enchant_limits." + path; + if (!config.isInt(finalPath)) return; + var value = config.getInt(finalPath); + + config.set(finalPath, null); + if (!config.contains("enchant_limits.minecraft:sweeping_edge")) return; + if (!config.contains("enchant_limits.sweeping_edge")) return; + + config.set("enchant_limits.minecraft:sweeping_edge", value); + } + + private static void migrateEnchantValues(FileConfiguration config, String path) { + migrateEnchantValues(config, path, "item"); + migrateEnchantValues(config, path, "book"); + } + + private static void migrateEnchantValues(FileConfiguration config, String path, String child) { + var finalPath = "enchant_values." + path + "." + child; + if (config.isInt(finalPath)) return; + var value = config.getInt(finalPath); + + config.set(finalPath, null); + if (!config.contains("enchant_values.minecraft:sweeping_edge." + child)) return; + if (!config.contains("enchant_values.sweeping_edge." + child)) return; + + config.set("enchant_values.minecraft:sweeping_edge." + child, value); + } + + private static void migrateUnitRepair(FileConfiguration config, String path) { + var section = config.getConfigurationSection(path); + if (section == null) return; + + config.set(path, null); + var turtle_scute = config.getConfigurationSection("minecraft:turtle_scute"); + if (turtle_scute == null) config.set("minecraft:turtle_scute", section); + else mergeSections(section, turtle_scute); + } + +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java b/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java new file mode 100644 index 00000000..972825dd --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_17_7.java @@ -0,0 +1,21 @@ +package xyz.alexcrea.cuanvil.update.plugin; + +import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.update.UpdateUtils; +import xyz.alexcrea.cuanvil.update.Version; +import xyz.alexcrea.cuanvil.update.minecraft.Update_1_20_5; + +import javax.annotation.Nonnull; +import java.util.Set; + +public class PUpdate_1_17_7 { + + public static void handleUpdate(@Nonnull Set toSave) { + // fix only needed for 1.20.5 and above + Version current = UpdateUtils.currentMinecraftVersion(); + if (new Version(1, 20, 5).greaterThan(current)) return; + + Update_1_20_5.updateName(toSave); + } + +} From d67d998dc17be7fd767269f07f3f681d1b85da5f Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 12:16:04 +0200 Subject: [PATCH 11/41] remove legacy compatibility code --- .../io/delilaheve/util/ConfigOptions.kt | 22 +------------------ .../cuanvil/group/EnchantConflictManager.kt | 15 ------------- 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index fc8a53a9..dddb64d7 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -613,20 +613,9 @@ object ConfigOptions { * Get default value if enchantment do not exist on config */ private fun getDefaultValue( - enchantment: CAEnchantment, // compatibility with 1.20.5. TODO better update system + enchantment: CAEnchantment, isFromBook: Boolean ): Int { - - val enchantmentName = enchantment.key.toString() - if (enchantmentName == "minecraft:sweeping_edge") { - var limit = enchantmentValue("minecraft:sweeping", isFromBook) - if (limit != null) return limit - - // legacy name - limit = enchantmentValue("sweeping", isFromBook) - if (limit != null) return limit - } - val rarity = enchantment.defaultRarity() return if (isFromBook) rarity.bookValue @@ -648,15 +637,6 @@ object ConfigOptions { value = maxBeforeMergeDisabled(legacy) if (value >= 0) return value - if (key == "minecraft:sweeping_edge") { - value = maxBeforeMergeDisabled("minecraft:sweeping") - if (value >= 0) return value - - // legacy name of legacy enchantment name - value = maxBeforeMergeDisabled("sweeping") - if (value >= 0) return value - } - return DEFAULT_MAX_BEFORE_MERGE_DISABLED } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index 5b256dd8..39def31f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -39,13 +39,6 @@ class EnchantConflictManager { // Default name for a joining group const val DEFAULT_GROUP_NAME = "joinedGroup" - - // 1.20.5 compatibility TODO better update system - private val SWEEPING_EDGE_ENCHANT = Collections.singletonList( - CAEnchantment.getByKey(NamespacedKey.minecraft("sweeping_edge")) - ?: CAEnchantment.getByKey(Enchantment.SWEEPING_EDGE.key) - ) - } lateinit var conflictList: ArrayList @@ -172,14 +165,6 @@ class EnchantConflictManager { } - // Temporary solution for 1.20.5 - when (enchantName) { - "minecraft:sweeping", "sweeping", - "minecraft:sweeping_edge", "sweeping_edge" -> { - return SWEEPING_EDGE_ENCHANT - } - } - return CAEnchantment.getListByName(enchantName) } From 460114ac0159ed82679df93904ada3b302bdf4dd Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 14:37:59 +0200 Subject: [PATCH 12/41] add book on book --- .../settings/EnchantCostSettingsGui.java | 4 +-- .../io/delilaheve/util/ConfigOptions.kt | 25 +++++++++++++------ .../cuanvil/util/anvil/AnvilXpUtil.kt | 24 ++++++++++-------- .../cuanvil/config/DefaultConfigTests.java | 4 +-- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java index 3bd923bf..2fbc47ad 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java @@ -285,14 +285,14 @@ public class EnchantCostSettingsGui extends IntSettingsGui { */ @Override public int getConfiguredValue() { - return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false); + return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, false); } /** * @return The configured value for the enchant setting book value. */ public int getConfiguredBookValue() { - return ConfigOptions.INSTANCE.enchantmentValue(enchantment, true); + return ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, true); } @Override diff --git a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt index dddb64d7..9b0c4cd0 100644 --- a/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt +++ b/src/main/kotlin/io/delilaheve/util/ConfigOptions.kt @@ -86,6 +86,7 @@ object ConfigOptions { // Keys for specific enchantment values private const val KEY_BOOK = "book" + private const val KEY_BOOK_ON_BOOK = "book_on_book" private const val KEY_ITEM = "item" // Debug flag @@ -578,14 +579,15 @@ object ConfigOptions { */ fun enchantmentValue( enchantment: CAEnchantment, - isFromBook: Boolean + isToBook: Boolean, + isFromBook: Boolean, ): Int { // Test namespace - var limit = enchantmentValue(enchantment.key.toString(), isFromBook) + var limit = enchantmentValue(enchantment.key.toString(), isToBook, isFromBook) if (limit != null) return limit // Test legacy (name only) - limit = enchantmentValue(enchantment.enchantmentName, isFromBook) + limit = enchantmentValue(enchantment.enchantmentName, isToBook, isFromBook) if (limit != null) return limit // get default (and test old legacy if present) @@ -599,13 +601,22 @@ object ConfigOptions { */ private fun enchantmentValue( enchantmentName: String, - isFromBook: Boolean + isToBook: Boolean, + isFromBook: Boolean, ): Int? { val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM val path = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$typeKey" - return CustomAnvil.instance - .config - .getInt(path, DEFAULT_ENCHANT_VALUE - 1) + + val config = ConfigHolder.DEFAULT_CONFIG.config + if(isFromBook && isToBook) { + val specialPath = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$KEY_BOOK_ON_BOOK" + + if(config.isInt(specialPath)) + return config.getInt(specialPath) + .takeIf { it >= DEFAULT_ENCHANT_VALUE } + } + + return config.getInt(path, DEFAULT_ENCHANT_VALUE - 1) .takeIf { it >= DEFAULT_ENCHANT_VALUE } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index 9d2f5420..78ea8830 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -23,6 +23,7 @@ import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager import xyz.alexcrea.cuanvil.group.ConflictType import xyz.alexcrea.cuanvil.util.AnvilTitleUtil import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil +import kotlin.math.sqrt object AnvilXpUtil { @@ -35,8 +36,9 @@ object AnvilXpUtil { inventory: AnvilInventory, view: InventoryView, player: Player, - result: AnvilResult) { - if(result.item == null) { + result: AnvilResult + ) { + if (result.item == null) { onNoResult(player, view) return } @@ -246,7 +248,8 @@ object AnvilXpUtil { fun getRightValues(left: ItemStack, right: ItemStack, result: ItemStack, cost: AnvilCost) { // Calculate right value and illegal enchant penalty - val rightIsFormBook = right.isEnchantedBook() + val isToBook = left.isEnchantedBook() + val isFromBook = right.isEnchantedBook() val rightEnchs = EnchantmentApi.getEnchantments(right) val resultEnchs = EnchantmentApi.getEnchantments(result) val resultEnchsKeys = HashMap(resultEnchs) @@ -274,22 +277,21 @@ object AnvilXpUtil { // We know "enchantment.key in resultEnchs" true val resultLevel = resultEnchs[enchantment.key]!! - val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, rightIsFormBook) + val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, isFromBook, isToBook) val value = resultLevel * enchantmentMultiplier CustomAnvil.log("Value for sacrifice item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)") rightValue += value } - if(ConfigOptions.includeLeftEnchantmentForCost) { - val leftIsFormBook = left.isEnchantedBook() + if (ConfigOptions.includeLeftEnchantmentForCost) { val leftEnchs = EnchantmentApi.getEnchantments(left) for (enchantment in leftEnchs) { // Do not process enchantment that are present on the sacrifice - if(rightEnchs.contains(enchantment.key)) continue + if (rightEnchs.contains(enchantment.key)) continue val resultLevel = resultEnchs.getOrDefault(enchantment.key, 0) - val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, leftIsFormBook) + val enchantmentMultiplier = ConfigOptions.enchantmentValue(enchantment.key, isFromBook, isToBook) val value = resultLevel * enchantmentMultiplier CustomAnvil.log("Value for left item ${enchantment.key.enchantmentName} level ${enchantment.value} is $value ($resultLevel * $enchantmentMultiplier)") leftValue += value @@ -312,15 +314,15 @@ object AnvilXpUtil { */ fun calculateLevelForXp(xp: Int): Int { return when { - xp <= 352 -> (Math.sqrt((xp + 9).toDouble()) - 3).toInt() + xp <= 352 -> (sqrt((xp + 9).toDouble()) - 3).toInt() xp <= 1507 -> { val inner = (2.0 / 5.0) * (xp - 7839.0 / 40.0) - (81.0 / 10.0 + Math.sqrt(inner)).toInt() + (81.0 / 10.0 + sqrt(inner)).toInt() } else -> { val inner = (2.0 / 9.0) * (xp - 54215.0 / 72.0) - (325.0 / 18.0 + Math.sqrt(inner)).toInt() + (325.0 / 18.0 + sqrt(inner)).toInt() } } } diff --git a/src/test/java/xyz/alexcrea/cuanvil/config/DefaultConfigTests.java b/src/test/java/xyz/alexcrea/cuanvil/config/DefaultConfigTests.java index ac3f73ea..a92b1d71 100644 --- a/src/test/java/xyz/alexcrea/cuanvil/config/DefaultConfigTests.java +++ b/src/test/java/xyz/alexcrea/cuanvil/config/DefaultConfigTests.java @@ -49,8 +49,8 @@ public class DefaultConfigTests extends SharedCustomAnvilTest { CAEnchantment enchantment = CAEnchantmentRegistry.getInstance().getByKey(key); Assertions.assertNotNull(enchantment, "Enchantment was somehow not found"); - int itemValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false); - int bookValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, true); + int itemValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, false); + int bookValue = ConfigOptions.INSTANCE.enchantmentValue(enchantment, false, true); EnchantmentRarity rarity = enchantment.defaultRarity(); From f6f68d19714a70bfa35b44f2990ccf2f5afd885c Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 7 Jul 2026 11:51:04 +0200 Subject: [PATCH 13/41] add current minecraft version to update checker [ci skip] --- src/main/kotlin/io/delilaheve/CustomAnvil.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 321165e5..a5cac722 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -24,6 +24,7 @@ import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener import xyz.alexcrea.cuanvil.update.ModrinthUpdateChecker import xyz.alexcrea.cuanvil.update.PluginSetDefault import xyz.alexcrea.cuanvil.update.UpdateHandler +import xyz.alexcrea.cuanvil.update.UpdateUtils import xyz.alexcrea.cuanvil.util.MetricsUtil import java.io.File import java.io.FileReader @@ -223,7 +224,8 @@ open class CustomAnvil : JavaPlugin() { val version = description.version val featured = if(version.contains("dev")) null else true - ModrinthUpdateChecker(modrinthPluginID, loader, null) + ModrinthUpdateChecker(modrinthPluginID, loader, + UpdateUtils.currentMinecraftVersion().toString()) .setFeatured(featured) .setOnError { logger.log(Level.WARNING, "error trying to fetch latest update", it) From 4c3b3b09ad9c5fae17578d92b18122eb4da04dda Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 24 Jun 2026 03:02:10 +0200 Subject: [PATCH 14/41] replace gui to config subcommand --- .../xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt | 9 +++++++-- .../xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt index 8bd1d827..648dbc1d 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt @@ -20,6 +20,7 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { private val helpCommand = HelpExecutor() private val commands = ImmutableMap.of( "gui", editConfigCommand, + "config", editConfigCommand, "reload", ReloadExecutor(), "diagnostic", DiagnosticExecutor(), "debug", DebugToggleExecutor(), @@ -42,12 +43,16 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { ): Boolean { // Find sub command to execute based on the provided command name val subcmd: CASubCommand? + val subcmdStr: String + val newargs: Array if(args.isEmpty()) { + subcmdStr = "config" subcmd = editConfigCommand newargs = args }else { - subcmd = commands[args[0].lowercase()] + subcmdStr = args[0].lowercase() + subcmd = commands[subcmdStr] newargs = args.copyOfRange(1, args.size) } @@ -57,7 +62,7 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { } try { - return subcmd.executeCommand(sender, cmd, cmdstr, newargs) + return subcmd.executeCommand(sender, cmd, subcmdStr, newargs) } catch (e: Throwable) { MetricsUtil.trackError(e) sender.sendMessage("§cError running this command") diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index d26db8c2..138ae870 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -29,6 +29,10 @@ class EditConfigExecutor: CASubCommand() { return false } + if ("gui".equals(cmdstr, ignoreCase = true)) { + sender.sendMessage("§c/ca gui has been moved to /ca config") + } + MainConfigGui.getInstance().show(sender) return true From a79e341ea85b47af6ef25f0613770286f34eb4d7 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Sat, 27 Jun 2026 08:26:54 +0200 Subject: [PATCH 15/41] add list gui filter --- .../global/AbstractEnchantConfigGui.java | 5 +-- .../config/global/CustomRecipeConfigGui.java | 2 +- .../gui/config/global/EnchantConflictGui.java | 2 +- .../gui/config/global/GroupConfigGui.java | 2 +- .../config/global/UnitRepairConfigGui.java | 2 +- .../gui/config/list/ElementListConfigGui.java | 38 ++++++++++++------- .../config/list/MappedGuiListConfigGui.java | 2 +- .../config/list/UnitRepairElementListGui.java | 2 +- .../settings/EnchantSelectSettingGui.java | 2 +- .../settings/MaterialSelectSettingGui.java | 2 +- 10 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java index 6bd7ea34..b4f732d4 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java @@ -5,7 +5,6 @@ import com.github.stefvanschie.inventoryframework.pane.util.Pattern; import org.bukkit.event.inventory.InventoryClickEvent; import xyz.alexcrea.cuanvil.enchant.CAEnchantment; import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry; -import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.config.list.SettingGuiListConfigGui; import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; @@ -37,7 +36,7 @@ public abstract class AbstractEnchantConfigGui getEveryDisplayableInstanceOfGeneric() { + protected Collection getEveryInstanceOfGeneric() { return CAEnchantmentRegistry.getInstance().getNameSortedEnchantments(); } @@ -73,7 +72,7 @@ public abstract class AbstractEnchantConfigGui getEveryDisplayableInstanceOfGeneric() { + protected Collection getEveryInstanceOfGeneric() { return ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().getRecipeList(); } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java index 912e6cb3..79f52923 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java @@ -97,7 +97,7 @@ public class EnchantConflictGui extends MappedGuiListConfigGui getEveryDisplayableInstanceOfGeneric() { + protected Collection getEveryInstanceOfGeneric() { return ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList(); } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/GroupConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/GroupConfigGui.java index 8e20751b..fa53174c 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/GroupConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/GroupConfigGui.java @@ -62,7 +62,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui getEveryDisplayableInstanceOfGeneric() { + protected Collection getEveryInstanceOfGeneric() { ArrayList includeGroups = new ArrayList<>(); for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) { diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java index 0e366ae6..c3e8bcb0 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java @@ -77,7 +77,7 @@ public class UnitRepairConfigGui extends } @Override - protected Collection getEveryDisplayableInstanceOfGeneric() { + protected Collection getEveryInstanceOfGeneric() { ArrayList materials = new ArrayList<>(); for (String matName : ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getKeys(false)) { diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java index f3cc0b46..a9e499b0 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java @@ -23,18 +23,21 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.UUID; +import java.util.function.Predicate; -public abstract class ElementListConfigGui< T > extends ChestGui implements ValueUpdatableGui { - - private final String namePrefix; - - protected PatternPane backgroundPane; +public abstract class ElementListConfigGui extends ChestGui implements ValueUpdatableGui { public static final int LIST_FILLER_START_X = 1; public static final int LIST_FILLER_START_Y = 1; public static final int LIST_FILLER_LENGTH = 7; public static final int LIST_FILLER_HEIGHT = 4; + private final String namePrefix; + + protected PatternPane backgroundPane; + + private Predicate filter = (t) -> true; + protected ElementListConfigGui(@NotNull String title, Gui parent) { super(6, title, CustomAnvil.instance); this.namePrefix = title; @@ -46,7 +49,11 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu } - protected Pattern getBackgroundPattern(){ + public void setFilter(Predicate filter) { + this.filter = filter; + } + + protected Pattern getBackgroundPattern() { return new Pattern( GuiSharedConstant.UPPER_FILLER_FULL_PLANE, GuiSharedConstant.EMPTY_FILLER_FULL_LINE, @@ -81,7 +88,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu protected GuiItem goLeftItem; protected GuiItem goRightItem; - protected void prepareStaticValues(){ + protected void prepareStaticValues() { // Left item creation for consumer & bind this.goLeftItem = new GuiItem(new ItemStack(Material.RED_STAINED_GLASS_PANE), event -> { HumanEntity viewer = event.getWhoClicked(); @@ -113,16 +120,17 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu }, CustomAnvil.instance); GuiItem createNew = prepareCreateNewItem(); - if(createNew != null){ + if (createNew != null) { this.backgroundPane.bindItem('C', createNew); } } - protected void reloadValues(){ + + protected void reloadValues() { this.firstPage.clear(); this.pages.clear(); this.pages.add(this.firstPage); - for (T generic : getEveryDisplayableInstanceOfGeneric()) { + for (T generic : getDisplayableInstanceOfGeneric()) { updateValueForGeneric(generic, false); } @@ -247,7 +255,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu // set title StringBuilder title = new StringBuilder(this.namePrefix); int pagesSize = this.pages.size(); - if(pagesSize > 1){ + if (pagesSize > 1) { title.append(" (").append(pageID + 1).append('/').append(pagesSize).append(')'); } setTitle(title.toString()); @@ -288,7 +296,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu public void removeGeneric(T generic) { GuiItem item = findGuiItemForRemoval(generic); - if(item == null) return; + if (item == null) return; removeFromPage(item); update(); @@ -300,7 +308,11 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu protected abstract void updateGeneric(T generic, ItemStack usedItem); - protected abstract Collection getEveryDisplayableInstanceOfGeneric(); + protected abstract Collection getEveryInstanceOfGeneric(); + + protected Collection getDisplayableInstanceOfGeneric() { + return getEveryInstanceOfGeneric().stream().filter(filter).toList(); + } @Override public void updateGuiValues() { diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java index 3aa18e0b..18a5f864 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java @@ -80,7 +80,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu // Try to find if it already exists in a for loop // Not the most efficient on large number of conflict, but it should not run often. - for (T generic : getEveryDisplayableInstanceOfGeneric()) { + for (T generic : getDisplayableInstanceOfGeneric()) { if (generic.toString().equalsIgnoreCase(message)) { player.sendMessage("§cPlease enter a "+genericDisplayedName()+" name that do not already exist..."); // wait next message. diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java index 35f8ebb9..c9f2ada2 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java @@ -134,7 +134,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui getEveryDisplayableInstanceOfGeneric() { + protected Collection getEveryInstanceOfGeneric() { ArrayList keys = new ArrayList<>(); if(!this.shouldWork){ return keys; diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java index 176da55b..397ae6f5 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java @@ -63,7 +63,7 @@ public class EnchantSelectSettingGui extends SettingGuiListConfigGui getEveryDisplayableInstanceOfGeneric() { + protected Collection getEveryInstanceOfGeneric() { Stream toDisplayStream; if(this.displayUnselected){ toDisplayStream = CAEnchantmentRegistry.getInstance().getNameSortedEnchantments().stream(); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/MaterialSelectSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/MaterialSelectSettingGui.java index fc519ff1..1869ad34 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/MaterialSelectSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/MaterialSelectSettingGui.java @@ -217,7 +217,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui getEveryDisplayableInstanceOfGeneric() { + protected Collection getEveryInstanceOfGeneric() { return this.defaultMaterials; } From 5f0a601e5b8d925e305d58eee9798861b169ccc2 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Sun, 28 Jun 2026 23:01:56 +0200 Subject: [PATCH 16/41] add edit config tab completer --- .../cuanvil/command/EditConfigExecutor.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index 138ae870..ac059e9e 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -1,10 +1,12 @@ package xyz.alexcrea.cuanvil.command +import com.willfp.eco.core.lookup.matches import io.delilaheve.CustomAnvil import org.bukkit.command.Command import org.bukkit.command.CommandSender import org.bukkit.entity.HumanEntity import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil +import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.gui.config.MainConfigGui import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions @@ -46,4 +48,28 @@ class EditConfigExecutor: CASubCommand() { return "Gui to edit the plugin's config" } + private fun allEnchantmentsByName(): Collection{ + val names = mutableSetOf() + for (enchantment in CAEnchantmentRegistry.getInstance().values()) { + names.add(enchantment.name) + names.add(enchantment.key.toString()) + } + + return names + } + + override fun tabCompleter(sender: CommandSender, args: Array, list: MutableList) { + list.addAll(when (args.size) { + 1 -> listOf("item", "enchant", "open") + 2 -> { + when(args[0].lowercase()) { + "enchant" -> allEnchantmentsByName() + else -> listOf() + } + } + else -> listOf() + }) + + } + } From 554fba008ec075f24155245005bb49d7c21a5325 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 30 Jun 2026 03:36:22 +0200 Subject: [PATCH 17/41] made main command logic --- .../cuanvil/command/EditConfigExecutor.kt | 90 ++++++++++++++----- 1 file changed, 69 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index ac059e9e..4be32bc3 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -1,28 +1,39 @@ package xyz.alexcrea.cuanvil.command -import com.willfp.eco.core.lookup.matches import io.delilaheve.CustomAnvil import org.bukkit.command.Command import org.bukkit.command.CommandSender import org.bukkit.entity.HumanEntity +import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil +import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.gui.config.MainConfigGui import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions -class EditConfigExecutor: CASubCommand() { +class EditConfigExecutor : CASubCommand() { - override fun executeCommand(sender: CommandSender, - cmd: Command, - cmdstr: String, - args: Array): Boolean { + override fun allowed(sender: CommandSender): Boolean { + return sender.hasPermission(CustomAnvil.editConfigPermission) + } + + override fun description(): String { + return "Gui to edit the plugin's config" + } + + override fun executeCommand( + sender: CommandSender, + cmd: Command, + cmdstr: String, + args: Array + ): Boolean { if (sender !is HumanEntity) return false if (!allowed(sender)) { sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM) return false } - if(PlatformUtil.isFolia){ + if (PlatformUtil.isFolia) { sender.sendMessage("§cIt look like you are using Folia. Sadly Custom Anvil do not support Config gui for Folia.") sender.sendMessage("§eIt is may come in a future version.") sender.sendMessage("") @@ -35,20 +46,54 @@ class EditConfigExecutor: CASubCommand() { sender.sendMessage("§c/ca gui has been moved to /ca config") } - MainConfigGui.getInstance().show(sender) + if (args.isEmpty()) + processOpen(sender) + else when (args[0].lowercase()) { + "open" -> processOpen(sender) + "enchant" -> processEnchant(sender, args) + "item" -> processItem(sender) + else -> sender.sendMessage("Unknown subcommand \"${args[0]}\"") + } return true } - override fun allowed(sender: CommandSender): Boolean { - return sender.hasPermission(CustomAnvil.editConfigPermission) + private fun processEnchant(sender: HumanEntity, args: Array) { + val enchantToFilter: Set + if (args.size <= 1) { + val item = sender.inventory.itemInMainHand + + enchantToFilter = EnchantmentApi.getEnchantments(item).keys + if (enchantToFilter.isEmpty()) { + sender.sendMessage("No enchantment found in the item you are holding") + return + } + } else { + enchantToFilter = HashSet(EnchantmentApi.getListByName(args[1].lowercase())) + + if (enchantToFilter.isEmpty()) { + sender.sendMessage("No enchantment found with the name \"${args[1]}\"") + return + } + } + + // TODO open enchantments edit gui + } - override fun description(): String { - return "Gui to edit the plugin's config" + private fun processItem(sender: HumanEntity) { + // TODO open item edit gui } - private fun allEnchantmentsByName(): Collection{ + private fun processOpen(sender: HumanEntity) { + MainConfigGui.getInstance().show(sender) + } + + // --------------- + // Tab completer + // --------------- + + private fun allEnchantmentsByName(): Collection { val names = mutableSetOf() for (enchantment in CAEnchantmentRegistry.getInstance().values()) { names.add(enchantment.name) @@ -59,16 +104,19 @@ class EditConfigExecutor: CASubCommand() { } override fun tabCompleter(sender: CommandSender, args: Array, list: MutableList) { - list.addAll(when (args.size) { - 1 -> listOf("item", "enchant", "open") - 2 -> { - when(args[0].lowercase()) { - "enchant" -> allEnchantmentsByName() - else -> listOf() + list.addAll( + when (args.size) { + 1 -> listOf("item", "enchant", "open") + 2 -> { + when (args[0].lowercase()) { + "enchant" -> allEnchantmentsByName() + else -> listOf() + } } + + else -> listOf() } - else -> listOf() - }) + ) } From 25f676f7f3388d9154de83109c3c1a38b3a16436 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 30 Jun 2026 19:26:52 +0200 Subject: [PATCH 18/41] enchant conflict working --- .../gui/config/global/EnchantConflictGui.java | 15 ++- .../gui/config/global/ItemConfigGui.java | 106 ++++++++++++++++++ .../gui/config/list/ElementListConfigGui.java | 2 +- .../list/MappedElementListConfigGui.java | 26 +++-- .../config/list/MappedGuiListConfigGui.java | 23 ++-- .../cuanvil/command/EditConfigExecutor.kt | 11 +- 6 files changed, 157 insertions(+), 26 deletions(-) create mode 100644 src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java index 79f52923..3c28e7c5 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.gui.config.global; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -24,26 +25,30 @@ public class EnchantConflictGui extends MappedGuiListConfigGui + group.getCantConflictGroup().contain(material) + ); + enchantConflictGui.init(); + } + + return enchantConflictGui; + } +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java index a9e499b0..1386b31d 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java @@ -68,7 +68,7 @@ public abstract class ElementListConfigGui extends ChestGui implements ValueU protected ArrayList pages; protected HashMap pageMap; - public void init() { // Why I'm using an init function ? //TODO determine why is it using a init function and not used on constructor. + public void init() { GuiGlobalItems.addBackgroundItem(this.backgroundPane); this.backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM); addPane(this.backgroundPane); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java index 31ab7184..9b6c6100 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.gui.config.list; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import io.delilaheve.CustomAnvil; import org.bukkit.Material; import org.bukkit.entity.HumanEntity; @@ -14,27 +15,32 @@ import java.util.Arrays; import java.util.HashMap; import java.util.function.Consumer; -public abstract class MappedElementListConfigGui< T, S > extends ElementListConfigGui< T > { +public abstract class MappedElementListConfigGui extends ElementListConfigGui { protected final HashMap elementGuiMap; - protected MappedElementListConfigGui(@NotNull String title) { - super(title, MainConfigGui.getInstance()); + + protected MappedElementListConfigGui(@NotNull String title, @NotNull Gui parent) { + super(title, parent); this.elementGuiMap = new HashMap<>(); } + protected MappedElementListConfigGui(@NotNull String title) { + this(title, MainConfigGui.getInstance()); + } + @Override - protected GuiItem prepareCreateNewItem(){ + protected GuiItem prepareCreateNewItem() { // Create new conflict item ItemStack createItem = new ItemStack(Material.PAPER); ItemMeta createMeta = createItem.getItemMeta(); assert createMeta != null; - createMeta.setDisplayName("§aCreate new "+genericDisplayedName()); + createMeta.setDisplayName("§aCreate new " + genericDisplayedName()); createMeta.setLore(Arrays.asList( - "§7Create a new "+genericDisplayedName()+".", - "§7You will be asked to name the "+genericDisplayedName()+" in chat.", - "§7Then, you should edit the "+genericDisplayedName()+" config as you need" + "§7Create a new " + genericDisplayedName() + ".", + "§7You will be asked to name the " + genericDisplayedName() + " in chat.", + "§7Then, you should edit the " + genericDisplayedName() + " config as you need" )); createItem.setItemMeta(createMeta); @@ -51,8 +57,8 @@ public abstract class MappedElementListConfigGui< T, S > extends ElementListConf } player.closeInventory(); - player.sendMessage("§eWrite the "+genericDisplayedName()+" name you want to create in the chat.\n" + - "§eOr write §ccancel §eto go back to "+genericDisplayedName()+" config menu"); + player.sendMessage("§eWrite the " + genericDisplayedName() + " name you want to create in the chat.\n" + + "§eOr write §ccancel §eto go back to " + genericDisplayedName() + " config menu"); CustomAnvil.Companion.getChatListener().setListenedCallback(player, prepareCreateItemConsumer(player)); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java index 18a5f864..8180694e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.gui.config.list; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import io.delilaheve.CustomAnvil; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; @@ -14,19 +15,22 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.function.Supplier; -public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGui.LazyElement> - extends MappedElementListConfigGui< T, S > { +public abstract class MappedGuiListConfigGui> + extends MappedElementListConfigGui { protected MappedGuiListConfigGui(@NotNull String title) { super(title); + } + protected MappedGuiListConfigGui(@NotNull String title, @NotNull Gui parent) { + super(title, parent); } @Override public void reloadValues() { this.elementGuiMap.forEach((conflict, element) -> { ElementMappedToListGui gui = element.getStored(); - if(gui != null) gui.cleanAndBeUnusable(); + if (gui != null) gui.cleanAndBeUnusable(); }); this.elementGuiMap.clear(); @@ -49,7 +53,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu @Override protected void updateElement(T generic, S element) { ElementMappedToListGui gui = element.getStored(); - if(gui != null) gui.updateLocal(); + if (gui != null) gui.updateLocal(); } @Override @@ -58,7 +62,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu } @Override - protected Consumer prepareCreateItemConsumer(HumanEntity player){ + protected Consumer prepareCreateItemConsumer(HumanEntity player) { AtomicReference> selfRef = new AtomicReference<>(); Consumer selfCallback = (message) -> { if (message == null) return; @@ -71,7 +75,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu message = message.toLowerCase(Locale.ROOT); if ("cancel".equalsIgnoreCase(message)) { - player.sendMessage(genericDisplayedName()+" creation cancelled..."); + player.sendMessage(genericDisplayedName() + " creation cancelled..."); show(player); return; } @@ -82,7 +86,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu // Not the most efficient on large number of conflict, but it should not run often. for (T generic : getDisplayableInstanceOfGeneric()) { if (generic.toString().equalsIgnoreCase(message)) { - player.sendMessage("§cPlease enter a "+genericDisplayedName()+" name that do not already exist..."); + player.sendMessage("§cPlease enter a " + genericDisplayedName() + " name that do not already exist..."); // wait next message. CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get()); return; @@ -90,7 +94,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu } T generic = createAndSaveNewEmptyGeneric(message); - if(generic == null) {// we don't know what to do. so we back up by opening this gui. + if (generic == null) {// we don't know what to do. so we back up by opening this gui. this.show(player); return; } @@ -117,6 +121,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu private final GuiItem parentItem; private final LazyValue> lazyOpenConsumer; + public LazyElement(GuiItem parentItem, Supplier valueSupplier) { super(valueSupplier); this.parentItem = parentItem; @@ -131,7 +136,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu } @NotNull - public Consumer openAction(){ + public Consumer openAction() { return event -> lazyOpenConsumer.get().accept(event); } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index 4be32bc3..8aa54a96 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -9,7 +9,10 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.gui.config.MainConfigGui +import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions +import xyz.alexcrea.cuanvil.util.MaterialUtil.customType +import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir class EditConfigExecutor : CASubCommand() { @@ -82,7 +85,13 @@ class EditConfigExecutor : CASubCommand() { } private fun processItem(sender: HumanEntity) { - // TODO open item edit gui + val item = sender.inventory.itemInMainHand + if(item.isAir) { + sender.sendMessage("Cannot configure the item in hand") + return + } + + ItemConfigGui(item.type, item.customType).show(sender) } private fun processOpen(sender: HumanEntity) { From a78f83f6f4b5c08ed37292cfeca833134584c06c Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 00:56:47 +0200 Subject: [PATCH 19/41] item config group config gui --- .../gui/config/global/GroupConfigGui.java | 5 ++++ .../gui/config/global/ItemConfigGui.java | 24 +++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/GroupConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/GroupConfigGui.java index fa53174c..7f85278e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/GroupConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/GroupConfigGui.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.gui.config.global; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -43,6 +44,10 @@ public class GroupConfigGui extends MappedGuiListConfigGui @@ -103,4 +106,17 @@ public class ItemConfigGui extends ChestGui { return enchantConflictGui; } + + private GroupConfigGui getGroupConfigGui(NamespacedKey material) { + if (groupConfigGui == null) { + groupConfigGui = new GroupConfigGui(this); + groupConfigGui.setFilter(group -> + group.contain(material) + ); + groupConfigGui.init(); + } + + return groupConfigGui; + } + } From 799008f6529237ed7f96fb58560db01a1601cb30 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 02:06:14 +0200 Subject: [PATCH 20/41] reworked unit repair --- .../alexcrea/cuanvil/api/UnitRepairApi.java | 188 ++++++++++++++---- .../alexcrea/cuanvil/util/UnitRepairUtil.kt | 58 +++--- 2 files changed, 172 insertions(+), 74 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/UnitRepairApi.java b/src/main/java/xyz/alexcrea/cuanvil/api/UnitRepairApi.java index bc50c162..f5df41bc 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/UnitRepairApi.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/UnitRepairApi.java @@ -3,18 +3,16 @@ package xyz.alexcrea.cuanvil.api; import io.delilaheve.CustomAnvil; import kotlin.Triple; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.jetbrains.annotations.NotNull; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.dependency.DependencyManager; import xyz.alexcrea.cuanvil.gui.config.global.UnitRepairConfigGui; -import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui; import xyz.alexcrea.cuanvil.gui.config.list.UnitRepairElementListGui; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; /** * Custom Anvil api for unit repair. @@ -22,7 +20,8 @@ import java.util.List; @SuppressWarnings("unused") public class UnitRepairApi { - private UnitRepairApi(){} + private UnitRepairApi() { + } private static Object saveChangeTask = null; @@ -35,7 +34,20 @@ public class UnitRepairApi { * @param repairable The item to be repaired. * @return true if successful. */ - public static boolean addUnitRepair(@NotNull Material unit, @NotNull Material repairable){ + public static boolean addUnitRepair(@NotNull Material unit, @NotNull Material repairable) { + return addUnitRepair(unit, repairable, 0.25, false); + } + + /** + * Write and add a custom anvil unit repair recipe. + * Will not write the recipe if it already exists or was deleted. + * Set the value to minecraft default value (0.25 = 25%) + * + * @param unit The unit material used to repair the bellow item. + * @param repairable The item to be repaired. + * @return true if successful. + */ + public static boolean addUnitRepair(@NotNull NamespacedKey unit, @NotNull NamespacedKey repairable) { return addUnitRepair(unit, repairable, 0.25, false); } @@ -48,7 +60,7 @@ public class UnitRepairApi { * @param value The amount to be repaired by every unit. (1% = 0.01) * @return true if successful. */ - public static boolean addUnitRepair(@NotNull Material unit, @NotNull Material repairable, double value){ + public static boolean addUnitRepair(@NotNull Material unit, @NotNull Material repairable, double value) { return addUnitRepair(unit, repairable, value, false); } @@ -62,12 +74,26 @@ public class UnitRepairApi { * @param overrideDeleted If we should write even if the recipe was previously deleted. * @return true if successful. */ - public static boolean addUnitRepair(@NotNull Material unit, @NotNull Material repairable, double value, boolean overrideDeleted){ - FileConfiguration config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); - String path = unit.name().toLowerCase() + "." + repairable.name().toLowerCase(); + public static boolean addUnitRepair(@NotNull Material unit, @NotNull Material repairable, double value, boolean overrideDeleted) { + return addUnitRepair(unit.getKey(), repairable.getKey(), value, overrideDeleted); + } - if(!overrideDeleted && ConfigHolder.UNIT_REPAIR_HOLDER.isDeleted(path)) return false; - if(config.contains(path)) return false; + /** + * Write and add a custom anvil unit repair recipe. + * Will not write the recipe if it already exists. + * + * @param unit The unit material used to repair the bellow item. + * @param repairable The item to be repaired. + * @param value The amount to be repaired by every unit. (1% = 0.01) + * @param overrideDeleted If we should write even if the recipe was previously deleted. + * @return true if successful. + */ + public static boolean addUnitRepair(@NotNull NamespacedKey unit, @NotNull NamespacedKey repairable, double value, boolean overrideDeleted) { + FileConfiguration config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); + String path = unit.toString().toLowerCase() + "." + repairable.toString().toLowerCase(); + + if (!overrideDeleted && ConfigHolder.UNIT_REPAIR_HOLDER.isDeleted(path)) return false; + if (config.contains(path)) return false; // Set unit repair return setUnitRepair(unit, repairable, value); @@ -82,11 +108,24 @@ public class UnitRepairApi { * @param value The amount to be repaired by every unit. (1% = 0.01) * @return true if successful. */ - public static boolean setUnitRepair(@NotNull Material unit, @NotNull Material repairable, double value){ + public static boolean setUnitRepair(@NotNull Material unit, @NotNull Material repairable, double value) { + return setUnitRepair(unit.getKey(), repairable.getKey(), value); + } + + /** + * Write and add a custom anvil unit repair recipe. + * Do not check if it previously existed or exist. + * + * @param unit The unit material used to repair the bellow item. + * @param repairable The item to be repaired. + * @param value The amount to be repaired by every unit. (1% = 0.01) + * @return true if successful. + */ + public static boolean setUnitRepair(@NotNull NamespacedKey unit, @NotNull NamespacedKey repairable, double value) { FileConfiguration config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); - String repairableName = repairable.name().toLowerCase(); - String path = unit.name().toLowerCase() + "." + repairableName; + String repairableName = repairable.toString().toLowerCase(); + String path = unit.toString().toLowerCase() + "." + repairableName; // Add to config then prepare save config.set(path, value); @@ -94,10 +133,10 @@ public class UnitRepairApi { // Add to gui UnitRepairConfigGui repairConfigGui = UnitRepairConfigGui.getCurrentInstance(); - if(repairConfigGui != null) { + if (repairConfigGui != null) { UnitRepairElementListGui elementGui = repairConfigGui.getInstanceOrCreate(unit).getStored(); - if(elementGui != null) elementGui.updateValueForGeneric(repairableName, true); + if (elementGui != null) elementGui.updateValueForGeneric(repairable, true); repairConfigGui.updateValueForGeneric(unit, true); } @@ -111,48 +150,56 @@ public class UnitRepairApi { * @param repairable The item used to be repaired. * @return true if successful. */ - public static boolean removeUnitRepair(@NotNull Material unit, @NotNull Material repairable){ + public static boolean removeUnitRepair(@NotNull Material unit, @NotNull Material repairable) { + return removeUnitRepair(unit.getKey(), repairable.getKey()); + } + + /** + * Remove a custom anvil unit repair recipe. + * + * @param unit The unit material used to repair the bellow item. + * @param repairable The item used to be repaired. + * @return true if successful. + */ + public static boolean removeUnitRepair(@NotNull NamespacedKey unit, @NotNull NamespacedKey repairable) { // Delete every possible variation and save to file - String unitName = unit.name(); - String repairableName = repairable.name(); FileConfiguration config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); - config.set(unitName.toLowerCase() + "." + repairableName.toUpperCase(), null); - config.set(unitName.toUpperCase() + "." + repairableName.toLowerCase(), null); - config.set(unitName.toUpperCase() + "." + repairableName.toUpperCase(), null); - config.set(unitName.toLowerCase() + "." + repairableName.toLowerCase(), null); + config.set(unit.getKey() + "." + repairable.getKey(), null); + config.set(unit.getKey() + "." + repairable, null); + config.set(unit + "." + repairable.getKey(), null); + config.set(unit + "." + repairable, null); // Test if it was the last value of this section boolean lastValue = false; - if(config.isConfigurationSection(unitName.toLowerCase())) { - ConfigurationSection section = config.getConfigurationSection(unitName.toLowerCase()); + if (config.isConfigurationSection(unit.toString())) { + ConfigurationSection section = config.getConfigurationSection(unit.toString()); - if(section != null && section.getKeys(false).isEmpty()) { + if (section != null && section.getKeys(false).isEmpty()) { lastValue = true; - config.set(unitName.toLowerCase(), null); + config.set(unit.toString(), null); } - } else if (config.isConfigurationSection(unitName.toUpperCase())) { - ConfigurationSection section = config.getConfigurationSection(unitName.toUpperCase()); - if(section != null && section.getKeys(false).isEmpty()) { + } else if (config.isConfigurationSection(unit.getKey())) { + ConfigurationSection section = config.getConfigurationSection(unit.getKey()); + if (section != null && section.getKeys(false).isEmpty()) { lastValue = true; - config.set(unitName.toUpperCase(), null); + config.set(unit.getKey(), null); } } else lastValue = true; - // We only need to "delete" as the lower case to be counted as deleted - ConfigHolder.UNIT_REPAIR_HOLDER.delete(unitName.toLowerCase() + "." + repairableName.toLowerCase()); + ConfigHolder.UNIT_REPAIR_HOLDER.delete(unit.toString().toLowerCase() + "." + repairable.toString().toLowerCase()); prepareSaveTask(); // Remove from gui UnitRepairConfigGui repairConfigGui = UnitRepairConfigGui.getCurrentInstance(); - if(repairConfigGui != null) { + if (repairConfigGui != null) { UnitRepairElementListGui elementGui = repairConfigGui.getInstanceOrCreate(unit).getStored(); - if(elementGui != null) elementGui.removeGeneric(repairableName); - if(lastValue){ + if (elementGui != null) elementGui.removeGeneric(repairable); + if (lastValue) { repairConfigGui.removeGeneric(unit); } } @@ -164,9 +211,9 @@ public class UnitRepairApi { * Prepare a task to save custom unit repair recipe configuration. */ private static void prepareSaveTask() { - if(saveChangeTask != null) return; + if (saveChangeTask != null) return; - saveChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, ()->{ + saveChangeTask = DependencyManager.scheduler.scheduleGlobally(CustomAnvil.instance, () -> { ConfigHolder.UNIT_REPAIR_HOLDER.saveToDisk(true); saveChangeTask = null; }); @@ -174,6 +221,7 @@ public class UnitRepairApi { /** * Get every unit repair recipes. + * * @return An immutable collection of unit repair recipes. *

    * Each element of the provided triple represent a part of the recipe @@ -182,29 +230,32 @@ public class UnitRepairApi { *

  • Second object is the item to be repaired. *
  • Last object is the amount to be repaired by every unit. (1% = 0.01) * + * @deprecated some may be missing. use {@link #getModernUnitRepairs()} + * */ + @Deprecated @NotNull - public static List> getUnitRepairs(){ + public static List> getUnitRepairs() { List> mutableList = new ArrayList<>(); FileConfiguration config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); for (String unitKey : config.getKeys(false)) { // Test if config section exist - if(!config.isConfigurationSection(unitKey)) continue; + if (!config.isConfigurationSection(unitKey)) continue; // Test if unit is a material Material unit = Material.getMaterial(unitKey.toUpperCase()); - if(unit == null) continue; + if (unit == null) continue; // Iterate over reparable items ConfigurationSection section = config.getConfigurationSection(unitKey); for (String repairableKey : section.getKeys(false)) { // Test if value section exist - if(!section.isDouble(repairableKey)) continue; + if (!section.isDouble(repairableKey)) continue; // Test if repairable is valid a material Material repairable = Material.getMaterial(repairableKey.toUpperCase()); - if(repairable == null) continue; + if (repairable == null) continue; // Add the values mutableList.add(new Triple<>(unit, repairable, section.getDouble(repairableKey))); @@ -215,4 +266,53 @@ public class UnitRepairApi { return Collections.unmodifiableList(mutableList); } + /** + * Get every unit repair recipes. + * + * @return An immutable collection of unit repair recipes. + *

    + *

  • First map contain a key the unit material used to repair the bellow item and value the second map + *
  • Second map contain as key the item to be repaired and as value the amount to be repaired by every unit. (1% = 0.01) + * + */ + @NotNull + public static Map> getModernUnitRepairs() { + Map> mutableList = new HashMap<>(); + + FileConfiguration config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); + for (String unitKey : config.getKeys(false)) { + // Test if config section exist + if (!config.isConfigurationSection(unitKey)) continue; + + // Test if unit is a material + NamespacedKey unit = NamespacedKey.fromString(unitKey.toLowerCase()); + if (unit == null) continue; + + Map map; + if (!mutableList.containsKey(unit)) { + map = new HashMap<>(); + mutableList.put(unit, map); + } else { + map = mutableList.get(unit); + } + + // Iterate over reparable items + ConfigurationSection section = config.getConfigurationSection(unitKey); + for (String repairableKey : section.getKeys(false)) { + // Test if value section exist + if (!section.isDouble(repairableKey)) continue; + + // Test if repairable is valid a material + NamespacedKey repairable = NamespacedKey.fromString(repairableKey.toLowerCase()); + if (repairable == null) continue; + + // Add the values + map.put(repairable, section.getDouble(repairableKey)); + + } + } + + return mutableList; + } + } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/UnitRepairUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/UnitRepairUtil.kt index 8463e27e..85c32f93 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/UnitRepairUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/UnitRepairUtil.kt @@ -1,6 +1,8 @@ package xyz.alexcrea.cuanvil.util +import org.bukkit.NamespacedKey import org.bukkit.configuration.ConfigurationSection +import org.bukkit.configuration.file.FileConfiguration import org.bukkit.inventory.ItemStack import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.util.MaterialUtil.customType @@ -22,40 +24,36 @@ object UnitRepairUtil { ): Double? { if (other == null) return null val config = ConfigHolder.UNIT_REPAIR_HOLDER.config - // Get configuration section if exist - val otherName = other.customType.key.lowercase() - var section = config.getConfigurationSection(otherName) - if (section == null) { - section = config.getConfigurationSection(otherName.uppercase()) - if (section == null) return null - } - // Get repair amount - var userDefault = config.getDouble(UNIT_REPAIR_DEFAULT_PATH, DEFAULT_DEFAULT_UNIT_REPAIR) - if (userDefault <= 0) { - userDefault = DEFAULT_DEFAULT_UNIT_REPAIR - } + val material = other.customType + val selfType = this.customType - return getRepairAmount(this, section, userDefault) + var result = checkSection(config, material.toString(), selfType) + if (result != null) return result + + result = checkSection(config, material.key, selfType) + if (result != null) return result + + // Get default + val userDefault = config.getDouble(UNIT_REPAIR_DEFAULT_PATH, DEFAULT_DEFAULT_UNIT_REPAIR) + if (userDefault <= 0) + return DEFAULT_DEFAULT_UNIT_REPAIR + return userDefault } - /** - * Get the item % repaired by this configuration section of a unit repair. - * null if not found. - * If value is set to less than or equal to 0 then it will be set to default - */ - private fun getRepairAmount(item: ItemStack, section: ConfigurationSection, default: Double): Double? { - val itemName = item.customType.key.lowercase() - val repairValue = if (section.isDouble(itemName)) { - section.getDouble(itemName) - } else if (section.isDouble(itemName.uppercase())) { - section.getDouble(itemName.uppercase()) - } else { - return null - } - if (repairValue <= 0) - return default - return repairValue + fun checkSection( + config: FileConfiguration, + path: String, + material: NamespacedKey + ): Double? { + val section = config.getConfigurationSection(path) ?: return null + + if (section.isDouble(material.toString())) + return section.getDouble(material.toString()) + if (section.isDouble(material.key)) + return section.getDouble(material.key) + + return null } } \ No newline at end of file From d1d01f90b834a732a38bcfed3989ccc40082fcb7 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 02:39:14 +0200 Subject: [PATCH 21/41] unit repair gui and internal update --- .../gui/config/global/ItemConfigGui.java | 13 ++- .../config/global/UnitRepairConfigGui.java | 74 ++++++++++------ .../config/list/UnitRepairElementListGui.java | 85 +++++++++++-------- .../xyz/alexcrea/cuanvil/util/MaterialUtil.kt | 3 + .../alexcrea/cuanvil/util/UnitRepairUtil.kt | 25 ++++-- 5 files changed, 129 insertions(+), 71 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java index e2144413..3bc19d5f 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java @@ -2,7 +2,6 @@ package xyz.alexcrea.cuanvil.gui.config.global; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; -import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.pane.PatternPane; import com.github.stefvanschie.inventoryframework.pane.util.Pattern; import io.delilaheve.CustomAnvil; @@ -119,4 +118,16 @@ public class ItemConfigGui extends ChestGui { return groupConfigGui; } + /*private UnitRepairConfigGui getUnitRepairConfigGui(NamespacedKey material) { + if (unitRepairConfigGui == null) { + unitRepairConfigGui = new UnitRepairConfigGui(this); + unitRepairConfigGui.setFilter(otherMat -> + group.contain(material) //TODO check material & what inside + ); + unitRepairConfigGui.init(); + } + + return unitRepairConfigGui; + }*/ + } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java index c3e8bcb0..cc4a981f 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java @@ -1,9 +1,10 @@ package xyz.alexcrea.cuanvil.gui.config.global; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import io.delilaheve.CustomAnvil; import org.bukkit.Material; -import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; @@ -13,24 +14,25 @@ import xyz.alexcrea.cuanvil.gui.config.ask.SelectItemTypeGui; import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui; import xyz.alexcrea.cuanvil.gui.config.list.UnitRepairElementListGui; import xyz.alexcrea.cuanvil.util.CasedStringUtil; +import xyz.alexcrea.cuanvil.util.MaterialUtil; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashSet; public class UnitRepairConfigGui extends - MappedGuiListConfigGui> { + MappedGuiListConfigGui> { private static UnitRepairConfigGui INSTANCE; @Nullable - public static UnitRepairConfigGui getCurrentInstance(){ + public static UnitRepairConfigGui getCurrentInstance() { return INSTANCE; } @NotNull - public static UnitRepairConfigGui getInstance(){ - if(INSTANCE == null) INSTANCE = new UnitRepairConfigGui(); + public static UnitRepairConfigGui getInstance() { + if (INSTANCE == null) INSTANCE = new UnitRepairConfigGui(); return INSTANCE; } @@ -41,8 +43,12 @@ public class UnitRepairConfigGui extends init(); } + public UnitRepairConfigGui(Gui parent) { + super("Unit Repair Config", parent); + } + @Override - protected LazyElement newInstanceOfGui(Material material, GuiItem item) { + protected LazyElement newInstanceOfGui(NamespacedKey material, GuiItem item) { return new LazyElement<>(item, () -> { UnitRepairElementListGui element = new UnitRepairElementListGui(material, this); element.init(); @@ -51,23 +57,34 @@ public class UnitRepairConfigGui extends } @Override - protected ItemStack createItemForGeneric(Material material) { - ConfigurationSection materialSection = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getConfigurationSection(material.name().toLowerCase()); - String materialName = CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase()); + protected ItemStack createItemForGeneric(@NotNull NamespacedKey material) { + var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); + var section = unitConfig.getConfigurationSection(material.toString().toLowerCase()); + var legacySection = unitConfig.getConfigurationSection(material.toString().toLowerCase()); - if(material.isAir()){ - material = Material.BARRIER; + String materialName = CasedStringUtil.snakeToUpperSpacedCase(material.getKey().toLowerCase()); + + var display = MaterialUtil.INSTANCE.getMatFromKey(material); + + if (display == null || display.isAir()) { + display = Material.BARRIER; } - int reparableItemCount = materialSection == null ? 0 : materialSection.getKeys(false).size(); // Probably an expensive call but... why not + var reparable = new HashSet(); + if (section != null) + reparable.addAll(section.getKeys(false)); + if (legacySection != null) + reparable.addAll(legacySection.getKeys(false)); - ItemStack item = new ItemStack(material); + var reparableItemCount = reparable.size(); + + ItemStack item = new ItemStack(display); ItemMeta meta = item.getItemMeta(); assert meta != null; - meta.setDisplayName("§eRepaired by " +materialName); + meta.setDisplayName("§eRepaired by " + materialName); meta.setLore(Arrays.asList( - "§7There is currently §e" +reparableItemCount+ " §7reparable item with "+materialName, + "§7There is currently §e" + reparableItemCount + " §7reparable item with " + materialName, "§7Click here to open the menu to edit reparable item by " + materialName )); @@ -77,13 +94,16 @@ public class UnitRepairConfigGui extends } @Override - protected Collection getEveryInstanceOfGeneric() { - ArrayList materials = new ArrayList<>(); + protected Collection getEveryInstanceOfGeneric() { + var materials = new HashSet(); + var config = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); - for (String matName : ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getKeys(false)) { - Material mat = Material.getMaterial(matName.toUpperCase()); - if(mat != null){ - materials.add(mat); + for (String matName : config.getKeys(false)) { + if(!config.isConfigurationSection(matName)) continue; + + NamespacedKey material = NamespacedKey.fromString(matName.toLowerCase()); + if (material != null) { + materials.add(material); } } return materials; @@ -113,7 +133,7 @@ public class UnitRepairConfigGui extends "§7You like to be an unit repair item", this, (itemStack, player) -> { - Material type = itemStack.getType(); + NamespacedKey type = MaterialUtil.INSTANCE.getCustomType(itemStack); // Add new material updateValueForGeneric(type, true); @@ -126,9 +146,9 @@ public class UnitRepairConfigGui extends } @NotNull - public LazyElement getInstanceOrCreate(Material mat){ + public LazyElement getInstanceOrCreate(NamespacedKey mat) { LazyElement element = this.elementGuiMap.get(mat); - if(element == null){ + if (element == null) { updateValueForGeneric(mat, false); element = this.elementGuiMap.get(mat); @@ -141,8 +161,10 @@ public class UnitRepairConfigGui extends protected String genericDisplayedName() { return "this function Should not be used."; } + @Override // Not used in this implementation. - protected Material createAndSaveNewEmptyGeneric(String name) { + protected NamespacedKey createAndSaveNewEmptyGeneric(String name) { return null; } + } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java index c9f2ada2..9b879fdc 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/UnitRepairElementListGui.java @@ -3,12 +3,14 @@ package xyz.alexcrea.cuanvil.gui.config.list; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.gui.config.ask.SelectItemTypeGui; import xyz.alexcrea.cuanvil.gui.config.global.UnitRepairConfigGui; @@ -17,26 +19,25 @@ import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.util.CasedStringUtil; +import xyz.alexcrea.cuanvil.util.MaterialUtil; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; +import java.util.*; import java.util.function.Consumer; -public class UnitRepairElementListGui extends SettingGuiListConfigGui implements ElementMappedToListGui { +public class UnitRepairElementListGui extends SettingGuiListConfigGui implements ElementMappedToListGui { - private final Material parentMaterial; + private final NamespacedKey parentMaterial; private final UnitRepairConfigGui parentGui; private final String materialName; private boolean shouldWork = true; - public UnitRepairElementListGui(@NotNull Material parentMaterial, + + public UnitRepairElementListGui(@NotNull NamespacedKey parentMaterial, @NotNull UnitRepairConfigGui parentGui) { - super("§e" + CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.name().toLowerCase()) + " §rUnit repair"); + super("§e" + CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.getKey().toLowerCase()) + " §rUnit repair"); this.parentMaterial = parentMaterial; this.parentGui = parentGui; - this.materialName = CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.name().toLowerCase()); + this.materialName = CasedStringUtil.snakeToUpperSpacedCase(parentMaterial.getKey().toLowerCase()); GuiGlobalItems.addBackItem(this.backgroundPane, parentGui); } @@ -54,7 +55,7 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui getCreateClickConsumer() { return event -> { event.setCancelled(true); - if(!this.shouldWork){ + if (!this.shouldWork) { return; } event.setCancelled(true); @@ -66,28 +67,28 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui { ItemMeta meta = itemStack.getItemMeta(); - Material type = itemStack.getType(); + NamespacedKey type = MaterialUtil.INSTANCE.getCustomType(itemStack); - if(!(meta instanceof Damageable) || (type.getMaxDurability() <= 0)) { + if (!(meta instanceof Damageable)) { player.sendMessage("§cThis item can't be damaged, so it can't be repaired."); return; } - if(type == this.parentMaterial){ + if (type.equals(this.parentMaterial)) { player.sendMessage("§cItem can't repair something of the same type."); return; } - String materialName = type.name().toLowerCase(); + String materialName = type.toString(); // Add new material - ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().set(parentMaterial.name().toLowerCase() + "." + materialName,0.25); + ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().set(parentMaterial.toString().toLowerCase() + "." + materialName, 0.25); if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) { ConfigHolder.UNIT_REPAIR_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE); } // Update gui - updateValueForGeneric(materialName, true); + updateValueForGeneric(type, true); this.parentGui.updateValueForGeneric(this.parentMaterial, true); @@ -106,17 +107,17 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui getEveryInstanceOfGeneric() { - ArrayList keys = new ArrayList<>(); - if(!this.shouldWork){ + protected Collection getEveryInstanceOfGeneric() { + Set keys = new HashSet<>(); + if (!this.shouldWork) { return keys; } - ConfigurationSection materialSection = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getConfigurationSection(parentMaterial.name().toLowerCase()); - if(materialSection == null){ - return keys; - } - keys.addAll(materialSection.getKeys(false)); + ConfigurationSection legacySection = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getConfigurationSection(parentMaterial.getKey().toLowerCase()); + ConfigurationSection materialSection = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().getConfigurationSection(parentMaterial.toString().toLowerCase()); + + addAllKeys(legacySection, keys); + addAllKeys(materialSection, keys); + return keys; } - private Material materialFromName(String materialName){ - Material mat = Material.getMaterial(materialName.toUpperCase()); - if(mat == null || mat.isAir()) return Material.BARRIER; + private void addAllKeys(@Nullable ConfigurationSection section, @NotNull Set keys) { + if (section == null) return; + for (var key : section.getKeys(false)) { + var material = NamespacedKey.fromString(key); + if (material == null) continue; + + keys.add(material); + } + } + + private Material materialFromName(NamespacedKey material) { + Material mat = MaterialUtil.INSTANCE.getMatFromKey(material); + if (mat == null || mat.isAir()) return Material.BARRIER; return mat; } @@ -163,7 +175,8 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui 0) return result // Get default val userDefault = config.getDouble(UNIT_REPAIR_DEFAULT_PATH, DEFAULT_DEFAULT_UNIT_REPAIR) @@ -41,6 +36,20 @@ object UnitRepairUtil { return userDefault } + private fun findRepairValue( + self: ItemStack, + other: ItemStack, + config: FileConfiguration + ): Double? { + val material = other.customType + val selfType = self.customType + + val result = checkSection(config, material.toString(), selfType) + if (result != null) return result + + return checkSection(config, material.key, selfType) + } + fun checkSection( config: FileConfiguration, path: String, From 6178282386451a2433b44fe87c660fce6b22a9f3 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 10:29:10 +0200 Subject: [PATCH 22/41] append new unit repair as minecraft namespace --- .../cuanvil/update/minecraft/Update_1_21.java | 1 - .../update/minecraft/Update_1_21_11.java | 36 +++++++++---------- .../update/minecraft/Update_1_21_9.java | 18 +++++----- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21.java b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21.java index 3aa60730..bbe35589 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21.java @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.update.minecraft; -import io.delilaheve.CustomAnvil; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.update.UpdateUtils; import xyz.alexcrea.cuanvil.update.Version; diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_11.java b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_11.java index d6395966..6dd8b5ba 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_11.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_11.java @@ -38,26 +38,26 @@ public class Update_1_21_11 extends MCUpdate{ addAbsentToList(conflictConfig, "restriction_fire_aspect.notAffectedGroups", "spears"); // Unit repair for spears - unitConfig.set("gold_ingot.golden_spear", 0.25); - unitConfig.set("copper_ingot.copper_spear", 0.25); - unitConfig.set("iron_ingot.iron_spear", 0.25); - unitConfig.set("diamond.diamond_spear", 0.25); - unitConfig.set("netherite_ingot.netherite_spear", 0.25); + unitConfig.set("minecraft:gold_ingot.minecraft:golden_spear", 0.25); + unitConfig.set("minecraft:copper_ingot.minecraft:copper_spear", 0.25); + unitConfig.set("minecraft:iron_ingot.minecraft:iron_spear", 0.25); + unitConfig.set("minecraft:diamond.minecraft:diamond_spear", 0.25); + unitConfig.set("minecraft:netherite_ingot.minecraft:netherite_spear", 0.25); - unitConfig.set("cobblestone.stone_spear", 0.25); - unitConfig.set("cobbled_deepslate.stone_spear", 0.25); + unitConfig.set("minecraft:cobblestone.stone_spear", 0.25); + unitConfig.set("minecraft:cobbled_deepslate.stone_spear", 0.25); - unitConfig.set("oak_planks.wooden_spear", 0.25); - unitConfig.set("spruce_planks.wooden_spear", 0.25); - unitConfig.set("birch_planks.wooden_spear", 0.25); - unitConfig.set("jungle_planks.wooden_spear", 0.25); - unitConfig.set("acacia_planks.wooden_spear", 0.25); - unitConfig.set("dark_oak_planks.wooden_spear", 0.25); - unitConfig.set("mangrove_planks.wooden_spear", 0.25); - unitConfig.set("cherry_planks.wooden_spear", 0.25); - unitConfig.set("bamboo_planks.wooden_spear", 0.25); - unitConfig.set("crimson_planks.wooden_spear", 0.25); - unitConfig.set("warped_planks.wooden_spear", 0.25); + unitConfig.set("minecraft:oak_planks.minecraft:wooden_spear", 0.25); + unitConfig.set("minecraft:spruce_planks.minecraft:wooden_spear", 0.25); + unitConfig.set("minecraft:birch_planks.minecraft:wooden_spear", 0.25); + unitConfig.set("minecraft:jungle_planks.minecraft:wooden_spear", 0.25); + unitConfig.set("minecraft:acacia_planks.minecraft:wooden_spear", 0.25); + unitConfig.set("minecraft:dark_oak_planks.minecraft:wooden_spear", 0.25); + unitConfig.set("minecraft:mangrove_planks.minecraft:wooden_spear", 0.25); + unitConfig.set("minecraft:cherry_planks.minecraft:wooden_spear", 0.25); + unitConfig.set("minecraft:bamboo_planks.minecraft:wooden_spear", 0.25); + unitConfig.set("minecraft:crimson_planks.minecraft:wooden_spear", 0.25); + unitConfig.set("minecraft:warped_planks.minecraft:wooden_spear", 0.25); // Create lunge enchant value and group baseConfig.set("enchant_limits.minecraft:lunge", 3); diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_9.java b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_9.java index d289b9bf..ec464ba1 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_9.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_9.java @@ -49,16 +49,16 @@ public class Update_1_21_9 extends MCUpdate{ public static void addCopperUnitRepair(FileConfiguration unitConfig) { // Add unit repair - unitConfig.set("copper_ingot.copper_helmet", 0.25); - unitConfig.set("copper_ingot.copper_chestplate", 0.25); - unitConfig.set("copper_ingot.copper_leggings", 0.25); - unitConfig.set("copper_ingot.copper_boots", 0.25); + unitConfig.set("minecraft:copper_ingot.minecraft:copper_helmet", 0.25); + unitConfig.set("minecraft:copper_ingot.minecraft:copper_chestplate", 0.25); + unitConfig.set("minecraft:copper_ingot.minecraft:copper_leggings", 0.25); + unitConfig.set("minecraft:copper_ingot.minecraft:copper_boots", 0.25); - unitConfig.set("copper_ingot.copper_pickaxe", 0.25); - unitConfig.set("copper_ingot.copper_shovel", 0.25); - unitConfig.set("copper_ingot.copper_hoe", 0.25); - unitConfig.set("copper_ingot.copper_axe", 0.25); - unitConfig.set("copper_ingot.copper_sword", 0.25); + unitConfig.set("minecraft:copper_ingot.minecraft:copper_pickaxe", 0.25); + unitConfig.set("minecraft:copper_ingot.minecraft:copper_shovel", 0.25); + unitConfig.set("minecraft:copper_ingot.minecraft:copper_hoe", 0.25); + unitConfig.set("minecraft:copper_ingot.minecraft:copper_axe", 0.25); + unitConfig.set("minecraft:copper_ingot.minecraft:copper_sword", 0.25); } } From bc9ac1cc138dbe232f25b70602b2f7df770f407e Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 13:21:18 +0200 Subject: [PATCH 23/41] add unit repair to item config --- .../cuanvil/gui/config/global/ItemConfigGui.java | 14 ++++++++------ .../gui/config/global/UnitRepairConfigGui.java | 2 +- .../xyz/alexcrea/cuanvil/util/UnitRepairUtil.kt | 15 +++++++++++++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java index 3bc19d5f..35633289 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java @@ -9,8 +9,10 @@ import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; +import xyz.alexcrea.cuanvil.util.UnitRepairUtil; import java.util.Collections; @@ -40,7 +42,7 @@ public class ItemConfigGui extends ChestGui { displayMeta.setDisplayName("§aConfiguring " + material); displayItemstack.setItemMeta(displayMeta); - pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance)); + pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance)); // Enchantment Conflicts item ItemStack enchantConflictItemstack = new ItemStack(Material.OAK_FENCE); @@ -76,8 +78,7 @@ public class ItemConfigGui extends ChestGui { unitRepairMeta.setLore(Collections.singletonList("§7Click here to open anvil unit repair menu")); unirRepairItemstack.setItemMeta(unitRepairMeta); - //TODO - GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, UnitRepairConfigGui.getInstance()); + GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, getUnitRepairConfigGui(material)); pane.bindItem('7', unitRepairItem); // Custom recipe item @@ -118,16 +119,17 @@ public class ItemConfigGui extends ChestGui { return groupConfigGui; } - /*private UnitRepairConfigGui getUnitRepairConfigGui(NamespacedKey material) { + private UnitRepairConfigGui getUnitRepairConfigGui(NamespacedKey material) { if (unitRepairConfigGui == null) { unitRepairConfigGui = new UnitRepairConfigGui(this); unitRepairConfigGui.setFilter(otherMat -> - group.contain(material) //TODO check material & what inside + otherMat.equals(material) || UnitRepairUtil.INSTANCE.findRawRepairValue( + material, otherMat, ConfigHolder.UNIT_REPAIR_HOLDER.getConfig()) != null ); unitRepairConfigGui.init(); } return unitRepairConfigGui; - }*/ + } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java index cc4a981f..54c4ce13 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/UnitRepairConfigGui.java @@ -60,7 +60,7 @@ public class UnitRepairConfigGui extends protected ItemStack createItemForGeneric(@NotNull NamespacedKey material) { var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig(); var section = unitConfig.getConfigurationSection(material.toString().toLowerCase()); - var legacySection = unitConfig.getConfigurationSection(material.toString().toLowerCase()); + var legacySection = unitConfig.getConfigurationSection(material.getKey().toLowerCase()); String materialName = CasedStringUtil.snakeToUpperSpacedCase(material.getKey().toLowerCase()); diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/UnitRepairUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/UnitRepairUtil.kt index 642a047d..5d059870 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/UnitRepairUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/UnitRepairUtil.kt @@ -25,7 +25,7 @@ object UnitRepairUtil { if (other == null) return null val config = ConfigHolder.UNIT_REPAIR_HOLDER.config - val result = findRepairValue(this, other, config) ?: return null + val result = findRawRepairValue(this, other, config) ?: return null if(result > 0) return result @@ -36,7 +36,7 @@ object UnitRepairUtil { return userDefault } - private fun findRepairValue( + private fun findRawRepairValue( self: ItemStack, other: ItemStack, config: FileConfiguration @@ -50,6 +50,17 @@ object UnitRepairUtil { return checkSection(config, material.key, selfType) } + fun findRawRepairValue( + self: NamespacedKey, + other: NamespacedKey, + config: FileConfiguration + ): Double? { + val result = checkSection(config, other.toString(), self) + if (result != null) return result + + return checkSection(config, other.key, self) + } + fun checkSection( config: FileConfiguration, path: String, From 8ea1db382f7dbace0f790d2d68443859be1e0f19 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 13:35:46 +0200 Subject: [PATCH 24/41] add custom recipe filter --- .../config/global/CustomRecipeConfigGui.java | 5 +++ .../gui/config/global/ItemConfigGui.java | 35 +++++++++++++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java index ba094126..aafb87f8 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/CustomRecipeConfigGui.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.gui.config.global; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import org.bukkit.Material; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -40,6 +41,10 @@ public class CustomRecipeConfigGui extends MappedGuiListConfigGui @@ -107,7 +109,7 @@ public class ItemConfigGui extends ChestGui { return enchantConflictGui; } - private GroupConfigGui getGroupConfigGui(NamespacedKey material) { + private GroupConfigGui getGroupConfigGui(@NotNull NamespacedKey material) { if (groupConfigGui == null) { groupConfigGui = new GroupConfigGui(this); groupConfigGui.setFilter(group -> @@ -119,7 +121,7 @@ public class ItemConfigGui extends ChestGui { return groupConfigGui; } - private UnitRepairConfigGui getUnitRepairConfigGui(NamespacedKey material) { + private UnitRepairConfigGui getUnitRepairConfigGui(@NotNull NamespacedKey material) { if (unitRepairConfigGui == null) { unitRepairConfigGui = new UnitRepairConfigGui(this); unitRepairConfigGui.setFilter(otherMat -> @@ -132,4 +134,25 @@ public class ItemConfigGui extends ChestGui { return unitRepairConfigGui; } + private CustomRecipeConfigGui getCustomRecipeConfigGui(@NotNull NamespacedKey material) { + if (customRecipeConfigGui == null) { + customRecipeConfigGui = new CustomRecipeConfigGui(this); + customRecipeConfigGui.setFilter(recipe -> { + if(isMaterial(recipe.getLeftItem(), material)) return true; + if(isMaterial(recipe.getRightItem(), material)) return true; + return isMaterial(recipe.getResultItem(), material); + } + ); + customRecipeConfigGui.init(); + } + + return customRecipeConfigGui; + } + + private boolean isMaterial(@Nullable ItemStack item, @NotNull NamespacedKey material) { + if(item == null) return false; + + return material.equals(MaterialUtil.INSTANCE.getCustomType(item)); + } + } From 23c7b0c75346b5abe8854f63f42f68595bd1fe81 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 1 Jul 2026 13:40:06 +0200 Subject: [PATCH 25/41] disable create item if has filter --- .../cuanvil/gui/config/global/ItemConfigGui.java | 3 ++- .../cuanvil/gui/config/list/ElementListConfigGui.java | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java index 063e7cd0..456e7e03 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java @@ -14,6 +14,7 @@ import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; +import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.MaterialUtil; import xyz.alexcrea.cuanvil.util.UnitRepairUtil; @@ -27,7 +28,7 @@ public class ItemConfigGui extends ChestGui { public CustomRecipeConfigGui customRecipeConfigGui; public ItemConfigGui(@NotNull Material display, @NotNull NamespacedKey material) { - super(3, material.getKey() + " Config", CustomAnvil.instance); + super(3, CasedStringUtil.snakeToUpperSpacedCase(material.getKey().toLowerCase()) + " Config", CustomAnvil.instance); Pattern pattern = new Pattern( "0000D0000", diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java index 1386b31d..19d31d9f 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java @@ -37,6 +37,7 @@ public abstract class ElementListConfigGui extends ChestGui implements ValueU protected PatternPane backgroundPane; private Predicate filter = (t) -> true; + private boolean hasDefaultFilter = true; protected ElementListConfigGui(@NotNull String title, Gui parent) { super(6, title, CustomAnvil.instance); @@ -51,6 +52,7 @@ public abstract class ElementListConfigGui extends ChestGui implements ValueU public void setFilter(Predicate filter) { this.filter = filter; + this.hasDefaultFilter = false; } protected Pattern getBackgroundPattern() { @@ -119,7 +121,12 @@ public abstract class ElementListConfigGui extends ChestGui implements ValueU viewer.setItemOnCursor(cursor); }, CustomAnvil.instance); - GuiItem createNew = prepareCreateNewItem(); + GuiItem createNew; + if(hasDefaultFilter) + createNew = prepareCreateNewItem(); + else + createNew = GuiSharedConstant.SECONDARY_BACKGROUND_ITEM; + if (createNew != null) { this.backgroundPane.bindItem('C', createNew); } From a9af606ae9bd443910812f63b577947295db6316 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 7 Jul 2026 15:22:22 +0200 Subject: [PATCH 26/41] refactor gui item creation --- .../cuanvil/gui/config/MainConfigGui.java | 189 ++++++++++-------- .../gui/config/global/ItemConfigGui.java | 59 ++---- .../cuanvil/command/EditConfigExecutor.kt | 2 +- 3 files changed, 123 insertions(+), 127 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/MainConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/MainConfigGui.java index cc4fddc5..57cc35bc 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/MainConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/MainConfigGui.java @@ -2,6 +2,7 @@ package xyz.alexcrea.cuanvil.gui.config; import com.github.stefvanschie.inventoryframework.gui.GuiItem; import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.pane.PatternPane; import com.github.stefvanschie.inventoryframework.pane.util.Pattern; import io.delilaheve.CustomAnvil; @@ -39,116 +40,142 @@ public class MainConfigGui extends ChestGui { GuiGlobalItems.addBackgroundItem(pane); // Basic config item - ItemStack basicConfigItemstack = new ItemStack(Material.COMMAND_BLOCK); - ItemMeta basicConfigMeta = basicConfigItemstack.getItemMeta(); - assert basicConfigMeta != null; - - basicConfigMeta.setDisplayName("§aBasic Config Menu"); - basicConfigMeta.setLore(Collections.singletonList("§7Click here to open basic config menu")); - basicConfigItemstack.setItemMeta(basicConfigMeta); - - GuiItem basicConfigItem = GuiGlobalItems.goToGuiItem(basicConfigItemstack, new BasicConfigGui(packetManager)); + var basicConfigItem = basicConfigItem(new BasicConfigGui(packetManager)); pane.bindItem('1', basicConfigItem); // enchant level limit item - ItemStack enchantLimitItemstack = new ItemStack(Material.ENCHANTED_BOOK); - ItemMeta enchantLimitMeta = enchantLimitItemstack.getItemMeta(); - assert enchantLimitMeta != null; - - enchantLimitMeta.setDisplayName("§aEnchantment Level Limit"); - enchantLimitMeta.setLore(Collections.singletonList("§7Click here to open enchantment level limit menu")); - enchantLimitItemstack.setItemMeta(enchantLimitMeta); - - GuiItem enchantLimitItem = GuiGlobalItems.goToGuiItem(enchantLimitItemstack, new EnchantLimitConfigGui()); + var enchantLimitItem = enchantLimitItem(new EnchantLimitConfigGui()); pane.bindItem('2', enchantLimitItem); // enchant level limit item - ItemStack enchantMergeLimitItemstack = new ItemStack(Material.ENCHANTED_BOOK); - ItemMeta enchantMergeLimitMeta = enchantMergeLimitItemstack.getItemMeta(); - assert enchantMergeLimitMeta != null; - - enchantMergeLimitMeta.setDisplayName("§aEnchantment Merge Limit"); - enchantMergeLimitMeta.setLore(Collections.singletonList("§7Click here to open enchantment merge limit menu")); - enchantMergeLimitItemstack.setItemMeta(enchantMergeLimitMeta); - - GuiItem enchantMergeLimitItem = GuiGlobalItems.goToGuiItem(enchantMergeLimitItemstack, new EnchantMergeLimitConfigGui()); + var enchantMergeLimitItem = enchantMergeLimitItem(new EnchantMergeLimitConfigGui()); pane.bindItem('3', enchantMergeLimitItem); // enchant cost item - ItemStack enchantCostItemstack = new ItemStack(Material.EXPERIENCE_BOTTLE); - ItemMeta enchantCostMeta = enchantCostItemstack.getItemMeta(); - assert enchantCostMeta != null; - - enchantCostMeta.setDisplayName("§aEnchantment Cost"); - enchantCostMeta.setLore(Collections.singletonList("§7Click here to open enchantment costs menu")); - enchantCostItemstack.setItemMeta(enchantCostMeta); - - GuiItem enchantCostItem = GuiGlobalItems.goToGuiItem(enchantCostItemstack, new EnchantCostConfigGui()); + var enchantCostItem = enchantCostItem(new EnchantCostConfigGui()); pane.bindItem('4', enchantCostItem); // Enchantment Conflicts item - ItemStack enchantConflictItemstack = new ItemStack(Material.OAK_FENCE); - ItemMeta enchantConflictMeta = enchantConflictItemstack.getItemMeta(); - assert enchantConflictMeta != null; - - enchantConflictMeta.setDisplayName("§aEnchantment Conflict"); - enchantConflictMeta.setLore(Collections.singletonList("§7Click here to open enchantment conflict menu")); - enchantConflictItemstack.setItemMeta(enchantConflictMeta); - - GuiItem enchantConflictItem = GuiGlobalItems.goToGuiItem(enchantConflictItemstack, EnchantConflictGui.getInstance()); + var enchantConflictItem = enchantConflictItem(EnchantConflictGui.getInstance()); pane.bindItem('5', enchantConflictItem); // Group config items - ItemStack groupItemstack = new ItemStack(Material.CHEST); - ItemMeta groupMeta = groupItemstack.getItemMeta(); - assert groupMeta != null; - - groupMeta.setDisplayName("§aItem Groups"); - groupMeta.setLore(Collections.singletonList("§7Click here to open item group menu")); - groupItemstack.setItemMeta(groupMeta); - - GuiItem groupConfigItem = GuiGlobalItems.goToGuiItem(groupItemstack, GroupConfigGui.getInstance()); - + var groupConfigItem = groupConfigItem(GroupConfigGui.getInstance()); pane.bindItem('6', groupConfigItem); // Unit repair item - ItemStack unirRepairItemstack = new ItemStack(Material.DIAMOND); - ItemMeta unitRepairMeta = unirRepairItemstack.getItemMeta(); - assert unitRepairMeta != null; - - unitRepairMeta.setDisplayName("§aUnit Repair"); - unitRepairMeta.setLore(Collections.singletonList("§7Click here to open anvil unit repair menu")); - unirRepairItemstack.setItemMeta(unitRepairMeta); - - GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, UnitRepairConfigGui.getInstance()); + var unitRepairItem = unitRepairItem(UnitRepairConfigGui.getInstance()); pane.bindItem('7', unitRepairItem); // Custom recipe item - ItemStack customRecipeItemstack = new ItemStack(Material.CRAFTING_TABLE); - ItemMeta customRecipeMeta = customRecipeItemstack.getItemMeta(); - assert customRecipeMeta != null; - - customRecipeMeta.setDisplayName("§aCustom recipes"); - customRecipeMeta.setLore(Collections.singletonList("§7Click here to open anvil custom recipe menu")); - customRecipeItemstack.setItemMeta(customRecipeMeta); - - GuiItem customRecipeItem = GuiGlobalItems.goToGuiItem(customRecipeItemstack, CustomRecipeConfigGui.getInstance()); + var customRecipeItem = customRecipeItem(CustomRecipeConfigGui.getInstance()); pane.bindItem('8', customRecipeItem); // quit item - ItemStack quitItemstack = new ItemStack(Material.BARRIER); - ItemMeta quitMeta = quitItemstack.getItemMeta(); - assert quitMeta != null; + pane.bindItem('Q', quitItem()); + } - quitMeta.setDisplayName("§cQuit"); - quitItemstack.setItemMeta(quitMeta); + public static GuiItem basicConfigItem(Gui target) { + var item = new ItemStack(Material.COMMAND_BLOCK); + var meta = item.getItemMeta(); + assert meta != null; - GuiItem quitItem = new GuiItem(quitItemstack, event -> { + meta.setDisplayName("§aBasic Config Menu"); + meta.setLore(Collections.singletonList("§7Click here to open basic config menu")); + item.setItemMeta(meta); + return GuiGlobalItems.goToGuiItem(item, target); + } + + public static GuiItem enchantLimitItem(Gui target) { + var item = new ItemStack(Material.ENCHANTED_BOOK); + var meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName("§aEnchantment Level Limit"); + meta.setLore(Collections.singletonList("§7Click here to open enchantment level limit menu")); + item.setItemMeta(meta); + return GuiGlobalItems.goToGuiItem(item, target); + } + + public static GuiItem enchantMergeLimitItem(Gui target) { + ItemStack item = new ItemStack(Material.ENCHANTED_BOOK); + ItemMeta meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName("§aEnchantment Merge Limit"); + meta.setLore(Collections.singletonList("§7Click here to open enchantment merge limit menu")); + item.setItemMeta(meta); + return GuiGlobalItems.goToGuiItem(item, target); + } + + public static GuiItem enchantCostItem(Gui target) { + ItemStack item = new ItemStack(Material.EXPERIENCE_BOTTLE); + ItemMeta meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName("§aEnchantment Cost"); + meta.setLore(Collections.singletonList("§7Click here to open enchantment costs menu")); + item.setItemMeta(meta); + return GuiGlobalItems.goToGuiItem(item, target); + } + + public static GuiItem enchantConflictItem(Gui target) { + var item = new ItemStack(Material.OAK_FENCE); + var meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName("§aEnchantment Conflict"); + meta.setLore(Collections.singletonList("§7Click here to open enchantment conflict menu")); + item.setItemMeta(meta); + return GuiGlobalItems.goToGuiItem(item, target); + } + + public static GuiItem groupConfigItem(Gui target) { + var item = new ItemStack(Material.CHEST); + var meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName("§aItem Groups"); + meta.setLore(Collections.singletonList("§7Click here to open item group menu")); + item.setItemMeta(meta); + return GuiGlobalItems.goToGuiItem(item, target); + } + + public static GuiItem unitRepairItem(Gui target) { + var item = new ItemStack(Material.DIAMOND); + var meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName("§aUnit Repair"); + meta.setLore(Collections.singletonList("§7Click here to open anvil unit repair menu")); + item.setItemMeta(meta); + + return GuiGlobalItems.goToGuiItem(item, target); + } + + public static GuiItem customRecipeItem(Gui target) { + var item = new ItemStack(Material.CRAFTING_TABLE); + var meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName("§aCustom recipes"); + meta.setLore(Collections.singletonList("§7Click here to open anvil custom recipe menu")); + item.setItemMeta(meta); + return GuiGlobalItems.goToGuiItem(item, target); + } + + public static GuiItem quitItem() { + var item = new ItemStack(Material.BARRIER); + var meta = item.getItemMeta(); + assert meta != null; + + meta.setDisplayName("§cQuit"); + item.setItemMeta(meta); + + return new GuiItem(item, event -> { event.setCancelled(true); event.getWhoClicked().closeInventory(); }, CustomAnvil.instance); - pane.bindItem('Q', quitItem); - } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java index 456e7e03..d721619a 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java @@ -12,14 +12,13 @@ import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.gui.config.MainConfigGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.MaterialUtil; import xyz.alexcrea.cuanvil.util.UnitRepairUtil; -import java.util.Collections; - public class ItemConfigGui extends ChestGui { public EnchantConflictGui enchantConflictGui; @@ -33,7 +32,7 @@ public class ItemConfigGui extends ChestGui { Pattern pattern = new Pattern( "0000D0000", "056000780", - "000000000" + "Q00000000" ); PatternPane pane = new PatternPane(0, 0, 9, 3, pattern); addPane(pane); @@ -49,53 +48,23 @@ public class ItemConfigGui extends ChestGui { pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance)); // Enchantment Conflicts item - ItemStack enchantConflictItemstack = new ItemStack(Material.OAK_FENCE); - ItemMeta enchantConflictMeta = enchantConflictItemstack.getItemMeta(); - assert enchantConflictMeta != null; - - enchantConflictMeta.setDisplayName("§aEnchantment Conflict"); - enchantConflictMeta.setLore(Collections.singletonList("§7Click here to open enchantment conflict menu")); - enchantConflictItemstack.setItemMeta(enchantConflictMeta); - - GuiItem enchantConflictItem = GuiGlobalItems.goToGuiItem(enchantConflictItemstack, getEnchantConflictGui(material)); + GuiItem enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui(material)); pane.bindItem('5', enchantConflictItem); // Group config items - ItemStack groupItemstack = new ItemStack(Material.CHEST); - ItemMeta groupMeta = groupItemstack.getItemMeta(); - assert groupMeta != null; - - groupMeta.setDisplayName("§aItem Groups"); - groupMeta.setLore(Collections.singletonList("§7Click here to open item group menu")); - groupItemstack.setItemMeta(groupMeta); - - GuiItem groupConfigItem = GuiGlobalItems.goToGuiItem(groupItemstack, getGroupConfigGui(material)); - + GuiItem groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui(material)); pane.bindItem('6', groupConfigItem); // Unit repair item - ItemStack unirRepairItemstack = new ItemStack(Material.DIAMOND); - ItemMeta unitRepairMeta = unirRepairItemstack.getItemMeta(); - assert unitRepairMeta != null; - - unitRepairMeta.setDisplayName("§aUnit Repair"); - unitRepairMeta.setLore(Collections.singletonList("§7Click here to open anvil unit repair menu")); - unirRepairItemstack.setItemMeta(unitRepairMeta); - - GuiItem unitRepairItem = GuiGlobalItems.goToGuiItem(unirRepairItemstack, getUnitRepairConfigGui(material)); + GuiItem unitRepairItem = MainConfigGui.unitRepairItem(getUnitRepairConfigGui(material)); pane.bindItem('7', unitRepairItem); // Custom recipe item - ItemStack customRecipeItemstack = new ItemStack(Material.CRAFTING_TABLE); - ItemMeta customRecipeMeta = customRecipeItemstack.getItemMeta(); - assert customRecipeMeta != null; - - customRecipeMeta.setDisplayName("§aCustom recipes"); - customRecipeMeta.setLore(Collections.singletonList("§7Click here to open anvil custom recipe menu")); - customRecipeItemstack.setItemMeta(customRecipeMeta); - - GuiItem customRecipeItem = GuiGlobalItems.goToGuiItem(customRecipeItemstack, getCustomRecipeConfigGui(material)); + GuiItem customRecipeItem = MainConfigGui.customRecipeItem(getCustomRecipeConfigGui(material)); pane.bindItem('8', customRecipeItem); + + // quit item + pane.bindItem('Q', MainConfigGui.quitItem()); } private EnchantConflictGui getEnchantConflictGui(@NotNull NamespacedKey material) { @@ -139,10 +108,10 @@ public class ItemConfigGui extends ChestGui { if (customRecipeConfigGui == null) { customRecipeConfigGui = new CustomRecipeConfigGui(this); customRecipeConfigGui.setFilter(recipe -> { - if(isMaterial(recipe.getLeftItem(), material)) return true; - if(isMaterial(recipe.getRightItem(), material)) return true; - return isMaterial(recipe.getResultItem(), material); - } + if (isMaterial(recipe.getLeftItem(), material)) return true; + if (isMaterial(recipe.getRightItem(), material)) return true; + return isMaterial(recipe.getResultItem(), material); + } ); customRecipeConfigGui.init(); } @@ -151,7 +120,7 @@ public class ItemConfigGui extends ChestGui { } private boolean isMaterial(@Nullable ItemStack item, @NotNull NamespacedKey material) { - if(item == null) return false; + if (item == null) return false; return material.equals(MaterialUtil.INSTANCE.getCustomType(item)); } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index 8aa54a96..0345441c 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -86,7 +86,7 @@ class EditConfigExecutor : CASubCommand() { private fun processItem(sender: HumanEntity) { val item = sender.inventory.itemInMainHand - if(item.isAir) { + if (item.isAir) { sender.sendMessage("Cannot configure the item in hand") return } From 341dd10e3faf994c21f60f01c97c2adb48243f88 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 7 Jul 2026 17:27:32 +0200 Subject: [PATCH 27/41] start of enchant config gui --- .../cuanvil/enchant/CAEnchantment.java | 9 ++ .../gui/config/global/EnchantConfigGui.java | 138 ++++++++++++++++++ .../gui/config/global/ItemConfigGui.java | 6 +- .../cuanvil/command/EditConfigExecutor.kt | 3 +- 4 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConfigGui.java diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java index ea657ace..1d1aca46 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.enchant.bulk.BulkCleanEnchantOperation; import xyz.alexcrea.cuanvil.enchant.bulk.BulkGetEnchantOperation; import xyz.alexcrea.cuanvil.group.EnchantConflictGroup; +import xyz.alexcrea.cuanvil.util.CasedStringUtil; import java.util.Collection; import java.util.HashMap; @@ -45,6 +46,14 @@ public interface CAEnchantment { @NotNull String getName(); + /** + * Get the enchantment name prettified (upper spaced case) + * @return Prettier enchantment name + */ + default String getPrettyName() { + return CasedStringUtil.snakeToUpperSpacedCase(getName()); + } + /** * Get the default maximum level of this enchantment. * @return The default maximum level of this enchantment. diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConfigGui.java new file mode 100644 index 00000000..aa79c64c --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConfigGui.java @@ -0,0 +1,138 @@ +package xyz.alexcrea.cuanvil.gui.config.global; + +import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.ChestGui; +import com.github.stefvanschie.inventoryframework.pane.PatternPane; +import com.github.stefvanschie.inventoryframework.pane.util.Pattern; +import io.delilaheve.CustomAnvil; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import xyz.alexcrea.cuanvil.api.EnchantmentApi; +import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.enchant.CAEnchantment; +import xyz.alexcrea.cuanvil.group.EnchantConflictGroup; +import xyz.alexcrea.cuanvil.gui.config.MainConfigGui; +import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; +import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; +import xyz.alexcrea.cuanvil.util.CasedStringUtil; +import xyz.alexcrea.cuanvil.util.MaterialUtil; +import xyz.alexcrea.cuanvil.util.UnitRepairUtil; + +import java.lang.ref.PhantomReference; +import java.lang.ref.SoftReference; +import java.lang.ref.WeakReference; +import java.util.Collections; +import java.util.HashMap; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +public class EnchantConfigGui extends ChestGui { + + public EnchantLimitConfigGui enchantLimitConfigGui; + public EnchantMergeLimitConfigGui enchantMergeLimitConfigGui; + public EnchantCostConfigGui enchantCostConfigGui; + public EnchantConflictGui enchantConflictGui; + public GroupConfigGui groupConfigGui; + + public EnchantConfigGui(@NotNull Set enchantments) { + super(3, + "Configuring Enchantments", + CustomAnvil.instance); + + Pattern pattern = new Pattern( + "0000D0000", + "023405600", + "Q00000000" + ); + PatternPane pane = new PatternPane(0, 0, 9, 3, pattern); + addPane(pane); + + GuiGlobalItems.addBackgroundItem(pane); + + ItemStack displayItemstack = new ItemStack(Material.ENCHANTED_BOOK); + ItemMeta displayMeta = displayItemstack.getItemMeta(); + assert displayMeta != null; + + displayMeta.setDisplayName("§aConfiguring Enchantments:"); + displayItemstack.setItemMeta(displayMeta); + + // Set enchantments + HashMap enchantmentMap = new HashMap<>(); + for (CAEnchantment enchantment : enchantments) { + enchantmentMap.put(enchantment, 1); + } + EnchantmentApi.setEnchantments(displayItemstack, enchantmentMap); + + pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance)); + + // enchant level limit item + var enchantLimitItem = MainConfigGui.enchantLimitItem(new EnchantLimitConfigGui()); //TODO + pane.bindItem('2', enchantLimitItem); + + // enchant level limit item + var enchantMergeLimitItem = MainConfigGui.enchantMergeLimitItem(new EnchantMergeLimitConfigGui()); //TODO + pane.bindItem('3', enchantMergeLimitItem); + + // enchant cost item + var enchantCostItem = MainConfigGui.enchantCostItem(new EnchantCostConfigGui()); //TODO + pane.bindItem('4', enchantCostItem); + + // Enchantment Conflicts item + var enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui(enchantments)); + pane.bindItem('5', enchantConflictItem); + + // Group config items + var groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui(enchantments)); + pane.bindItem('6', groupConfigItem); + + // quit item + pane.bindItem('Q', MainConfigGui.quitItem()); + } + + @NotNull + @Contract(pure = true) + private Predicate getGroupFilter(@NotNull Set enchantments) { + return group -> group.getEnchants() + .stream() + .anyMatch(enchantments::contains); + } + + private EnchantConflictGui getEnchantConflictGui(@NotNull Set enchantments) { + if (enchantConflictGui == null) { + enchantConflictGui = new EnchantConflictGui(this); + enchantConflictGui.setFilter(getGroupFilter(enchantments)); + enchantConflictGui.init(); + } + + return enchantConflictGui; + } + + private GroupConfigGui getGroupConfigGui(@NotNull Set enchantments) { + if (groupConfigGui == null) { + groupConfigGui = new GroupConfigGui(this); + + // Get all the conflict related to this enchantment + var groups = ConfigHolder.CONFLICT_HOLDER + .getConflictManager() + .getConflictList() + .stream() + .filter(getGroupFilter(enchantments)) + .map(EnchantConflictGroup::getCantConflictGroup) + .collect(Collectors.toSet()); + + groupConfigGui.setFilter(group -> + groups.stream().anyMatch(other -> other.isReferencing(group)) + ); + groupConfigGui.init(); + } + + return groupConfigGui; + } + +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java index d721619a..f7691d6e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java @@ -27,7 +27,11 @@ public class ItemConfigGui extends ChestGui { public CustomRecipeConfigGui customRecipeConfigGui; public ItemConfigGui(@NotNull Material display, @NotNull NamespacedKey material) { - super(3, CasedStringUtil.snakeToUpperSpacedCase(material.getKey().toLowerCase()) + " Config", CustomAnvil.instance); + super(3, + CasedStringUtil.snakeToUpperSpacedCase( + material.getKey().toLowerCase() + ) + " Config", + CustomAnvil.instance); Pattern pattern = new Pattern( "0000D0000", diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index 0345441c..b11bfb4a 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -9,6 +9,7 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.gui.config.MainConfigGui +import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions import xyz.alexcrea.cuanvil.util.MaterialUtil.customType @@ -80,7 +81,7 @@ class EditConfigExecutor : CASubCommand() { } } - // TODO open enchantments edit gui + EnchantConfigGui(enchantToFilter).show(sender) } From b2561f55aec737bbca597fd7d33c505c455236d7 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 7 Jul 2026 21:55:41 +0200 Subject: [PATCH 28/41] per enchant config finished --- .../global/AbstractEnchantConfigGui.java | 5 + .../gui/config/global/EnchantConfigGui.java | 126 +++++++++++++----- .../config/global/EnchantCostConfigGui.java | 27 ++-- .../config/global/EnchantLimitConfigGui.java | 12 +- .../global/EnchantMergeLimitConfigGui.java | 16 ++- .../gui/config/global/ItemConfigGui.java | 8 +- .../config/list/SettingGuiListConfigGui.java | 18 ++- .../settings/EnchantCostSettingsGui.java | 3 +- .../gui/config/settings/IntSettingsGui.java | 6 +- 9 files changed, 162 insertions(+), 59 deletions(-) diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java index b4f732d4..5583b382 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/AbstractEnchantConfigGui.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.gui.config.global; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.pane.util.Pattern; import org.bukkit.event.inventory.InventoryClickEvent; import xyz.alexcrea.cuanvil.enchant.CAEnchantment; @@ -30,6 +31,10 @@ public abstract class AbstractEnchantConfigGui enchantments; + private final PatternPane pane; + + private EnchantLimitConfigGui enchantLimitConfigGui; + private EnchantMergeLimitConfigGui enchantMergeLimitConfigGui; + private EnchantCostConfigGui enchantCostConfigGui; + + private EnchantConflictGui enchantConflictGui; + private GroupConfigGui groupConfigGui; public EnchantConfigGui(@NotNull Set enchantments) { super(3, "Configuring Enchantments", CustomAnvil.instance); + this.enchantments = enchantments; Pattern pattern = new Pattern( "0000D0000", "023405600", "Q00000000" ); - PatternPane pane = new PatternPane(0, 0, 9, 3, pattern); + pane = new PatternPane(0, 0, 9, 3, pattern); addPane(pane); GuiGlobalItems.addBackgroundItem(pane); @@ -71,49 +69,93 @@ public class EnchantConfigGui extends ChestGui { pane.bindItem('D', new GuiItem(displayItemstack, GuiGlobalActions.stayInPlace, CustomAnvil.instance)); - // enchant level limit item - var enchantLimitItem = MainConfigGui.enchantLimitItem(new EnchantLimitConfigGui()); //TODO - pane.bindItem('2', enchantLimitItem); - - // enchant level limit item - var enchantMergeLimitItem = MainConfigGui.enchantMergeLimitItem(new EnchantMergeLimitConfigGui()); //TODO - pane.bindItem('3', enchantMergeLimitItem); - - // enchant cost item - var enchantCostItem = MainConfigGui.enchantCostItem(new EnchantCostConfigGui()); //TODO - pane.bindItem('4', enchantCostItem); + updateGuiValues(); // Enchantment Conflicts item - var enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui(enchantments)); + var enchantConflictItem = MainConfigGui.enchantConflictItem(getEnchantConflictGui()); pane.bindItem('5', enchantConflictItem); // Group config items - var groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui(enchantments)); + var groupConfigItem = MainConfigGui.groupConfigItem(getGroupConfigGui()); pane.bindItem('6', groupConfigItem); // quit item pane.bindItem('Q', MainConfigGui.quitItem()); } + private GuiItem enchantLimitConfigGui() { + if (enchantLimitConfigGui == null) { + enchantLimitConfigGui = new EnchantLimitConfigGui(this); + enchantLimitConfigGui.setFilter(enchantments::contains); + enchantLimitConfigGui.init(); + } + + // Bypass + if(enchantments.size() == 1) { + var enchant = enchantments.iterator().next(); + var factory = EnchantLimitConfigGui.createFactory(enchant, this); + + return enchantLimitConfigGui.itemFromFactory(enchant, factory); + } + + return MainConfigGui.enchantLimitItem(enchantLimitConfigGui); + } + + private GuiItem enchantMergeLimitConfigGui() { + if (enchantMergeLimitConfigGui == null) { + enchantMergeLimitConfigGui = new EnchantMergeLimitConfigGui(this); + enchantMergeLimitConfigGui.setFilter(enchantments::contains); + enchantMergeLimitConfigGui.init(); + } + + // Bypass + if(enchantments.size() == 1) { + var enchant = enchantments.iterator().next(); + var factory = EnchantMergeLimitConfigGui.createFactory(enchant, this); + + return enchantMergeLimitConfigGui.itemFromFactory(enchant, factory); + } + + return MainConfigGui.enchantMergeLimitItem(enchantMergeLimitConfigGui); + } + + private GuiItem enchantCostConfigGui() { + if (enchantCostConfigGui == null) { + enchantCostConfigGui = new EnchantCostConfigGui(this); + enchantCostConfigGui.setFilter(enchantments::contains); + enchantCostConfigGui.init(); + } + + // Bypass + if(enchantments.size() == 1) { + var enchant = enchantments.iterator().next(); + var factory = EnchantCostConfigGui.createFactory(enchant, this); + + return enchantCostConfigGui.itemFromFactory(enchant, factory); + } + + return MainConfigGui.enchantCostItem(enchantCostConfigGui); + } + @NotNull @Contract(pure = true) - private Predicate getGroupFilter(@NotNull Set enchantments) { + private Predicate getGroupFilter() { return group -> group.getEnchants() .stream() .anyMatch(enchantments::contains); } - private EnchantConflictGui getEnchantConflictGui(@NotNull Set enchantments) { + private EnchantConflictGui getEnchantConflictGui() { if (enchantConflictGui == null) { enchantConflictGui = new EnchantConflictGui(this); - enchantConflictGui.setFilter(getGroupFilter(enchantments)); + enchantConflictGui.setFilter(getGroupFilter()); enchantConflictGui.init(); } return enchantConflictGui; } - private GroupConfigGui getGroupConfigGui(@NotNull Set enchantments) { + private GroupConfigGui getGroupConfigGui() { if (groupConfigGui == null) { groupConfigGui = new GroupConfigGui(this); @@ -122,7 +164,7 @@ public class EnchantConfigGui extends ChestGui { .getConflictManager() .getConflictList() .stream() - .filter(getGroupFilter(enchantments)) + .filter(getGroupFilter()) .map(EnchantConflictGroup::getCantConflictGroup) .collect(Collectors.toSet()); @@ -135,4 +177,20 @@ public class EnchantConfigGui extends ChestGui { return groupConfigGui; } + @Override + public void updateGuiValues() { + // enchant level limit item + pane.bindItem('2', enchantLimitConfigGui()); + + // enchant level limit item + pane.bindItem('3', enchantMergeLimitConfigGui()); + + // enchant cost item + pane.bindItem('4', enchantCostConfigGui()); + } + + @Override + public Gui getConnectedGui() { + return this; + } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java index a6145368..677ca54d 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantCostConfigGui.java @@ -1,14 +1,14 @@ package xyz.alexcrea.cuanvil.gui.config.global; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.enchant.CAEnchantment; -import xyz.alexcrea.cuanvil.enchant.EnchantmentProperties; -import xyz.alexcrea.cuanvil.enchant.EnchantmentRarity; +import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.util.CasedStringUtil; @@ -18,13 +18,13 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; +import static io.delilaheve.util.ConfigOptions.ENCHANT_VALUES_ROOT; + /** * Global Config gui for enchantment cost settings. */ public class EnchantCostConfigGui extends AbstractEnchantConfigGui { - private static final String SECTION_NAME = "enchant_values"; - private static EnchantCostConfigGui INSTANCE = null; @Nullable @@ -37,18 +37,29 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui displayLore = factory.getDisplayLore(); - if(!displayLore.isEmpty()){ + if (!displayLore.isEmpty()) { lore.add(""); lore.addAll(displayLore); } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java index e9edbebf..1d5c9ec5 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantLimitConfigGui.java @@ -1,11 +1,13 @@ package xyz.alexcrea.cuanvil.gui.config.global; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import io.delilaheve.util.ConfigOptions; import org.bukkit.Material; import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.enchant.CAEnchantment; +import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui; import xyz.alexcrea.cuanvil.util.CasedStringUtil; @@ -36,14 +38,22 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui extends ElementListConfigGui< T >{ +public abstract class SettingGuiListConfigGui extends ElementListConfigGui { protected HashMap guiItemMap; protected HashMap factoryMap; + protected SettingGuiListConfigGui(@NotNull String title, Gui parent) { super(title, parent); this.guiItemMap = new HashMap<>(); @@ -44,7 +45,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu @Override public void updateValueForGeneric(T generic, boolean shouldUpdate) { - if(!this.factoryMap.containsKey(generic)){ + if (!this.factoryMap.containsKey(generic)) { // Create new item & factory S factory = createFactory(generic); GuiItem newItem = itemFromFactory(generic, factory); @@ -52,7 +53,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu addToPage(newItem); this.guiItemMap.put(generic, newItem); this.factoryMap.put(generic, factory); - }else{ + } else { S factory = this.factoryMap.get(generic); // Update old item GuiItem oldItem = this.guiItemMap.get(generic); @@ -61,7 +62,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu updateGuiItem(oldItem, newItem); } - if(shouldUpdate){ + if (shouldUpdate) { update(); } } @@ -74,7 +75,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu super.reloadValues(); } - private void updateGuiItem(GuiItem oldITem, GuiItem newItem){ + private void updateGuiItem(GuiItem oldITem, GuiItem newItem) { oldITem.setItem(newItem.getItem()); oldITem.setProperties(newItem.getProperties()); oldITem.setVisible(newItem.isVisible()); @@ -86,17 +87,22 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu } @Override // Not used - protected void updateGeneric(T generic, ItemStack usedItem) {} + protected void updateGeneric(T generic, ItemStack usedItem) { + } + @Override // Not used protected ItemStack createItemForGeneric(T generic) { return null; } protected abstract List getCreateItemLore(); + protected abstract Consumer getCreateClickConsumer(); + protected abstract String createItemName(); protected abstract S createFactory(T generic); + protected abstract GuiItem itemFromFactory(T generic, S factory); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java index 2fbc47ad..0d4bc89a 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantCostSettingsGui.java @@ -183,7 +183,7 @@ public class EnchantCostSettingsGui extends IntSettingsGui { assert nowMeta != null; nowMeta.setDisplayName("§fValue: §e" + nowBook); - if(!holder.displayLore.isEmpty()){ + if (!holder.displayLore.isEmpty()) { nowMeta.setLore(holder.displayLore); } @@ -202,7 +202,6 @@ public class EnchantCostSettingsGui extends IntSettingsGui { } pane.bindItem('D', returnToDefault); - } /** diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java index 73121a64..c32d22ca 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/IntSettingsGui.java @@ -318,9 +318,9 @@ public class IntSettingsGui extends AbstractSettingGui { this.defaultVal = defaultVal; this.steps = steps; - if(displayLore == null){ + if (displayLore == null) { this.displayLore = Collections.emptyList(); - }else { + } else { this.displayLore = displayLore; } } @@ -392,7 +392,7 @@ public class IntSettingsGui extends AbstractSettingGui { protected String deltaDisplay(ValueDisplayType type, int now, int planned) { var delta = planned - now; - if(delta < 0) return "§c" + delta; + if (delta < 0) return "§c" + delta; else return "§a+" + delta; } From c062684a3cea5a5b98b5113ce8fc49685f126281 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 7 Jul 2026 22:13:57 +0200 Subject: [PATCH 29/41] do not allow gui in tab completer --- .../kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt index 648dbc1d..9287a7c7 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt @@ -80,6 +80,7 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { if(args.size < 2) { for ((key, cmd) in commands) { if(!cmd.allowed(sender)) continue + if("gui".contentEquals(key)) continue result.add(key) } } else { From a202df9f0af21daea8cb8cd20e80adc838600e77 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 8 Jul 2026 03:28:10 +0200 Subject: [PATCH 30/41] add /ca enchant --- README.md | 3 +- src/main/kotlin/io/delilaheve/CustomAnvil.kt | 2 + .../alexcrea/cuanvil/command/CASubCommand.kt | 11 ++ .../cuanvil/command/CustomAnvilCommand.kt | 8 +- .../cuanvil/command/EditConfigExecutor.kt | 12 -- .../cuanvil/command/EnchantExecutor.kt | 113 ++++++++++++++++++ .../cuanvil/command/ReloadExecutor.kt | 1 - src/main/resources/plugin.yml | 3 + 8 files changed, 136 insertions(+), 17 deletions(-) create mode 100644 src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt diff --git a/README.md b/README.md index 9d9e678e..27d08fac 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,8 @@ ca.bypass.level: Allow player to bypass every level limit (no custom limit) # Command permissions ca.command.reload: Allow administrator to reload the plugin's configs -ca.command.diagnostic: Allow adminastator to diagnistic some simple problem with the plugin +ca.command.diagnostic: Get debug information about the plugin and server +ca.command.enchantment: Allows to set enchantment to holden item ca.config.edit: Allow administrator to edit the plugin's config in game # ----------------------------------------------------------------------------- diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index a5cac722..906e023f 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -57,6 +57,8 @@ open class CustomAnvil : JavaPlugin() { // Permission string required to edit the plugin's config const val editConfigPermission = "ca.config.edit" + // Permission string required to edit the plugin's config + const val giveEnchantmentPermission = "ca.command.enchantment" // Command Name to reload the config const val commandReloadName = "anvilconfigreload" diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt index 4c71c68b..60dcdbee 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt @@ -4,6 +4,7 @@ import org.bukkit.ChatColor import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender +import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry abstract class CASubCommand: CommandExecutor { @@ -43,4 +44,14 @@ abstract class CASubCommand: CommandExecutor { return "no description" } + protected fun allEnchantmentsByName(): Collection { + val names = mutableSetOf() + for (enchantment in CAEnchantmentRegistry.getInstance().values()) { + names.add(enchantment.name) + names.add(enchantment.key.toString()) + } + + return names + } + } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt index 9287a7c7..9b9402c9 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt @@ -7,7 +7,6 @@ import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import org.bukkit.command.TabCompleter import xyz.alexcrea.cuanvil.util.MetricsUtil -import java.util.ArrayList class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { @@ -18,13 +17,14 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { private val editConfigCommand = EditConfigExecutor() private val helpCommand = HelpExecutor() - private val commands = ImmutableMap.of( + private val commands: ImmutableMap = ImmutableMap.of( "gui", editConfigCommand, "config", editConfigCommand, "reload", ReloadExecutor(), "diagnostic", DiagnosticExecutor(), "debug", DebugToggleExecutor(), "help", helpCommand, + "enchant", EnchantExecutor(), ) init { @@ -95,9 +95,11 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { } //assumed all provided tab completed string are lowercase + val prefix = args[args.size - 1] return result.stream() - .filter { it.startsWith(args[args.size - 1]) } + .filter { it.startsWith(prefix) } .sorted() .toList() } + } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index b11bfb4a..c6bc191b 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -7,7 +7,6 @@ import org.bukkit.entity.HumanEntity import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil import xyz.alexcrea.cuanvil.enchant.CAEnchantment -import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.gui.config.MainConfigGui import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui @@ -103,16 +102,6 @@ class EditConfigExecutor : CASubCommand() { // Tab completer // --------------- - private fun allEnchantmentsByName(): Collection { - val names = mutableSetOf() - for (enchantment in CAEnchantmentRegistry.getInstance().values()) { - names.add(enchantment.name) - names.add(enchantment.key.toString()) - } - - return names - } - override fun tabCompleter(sender: CommandSender, args: Array, list: MutableList) { list.addAll( when (args.size) { @@ -127,7 +116,6 @@ class EditConfigExecutor : CASubCommand() { else -> listOf() } ) - } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt new file mode 100644 index 00000000..dd2957fa --- /dev/null +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt @@ -0,0 +1,113 @@ +package xyz.alexcrea.cuanvil.command + +import io.delilaheve.CustomAnvil +import io.delilaheve.util.ConfigOptions +import org.bukkit.command.Command +import org.bukkit.command.CommandSender +import org.bukkit.entity.HumanEntity +import xyz.alexcrea.cuanvil.api.EnchantmentApi +import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir + +class EnchantExecutor : CASubCommand() { + + + override fun allowed(sender: CommandSender): Boolean { + return sender.hasPermission(CustomAnvil.giveEnchantmentPermission) + } + + override fun description(): String { + return "Allows to set enchantment to holden item" + } + + override fun executeCommand( + sender: CommandSender, + cmd: Command, + cmdstr: String, + args: Array + ): Boolean { + if (sender !is HumanEntity) return true + + if (!allowed(sender)) { + sender.sendMessage("No permission to execute this command") + return true + } + + when (args.size) { + 0 -> { + sender.sendMessage("Missing enchantment parameter") + return true + } + + 1 -> { + sender.sendMessage("Missing level parameter") + return true + } + } + + val enchants = EnchantmentApi.getListByName(args[0].lowercase()) + if (enchants.isEmpty()) { + sender.sendMessage("Enchantment not found: ${args[0]}") + return true + } + + val enchant = enchants.iterator().next() + + val level = args[1].toIntOrNull()?.coerceIn(0, ConfigOptions.ENCHANT_LIMIT) + if (level == null) { + sender.sendMessage("Invalid number: ${args[1]}") + return true + } + + val inHand = sender.inventory.itemInMainHand + if (inHand.isAir) { + sender.sendMessage("Cannot enchant this item") + return true + } + + if (level == 0) { + enchant.removeFrom(inHand) + sender.sendMessage("${enchant.prettyName} removed") + } else { + enchant.addEnchantmentUnsafe(inHand, level) + sender.sendMessage("${enchant.prettyName} set to level $level") + } + + return true + } + + override fun tabCompleter(sender: CommandSender, args: Array, list: MutableList) { + if (sender !is HumanEntity) return + + list.addAll( + when (args.size) { + 1 -> allEnchantmentsByName() + 2 -> findEnchantmentLevels(sender, args[0]) + + else -> listOf() + } + ) + } + + private fun findEnchantmentLevels( + sender: HumanEntity, + name: String + ): Collection { + val enchants = EnchantmentApi.getListByName(name.lowercase()) + if (enchants.isEmpty()) return listOf() + + val enchant = enchants.iterator().next() + val limit = ConfigOptions.enchantLimit(enchant) + val result = mutableListOf() + + for (i in 1 until limit + 1) { + result.add(i.toString()) + } + + val inHand = sender.inventory.itemInMainHand + if (enchant.isEnchantmentPresent(inHand)) + result.add("0") + + return result + } + +} diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt index ef23e7d6..cb0d24a9 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt @@ -3,7 +3,6 @@ package xyz.alexcrea.cuanvil.command import io.delilaheve.CustomAnvil import org.bukkit.Bukkit import org.bukkit.command.Command -import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent import xyz.alexcrea.cuanvil.config.ConfigHolder diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index dab9997b..d436b10a 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -43,6 +43,9 @@ permissions: ca.command.diagnostic: default: op description: Get debug information about the plugin and server + ca.command.enchantment: + default: op + description: Allows to set enchantment to holden item ca.config.edit: default: op description: Allow administrator to edit the plugin's config in game From 4fc037ebcedd07e48890945959bc910bb9cc188f Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 8 Jul 2026 03:28:41 +0200 Subject: [PATCH 31/41] version bump --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 76ab4c00..3c34895e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.17.7" +version = "1.18.0" val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true" From cf768d67bd57bdaaadc4657ddae5c2dbaf46e89b Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 8 Jul 2026 03:42:14 +0200 Subject: [PATCH 32/41] more proper comment [ci skip] --- .../alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt index a9c7f396..52630454 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilUseTypeUtil.kt @@ -5,16 +5,11 @@ import io.delilaheve.util.ConfigOptions object AnvilUseTypeUtil { /* - By stupidity of kotlin not allowing static function outside of companion object I need to do another util class only for 1 function: + By kotlin not having static function outside of companion object I need to do another util class only for 1 function: Companion object on enum class seems to get initialized AFTER the enum itself - that mean. if you want to call a static function on the enum class itself YOU CAN'T. you need to do this stupid thing - or you can make a stupid top level function OR object that even worse because of global scope pollution - (btw was gpt ""solution"". fortunately I do not "vibe code" so I do what I know instead of stupid AI solution & code) - I mean, this is still global scope pollution bc of a USELESS class that SHOULD not exist but as a class is better than a random *ss function - - sorry for the rent but this made me frustrated - - Note: I still like a lot of part of kotlin compared to java but this part is one that I hate + that mean. if you want to call a static function on enum construction YOU CAN'T. you need to do this stupid thing, + or you can make a stupid top level function or object that at least as bad as this + I mean, this is still an unnecessary class that should not exist but as a class is better than a random function in my opinion */ /** * Get config path for normal anvil use From 007a664db12e47b758c4579e7e8c068f8cb1382e Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 23 Apr 2026 13:01:00 +0200 Subject: [PATCH 33/41] initial 1.21 transition --- build.gradle.kts | 2 +- gradle.properties | 2 +- nms/v1_17R1/.gitignore | 1 - nms/v1_17R1/build.gradle.kts | 35 ------------------- .../packet/versions/V1_17R1_PacketManager.kt | 33 ----------------- nms/v1_18R1/.gitignore | 1 - nms/v1_18R1/build.gradle.kts | 35 ------------------- .../packet/versions/V1_18R1_PacketManager.kt | 33 ----------------- nms/v1_18R2/.gitignore | 1 - nms/v1_18R2/build.gradle.kts | 35 ------------------- .../packet/versions/V1_18R2_PacketManager.kt | 33 ----------------- nms/v1_19R1/.gitignore | 1 - nms/v1_19R1/build.gradle.kts | 35 ------------------- .../packet/versions/V1_19R1_PacketManager.kt | 33 ----------------- nms/v1_19R2/.gitignore | 1 - nms/v1_19R2/build.gradle.kts | 35 ------------------- .../packet/versions/V1_19R2_PacketManager.kt | 33 ----------------- nms/v1_19R3/.gitignore | 1 - nms/v1_19R3/build.gradle.kts | 35 ------------------- .../packet/versions/V1_19R3_PacketManager.kt | 33 ----------------- nms/v1_20R1/.gitignore | 1 - nms/v1_20R1/build.gradle.kts | 35 ------------------- .../packet/versions/V1_20R1_PacketManager.kt | 33 ----------------- nms/v1_20R2/.gitignore | 1 - nms/v1_20R2/build.gradle.kts | 35 ------------------- .../packet/versions/V1_20R2_PacketManager.kt | 33 ----------------- nms/v1_20R3/.gitignore | 1 - nms/v1_20R3/build.gradle.kts | 35 ------------------- .../packet/versions/V1_20R3_PacketManager.kt | 33 ----------------- nms/v1_20R4/.gitignore | 1 - nms/v1_20R4/build.gradle.kts | 35 ------------------- .../packet/versions/V1_20R4_PacketManager.kt | 33 ----------------- .../settings/EnchantSelectSettingGui.java | 4 +-- .../settings/GroupSelectSettingGui.java | 4 +-- .../cuanvil/command/DiagnosticExecutor.kt | 7 ++-- 35 files changed, 10 insertions(+), 699 deletions(-) delete mode 100644 nms/v1_17R1/.gitignore delete mode 100644 nms/v1_17R1/build.gradle.kts delete mode 100644 nms/v1_17R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_17R1_PacketManager.kt delete mode 100644 nms/v1_18R1/.gitignore delete mode 100644 nms/v1_18R1/build.gradle.kts delete mode 100644 nms/v1_18R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R1_PacketManager.kt delete mode 100644 nms/v1_18R2/.gitignore delete mode 100644 nms/v1_18R2/build.gradle.kts delete mode 100644 nms/v1_18R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R2_PacketManager.kt delete mode 100644 nms/v1_19R1/.gitignore delete mode 100644 nms/v1_19R1/build.gradle.kts delete mode 100644 nms/v1_19R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R1_PacketManager.kt delete mode 100644 nms/v1_19R2/.gitignore delete mode 100644 nms/v1_19R2/build.gradle.kts delete mode 100644 nms/v1_19R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R2_PacketManager.kt delete mode 100644 nms/v1_19R3/.gitignore delete mode 100644 nms/v1_19R3/build.gradle.kts delete mode 100644 nms/v1_19R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R3_PacketManager.kt delete mode 100644 nms/v1_20R1/.gitignore delete mode 100644 nms/v1_20R1/build.gradle.kts delete mode 100644 nms/v1_20R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R1_PacketManager.kt delete mode 100644 nms/v1_20R2/.gitignore delete mode 100644 nms/v1_20R2/build.gradle.kts delete mode 100644 nms/v1_20R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R2_PacketManager.kt delete mode 100644 nms/v1_20R3/.gitignore delete mode 100644 nms/v1_20R3/build.gradle.kts delete mode 100644 nms/v1_20R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R3_PacketManager.kt delete mode 100644 nms/v1_20R4/.gitignore delete mode 100644 nms/v1_20R4/build.gradle.kts delete mode 100644 nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R4_PacketManager.kt diff --git a/build.gradle.kts b/build.gradle.kts index 3c34895e..e3ef6a3a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -55,7 +55,7 @@ val reobfNMS = providers.gradleProperty("subprojects.reobfnms") dependencies { // Spigot api - compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT") // fast stats implementation("dev.faststats.metrics:bukkit:0.27.0") diff --git a/gradle.properties b/gradle.properties index 4397d2e8..8bf9e80a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ signing.secretKeyRingFile=~/.gnupg/secring.gpg kotlin.daemon.jvmargs=-Xmx8G # list of nms -subprojects.reobfnms=v1_17R1,v1_18R1,v1_18R2,v1_19R1,v1_19R2,v1_19R3,v1_20R1,v1_20R2,v1_20R3,v1_20R4,v1_21R1,v1_21R2,v1_21R3,v1_21R4,v1_21R5,v1_21R6,v1_21R7 +subprojects.reobfnms=v1_21R1,v1_21R2,v1_21R3,v1_21R4,v1_21R5,v1_21R6,v1_21R7 # list of version for hangar release paperVersion=1.18-26.2 diff --git a/nms/v1_17R1/.gitignore b/nms/v1_17R1/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_17R1/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_17R1/build.gradle.kts b/nms/v1_17R1/build.gradle.kts deleted file mode 100644 index c354b1ce..00000000 --- a/nms/v1_17R1/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.17.1-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "16" - targetCompatibility = "16" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_16) - } -} diff --git a/nms/v1_17R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_17R1_PacketManager.kt b/nms/v1_17R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_17R1_PacketManager.kt deleted file mode 100644 index c820eabf..00000000 --- a/nms/v1_17R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_17R1_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_17R1_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_18R1/.gitignore b/nms/v1_18R1/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_18R1/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_18R1/build.gradle.kts b/nms/v1_18R1/build.gradle.kts deleted file mode 100644 index 44873d5a..00000000 --- a/nms/v1_18R1/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.18.1-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "17" - targetCompatibility = "17" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/nms/v1_18R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R1_PacketManager.kt b/nms/v1_18R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R1_PacketManager.kt deleted file mode 100644 index 71df5c72..00000000 --- a/nms/v1_18R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R1_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_18R1_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_18R2/.gitignore b/nms/v1_18R2/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_18R2/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_18R2/build.gradle.kts b/nms/v1_18R2/build.gradle.kts deleted file mode 100644 index cf349ec6..00000000 --- a/nms/v1_18R2/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.18.2-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "17" - targetCompatibility = "17" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/nms/v1_18R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R2_PacketManager.kt b/nms/v1_18R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R2_PacketManager.kt deleted file mode 100644 index ee442f5e..00000000 --- a/nms/v1_18R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_18R2_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_18R2_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_19R1/.gitignore b/nms/v1_19R1/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_19R1/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_19R1/build.gradle.kts b/nms/v1_19R1/build.gradle.kts deleted file mode 100644 index 9791b9b9..00000000 --- a/nms/v1_19R1/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.19.2-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "17" - targetCompatibility = "17" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/nms/v1_19R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R1_PacketManager.kt b/nms/v1_19R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R1_PacketManager.kt deleted file mode 100644 index 7a057fcc..00000000 --- a/nms/v1_19R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R1_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_19_R1.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_19R1_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_19R2/.gitignore b/nms/v1_19R2/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_19R2/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_19R2/build.gradle.kts b/nms/v1_19R2/build.gradle.kts deleted file mode 100644 index 88f1a8ad..00000000 --- a/nms/v1_19R2/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.19.3-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "17" - targetCompatibility = "17" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/nms/v1_19R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R2_PacketManager.kt b/nms/v1_19R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R2_PacketManager.kt deleted file mode 100644 index 0d04cd1f..00000000 --- a/nms/v1_19R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R2_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_19R2_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_19R3/.gitignore b/nms/v1_19R3/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_19R3/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_19R3/build.gradle.kts b/nms/v1_19R3/build.gradle.kts deleted file mode 100644 index 3d609af4..00000000 --- a/nms/v1_19R3/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.19.4-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "17" - targetCompatibility = "17" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_17) - } -} diff --git a/nms/v1_19R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R3_PacketManager.kt b/nms/v1_19R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R3_PacketManager.kt deleted file mode 100644 index 7c727912..00000000 --- a/nms/v1_19R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_19R3_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_19R3_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_20R1/.gitignore b/nms/v1_20R1/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_20R1/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_20R1/build.gradle.kts b/nms/v1_20R1/build.gradle.kts deleted file mode 100644 index 67b46b5e..00000000 --- a/nms/v1_20R1/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.20.1-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "18" - targetCompatibility = "18" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_18) - } -} diff --git a/nms/v1_20R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R1_PacketManager.kt b/nms/v1_20R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R1_PacketManager.kt deleted file mode 100644 index 1fbac836..00000000 --- a/nms/v1_20R1/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R1_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_20R1_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_20R2/.gitignore b/nms/v1_20R2/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_20R2/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_20R2/build.gradle.kts b/nms/v1_20R2/build.gradle.kts deleted file mode 100644 index e8417cd8..00000000 --- a/nms/v1_20R2/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "18" - targetCompatibility = "18" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_18) - } -} diff --git a/nms/v1_20R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R2_PacketManager.kt b/nms/v1_20R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R2_PacketManager.kt deleted file mode 100644 index a2db371b..00000000 --- a/nms/v1_20R2/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R2_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_20R2_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_20R3/.gitignore b/nms/v1_20R3/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_20R3/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_20R3/build.gradle.kts b/nms/v1_20R3/build.gradle.kts deleted file mode 100644 index c49ff48d..00000000 --- a/nms/v1_20R3/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "18" - targetCompatibility = "18" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_18) - } -} diff --git a/nms/v1_20R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R3_PacketManager.kt b/nms/v1_20R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R3_PacketManager.kt deleted file mode 100644 index 51c2ecb6..00000000 --- a/nms/v1_20R3/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R3_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_20R3_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/nms/v1_20R4/.gitignore b/nms/v1_20R4/.gitignore deleted file mode 100644 index 47374f17..00000000 --- a/nms/v1_20R4/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.lastDeploymentsId \ No newline at end of file diff --git a/nms/v1_20R4/build.gradle.kts b/nms/v1_20R4/build.gradle.kts deleted file mode 100644 index 3b98361e..00000000 --- a/nms/v1_20R4/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -group = rootProject.group -version = rootProject.version - -plugins { - id("io.papermc.paperweight.userdev") -} - -dependencies { - implementation(project(":nms:nms-common")) - - // Used for nms - paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") -} - -repositories { - maven("https://repo.papermc.io/repository/maven-public/") - -} - -// Set target version -tasks.withType().configureEach { - sourceCompatibility = "18" - targetCompatibility = "18" - - options.encoding = "UTF-8" -} - -kotlin { - compilerOptions { - apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0) - jvmTarget.set(JvmTarget.JVM_18) - } -} diff --git a/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R4_PacketManager.kt b/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R4_PacketManager.kt deleted file mode 100644 index ac1e504d..00000000 --- a/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/V1_20R4_PacketManager.kt +++ /dev/null @@ -1,33 +0,0 @@ -package xyz.alexcrea.cuanvil.dependency.packet.versions - -import net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket -import net.minecraft.world.entity.player.Abilities -import org.bukkit.craftbukkit.entity.CraftPlayer -import org.bukkit.entity.Player -import xyz.alexcrea.cuanvil.dependency.packet.PacketManager -import xyz.alexcrea.cuanvil.dependency.packet.PacketManagerBase - -class V1_20R4_PacketManager : PacketManagerBase(), PacketManager { - override val canSetInstantBuild: Boolean - get() = true - - override fun setInstantBuild(player: Player, instantBuild: Boolean) { - val nmsPlayer = (player as CraftPlayer).handle - val playerAbilities = nmsPlayer.abilities - val sendedAbilities: Abilities - if (playerAbilities.instabuild == instantBuild) { - sendedAbilities = playerAbilities - } else { - sendedAbilities = Abilities() - sendedAbilities.invulnerable = playerAbilities.invulnerable - sendedAbilities.flying = playerAbilities.flying - sendedAbilities.mayfly = playerAbilities.mayfly - sendedAbilities.instabuild = instantBuild - sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed - sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed - } - val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) - nmsPlayer.connection.send(packet) - } -} diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java index 397ae6f5..4473eb29 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java @@ -141,10 +141,10 @@ public class EnchantSelectSettingGui extends SettingGuiListConfigGui Date: Wed, 3 Jun 2026 04:25:10 +0200 Subject: [PATCH 34/41] progress on 1.21 transition --- .github/workflows/gradle.yml | 2 +- README.md | 7 +- defaultconfigs/1.18/README.md | 6 - defaultconfigs/1.18/config.yml | 472 ------------------ defaultconfigs/1.18/custom_recipes.yml | 5 - defaultconfigs/1.18/enchant_conflict.yml | 247 --------- defaultconfigs/1.18/item_groups.yml | 210 -------- defaultconfigs/1.18/unit_repair_item.yml | 190 ------- defaultconfigs/README.md | 1 - impl/LegacyEcoEnchant/build.gradle.kts | 2 +- nms/nms-common/build.gradle.kts | 6 +- nms/nms-paper/build.gradle.kts | 6 +- .../dependency/datapack/DataPackTester.kt | 26 +- .../cuanvil/enchant/EnchantmentRarity.java | 2 +- .../cuanvil/command/DiagnosticExecutor.kt | 35 +- .../cuanvil/dependency/DependencyManager.kt | 25 +- .../dependency/MinecraftVersionUtil.kt | 27 +- .../plugins/DisenchantmentDependency.kt | 18 +- .../dependency/plugins/HavenBagsDependency.kt | 10 +- .../cuanvil/listener/AnvilCloseListener.kt | 4 +- src/main/resources/enchant_conflict.yml | 3 - src/main/resources/item_groups.yml | 1 - src/main/resources/plugin.yml | 2 +- 23 files changed, 62 insertions(+), 1245 deletions(-) delete mode 100644 defaultconfigs/1.18/README.md delete mode 100644 defaultconfigs/1.18/config.yml delete mode 100644 defaultconfigs/1.18/custom_recipes.yml delete mode 100644 defaultconfigs/1.18/enchant_conflict.yml delete mode 100644 defaultconfigs/1.18/item_groups.yml delete mode 100644 defaultconfigs/1.18/unit_repair_item.yml diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index a50cacd8..befd5102 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -26,7 +26,7 @@ jobs: contents: write env: - MODRINTH_VERSIONS: '["1.18.x", "1.19.x", "1.20.x", "1.21.x", "26.1.x", "26.2.x"]' + MODRINTH_VERSIONS: '["1.21.x", "26.1.x", "26.2.x"]' MODRINTH_PLATFORMS: '["spigot", "paper", "purpur", "folia"]' steps: diff --git a/README.md b/README.md index 27d08fac..d568fde1 100644 --- a/README.md +++ b/README.md @@ -73,10 +73,9 @@ See the [Compatibility list](https://github.com/alexcrea/CustomAnvil/blob/v1.x.x One of the configurations allow displaying price about 40 and removing Too Expensive. \ By how the minecraft client work: price above 40 can only be displayed green, even if the player does not own enough experience level. -spigot version 1.18 to 1.21.11 do not need any ProtocoLib dependency. (26.1.0 or above requires it) \ -Any recent paper version also are supported for this feature. -But you should wait for update for new version containing new enchantable item or new enchantments if any of this got added. -Else it is, likely, fine to use the current version you are ussing on a new paper version +You do not need Protocolib unless you are using spigot above in 26.1 or above \ + +But you should wait for update or announcement for new version containing new enchantable item or new enchantments. ### For custom enchantment plugin developers For information about the API, please refer to [the Wiki](https://github.com/alexcrea/CustomAnvil/wiki) \ diff --git a/defaultconfigs/1.18/README.md b/defaultconfigs/1.18/README.md deleted file mode 100644 index d390f3f5..00000000 --- a/defaultconfigs/1.18/README.md +++ /dev/null @@ -1,6 +0,0 @@ -### Default Plugin's Configurations For 1.18 to 1.20.6 -- [config.yml](https://github.com/alexcrea/CustomAnvil/blob/master/defaultconfigs/1.18/config.yml) -- [enchant_conflict.yml](https://github.com/alexcrea/CustomAnvil/blob/master/defaultconfigs/1.18/enchant_conflict.yml) -- [item_groups.yml](https://github.com/alexcrea/CustomAnvil/blob/master/defaultconfigs/1.18/item_groups.yml) -- [unit_repair_item.yml](https://github.com/alexcrea/CustomAnvil/blob/master/defaultconfigs/1.18/unit_repair_item.yml) -- [custom_recipes.yml](https://github.com/alexcrea/CustomAnvil/blob/master/defaultconfigs/1.18/custom_recipes.yml) diff --git a/defaultconfigs/1.18/config.yml b/defaultconfigs/1.18/config.yml deleted file mode 100644 index 377b3499..00000000 --- a/defaultconfigs/1.18/config.yml +++ /dev/null @@ -1,472 +0,0 @@ -# -# It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! -# - -# What service of metric should custom anvil use -# Custom anvil collect generic information like server minecraft version, type, etc... -# It can also collect error information if error is happening (currently faststats only) -# It can also be disabled -# Please refer to README for public metric link -# Possible options: auto, bstat, faststats, disabled (auto by default) -metric_type: auto - -# Allow to report errors made caused by this plugin (only for faststats) -# This allows me to fix potentials issue that I'm not aware of -# Accept true or false (true by default) -metric_collect_errors: true - -# All anvil cost will be capped to limit_repair_value if enabled. -# -# In other words: -# For any anvil cost greater than limit_repair_value, Cost will be set to limit_repair_value. -limit_repair_cost: false - -# Max cost value the Anvil can get to. -# -# Valid values include 0 to 1000. -# Cost will be displayed as "Too Expensive": -# - If Cost is above 39 -# - And replace_too_expensive is disabled (false) -limit_repair_value: 39 - -# Whether the anvil's cost limit should be removed entirely. -# -# The anvil will still visually display "Too Expensive" if "replace_too_expensive" is disabled -# However, the action will be completable if xp requirement is meet. -remove_repair_limit: false - -# Whenever anvil cost is above 39 should display the true price and not "Too Expensive". -# -# However, when bypassing "Too Expensive", anvil price will be displayed as Green. -# If the action is not completable, the cost will still be displayed as "Too expensive". -# That mean you also need to change other settings like remove_repair_limit or limit_repair_cost. -# -# Require ProtocoLib. -replace_too_expensive: false - -# XP Level amount added to the anvil when the item is repaired by another item of the same type -# -# Valid values include 0 to 1000 -item_repair_cost: 2 - -# XP Level amount added to the anvil when the item is renamed -# -# Valid values include 0 to 1000 -item_rename_cost: 1 - -# XP Level amount added to the anvil when the item is repaired by an "unit" -# For example: a Diamond on a Diamond Sword -# What's considered unit for what can be edited on the unit repair configuration. -# -# Valid values include 0 to 1000 -unit_repair_cost: 1 - -# XP Level amount added to the anvil when a sacrifice enchantment -# conflict with one of the left item enchantment -# -# Valid values include 0 to 1000 -sacrifice_illegal_enchant_cost: 1 - -# Allow using color code and hexadecimal color. -# -# Color code are prefixed by "&" and hexadecimal color by "#". -# Color code will not be applied if it colors nothing. "&&" can be used to write "&". -# For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ -allow_color_code: false -allow_hexadecimal_color: false -allow_minimessage: false - -# This enables restricting color code for player having specific permission -# It requires allow_color_code enabled for... obvious reasons -# -# For example: if player want to use "&aHello" it will be required that the player has -# the permission "ca.color.code.a" as he used the color code "a" -# In general permission to give to the player is "ca.color.code.[code]" -# where [code] is the color code you wish to allow the player -# -# It is kinda of useless when minimessage is supported as players would be able to bypass -# that using the equivalent minimessage tag -per_color_code_permission: false - -# Toggle if color should only be applicable if the player a certain permission. -# -# permission are "ca.color.code" for use of color code and "ca.color.hex" for use of hexadecimal color. -permission_needed_for_color: true - -# Xp cost if the player use color in the items name on rename. -# -# Valid values include 0 to 1000. -use_of_color_cost: 0 - -# Dialogue rename menu make use of dialog menu to allow bigger rename -# You can also change the maximum size and set it to -1 or less for maximum -# -# This feature only work on paper 1.21.7 or later -# -# At the moment only english is available for this menu... sorry ! -# -# CustomAnvil use "ca.rename.dialog" when permission -enable_dialog_rename: false -dialog_rename_max_size: 256 -permission_needed_for_dialog_rename: false - -# This allows custom anvil to not "guess" the text used for rename but store it in the item -# It will make item stackable only and only if it had used the same rename text -# -# For practical reason. this only work when dialog rename is enabled -dialog_rename_keep_user_text: true - -# Also count left item enchantments for the final price -include_left_enchantment_for_cost: false - -# Override limits for specific enchants -# -# Enchantments not listed here will use the value of default_limit -# -# Overrides provided default from aqua_affinity to depth_strider won't change effect with extra levels -# -# Valid range of 0 - 255 for each enchantment -# -1 mean keep default -enchant_limits: - minecraft:aqua_affinity: 1 - minecraft:binding_curse: 1 - minecraft:channeling: 1 - minecraft:flame: 1 - minecraft:infinity: 1 - minecraft:mending: 1 - minecraft:multishot: 1 - minecraft:silk_touch: 1 - minecraft:vanishing_curse: 1 - minecraft:depth_strider: 3 # anything more than 3 is treated as 3 by the game - minecraft:protection: 4 - minecraft:fire_protection: 4 - minecraft:blast_protection: 4 - minecraft:projectile_protection: 4 - minecraft:feather_falling: 4 - minecraft:thorns: 3 - minecraft:respiration: 3 - minecraft:sharpness: 5 - minecraft:smite: 5 - minecraft:bane_of_arthropods: 5 - minecraft:knockback: 2 - minecraft:fire_aspect: 2 - minecraft:looting: 3 - minecraft:sweeping: 3 - minecraft:sweeping_edge: 3 - minecraft:efficiency: 5 - minecraft:unbreaking: 3 - minecraft:fortune: 3 - minecraft:power: 5 - minecraft:punch: 2 - minecraft:luck_of_the_sea: 3 - minecraft:lure: 3 - minecraft:frost_walker: 2 - minecraft:impaling: 5 - minecraft:riptide: 3 - minecraft:loyalty: 3 - minecraft:piercing: 4 - minecraft:quick_charge: 3 - minecraft:soul_speed: 3 - minecraft:swift_sneak: 3 - -# Multipliers used to calculate the enchantment's value in repair/combining -# -# Values here are pulled from the minecraft wiki: -# https://minecraft.wiki/w/Anvil_mechanics#Costs_for_combining_enchantments -# -# If an enchantment is missing values here, or is less than 0, it will default to 0 -# -# Calculated as: [Enchantment lvl] * [multiplier] -# -# With default values protection 4 would have a value of 4 when -# coming from either a book (4 * 1) or an item (4 * 1) -enchant_values: - minecraft:aqua_affinity: - item: 4 - book: 2 - minecraft:bane_of_arthropods: - item: 2 - book: 1 - minecraft:binding_curse: - item: 8 - book: 4 - minecraft:blast_protection: - item: 4 - book: 2 - minecraft:channeling: - item: 8 - book: 4 - minecraft:depth_strider: - item: 4 - book: 2 - minecraft:efficiency: - item: 1 - book: 1 - minecraft:flame: - item: 4 - book: 2 - minecraft:feather_falling: - item: 2 - book: 1 - minecraft:fire_aspect: - item: 4 - book: 2 - minecraft:fire_protection: - item: 2 - book: 1 - minecraft:fortune: - item: 4 - book: 2 - minecraft:frost_walker: - item: 4 - book: 2 - minecraft:impaling: - item: 4 - book: 2 - minecraft:infinity: - item: 8 - book: 4 - minecraft:knockback: - item: 2 - book: 1 - minecraft:looting: - item: 4 - book: 2 - minecraft:loyalty: - item: 1 - book: 1 - minecraft:luck_of_the_sea: - item: 4 - book: 2 - minecraft:lure: - item: 4 - book: 2 - minecraft:mending: - item: 4 - book: 2 - minecraft:multishot: - item: 4 - book: 2 - minecraft:piercing: - item: 1 - book: 1 - minecraft:power: - item: 1 - book: 1 - minecraft:projectile_protection: - item: 2 - book: 1 - minecraft:protection: - item: 1 - book: 1 - minecraft:punch: - item: 4 - book: 2 - minecraft:quick_charge: - item: 2 - book: 1 - minecraft:respiration: - item: 4 - book: 2 - minecraft:riptide: - item: 4 - book: 2 - minecraft:silk_touch: - item: 8 - book: 4 - minecraft:sharpness: - item: 1 - book: 1 - minecraft:smite: - item: 2 - book: 1 - minecraft:soul_speed: - item: 8 - book: 4 - minecraft:swift_sneak: - item: 8 - book: 4 - minecraft:sweeping: - item: 4 - book: 2 - minecraft:sweeping_edge: - item: 4 - book: 2 - minecraft:thorns: - item: 8 - book: 4 - minecraft:unbreaking: - item: 2 - book: 1 - minecraft:vanishing_curse: - item: 8 - book: 4 - -# Disable enchantment merging for level above the set value -# Enchantment merging is when, for example, 2 unbreaking II book combine to give sharpness III -# But Enchantment above this value can still be applied. following the previous example, we could still apply a unbreaking III book to a sword -# Even if disable-merge-over of unbreaking is set to 2 -# -1 mean enchantment merge for this enchantment is not disabled. default to -1 if absent. -disable-merge-over: - # Sharpness is set to -1. it equivalent to it not being set to anything (and work as vanilla on default configuration) - minecraft:sharpness: -1 - # If uncommented. 2 unbreaking II book would not give an unbreaking III book. but unbreaking III book can still be applied - #minecraft:unbreaking: 2 - -# The maximum number of enchantment an item can get. -1 for infinity -# Use eco enchant enchant_limit if present by default unless "default" is not equal to -1 -enchantment_count_limit: - default: -1 - # Limit for specific items. example bellow is an example with stick - # Per item enchantment limit override eco enchant enchant_limit and default limit - items: - stick: -1 - -# Settings for lore modification -lore_edit: - book_and_quil: - # Permission is ca.lore_edit.book - use_permission: true - append: - # If adding lore using book & quil is enabled - enabled: false - # Cost used every time - fixed_cost: 1 - # Cost used for every lore line added - per_line_cost: 0 - # Use left item vanilla cost penalty if any - shared_increase: false - # Increase shared left item cost penalty - shared_additive: false - # If adding the lore consume the book & quil - do_consume: false - # Allow using color code and hexadecimal color when editing lore via book & quil - # - # Color code are prefixed by "&" and hexadecimal color by "#" - # Color code will not be applied if it colors nothing. "&&" can be used to write "&" - # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ - # - # Note that currently minimessage would disable hex code when adding color - allow_color_code: true - allow_hexadecimal_color: false - allow_minimessage: true - - remove: - # If removing lore using book & quil is enabled - enabled: false - # Cost used every time - fixed_cost: 1 - # Cost used for every lore line removed - per_line_cost: 0 - # Use left item vanilla cost penalty if any - shared_increase: false - # Increase shared left item cost penalty - shared_additive: false - # If removing the lore consume the book & quil - do_consume: false - # Cost of replacing colors - remove_color_cost: 0 - # Allowed some color and tags to be reverted to plain text - # Custom anvil will prioritise format that result is a smaller resulting text - # Note that not allowing certain format will lead to some lost of color or tags. - # If configuration are exact as append appending this book should result in the exact same color - # - # Color code will be prefixed by "&" and hexadecimal color by "#". - # If color code is allowed, "&" in the text will get converted to "&&" - # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ - allow_color_code: true - allow_hexadecimal_color: false - allow_minimessage: true - - paper: - # Permission is ca.lore_edit.paper - use_permission: true - # what order should the lines should get added/removed (start/end, if invalid or not present will be end) - order: end - - append_line: - # If adding lore line using paper is enabled - enabled: false - # Cost used every time - fixed_cost: 1 - # Use left item vanilla cost penalty if any - shared_increase: false - # Increase shared left item cost penalty - shared_additive: false - # If adding the lore line consume the paper - do_consume: false - # Allow using color code and hexadecimal color when editing lore via book & quil - # - # Color code are prefixed by "&" and hexadecimal color by "#" - # Color code will not be applied if it colors nothing. "&&" can be used to write "&" - # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ - # - # Note that currently minimessage would disable hex code when adding color - allow_color_code: true - allow_hexadecimal_color: false - allow_minimessage: true - color_use_cost: 0 - - remove_line: - # If removing lore line using paper is enabled - enabled: false - # Cost used every time - fixed_cost: 1 - # Use left item vanilla cost penalty if any - shared_increase: false - # Increase shared left item cost penalty - shared_additive: false - # If removing the lore line consume the paper - do_consume: false - # Cost of replacing colors - remove_color_cost: 0 - # Allowed some color and tags to be reverted to plain text - # Custom anvil will prioritise format that result is a smaller resulting text - # Note that not allowing certain format will lead to some lost of color or tags. - # If configuration are exact as append appending this paper should result in the exact same color - # - # Color code will be prefixed by "&" and hexadecimal color by "#". - # If color code is allowed, "&" in the text will get converted to "&&" - # For minimessage see minimessage formating https://docs.papermc.io/adventure/minimessage/format/ - allow_color_code: true - allow_hexadecimal_color: false - allow_minimessage: true - -# Allow to replace the xp cost by a monetary cost -# If enabled it will not be bound to the experience level limits -# -# It also requires to enable dialog rename (set "enable_dialog_rename: false" a bit higher) -# If dialog rename permission is enabled and player do not have the permission merge will fall back to vanilla xp cost -# -# If you are using custom craft I recommend using Linear Xp Cost with Exact Linear Xp as normal Xp Cost will act "weird" -# But Linear Xp will act as 1$ time global multiplier. In other word: like you expect -# -# As this feature require dialog rename, it can only be enabled starting with paper 1.21.6 and later -monetary_cost: - enabled: false - # If using vault unlocked this allow to specify what currency should be used for anvil usage - # default being the default currency - currency: default - # multiply the anvil cost by a value to allow to have price a big bigger than like 40 - multipliers: - # global multipliers. all usage type will be multiplied by this value - global: 1.0 - # usage specific type. it will only apply for specific xp "reason" - enchantment: 1.0 # related to enchantments level - repair: 1.0 # for repairing via unit repair (per unit) - rename: 1.0 # for renaming the item - lore_edit: 1.0 # for changing the lore of the item (only if lore edit is enabled) - work_penalty: 1.0 # for work penalty (aka use penalty) - recipe: 1.0 # for custom anvil recipe cost - -# Whether to show debug logging -debug_log: false - -# Whether to show verbose debug logging -debug_log_verbose: false - -# Whether to show inside the console or require to run /ca debug get -display_debug_in_console: false - -configVersion: 1.11.0 diff --git a/defaultconfigs/1.18/custom_recipes.yml b/defaultconfigs/1.18/custom_recipes.yml deleted file mode 100644 index 57c2220c..00000000 --- a/defaultconfigs/1.18/custom_recipes.yml +++ /dev/null @@ -1,5 +0,0 @@ -# ---------------------------------------------------- -# This config file is to store custom craft -# It is recommended to use the in game config editor for this configuration. -# /customanvilconfig With ca.config.edit permission -# ---------------------------------------------------- diff --git a/defaultconfigs/1.18/enchant_conflict.yml b/defaultconfigs/1.18/enchant_conflict.yml deleted file mode 100644 index 31506d2b..00000000 --- a/defaultconfigs/1.18/enchant_conflict.yml +++ /dev/null @@ -1,247 +0,0 @@ -# -# It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! -# - -# material conflicts -# -# If you want to edit this file: -# - A conflict will apply to every item except if in one of the notAffectedGroups group -# - the conflict will count only if the user try to combine at least as -# many conflicting enchantment as "maxEnchantmentBeforeConflict" -# -# -# ---------------------------------------------------- -# These restriction are about not allowing enchantment -# on illegal items -# ---------------------------------------------------- - -restriction_aqua_affinity: - enchantments: [ minecraft:aqua_affinity ] - notAffectedGroups: [ enchanted_book, helmets ] - -restriction_bane_of_arthropods: - enchantments: [ minecraft:bane_of_arthropods ] - notAffectedGroups: [ enchanted_book, melee_weapons ] - -restriction_blast_protection: - enchantments: [ minecraft:blast_protection ] - notAffectedGroups: [ enchanted_book, armors ] - -restriction_channeling: - enchantments: [ minecraft:channeling ] - notAffectedGroups: [ enchanted_book, trident ] - -restriction_binding_curse: - enchantments: [ minecraft:binding_curse ] - notAffectedGroups: [ enchanted_book, wearable ] - -restriction_vanishing_curse: - enchantments: [ minecraft:vanishing_curse ] - notAffectedGroups: [ enchanted_book, can_vanish ] - -restriction_depth_strider: - enchantments: [ minecraft:depth_strider ] - notAffectedGroups: [ enchanted_book, boots ] - -restriction_efficiency: - enchantments: [ minecraft:efficiency ] - notAffectedGroups: [ enchanted_book, tools, shears ] - -restriction_feather_falling: - enchantments: [ minecraft:feather_falling ] - notAffectedGroups: [ enchanted_book, boots ] - -restriction_fire_aspect: - enchantments: [ minecraft:fire_aspect ] - notAffectedGroups: [ enchanted_book, swords ] - -restriction_fire_protection: - enchantments: [ minecraft:fire_protection ] - notAffectedGroups: [ enchanted_book, armors ] - -restriction_flame: - enchantments: [ minecraft:flame ] - notAffectedGroups: [ enchanted_book, bow ] - -restriction_fortune: - enchantments: [ minecraft:fortune ] - notAffectedGroups: [ enchanted_book, tools ] - -restriction_frost_walker: - enchantments: [ minecraft:frost_walker ] - notAffectedGroups: [ enchanted_book, boots ] - -restriction_impaling: - enchantments: [ minecraft:impaling ] - notAffectedGroups: [ enchanted_book, trident ] - -restriction_infinity: - enchantments: [ minecraft:infinity ] - notAffectedGroups: [ enchanted_book, bow ] - -restriction_knockback: - enchantments: [ minecraft:knockback ] - notAffectedGroups: [ enchanted_book, swords ] - -restriction_looting: - enchantments: [ minecraft:looting ] - notAffectedGroups: [ enchanted_book, swords ] - -restriction_loyalty: - enchantments: [ minecraft:loyalty ] - notAffectedGroups: [ enchanted_book, trident ] - -restriction_luck_of_the_sea: - enchantments: [ minecraft:luck_of_the_sea ] - notAffectedGroups: [ enchanted_book, fishing_rod ] - -restriction_lure: - enchantments: [ minecraft:lure ] - notAffectedGroups: [ enchanted_book, fishing_rod ] - -restriction_mending: - enchantments: [ minecraft:mending ] - notAffectedGroups: [ enchanted_book, can_unbreak ] - -restriction_minecraft_multishot: - enchantments: [ minecraft:multishot ] - notAffectedGroups: [ enchanted_book, crossbow ] - -restriction_piercing: - enchantments: [ minecraft:piercing ] - notAffectedGroups: [ enchanted_book, crossbow ] - -restriction_power: - enchantments: [ minecraft:power ] - notAffectedGroups: [ enchanted_book, bow ] - -restriction_projectile_protection: - enchantments: [ minecraft:projectile_protection ] - notAffectedGroups: [ enchanted_book, armors ] - -restriction_protection: - enchantments: [ minecraft:protection ] - notAffectedGroups: [ enchanted_book, armors ] - -restriction_punch: - enchantments: [ minecraft:punch ] - notAffectedGroups: [ enchanted_book, bow ] - -restriction_quick_charge: - enchantments: [ minecraft:quick_charge ] - notAffectedGroups: [ enchanted_book, crossbow ] - -restriction_respiration: - enchantments: [ minecraft:respiration ] - notAffectedGroups: [ enchanted_book, helmets ] - -restriction_riptide: - enchantments: [ minecraft:riptide ] - notAffectedGroups: [ enchanted_book, trident ] - -restriction_sharpness: - enchantments: [ minecraft:sharpness ] - notAffectedGroups: [ enchanted_book, melee_weapons ] - -restriction__silk_touch: - enchantments: [ minecraft:silk_touch ] - notAffectedGroups: [ enchanted_book, tools ] - -restriction_smite: - enchantments: [ minecraft:smite ] - notAffectedGroups: [ enchanted_book, melee_weapons ] - -restriction_soul_speed: - enchantments: [ minecraft:soul_speed ] - notAffectedGroups: [ enchanted_book, boots ] - -restriction_sweeping_edge: - enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ] - notAffectedGroups: [ enchanted_book, swords ] - -# Do not exist in 1.18, that mean useInFuture will be set to true -# useInFuture set to true also mean it will not warn if there is an issue -restriction_swift_sneak: - useInFuture: true - enchantments: [ minecraft:swift_sneak ] - notAffectedGroups: [ enchanted_book, leggings ] - -restriction_thorns: - enchantments: [ minecraft:thorns ] - notAffectedGroups: [ enchanted_book, armors ] - -restriction__unbreaking: - enchantments: [ minecraft:unbreaking ] - notAffectedGroups: [ enchanted_book, can_unbreak ] - -# ---------------------------------------------------- -# Now we have conflicts about enchantment Incompatibility -# We just filtered what item enchantments can be applied -# notAffectedGroups is empty as we don't want anything to not respect theses rules -# maxEnchantmentBeforeConflict is set to 1 to only have 1 on those enchantment available -# ---------------------------------------------------- - -sword_enchant_conflict: - enchantments: - - minecraft:bane_of_arthropods - - minecraft:smite - - minecraft:sharpness - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -protection_enchant_conflict: - enchantments: - - minecraft:blast_protection - - minecraft:fire_protection - - minecraft:projectile_protection - - minecraft:protection - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -trident_conflict1: - enchantments: - - minecraft:channeling - - minecraft:riptide - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -trident_conflict2: - enchantments: - - minecraft:loyalty - - minecraft:riptide - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -boot_conflict: - enchantments: - - minecraft:depth_strider - - minecraft:frost_walker - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -tool_conflict: - enchantments: - - minecraft:fortune - - minecraft:silk_touch - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -bow_conflict: - enchantments: - - minecraft:mending - - minecraft:infinity - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -crossbow_conflict: - enchantments: - - minecraft:multishot - - minecraft:piercing - notAffectedGroups: [ ] - maxEnchantmentBeforeConflict: 1 - -# ---------------------------------------------------- -# Bellow is for custom conflicts. -# This is also where conflict create from the gui will be placed. -# ---------------------------------------------------- diff --git a/defaultconfigs/1.18/item_groups.yml b/defaultconfigs/1.18/item_groups.yml deleted file mode 100644 index 6963d2e4..00000000 --- a/defaultconfigs/1.18/item_groups.yml +++ /dev/null @@ -1,210 +0,0 @@ -# -# It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! -# - -# Please note this config use spigot material names. -# It should match minecraft name in most case, maybe every case, but I can't be sure -# In case there an issue with material name, you can found them here: -# https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Material.html - -# An empty Exclude group exclude nothing, so it contain everything -everything: - type: exclude - -# An empty include group will include nothing -nothing: - type: include - -# This group is an example of a group including only stone and polished granite -example_include: - type: include - items: - - stone - - polished_granite - -# This group contain everything except polished granite and elements of example_include -example_exclude: - type: exclude - items: - - polished_granite - groups: - - example_include - -# Default configuration should be vanilla enchantment conflict group -# there may have error, if you find one you can fix it ! -# https://minecraft.fandom.com/wiki/Enchanting - -swords: - type: include - items: - - wooden_sword - - stone_sword - - iron_sword - - diamond_sword - - golden_sword - - netherite_sword - -axes: - type: include - items: - - wooden_axe - - stone_axe - - iron_axe - - diamond_axe - - golden_axe - - netherite_axe - -melee_weapons: - type: include - groups: - - swords - - axes - -helmets: - type: include - items: - - leather_helmet - - chainmail_helmet - - iron_helmet - - diamond_helmet - - golden_helmet - - netherite_helmet - - turtle_helmet - -chestplate: - type: include - items: - - leather_chestplate - - chainmail_chestplate - - iron_chestplate - - diamond_chestplate - - golden_chestplate - - netherite_chestplate - -leggings: - type: include - items: - - leather_leggings - - chainmail_leggings - - iron_leggings - - diamond_leggings - - golden_leggings - - netherite_leggings - -boots: - type: include - items: - - leather_boots - - chainmail_boots - - iron_boots - - diamond_boots - - golden_boots - - netherite_boots - -armors: - type: include - groups: - - helmets - - chestplate - - leggings - - boots - -wearable: - type: include - items: - - elytra - - carved_pumpkin - - skeleton_skull - - wither_skeleton_skull - - zombie_head - - player_head - - creeper_head - - dragon_head - # do not exist in 1.18 but exist in future update - - piglin_head - groups: - - armors - -tools: - type: include - items: - - wooden_pickaxe - - stone_pickaxe - - iron_pickaxe - - diamond_pickaxe - - golden_pickaxe - - netherite_pickaxe - - wooden_shovel - - stone_shovel - - iron_shovel - - diamond_shovel - - golden_shovel - - netherite_shovel - - wooden_hoe - - stone_hoe - - iron_hoe - - diamond_hoe - - golden_hoe - - netherite_hoe - groups: - - axes - -enchanted_book: - type: include - items: - - enchanted_book - -trident: - type: include - items: - - trident - -bow: - type: include - items: - - bow - -crossbow: - type: include - items: - - crossbow - -fishing_rod: - type: include - items: - - fishing_rod - -shears: - type: include - items: - - shears - -can_unbreak: - type: include - items: - - elytra - - flint_and_steel - - shield - - carrot_on_a_stick - - warped_fungus_on_a_stick - # do not exist in 1.18 but exist in future update - - brush - groups: - - melee_weapons - - tools - - armors - - trident - - bow - - crossbow - - fishing_rod - - shears - -can_vanish: - type: include - items: - - compass - groups: - - wearable - - can_unbreak - diff --git a/defaultconfigs/1.18/unit_repair_item.yml b/defaultconfigs/1.18/unit_repair_item.yml deleted file mode 100644 index 98fd0bec..00000000 --- a/defaultconfigs/1.18/unit_repair_item.yml +++ /dev/null @@ -1,190 +0,0 @@ -# -# It is recommended that you use /configanvil to edit theses config. -# You can still manually edit here if you like to. but if you do, don't forget to /ca reload after you changes ! -# - -# Unit repair configuration -# -# This configuration is to make custom unit repair -# A unit repair is, for example, a diamond to repair a diamond sword -# In vanilla, a unit repair 25% of object durability -# you can make a custom value here -# -# Item name should NOT combine caps and no caps (example: Stone) - -# Default value if the config is an invalid value (value <= 0 ) -# If value > 1 it will be treated as being = 1 -default_repair_amount: 0.25 - -# You can add custom unit repair -# The example bellow make a shield repaired by 10% by sticks - -#stick: -# shield: 0.10 - - -# Vanilla unit repair group is bellow -diamond: - diamond_helmet: 0.25 - diamond_chestplate: 0.25 - diamond_leggings: 0.25 - diamond_boots: 0.25 - diamond_sword: 0.25 - diamond_pickaxe: 0.25 - diamond_axe: 0.25 - diamond_shovel: 0.25 - diamond_hoe: 0.25 - -netherite_ingot: - netherite_helmet: 0.25 - netherite_chestplate: 0.25 - netherite_leggings: 0.25 - netherite_boots: 0.25 - netherite_sword: 0.25 - netherite_pickaxe: 0.25 - netherite_axe: 0.25 - netherite_shovel: 0.25 - netherite_hoe: 0.25 - -gold_ingot: - golden_helmet: 0.25 - golden_chestplate: 0.25 - golden_leggings: 0.25 - golden_boots: 0.25 - golden_sword: 0.25 - golden_pickaxe: 0.25 - golden_axe: 0.25 - golden_shovel: 0.25 - golden_hoe: 0.25 - -iron_ingot: - iron_helmet: 0.25 - iron_chestplate: 0.25 - iron_leggings: 0.25 - iron_boots: 0.25 - iron_sword: 0.25 - iron_pickaxe: 0.25 - iron_axe: 0.25 - iron_shovel: 0.25 - iron_hoe: 0.25 - -cobblestone: - stone_sword: 0.25 - stone_pickaxe: 0.25 - stone_axe: 0.25 - stone_shovel: 0.25 - stone_hoe: 0.25 - -cobbled_deepslate: - stone_sword: 0.25 - stone_pickaxe: 0.25 - stone_axe: 0.25 - stone_shovel: 0.25 - stone_hoe: 0.25 - -blackstone: - stone_sword: 0.25 - stone_pickaxe: 0.25 - stone_axe: 0.25 - stone_shovel: 0.25 - stone_hoe: 0.25 - -leather: - leather_helmet: 0.25 - leather_chestplate: 0.25 - leather_leggings: 0.25 - leather_boots: 0.25 - -phantom_membrane: - elytra: 0.25 - -scute: - turtle_helmet: 0.25 - -oak_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -spruce_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -birch_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -jungle_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -acacia_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -dark_oak_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -mangrove_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -cherry_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -bamboo_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -crimson_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 - -warped_planks: - wooden_sword: 0.25 - wooden_pickaxe: 0.25 - wooden_axe: 0.25 - wooden_shovel: 0.25 - wooden_hoe: 0.25 - shield: 0.25 diff --git a/defaultconfigs/README.md b/defaultconfigs/README.md index daa20882..e4f40d22 100644 --- a/defaultconfigs/README.md +++ b/defaultconfigs/README.md @@ -1,5 +1,4 @@ ### Default Plugin's Configurations -From 1.18 to 1.20.6 use [1.18 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.18) \ From 1.21 to 1.21.8 use [1.21 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21) \ From 1.21.9 to 1.21.10 use [1.21.9 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21.9) \ From 1.21.11 use [1.21.11 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21.11) diff --git a/impl/LegacyEcoEnchant/build.gradle.kts b/impl/LegacyEcoEnchant/build.gradle.kts index 83057a73..3c3f1aeb 100644 --- a/impl/LegacyEcoEnchant/build.gradle.kts +++ b/impl/LegacyEcoEnchant/build.gradle.kts @@ -8,6 +8,6 @@ plugins { // Imitate needed class and method to support legacy version of EcoEnchant dependencies { // Spigot api - compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT") + compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/nms/nms-common/build.gradle.kts b/nms/nms-common/build.gradle.kts index 950d8072..46f684d7 100644 --- a/nms/nms-common/build.gradle.kts +++ b/nms/nms-common/build.gradle.kts @@ -21,8 +21,8 @@ repositories { // Set target version tasks.withType().configureEach { - sourceCompatibility = "16" - targetCompatibility = "16" + sourceCompatibility = "21" + targetCompatibility = "21" options.encoding = "UTF-8" } @@ -30,6 +30,6 @@ tasks.withType().configureEach { kotlin { compilerOptions { apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_16) + jvmTarget.set(JvmTarget.JVM_21) } } diff --git a/nms/nms-paper/build.gradle.kts b/nms/nms-paper/build.gradle.kts index d0e12a76..19033be7 100644 --- a/nms/nms-paper/build.gradle.kts +++ b/nms/nms-paper/build.gradle.kts @@ -21,8 +21,8 @@ repositories { // Set target version tasks.withType().configureEach { - sourceCompatibility = "18" - targetCompatibility = "18" + sourceCompatibility = "21" + targetCompatibility = "21" options.encoding = "UTF-8" } @@ -30,6 +30,6 @@ tasks.withType().configureEach { kotlin { compilerOptions { apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_2) - jvmTarget.set(JvmTarget.JVM_18) + jvmTarget.set(JvmTarget.JVM_21) } } diff --git a/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/datapack/DataPackTester.kt b/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/datapack/DataPackTester.kt index 9003fdf4..221dd2fa 100644 --- a/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/datapack/DataPackTester.kt +++ b/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/datapack/DataPackTester.kt @@ -2,37 +2,19 @@ package xyz.alexcrea.cuanvil.dependency.datapack import io.papermc.paper.datapack.Datapack import org.bukkit.Bukkit -import org.bukkit.packs.DataPack import java.util.* object DataPackTester { - val legacyNames: List - get() = Bukkit.getDataPackManager().dataPacks - .stream().filter { obj -> obj.isEnabled } - .map { pack -> pack.key.key } - .toList() val enabledPacks: List get() { - try { - // will throw error if do not exist - Bukkit::class.java.getDeclaredMethod("getDatapackManager") - - return Bukkit.getDatapackManager().enabledPacks + return try { + Bukkit.getDatapackManager().enabledPacks .stream().map { obj: Datapack -> obj.name } .toList() - } catch (e: NoSuchMethodException) { - try { - DataPack::class.java.getDeclaredMethod("getKey") - } catch (e: NoSuchMethodException) { - System.err.println("Could not find compatible datapack manager") - System.err.println("If you are using a datapack that should be compatible with CustomAnvil. It will not get detected...") - return emptyList() - } - return legacyNames - } catch (e: Exception){ + } catch (_: Exception){ // Assume cause UnimplementedOperationException on mock server - return Collections.emptyList() + Collections.emptyList() } } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentRarity.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentRarity.java index 3718f39b..7ad3269e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentRarity.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/EnchantmentRarity.java @@ -1,6 +1,6 @@ package xyz.alexcrea.cuanvil.enchant; -// because spigot (1.18) do not look like to provide access to enchantment rarity I need to do it myself... +// because spigot (1.21) do not look like to provide access to enchantment rarity I need to do it myself... public class EnchantmentRarity { public static final EnchantmentRarity NO_RARITY = new EnchantmentRarity(0, 0); diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt index e4e197ee..f0775241 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.command -import com.github.stefvanschie.inventoryframework.inventoryview.interface_.InventoryViewUtil import io.delilaheve.CustomAnvil import net.md_5.bungee.api.chat.ClickEvent import net.md_5.bungee.api.chat.HoverEvent @@ -16,8 +15,6 @@ import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryType import org.bukkit.event.inventory.PrepareAnvilEvent -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Damageable import org.bukkit.inventory.meta.EnchantmentStorageMeta @@ -263,7 +260,7 @@ class DiagnosticExecutor: CASubCommand() { } fun simulateAnvil(player: Player, stb: StringBuilder, left: ItemStack?, right: ItemStack?, result: ItemStack?) { - var invView: InventoryView + var invView: AnvilView var event: PrepareAnvilEvent try { val fakeInv = Bukkit.createInventory(player, InventoryType.ANVIL) @@ -275,42 +272,40 @@ class DiagnosticExecutor: CASubCommand() { val anvilTypeField = menuTypeClazz.getField("ANVIL") val anvilType = anvilTypeField.get(null) val createMethod = anvilType.javaClass.getMethod("create", HumanEntity::class.java) - invView = createMethod.invoke(anvilType, player) as InventoryView + invView = createMethod.invoke(anvilType, player) as AnvilView player.openInventory(invView) - val anvilViewClass = Class.forName("org.bukkit.inventory.view.AnvilView") - val constructor = PrepareAnvilEvent::class.java.getConstructor(anvilViewClass, ItemStack::class.java) + val constructor = PrepareAnvilEvent::class.java.getConstructor(AnvilView::class.java, ItemStack::class.java) event = constructor.newInstance(invView, result) } - val fakeInv = InventoryViewUtil.getInstance().getTopInventory(invView) as AnvilInventory - fakeInv.setItem(0, left) - fakeInv.setItem(1, right) + invView.setItem(0, left) + invView.setItem(1, right) - val xp = fakeInv.repairCost - val maxXp = fakeInv.maximumRepairCost - val mergeResult = fakeInv.getItem(2) + val xp = invView.repairCost + val maxXp = invView.maximumRepairCost + val mergeResult = invView.getItem(2) stb.append("\n${if(result == mergeResult) "E" else "Une"}xpected Result") PrepareAnvilListener().anvilCombineCheck(event) // Now we check if item and xp same stb.append("\nXP/Max XP: ") - .append(if(fakeInv.repairCost == xp) "Correct" else "Incorrect") + .append(if(invView.repairCost == xp) "Correct" else "Incorrect") .append("/") - .append(if(fakeInv.maximumRepairCost == maxXp) "Correct" else "Incorrect") - .append(" (${fakeInv.repairCost} $xp|${fakeInv.maximumRepairCost} $maxXp)") + .append(if(invView.maximumRepairCost == maxXp) "Correct" else "Incorrect") + .append(" (${invView.repairCost} $xp|${invView.maximumRepairCost} $maxXp)") .append("\nMerge result: ") - .append(if(fakeInv.getItem(2) == mergeResult) "Correct" else "Incorrect") + .append(if(invView.getItem(2) == mergeResult) "Correct" else "Incorrect") PrepareAnvilListener.IS_EMPTY_TEST = true Bukkit.getPluginManager().callEvent(event) stb.append("\nNull result test: ") .append(if(event.result == null) "Correct" else "Incorrect") - fakeInv.setItem(0, null) - fakeInv.setItem(1, null) - fakeInv.setItem(2, null) + invView.setItem(0, null) + invView.setItem(1, null) + invView.setItem(2, null) player.closeInventory() } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index b730a0ee..6a6950cc 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -15,6 +15,7 @@ import org.bukkit.inventory.Inventory import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import xyz.alexcrea.cuanvil.anvil.AnvilCost +import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.anvil.AnvilUseType import xyz.alexcrea.cuanvil.api.event.listener.CAClickResultBypassEvent import xyz.alexcrea.cuanvil.api.event.listener.CAEarlyPreAnvilBypassEvent @@ -164,9 +165,9 @@ object DependencyManager { ) } - private fun logExceptionAndClear(target: CommandSender, inventory: Inventory, e: Exception) { + private fun logExceptionAndClear(target: CommandSender, view: AnvilView, e: Exception) { // Just in case to avoid illegal items - inventory.setItem(ANVIL_OUTPUT_SLOT, null) + view.setItem(ANVIL_OUTPUT_SLOT, null) logException(target, e) } @@ -177,7 +178,7 @@ object DependencyManager { try { return earlyUnsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.inventory, e) + logExceptionAndClear(event.view.player, event.view, e) return true } } @@ -203,7 +204,7 @@ object DependencyManager { try { return unsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.inventory, e) + logExceptionAndClear(event.view.player, event.view, e) return true } } @@ -257,16 +258,16 @@ object DependencyManager { } // Return true if should bypass (either by a dependency or error) - fun tryClickAnvilResultBypass(event: InventoryClickEvent, inventory: AnvilInventory): Boolean { + fun tryClickAnvilResultBypass(event: InventoryClickEvent, view: AnvilView): Boolean { try { - return unsafeTryClickAnvilResultBypass(event, inventory) + return unsafeTryClickAnvilResultBypass(event, view) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.inventory, e) + logExceptionAndClear(event.view.player, event.view, e) return true } } - private fun unsafeTryClickAnvilResultBypass(event: InventoryClickEvent, inventory: AnvilInventory): Boolean { + private fun unsafeTryClickAnvilResultBypass(event: InventoryClickEvent, view: AnvilView): Boolean { // Run the event val bypassEvent = CAClickResultBypassEvent(event) Bukkit.getPluginManager().callEvent(bypassEvent) @@ -274,10 +275,10 @@ object DependencyManager { var bypass = bypassEvent.isCancelled // Test if disenchantment used event click - if (!bypass && (disenchantmentCompatibility?.testAnvilResult(event, inventory) == true)) bypass = true + if (!bypass && (disenchantmentCompatibility?.testAnvilResult(event, view) == true)) bypass = true // Test if haven bag used event click - if (!bypass && (havenBagsCompatibility?.testAnvilResult(event, inventory) == true)) bypass = true + if (!bypass && (havenBagsCompatibility?.testAnvilResult(event, view) == true)) bypass = true // Test if disenchantment used event click if (!bypass && (excellentEnchantsCompatibility?.testAnvilResult(event) == true)) bypass = true @@ -287,10 +288,10 @@ object DependencyManager { } // Test if the inventory is a gui(version specific) - if (!bypass && externGuiTester.testIfGui(event.view)) bypass = true + if (!bypass && externGuiTester.testIfGui(view)) bypass = true // Test if in an ax player warp rating gui - if (!bypass && (axPlayerWarpsCompatibility?.testIfGui(event.view.player) == true)) bypass = true + if (!bypass && (axPlayerWarpsCompatibility?.testIfGui(view.player) == true)) bypass = true return bypass } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt index cbd22095..3e9f2ac4 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt @@ -10,32 +10,6 @@ object MinecraftVersionUtil { if (version.major != 1) return null return when (version.minor) { - 17 -> when (version.patch) { - 0, 1 -> "1_17R1" - else -> null - } - - 18 -> when (version.patch) { - 0, 1 -> "1_18R1" - 2 -> "1_18R2" - else -> null - } - - 19 -> when (version.patch) { - 0, 1, 2 -> "1_19R1" - 3 -> "1_19R2" - 4 -> "1_19R3" - else -> null - } - - 20 -> when (version.patch) { - 0, 1 -> "1_20R1" - 2 -> "1_20R2" - 3, 4 -> "1_20R3" - 5, 6 -> "1_20R4" - else -> null - } - 21 -> when (version.patch) { 0, 1 -> "1_21R1" 2, 3 -> "1_21R2" @@ -46,6 +20,7 @@ object MinecraftVersionUtil { 11 -> "1_21R7" else -> null } + //TODO need to continue updating that for anvil gui test dependency.... else -> null } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt index 690b3846..8b9e78ef 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt @@ -12,8 +12,8 @@ import org.bukkit.entity.Player import org.bukkit.event.Listener import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.PrepareAnvilEvent -import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.anvil.AnvilCost import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError @@ -59,14 +59,14 @@ class DisenchantmentDependency { DisenchantEvent.onEvent(event) if (event.result != null) { CustomAnvil.log("Detected pre anvil item extract bypass.") - AnvilXpUtil.setAnvilInvCost(event.inventory, event.view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(event.view, player, AnvilCost(event.view.repairCost)) return true } ShatterEvent.onEvent(event) if (event.result != null) { CustomAnvil.log("Detected pre anvil split enchant bypass.") - AnvilXpUtil.setAnvilInvCost(event.inventory, event.view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(event.view, player, AnvilCost(event.view.repairCost)) return true } @@ -74,18 +74,18 @@ class DisenchantmentDependency { return false } - fun testAnvilResult(event: InventoryClickEvent, inventory: AnvilInventory): Boolean { - val previousResultSlot = inventory.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)?.clone() + fun testAnvilResult(event: InventoryClickEvent, view: AnvilView): Boolean { + val previousResultSlot = view.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)?.clone() // Test event if change the result DisenchantClickEvent.onEvent(event) - if (!testAnvilInventoryChange(inventory, previousResultSlot) || event.isCancelled) { + if (!testAnvilChange(view, previousResultSlot) || event.isCancelled) { CustomAnvil.log("Detected anvil click item extract bypass.") return true } ShatterClickEvent.onEvent(event) - if (!testAnvilInventoryChange(inventory, previousResultSlot) || event.isCancelled) { + if (!testAnvilChange(view, previousResultSlot) || event.isCancelled) { CustomAnvil.log("Detected anvil click split enchant bypass.") return true } @@ -93,8 +93,8 @@ class DisenchantmentDependency { return false } - private fun testAnvilInventoryChange(inventory: AnvilInventory, previous: ItemStack?): Boolean { - val currentResult = inventory.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT) + private fun testAnvilChange(view: AnvilView, previous: ItemStack?): Boolean { + val currentResult = view.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT) return currentResult == previous } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt index 6f304973..b9c3ce68 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt @@ -4,7 +4,7 @@ import io.delilaheve.CustomAnvil import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.PrepareAnvilEvent -import org.bukkit.inventory.AnvilInventory +import org.bukkit.inventory.view.AnvilView import org.bukkit.plugin.RegisteredListener import valorless.havenbags.HavenBags import valorless.havenbags.features.BagSkin @@ -54,14 +54,14 @@ class HavenBagsDependency { bagSkin.onPrepareAnvil(event) if (event.result != null) { CustomAnvil.log("Detected pre anvil heaven bag anvil skin.") - AnvilXpUtil.setAnvilInvCost(event.inventory, event.view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(event.view, player, AnvilCost(event.view.repairCost)) return true } bagUpgrade.onPrepareAnvil(event) if (event.result != null) { CustomAnvil.log("Detected pre anvil heaven bag anvil upgrade.") - AnvilXpUtil.setAnvilInvCost(event.inventory, event.view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(event.view, player, AnvilCost(event.view.repairCost)) return true } @@ -69,8 +69,8 @@ class HavenBagsDependency { return false } - fun testAnvilResult(event: InventoryClickEvent, inventory: AnvilInventory): Boolean { - val result = inventory.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)?.clone() + fun testAnvilResult(event: InventoryClickEvent, view: AnvilView): Boolean { + val result = view.getItem(PrepareAnvilListener.ANVIL_OUTPUT_SLOT)?.clone() if (HavenBags.IsBag(result)) { CustomAnvil.log("Detected anvil click haven bag bypass.") diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt index d707b562..85b9414e 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt @@ -5,7 +5,7 @@ import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.inventory.InventoryCloseEvent -import org.bukkit.inventory.AnvilInventory +import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.dependency.packet.PacketManager import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil @@ -14,7 +14,7 @@ class AnvilCloseListener(private val packetManager: PacketManager) : Listener { @EventHandler fun onAnvilClose(event: InventoryCloseEvent){ val player = event.player - if(event.inventory !is AnvilInventory) return + if(event.view !is AnvilView) return if(player is Player && GameMode.CREATIVE != player.gameMode){ packetManager.setInstantBuild(player, false) } diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml index 31506d2b..0af1be6e 100644 --- a/src/main/resources/enchant_conflict.yml +++ b/src/main/resources/enchant_conflict.yml @@ -160,10 +160,7 @@ restriction_sweeping_edge: enchantments: [ minecraft:sweeping, minecraft:sweeping_edge ] notAffectedGroups: [ enchanted_book, swords ] -# Do not exist in 1.18, that mean useInFuture will be set to true -# useInFuture set to true also mean it will not warn if there is an issue restriction_swift_sneak: - useInFuture: true enchantments: [ minecraft:swift_sneak ] notAffectedGroups: [ enchanted_book, leggings ] diff --git a/src/main/resources/item_groups.yml b/src/main/resources/item_groups.yml index f2042f03..1dd06a1d 100644 --- a/src/main/resources/item_groups.yml +++ b/src/main/resources/item_groups.yml @@ -121,7 +121,6 @@ wearable: - player_head - creeper_head - dragon_head - # do not exist in 1.18 but exist in future update - piglin_head groups: - armors diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d436b10a..1268ae6c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ prefix: "Custom Anvil" version: ${version} folia-supported: true description: Allow to customise anvil mechanics -api-version: 1.16 +api-version: 1.21 load: POSTWORLD authors: [ DelilahEve, alexcrea ] libraries: [${libraries}] From aeda3d7112b4f1e612e624d790084be72fa10e09 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Sat, 23 May 2026 18:30:14 +0200 Subject: [PATCH 35/41] fix from rebase --- src/main/kotlin/io/delilaheve/util/ItemUtil.kt | 11 +---------- .../cuanvil/dependency/DependencyManager.kt | 13 ++++++------- .../dependency/plugins/SuperEnchantDependency.kt | 8 +++++++- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/util/ItemUtil.kt b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt index bf075231..4ed9753a 100644 --- a/src/main/kotlin/io/delilaheve/util/ItemUtil.kt +++ b/src/main/kotlin/io/delilaheve/util/ItemUtil.kt @@ -4,9 +4,7 @@ import org.bukkit.Material.ENCHANTED_BOOK import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Damageable import xyz.alexcrea.cuanvil.enchant.CAEnchantment -import xyz.alexcrea.cuanvil.update.UpdateUtils import xyz.alexcrea.cuanvil.util.MaterialUtil.customType -import xyz.alexcrea.cuanvil.util.MaxDamageCheckerUtil import kotlin.math.ceil import kotlin.math.max import kotlin.math.min @@ -21,13 +19,6 @@ object ItemUtil { */ fun ItemStack.isEnchantedBook() = type == ENCHANTED_BOOK - private fun maxDamage(damageable: Damageable): Int { - val ver = UpdateUtils.currentMinecraftVersion() - if(ver.major <= 1 && ver.minor <= 20 && ver.patch < 5) return Integer.MAX_VALUE - - return MaxDamageCheckerUtil.getMaxDamage(damageable) - } - /** * Set this [ItemStack]s durability from a combination of the * [first] and [second] item's durability values @@ -47,8 +38,8 @@ object ItemUtil { val secondDurability = durability - secondDamage val combinedDurability = firstDurability + secondDurability val newDurability = min(combinedDurability, durability) + val maxDamage = if(it.hasMaxDamage()) it.maxDamage else Int.MAX_VALUE - val maxDamage = maxDamage(it) it.damage = min(durability - newDurability, maxDamage) itemMeta = it return true diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index 6a6950cc..a76c4a79 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.dependency -import com.maddoxh.superEnchants.SuperEnchants import io.delilaheve.CustomAnvil import net.kyori.adventure.text.Component import org.bukkit.Bukkit @@ -118,7 +117,7 @@ object DependencyManager { genericDependencies.add(GenericPluginDependency(pluginManager.getPlugin("ItemsAdder")!!)) if (pluginManager.isPluginEnabled("SuperEnchants")){ - val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!! as SuperEnchants) + val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!!) if(compatibility.registerEnchantments()) genericDependencies.add(compatibility) } @@ -165,11 +164,11 @@ object DependencyManager { ) } - private fun logExceptionAndClear(target: CommandSender, view: AnvilView, e: Exception) { + private fun logExceptionAndClear(view: AnvilView, e: Exception) { // Just in case to avoid illegal items view.setItem(ANVIL_OUTPUT_SLOT, null) - logException(target, e) + logException(view.player, e) } // Return true if should bypass (either by a dependency or error) @@ -178,7 +177,7 @@ object DependencyManager { try { return earlyUnsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.view, e) + logExceptionAndClear(event.view, e) return true } } @@ -204,7 +203,7 @@ object DependencyManager { try { return unsafeTryEventPreAnvilBypass(event, player) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.view, e) + logExceptionAndClear(event.view, e) return true } } @@ -262,7 +261,7 @@ object DependencyManager { try { return unsafeTryClickAnvilResultBypass(event, view) } catch (e: Exception) { - logExceptionAndClear(event.view.player, event.view, e) + logExceptionAndClear(view, e) return true } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt index 11622f92..8676b4cd 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt @@ -8,17 +8,23 @@ import org.bukkit.command.Command import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.plugin.Plugin import org.bukkit.plugin.RegisteredListener import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.enchant.bulk.SuperEnchantBulkOperation import xyz.alexcrea.cuanvil.enchant.wrapped.CASuperEnchantEnchantment import java.util.logging.Level -class SuperEnchantDependency(override val plugin: SuperEnchants): GenericPluginDependency(plugin, false) { +class SuperEnchantDependency: GenericPluginDependency { + override val plugin: SuperEnchants lateinit var enchManager: EnchantManager val enchantments = ArrayList() + constructor(plugin: Plugin) : super(plugin) { + this.plugin = plugin as SuperEnchants + } + fun registerEnchantments(): Boolean{ CustomAnvil.instance.logger.info("Preparing Super Enchant compatibility...") From fba34fecb8910960f6d33f39bf135010a90c89b4 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 3 Jun 2026 17:53:17 +0200 Subject: [PATCH 36/41] 1.21 cleanup and fix also random cleanup --- .../alexcrea/cuanvil/anvil/AnvilMergeLogic.kt | 12 ++- .../alexcrea/cuanvil/command/CASubCommand.kt | 16 +-- .../cuanvil/command/CustomAnvilCommand.kt | 18 ++-- .../cuanvil/command/DiagnosticExecutor.kt | 63 ++++++------ .../alexcrea/cuanvil/command/HelpExecutor.kt | 14 +-- .../cuanvil/command/ReloadExecutor.kt | 10 +- .../cuanvil/dependency/DependencyManager.kt | 9 +- .../dependency/MinecraftVersionUtil.kt | 8 +- .../dependency/gui/GenericExternGuiTester.kt | 4 +- .../packet/PacketManagerSelector.kt | 2 +- .../plugins/DisenchantmentDependency.kt | 1 + .../plugins/EnchantmentSquaredDependency.kt | 34 ++++--- .../plugins/ExcellentEnchantsDependency.kt | 6 +- .../plugins/GenericPluginDependency.kt | 9 +- .../dependency/plugins/HavenBagsDependency.kt | 1 + .../plugins/ItemsAdderDependency.kt | 8 +- .../plugins/SuperEnchantDependency.kt | 8 +- .../dependency/plugins/ToolStatsDependency.kt | 1 - .../cuanvil/group/EnchantConflictGroup.kt | 15 +-- .../cuanvil/group/EnchantConflictManager.kt | 1 - .../alexcrea/cuanvil/group/ExcludeGroup.kt | 1 - .../alexcrea/cuanvil/group/IncludeGroup.kt | 2 - .../cuanvil/group/ItemGroupManager.kt | 11 +-- .../cuanvil/group/NegativeMaterialSet.kt | 2 +- .../cuanvil/listener/AnvilCloseListener.kt | 7 +- .../cuanvil/listener/AnvilResultListener.kt | 98 +++++++++---------- .../cuanvil/listener/ChatEventListener.kt | 7 +- .../cuanvil/listener/PrepareAnvilListener.kt | 28 +++--- .../xyz/alexcrea/cuanvil/util/MaterialUtil.kt | 1 - .../cuanvil/util/anvil/AnvilXpUtil.kt | 37 +++---- 30 files changed, 223 insertions(+), 211 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt index fd7055ed..80f8f053 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt @@ -14,6 +14,7 @@ import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.ItemMeta +import org.bukkit.inventory.view.AnvilView import org.bukkit.persistence.PersistentDataType import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.dependency.DependencyManager @@ -31,6 +32,7 @@ import xyz.alexcrea.cuanvil.util.anvil.AnvilXpUtil import xyz.alexcrea.cuanvil.util.config.LoreEditType import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil +@Suppress("UnstableApiUsage") object AnvilMergeLogic { open class AnvilResult { @@ -103,7 +105,7 @@ object AnvilMergeLogic { ): AnvilResult { val resultItem = DependencyManager.cloneItem(player, first) val cost = AnvilCost() - cost.rename = handleRename(resultItem, inventory, player) + cost.rename = handleRename(resultItem, view, player) // Test/stop if nothing changed. if (first == resultItem) { @@ -136,9 +138,9 @@ object AnvilMergeLogic { } } - private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory, player: HumanEntity): Int { + private fun handleRename(resultItem: ItemStack, view: AnvilView, player: HumanEntity): Int { // Can be null - var renameText = ChatColor.stripColor(inventory.renameText) + var renameText = ChatColor.stripColor(view.renameText) var sumCost = 0 var useColor = false @@ -219,7 +221,7 @@ object AnvilMergeLogic { // As calculatePenalty edit result, we need to calculate penalty after checking equality cost.workPenalty = AnvilXpUtil.calculatePenalty(first, second, resultItem, AnvilUseType.MERGE) // Calculate rename cost - cost.rename = handleRename(resultItem, inventory, player) + cost.rename = handleRename(resultItem, view, player) val result = DependencyManager.tryTreatAnvilResult(view, inventory, player, resultItem, AnvilUseType.MERGE, cost) @@ -288,7 +290,7 @@ object AnvilMergeLogic { ): UnitRepairResult { val resultItem = DependencyManager.cloneItem(player, first) val cost = AnvilCost() - cost.rename = handleRename(resultItem, inventory, player) + cost.rename = handleRename(resultItem, view, player) val repairAmount = resultItem.unitRepair(second.amount, unitRepairAmount) if (repairAmount > 0) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt index 60dcdbee..943dd6bd 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt @@ -6,7 +6,7 @@ import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry -abstract class CASubCommand: CommandExecutor { +abstract class CASubCommand : CommandExecutor { private var alreadySaid = false; override fun onCommand( @@ -15,9 +15,11 @@ abstract class CASubCommand: CommandExecutor { cmdstr: String, args: Array ): Boolean { - if(!alreadySaid){ - sender.sendMessage(ChatColor.RED.toString() + - "Please not that this command will be replaced as a subcommand of `/customanvil` or `/ca`") + if (!alreadySaid) { + sender.sendMessage( + ChatColor.RED.toString() + + "Please not that this command will be replaced as a subcommand of `/customanvil` or `/ca`" + ) alreadySaid = true } @@ -28,7 +30,8 @@ abstract class CASubCommand: CommandExecutor { sender: CommandSender, cmd: Command, cmdstr: String, - args: Array): Boolean + args: Array + ): Boolean open fun allowed(sender: CommandSender): Boolean { return true @@ -37,7 +40,8 @@ abstract class CASubCommand: CommandExecutor { open fun tabCompleter( sender: CommandSender, args: Array, - list: MutableList) { + list: MutableList + ) { } open fun description(): String { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt index 9b9402c9..1cae583f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCommand.kt @@ -46,17 +46,17 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { val subcmdStr: String val newargs: Array - if(args.isEmpty()) { + if (args.isEmpty()) { subcmdStr = "config" subcmd = editConfigCommand newargs = args - }else { + } else { subcmdStr = args[0].lowercase() subcmd = commands[subcmdStr] newargs = args.copyOfRange(1, args.size) } - if(subcmd == null || !subcmd.allowed(sender)) { + if (subcmd == null || !subcmd.allowed(sender)) { sender.sendMessage("Invalid subcommand. run `$cmdstr help` to see available commands") return true } @@ -77,18 +77,18 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { args: Array ): MutableList { val result = ArrayList() - if(args.size < 2) { - for ((key, cmd) in commands) { - if(!cmd.allowed(sender)) continue - if("gui".contentEquals(key)) continue + if (args.size < 2) { + for ((key, cmd) in commands) { + if (!cmd.allowed(sender)) continue + if("gui".contentEquals(key)) continue result.add(key) } } else { val subcmd = commands[args[0].lowercase()] - if(subcmd != null) { + if (subcmd != null) { val newArgs = args.copyOfRange(1, args.size) - if(!subcmd.allowed(sender)) return result + if (!subcmd.allowed(sender)) return result subcmd.tabCompleter(sender, newArgs, result) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt index f0775241..b7bb1dd9 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt @@ -31,9 +31,9 @@ import java.util.* import java.util.stream.Collectors -class DiagnosticExecutor: CASubCommand() { +class DiagnosticExecutor : CASubCommand() { - companion object{ + companion object { const val NO_DIAG_PERM = "You do not have permission to diagnostic this server" fun fetchNMSType(): String { @@ -41,7 +41,7 @@ class DiagnosticExecutor: CASubCommand() { val packetManagerClass = packetManager.javaClass val className = packetManagerClass.name - val result = if(className.contains("PaperPacket")) { + val result = if (className.contains("PaperPacket")) { "Paper" } else { when (packetManagerClass) { @@ -52,7 +52,7 @@ class DiagnosticExecutor: CASubCommand() { } - return "$result ${if(packetManager.canSetInstantBuild) '✅' else '❌'}" + return "$result ${if (packetManager.canSetInstantBuild) '✅' else '❌'}" } } @@ -73,7 +73,7 @@ class DiagnosticExecutor: CASubCommand() { } for (param in DiagParams.entries) { - if(argSet.contains(param.value)) + if (argSet.contains(param.value)) result.add(param) } @@ -83,12 +83,13 @@ class DiagnosticExecutor: CASubCommand() { override fun tabCompleter( sender: CommandSender, args: Array, - list: MutableList) { - if(!allowed(sender)) return + list: MutableList + ) { + if (!allowed(sender)) return val map = fetchParameters(args) for (param in DiagParams.entries) { - if(!map.contains(param)) + if (!map.contains(param)) list.add(param.value) } @@ -110,7 +111,7 @@ class DiagnosticExecutor: CASubCommand() { var hasError = false try { diagnostic(sender, stb, params) - } catch(e: Throwable){ + } catch (e: Throwable) { stb.append("\n\nError happened trying to get diagnostic data:\n") .append(e.message).append("\n") .append(e.stackTrace.joinToString("\n")) @@ -121,8 +122,9 @@ class DiagnosticExecutor: CASubCommand() { stb.append("\n```") if (sender is HumanEntity) { - if(hasError) - sender.spigot().sendMessage(TextComponent(ChatColor.RED.toString() + "There was an error running the diagnostic")) + if (hasError) + sender.spigot() + .sendMessage(TextComponent(ChatColor.RED.toString() + "There was an error running the diagnostic")) val message = TextComponent(ChatColor.GREEN.toString() + "Click to copy diagnostic data") message.clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stb.toString()) @@ -140,41 +142,41 @@ class DiagnosticExecutor: CASubCommand() { return sender.hasPermission(CustomAnvil.diagnosticPermission) } - fun diagnostic(sender: CommandSender, stb: StringBuilder, params: Set){ + fun diagnostic(sender: CommandSender, stb: StringBuilder, params: Set) { stb.append("Server Info\n") val version = CustomAnvil.instance.description.version stb.append("\nPlugin Version: ").append(version) - if(version.contains("dev")) stb.append(" (alpha)") + if (version.contains("dev")) stb.append(" (alpha)") stb.append("\nLatest Update: ").append(CustomAnvil.latestVer) stb.append("\nServer Version: ").append(Bukkit.getVersion()).append(" (").append(Bukkit.getName()).append(')') - stb.append("\nPlugin Enabled: ").append(if(CustomAnvil.instance.isEnabled) "Yes" else "No") + stb.append("\nPlugin Enabled: ").append(if (CustomAnvil.instance.isEnabled) "Yes" else "No") stb.append("\nNMS type: ").append(fetchNMSType()) - if(!params.contains(DiagParams.OS_PRIVACY)) { + if (!params.contains(DiagParams.OS_PRIVACY)) { stb.append("\nJava Version: ").append(System.getProperty("java.version")) stb.append("\nOS: ").append(System.getProperty("os.name")).append(" ") .append(System.getProperty("os.version")) .append(System.getProperty("os.arch")) } - stb.append("\nHad detect error: ").append(if(MetricsUtil.lastError != null) "Yes" else "No") + stb.append("\nHad detect error: ").append(if (MetricsUtil.lastError != null) "Yes" else "No") - if(!params.contains(DiagParams.PLUGIN_PRIVACY)) { + if (!params.contains(DiagParams.PLUGIN_PRIVACY)) { pluginListDiag(sender, stb) } prepareAnvilListeners(stb) - if(!params.contains(DiagParams.NO_MERGE_TEST)){ - if(sender is Player) testMerge(sender, stb) + if (!params.contains(DiagParams.NO_MERGE_TEST)) { + if (sender is Player) testMerge(sender, stb) } stb.append("\n\nEnchantments data:") partialEnchantmentData(stb) - if(params.contains(DiagParams.FULL_ENCHANTMENT_DATA)){ + if (params.contains(DiagParams.FULL_ENCHANTMENT_DATA)) { fullEnchantmentData(stb) } - if(params.contains(DiagParams.INCLUDE_LAST_ERROR)){ + if (params.contains(DiagParams.INCLUDE_LAST_ERROR)) { includeLastError(stb) } } @@ -286,22 +288,22 @@ class DiagnosticExecutor: CASubCommand() { val xp = invView.repairCost val maxXp = invView.maximumRepairCost val mergeResult = invView.getItem(2) - stb.append("\n${if(result == mergeResult) "E" else "Une"}xpected Result") + stb.append("\n${if (result == mergeResult) "E" else "Une"}xpected Result") PrepareAnvilListener().anvilCombineCheck(event) // Now we check if item and xp same stb.append("\nXP/Max XP: ") - .append(if(invView.repairCost == xp) "Correct" else "Incorrect") + .append(if (invView.repairCost == xp) "Correct" else "Incorrect") .append("/") - .append(if(invView.maximumRepairCost == maxXp) "Correct" else "Incorrect") + .append(if (invView.maximumRepairCost == maxXp) "Correct" else "Incorrect") .append(" (${invView.repairCost} $xp|${invView.maximumRepairCost} $maxXp)") .append("\nMerge result: ") - .append(if(invView.getItem(2) == mergeResult) "Correct" else "Incorrect") + .append(if (invView.getItem(2) == mergeResult) "Correct" else "Incorrect") PrepareAnvilListener.IS_EMPTY_TEST = true Bukkit.getPluginManager().callEvent(event) stb.append("\nNull result test: ") - .append(if(event.result == null) "Correct" else "Incorrect") + .append(if (event.result == null) "Correct" else "Incorrect") invView.setItem(0, null) invView.setItem(1, null) @@ -323,11 +325,13 @@ class DiagnosticExecutor: CASubCommand() { map[enchant.key.namespace] = map.getOrDefault(enchant.key.namespace, 0) + 1 } - stb.append("\nNamespaces: ${ + stb.append( + "\nNamespaces: ${ map.entries.stream() .map { (key, value) -> "$key ($value)" } .reduce { a, b -> "$a, $b" }.get() - }") + }" + ) } @@ -337,7 +341,6 @@ class DiagnosticExecutor: CASubCommand() { stb.append("\n\nLast stack trace: ${e.stackTraceToString()}") - } - + } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt index 697f1ee2..1314d0ec 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt @@ -4,18 +4,20 @@ import com.google.common.collect.ImmutableMap import org.bukkit.command.Command import org.bukkit.command.CommandSender -class HelpExecutor: CASubCommand() { +class HelpExecutor : CASubCommand() { lateinit var commands: ImmutableMap - override fun executeCommand(sender: CommandSender, - cmd: Command, - cmdstr: String, - args: Array): Boolean { + override fun executeCommand( + sender: CommandSender, + cmd: Command, + cmdstr: String, + args: Array + ): Boolean { val stb = StringBuilder("List of available commands:") for ((key, cmd) in commands) { - if(!cmd.allowed(sender)) continue + if (!cmd.allowed(sender)) continue stb.append("\n- $key: ").append(cmd.description()) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt index cb0d24a9..ab832c4f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt @@ -12,10 +12,12 @@ import xyz.alexcrea.cuanvil.update.UpdateHandler class ReloadExecutor : CASubCommand() { - override fun executeCommand(sender: CommandSender, - cmd: Command, - cmdstr: String, - args: Array): Boolean { + override fun executeCommand( + sender: CommandSender, + cmd: Command, + cmdstr: String, + args: Array + ): Boolean { if (!allowed(sender)) { sender.sendMessage("§cYou do not have permission to reload the config") return false diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index a76c4a79..3139fc51 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -35,6 +35,7 @@ import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError import java.util.logging.Level +@Suppress("UnstableApiUsage") object DependencyManager { lateinit var scheduler: TaskScheduler @@ -103,7 +104,7 @@ object DependencyManager { axPlayerWarpsCompatibility = AxPlayerWarpsDependency() } - if (pluginManager.isPluginEnabled("ItemsAdder")){ + if (pluginManager.isPluginEnabled("ItemsAdder")) { val dependency = ItemsAdderDependency(pluginManager.getPlugin("ItemsAdder")!!) itemsAdderCompatibility = dependency genericDependencies.add(dependency) @@ -116,9 +117,9 @@ object DependencyManager { if (pluginManager.isPluginEnabled("ItemsAdder")) genericDependencies.add(GenericPluginDependency(pluginManager.getPlugin("ItemsAdder")!!)) - if (pluginManager.isPluginEnabled("SuperEnchants")){ + if (pluginManager.isPluginEnabled("SuperEnchants")) { val compatibility = SuperEnchantDependency(pluginManager.getPlugin("SuperEnchants")!!) - if(compatibility.registerEnchantments()) + if (compatibility.registerEnchantments()) genericDependencies.add(compatibility) } @@ -307,7 +308,7 @@ object DependencyManager { private fun unsafeCloneItem(item: ItemStack): ItemStack { val cloned = itemsAdderCompatibility?.tryClone(item) - if(cloned != null) return cloned + if (cloned != null) return cloned return item.clone() } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt index 3e9f2ac4..7813cb4e 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt @@ -26,8 +26,10 @@ object MinecraftVersionUtil { } } - val isTooNewForSpigot: Boolean get() { - return UpdateUtils.currentMinecraftVersion().major != 1 - } + val isTooNewForSpigot: Boolean + get() { + + return UpdateUtils.currentMinecraftVersion().major != 1 + } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/GenericExternGuiTester.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/GenericExternGuiTester.kt index 4046f4ab..b9410886 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/GenericExternGuiTester.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/GenericExternGuiTester.kt @@ -64,11 +64,11 @@ class GenericExternGuiTester { } // Try if were in another plugin anvil inventory - fun testIfGui(inventory: InventoryView): Boolean { + fun testIfGui(view: InventoryView): Boolean { // In case we are in a test environment if(isInTest()) return false - val clazz = getContainerClass(inventory) ?: return false + val clazz = getContainerClass(view) ?: return false val clazzName = clazz.name if(!PlatformUtil.isPaper){ diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt index d74ef089..e21a66ed 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt @@ -3,7 +3,7 @@ package xyz.alexcrea.cuanvil.dependency.packet import org.bukkit.Bukkit import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.dependency.MinecraftVersionUtil -import xyz.alexcrea.cuanvil.dependency.packet.versions.* +import xyz.alexcrea.cuanvil.dependency.packet.versions.PaperPacketManager import xyz.alexcrea.cuanvil.update.UpdateUtils object PacketManagerSelector { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt index 8b9e78ef..ba0b330b 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/DisenchantmentDependency.kt @@ -21,6 +21,7 @@ import xyz.alexcrea.cuanvil.util.anvil.AnvilXpUtil import java.util.logging.Level import kotlin.reflect.KClass +@Suppress("UnstableApiUsage") class DisenchantmentDependency { init { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EnchantmentSquaredDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EnchantmentSquaredDependency.kt index d769986b..72c8fbab 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EnchantmentSquaredDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/EnchantmentSquaredDependency.kt @@ -30,28 +30,29 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) "disable_anvil, " + "incompatible_vanilla_enchantments, " + "incompatible_custom_enchantments and max_level " + - "configuration values.") + "configuration values." + ) } - fun disableAnvilListener(){ + fun disableAnvilListener() { PrepareAnvilEvent.getHandlerList().unregister(this.enchantmentSquaredPlugin) // Find the anvil click event var toRemove: AnvilListener? = null for (registered in InventoryClickEvent.getHandlerList().registeredListeners) { val listener = registered.listener - if(listener is AnvilListener) { + if (listener is AnvilListener) { toRemove = listener break } } - if(toRemove != null) + if (toRemove != null) InventoryClickEvent.getHandlerList().unregister(toRemove) } - fun registerEnchantments(){ + fun registerEnchantments() { CustomAnvil.instance.logger.info("Preparing Enchantment Squared compatibility...") // Register enchantments @@ -69,20 +70,21 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) fun getEnchantmentsSquared(item: ItemStack, enchantments: MutableMap) { val customEnchants = CustomEnchantManager.getInstance().getItemsEnchantsFromPDC(item) - customEnchants.forEach{ - (enchantment, level ) -> enchantments[getWrappedEnchant(enchantment)] = level + customEnchants.forEach { (enchantment, level) -> + enchantments[getWrappedEnchant(enchantment)] = level } } - fun getKeyFromEnchant(enchant: CustomEnchant): NamespacedKey{ + fun getKeyFromEnchant(enchant: CustomEnchant): NamespacedKey { return NamespacedKey.fromString(enchant.type.lowercase(Locale.getDefault()), this.enchantmentSquaredPlugin)!! } + private fun getWrappedEnchant(enchant: CustomEnchant): CAEnchantment { return CAEnchantment.getByKey(getKeyFromEnchant(enchant))!! } - fun registerPluginConfiguration(){ + fun registerPluginConfiguration() { CustomAnvil.instance.logger.info("Preparing Enchantment Squared config...") // Prepare enchantments @@ -99,7 +101,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) CustomAnvil.instance.logger.info("Enchantment Squared should now work as expected !") } - private fun writeMissingGroups(){ + private fun writeMissingGroups() { // Write group that do not exist on custom anvil. val shield = IncludeGroup("shield") shield.addToPolicy(Material.SHIELD.key) @@ -114,7 +116,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) MaterialGroupApi.addMaterialGroup(trinkets) } - private fun writeMaterialRestriction(esEnchantments: List){ + private fun writeMaterialRestriction(esEnchantments: List) { for (enchantment in esEnchantments) { val conflict = ConflictBuilder("restriction_${enchantment.key.key}", CustomAnvil.instance) conflict.addEnchantment(enchantment) @@ -125,7 +127,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) // Get allowed groups for (esGroup in enchantment.enchant.compatibleItems) { val caGroup = esGroupToCAGroup(esGroup) - if(caGroup == null){ + if (caGroup == null) { CustomAnvil.instance.logger.info("Could not find equivalent custom anvil group for $esGroup") continue } @@ -136,7 +138,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) } } - private fun writeEnchantmentConflicts(esEnchantments: List){ + private fun writeEnchantmentConflicts(esEnchantments: List) { val otherEnchants = ArrayList() otherEnchants.addAll(CAEnchantmentRegistry.getInstance().values()) @@ -145,14 +147,14 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) // find conflicting enchantment. for (otherEnchant in otherEnchants) { - if(enchantment.enchant.conflictsWithEnchantment(otherEnchant.name)){ + if (enchantment.enchant.conflictsWithEnchantment(otherEnchant.name)) { writeConflict(enchantment, otherEnchant) } } } } - private fun writeConflict(enchantment1: CAEnchantment, enchantment2: CAEnchantment){ + private fun writeConflict(enchantment1: CAEnchantment, enchantment2: CAEnchantment) { val conflict = ConflictBuilder("${enchantment1.name}_with_${enchantment2.name}_conflict", CustomAnvil.instance) conflict.addEnchantment(enchantment1).addEnchantment(enchantment2) @@ -165,7 +167,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) * Transform an Enchantment Squared group to a Custom Anvil group */ private fun esGroupToCAGroup(esGroup: String): String? { - return when(esGroup){ + return when (esGroup) { "SWORDS" -> "swords" "BOWS" -> "bow" "CROSSBOWS" -> "crossbow" diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt index 816a4dfe..d3d46ccc 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt @@ -17,10 +17,10 @@ import java.lang.reflect.Constructor import java.lang.reflect.Method import su.nightexpress.excellentenchants.api.EnchantRegistry as V5EnchantRegistry import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant as LegacyCurseOfFragilityEnchant -import su.nightexpress.excellentenchants.manager.listener.AnvilListener as V5AnvilListener import su.nightexpress.excellentenchants.enchantment.listener.AnvilListener as PreV5AnvilListener import su.nightexpress.excellentenchants.enchantment.listener.EnchantAnvilListener as LegacyAnvilListener import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry as LegacyEnchantRegistry +import su.nightexpress.excellentenchants.manager.listener.AnvilListener as V5AnvilListener import su.nightexpress.excellentenchants.registry.EnchantRegistry as PreV5EnchantRegistry // I don't like that I need to support older version. if I could just drop older support it would be sooo nice @@ -53,7 +53,7 @@ class ExcellentEnchantsDependency { if (listenerVersion == null) { CustomAnvil.instance.logger.severe("Found issue with listener of Excellent Enchants. compatiblity is broken. please contact CustomAnvil devs") - } else{ + } else { CustomAnvil.log("Support version: " + listenerVersion.name) } @@ -173,6 +173,7 @@ class ExcellentEnchantsDependency { ListenerVersion.V5, ListenerVersion.V5_4, -> this.usedAnvilListener = v5AnvilListener!! + ListenerVersion.PRE_V5 -> this.usedAnvilListener = preV5AnvilListener!! ListenerVersion.LEGACY -> this.usedAnvilListener = legacyAnvilListener!! null -> {} @@ -240,6 +241,7 @@ class ExcellentEnchantsDependency { ListenerVersion.V5_3, ListenerVersion.V5_4, -> v5AnvilListener!!.onClickAnvil(event) + ListenerVersion.PRE_V5 -> preV5AnvilListener!!.onClickAnvil(event) ListenerVersion.LEGACY -> legacyAnvilListener!!.onClickAnvil(event) null -> {} diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/GenericPluginDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/GenericPluginDependency.kt index 62dae9ba..8bfd98ea 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/GenericPluginDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/GenericPluginDependency.kt @@ -24,7 +24,7 @@ open class GenericPluginDependency(protected open val plugin: Plugin, private va } } - open fun fillPreAnvil(preAnvil: ArrayList){ + open fun fillPreAnvil(preAnvil: ArrayList) { // get PreAnvil and PostAnvil listeners for (registeredListener in PrepareAnvilEvent.getHandlerList().registeredListeners) { @@ -35,12 +35,13 @@ open class GenericPluginDependency(protected open val plugin: Plugin, private va protected open fun fillPostAnvil( postAnvil: ArrayList, - preAnvil: ArrayList) { + preAnvil: ArrayList + ) { } open fun testPrepareAnvil(event: PrepareAnvilEvent): Boolean { - if(!testPrepare) return false + if (!testPrepare) return false val previousResult = event.result event.result = null @@ -61,7 +62,7 @@ open class GenericPluginDependency(protected open val plugin: Plugin, private va } open fun testAnvilResult(event: InventoryClickEvent): Boolean { - if(!testPrepare) return false + if (!testPrepare) return false for (registeredListener in postAnvil) { // We do not want error from another plugin to be our fault diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt index b9c3ce68..23a8544d 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/HavenBagsDependency.kt @@ -13,6 +13,7 @@ import xyz.alexcrea.cuanvil.anvil.AnvilCost import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener import xyz.alexcrea.cuanvil.util.anvil.AnvilXpUtil +@Suppress("UnstableApiUsage") class HavenBagsDependency { init { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt index 7f977e18..9f366b20 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ItemsAdderDependency.kt @@ -17,19 +17,19 @@ class ItemsAdderDependency(plugin: Plugin) : GenericPluginDependency(plugin) { } fun tryClone(item: ItemStack): ItemStack? { - if(!isLoaded) return null + if (!isLoaded) return null val customItem = CustomStack.byItemStack(item) ?: return null return CustomStack.getInstance(customItem.namespacedID)?.itemStack } fun fromKey(key: NamespacedKey): ItemStack? { - if(!isLoaded) return null + if (!isLoaded) return null return CustomStack.getInstance(key.toString())?.itemStack } - fun getKey(item: ItemStack) : NamespacedKey? { - if(!isLoaded) return null + fun getKey(item: ItemStack): NamespacedKey? { + if (!isLoaded) return null val customItem = CustomStack.byItemStack(item) ?: return null return NamespacedKey.fromString(customItem.namespacedID) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt index 8676b4cd..6b9d6fd7 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/SuperEnchantDependency.kt @@ -15,7 +15,7 @@ import xyz.alexcrea.cuanvil.enchant.bulk.SuperEnchantBulkOperation import xyz.alexcrea.cuanvil.enchant.wrapped.CASuperEnchantEnchantment import java.util.logging.Level -class SuperEnchantDependency: GenericPluginDependency { +class SuperEnchantDependency : GenericPluginDependency { override val plugin: SuperEnchants lateinit var enchManager: EnchantManager @@ -25,11 +25,11 @@ class SuperEnchantDependency: GenericPluginDependency { this.plugin = plugin as SuperEnchants } - fun registerEnchantments(): Boolean{ + fun registerEnchantments(): Boolean { CustomAnvil.instance.logger.info("Preparing Super Enchant compatibility...") val field = SuperEnchants::class.java.getDeclaredField("enchantManager") - if(field == null) { + if (field == null) { CustomAnvil.instance.logger.log(Level.SEVERE, "Failed to initialize Super Enchant compatibility") return false } @@ -67,7 +67,7 @@ class SuperEnchantDependency: GenericPluginDependency { reload?.setExecutor(ReloadInterceptor(reload.executor)) } - inner class ReloadInterceptor(val other: CommandExecutor): CommandExecutor { + inner class ReloadInterceptor(val other: CommandExecutor) : CommandExecutor { override fun onCommand( sender: CommandSender, diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ToolStatsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ToolStatsDependency.kt index 255f7373..f1193d17 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ToolStatsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ToolStatsDependency.kt @@ -5,7 +5,6 @@ import lol.hyper.toolstats.tools.ItemChecker import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.ItemStack import org.bukkit.plugin.Plugin -import org.bukkit.plugin.RegisteredListener import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener import java.lang.reflect.Method diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt index 59841ac6..2957e324 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt @@ -18,18 +18,19 @@ class EnchantConflictGroup( fun addEnchantment(enchant: CAEnchantment) { enchantments.add(enchant) } + fun addEnchantments(enchants: List) { enchantments.addAll(enchants) } private fun canBypassByBeforeLevel(enchants: Map): Boolean { // Either there no "conflict after" - if(conflictsAfterLevel.isEmpty()) return false + if (conflictsAfterLevel.isEmpty()) return false // Or we check if any conflict after enchantment is true for (entry in conflictsAfterLevel) { val current = enchants.getOrDefault(entry.key, 0) - if(current > entry.value) + if (current > entry.value) return false } @@ -38,12 +39,12 @@ class EnchantConflictGroup( private fun canBypassByAfterLevel(enchants: Map): Boolean { // Either there no "conflict after" - if(conflictsBeforeLevel.isEmpty()) return false + if (conflictsBeforeLevel.isEmpty()) return false // Or we check if any conflict after enchantment is true for (entry in conflictsBeforeLevel) { val current = enchants.getOrDefault(entry.key, 0) - if(current < entry.value) + if (current < entry.value) return false } @@ -64,7 +65,7 @@ class EnchantConflictGroup( return true // If empty we skip. else we - if(canBypassConflictByLevel(enchants)) + if (canBypassConflictByLevel(enchants)) return true // Count the amount of enchantment that are in the list @@ -102,7 +103,7 @@ class EnchantConflictGroup( fun putConflictAfterLevel(enchantment: CAEnchantment, level: Int): Boolean { return null != ( - if(level < 0) conflictsAfterLevel.remove(enchantment) + if (level < 0) conflictsAfterLevel.remove(enchantment) else conflictsAfterLevel.put(enchantment, level)) } @@ -117,7 +118,7 @@ class EnchantConflictGroup( fun putConflictsBeforeLevel(enchantment: CAEnchantment, level: Int): Boolean { return null != ( - if(level < 0) conflictsBeforeLevel.remove(enchantment) + if (level < 0) conflictsBeforeLevel.remove(enchantment) else conflictsBeforeLevel.put(enchantment, level)) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index 39def31f..6b836c13 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -11,7 +11,6 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.util.MaterialUtil.customType import java.util.* -import kotlin.collections.set class EnchantConflictManager { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt index d752db5b..4b1a31bb 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ExcludeGroup.kt @@ -1,7 +1,6 @@ package xyz.alexcrea.cuanvil.group import org.bukkit.NamespacedKey -import java.util.* class ExcludeGroup(name: String) : AbstractMaterialGroup(name) { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/IncludeGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/IncludeGroup.kt index fc9614b7..f4076350 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/IncludeGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/IncludeGroup.kt @@ -1,8 +1,6 @@ package xyz.alexcrea.cuanvil.group -import org.bukkit.Material import org.bukkit.NamespacedKey -import java.util.* class IncludeGroup(name: String) : AbstractMaterialGroup(name) { override fun createDefaultSet(): MutableSet { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt index 348d0fff..7a9c388b 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/ItemGroupManager.kt @@ -41,7 +41,7 @@ class ItemGroupManager { fun createGroup( config: ConfigurationSection, name: String - ): AbstractMaterialGroup{ + ): AbstractMaterialGroup { return createGroup(config, groupMap.keys, name) } @@ -109,11 +109,10 @@ class ItemGroupManager { } // Get other group or create it if not yet created val otherGroup = - if (!groupMap.containsKey(groupName)) { - if(!config.isConfigurationSection(groupName)) continue - createGroup(config, keys, groupName) - } - else groupMap[groupName]!! + if (!groupMap.containsKey(groupName)) { + if (!config.isConfigurationSection(groupName)) continue + createGroup(config, keys, groupName) + } else groupMap[groupName]!! // Avoid self reference or it will create an infinite loop if (otherGroup.isReferencing(group)) { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt index d87004d4..ef442e57 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/NegativeMaterialSet.kt @@ -4,7 +4,7 @@ import org.bukkit.NamespacedKey import xyz.alexcrea.cuanvil.util.MaterialUtil import xyz.alexcrea.cuanvil.util.NegativeSet -class NegativeMaterialSet: NegativeSet() { +class NegativeMaterialSet : NegativeSet() { override fun iterator(): MutableIterator { val materials = MaterialUtil.getMaterials() diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt index 85b9414e..b73effe1 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilCloseListener.kt @@ -9,13 +9,14 @@ import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.dependency.packet.PacketManager import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil +@Suppress("UnstableApiUsage") class AnvilCloseListener(private val packetManager: PacketManager) : Listener { @EventHandler - fun onAnvilClose(event: InventoryCloseEvent){ + fun onAnvilClose(event: InventoryCloseEvent) { val player = event.player - if(event.view !is AnvilView) return - if(player is Player && GameMode.CREATIVE != player.gameMode){ + if (event.view !is AnvilView) return + if (player is Player && GameMode.CREATIVE != player.gameMode) { packetManager.setInstantBuild(player, false) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index e9290ac9..09fad8ce 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -11,10 +11,9 @@ import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.inventory.ClickType import org.bukkit.event.inventory.InventoryClickEvent -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.BookMeta +import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.anvil.AnvilCost import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.AnvilResult @@ -37,6 +36,7 @@ import java.util.* import java.util.concurrent.atomic.AtomicReference import kotlin.math.min +@Suppress("UnstableApiUsage") class AnvilResultListener : Listener { companion object { @@ -51,7 +51,7 @@ class AnvilResultListener : Listener { @EventHandler(ignoreCancelled = true) fun anvilExtractionCheck(event: InventoryClickEvent) { val player = event.whoClicked as? Player ?: return - val inventory = event.inventory as? AnvilInventory ?: return + val view = event.view as? AnvilView ?: return val view = event.view if (event.rawSlot != ANVIL_OUTPUT_SLOT) { @@ -59,17 +59,17 @@ class AnvilResultListener : Listener { } // Test if the event should bypass custom anvil. - if (DependencyManager.tryClickAnvilResultBypass(event, inventory)) return + if (DependencyManager.tryClickAnvilResultBypass(event, view)) return if (!player.hasPermission(CustomAnvil.affectedByPluginPermission)) return - val output = inventory.getItem(ANVIL_OUTPUT_SLOT) ?: return - val leftItem = inventory.getItem(ANVIL_INPUT_LEFT) ?: return - val rightItem = inventory.getItem(ANVIL_INPUT_RIGHT) + val output = view.getItem(ANVIL_OUTPUT_SLOT) ?: return + val leftItem = view.getItem(ANVIL_INPUT_LEFT) ?: return + val rightItem = view.getItem(ANVIL_INPUT_RIGHT) // Deny by default. allow if working event.result = Event.Result.DENY - if (GameMode.CREATIVE != player.gameMode && inventory.repairCost >= inventory.maximumRepairCost) { + if (GameMode.CREATIVE != player.gameMode && view.repairCost >= view.maximumRepairCost) { return } @@ -77,14 +77,14 @@ class AnvilResultListener : Listener { val customRecipeResult = AnvilMergeLogic.testCustomRecipe(view, inventory, player, leftItem, rightItem) if (!customRecipeResult.isEmpty()) { onCustomCraft( - event, player, inventory, + event, player, view, leftItem, rightItem, customRecipeResult ) return } // Do not continue if there was no change - if ((output == inventory.getItem(ANVIL_INPUT_LEFT))) { + if ((output == view.getItem(ANVIL_INPUT_LEFT))) { return } @@ -94,7 +94,7 @@ class AnvilResultListener : Listener { if (result.isEmpty()) return extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, null, 0, result @@ -108,7 +108,7 @@ class AnvilResultListener : Listener { val result = AnvilMergeLogic.doMerge(view, inventory, player, leftItem, rightItem) val worked = extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, null, 0, result @@ -128,7 +128,7 @@ class AnvilResultListener : Listener { ) if (!unitRepairResult.isEmpty()) { onUnitRepairExtract( - rightItem, event, player, inventory, + rightItem, event, player, view, unitRepairResult ) return @@ -138,9 +138,9 @@ class AnvilResultListener : Listener { val loreResult = AnvilMergeLogic.testLoreEdit(player, leftItem, rightItem) if (!loreResult.isEmpty()) { if (loreResult.type.isBook) - handleBookLoreEdit(event, inventory, player, leftItem, rightItem, loreResult) + handleBookLoreEdit(event, view, player, leftItem, rightItem, loreResult) else - handlePaperLoreEdit(event, inventory, player, leftItem, rightItem, loreResult) + handlePaperLoreEdit(event, view, player, leftItem, rightItem, loreResult) return } } @@ -148,7 +148,7 @@ class AnvilResultListener : Listener { private fun onCustomCraft( event: InventoryClickEvent, player: Player, - inventory: AnvilInventory, + view: AnvilView, leftItem: ItemStack, rightItem: ItemStack?, result: CustomCraftResult, @@ -186,7 +186,7 @@ class AnvilResultListener : Listener { if (event.click != ClickType.MIDDLE && !handleCustomCraftClick( event, - inventory, + view, player, leftItem, rightItem, @@ -204,7 +204,7 @@ class AnvilResultListener : Listener { private fun handleCustomCraftClick( event: InventoryClickEvent, - inventory: AnvilInventory, player: Player, + view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack?, result: CustomCraftResult ): Boolean { @@ -216,11 +216,11 @@ class AnvilResultListener : Listener { if (recipe.rightItem == null) return false// in case it changed rightItem.amount -= amount * recipe.rightItem!!.amount - inventory.setItem(ANVIL_INPUT_RIGHT, rightItem) + view.setItem(ANVIL_INPUT_RIGHT, rightItem) } leftItem.amount -= amount * recipe.leftItem!!.amount - inventory.setItem(ANVIL_INPUT_LEFT, leftItem) + view.setItem(ANVIL_INPUT_LEFT, leftItem) removeCustomCraftCost(player, result) @@ -229,17 +229,15 @@ class AnvilResultListener : Listener { CustomAnvil.verboseLog("new amount is $newAmount") if (newAmount <= 0 || recipe.exactCount) { - inventory.setItem(ANVIL_OUTPUT_SLOT, null) + view.setItem(ANVIL_OUTPUT_SLOT, null) } else { val resultItem: ItemStack = recipe.resultItem!!.clone() resultItem.amount *= newAmount val newXp = newAmount * newAmount - inventory.repairCost = newXp - event.view.setProperty(InventoryView.Property.REPAIR_COST, newXp) - - inventory.setItem(ANVIL_OUTPUT_SLOT, resultItem) + view.repairCost = newXp + view.setItem(ANVIL_OUTPUT_SLOT, resultItem) player.updateInventory() } @@ -305,7 +303,7 @@ class AnvilResultListener : Listener { private fun extractAnvilResult( event: InventoryClickEvent, player: Player, - inventory: AnvilInventory, + view: AnvilView, leftItem: ItemStack?, leftRemoveCount: Int, rightItem: ItemStack?, @@ -322,7 +320,7 @@ class AnvilResultListener : Listener { event.isCancelled = true val cost = result.cost - processCost(inventory, player, cost) + processCost(view, player, cost) if (!cost.valid && player.gameMode != GameMode.CREATIVE) { CustomAnvil.verboseLog("Player cannot afford the cost") return false @@ -338,12 +336,12 @@ class AnvilResultListener : Listener { // We remove what should be removed if (leftItem != null) leftItem.amount -= leftRemoveCount - inventory.setItem(ANVIL_INPUT_LEFT, leftItem) + view.setItem(ANVIL_INPUT_LEFT, leftItem) if (rightItem != null) rightItem.amount -= rightRemoveCount - inventory.setItem(ANVIL_INPUT_RIGHT, rightItem) + view.setItem(ANVIL_INPUT_RIGHT, rightItem) - inventory.setItem(ANVIL_OUTPUT_SLOT, null) + view.setItem(ANVIL_OUTPUT_SLOT, null) } @@ -358,7 +356,7 @@ class AnvilResultListener : Listener { return true } - private fun processCost(inventory: AnvilInventory, player: Player, cost: AnvilCost) { + private fun processCost(view: AnvilView, player: Player, cost: AnvilCost) { var sum = cost.repair if ( @@ -376,7 +374,7 @@ class AnvilResultListener : Listener { if (!EconomyManager.economy!!.has(player, cost.asMonetaryCost())) cost.valid = false } else { - if ((inventory.maximumRepairCost <= sum) + if ((view.maximumRepairCost <= sum) || (player.level < sum) ) cost.valid = false } @@ -386,12 +384,12 @@ class AnvilResultListener : Listener { rightItem: ItemStack, event: InventoryClickEvent, player: Player, - inventory: AnvilInventory, + view: AnvilView, result: UnitRepairResult, ) { // We give the item manually extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, rightItem, result.repairAmount, result @@ -400,21 +398,21 @@ class AnvilResultListener : Listener { private fun handleBookLoreEdit( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack, result: LoreEditResult ) { if (result.type.isAppend) - handleBookLoreAppend(event, inventory, player, rightItem, result) + handleBookLoreAppend(event, view, player, rightItem, result) else - handleBookLoreRemove(event, inventory, player, leftItem, rightItem, result) + handleBookLoreRemove(event, view, player, leftItem, rightItem, result) } private fun handleBookLoreAppend( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, rightItem: ItemStack, result: LoreEditResult @@ -432,7 +430,7 @@ class AnvilResultListener : Listener { } extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, clearedBook, 0, result @@ -441,7 +439,7 @@ class AnvilResultListener : Listener { private fun handleBookLoreRemove( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack, @@ -477,7 +475,7 @@ class AnvilResultListener : Listener { } extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, rightCopy, 0, result @@ -486,21 +484,21 @@ class AnvilResultListener : Listener { private fun handlePaperLoreEdit( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack, result: LoreEditResult ) { if (result.type.isAppend) - handlePaperLoreAppend(event, inventory, player, rightItem, result) + handlePaperLoreAppend(event, view, player, rightItem, result) else - handlePaperLoreRemove(event, inventory, player, leftItem, rightItem, result) + handlePaperLoreRemove(event, view, player, leftItem, rightItem, result) } private fun handlePaperLoreAppend( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, rightItem: ItemStack, result: LoreEditResult @@ -525,14 +523,14 @@ class AnvilResultListener : Listener { if (rightItem.amount > 1) { extractAnvilResult( - event, player, inventory, + event, player, view, paperCopy, 0, rightItem, 1, result ) } else { extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, paperCopy, 0, result @@ -542,7 +540,7 @@ class AnvilResultListener : Listener { private fun handlePaperLoreRemove( event: InventoryClickEvent, - inventory: AnvilInventory, + view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack, @@ -577,14 +575,14 @@ class AnvilResultListener : Listener { if (rightItem.amount > 1) { extractAnvilResult( - event, player, inventory, + event, player, view, rightClone, 0, rightItem, 1, result ) } else { extractAnvilResult( - event, player, inventory, + event, player, view, null, 0, rightClone, 0, result diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/ChatEventListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/ChatEventListener.kt index f166fa39..f2a68cb0 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/ChatEventListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/ChatEventListener.kt @@ -41,9 +41,10 @@ class ChatEventListener : Listener { // sync callback with default server thread DependencyManager.scheduler.scheduleOnEntity( CustomAnvil.instance, player, - Runnable { - eventCallback.accept(event.message) - }, 0L) + { + eventCallback.accept(event.message) + }, 0L + ) } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt index c0fe939b..ce263613 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.listener -import com.github.stefvanschie.inventoryframework.util.InventoryViewUtil import io.delilaheve.CustomAnvil import io.delilaheve.util.ConfigOptions import io.delilaheve.util.ItemUtil.canMergeWith @@ -16,6 +15,7 @@ import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.EnchantmentStorageMeta import org.bukkit.inventory.meta.ItemMeta import xyz.alexcrea.cuanvil.anvil.AnvilCost +import org.bukkit.inventory.view.AnvilView import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.AnvilResult import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.doMerge import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.doRenaming @@ -30,6 +30,7 @@ import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil /** * Listener for anvil events */ +@Suppress("UnstableApiUsage") class PrepareAnvilListener : Listener { companion object { @@ -48,24 +49,23 @@ class PrepareAnvilListener : Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) fun anvilCombineCheck(event: PrepareAnvilEvent) { val view = event.view - val inventory = event.inventory + val player = view.player - val player = InventoryViewUtil.getInstance().getPlayer(view) - if(player !is Player) return + if (player !is Player) return tryRenameDialog(player, event) // Test if custom anvil is bypassed before immutability test if (DependencyManager.earlyTryEventPreAnvilBypass(event, player)) { // even if we got bypassed we still want to set price - AnvilXpUtil.setAnvilInvCost(inventory, view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(view, player, AnvilCost(view.repairCost)) return } - val first = inventory.getItem(ANVIL_INPUT_LEFT) - val second = inventory.getItem(ANVIL_INPUT_RIGHT) + val first = view.getItem(ANVIL_INPUT_LEFT) + val second = view.getItem(ANVIL_INPUT_RIGHT) - if(IS_EMPTY_TEST) { + if (IS_EMPTY_TEST) { IS_EMPTY_TEST = false applyResult(event, player, AnvilResult.EMPTY) return @@ -86,7 +86,7 @@ class PrepareAnvilListener : Listener { // Test if the event should bypass custom anvil. if (DependencyManager.tryEventPreAnvilBypass(event, player)) { // even if we got bypassed we still want to set price - AnvilXpUtil.setAnvilInvCost(inventory, view, player, AnvilCost(event.inventory.repairCost)) + AnvilXpUtil.setAnvilInvCost(view, player, AnvilCost(view.repairCost)) return } @@ -100,9 +100,9 @@ class PrepareAnvilListener : Listener { view: InventoryView, //TODO use anvil view inventory: AnvilInventory, player: Player, - first: ItemStack?, second: ItemStack?) : AnvilResult - { - if(first == null) + first: ItemStack?, second: ItemStack? + ): AnvilResult { + if (first == null) return AnvilResult.EMPTY // Test custom recipe @@ -137,7 +137,7 @@ class PrepareAnvilListener : Listener { player: HumanEntity, event: PrepareAnvilEvent ) { - if(!ConfigOptions.canUseDialogRename(player)) return + if (!ConfigOptions.canUseDialogRename(player)) return AnvilRenameDialogUtil.anvilRenameDialog.tryShowDialog(player, event) } @@ -171,7 +171,7 @@ class PrepareAnvilListener : Listener { private fun applyResult(event: PrepareAnvilEvent, player: Player, result: AnvilResult) { event.result = result.item - AnvilXpUtil.setAnvilResult(event.inventory, event.view, player, result) + AnvilXpUtil.setAnvilResult(event.view, player, result) } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt index dc1e25a9..af5020c7 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaterialUtil.kt @@ -1,6 +1,5 @@ package xyz.alexcrea.cuanvil.util -import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.inventory.ItemStack diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index 78ea8830..d8cb9102 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -8,10 +8,10 @@ import org.bukkit.GameMode import org.bukkit.NamespacedKey import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player -import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Repairable +import org.bukkit.inventory.view.AnvilView import org.bukkit.persistence.PersistentDataType import xyz.alexcrea.cuanvil.anvil.AnvilCost import xyz.alexcrea.cuanvil.anvil.AnvilMergeLogic.AnvilResult @@ -25,6 +25,7 @@ import xyz.alexcrea.cuanvil.util.AnvilTitleUtil import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil import kotlin.math.sqrt +@Suppress("UnstableApiUsage") object AnvilXpUtil { const val EXCLUSIVE_PENALTY_PREFIX = "repair_cost" @@ -50,17 +51,16 @@ object AnvilXpUtil { * Display the required cost (either as xp or as money) */ fun setAnvilInvCost( - inventory: AnvilInventory, - view: InventoryView, + view: AnvilView, player: Player, cost: AnvilCost, ignoreRules: Boolean = false ) { if (ConfigOptions.shouldUseMoney(player)) { cost.isMonetary = true - setAnvilPrice(inventory, view, player, cost) + setAnvilPrice(view, player, cost) } else - setAnvilInvXp(inventory, view, player, cost.filteredXpCost(ignoreRules), ignoreRules) + setAnvilInvXp(view, player, cost.filteredXpCost(ignoreRules), ignoreRules) } fun maximumXpCost(ignoreRules: Boolean = false): Int { @@ -75,8 +75,7 @@ object AnvilXpUtil { * Display xp needed for the work on the anvil inventory */ private fun setAnvilInvXp( - inventory: AnvilInventory, - view: InventoryView, + view: AnvilView, player: HumanEntity, anvilCost: Int, ignoreRules: Boolean = false @@ -84,8 +83,8 @@ object AnvilXpUtil { val maximumRepairCost = maximumXpCost(ignoreRules) // Try first just in case another plugin, or the test need this - inventory.maximumRepairCost = maximumRepairCost - inventory.repairCost = anvilCost + view.maximumRepairCost = maximumRepairCost + view.repairCost = anvilCost // TODO for 2.x.x use anvil view & set directly there /* Because Minecraft likes to have the final say in the repair cost displayed @@ -95,16 +94,15 @@ object AnvilXpUtil { CustomAnvil.instance, player ) { // retry after a tick - inventory.maximumRepairCost = maximumRepairCost - inventory.repairCost = anvilCost - // TODO for 2.x.x use anvil view & set directly there + view.maximumRepairCost = maximumRepairCost + view.repairCost = anvilCost if (player !is Player) return@scheduleOnEntity if (player.gameMode != GameMode.CREATIVE) { val bypassToExpensive = (ConfigOptions.doReplaceTooExpensive) && (anvilCost >= 40) && - anvilCost < inventory.maximumRepairCost + anvilCost < view.maximumRepairCost DependencyManager.packetManager.setInstantBuild(player, bypassToExpensive) } @@ -117,8 +115,7 @@ object AnvilXpUtil { * Display monetary cost needed for the work on the anvil inventory */ private fun setAnvilPrice( - inventory: AnvilInventory, - view: InventoryView, + view: AnvilView, player: Player, cost: AnvilCost, ) { @@ -136,22 +133,20 @@ object AnvilXpUtil { CustomAnvil.instance ) - clearAnvilXpCost(inventory, view, player) + clearAnvilXpCost(view, player) } private fun clearAnvilXpCost( - inventory: AnvilInventory, - view: InventoryView, + view: AnvilView, player: HumanEntity, ) { - // TODO for 2.x.x use anvil view & set directly there - inventory.repairCost = 0 + view.repairCost = 0 // retry after a tick DependencyManager.scheduler.scheduleOnEntity( CustomAnvil.instance, player ) { - inventory.repairCost = 0 + view.repairCost = 0 if (player !is Player) return@scheduleOnEntity player.updateInventory() From b5843756c79e0f2c4029955e6cc6ca4bcbcfd9fe Mon Sep 17 00:00:00 2001 From: alexcrea Date: Fri, 12 Jun 2026 19:58:46 +0200 Subject: [PATCH 37/41] rebase on new update --- .../cuanvil/util/MaxDamageCheckerUtil.kt | 18 ------------- .../listener/CATreatAnvilResult2Event.java | 19 +++++-------- .../alexcrea/cuanvil/anvil/AnvilMergeLogic.kt | 27 +++++++------------ .../cuanvil/dependency/DependencyManager.kt | 10 +++---- .../cuanvil/listener/AnvilResultListener.kt | 11 +++----- .../cuanvil/listener/PrepareAnvilListener.kt | 15 +++++------ .../cuanvil/util/anvil/AnvilXpUtil.kt | 3 ++- 7 files changed, 32 insertions(+), 71 deletions(-) delete mode 100644 nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt diff --git a/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt b/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt deleted file mode 100644 index b3ce0ff6..00000000 --- a/nms/v1_20R4/src/main/kotlin/xyz/alexcrea/cuanvil/util/MaxDamageCheckerUtil.kt +++ /dev/null @@ -1,18 +0,0 @@ -package xyz.alexcrea.cuanvil.util - -import org.bukkit.inventory.meta.Damageable - -// I LOVE support of old versions and needing to do modules like that -// That truly is my favorite activity -// TODO clean this one of legacy removal branch -object MaxDamageCheckerUtil { - - /** - * @return max damage or int max if not set - */ - fun getMaxDamage(meta: Damageable): Int { - if(!meta.hasMaxDamage()) return Integer.MAX_VALUE - return meta.maxDamage - } - -} \ No newline at end of file diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java index 30c53806..5d534d91 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java @@ -5,6 +5,7 @@ import org.bukkit.event.HandlerList; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.view.AnvilView; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -21,7 +22,7 @@ import xyz.alexcrea.cuanvil.anvil.AnvilUseType; *

    * A null result will cancel this event */ -@SuppressWarnings("unused") +@SuppressWarnings({"unused", "UnstableApiUsage"}) public class CATreatAnvilResult2Event extends Event { private static final HandlerList HANDLERS = new HandlerList(); @@ -36,7 +37,7 @@ public class CATreatAnvilResult2Event extends Event { } @NotNull - private final InventoryView view; + private final AnvilView view; private final AnvilUseType useType; @@ -50,32 +51,26 @@ public class CATreatAnvilResult2Event extends Event { private final AnvilCost cost; - @ApiStatus.Internal public CATreatAnvilResult2Event( - @NotNull InventoryView view, - Inventory inv, + @NotNull AnvilView view, AnvilUseType useType, @Nullable ItemStack result, AnvilCost cost) { this.view = view; this.useType = useType; - this.left = inv.getItem(0); // TODO use view here - this.right = inv.getItem(1); + this.left = view.getItem(0); + this.right = view.getItem(1); this.result = result; this.cost = cost; } /** * Get the bukkit inventory view. - *

    - * Temporarily marked as internal as it will get changed to anvil view on legacy removal - * so signature will change * * @return The inventory view of this event. */ - @ApiStatus.Internal - public @NotNull InventoryView getView() { + public @NotNull AnvilView getView() { return view; } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt index 80f8f053..e5e5bc7f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt @@ -10,8 +10,6 @@ import org.bukkit.ChatColor import org.bukkit.Material import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.ItemMeta import org.bukkit.inventory.view.AnvilView @@ -99,8 +97,7 @@ object AnvilMergeLogic { } fun doRenaming( - view: InventoryView, //TODO use anvil view - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack ): AnvilResult { val resultItem = DependencyManager.cloneItem(player, first) @@ -115,7 +112,7 @@ object AnvilMergeLogic { cost.workPenalty = AnvilXpUtil.calculatePenalty(first, null, resultItem, AnvilUseType.RENAME_ONLY) val result = - DependencyManager.tryTreatAnvilResult(view, inventory, player, resultItem, AnvilUseType.RENAME_ONLY, cost) + DependencyManager.tryTreatAnvilResult(view, player, resultItem, AnvilUseType.RENAME_ONLY, cost) return AnvilResult(result, cost) } @@ -185,8 +182,7 @@ object AnvilMergeLogic { } fun doMerge( - view: InventoryView, //TODO use anvil view instead - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack, second: ItemStack ): AnvilResult { @@ -224,7 +220,7 @@ object AnvilMergeLogic { cost.rename = handleRename(resultItem, view, player) val result = - DependencyManager.tryTreatAnvilResult(view, inventory, player, resultItem, AnvilUseType.MERGE, cost) + DependencyManager.tryTreatAnvilResult(view, player, resultItem, AnvilUseType.MERGE, cost) return AnvilResult(result, cost) } @@ -243,8 +239,7 @@ object AnvilMergeLogic { // return true if a custom recipe exist with these ingredients fun testCustomRecipe( - view: InventoryView, //TODO use anvil view instead - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack, second: ItemStack? ): CustomCraftResult { @@ -266,24 +261,22 @@ object AnvilMergeLogic { else AnvilXpUtil.calculateLevelForXp(xpCost) val result = - DependencyManager.tryTreatAnvilResult(view, inventory, player, resultItem, AnvilUseType.CUSTOM_CRAFT, cost) + DependencyManager.tryTreatAnvilResult(view, player, resultItem, AnvilUseType.CUSTOM_CRAFT, cost) return CustomCraftResult(result, cost, amount, recipe) } fun testUnitRepair( - view: InventoryView, //TODO use anvil view - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack, second: ItemStack ): UnitRepairResult { val unitRepairAmount = first.getRepair(second) ?: return UnitRepairResult.EMPTY - return testUnitRepair(view, inventory, player, first, second, unitRepairAmount) + return testUnitRepair(view, player, first, second, unitRepairAmount) } fun testUnitRepair( - view: InventoryView, //TODO use anvil view instead - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack, second: ItemStack, unitRepairAmount: Double @@ -306,7 +299,7 @@ object AnvilMergeLogic { } val result = - DependencyManager.tryTreatAnvilResult(view, inventory, player, resultItem, AnvilUseType.UNIT_REPAIR, cost) + DependencyManager.tryTreatAnvilResult(view, player, resultItem, AnvilUseType.UNIT_REPAIR, cost) return UnitRepairResult(result, cost, repairAmount) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index 3139fc51..3558bcf0 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -9,9 +9,6 @@ import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.PrepareAnvilEvent -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.Inventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import xyz.alexcrea.cuanvil.anvil.AnvilCost import org.bukkit.inventory.view.AnvilView @@ -234,19 +231,18 @@ object DependencyManager { // Return null if there was an issue fun tryTreatAnvilResult( - view: InventoryView, - inventory: Inventory, // TODO REMOVE, use view instead on legacy removal + view: AnvilView, player: HumanEntity, result: ItemStack, useType: AnvilUseType, cost: AnvilCost ): ItemStack? { - val treatEvent = CATreatAnvilResult2Event(view, inventory, useType, result, cost) + val treatEvent = CATreatAnvilResult2Event(view, useType, result, cost) try { unsafeTryTreatAnvilResult(treatEvent) return treatEvent.result } catch (e: Exception) { - logExceptionAndClear(player, inventory, e) + logExceptionAndClear(view, e) return null } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index 09fad8ce..7d750d06 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -52,7 +52,6 @@ class AnvilResultListener : Listener { fun anvilExtractionCheck(event: InventoryClickEvent) { val player = event.whoClicked as? Player ?: return val view = event.view as? AnvilView ?: return - val view = event.view if (event.rawSlot != ANVIL_OUTPUT_SLOT) { return @@ -74,7 +73,7 @@ class AnvilResultListener : Listener { } // Test custom recipe - val customRecipeResult = AnvilMergeLogic.testCustomRecipe(view, inventory, player, leftItem, rightItem) + val customRecipeResult = AnvilMergeLogic.testCustomRecipe(view, player, leftItem, rightItem) if (!customRecipeResult.isEmpty()) { onCustomCraft( event, player, view, @@ -90,7 +89,7 @@ class AnvilResultListener : Listener { // Rename if (rightItem == null) { - val result = AnvilMergeLogic.doRenaming(view, inventory, player, leftItem) + val result = AnvilMergeLogic.doRenaming(view, player, leftItem) if (result.isEmpty()) return extractAnvilResult( @@ -105,7 +104,7 @@ class AnvilResultListener : Listener { // Merge val canMerge = leftItem.canMergeWith(rightItem) if (canMerge) { - val result = AnvilMergeLogic.doMerge(view, inventory, player, leftItem, rightItem) + val result = AnvilMergeLogic.doMerge(view, player, leftItem, rightItem) val worked = extractAnvilResult( event, player, view, @@ -123,7 +122,7 @@ class AnvilResultListener : Listener { // Unit repair val unitRepairResult = AnvilMergeLogic.testUnitRepair( - view, inventory, player, + view, player, leftItem, rightItem ) if (!unitRepairResult.isEmpty()) { @@ -185,7 +184,6 @@ class AnvilResultListener : Listener { // Handle not creative middle click... if (event.click != ClickType.MIDDLE && !handleCustomCraftClick( - event, view, player, leftItem, @@ -203,7 +201,6 @@ class AnvilResultListener : Listener { } private fun handleCustomCraftClick( - event: InventoryClickEvent, view: AnvilView, player: Player, leftItem: ItemStack, rightItem: ItemStack?, result: CustomCraftResult diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt index ce263613..eda35fc6 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/PrepareAnvilListener.kt @@ -9,8 +9,6 @@ import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.Listener import org.bukkit.event.inventory.PrepareAnvilEvent -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.EnchantmentStorageMeta import org.bukkit.inventory.meta.ItemMeta @@ -92,13 +90,12 @@ class PrepareAnvilListener : Listener { if (!player.hasPermission(CustomAnvil.affectedByPluginPermission)) return - val result = getResult(view, inventory, player, first, second) + val result = getResult(view, player, first, second) applyResult(event, player, result) } fun getResult( - view: InventoryView, //TODO use anvil view - inventory: AnvilInventory, + view: AnvilView, player: Player, first: ItemStack?, second: ItemStack? ): AnvilResult { @@ -106,7 +103,7 @@ class PrepareAnvilListener : Listener { return AnvilResult.EMPTY // Test custom recipe - var result: AnvilResult = testCustomRecipe(view, inventory, player, first, second) + var result: AnvilResult = testCustomRecipe(view, player, first, second) if (!result.isEmpty()) return result @@ -114,14 +111,14 @@ class PrepareAnvilListener : Listener { val shouldTryRename = second.isAir CustomAnvil.verboseLog("checking air in main logic: $shouldTryRename") if (shouldTryRename) - return doRenaming(view, inventory, player, first) + return doRenaming(view, player, first) // Test for merge if (first.canMergeWith(second!!)) - return doMerge(view, inventory, player, first, second) + return doMerge(view, player, first, second) // Test for unit repair - result = testUnitRepair(view, inventory, player, first, second) + result = testUnitRepair(view, player, first, second) if (!result.isEmpty()) return result diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index d8cb9102..9f8f9542 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -8,6 +8,7 @@ import org.bukkit.GameMode import org.bukkit.NamespacedKey import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player +import org.bukkit.inventory.AnvilInventory import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Repairable @@ -199,7 +200,7 @@ object AnvilXpUtil { return resultSum } - fun onNoResult(player: HumanEntity, view: InventoryView) { + fun onNoResult(player: HumanEntity, view: AnvilView) { if (ConfigOptions.shouldUseMoney(player)) AnvilTitleUtil.rename( view, "Repair & Name", From 5e5493b0e848b5bf03078533924d005fa1265636 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Mon, 22 Jun 2026 03:44:18 +0200 Subject: [PATCH 38/41] prepare for v2 --- .github/workflows/gradle.yml | 4 +- build.gradle.kts | 2 +- .../cuanvil/api/AnvilRecipeBuilder.java | 23 --- .../alexcrea/cuanvil/api/ConflictBuilder.java | 2 +- .../alexcrea/cuanvil/api/EnchantmentApi.java | 17 +- .../listener/CAClickResultBypassEvent.java | 2 +- .../listener/CAEarlyPreAnvilBypassEvent.java | 2 +- .../event/listener/CAPreAnvilBypassEvent.java | 2 +- .../listener/CATreatAnvilResult2Event.java | 191 ------------------ .../listener/CATreatAnvilResultEvent.java | 100 ++++----- .../cuanvil/enchant/CAEnchantment.java | 17 +- .../enchant/CAEnchantmentRegistry.java | 18 +- .../cuanvil/dependency/DependencyManager.kt | 8 +- .../dependency/economy/VaultEconomyManager.kt | 2 + .../plugins/ExcellentEnchantsDependency.kt | 4 +- .../cuanvil/group/EnchantConflictManager.kt | 2 +- .../cuanvil/util/anvil/AnvilXpUtil.kt | 3 - .../cuanvil/util/AnvilFuseTestUtil.java | 2 +- 18 files changed, 64 insertions(+), 337 deletions(-) delete mode 100644 src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index befd5102..663bb9b3 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -9,9 +9,9 @@ name: Java CI with Gradle on: push: - branches: [ "v1.x.x", "v2.x.x" ] + branches: [ "v1.x.x", "v2.x.x", "v3.x.x" ] pull_request: - branches: [ "v1.x.x", "v2.x.x" ] + branches: [ "v1.x.x", "v2.x.x", "v3.x.x" ] release: types: [published] diff --git a/build.gradle.kts b/build.gradle.kts index e3ef6a3a..214a49f9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.18.0" +version = "2.0.0" val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true" diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/AnvilRecipeBuilder.java b/src/main/java/xyz/alexcrea/cuanvil/api/AnvilRecipeBuilder.java index 4292fa01..c4a52daf 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/AnvilRecipeBuilder.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/AnvilRecipeBuilder.java @@ -90,29 +90,6 @@ public class AnvilRecipeBuilder { return this; } - /** - * Get the xp level cost per craft. (default 0) - * - * @return The xp level cost per craft - * @deprecated use {@link #getLevelCostPerCraft() getLevelCostPerCraft} instead - */ - @Deprecated(since = "1.13.0") - public int getXpCostPerCraft() { - return getLevelCostPerCraft(); - } - - /** - * Sets the xp level cost per craft. - * - * @param xpCostPerCraft The xp level cost per craft - * @return This recipe builder instance. - * @deprecated use {@link #setLevelCostPerCraft(int) setLevelCostPerCraft} instead - */ - @Deprecated(since = "1.13.0") - public AnvilRecipeBuilder setXpCostPerCraft(int xpCostPerCraft) { - return setLevelCostPerCraft(xpCostPerCraft); - } - /** * Get the xp level cost per craft. (default 0) * diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/ConflictBuilder.java b/src/main/java/xyz/alexcrea/cuanvil/api/ConflictBuilder.java index 14607664..df0ccfbf 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/ConflictBuilder.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/ConflictBuilder.java @@ -387,7 +387,7 @@ public class ConflictBuilder { */ protected void appendEnchantments(@NotNull EnchantConflictGroup conflict) { for (String enchantmentName : getEnchantmentNames()) { - if (appendEnchantments(conflict, EnchantmentApi.getListByName(enchantmentName)) == 0) { + if (appendEnchantments(conflict, EnchantmentApi.getByName(enchantmentName)) == 0) { CustomAnvil.instance.getLogger().warning("Could not find enchantment " + enchantmentName + " for conflict " + getName()); ConflictAPI.logConflictOrigin(this); } diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java b/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java index 965d7495..c0a5ff2b 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/EnchantmentApi.java @@ -132,27 +132,14 @@ public class EnchantmentApi { return CAEnchantment.getByKey(key); } - /** - * Get by name an enchantment. - * - * @param name The name used to fetch - * @return The custom anvil enchantment of this name. null if not found. - * @deprecated use {@link #getListByName(String)} - */ - @Deprecated(since = "1.6.3") - @Nullable - public static CAEnchantment getByName(@NotNull String name) { - return CAEnchantment.getByName(name); - } - /** * Get list of enchantment using the provided name. * * @param name The name used to fetch * @return List of custom anvil enchantments of this name. May be empty if not found. */ - public static List getListByName(@NotNull String name) { - return CAEnchantment.getListByName(name); + public static List getByName(@NotNull String name) { + return CAEnchantment.getByName(name); } /** diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java index fe5e1993..a27c65e4 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAClickResultBypassEvent.java @@ -17,7 +17,7 @@ import org.jetbrains.annotations.NotNull; * Most of the time you would likely need {@link CAPreAnvilBypassEvent} or {@link CAEarlyPreAnvilBypassEvent} * for this event to be useful. *

    - * There is also {@link CATreatAnvilResult2Event} that may be better for some use case. + * There is also {@link CATreatAnvilResultEvent} that may be better for some use case. */ public class CAClickResultBypassEvent extends Event implements Cancellable { diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java index e92b4cdb..2fbd275d 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAEarlyPreAnvilBypassEvent.java @@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull; *

    * You should also use {@link CAClickResultBypassEvent} if you want to use this event for something useful. *

    - * It is also recommended that you read about {@link CAPreAnvilBypassEvent} and {@link CATreatAnvilResult2Event} + * It is also recommended that you read about {@link CAPreAnvilBypassEvent} and {@link CATreatAnvilResultEvent} * as your use case may be more prone to use theses. */ public class CAEarlyPreAnvilBypassEvent extends Event implements Cancellable { diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java index 9103a4b2..18334e36 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CAPreAnvilBypassEvent.java @@ -18,7 +18,7 @@ import org.jetbrains.annotations.NotNull; *

    * You should also use {@link CAClickResultBypassEvent} if you want to use this event for something useful. *

    - * It is also recommended that you read about {@link CAEarlyPreAnvilBypassEvent} and {@link CATreatAnvilResult2Event} + * It is also recommended that you read about {@link CAEarlyPreAnvilBypassEvent} and {@link CATreatAnvilResultEvent} * as your use case may be more prone to use theses. */ public class CAPreAnvilBypassEvent extends Event implements Cancellable { diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java deleted file mode 100644 index 5d534d91..00000000 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResult2Event.java +++ /dev/null @@ -1,191 +0,0 @@ -package xyz.alexcrea.cuanvil.api.event.listener; - -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryView; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.view.AnvilView; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import xyz.alexcrea.cuanvil.anvil.AnvilCost; -import xyz.alexcrea.cuanvil.anvil.AnvilUseType; - -/** - * Called after custom anvil processed the click on the result on the anvil inventory. - * This event should be used to modify the result of an anvil use. - *

    - * You may also want to check {@link CAClickResultBypassEvent}, - * {@link CAPreAnvilBypassEvent} - * and {@link CAEarlyPreAnvilBypassEvent} for your use case - *

    - * A null result will cancel this event - */ -@SuppressWarnings({"unused", "UnstableApiUsage"}) -public class CATreatAnvilResult2Event extends Event { - - private static final HandlerList HANDLERS = new HandlerList(); - - public static HandlerList getHandlerList() { - return HANDLERS; - } - - @Override - public @NotNull HandlerList getHandlers() { - return HANDLERS; - } - - @NotNull - private final AnvilView view; - - private final AnvilUseType useType; - - @Nullable - private final ItemStack left; - @Nullable - private final ItemStack right; - - @Nullable - private ItemStack result; - - private final AnvilCost cost; - - public CATreatAnvilResult2Event( - @NotNull AnvilView view, - AnvilUseType useType, - @Nullable ItemStack result, - AnvilCost cost) { - this.view = view; - this.useType = useType; - - this.left = view.getItem(0); - this.right = view.getItem(1); - this.result = result; - this.cost = cost; - } - - /** - * Get the bukkit inventory view. - * - * @return The inventory view of this event. - */ - public @NotNull AnvilView getView() { - return view; - } - - - /** - * Get the type of use source of the result. - * - * @return The craft use type. - */ - public AnvilUseType getUseType() { - return useType; - } - - /** - * Get the left item of the anvil use - * - * @return the left item - */ - public @Nullable ItemStack getLeftItem() { - return left; - } - - /** - * Get the right item of the anvil use - * - * @return the right item - */ - public @Nullable ItemStack getRightItem() { - return right; - } - - /** - * Get the current result - *

    - * note that it will not be null unless another listener previously set it to null. - * - * @return The current result. - */ - public @Nullable ItemStack getResult() { - return result; - } - - /** - * Set the current result - *

    - * note that a null result will cancel this anvil use. - * - * @param result The new result - */ - public void setResult(@Nullable ItemStack result) { - this.result = result; - } - - /** - * Get the level cost displayed on the anvil. - *

    Important note:

    - * the final price are re calculated on click for the following use case: - *
      - *
    • Custom craft
    • - *
    • Unit repair
    • - *
    • Lore edit
    • - *
    - * This value will be used as final price for: - *
  • Item merge
  • - *
  • Item rename
  • - * - * - * @return The current cost. - * @deprecated use #{@link #getCost()} instead - */ - @Deprecated(forRemoval = true, since = "1.17.0") - public int getLevelCost() { - return cost.asXpCost(); - } - - /** - * Set the level cost displayed on the anvil. - *

    Important note:

    - * the final price are re calculated on click for the following use case: - *
      - *
    • Custom craft
    • - *
    • Unit repair
    • - *
    • Lore edit
    • - *
    - * This value will be used as final price for: - *
  • Item merge
  • - *
  • Item rename
  • - * - * - * @param levelCost The new cost. - * @deprecated use #{@link #getCost()} and set value on this instead - */ - @Deprecated(forRemoval = true, since = "1.17.0") - public void setLevelCost(int levelCost) { - cost.setGeneric(levelCost - cost.getGeneric() - cost.asXpCost()); - } - - /** - * Allow access to the current cost of the event - * Note that modifying this object will change the event resulting cost - * - *

    Important note:

    - * the final price are re calculated on click for the following use case: - *
      - *
    • Custom craft
    • - *
    • Unit repair
    • - *
    • Lore edit
    • - *
    - * This value will be used as final price for: - *
  • Item merge
  • - *
  • Item rename
  • - * - * @return the current anvil cost - */ - public AnvilCost getCost() { - return cost; - } -} diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java index 80965b57..703a2829 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/event/listener/CATreatAnvilResultEvent.java @@ -2,8 +2,8 @@ package xyz.alexcrea.cuanvil.api.event.listener; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -import org.bukkit.event.inventory.PrepareAnvilEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.view.AnvilView; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import xyz.alexcrea.cuanvil.anvil.AnvilCost; @@ -17,13 +17,9 @@ import xyz.alexcrea.cuanvil.anvil.AnvilUseType; * {@link CAPreAnvilBypassEvent} * and {@link CAEarlyPreAnvilBypassEvent} for your use case *

    - * A null result will cancel this pre anvil event - * - * @deprecated Prepare anvil Event cannot be provided as it can be called on result and therefore not have prepared anvil event - * use {@link CATreatAnvilResult2Event} instead + * A null result will cancel this event */ -@SuppressWarnings("unused") -@Deprecated(forRemoval = true, since = "1.17.0") +@SuppressWarnings({"unused", "UnstableApiUsage"}) public class CATreatAnvilResultEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); @@ -38,31 +34,44 @@ public class CATreatAnvilResultEvent extends Event { } @NotNull - private final PrepareAnvilEvent event; + private final AnvilView view; private final AnvilUseType useType; + @Nullable + private final ItemStack left; + @Nullable + private final ItemStack right; + @Nullable private ItemStack result; private final AnvilCost cost; - public CATreatAnvilResultEvent(@NotNull PrepareAnvilEvent event, AnvilUseType useType, @Nullable ItemStack result, AnvilCost cost) { - this.event = event; + public CATreatAnvilResultEvent( + @NotNull AnvilView view, + AnvilUseType useType, + @Nullable ItemStack result, + AnvilCost cost) { + this.view = view; this.useType = useType; + + this.left = view.getItem(0); + this.right = view.getItem(1); this.result = result; this.cost = cost; } /** - * Get the bukkit inventory click event causing to this event. + * Get the bukkit inventory view. * - * @return The click event causing to this event. + * @return The inventory view of this event. */ - public @NotNull PrepareAnvilEvent getEvent() { - return event; + public @NotNull AnvilView getView() { + return view; } + /** * Get the type of use source of the result. * @@ -72,6 +81,24 @@ public class CATreatAnvilResultEvent extends Event { return useType; } + /** + * Get the left item of the anvil use + * + * @return the left item + */ + public @Nullable ItemStack getLeftItem() { + return left; + } + + /** + * Get the right item of the anvil use + * + * @return the right item + */ + public @Nullable ItemStack getRightItem() { + return right; + } + /** * Get the current result *

    @@ -94,50 +121,6 @@ public class CATreatAnvilResultEvent extends Event { this.result = result; } - /** - * Get the level cost displayed on the anvil. - *

    Important note:

    - * the final price are re calculated on click for the following use case: - *
      - *
    • Custom craft
    • - *
    • Unit repair
    • - *
    • Lore edit
    • - *
    - * This value will be used as final price for: - *
  • Item merge
  • - *
  • Item rename
  • - * - * - * @return The current cost. - * @deprecated use #{@link #getCost()} instead - */ - @Deprecated(forRemoval = true, since = "1.17.0") - public int getLevelCost() { - return cost.asXpCost(); - } - - /** - * Set the level cost displayed on the anvil. - *

    Important note:

    - * the final price are re calculated on click for the following use case: - *
      - *
    • Custom craft
    • - *
    • Unit repair
    • - *
    • Lore edit
    • - *
    - * This value will be used as final price for: - *
  • Item merge
  • - *
  • Item rename
  • - * - * - * @param levelCost The new cost. - * @deprecated use #{@link #getCost()} and set value on this instead - */ - @Deprecated(forRemoval = true, since = "1.17.0") - public void setLevelCost(int levelCost) { - cost.setGeneric(levelCost - cost.getGeneric() - cost.asXpCost()); - } - /** * Allow access to the current cost of the event * Note that modifying this object will change the event resulting cost @@ -158,5 +141,4 @@ public class CATreatAnvilResultEvent extends Event { public AnvilCost getCost() { return cost; } - } diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java index 1d1aca46..fed90277 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantment.java @@ -234,25 +234,14 @@ public interface CAEnchantment { return CAEnchantmentRegistry.getInstance().getByKey(key); } - /** - * Gets the enchantment by the provided name. - * @param name Name to fetch. - * @return Registered enchantment. null if absent. - * - * @deprecated use {@link #getListByName(String)} - */ - @Deprecated(since = "1.6.3") - static @Nullable CAEnchantment getByName(@NotNull String name){ - return CAEnchantmentRegistry.getInstance().getByName(name); - } - /** * Gets list of enchantment using the provided name. + * * @param name Name to fetch. * @return List of registered enchantment. */ - static List getListByName(@NotNull String name){ - return CAEnchantmentRegistry.getInstance().getListByName(name); + static List getByName(@NotNull String name){ + return CAEnchantmentRegistry.getInstance().getByName(name); } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantmentRegistry.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantmentRegistry.java index 854ed55c..ec83616d 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantmentRegistry.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/CAEnchantmentRegistry.java @@ -155,22 +155,6 @@ public class CAEnchantmentRegistry { return byKeyMap.get(key); } - /** - * Gets the enchantment by the provided name. - * - * @param name Name to fetch. - * @return Registered enchantment. null if absent. - * @deprecated use {@link #getListByName(String)} - */ - @Deprecated(since = "1.6.3") - @Nullable - public CAEnchantment getByName(@NotNull String name) { - List enchantments = getListByName(name); - if (enchantments.isEmpty()) return null; - - return enchantments.get(0); - } - /** * Gets list of enchantment using the provided name. * @@ -178,7 +162,7 @@ public class CAEnchantmentRegistry { * @return List of registered enchantment. */ @NotNull - public List getListByName(@NotNull String name) { + public List getByName(@NotNull String name) { return byNameMap.getOrDefault(name, Collections.emptyList()); } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt index 3558bcf0..50743d81 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/DependencyManager.kt @@ -10,13 +10,13 @@ import org.bukkit.entity.Player import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.inventory.ItemStack -import xyz.alexcrea.cuanvil.anvil.AnvilCost import org.bukkit.inventory.view.AnvilView +import xyz.alexcrea.cuanvil.anvil.AnvilCost import xyz.alexcrea.cuanvil.anvil.AnvilUseType import xyz.alexcrea.cuanvil.api.event.listener.CAClickResultBypassEvent import xyz.alexcrea.cuanvil.api.event.listener.CAEarlyPreAnvilBypassEvent import xyz.alexcrea.cuanvil.api.event.listener.CAPreAnvilBypassEvent -import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResult2Event +import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResultEvent import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.dependency.datapack.DataPackDependency import xyz.alexcrea.cuanvil.dependency.gui.GenericExternGuiTester @@ -237,7 +237,7 @@ object DependencyManager { useType: AnvilUseType, cost: AnvilCost ): ItemStack? { - val treatEvent = CATreatAnvilResult2Event(view, useType, result, cost) + val treatEvent = CATreatAnvilResultEvent(view, useType, result, cost) try { unsafeTryTreatAnvilResult(treatEvent) return treatEvent.result @@ -247,7 +247,7 @@ object DependencyManager { } } - private fun unsafeTryTreatAnvilResult(event: CATreatAnvilResult2Event) { + private fun unsafeTryTreatAnvilResult(event: CATreatAnvilResultEvent) { Bukkit.getPluginManager().callEvent(event) excellentEnchantsCompatibility?.treatAnvilResult(event) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/economy/VaultEconomyManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/economy/VaultEconomyManager.kt index 058485e2..23d22b52 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/economy/VaultEconomyManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/economy/VaultEconomyManager.kt @@ -1,3 +1,5 @@ +@file:Suppress("DEPRECATION") + package xyz.alexcrea.cuanvil.dependency.economy import net.milkbowl.vault.economy.Economy diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt index d3d46ccc..9370decd 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt @@ -8,7 +8,7 @@ import org.bukkit.event.inventory.PrepareAnvilEvent import org.bukkit.inventory.ItemStack import org.bukkit.plugin.RegisteredListener import xyz.alexcrea.cuanvil.api.EnchantmentApi -import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResult2Event +import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResultEvent import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEPreV5Enchantment import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5Enchantment import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5_4Enchantment @@ -222,7 +222,7 @@ class ExcellentEnchantsDependency { return handleRechargeMethod.invoke(this.usedAnvilListener, event, first, second) as Boolean } - fun treatAnvilResult(event: CATreatAnvilResult2Event) { + fun treatAnvilResult(event: CATreatAnvilResultEvent) { val result = event.result ?: return val first: ItemStack = treatInput(event.leftItem) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index 6b836c13..c235abd4 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -164,7 +164,7 @@ class EnchantConflictManager { } - return CAEnchantment.getListByName(enchantName) + return CAEnchantment.getByName(enchantName) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index 9f8f9542..b397e865 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -8,8 +8,6 @@ import org.bukkit.GameMode import org.bukkit.NamespacedKey import org.bukkit.entity.HumanEntity import org.bukkit.entity.Player -import org.bukkit.inventory.AnvilInventory -import org.bukkit.inventory.InventoryView import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.Repairable import org.bukkit.inventory.view.AnvilView @@ -86,7 +84,6 @@ object AnvilXpUtil { // Try first just in case another plugin, or the test need this view.maximumRepairCost = maximumRepairCost view.repairCost = anvilCost - // TODO for 2.x.x use anvil view & set directly there /* Because Minecraft likes to have the final say in the repair cost displayed * we need to wait for the event to end before overriding it, this ensures that diff --git a/src/test/java/xyz/alexcrea/cuanvil/util/AnvilFuseTestUtil.java b/src/test/java/xyz/alexcrea/cuanvil/util/AnvilFuseTestUtil.java index fefec130..75af4db3 100644 --- a/src/test/java/xyz/alexcrea/cuanvil/util/AnvilFuseTestUtil.java +++ b/src/test/java/xyz/alexcrea/cuanvil/util/AnvilFuseTestUtil.java @@ -71,7 +71,7 @@ public class AnvilFuseTestUtil { List enchantments = new ArrayList<>(); for (String enchantmentName : enchantmentNames) { - List enchantmentList = CAEnchantment.getListByName(enchantmentName); + List enchantmentList = CAEnchantment.getByName(enchantmentName); Assertions.assertNotEquals(0, enchantmentList.size(), "Could not find enchantment \"" + enchantmentName + "\""); From 8078e54b15909a7b0c3aae44d337715cc8a27bb8 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 30 Jun 2026 23:35:00 +0200 Subject: [PATCH 39/41] rebase on news update --- .../xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt | 2 +- .../kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index 7d750d06..2bfc97d0 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -115,7 +115,7 @@ class AnvilResultListener : Listener { if(!worked) { CustomAnvil.verboseLog("Merge extract failed. reset the displayed price") // Reset the price - AnvilXpUtil.setAnvilResult(inventory, view, player, result) + AnvilXpUtil.setAnvilResult(view, player, result) } return } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index b397e865..433680b0 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -33,8 +33,7 @@ object AnvilXpUtil { * Display the required cost (either as xp or as money) or reset anvil price depending on result */ fun setAnvilResult( - inventory: AnvilInventory, - view: InventoryView, + view: AnvilView, player: Player, result: AnvilResult ) { @@ -43,7 +42,7 @@ object AnvilXpUtil { return } - setAnvilInvCost(inventory, view, player, result.cost, result.ignoreXpRules) + setAnvilInvCost(view, player, result.cost, result.ignoreXpRules) } /** From b56782b2346da5886d79aefbc0caaa77967c92ca Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 30 Jun 2026 23:47:16 +0200 Subject: [PATCH 40/41] remove legacy command --- src/main/kotlin/io/delilaheve/CustomAnvil.kt | 12 +----- .../alexcrea/cuanvil/command/CASubCommand.kt | 37 +++---------------- .../cuanvil/command/DebugToggleExecutor.kt | 2 +- .../cuanvil/command/DiagnosticExecutor.kt | 11 +++--- .../cuanvil/command/EditConfigExecutor.kt | 15 +++++--- .../alexcrea/cuanvil/command/HelpExecutor.kt | 13 ++++++- .../cuanvil/command/ReloadExecutor.kt | 9 ++++- src/main/resources/plugin.yml | 12 ------ 8 files changed, 43 insertions(+), 68 deletions(-) diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 906e023f..a119bfc7 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -145,7 +145,7 @@ open class CustomAnvil : JavaPlugin() { // Add commands try { - prepareCommand() + CustomAnvilCommand(this) } catch (e: Exception) { logger.log(Level.SEVERE, "error trying to register commands", e) MetricsUtil.trackError(e) @@ -330,14 +330,4 @@ open class CustomAnvil : JavaPlugin() { return yamlConfig } - fun prepareCommand() { - var command = getCommand(commandReloadName) - command?.setExecutor(ReloadExecutor()) - - command = getCommand(commandConfigName) - command?.setExecutor(EditConfigExecutor()) - - CustomAnvilCommand(this) - } - } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt index 943dd6bd..67613335 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt @@ -1,52 +1,27 @@ package xyz.alexcrea.cuanvil.command -import org.bukkit.ChatColor import org.bukkit.command.Command -import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry -abstract class CASubCommand : CommandExecutor { +interface CASubCommand { - private var alreadySaid = false; - override fun onCommand( - sender: CommandSender, - cmd: Command, - cmdstr: String, - args: Array - ): Boolean { - if (!alreadySaid) { - sender.sendMessage( - ChatColor.RED.toString() + - "Please not that this command will be replaced as a subcommand of `/customanvil` or `/ca`" - ) - alreadySaid = true - } - - return executeCommand(sender, cmd, cmdstr, args) - } - - abstract fun executeCommand( + fun executeCommand( sender: CommandSender, cmd: Command, cmdstr: String, args: Array ): Boolean - open fun allowed(sender: CommandSender): Boolean { - return true - } + fun allowed(sender: CommandSender): Boolean - open fun tabCompleter( + fun tabCompleter( sender: CommandSender, args: Array, list: MutableList - ) { - } + ) - open fun description(): String { - return "no description" - } + fun description(): String protected fun allEnchantmentsByName(): Collection { val names = mutableSetOf() diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt index c668e6e0..302ff782 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt @@ -12,7 +12,7 @@ import org.bukkit.command.CommandSender import org.bukkit.entity.Player import xyz.alexcrea.cuanvil.command.DiagnosticExecutor.Companion.NO_DIAG_PERM -class DebugToggleExecutor : CASubCommand() { +class DebugToggleExecutor : CASubCommand { override fun description(): String { return "Used to toggle debug logs and retrieve it" diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt index b7bb1dd9..efbf2902 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt @@ -30,8 +30,7 @@ import xyz.alexcrea.cuanvil.util.MetricsUtil import java.util.* import java.util.stream.Collectors - -class DiagnosticExecutor : CASubCommand() { +class DiagnosticExecutor : CASubCommand { companion object { const val NO_DIAG_PERM = "You do not have permission to diagnostic this server" @@ -327,10 +326,10 @@ class DiagnosticExecutor : CASubCommand() { stb.append( "\nNamespaces: ${ - map.entries.stream() - .map { (key, value) -> "$key ($value)" } - .reduce { a, b -> "$a, $b" }.get() - }" + map.entries.stream() + .map { (key, value) -> "$key ($value)" } + .reduce { a, b -> "$a, $b" }.get() + }" ) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index c6bc191b..a4eb99a0 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -14,16 +14,12 @@ import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions import xyz.alexcrea.cuanvil.util.MaterialUtil.customType import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir -class EditConfigExecutor : CASubCommand() { +class EditConfigExecutor : CASubCommand { override fun allowed(sender: CommandSender): Boolean { return sender.hasPermission(CustomAnvil.editConfigPermission) } - override fun description(): String { - return "Gui to edit the plugin's config" - } - override fun executeCommand( sender: CommandSender, cmd: Command, @@ -116,6 +112,15 @@ class EditConfigExecutor : CASubCommand() { else -> listOf() } ) + override fun tabCompleter( + sender: CommandSender, + args: Array, + list: MutableList + ) { + } + + override fun description(): String { + return "Gui to edit the plugin's config" } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt index 1314d0ec..c6c4d08c 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt @@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableMap import org.bukkit.command.Command import org.bukkit.command.CommandSender -class HelpExecutor : CASubCommand() { +class HelpExecutor : CASubCommand { lateinit var commands: ImmutableMap @@ -27,6 +27,17 @@ class HelpExecutor : CASubCommand() { return true } + override fun allowed(sender: CommandSender): Boolean { + return true + } + + override fun tabCompleter( + sender: CommandSender, + args: Array, + list: MutableList + ) { + } + override fun description(): String { return "Help command" } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt index ab832c4f..d3df341a 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt @@ -10,7 +10,7 @@ import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.gui.config.global.* import xyz.alexcrea.cuanvil.update.UpdateHandler -class ReloadExecutor : CASubCommand() { +class ReloadExecutor : CASubCommand { override fun executeCommand( sender: CommandSender, @@ -40,6 +40,13 @@ class ReloadExecutor : CASubCommand() { return sender.hasPermission(CustomAnvil.commandReloadPermission) } + override fun tabCompleter( + sender: CommandSender, + args: Array, + list: MutableList + ) { + } + override fun description(): String { return "Reload the configuration of this plugin" } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1268ae6c..4828330b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -14,18 +14,6 @@ commands: description: Generic command for custom anvil aliases: - ca - anvilconfigreload: - description: Reload every config of this plugin - permission: ca.command.reload - aliases: - #- acreload # anvil config reload - #- careload # custom anvil reload - - carl # custom anvil reload - customanvilconfig: - description: open a menu for administrator to edit plugin's config in game - permission: ca.config.edit - aliases: - - configanvil permissions: ca.affected: From eeff628da651fcf6942abb58fc77c5974e0670ba Mon Sep 17 00:00:00 2001 From: alexcrea Date: Wed, 8 Jul 2026 03:58:03 +0200 Subject: [PATCH 41/41] update from v1.x.x --- .../xyz/alexcrea/cuanvil/command/CASubCommand.kt | 2 +- .../cuanvil/command/EditConfigExecutor.kt | 15 +++++---------- .../alexcrea/cuanvil/command/EnchantExecutor.kt | 6 +++--- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt index 67613335..ede87e9a 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt @@ -23,7 +23,7 @@ interface CASubCommand { fun description(): String - protected fun allEnchantmentsByName(): Collection { + fun allEnchantmentsByName(): Collection { val names = mutableSetOf() for (enchantment in CAEnchantmentRegistry.getInstance().values()) { names.add(enchantment.name) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index a4eb99a0..79151cd3 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -20,6 +20,10 @@ class EditConfigExecutor : CASubCommand { return sender.hasPermission(CustomAnvil.editConfigPermission) } + override fun description(): String { + return "Gui to edit the plugin's config" + } + override fun executeCommand( sender: CommandSender, cmd: Command, @@ -68,7 +72,7 @@ class EditConfigExecutor : CASubCommand { return } } else { - enchantToFilter = HashSet(EnchantmentApi.getListByName(args[1].lowercase())) + enchantToFilter = HashSet(EnchantmentApi.getByName(args[1].lowercase())) if (enchantToFilter.isEmpty()) { sender.sendMessage("No enchantment found with the name \"${args[1]}\"") @@ -112,15 +116,6 @@ class EditConfigExecutor : CASubCommand { else -> listOf() } ) - override fun tabCompleter( - sender: CommandSender, - args: Array, - list: MutableList - ) { - } - - override fun description(): String { - return "Gui to edit the plugin's config" } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt index dd2957fa..fdae6b04 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EnchantExecutor.kt @@ -8,7 +8,7 @@ import org.bukkit.entity.HumanEntity import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir -class EnchantExecutor : CASubCommand() { +class EnchantExecutor : CASubCommand { override fun allowed(sender: CommandSender): Boolean { @@ -44,7 +44,7 @@ class EnchantExecutor : CASubCommand() { } } - val enchants = EnchantmentApi.getListByName(args[0].lowercase()) + val enchants = EnchantmentApi.getByName(args[0].lowercase()) if (enchants.isEmpty()) { sender.sendMessage("Enchantment not found: ${args[0]}") return true @@ -92,7 +92,7 @@ class EnchantExecutor : CASubCommand() { sender: HumanEntity, name: String ): Collection { - val enchants = EnchantmentApi.getListByName(name.lowercase()) + val enchants = EnchantmentApi.getByName(name.lowercase()) if (enchants.isEmpty()) return listOf() val enchant = enchants.iterator().next()