diff --git a/gradle.properties b/gradle.properties index 1fbb0432..7b21ada0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 4.1.4 b73 +version = 4.1.4 b74 description = The Ultimate RPG Mob Levelling Solution \ No newline at end of file diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsParser.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsParser.kt index 7770502e..0e68f558 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsParser.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/customdrops/CustomDropsParser.kt @@ -22,8 +22,6 @@ import java.util.Locale import java.util.SortedMap import java.util.TreeMap import org.bukkit.Material -import org.bukkit.NamespacedKey -import org.bukkit.Registry import org.bukkit.command.CommandSender import org.bukkit.configuration.ConfigurationSection import org.bukkit.configuration.MemorySection @@ -708,17 +706,15 @@ class CustomDropsParser( if (value is LinkedHashMap<*, *>) { // contains enchantment chances - val en = Registry.ENCHANTMENT.get( - NamespacedKey.minecraft(enchantName.lowercase(Locale.getDefault())) - ) + val enchantment = Utils.getEnchantment(enchantName) - if (en == null) { + if (enchantment == null) { hadError("Invalid enchantment: $enchantName") continue } val enchantments = value as MutableMap - parseEnchantmentChances(en, enchantments, item) + parseEnchantmentChances(enchantment, enchantments, item) continue } @@ -726,18 +722,17 @@ class CustomDropsParser( if (value != null && Utils.isInteger(value.toString())) enchantLevel = value.toString().toInt() - val en = Registry.ENCHANTMENT.get( - NamespacedKey.minecraft(enchantName.lowercase(Locale.getDefault())) - ) - if (en != null) { + val enchantment = Utils.getEnchantment(enchantName) + + if (enchantment != null) { if (item.material == Material.ENCHANTED_BOOK) { val meta = item.itemStack ?.itemMeta as EnchantmentStorageMeta - meta.addStoredEnchant(en, enchantLevel, true) + meta.addStoredEnchant(enchantment, enchantLevel, true) item.itemStack!!.setItemMeta(meta) } else - item.itemStack!!.addUnsafeEnchantment(en, enchantLevel) + item.itemStack!!.addUnsafeEnchantment(enchantment, enchantLevel) } else hadError("Invalid enchantment: $enchantName") @@ -1205,15 +1200,17 @@ class CustomDropsParser( sb.append(enchantmentLevels) } + // enchantment info here if (item.itemStack != null) { - val meta = item.itemStack!!.itemMeta + val itemStack = item.itemStack!! + val meta = itemStack.itemMeta val sb2 = StringBuilder() if (meta != null) { for (enchant in meta.enchants.keys) { if (sb2.isNotEmpty()) sb2.append(", ") sb2.append( - "&b${enchant.key.key}&r (${item.itemStack!!.itemMeta.enchants[enchant]})", enchant.key.key + "&b${enchant.key.key}&r (${itemStack.itemMeta.enchants[enchant]})" ) } } diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt index b507dd5b..f249867f 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/managers/LevelManager.kt @@ -136,27 +136,73 @@ class LevelManager : LevelInterface2 { this.forcedBlockedEntityTypes.addAll( mutableListOf( - EntityType.AREA_EFFECT_CLOUD, EntityType.ARMOR_STAND, EntityType.ARROW, - EntityType.DRAGON_FIREBALL, EntityType.ITEM_DISPLAY, EntityType.EGG, - EntityType.END_CRYSTAL, - EntityType.ENDER_PEARL, EntityType.EYE_OF_ENDER, EntityType.EXPERIENCE_ORB, + EntityType.AREA_EFFECT_CLOUD, + EntityType.ARMOR_STAND, + EntityType.ARROW, + EntityType.DRAGON_FIREBALL, + EntityType.EGG, + mapLegacyEntityTypeName("ENDER_CRYSTAL"), + EntityType.ENDER_PEARL, + mapLegacyEntityTypeName("ENDER_SIGNAL"), + EntityType.EXPERIENCE_ORB, EntityType.FALLING_BLOCK, - EntityType.FIREBALL, EntityType.FIREWORK_ROCKET, EntityType.FISHING_BOBBER, - EntityType.ITEM_FRAME, EntityType.LEASH_KNOT, EntityType.LIGHTNING_BOLT, + EntityType.FIREBALL, + mapLegacyEntityTypeName("FIREWORK"), + mapLegacyEntityTypeName("FISHING_HOOK"), + EntityType.ITEM_FRAME, + mapLegacyEntityTypeName("LEASH_HITCH"), + mapLegacyEntityTypeName("LIGHTNING"), EntityType.LLAMA_SPIT, - EntityType.MINECART, EntityType.CHEST_MINECART, EntityType.COMMAND_BLOCK_MINECART, - EntityType.FURNACE_MINECART, - EntityType.HOPPER_MINECART, EntityType.SPAWNER_MINECART, EntityType.TNT_MINECART, + EntityType.MINECART, + mapLegacyEntityTypeName("MINECART_CHEST"), + mapLegacyEntityTypeName("MINECART_COMMAND"), + mapLegacyEntityTypeName("MINECART_FURNACE"), + mapLegacyEntityTypeName("MINECART_HOPPER"), + mapLegacyEntityTypeName("MINECART_MOB_SPAWNER"), + mapLegacyEntityTypeName("MINECART_TNT"), EntityType.PAINTING, - EntityType.TNT, EntityType.SMALL_FIREBALL, EntityType.SNOWBALL, + mapLegacyEntityTypeName("PRIMED_TNT"), + EntityType.SMALL_FIREBALL, + EntityType.SNOWBALL, EntityType.SPECTRAL_ARROW, - EntityType.POTION, EntityType.EXPERIENCE_BOTTLE, EntityType.TRIDENT, + mapLegacyEntityTypeName("SPLASH_POTION"), + mapLegacyEntityTypeName("THROWN_EXP_BOTTLE"), + EntityType.TRIDENT, EntityType.UNKNOWN, - EntityType.WITHER_SKULL, EntityType.SHULKER_BULLET, EntityType.PLAYER + EntityType.WITHER_SKULL, + EntityType.SHULKER_BULLET, + EntityType.PLAYER ) ) } + private fun mapLegacyEntityTypeName( + name: String + ): EntityType{ + return if (LevelledMobs.instance.ver.minorVersion >= 21){ + when (name){ + "ENDER_CRYSTAL" -> EntityType.END_CRYSTAL + "ENDER_SIGNAL" -> EntityType.EYE_OF_ENDER + "FIREWORK" -> EntityType.FIREWORK_ROCKET + "FISHING_HOOK" -> EntityType.FISHING_BOBBER + "LEASH_HITCH" -> EntityType.LEASH_KNOT + "LIGHTNING" -> EntityType.LIGHTNING_BOLT + "MINECART_CHEST" -> EntityType.CHEST_MINECART + "MINECART_COMMAND" -> EntityType.COMMAND_BLOCK_MINECART + "MINECART_FURNACE" -> EntityType.FURNACE_MINECART + "MINECART_HOPPER" -> EntityType.HOPPER_MINECART + "MINECART_MOB_SPAWNER" -> EntityType.SPAWNER_MINECART + "MINECART_TNT" -> EntityType.TNT_MINECART + "PRIMED_TNT" -> EntityType.TNT + "SPLASH_POTION" -> EntityType.POTION + "THROWN_EXP_BOTTLE" -> EntityType.EXPERIENCE_BOTTLE + else -> EntityType.UNKNOWN + } + } + else + EntityType.valueOf(name) + } + /** * This method generates a level for the mob. It utilises the levelling mode specified by the * administrator through the settings.yml configuration. @@ -1976,7 +2022,7 @@ class LevelManager : LevelInterface2 { if (lmEntity.livingEntity is Zombie) attribs.add(Addition.ATTRIBUTE_ZOMBIE_SPAWN_REINFORCEMENTS) - else if (lmEntity.livingEntity is Horse) + else if (main.ver.minorVersion >= 20 && lmEntity.livingEntity is Horse) attribs.add(Addition.ATTRIBUTE_HORSE_JUMP_STRENGTH) main.levelManager.applyLevelledAttributes(lmEntity, attribs, nbtDatas) diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt index 649f9f21..0ba279df 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/rules/RulesParser.kt @@ -28,6 +28,8 @@ import io.github.arcaneplugins.levelledmobs.rules.strategies.YDistanceStrategy import io.github.arcaneplugins.levelledmobs.util.Log import io.github.arcaneplugins.levelledmobs.util.Utils.isDouble import io.github.arcaneplugins.levelledmobs.util.Utils.isInteger +import io.papermc.paper.registry.RegistryAccess +import io.papermc.paper.registry.RegistryKey import org.bukkit.NamespacedKey import org.bukkit.Particle import org.bukkit.Registry @@ -351,7 +353,21 @@ class RulesParser { if (input.isEmpty()) continue val namespace = if (input.size == 1) NamespacedKey.MINECRAFT_NAMESPACE else input[0] val key = if (input.size == 1) input[0].lowercase() else input[1].lowercase() - val structure = Registry.STRUCTURE.get(NamespacedKey(namespace, key)) + val structure: Structure? + + if (LevelledMobs.instance.ver.isRunningPaper && LevelledMobs.instance.ver.minorVersion >= 21){ + val registry = RegistryAccess.registryAccess().getRegistry( + RegistryKey.STRUCTURE + ) + structure = registry.get( + NamespacedKey.minecraft(key.lowercase(Locale.getDefault())) + ) + } + else{ + // legacy versions < 1.21 + @Suppress("DEPRECATION") + structure = Registry.STRUCTURE.get(NamespacedKey(namespace, key)) + } if (structure == null) Log.war("Invalid $invalidWord ${mlpi.itemName}: $item") diff --git a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/Utils.kt b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/Utils.kt index d8184e27..8da7fa61 100644 --- a/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/Utils.kt +++ b/levelledmobs-plugin/src/main/kotlin/io/github/arcaneplugins/levelledmobs/util/Utils.kt @@ -15,12 +15,17 @@ import io.github.arcaneplugins.levelledmobs.result.PlayerNetherOrWorldSpawnResul import io.github.arcaneplugins.levelledmobs.rules.MinAndMax import io.github.arcaneplugins.levelledmobs.rules.RulesManager import io.github.arcaneplugins.levelledmobs.wrappers.LivingEntityWrapper +import io.papermc.paper.registry.RegistryAccess +import io.papermc.paper.registry.RegistryKey import org.bukkit.Chunk import org.bukkit.GameMode import org.bukkit.Location +import org.bukkit.NamespacedKey +import org.bukkit.Registry import org.bukkit.World import org.bukkit.block.Biome import org.bukkit.command.CommandSender +import org.bukkit.enchantments.Enchantment import org.bukkit.entity.Entity import org.bukkit.entity.LivingEntity import org.bukkit.entity.Player @@ -592,4 +597,29 @@ object Utils { return results } + + fun getEnchantment( + enchantName: String + ): Enchantment?{ + val enchantment: Enchantment? + val ver = LevelledMobs.instance.ver + + if (ver.isRunningPaper && ver.minorVersion >= 21){ + val registry = RegistryAccess.registryAccess().getRegistry( + RegistryKey.ENCHANTMENT + ) + enchantment = registry.get( + NamespacedKey.minecraft(enchantName.lowercase(Locale.getDefault())) + ) + } + else{ + // legacy versions < 1.21 + @Suppress("DEPRECATION") + enchantment = Registry.ENCHANTMENT.get( + NamespacedKey.minecraft(enchantName.lowercase(Locale.getDefault())) + ) + } + + return enchantment + } } \ No newline at end of file