Skip to content

Commit

Permalink
v4.1.4 b75
Browse files Browse the repository at this point in the history
* fix Minecraft versions older than 1.21 broken since b73
* use new Paper 1.21 APIs for enchantments and structures
* improve custom drops debug message when enchantments are used
  • Loading branch information
stumper66 committed Nov 7, 2024
1 parent c0b0e0b commit db5d3cf
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 30 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 4.1.4 b73
version = 4.1.4 b74
description = The Ultimate RPG Mob Levelling Solution
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -708,36 +706,33 @@ 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<Any, Any>
parseEnchantmentChances(en, enchantments, item)
parseEnchantmentChances(enchantment, enchantments, item)
continue
}

var enchantLevel = 1
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")
Expand Down Expand Up @@ -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]})"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}

0 comments on commit db5d3cf

Please sign in to comment.