[SPIGOT-2964] PrepareItemEnchantEvent#getEnchantmentBonus always returns 3 Created: 26/Dec/16  Updated: 27/Dec/16  Resolved: 27/Dec/16

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Jikoo Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: craftbukkit, enchantment


 Description   

Since the recent enchantment changes, the number of shelves offered by the PrepareItemEnchantEvent is incorrect and must be manually checked.

The issue is in the patch for ContainerEnchantTable - rather than iterate over a new or safe integer for the quantity of buttons, the quantity of shelves is overwritten. It appears that the variable i (quantity of shelves) was mistakenly used instead of j.

Test plugin:

    @EventHandler
    public void onPrepareItemEnchant(PrepareItemEnchantEvent event) {
        Bukkit.broadcastMessage(String.valueOf(event.getEnchantmentBonus()));
    }

Current code (L74-77):

                    for (i = 0; i < 3; ++i) {
                        org.bukkit.enchantments.Enchantment enchantment = (this.h[i] >= 0) ? org.bukkit.enchantments.Enchantment.getById(this.h[i]) : null;
                        offers[i] = ((enchantment != null) ? new EnchantmentOffer(enchantment, this.i[i], this.costs[i]) : null);
                    }

Proposed fix:

                    for (j = 0; j < 3; ++j) {
                        org.bukkit.enchantments.Enchantment enchantment = (this.h[j] >= 0) ? org.bukkit.enchantments.Enchantment.getById(this.h[j]) : null;
                        offers[j] = ((enchantment != null) ? new EnchantmentOffer(enchantment, this.i[j], this.costs[j]) : null);
                    }

Generated at Tue Apr 22 06:49:49 UTC 2025 using Jira 10.3.5#10030005-sha1:190c783f2bd6c69cd5accdb70f97e48812a78d14.