Skip to content

Commit

Permalink
Updated to 1.21 and Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Jun 24, 2024
1 parent 291df4a commit 5bfe29a
Show file tree
Hide file tree
Showing 28 changed files with 116 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
- name: Checkout latest code
uses: actions/checkout@v2

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

- name: Change wrapper permissions
run: chmod +x ./gradlew
Expand Down
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
plugins {
java
id("java-library")
id("com.github.johnrengelman.shadow") version "7.0.0"
id("io.github.goooler.shadow") version "8.1.7"
id("maven-publish")
}

Expand All @@ -23,7 +23,7 @@ allprojects {
apply(plugin = "kotlin")
apply(plugin = "java")
apply(plugin = "maven-publish")
apply(plugin = "com.github.johnrengelman.shadow")
apply(plugin = "io.github.goooler.shadow")

repositories {
mavenCentral()
Expand Down Expand Up @@ -70,12 +70,12 @@ allprojects {

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "17"
jvmTarget = "21"
}
}

java.sourceCompatibility = JavaVersion.VERSION_17
java.targetCompatibility = JavaVersion.VERSION_17
java.sourceCompatibility = JavaVersion.VERSION_21
java.targetCompatibility = JavaVersion.VERSION_21

tasks {
compileJava {
Expand Down
4 changes: 2 additions & 2 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ dependencies {
}
implementation("com.willfp:ModelEngineBridge:1.3.0")

compileOnly("com.willfp:eco:6.70.0")
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("com.willfp:eco:6.71.0")
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
compileOnly("net.kyori:adventure-text-minimessage:4.14.0")

compileOnly("dev.aurelium:auraskills-api-bukkit:2.0.0")
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/kotlin/com/willfp/libreforge/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import com.willfp.eco.core.items.Items
import org.bukkit.Bukkit
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.Sound
import org.bukkit.SoundCategory
import org.bukkit.block.Block
import org.bukkit.enchantments.Enchantment
import org.bukkit.entity.AbstractArrow
import org.bukkit.entity.Entity
import org.bukkit.entity.LivingEntity
Expand Down Expand Up @@ -75,10 +77,15 @@ fun ItemStack.applyDamage(damage: Int, player: Player?): Boolean {
Bukkit.getPluginManager().callEvent(PlayerItemBreakEvent(player, this))
player.playSound(player.location, Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1f, 1f)
}
@Suppress("DEPRECATION")
this.type = Material.AIR
} else {
this.itemMeta = meta
}

return true
}

@Suppress("DEPRECATION")
fun getEnchantment(id: String): Enchantment? =
Enchantment.getByKey(NamespacedKey.minecraft(id))
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object ConditionHasPotionEffect : Condition<NoCompileData>("has_potion_effect")
): Boolean {
val livingEntity = dispatcher.get<LivingEntity>() ?: return false

return livingEntity.activePotionEffects.map { it.type.name }.containsIgnoreCase(
return livingEntity.activePotionEffects.map { it.type.key.key }.containsIgnoreCase(
config.getString("effect")
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.bukkit.command.CommandSender
import java.io.BufferedReader
import java.io.File
import java.net.HttpURLConnection
import java.net.URI
import java.net.URL

class CommandLrcdbImport(plugin: EcoPlugin) : Subcommand(
Expand All @@ -28,7 +29,7 @@ class CommandLrcdbImport(plugin: EcoPlugin) : Subcommand(
val id = args[0]

onLrcdbThread {
val url = URL("https://lrcdb.auxilor.io/api/v1/getConfigByID?id=$id&isDownload=true")
val url = URI("https://lrcdb.auxilor.io/api/v1/getConfigByID?id=$id&isDownload=true").toURL()
val connection = url.openConnection() as HttpURLConnection
val code = connection.responseCode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.willfp.libreforge.effects.impl
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.effects.Effect
import com.willfp.libreforge.getEnchantment
import com.willfp.libreforge.getIntFromExpression
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
Expand All @@ -20,7 +21,7 @@ object EffectAddEnchant : Effect<NoCompileData>("add_enchant") {

val meta = item.itemMeta ?: return false

val enchant = Enchantment.getByKey(NamespacedKey.minecraft(config.getString("enchant"))) ?: return false
val enchant = getEnchantment(config.getString("enchant")) ?: return false
val level = config.getIntFromExpression("level", data)

if (meta is EnchantmentStorageMeta) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.willfp.eco.core.fast.FastItemStack
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.arguments
import com.willfp.libreforge.effects.Effect
import com.willfp.libreforge.getEnchantment
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.event.DropResult
import com.willfp.libreforge.triggers.event.EditableBlockDropEvent
Expand Down Expand Up @@ -70,10 +71,11 @@ object EffectAutosmelt : Effect<NoCompileData>("autosmelt") {

private fun handleEvent(player: Player, event: EditableDropEvent, config: Config) {
val fortune = FastItemStack.wrap(player.inventory.itemInMainHand)
.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS, false)
.getEnchantmentLevel(getEnchantment("fortune")!!, false)

event.addModifier {
var (type, xp) = getOutput(it.type)
@Suppress("DEPRECATION")
it.type = type

if (fortune > 0 && it.maxStackSize > 1 && event is EditableBlockDropEvent && fortuneMaterials.contains(type)) {
Expand All @@ -91,6 +93,7 @@ object EffectAutosmelt : Effect<NoCompileData>("autosmelt") {

private fun handleItem(item: ItemStack) {
val (type, _) = getOutput(item.type)
@Suppress("DEPRECATION")
item.type = type
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object EffectConsumeHeldItem : Effect<NoCompileData>("consume_held_item") {

val newAmount = item.amount - amount
if (newAmount <= 0) {
@Suppress("DEPRECATION")
item.type = Material.AIR
} else {
item.amount = newAmount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ object EffectDamageArmor : Effect<NoCompileData>("damage_armor") {
player.playSound(player.location, Sound.ENTITY_ITEM_BREAK, SoundCategory.BLOCKS, 1f, 1f)
}

@Suppress("DEPRECATION")
itemStack.type = Material.AIR
} else {
itemStack.itemMeta = meta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object EffectPermanentPotionEffect : Effect<NoCompileData>("permanent_potion_eff
"https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html",
Config::getString
) {
@Suppress("DEPRECATION")
PotionEffectType.getByName(it.uppercase()) != null
}
require("level", "You must specify the effect level!")
Expand Down Expand Up @@ -73,8 +74,9 @@ object EffectPermanentPotionEffect : Effect<NoCompileData>("permanent_potion_eff
) {
val player = dispatcher.get<Player>() ?: return

@Suppress("DEPRECATION")
val effectType = PotionEffectType.getByName(config.getString("effect").uppercase())
?: PotionEffectType.INCREASE_DAMAGE
?: PotionEffectType.LUCK

val level = config.getIntFromExpression("level", player) - 1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("DEPRECATION", "REMOVAL")

package com.willfp.libreforge.effects.impl

import com.willfp.eco.util.duration
Expand All @@ -18,8 +20,7 @@ import org.bukkit.potion.PotionType

object EffectPotionDurationMultiplier : MultiplierEffect("potion_duration_multiplier") {
private val cannotExtend = setOf(
PotionType.INSTANT_DAMAGE, PotionType.INSTANT_HEAL, PotionType.AWKWARD,
PotionType.MUNDANE, PotionType.THICK, PotionType.WATER
PotionType.AWKWARD, PotionType.MUNDANE, PotionType.THICK, PotionType.WATER
)

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
Expand All @@ -33,7 +34,7 @@ object EffectPotionDurationMultiplier : MultiplierEffect("potion_duration_multip
val item = event.contents.getItem(i) ?: continue
val meta = item.itemMeta as? PotionMeta ?: continue

val potionData = meta.basePotionData
val potionData = meta.basePotionData ?: continue

if (potionData.type in cannotExtend) {
continue
Expand Down Expand Up @@ -62,15 +63,17 @@ object EffectPotionDurationMultiplier : MultiplierEffect("potion_duration_multip
}

val delta = meta.delta
val data = meta.basePotionData
val data = meta.basePotionData ?: return

val type = data.type

val effects = mutableMapOf<PotionEffectType, Int>()

if (data.type == PotionType.TURTLE_MASTER) {
effects[PotionEffectType.SLOW] = 4
effects[PotionEffectType.DAMAGE_RESISTANCE] = 2
if (type == PotionType.TURTLE_MASTER) {
effects[PotionEffectType.SLOWNESS] = 4
effects[PotionEffectType.RESISTANCE] = 2
} else {
val effectType = data.type.effectType ?: return
val effectType = type.effectType ?: return
effects[effectType] = if (data.isUpgraded) 2 else 1
}

Expand All @@ -93,13 +96,13 @@ object EffectPotionDurationMultiplier : MultiplierEffect("potion_duration_multip
val item = event.potion.item

val meta = item.itemMeta as? PotionMeta ?: return
val data = meta.basePotionData
val data = meta.basePotionData ?: return

val effects = mutableMapOf<PotionEffectType, Int>()

if (data.type == PotionType.TURTLE_MASTER) {
effects[PotionEffectType.SLOW] = 4
effects[PotionEffectType.DAMAGE_RESISTANCE] = 2
effects[PotionEffectType.SLOWNESS] = 4
effects[PotionEffectType.RESISTANCE] = 2
} else {
effects[data.type.effectType ?: return] = if (data.isUpgraded) 2 else 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ object EffectPotionEffect : Effect<NoCompileData>("potion_effect") {
"https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html",
Config::getString
) {
@Suppress("DEPRECATION")
PotionEffectType.getByName(it.uppercase()) != null
}
require("level", "You must specify the effect level!")
Expand All @@ -37,8 +38,9 @@ object EffectPotionEffect : Effect<NoCompileData>("potion_effect") {

toApply.addPotionEffect(
PotionEffect(
@Suppress("DEPRECATION")
PotionEffectType.getByName(config.getString("effect").uppercase())
?: PotionEffectType.INCREASE_DAMAGE,
?: PotionEffectType.LUCK,
config.getIntFromExpression("duration", data),
config.getIntFromExpression("level", data) - 1,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.willfp.libreforge.effects.impl
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.effects.Effect
import com.willfp.libreforge.getEnchantment
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
import org.bukkit.NamespacedKey
Expand All @@ -19,7 +20,7 @@ object EffectRemoveEnchant : Effect<NoCompileData>("remove_enchant") {

val meta = item.itemMeta ?: return false

val enchant = Enchantment.getByKey(NamespacedKey.minecraft(config.getString("enchant"))) ?: return false
val enchant = getEnchantment(config.getString("enchant")) ?: return false

if (meta is EnchantmentStorageMeta) {
meta.removeStoredEnchant(enchant)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ object EffectRemovePotionEffect : Effect<NoCompileData>("remove_potion_effect")
"https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/potion/PotionEffectType.html",
Config::getString
) {
@Suppress("DEPRECATION")
PotionEffectType.getByName(it.uppercase()) != null
}
}
Expand All @@ -34,8 +35,9 @@ object EffectRemovePotionEffect : Effect<NoCompileData>("remove_potion_effect")

plugin.scheduler.run {
toApply.removePotionEffect(
@Suppress("DEPRECATION")
PotionEffectType.getByName(config.getString("effect").uppercase())
?: PotionEffectType.INCREASE_DAMAGE
?: PotionEffectType.LUCK
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ object EffectSellItems : Effect<Collection<TestableItem>?>("sell_items") {

for (soldItem in sold) {
if (item == soldItem) {
@Suppress("DEPRECATION")
item.type = Material.AIR
item.amount = 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ object EffectSetArmorTrim : Effect<NoCompileData>("set_armor_trim") {

override val arguments = arguments {
require("pattern", "You must specify a valid trim pattern!", Config::getString) {
@Suppress("DEPRECATION")
Registry.TRIM_PATTERN.get(NamespacedKey.minecraft(it)) != null
}
require("material", "You must specify a valid trim material!", Config::getString) {
@Suppress("DEPRECATION")
Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft(it)) != null
}
}
Expand All @@ -29,7 +31,9 @@ object EffectSetArmorTrim : Effect<NoCompileData>("set_armor_trim") {
val item = data.foundItem ?: return false
val meta = item.itemMeta as? ArmorMeta ?: return false

@Suppress("DEPRECATION")
val material = Registry.TRIM_MATERIAL.get(NamespacedKey.minecraft(config.getString("material"))) ?: return false
@Suppress("DEPRECATION")
val pattern = Registry.TRIM_PATTERN.get(NamespacedKey.minecraft(config.getString("pattern"))) ?: return false

meta.trim = ArmorTrim(material, pattern)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object EffectSpawnPotionCloud : Effect<NoCompileData>("spawn_potion_cloud") {
val location = data.location ?: return false
val world = location.world ?: return false

@Suppress("DEPRECATION")
val effect = PotionEffectType.getByName(config.getString("effect").uppercase()) ?: return false
val level = config.getIntFromExpression("level", data)
val duration = config.getIntFromExpression("duration", data)
Expand Down
Loading

0 comments on commit 5bfe29a

Please sign in to comment.