Update 1.4.0
Hi guys, this update is a big cleanup pass. I went through the whole plugin looking for slow code, and along the way I found 16 bugs, some of them pretty old. Everything is fixed in this release.
Tested on Minecraft 26.2. Please back up your plugins/CustomEnchantments3 folder before updating, and let me know if anything acts up in the discussions page.
Read this first
If you use /ce reload, your players' RACO balances were being wiped every time. The reload code was looking in the wrong file for the saved balances, found nothing, and reset everyone to 0. The next save then wrote that back to disk. This is fixed, but any balance already lost is gone. Restarting the server was never affected, only /ce reload.
Seven fixes change gameplay. Full list further down under "Balance changes". Nothing else in this update should be noticeable in play.
Performance
This was the main reason for the update. Custom enchantments are stored as JSON on the item, and the plugin was re-reading and re-parsing that JSON far more often than it needed to.
One example: a single sword hit was costing several hundred JSON parses, because every attack and defence handler built its own player object and each of those read the main hand, the off hand and all four armor pieces twice over. That is down to a handful now.
- Enchantment reads no longer allocate a JSON parser, a reflection object and a key on every single call
- Player data is loaded when it is actually needed instead of up front
- Enchantment name lookups are a map lookup instead of scanning all 58 every time
- Server version checks are cached instead of re-parsing the version string, this one was being called twice per step inside 360-step particle loops
- PlayerMoveEvent, the busiest event on any server, no longer reads your boots several times per tick
- Block breaking with Deforestation was quadratic on large trees, now it is not
- Loot plot generation used to scan around 4.5 million blocks on the main thread, twice. It now reads chunk block entity lists instead
Memory leaks fixed:
- A permission object was being stacked on the player on every single /ce command and never removed
- The currency exchange screen kept refreshing once a second forever, for every player who had ever opened it, even after they logged off
- The world list grew forever, and gained another background task on every reload
- Decorative particle drops (blood, gold nuggets) were added to a list that was never cleaned up and searched on every item pickup on the map
- There was no logout handler at all, so per-player data piled up until restart
Bug fixes
- Dummy shops could be killed. The damage readout worked, but with melee the hit also landed for real, so a decent weapon just killed the dummy. Fire, lava, fall damage, explosions and mobs could kill one too. Dummies are properly protected now, the same as every other shop entity
- /ce reload wiped all RACO balances. Read the warning above
- Armor enchantments ignored CustomEnchantsWorld. Tank, Magic Resist, Regain, Freeze, Thorns, Mana Shield, Sturdy, Omni Vamp and Blindness all kept working in worlds where the plugin is supposed to be off. Weapon enchantments were checking correctly, so the two halves disagreed
- PENETRATION did nothing at all. The warrior passive was writing the wrong stat, onto an object that got thrown away immediately
- Protected boundaries were not blocking mob spawns. The check was backwards, it only blocked spawns in worlds where the plugin was disabled
- Loot plots almost never spawned. The "is there a bed nearby" check also matched BEDROCK, and the search box reaches 80 blocks below you, so most attempts got rejected on sight
- Offline shop sales lost money. If you sold two items while offline you were only paid for the second one
- LightSpiritManaCost in config.yml did nothing. The Lightning cost was being written over the top of it
- Several 1.21.x versions were treated as unsupported. 1.21, 1.21.0, 1.21.2, 1.21.3, 1.21.6, 1.21.7 and 1.21.9 fell through the version check, which quietly turned off anything version-gated. Version checks are numeric now
- The last treasure item could never drop. "Ancient Netherite Scrap" was unobtainable, and "Lucky Treasure" was dropping at double the intended rate
- Empty loot rarity lists crashed chest generation. If LootItems.yml had no item of some rarity, chest generation broke for the whole world once that rarity rolled
- Shops in another world could break commands. Distance checks against shops in a different world threw an error and aborted the whole handler
- Three background tasks were reading player inventories and writing mana from async threads, which is not safe with the Bukkit API. All moved to the main thread
- /ce settings protection list was doing millions of pointless allocations to build a list it then threw away
Balance changes
These are the ones your players may notice:
- PENETRATION now works. Warriors ignore 0.5% of physical defence per level, 5% at level 10
- Armor enchantments stop working in worlds not listed in CustomEnchantsWorld. Only affects you if you actually restrict the plugin to specific worlds. The default empty list means all worlds, so most servers see no change
- Hostile mobs no longer spawn inside protected boundaries, which is what the feature was always meant to do
- Loot plots will actually generate now, including underground. If that turns out to be too often for your taste, turn LootPlotSpawnChance down. Trapped chests also count as player building now, so plots avoid them
- Light Spirit's mana cost drops from 12.5 to 10 with the default config, it is reading LightSpiritManaCost properly now. Lightning is unchanged, but its shop description was showing the wrong number and now shows the right one
- "Ancient Netherite Scrap" is obtainable and "Lucky Treasure" drops at a normal rate
- Dummies do not die and no longer get knocked around. They still flash when you hit them and still show the damage number, they just stay put now
Worth testing
If you can, please check these and report anything odd:
- Hitting a dummy shop with your strongest weapon, it should survive and still show the damage
- Melee combat against players wearing enchanted armor
- Mob spawning inside a protected boundary
- Light Spirit mana usage
- /ce reload, then check a player's RACO balance is still there
- Loot plot generation, if you have GenerateLootPlots: true
No features were added or removed in this update.