From 0c82e8d2e99e82f98b1c168b701c1a2b433bfc01 Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 10:27:42 -0500 Subject: [PATCH 01/12] Bump gradle version --- build.gradle.kts | 16 ++++++++-------- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d7b5b1d..824d41b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -28,14 +28,14 @@ sourceSets { tasks { withType { kotlinOptions { - apiVersion = "1.5" - languageVersion = "1.5" - jvmTarget = "17" + apiVersion = "2.1" + languageVersion = "2.1" + jvmTarget = "21" } } withType { - sourceCompatibility = "17" - targetCompatibility = "17" + sourceCompatibility = "21" + targetCompatibility = "21" } jar { val dependencies = configurations @@ -57,7 +57,7 @@ tasks { plugins { // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. - id("org.jetbrains.kotlin.jvm") version "1.8.22" + id("org.jetbrains.kotlin.jvm") version "2.1.0" // Apply the java-library plugin for API and implementation separation. `java-library` @@ -78,9 +78,9 @@ dependencies { // Use the Kotlin JDK 8 standard library. implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") + compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT") compileOnly("net.kyori:adventure-text-serializer-plain:4.14.0") - compileOnly("com.comphenix.protocol:ProtocolLib:5.0.0") + compileOnly("com.comphenix.protocol:ProtocolLib:5.3.0") compileOnly("com.discordsrv:discordsrv:1.26.0") implementation( diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 00e33ed..d6e308a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 5ac2a9840e94222494fbcbaf475bf942795b7c28 Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 10:36:59 -0500 Subject: [PATCH 02/12] bump kotlin version --- build.gradle.kts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 824d41b..422ff9e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,6 +7,8 @@ */ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion sourceSets { main { @@ -27,10 +29,10 @@ sourceSets { tasks { withType { - kotlinOptions { - apiVersion = "2.1" - languageVersion = "2.1" - jvmTarget = "21" + compilerOptions { + jvmTarget.set(JvmTarget.JVM_21) + apiVersion.set(KotlinVersion.KOTLIN_2_1) + languageVersion.set(KotlinVersion.KOTLIN_2_1) } } withType { From 8ae12117af294396bf49443fb9391f5973c37281 Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 11:10:27 -0500 Subject: [PATCH 03/12] Fix several breaking constant name changes in latest spigot (1.21.3) --- src/BlockTypes.kt | 2 +- src/DragonBombManager.kt | 2 +- src/FallDamageListener.kt | 4 ++-- src/GrassPoisonListener.kt | 2 +- src/PiglinBarterListener.kt | 28 ++++++++++++------------ src/PumpkinSlownessManager.kt | 4 ++-- src/SaddleListener.kt | 6 +++--- src/SlowSlabListener.kt | 2 +- src/SweetDreamsListener.kt | 6 +++--- src/ZombieSpeedListener.kt | 2 +- src/angel/WeepingAngelManager.kt | 2 +- src/cake/ApplyPotionEffect.kt | 18 ++++++++-------- src/cookie/CookieEat.kt | 18 ++++++++-------- src/demand/DeathCondition.kt | 2 +- src/demand/bowser/RewardsPool.kt | 2 +- src/drop/BlockBreakEventListener.kt | 2 +- src/drop/ReplaceDropsAction.kt | 2 +- src/drop/ShuffleDropsAction.kt | 2 +- src/gravestone/CauseOfDeath.kt | 30 ++++++++++++++++++++------ src/jump/EncumbranceManagerFactory.kt | 4 ++-- src/parrot/ParrotManager.kt | 2 +- src/pokeball/Capture.kt | 6 +++--- src/pokeball/PokeballManager.kt | 2 +- src/pokeball/speciesCaptureRate.kt | 4 ++-- src/pokeball/toSpawnEgg.kt | 4 ++-- src/rain/RainOxygenMeter.kt | 2 +- src/trivia/question/QuestionLibrary.kt | 2 +- 27 files changed, 90 insertions(+), 72 deletions(-) diff --git a/src/BlockTypes.kt b/src/BlockTypes.kt index b3dd725..0699a8b 100644 --- a/src/BlockTypes.kt +++ b/src/BlockTypes.kt @@ -27,7 +27,7 @@ object BlockTypes { ) val TALL_GRASS = SetListAllomorph.of( - Material.GRASS, Material.TALL_GRASS, Material.FERN, + Material.GRASS_BLOCK, Material.TALL_GRASS, Material.FERN, Material.LARGE_FERN, Material.DEAD_BUSH, Material.CRIMSON_ROOTS, Material.WARPED_ROOTS, ) diff --git a/src/DragonBombManager.kt b/src/DragonBombManager.kt index 50b84a6..1e501ad 100644 --- a/src/DragonBombManager.kt +++ b/src/DragonBombManager.kt @@ -79,7 +79,7 @@ class DragonBombManager( } private fun currentTriggersPerAttack(dragon: EnderDragon): Long { - val maxHealth = dragon.getAttribute(Attribute.GENERIC_MAX_HEALTH)!!.getValue() + val maxHealth = dragon.getAttribute(Attribute.MAX_HEALTH)!!.getValue() val healthFraction = dragon.getHealth().toDouble() / maxHealth val triggers = healthFraction * maxTimerTriggersPerAttack + (1 - healthFraction) * minTimerTriggersPerAttack return triggers.toLong() diff --git a/src/FallDamageListener.kt b/src/FallDamageListener.kt index f1625c2..e931b17 100644 --- a/src/FallDamageListener.kt +++ b/src/FallDamageListener.kt @@ -36,8 +36,8 @@ class FallDamageListener() : AbstractFeature(), Listener { if (!event.isCancelled()) { if (victim is Player) { if (event.cause == EntityDamageEvent.DamageCause.FALL) { - victim.addPotionEffect(PotionEffect(PotionEffectType.CONFUSION, Constants.TICKS_PER_SECOND * 10, 1)) - victim.addPotionEffect(PotionEffect(PotionEffectType.SLOW, Constants.TICKS_PER_SECOND * 10, 0)) + victim.addPotionEffect(PotionEffect(PotionEffectType.NAUSEA, Constants.TICKS_PER_SECOND * 10, 1)) + victim.addPotionEffect(PotionEffect(PotionEffectType.SLOWNESS, Constants.TICKS_PER_SECOND * 10, 0)) } } } diff --git a/src/GrassPoisonListener.kt b/src/GrassPoisonListener.kt index 6606c06..88e895d 100644 --- a/src/GrassPoisonListener.kt +++ b/src/GrassPoisonListener.kt @@ -44,7 +44,7 @@ class GrassPoisonListener( if (!bootsDamager.tryWearDownBoots(player)) { telegrapher.trigger(player) player.addPotionEffect(PotionEffect(PotionEffectType.POISON, Constants.TICKS_PER_SECOND * 5, 0)) - player.addPotionEffect(PotionEffect(PotionEffectType.SLOW, Constants.TICKS_PER_SECOND * 10, 1)) + player.addPotionEffect(PotionEffect(PotionEffectType.SLOWNESS, Constants.TICKS_PER_SECOND * 10, 1)) } } } diff --git a/src/PiglinBarterListener.kt b/src/PiglinBarterListener.kt index 4b4fdcd..338a7ca 100644 --- a/src/PiglinBarterListener.kt +++ b/src/PiglinBarterListener.kt @@ -33,20 +33,20 @@ class PiglinBarterListener( private val ENCHANTMENT_CHOICES = listOf( EnchantmentData(Enchantment.MENDING, 1), EnchantmentData(Enchantment.THORNS, 1), - EnchantmentData(Enchantment.DURABILITY, 2), - EnchantmentData(Enchantment.DURABILITY, 3), - EnchantmentData(Enchantment.PROTECTION_ENVIRONMENTAL, 1), - EnchantmentData(Enchantment.PROTECTION_ENVIRONMENTAL, 2), - EnchantmentData(Enchantment.PROTECTION_ENVIRONMENTAL, 3), - EnchantmentData(Enchantment.PROTECTION_FIRE, 2), - EnchantmentData(Enchantment.PROTECTION_FIRE, 3), - EnchantmentData(Enchantment.PROTECTION_FIRE, 4), - EnchantmentData(Enchantment.PROTECTION_EXPLOSIONS, 2), - EnchantmentData(Enchantment.PROTECTION_EXPLOSIONS, 3), - EnchantmentData(Enchantment.PROTECTION_EXPLOSIONS, 4), - EnchantmentData(Enchantment.PROTECTION_PROJECTILE, 2), - EnchantmentData(Enchantment.PROTECTION_PROJECTILE, 3), - EnchantmentData(Enchantment.PROTECTION_PROJECTILE, 4), + EnchantmentData(Enchantment.UNBREAKING, 2), + EnchantmentData(Enchantment.UNBREAKING, 3), + EnchantmentData(Enchantment.PROTECTION, 1), + EnchantmentData(Enchantment.PROTECTION, 2), + EnchantmentData(Enchantment.PROTECTION, 3), + EnchantmentData(Enchantment.FIRE_PROTECTION, 2), + EnchantmentData(Enchantment.FIRE_PROTECTION, 3), + EnchantmentData(Enchantment.FIRE_PROTECTION, 4), + EnchantmentData(Enchantment.BLAST_PROTECTION, 2), + EnchantmentData(Enchantment.BLAST_PROTECTION, 3), + EnchantmentData(Enchantment.BLAST_PROTECTION, 4), + EnchantmentData(Enchantment.PROJECTILE_PROTECTION, 2), + EnchantmentData(Enchantment.PROJECTILE_PROTECTION, 3), + EnchantmentData(Enchantment.PROJECTILE_PROTECTION, 4), ) override fun create(state: BuilderState): FeatureContainer = diff --git a/src/PumpkinSlownessManager.kt b/src/PumpkinSlownessManager.kt index d9fb5e7..2d3380f 100644 --- a/src/PumpkinSlownessManager.kt +++ b/src/PumpkinSlownessManager.kt @@ -41,8 +41,8 @@ class PumpkinSlownessManager(plugin: Plugin) : RunnableFeature(plugin), Listener } for (player in Bukkit.getOnlinePlayers()) { if (Hats.isWearingOrdinaryHat(player)) { - player.addPotionEffect(PotionEffect(PotionEffectType.SLOW, Constants.TICKS_PER_SECOND * 10, 1)) - player.addPotionEffect(PotionEffect(PotionEffectType.SLOW_DIGGING, Constants.TICKS_PER_SECOND * 10, 0)) + player.addPotionEffect(PotionEffect(PotionEffectType.SLOWNESS, Constants.TICKS_PER_SECOND * 10, 1)) + player.addPotionEffect(PotionEffect(PotionEffectType.MINING_FATIGUE, Constants.TICKS_PER_SECOND * 10, 0)) } } } diff --git a/src/SaddleListener.kt b/src/SaddleListener.kt index b7c58a1..c567fd9 100644 --- a/src/SaddleListener.kt +++ b/src/SaddleListener.kt @@ -19,8 +19,8 @@ import org.bukkit.Chunk import org.bukkit.plugin.Plugin import org.bukkit.potion.PotionEffect import org.bukkit.potion.PotionEffectType -import org.spigotmc.event.entity.EntityMountEvent -import org.spigotmc.event.entity.EntityDismountEvent +import org.bukkit.event.entity.EntityMountEvent +import org.bukkit.event.entity.EntityDismountEvent class SaddleListener( val plugin: Plugin, @@ -37,7 +37,7 @@ class SaddleListener( PotionEffect(PotionEffectType.SPEED, Constants.TICKS_PER_SECOND * 999, 100) } EntityType.STRIDER -> { - PotionEffect(PotionEffectType.SLOW, Constants.TICKS_PER_SECOND * 999, 2) + PotionEffect(PotionEffectType.SLOWNESS, Constants.TICKS_PER_SECOND * 999, 2) } else -> { null diff --git a/src/SlowSlabListener.kt b/src/SlowSlabListener.kt index a5e072b..5f770a4 100644 --- a/src/SlowSlabListener.kt +++ b/src/SlowSlabListener.kt @@ -46,7 +46,7 @@ class SlowSlabListener( if (BLOCKS.contains(block.type)) { val player = event.player if (!bootsDamager.tryWearDownBoots(player)) { - player.addPotionEffect(PotionEffect(PotionEffectType.SLOW, Constants.TICKS_PER_SECOND * slowTimeSeconds, slownessLevel)) + player.addPotionEffect(PotionEffect(PotionEffectType.SLOWNESS, Constants.TICKS_PER_SECOND * slowTimeSeconds, slownessLevel)) } } } diff --git a/src/SweetDreamsListener.kt b/src/SweetDreamsListener.kt index 5e8c06e..6b9161e 100644 --- a/src/SweetDreamsListener.kt +++ b/src/SweetDreamsListener.kt @@ -22,10 +22,10 @@ class SweetDreamsListener( companion object : FeatureContainerFactory { val DEFAULT_EFFECTS_POOL: List<(Int) -> PotionEffect> = listOf( - { length -> PotionEffect(PotionEffectType.SLOW, length, 1) }, - { length -> PotionEffect(PotionEffectType.CONFUSION, length, 0) }, + { length -> PotionEffect(PotionEffectType.SLOWNESS, length, 1) }, + { length -> PotionEffect(PotionEffectType.NAUSEA, length, 0) }, { length -> PotionEffect(PotionEffectType.BLINDNESS, length, 0) }, - { length -> PotionEffect(PotionEffectType.SLOW_DIGGING, length, 4) }, + { length -> PotionEffect(PotionEffectType.MINING_FATIGUE, length, 4) }, { length -> PotionEffect(PotionEffectType.REGENERATION, length, 4) }, ) diff --git a/src/ZombieSpeedListener.kt b/src/ZombieSpeedListener.kt index c56fa11..911a82b 100644 --- a/src/ZombieSpeedListener.kt +++ b/src/ZombieSpeedListener.kt @@ -36,7 +36,7 @@ class ZombieSpeedListener( } val entity = event.entity if (entity is Zombie) { - val instance = entity.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED) + val instance = entity.getAttribute(Attribute.MOVEMENT_SPEED) instance?.setBaseValue(desiredSpeed) } } diff --git a/src/angel/WeepingAngelManager.kt b/src/angel/WeepingAngelManager.kt index a1fa713..df45a04 100644 --- a/src/angel/WeepingAngelManager.kt +++ b/src/angel/WeepingAngelManager.kt @@ -144,7 +144,7 @@ class WeepingAngelManager( safeAngels.add(lookingAt) val location = lookingAt.location.clone().add(0.0, 1.0, 0.0) val world = lookingAt.world - world.spawnParticle(Particle.REDSTONE, location, 4, 0.25, 0.5, 0.25, Particle.DustOptions(Color.ORANGE, 1.0f)) + world.spawnParticle(Particle.DUST, location, 4, 0.25, 0.5, 0.25, Particle.DustOptions(Color.ORANGE, 1.0f)) } } diff --git a/src/cake/ApplyPotionEffect.kt b/src/cake/ApplyPotionEffect.kt index aabbfc7..2d261e7 100644 --- a/src/cake/ApplyPotionEffect.kt +++ b/src/cake/ApplyPotionEffect.kt @@ -19,16 +19,16 @@ class ApplyPotionEffect( companion object { val Absorption = ApplyPotionEffect( 0.85, "Absorption" , PotionEffect(PotionEffectType.ABSORPTION , Constants.TICKS_PER_SECOND * 60, 1)) - val DamageResistance = ApplyPotionEffect( 0.85, "Damage Resistance" , PotionEffect(PotionEffectType.DAMAGE_RESISTANCE , Constants.TICKS_PER_SECOND * 60, 1)) + val DamageResistance = ApplyPotionEffect( 0.85, "Damage Resistance" , PotionEffect(PotionEffectType.RESISTANCE , Constants.TICKS_PER_SECOND * 60, 1)) val DolphinsGrace = ApplyPotionEffect( 0.40, "Dolphin's Grace" , PotionEffect(PotionEffectType.DOLPHINS_GRACE , Constants.TICKS_PER_SECOND * 60, 1)) - val FastDigging = ApplyPotionEffect( 0.55, "Fast Digging" , PotionEffect(PotionEffectType.FAST_DIGGING , Constants.TICKS_PER_SECOND * 60, 1)) + val FastDigging = ApplyPotionEffect( 0.55, "Haste" , PotionEffect(PotionEffectType.HASTE , Constants.TICKS_PER_SECOND * 60, 1)) val FireResistance = ApplyPotionEffect( 0.80, "Fire Resistance" , PotionEffect(PotionEffectType.FIRE_RESISTANCE , Constants.TICKS_PER_SECOND * 60, 1)) - val Heal = ApplyPotionEffect( 0.75, "Heal" , PotionEffect(PotionEffectType.HEAL , Constants.TICKS_PER_SECOND * 60, 1)) + val Heal = ApplyPotionEffect( 0.75, "Instant Health" , PotionEffect(PotionEffectType.INSTANT_HEALTH , Constants.TICKS_PER_SECOND * 60, 1)) val HealthBoost = ApplyPotionEffect( 0.75, "Health Boost" , PotionEffect(PotionEffectType.HEALTH_BOOST , Constants.TICKS_PER_SECOND * 60, 1)) val HeroOfTheVillage = ApplyPotionEffect( 0.45, "Hero Of The Village", PotionEffect(PotionEffectType.HERO_OF_THE_VILLAGE, Constants.TICKS_PER_SECOND * 60, 1)) - val IncreaseDamage = ApplyPotionEffect( 0.55, "Increase Damage" , PotionEffect(PotionEffectType.INCREASE_DAMAGE , Constants.TICKS_PER_SECOND * 60, 1)) + val IncreaseDamage = ApplyPotionEffect( 0.55, "Strength" , PotionEffect(PotionEffectType.STRENGTH , Constants.TICKS_PER_SECOND * 60, 1)) val Invisibility = ApplyPotionEffect( 0.35, "Invisibility" , PotionEffect(PotionEffectType.INVISIBILITY , Constants.TICKS_PER_SECOND * 60, 1)) - val Jump = ApplyPotionEffect( 0.50, "Jump" , PotionEffect(PotionEffectType.JUMP , Constants.TICKS_PER_SECOND * 60, 1)) + val Jump = ApplyPotionEffect( 0.50, "Jump Boost" , PotionEffect(PotionEffectType.JUMP_BOOST , Constants.TICKS_PER_SECOND * 60, 1)) val Luck = ApplyPotionEffect( 0.40, "Luck" , PotionEffect(PotionEffectType.LUCK , Constants.TICKS_PER_SECOND * 60, 1)) val NightVision = ApplyPotionEffect( 0.65, "Night Vision" , PotionEffect(PotionEffectType.NIGHT_VISION , Constants.TICKS_PER_SECOND * 60, 1)) val Regeneration = ApplyPotionEffect( 0.90, "Regeneration" , PotionEffect(PotionEffectType.REGENERATION , Constants.TICKS_PER_SECOND * 60, 1)) @@ -43,12 +43,12 @@ class ApplyPotionEffect( val BadOmen = ApplyPotionEffect(-0.45, "Bad Omen" , PotionEffect(PotionEffectType.BAD_OMEN , Constants.TICKS_PER_SECOND * 60, 1)) val Blindness = ApplyPotionEffect(-0.55, "Blindness" , PotionEffect(PotionEffectType.BLINDNESS , Constants.TICKS_PER_SECOND * 60, 1)) - val Confusion = ApplyPotionEffect(-0.60, "Confusion" , PotionEffect(PotionEffectType.CONFUSION , Constants.TICKS_PER_SECOND * 60, 1)) - val Harm = ApplyPotionEffect(-0.70, "Harm" , PotionEffect(PotionEffectType.HARM , Constants.TICKS_PER_SECOND * 60, 1)) + val Confusion = ApplyPotionEffect(-0.60, "Nausea" , PotionEffect(PotionEffectType.NAUSEA , Constants.TICKS_PER_SECOND * 60, 1)) + val Harm = ApplyPotionEffect(-0.70, "Instant Damage" , PotionEffect(PotionEffectType.INSTANT_DAMAGE , Constants.TICKS_PER_SECOND * 60, 1)) val Hunger = ApplyPotionEffect(-0.60, "Hunger" , PotionEffect(PotionEffectType.HUNGER , Constants.TICKS_PER_SECOND * 60, 1)) val Poison = ApplyPotionEffect(-0.80, "Poison" , PotionEffect(PotionEffectType.POISON , Constants.TICKS_PER_SECOND * 60, 1)) - val Slow = ApplyPotionEffect(-0.30, "Slow" , PotionEffect(PotionEffectType.SLOW , Constants.TICKS_PER_SECOND * 60, 1)) - val SlowDigging = ApplyPotionEffect(-0.50, "Slow Digging" , PotionEffect(PotionEffectType.SLOW_DIGGING , Constants.TICKS_PER_SECOND * 60, 1)) + val Slow = ApplyPotionEffect(-0.30, "Slowness" , PotionEffect(PotionEffectType.SLOWNESS , Constants.TICKS_PER_SECOND * 60, 1)) + val SlowDigging = ApplyPotionEffect(-0.50, "Mining Fatigue" , PotionEffect(PotionEffectType.MINING_FATIGUE , Constants.TICKS_PER_SECOND * 60, 1)) val Unluck = ApplyPotionEffect(-0.40, "Unluck" , PotionEffect(PotionEffectType.UNLUCK , Constants.TICKS_PER_SECOND * 60, 1)) val Weakness = ApplyPotionEffect(-0.30, "Weakness" , PotionEffect(PotionEffectType.WEAKNESS , Constants.TICKS_PER_SECOND * 60, 1)) val Wither = ApplyPotionEffect(-0.90, "Wither" , PotionEffect(PotionEffectType.WITHER , Constants.TICKS_PER_SECOND * 60, 1)) diff --git a/src/cookie/CookieEat.kt b/src/cookie/CookieEat.kt index e730f6b..e235b97 100644 --- a/src/cookie/CookieEat.kt +++ b/src/cookie/CookieEat.kt @@ -32,16 +32,16 @@ object CookieEat { Weight(DeathEffect(plugin), 0.2), // Status Effects (sum = 1.0) Weight(ApplyPotionEffect("Absorption", PotionEffectType.ABSORPTION), 0.031), - Weight(ApplyPotionEffect("Damage Resistance", PotionEffectType.DAMAGE_RESISTANCE), 0.031), + Weight(ApplyPotionEffect("Damage Resistance", PotionEffectType.RESISTANCE), 0.031), Weight(ApplyPotionEffect("Dolphins Grace", PotionEffectType.DOLPHINS_GRACE), 0.031), - Weight(ApplyPotionEffect("Fast Digging", PotionEffectType.FAST_DIGGING), 0.031), + Weight(ApplyPotionEffect("Haste", PotionEffectType.HASTE), 0.031), Weight(ApplyPotionEffect("Fire Resistance", PotionEffectType.FIRE_RESISTANCE), 0.031), - Weight(ApplyPotionEffect("Heal", PotionEffectType.HEAL), 0.031), + Weight(ApplyPotionEffect("Instant Health", PotionEffectType.INSTANT_HEALTH), 0.031), Weight(ApplyPotionEffect("Health Boost", PotionEffectType.HEALTH_BOOST), 0.031), Weight(ApplyPotionEffect("Hero Of The Village", PotionEffectType.HERO_OF_THE_VILLAGE), 0.031), - Weight(ApplyPotionEffect("Increase Damage", PotionEffectType.INCREASE_DAMAGE), 0.031), + Weight(ApplyPotionEffect("Strength", PotionEffectType.STRENGTH), 0.031), Weight(ApplyPotionEffect("Invisibility", PotionEffectType.INVISIBILITY), 0.031), - Weight(ApplyPotionEffect("Jump", PotionEffectType.JUMP), 0.031), + Weight(ApplyPotionEffect("Jump Boost", PotionEffectType.JUMP_BOOST), 0.031), Weight(ApplyPotionEffect("Luck", PotionEffectType.LUCK), 0.031), Weight(ApplyPotionEffect("Night Vision", PotionEffectType.NIGHT_VISION), 0.031), Weight(ApplyPotionEffect("Regeneration", PotionEffectType.REGENERATION), 0.031), @@ -54,12 +54,12 @@ object CookieEat { Weight(ApplyPotionEffect("Levitation", PotionEffectType.LEVITATION), 0.031), Weight(ApplyPotionEffect("Bad Omen", PotionEffectType.BAD_OMEN), 0.031), Weight(ApplyPotionEffect("Blindness", PotionEffectType.BLINDNESS), 0.031), - Weight(ApplyPotionEffect("Confusion", PotionEffectType.CONFUSION), 0.031), - Weight(ApplyPotionEffect("Harm", PotionEffectType.HARM), 0.031), + Weight(ApplyPotionEffect("Nausea", PotionEffectType.NAUSEA), 0.031), + Weight(ApplyPotionEffect("Instant Damage", PotionEffectType.INSTANT_DAMAGE), 0.031), Weight(ApplyPotionEffect("Hunger", PotionEffectType.HUNGER), 0.031), Weight(ApplyPotionEffect("Poison", PotionEffectType.POISON), 0.031), - Weight(ApplyPotionEffect("Slow", PotionEffectType.SLOW), 0.031), - Weight(ApplyPotionEffect("Slow Digging", PotionEffectType.SLOW_DIGGING), 0.031), + Weight(ApplyPotionEffect("Slowness", PotionEffectType.SLOWNESS), 0.031), + Weight(ApplyPotionEffect("Mining Fatigue", PotionEffectType.MINING_FATIGUE), 0.031), Weight(ApplyPotionEffect("Unluck", PotionEffectType.UNLUCK), 0.031), Weight(ApplyPotionEffect("Weakness", PotionEffectType.WEAKNESS), 0.031), Weight(ApplyPotionEffect("Wither", PotionEffectType.WITHER), 0.031), diff --git a/src/demand/DeathCondition.kt b/src/demand/DeathCondition.kt index 093e40c..1099010 100644 --- a/src/demand/DeathCondition.kt +++ b/src/demand/DeathCondition.kt @@ -161,7 +161,7 @@ abstract class DeathCondition : DailyDemandEvent { override fun test(event: PlayerDeathEvent, cause: CauseOfDeath): Boolean = (cause is Vanilla && conditions.contains(cause.cause)) || - (cause is VanillaMob && cause.entityType == EntityType.LIGHTNING) + (cause is VanillaMob && cause.entityType == EntityType.LIGHTNING_BOLT) } diff --git a/src/demand/bowser/RewardsPool.kt b/src/demand/bowser/RewardsPool.kt index d04824a..bd7b5e5 100644 --- a/src/demand/bowser/RewardsPool.kt +++ b/src/demand/bowser/RewardsPool.kt @@ -25,7 +25,7 @@ object RewardsPool { val ALL_REWARDS: List = listOf( ItemReward( mainItem = ItemStack(Material.DIAMOND_PICKAXE), - specialItem = ItemStack(Material.DIAMOND_PICKAXE).withEnchantment(Enchantment.DURABILITY, 1), + specialItem = ItemStack(Material.DIAMOND_PICKAXE).withEnchantment(Enchantment.UNBREAKING, 1), mainText = itemRewardText("Diamond Pickaxe"), specialText = ::enchantedItemText, ), diff --git a/src/drop/BlockBreakEventListener.kt b/src/drop/BlockBreakEventListener.kt index f0d420b..c4bdd0b 100644 --- a/src/drop/BlockBreakEventListener.kt +++ b/src/drop/BlockBreakEventListener.kt @@ -106,7 +106,7 @@ class BlockBreakEventListener( } private fun getWeightedActions(event: BlockBreakEvent): List> { - val playerLuck = event.player.getAttribute(Attribute.GENERIC_LUCK)?.value ?: 0.0 + val playerLuck = event.player.getAttribute(Attribute.LUCK)?.value ?: 0.0 return actions .filter { it.value.shouldTrigger(event) } .map { adjustWeight(it, playerLuck) } diff --git a/src/drop/ReplaceDropsAction.kt b/src/drop/ReplaceDropsAction.kt index 96dfd36..af536ad 100644 --- a/src/drop/ReplaceDropsAction.kt +++ b/src/drop/ReplaceDropsAction.kt @@ -25,7 +25,7 @@ class ReplaceDropsAction( event.block.type = Material.AIR event.setCancelled(true) - val item = w.spawnEntity(loc, EntityType.DROPPED_ITEM) as Item + val item = w.spawnEntity(loc, EntityType.ITEM) as Item item.itemStack = itemStack.clone() } diff --git a/src/drop/ShuffleDropsAction.kt b/src/drop/ShuffleDropsAction.kt index e501a79..be78c35 100644 --- a/src/drop/ShuffleDropsAction.kt +++ b/src/drop/ShuffleDropsAction.kt @@ -31,7 +31,7 @@ class ShuffleDropsAction( repeat(dropCount) { val itemType = types.random() - val item = w.spawnEntity(loc, EntityType.DROPPED_ITEM) as Item + val item = w.spawnEntity(loc, EntityType.ITEM) as Item item.itemStack = ItemStack(itemType, 1) } diff --git a/src/gravestone/CauseOfDeath.kt b/src/gravestone/CauseOfDeath.kt index cf4d013..2bd67a1 100644 --- a/src/gravestone/CauseOfDeath.kt +++ b/src/gravestone/CauseOfDeath.kt @@ -153,6 +153,7 @@ data class Vanilla(val cause: EntityDamageEvent.DamageCause) : CauseOfDeath { private fun inscriptionText(): String = when (cause) { EntityDamageEvent.DamageCause.BLOCK_EXPLOSION -> "TNT go boom" + EntityDamageEvent.DamageCause.CAMPFIRE -> "Hot wood" EntityDamageEvent.DamageCause.CONTACT -> "Prickly tree" EntityDamageEvent.DamageCause.CRAMMING -> "Overpopulation" EntityDamageEvent.DamageCause.CUSTOM -> "Idk" @@ -195,37 +196,54 @@ data class VanillaMob(val entityType: EntityType) : CauseOfDeath { private fun inscriptionText(): String? = when (entityType) { EntityType.AXOLOTL -> "Salamander" + EntityType.AREA_EFFECT_CLOUD -> "Big ball of smoke" + EntityType.ARMOR_STAND -> "Dress up&hurt me" EntityType.ARROW, EntityType.TRIDENT -> "Sharp rock" EntityType.BEE -> "Seinfeld" EntityType.BLAZE, EntityType.MAGMA_CUBE -> "Flamey boi" EntityType.CAVE_SPIDER, EntityType.SPIDER -> "Wall crawler" EntityType.CREEPER -> "Splodey boi" - EntityType.DRAGON_FIREBALL, EntityType.FIREBALL -> "Great balls of fire" + EntityType.DONKEY, EntityType.MULE -> "Shrek's buddy" + EntityType.DRAGON_FIREBALL, EntityType.SMALL_FIREBALL, EntityType.FIREBALL -> "Great balls of fire" EntityType.DROWNED, EntityType.ZOMBIE, EntityType.HUSK, EntityType.ZOMBIE_VILLAGER -> "Braaaaaains" EntityType.ELDER_GUARDIAN, EntityType.GUARDIAN -> "Mind games" - EntityType.ENDER_CRYSTAL -> "Shiny rock" + EntityType.END_CRYSTAL -> "Shiny rock" EntityType.ENDER_DRAGON -> "Big Bird" EntityType.ENDER_PEARL -> "Flying rock" EntityType.ENDERMAN -> "Marble Hornets" + EntityType.ENDERMITE -> "Tiny Hornets" EntityType.EVOKER, EntityType.EVOKER_FANGS, EntityType.VEX -> "Draw Four" EntityType.FALLING_BLOCK -> "The sky is falling" - EntityType.FIREWORK -> "Murica!!!" + EntityType.FIREWORK_ROCKET -> "Murica!!!" EntityType.GHAST -> "Boooooooooo" EntityType.GIANT -> "Big braaaaains" - EntityType.HOGLIN, EntityType.PIGLIN, EntityType.PIGLIN_BRUTE, EntityType.ZOGLIN, EntityType.ZOMBIFIED_PIGLIN -> "Porkchop" + EntityType.HOGLIN, EntityType.PIGLIN, EntityType.PIGLIN_BRUTE, EntityType.ZOGLIN, EntityType.ZOMBIFIED_PIGLIN, EntityType.PIG -> "Porkchop" + EntityType.HORSE, EntityType.ZOMBIE_HORSE, EntityType.SKELETON_HORSE -> "Pale rider" EntityType.SKELETON, EntityType.STRAY, EntityType.WITHER_SKELETON -> "Spooky scary" + EntityType.SHULKER, EntityType.SHULKER_BULLET -> "Bitey chest" EntityType.SILVERFISH -> "Shiny bug" + EntityType.SPECTRAL_ARROW -> "Shiny rock" EntityType.ILLUSIONER -> "Now you see him" EntityType.IRON_GOLEM -> "Nerves of steel" - EntityType.LIGHTNING -> "Divine intervention" - EntityType.LLAMA, EntityType.LLAMA_SPIT, EntityType.TRADER_LLAMA -> "Kuzco's rage" + EntityType.LIGHTNING_BOLT -> "Divine intervention" + EntityType.LLAMA, EntityType.LLAMA_SPIT, EntityType.TRADER_LLAMA, EntityType.CAMEL -> "Kuzco's rage" + EntityType.MINECART, EntityType.CHEST_MINECART, EntityType.FURNACE_MINECART, EntityType.COMMAND_BLOCK_MINECART, EntityType.HOPPER_MINECART, EntityType.SPAWNER_MINECART -> "Rollercoaster" + EntityType.TNT_MINECART -> "Boomycoaster" + EntityType.PARROT -> "Polly wanna cracker" EntityType.PHANTOM -> "Direction&magnitude" + EntityType.POLAR_BEAR, EntityType.PANDA -> "Mama bear" + EntityType.POTION -> "Magic sauce" EntityType.PUFFERFISH -> "Tears of the sky" + EntityType.RABBIT -> "Holy hand grenade" + EntityType.RAVAGER -> "Zoinks!" + EntityType.SLIME -> "Slimer" + EntityType.TNT -> "TNT go boom" EntityType.VINDICATOR, EntityType.PILLAGER -> "Raid shadow legends" EntityType.WARDEN -> "Daredevil" EntityType.WITCH -> "Bippity boppity boo" EntityType.WITHER, EntityType.WITHER_SKULL -> "Oof good luck with that" EntityType.WOLF -> "Man's best friend" + // Entities that *shouldn't* be able to damage you else -> null } diff --git a/src/jump/EncumbranceManagerFactory.kt b/src/jump/EncumbranceManagerFactory.kt index b2ad5e7..01806ed 100644 --- a/src/jump/EncumbranceManagerFactory.kt +++ b/src/jump/EncumbranceManagerFactory.kt @@ -29,8 +29,8 @@ abstract class EncumbranceManagerFactory() : FeatureContainerFactory { isIncapacitated = true } - PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, - PotionEffectType.HARM, PotionEffectType.POISON -> { + PotionEffectType.BLINDNESS, PotionEffectType.NAUSEA, + PotionEffectType.INSTANT_DAMAGE, PotionEffectType.POISON -> { isStunned = true } } diff --git a/src/pokeball/PokeballManager.kt b/src/pokeball/PokeballManager.kt index 57f7c03..779997c 100644 --- a/src/pokeball/PokeballManager.kt +++ b/src/pokeball/PokeballManager.kt @@ -67,7 +67,7 @@ class PokeballManager(plugin: Plugin) : RecipeFeature(plugin), Listener { summonItem(mob.location, ItemStack(Material.IRON_BLOCK, 6)) } // Exception: Snow golem - if (mob.type == EntityType.SNOWMAN) { + if (mob.type == EntityType.SNOW_GOLEM) { summonItem(mob.location, ItemStack(Material.SNOWBALL, 16)) } // Exception: Giant diff --git a/src/pokeball/speciesCaptureRate.kt b/src/pokeball/speciesCaptureRate.kt index d245ed1..80a1392 100644 --- a/src/pokeball/speciesCaptureRate.kt +++ b/src/pokeball/speciesCaptureRate.kt @@ -40,7 +40,7 @@ fun speciesCaptureRate(entityType: EntityType): Int = EntityType.LLAMA -> 190 EntityType.MAGMA_CUBE -> 120 EntityType.MULE -> 200 - EntityType.MUSHROOM_COW -> 210 + EntityType.MOOSHROOM -> 210 EntityType.OCELOT -> 220 EntityType.PANDA -> 240 EntityType.PARROT -> 190 @@ -61,7 +61,7 @@ fun speciesCaptureRate(entityType: EntityType): Int = EntityType.SKELETON_HORSE -> 130 EntityType.SLIME -> 150 EntityType.SNIFFER -> 220 - EntityType.SNOWMAN -> 255 + EntityType.SNOW_GOLEM -> 255 EntityType.SPIDER -> 100 EntityType.SQUID -> 255 EntityType.STRAY -> 120 diff --git a/src/pokeball/toSpawnEgg.kt b/src/pokeball/toSpawnEgg.kt index 2cb77b9..7150740 100644 --- a/src/pokeball/toSpawnEgg.kt +++ b/src/pokeball/toSpawnEgg.kt @@ -41,7 +41,7 @@ fun toSpawnEgg(entityType: EntityType): Material? = EntityType.LLAMA -> Material.LLAMA_SPAWN_EGG EntityType.MAGMA_CUBE -> Material.MAGMA_CUBE_SPAWN_EGG EntityType.MULE -> Material.MULE_SPAWN_EGG - EntityType.MUSHROOM_COW -> Material.MOOSHROOM_SPAWN_EGG + EntityType.MOOSHROOM -> Material.MOOSHROOM_SPAWN_EGG EntityType.OCELOT -> Material.OCELOT_SPAWN_EGG EntityType.PANDA -> Material.PANDA_SPAWN_EGG EntityType.PARROT -> Material.PARROT_SPAWN_EGG @@ -62,7 +62,7 @@ fun toSpawnEgg(entityType: EntityType): Material? = EntityType.SKELETON_HORSE -> Material.SKELETON_HORSE_SPAWN_EGG EntityType.SLIME -> Material.SLIME_SPAWN_EGG EntityType.SNIFFER -> Material.SNIFFER_SPAWN_EGG - EntityType.SNOWMAN -> null + EntityType.SNOW_GOLEM -> null EntityType.SPIDER -> Material.SPIDER_SPAWN_EGG EntityType.SQUID -> Material.SQUID_SPAWN_EGG EntityType.STRAY -> Material.STRAY_SPAWN_EGG diff --git a/src/rain/RainOxygenMeter.kt b/src/rain/RainOxygenMeter.kt index da77c52..d0f3613 100644 --- a/src/rain/RainOxygenMeter.kt +++ b/src/rain/RainOxygenMeter.kt @@ -84,7 +84,7 @@ class RainOxygenMeter( private fun getRespirationLevel(): Int { val helmet = player.equipment.helmet if (helmet != null) { - return helmet.getEnchantmentLevel(Enchantment.OXYGEN) + return helmet.getEnchantmentLevel(Enchantment.RESPIRATION) } else { return 0 } diff --git a/src/trivia/question/QuestionLibrary.kt b/src/trivia/question/QuestionLibrary.kt index 479c50c..fe976fd 100644 --- a/src/trivia/question/QuestionLibrary.kt +++ b/src/trivia/question/QuestionLibrary.kt @@ -610,7 +610,7 @@ object QuestionLibrary { Material.IRON_LEGGINGS, Material.IRON_HELMET, ) toRewards(armorMaterials) { - EnchantedItemReward(it.withEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 1)) + EnchantedItemReward(it.withEnchantment(Enchantment.BLAST_PROTECTION, 1)) } }, ) From 19215afa27df171ef131e0ffea590730bab870d4 Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 12:12:32 -0500 Subject: [PATCH 04/12] fix several deprecations --- src/BucketRouletteRunnable.kt | 11 +++++++---- src/cookie/TeleportToEffect.kt | 2 +- src/dripstone/Stalactite.kt | 7 +++++-- src/egg/EggHatch.kt | 5 ++++- src/spillage/SpillLiquidAndEntity.kt | 4 ++-- src/trivia/question/QuestionLibrary.kt | 3 +-- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/BucketRouletteRunnable.kt b/src/BucketRouletteRunnable.kt index ed99a12..9c5f831 100644 --- a/src/BucketRouletteRunnable.kt +++ b/src/BucketRouletteRunnable.kt @@ -29,12 +29,12 @@ class BucketRouletteRunnable(plugin: Plugin) : RunnableFeature(plugin) { return !itemMeta.hasDisplayName() } - private fun cycleBucketType(itemStack: ItemStack) { + private fun cycleBucketType(itemStack: ItemStack): ItemStack { var newBucketType = BlockTypes.BUCKETS.random() while (newBucketType == itemStack.type) { newBucketType = BlockTypes.BUCKETS.random() } - itemStack.type = newBucketType + return ItemStack(newBucketType, itemStack.amount) } } @@ -53,9 +53,12 @@ class BucketRouletteRunnable(plugin: Plugin) : RunnableFeature(plugin) { for (player in onlinePlayers) { // TODO (HACK) Kotlin can't parse the more complex nullability // annotation on getContents(), so it gets the wrong idea. - for (itemStack in player.inventory.contents!!) { + var inventoryIter = player.inventory.iterator() + while (inventoryIter.hasNext()) { + val itemStack = inventoryIter.next() if ((itemStack != null) && (shouldCycle(itemStack))) { - cycleBucketType(itemStack) + val newItemStack = cycleBucketType(itemStack) + inventoryIter.set(newItemStack) } } } diff --git a/src/cookie/TeleportToEffect.kt b/src/cookie/TeleportToEffect.kt index 8f5b357..2a6e0a3 100644 --- a/src/cookie/TeleportToEffect.kt +++ b/src/cookie/TeleportToEffect.kt @@ -43,7 +43,7 @@ abstract class TeleportToEffect(private val plugin: Plugin) : CookieEffect { override fun getTarget(player: Player): Location = // If the player doesn't have a bed spawn, use world spawn - player.getBedSpawnLocation() ?: fallback.getTarget(player) + player.getRespawnLocation() ?: fallback.getTarget(player) } diff --git a/src/dripstone/Stalactite.kt b/src/dripstone/Stalactite.kt index e463866..fdf5452 100644 --- a/src/dripstone/Stalactite.kt +++ b/src/dripstone/Stalactite.kt @@ -5,6 +5,7 @@ import org.bukkit.block.Block import org.bukkit.block.BlockFace import org.bukkit.Material import org.bukkit.Location +import org.bukkit.entity.FallingBlock import org.bukkit.block.`data`.type.PointedDripstone import com.mercerenies.turtletroll.nms.NMS @@ -88,8 +89,10 @@ data class Stalactite(val blocks: Set) { val blockData = block.block.getBlockData() as PointedDripstone val location = block.block.location.clone().add(0.5, 0.0, 0.5) block.block.type = Material.AIR - val fallingBlock = block.block.world.spawnFallingBlock(location, blockData) - NMS.makeFallingBlockHurt(fallingBlock) + block.block.world.spawn(location, FallingBlock::class.java) { fallingBlock -> + fallingBlock.setBlockData(blockData) + NMS.makeFallingBlockHurt(fallingBlock) + } } } diff --git a/src/egg/EggHatch.kt b/src/egg/EggHatch.kt index 5730297..ee1fdba 100644 --- a/src/egg/EggHatch.kt +++ b/src/egg/EggHatch.kt @@ -8,6 +8,7 @@ import org.bukkit.material.Colorable import org.bukkit.DyeColor import org.bukkit.Material import org.bukkit.plugin.Plugin +import org.bukkit.Registry import org.bukkit.inventory.ItemStack // Helper for common egg hatch effects @@ -88,7 +89,9 @@ object EggHatch { ) private fun randomizeCatData(entity: Cat) { - entity.catType = Cat.Type.values().random() + // TODO Clean this up :( + val allCatTypes = Registry.CAT_VARIANT.iterator().asSequence().toList() + entity.catType = allCatTypes.random() entity.collarColor = DyeColor.values().random() } diff --git a/src/spillage/SpillLiquidAndEntity.kt b/src/spillage/SpillLiquidAndEntity.kt index 621efe1..7981f0f 100644 --- a/src/spillage/SpillLiquidAndEntity.kt +++ b/src/spillage/SpillLiquidAndEntity.kt @@ -5,6 +5,7 @@ import org.bukkit.Material import org.bukkit.entity.EntityType import org.bukkit.entity.Entity import org.bukkit.entity.Item +import org.bukkit.inventory.ItemStack open class SpillLiquidAndEntity( val itemType: Material, @@ -16,8 +17,7 @@ open class SpillLiquidAndEntity( item.itemStack.type == itemType open fun revertItem(item: Item) { - val itemStack = item.itemStack - itemStack.type = Material.BUCKET + val itemStack = ItemStack(Material.BUCKET, item.itemStack.amount) item.itemStack = itemStack } diff --git a/src/trivia/question/QuestionLibrary.kt b/src/trivia/question/QuestionLibrary.kt index fe976fd..6fca68c 100644 --- a/src/trivia/question/QuestionLibrary.kt +++ b/src/trivia/question/QuestionLibrary.kt @@ -8,7 +8,6 @@ import com.mercerenies.turtletroll.BlockTypes import org.bukkit.Material import org.bukkit.potion.PotionType -import org.bukkit.potion.PotionData import org.bukkit.inventory.ItemStack import org.bukkit.enchantments.Enchantment import org.bukkit.inventory.`meta`.EnchantmentStorageMeta @@ -385,7 +384,7 @@ object QuestionLibrary { rewards = run { val itemStack = ItemStack(Material.POTION) val meta = itemStack.itemMeta as PotionMeta - meta.setBasePotionData(PotionData(PotionType.SLOW_FALLING)) + meta.setBasePotionType(PotionType.SLOW_FALLING) itemStack.itemMeta = meta listOf(ItemReward(itemStack)) }, From c051fe986363977fbd5fc67854939cd60893528b Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 12:32:42 -0500 Subject: [PATCH 05/12] Stalactite effect no longer requires NMS :D --- src/dripstone/Stalactite.kt | 8 ++++---- src/nms/NMS.kt | 23 ----------------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/src/dripstone/Stalactite.kt b/src/dripstone/Stalactite.kt index fdf5452..46f869e 100644 --- a/src/dripstone/Stalactite.kt +++ b/src/dripstone/Stalactite.kt @@ -8,8 +8,6 @@ import org.bukkit.Location import org.bukkit.entity.FallingBlock import org.bukkit.block.`data`.type.PointedDripstone -import com.mercerenies.turtletroll.nms.NMS - // A collection of blocks forming a stalactite of dripstone. This // class provides helpers for extending or dropping the stalactite. data class Stalactite(val blocks: Set) { @@ -90,8 +88,10 @@ data class Stalactite(val blocks: Set) { val location = block.block.location.clone().add(0.5, 0.0, 0.5) block.block.type = Material.AIR block.block.world.spawn(location, FallingBlock::class.java) { fallingBlock -> - fallingBlock.setBlockData(blockData) - NMS.makeFallingBlockHurt(fallingBlock) + fallingBlock.blockData = blockData + fallingBlock.setHurtEntities(true) + fallingBlock.damagePerBlock = 1.0f + fallingBlock.maxDamage = 40 } } } diff --git a/src/nms/NMS.kt b/src/nms/NMS.kt index 98b8117..b4d8c2b 100644 --- a/src/nms/NMS.kt +++ b/src/nms/NMS.kt @@ -80,29 +80,6 @@ object NMS { fun getClass(suffix: String): Class<*> = Class.forName("org.bukkit.craftbukkit.${version()}.${suffix}") - // Go to org.bukkit.craftbukkit.*.entity.CraftFallingBlock and look - // at the implementation of canHurtEntities(). It returns a Boolean. - // Remember the name of that Boolean (in 1.17, it's 'ap'; in 1.18 - // and 1.19.2, it's 'aq'; in 1.20.1 it's 'i'). Now go to - // net.minecraft.world.entity.item.EntityFallingBlock. There should - // be a method with signature - // - // public void ???(float, int) - // - // Which sets that variable (again, `ap` in 1.17; 'aq' in - // 1.18/1.19.2; `i` in 1.20.1) to true and sets two other variables - // to the arguments. We want to call that function (`b` in 1.17, - // 1.18, 1.19.2, and 1.20.1) with 1.0f and 40. - fun makeFallingBlockHurt(block: FallingBlock) { - safely { - val cls = getClass("entity.CraftFallingBlock") - val mcBlock = cls.getMethod("getHandle").invoke(block) - Class.forName("net.minecraft.world.entity.item.EntityFallingBlock") - .getMethod("b", java.lang.Float.TYPE, java.lang.Integer.TYPE) - .invoke(mcBlock, 1.0f, 40) - } - } - // Go to net.minecraft.world.entity.animal.allay.Allay. Find the // method with signature // From 024b52f9c1aacf2e013d5f86ce2c49af851d57ed Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 12:57:00 -0500 Subject: [PATCH 06/12] Fix versioning information and Allay summoning --- src/nms/NMS.kt | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/nms/NMS.kt b/src/nms/NMS.kt index b4d8c2b..5e98d5c 100644 --- a/src/nms/NMS.kt +++ b/src/nms/NMS.kt @@ -2,11 +2,11 @@ package com.mercerenies.turtletroll.nms import org.bukkit.Bukkit -import org.bukkit.entity.FallingBlock import org.bukkit.entity.Player import org.bukkit.entity.Allay import java.util.logging.Logger +import java.util.logging.Level // https://riptutorial.com/bukkit/example/29589/accessing-the-current-minecraft-version :) // @@ -64,7 +64,7 @@ object NMS { try { return fn() } catch (e: Exception) { - logger().severe("Error during NMS: $e") + logger().log(Level.SEVERE, "Error during NMS", e) return default } } @@ -72,13 +72,16 @@ object NMS { fun safely(fn: () -> Unit) = safely(Unit, fn) - // This should never need to change. + // As of 1.21.3, it looks like the version number doesn't exist + // anymore and we just use the base package name, which is much + // nicer. + @Deprecated("Newer Bukkit versions do not place this information in the package name anymore.") fun version(): String = - Bukkit.getServer()::class.java.getPackage().getName().substring(23) + "" // This should never need to change. fun getClass(suffix: String): Class<*> = - Class.forName("org.bukkit.craftbukkit.${version()}.${suffix}") + Class.forName("org.bukkit.craftbukkit.${suffix}") // Go to net.minecraft.world.entity.animal.allay.Allay. Find the // method with signature @@ -113,15 +116,15 @@ object NMS { val allayCls = getClass("entity.CraftAllay") val memoryModuleTypeCls = Class.forName("net.minecraft.world.entity.ai.memory.MemoryModuleType") val mcAllayCls = Class.forName("net.minecraft.world.entity.animal.allay.Allay") - val behaviorControllerCls = Class.forName("net.minecraft.world.entity.ai.BehaviorController") + val behaviorControllerCls = Class.forName("net.minecraft.world.entity.ai.Brain") val entityCls = Class.forName("net.minecraft.world.entity.player.EntityHuman") val mcPlayerEntity = playerCls.getMethod("getHandle").invoke(player) val mcAllayEntity = allayCls.getMethod("getHandle").invoke(allay) - val memoryModuleType = memoryModuleTypeCls.getField("aL").get(null) - val controller = mcAllayCls.getMethod("dK").invoke(mcAllayEntity) - val playerUuid = entityCls.getMethod("ct").invoke(mcPlayerEntity) - behaviorControllerCls.getMethod("a", memoryModuleTypeCls, Object::class.java).invoke(controller, memoryModuleType, playerUuid) + val memoryModuleType = memoryModuleTypeCls.getField("LIKED_PLAYER").get(null) + val controller = mcAllayCls.getMethod("getBrain").invoke(mcAllayEntity) + val playerUuid = entityCls.getMethod("getUUID").invoke(mcPlayerEntity) + behaviorControllerCls.getMethod("setMemory", memoryModuleTypeCls, Object::class.java).invoke(controller, memoryModuleType, playerUuid) } } From 497a59022cb5b2ba26c6605d41b633e5cbb9480b Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 12:59:18 -0500 Subject: [PATCH 07/12] Add some notes on versioning info --- src/nms/NMS.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/nms/NMS.kt b/src/nms/NMS.kt index 5e98d5c..87a3d49 100644 --- a/src/nms/NMS.kt +++ b/src/nms/NMS.kt @@ -110,6 +110,14 @@ object NMS { // and find the non-static method that takes a MemoryModuleType // and a (nullable) U. It's called a on 1.19.2/1.20.1 (and is one of // several overloads). + // + // ---- + // + // As of 1.21.3, the Allay class has been refactored. The + // EnumInteractionResult method is gone, and BehaviorController is + // now Brain. But more importantly, the methods appear to NOT be + // obfuscated, which means (maybe?) we don't have to keep updating + // this. fun setAllayFriend(allay: Allay, player: Player) { safely { val playerCls = getClass("entity.CraftPlayer") From c80faccc0242d91695b8be97cb3b6fc39f9508bf Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 14:05:10 -0500 Subject: [PATCH 08/12] Update and generic-ize some packet stuff --- src/nms/EntityMetadata.kt | 6 ++-- src/nms/NMS.kt | 52 ++++++++++++++++++------------ src/rain/RainwaterPacketUpdater.kt | 8 ++--- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/nms/EntityMetadata.kt b/src/nms/EntityMetadata.kt index fa471e1..d8bd886 100644 --- a/src/nms/EntityMetadata.kt +++ b/src/nms/EntityMetadata.kt @@ -1,11 +1,9 @@ package com.mercerenies.turtletroll.nms -interface EntityMetadata { +interface EntityMetadata { val id: Int - val serializer: Any? - var value: Any? + var value: T fun getHandle(): Any - } diff --git a/src/nms/NMS.kt b/src/nms/NMS.kt index 87a3d49..fe114ea 100644 --- a/src/nms/NMS.kt +++ b/src/nms/NMS.kt @@ -16,38 +16,39 @@ import java.util.logging.Level // alleviate that as much as possible. object NMS { - private class RawEntityMetadata( + private class RawEntityMetadataInt( private var handle: Any, - ) : EntityMetadata { + ) : EntityMetadata { // I seriously doubt these field names will change, given that // it's a Java record. But just in case: We want the integer, then // the data watcher serializer, then the T. All of these are // constructor parameters to the record type identified by // getEntityMetadataClass below. + // + // Welp, time to eat those words. Methods are named in 1.23.3, AND + // the serializer works differently now. override val id: Int get() = safely(0) { - getEntityMetadataClass().getMethod("a").invoke(handle) as Int + getEntityMetadataClass().getMethod("id").invoke(handle) as Int } - override val serializer: Any? + private val serializer: Any? get() = safely(null) { - getEntityMetadataClass().getMethod("b").invoke(handle) + getEntityMetadataClass().getMethod("serializer").invoke(handle) } - override var value: Any? + override var value: Int get() = - safely(null) { - getEntityMetadataClass().getMethod("c").invoke(handle) + safely(0) { + getEntityMetadataClass().getMethod("value").invoke(handle) as Int } set(newValue) { safely { - val serializerCls = Class.forName("net.minecraft.network.syncher.DataWatcherSerializer") - val ctor = getEntityMetadataClass().getConstructor(java.lang.Integer.TYPE, serializerCls, Object::class.java) - handle = ctor.newInstance(id, serializer, newValue) + handle = constructEntityMetadataInt(id, newValue) } } @@ -142,25 +143,34 @@ object NMS { // should match the type of elements in that list. It's // DataWatcher.b in 1.20.1. Remember to translate using the Java // naming convention, so inner class scoping is replaced with '$'. + // + // In 1.23.3, the packet has been renamed to + // ClientboundSetEntityDataPacket, and the relevant record class is + // SynchedEntityData.DataValue. fun getEntityMetadataClass(): Class<*> = - Class.forName("net.minecraft.network.syncher.DataWatcher\$b") + Class.forName("net.minecraft.network.syncher.SynchedEntityData\$DataValue") - fun getEntityMetadata(handle: Any): EntityMetadata? { + fun getEntityMetadata(handle: Any): EntityMetadata? { if (getEntityMetadataClass().isInstance(handle)) { - return RawEntityMetadata(handle) + return RawEntityMetadataInt(handle) } else { return null } } - // Go to net.minecraft.network.syncher and find the - // DataWatcherSerializer field. It's b in 1.20.1. - fun constructEntityMetadataInt(id: Int, value: Int): EntityMetadata { - val serializerCls = Class.forName("net.minecraft.network.syncher.DataWatcherSerializer") + private fun constructEntityMetadataHandle(id: Int, value: Int): Any { + val serializerCls = Class.forName("net.minecraft.network.syncher.EntityDataSerializer") val ctor = getEntityMetadataClass().getConstructor(java.lang.Integer.TYPE, serializerCls, Object::class.java) - val serializer = Class.forName("net.minecraft.network.syncher.DataWatcherRegistry").getField("b").get(null) - val handle = ctor.newInstance(id, serializer, value) - return RawEntityMetadata(handle) + val serializer = getSyncherSerializer("INT") + return ctor.newInstance(id, serializer, value) + } + + fun constructEntityMetadataInt(id: Int, value: Int): EntityMetadata = + RawEntityMetadataInt(constructEntityMetadataHandle(id, value)) + + private fun getSyncherSerializer(fieldName: String): Any? { + val serializerStaticCls = Class.forName("net.minecraft.network.syncher.EntityDataSerializers") + return serializerStaticCls.getField(fieldName).get(null) } } diff --git a/src/rain/RainwaterPacketUpdater.kt b/src/rain/RainwaterPacketUpdater.kt index 1d1bd79..847ff7b 100644 --- a/src/rain/RainwaterPacketUpdater.kt +++ b/src/rain/RainwaterPacketUpdater.kt @@ -36,8 +36,8 @@ object RainwaterPacketUpdater { for (elem in list) { if (elem != null) { val meta = NMS.getEntityMetadata(elem) - if ((meta != null) && (meta.id == ADDRESS_ID) && (meta.value is Int)) { - return meta.value as Int + if ((meta != null) && (meta.id == ADDRESS_ID)) { + return meta.value } } } @@ -51,8 +51,8 @@ object RainwaterPacketUpdater { val elem = list[idx] if (elem != null) { val meta = NMS.getEntityMetadata(elem) - if ((meta != null) && (meta.id == ADDRESS_ID) && (meta.value is Int)) { - val oldBubbleCount = meta.value as Int + if ((meta != null) && (meta.id == ADDRESS_ID)) { + val oldBubbleCount = meta.value meta.value = min(newBubbleCount, oldBubbleCount) found = true list[idx] = meta.getHandle() From 0f7cd38e83685b0755aca3a1d20c037e893a0a78 Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 14:20:07 -0500 Subject: [PATCH 09/12] Fix rainwater effect --- src/BlockTypes.kt | 2 +- src/rain/RainOxygenMeter.kt | 4 +++ src/rain/RainwaterManager.kt | 41 ++++------------------------- src/rain/RainwaterManagerFactory.kt | 10 ------- 4 files changed, 10 insertions(+), 47 deletions(-) diff --git a/src/BlockTypes.kt b/src/BlockTypes.kt index 0699a8b..e360063 100644 --- a/src/BlockTypes.kt +++ b/src/BlockTypes.kt @@ -132,7 +132,7 @@ object BlockTypes { Material.CORNFLOWER, Material.LILY_OF_THE_VALLEY, Material.WITHER_ROSE, Material.SUNFLOWER, Material.LILAC, Material.ROSE_BUSH, Material.PEONY, Material.PINK_TULIP, Material.WHITE_TULIP, Material.ORANGE_TULIP, - Material.SWEET_BERRY_BUSH, Material.TORCHFLOWER, + Material.TORCHFLOWER, ) val WOOLS = SetListAllomorph.of( diff --git a/src/rain/RainOxygenMeter.kt b/src/rain/RainOxygenMeter.kt index d0f3613..6d8ab1d 100644 --- a/src/rain/RainOxygenMeter.kt +++ b/src/rain/RainOxygenMeter.kt @@ -65,6 +65,7 @@ class RainOxygenMeter( fun runTick() { if (isInRain(player)) { + println(airAmount) if (airAmount <= 0) { dealDamage() } else { @@ -75,6 +76,9 @@ class RainOxygenMeter( } } + fun getAirFraction(): Double = + airAmount.toDouble() / MAX_AIR + fun getDesiredHudBubbleValue(): Int = getHudBubbleValue(airAmount / 2) diff --git a/src/rain/RainwaterManager.kt b/src/rain/RainwaterManager.kt index 4bfa992..6e0aeea 100644 --- a/src/rain/RainwaterManager.kt +++ b/src/rain/RainwaterManager.kt @@ -6,7 +6,6 @@ import com.mercerenies.turtletroll.util.* import com.mercerenies.turtletroll.Constants import com.mercerenies.turtletroll.gravestone.CustomDeathMessageRegistry import com.mercerenies.turtletroll.feature.RunnableFeature -import com.mercerenies.turtletroll.bridge.ProtocolLibBridge import org.bukkit.entity.Player import org.bukkit.plugin.Plugin @@ -15,51 +14,21 @@ import org.bukkit.event.Listener import org.bukkit.event.EventHandler import org.bukkit.event.entity.EntityDeathEvent -import com.comphenix.protocol.PacketType import com.comphenix.protocol.ProtocolLibrary -import com.comphenix.protocol.events.PacketAdapter -import com.comphenix.protocol.events.PacketListener -import com.comphenix.protocol.events.ListenerPriority -import com.comphenix.protocol.events.PacketEvent import kotlin.collections.HashMap +import kotlin.math.min class RainwaterManager( plugin: Plugin, private val deathRegistry: CustomDeathMessageRegistry, ) : RunnableFeature(plugin), Listener { - init { - ProtocolLibBridge.assertExists( - errorMessage = "RainwaterManager cannot be constructed without ProtocolLib", - ) - } - private val oxygenMeters: HashMap = HashMap() private fun getOxygenMeter(player: Player): RainOxygenMeter = oxygenMeters.getOrPut(player) { RainOxygenMeter(player, deathRegistry) } - val oxygenMeterPacketListener: PacketListener = object : PacketAdapter( - plugin, - ListenerPriority.NORMAL, - PacketType.Play.Server.ENTITY_METADATA, - ) { - - override fun onPacketSending(event: PacketEvent) { - if (!isEnabled()) { - return - } - val packet = event.packet - if (packet.getIntegers().read(0) as Int != event.player.getEntityId()) { - return - } - val oxygenMeter = getOxygenMeter(event.player) - RainwaterPacketUpdater.updateBubbleCount(packet, oxygenMeter.getDesiredHudBubbleValue()) - } - - } - override val name: String = "rainwater" override val description: String = "Players can drown in the rain" @@ -79,12 +48,12 @@ class RainwaterManager( val oxygenMeter = getOxygenMeter(player) if (tick == 0) { // Only do this every four times we run (approximately once - // per second). But send the packet every time we run. + // per second). But force update Minecraft every time we run. oxygenMeter.runTick() } - val bubbleValue = oxygenMeter.getDesiredHudBubbleValue() - val packet = RainwaterPacketUpdater.createBubbleCountPacket(player, bubbleValue) - protocolManager.sendServerPacket(player, packet) + val airFraction = oxygenMeter.getAirFraction() + val remainingAir = min((airFraction * player.maximumAir).toInt(), player.remainingAir) + player.remainingAir = remainingAir } } diff --git a/src/rain/RainwaterManagerFactory.kt b/src/rain/RainwaterManagerFactory.kt index a544dd2..e7b6eb8 100644 --- a/src/rain/RainwaterManagerFactory.kt +++ b/src/rain/RainwaterManagerFactory.kt @@ -1,14 +1,11 @@ package com.mercerenies.turtletroll.rain -import com.mercerenies.turtletroll.TurtleTrollPlugin import com.mercerenies.turtletroll.feature.container.FeatureContainer -import com.mercerenies.turtletroll.feature.container.NullFeatureContainer import com.mercerenies.turtletroll.feature.builder.FeatureBuilder import com.mercerenies.turtletroll.feature.builder.BuilderState import com.mercerenies.turtletroll.feature.builder.FeatureContainerFactory import com.mercerenies.turtletroll.gravestone.CustomDeathMessageRegistry -import com.mercerenies.turtletroll.bridge.ProtocolLibBridge import org.bukkit.Bukkit @@ -23,18 +20,11 @@ class RainwaterManagerFactory( Bukkit.getLogger().warning("Could not find death registry, got null") deathRegistry = CustomDeathMessageRegistry.Unit } - if (!ProtocolLibBridge.exists()) { - if (!state.config.getBoolean(TurtleTrollPlugin.SUPPRESS_PROTOCOLLIB_WARNING)) { - Bukkit.getLogger().warning("Cannot construct `rainwater` feature without ProtocolLib") - } - return NullFeatureContainer - } val manager = RainwaterManager(state.plugin, deathRegistry) return FeatureBuilder() .addListener(manager) .addFeature(manager) .addGameModification(manager) - .addPacketListener(manager.oxygenMeterPacketListener) .build() } From 03fde5162a058e547d488ea6070506bf90687447 Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 14:20:15 -0500 Subject: [PATCH 10/12] Fix allay using extra item --- src/AllayManager.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/AllayManager.kt b/src/AllayManager.kt index 069a692..cb5a09e 100644 --- a/src/AllayManager.kt +++ b/src/AllayManager.kt @@ -13,9 +13,7 @@ import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.entity.EntitySpawnEvent import org.bukkit.potion.PotionEffectType -import org.bukkit.entity.Entity import org.bukkit.entity.Allay -import org.bukkit.entity.Player import org.bukkit.plugin.Plugin import org.bukkit.inventory.ItemStack import org.bukkit.Bukkit From e60d2bf9d10dd81cf55a8deca03eb85a76570054 Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 14:26:07 -0500 Subject: [PATCH 11/12] Clean up RainOxygenMeter slightly --- src/rain/RainOxygenMeter.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/rain/RainOxygenMeter.kt b/src/rain/RainOxygenMeter.kt index 6d8ab1d..884b8ba 100644 --- a/src/rain/RainOxygenMeter.kt +++ b/src/rain/RainOxygenMeter.kt @@ -77,10 +77,9 @@ class RainOxygenMeter( } fun getAirFraction(): Double = - airAmount.toDouble() / MAX_AIR - - fun getDesiredHudBubbleValue(): Int = - getHudBubbleValue(airAmount / 2) + // Subtracting 0.25 here seems to make the UI less flickery for + // whatever reason. It's still flickery, mind, just less so. + (airAmount.toDouble() - 0.25) / MAX_AIR private fun hasWaterBreathing(): Boolean = player.getPotionEffect(PotionEffectType.WATER_BREATHING) != null From ae955a855993037736aa221d23555c3c85635b1a Mon Sep 17 00:00:00 2001 From: Silvio Mayolo Date: Fri, 17 Jan 2025 14:32:54 -0500 Subject: [PATCH 12/12] remove a bunch of unused code --- README.md | 9 ++-- src/bridge/ProtocolLibBridge.kt | 3 ++ src/nms/EntityMetadata.kt | 9 ---- src/nms/NMS.kt | 79 ------------------------------ src/rain/RainwaterPacketUpdater.kt | 78 ----------------------------- 5 files changed, 8 insertions(+), 170 deletions(-) delete mode 100644 src/nms/EntityMetadata.kt delete mode 100644 src/rain/RainwaterPacketUpdater.kt diff --git a/README.md b/README.md index cdbce2c..76689ae 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,6 @@ A Turtle's Troll also provides integrations with a few other plugins. None of these are required, but some features may be unavailable if these dependencies are not present. -* [ProtocolLib](https://www.spigotmc.org/resources/protocollib.1997/) - is required for the `rainwater` feature. If ProtocolLib is not - present, this feature will be disabled. * [Raccoon-Mischief](https://github.com/EvanSkiStudios/Raccoon-Mischief) is recommended for interoperation with several features. Nothing strictly requires this plugin to be present, but many things either @@ -49,7 +46,11 @@ these dependencies are not present. ### Version 1.25 -* Random events that apply to players do not fire if there are no players online (currently this is all random events, though in the future there may be events that make sense with no players) +* A Turtle's Troll has been updated to run in Minecraft 1.21.3. +* The `rainwater` effect no longer depends on ProtocolLib and will + work out-of-the-box. +* Random events that apply to players do not fire if there are no players online (currently this is all random events, though in the future there may be events that make sense with no players). +* The allay's flower pool has been adjusted to prevent bugs. ### Version 1.24.2 diff --git a/src/bridge/ProtocolLibBridge.kt b/src/bridge/ProtocolLibBridge.kt index 554d86f..14836f2 100644 --- a/src/bridge/ProtocolLibBridge.kt +++ b/src/bridge/ProtocolLibBridge.kt @@ -4,6 +4,9 @@ package com.mercerenies.turtletroll.bridge import com.comphenix.protocol.ProtocolLibrary import com.comphenix.protocol.ProtocolManager +// As of 1.23.3, we don't use ProtocolLib for anything (since +// `rainwater` is available in stock Bukkit now). But this class still +// exists, in case we need it for something ridiculous down the road. object ProtocolLibBridge : PluginBridge() { override val pluginName = "ProtocolLib" diff --git a/src/nms/EntityMetadata.kt b/src/nms/EntityMetadata.kt deleted file mode 100644 index d8bd886..0000000 --- a/src/nms/EntityMetadata.kt +++ /dev/null @@ -1,9 +0,0 @@ - -package com.mercerenies.turtletroll.nms - -interface EntityMetadata { - val id: Int - var value: T - - fun getHandle(): Any -} diff --git a/src/nms/NMS.kt b/src/nms/NMS.kt index fe114ea..9607b98 100644 --- a/src/nms/NMS.kt +++ b/src/nms/NMS.kt @@ -15,48 +15,6 @@ import java.util.logging.Level // version (1.19), then it's going to be a pain. Hopefully I can // alleviate that as much as possible. object NMS { - - private class RawEntityMetadataInt( - private var handle: Any, - ) : EntityMetadata { - - // I seriously doubt these field names will change, given that - // it's a Java record. But just in case: We want the integer, then - // the data watcher serializer, then the T. All of these are - // constructor parameters to the record type identified by - // getEntityMetadataClass below. - // - // Welp, time to eat those words. Methods are named in 1.23.3, AND - // the serializer works differently now. - - override val id: Int - get() = - safely(0) { - getEntityMetadataClass().getMethod("id").invoke(handle) as Int - } - - private val serializer: Any? - get() = - safely(null) { - getEntityMetadataClass().getMethod("serializer").invoke(handle) - } - - override var value: Int - get() = - safely(0) { - getEntityMetadataClass().getMethod("value").invoke(handle) as Int - } - set(newValue) { - safely { - handle = constructEntityMetadataInt(id, newValue) - } - } - - override fun getHandle(): Any = - handle - - } - fun logger(): Logger = Bukkit.getLogger() @@ -136,41 +94,4 @@ object NMS { behaviorControllerCls.getMethod("setMemory", memoryModuleTypeCls, Object::class.java).invoke(controller, memoryModuleType, playerUuid) } } - - // Go to - // net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata. - // Look for a private final field of List type. This class name - // should match the type of elements in that list. It's - // DataWatcher.b in 1.20.1. Remember to translate using the Java - // naming convention, so inner class scoping is replaced with '$'. - // - // In 1.23.3, the packet has been renamed to - // ClientboundSetEntityDataPacket, and the relevant record class is - // SynchedEntityData.DataValue. - fun getEntityMetadataClass(): Class<*> = - Class.forName("net.minecraft.network.syncher.SynchedEntityData\$DataValue") - - fun getEntityMetadata(handle: Any): EntityMetadata? { - if (getEntityMetadataClass().isInstance(handle)) { - return RawEntityMetadataInt(handle) - } else { - return null - } - } - - private fun constructEntityMetadataHandle(id: Int, value: Int): Any { - val serializerCls = Class.forName("net.minecraft.network.syncher.EntityDataSerializer") - val ctor = getEntityMetadataClass().getConstructor(java.lang.Integer.TYPE, serializerCls, Object::class.java) - val serializer = getSyncherSerializer("INT") - return ctor.newInstance(id, serializer, value) - } - - fun constructEntityMetadataInt(id: Int, value: Int): EntityMetadata = - RawEntityMetadataInt(constructEntityMetadataHandle(id, value)) - - private fun getSyncherSerializer(fieldName: String): Any? { - val serializerStaticCls = Class.forName("net.minecraft.network.syncher.EntityDataSerializers") - return serializerStaticCls.getField(fieldName).get(null) - } - } diff --git a/src/rain/RainwaterPacketUpdater.kt b/src/rain/RainwaterPacketUpdater.kt deleted file mode 100644 index 847ff7b..0000000 --- a/src/rain/RainwaterPacketUpdater.kt +++ /dev/null @@ -1,78 +0,0 @@ - -package com.mercerenies.turtletroll.rain - -import com.mercerenies.turtletroll.nms.NMS - -import com.comphenix.protocol.events.PacketContainer -import com.comphenix.protocol.reflect.EquivalentConverter -import com.comphenix.protocol.PacketType - -import org.bukkit.entity.Entity - -import kotlin.math.min - -object RainwaterPacketUpdater { - - object TrivialConverter : EquivalentConverter { - - override fun getGeneric(specific: Any?): Any? = - specific - - override fun getSpecific(generic: Any?): Any? = - generic - - // We need Class for the type. Java doesn't care about - // nullability, so Class is good enough. - @Suppress("UNCHECKED_CAST") - override fun getSpecificType(): Class = - Any::class.java as Class - - } - - private val ADDRESS_ID: Int = 1 - - fun getBubbleCount(packet: PacketContainer): Int? { - val list = packet.getLists(TrivialConverter).read(0) - for (elem in list) { - if (elem != null) { - val meta = NMS.getEntityMetadata(elem) - if ((meta != null) && (meta.id == ADDRESS_ID)) { - return meta.value - } - } - } - return null - } - - fun updateBubbleCount(packet: PacketContainer, newBubbleCount: Int) { - val list = packet.getLists(TrivialConverter).read(0) - var found = false - for (idx in list.indices) { - val elem = list[idx] - if (elem != null) { - val meta = NMS.getEntityMetadata(elem) - if ((meta != null) && (meta.id == ADDRESS_ID)) { - val oldBubbleCount = meta.value - meta.value = min(newBubbleCount, oldBubbleCount) - found = true - list[idx] = meta.getHandle() - } - } - } - // If this packet did not contain a bubble count, append it onto - // the end. - if (!found) { - list.add(NMS.constructEntityMetadataInt(ADDRESS_ID, newBubbleCount).getHandle()) - } - packet.getLists(TrivialConverter).write(0, list) - } - - fun createBubbleCountPacket(entity: Entity, bubbleCount: Int): PacketContainer { - val packet = PacketContainer(PacketType.Play.Server.ENTITY_METADATA) - packet.getModifier().write(0, entity.getEntityId()) - val lst = listOf(NMS.constructEntityMetadataInt(ADDRESS_ID, bubbleCount).getHandle()) - packet.getModifier().write(1, lst) - return packet - } - -}