瀏覽代碼

Fix enchanted books not being created with the proper data

nossr50 5 年之前
父節點
當前提交
aed4cb87be
共有 2 個文件被更改,包括 8 次插入3 次删除
  1. 2 0
      Changelog.txt
  2. 6 3
      src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java

+ 2 - 0
Changelog.txt

@@ -1,9 +1,11 @@
 Version 2.1.165
+    Fixed a bug where Enchanted Books dropped by mcMMO (in Fishing) did not function correctly
     The mcMMO system which tracks player placed blocks has had some major rewrites (thanks t00thpick1)
     mcMMO will now be compatible with changes to world height (1.17 compatibility)
     Added missing cooldown locale message 'Commands.Database.Cooldown'
 
     NOTES:
+    Books dropped before this fix will not be usable and should just be chucked in lava, the broken books have blue names, the working books have yellow names.
     t00thpick1 has taken time to rewrite our block meta tracking system to be more efficient, easier to maintain, and support upcoming features such as world height changes
     This new system is compatible with the old one, it will convert old files to the new format as needed.
     This update shouldn't break anything as the API is the same

+ 6 - 3
src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java

@@ -37,6 +37,7 @@ import org.bukkit.entity.*;
 import org.bukkit.event.entity.EntityDamageEvent;
 import org.bukkit.inventory.ItemStack;
 import org.bukkit.inventory.PlayerInventory;
+import org.bukkit.inventory.meta.EnchantmentStorageMeta;
 import org.bukkit.inventory.meta.ItemMeta;
 import org.bukkit.inventory.meta.SkullMeta;
 import org.bukkit.util.BoundingBox;
@@ -466,11 +467,13 @@ public class FishingManager extends SkillManager {
         EnchantmentWrapper enchantmentWrapper = getRandomEnchantment(fishingTreasureBook.getLegalEnchantments());
         ItemMeta itemMeta = itemStack.getItemMeta();
 
-        if(itemMeta == null)
+        if(itemMeta == null) {
             return itemStack;
+        }
 
-        itemMeta.addEnchant(enchantmentWrapper.getEnchantment(), enchantmentWrapper.getEnchantmentLevel(), ExperienceConfig.getInstance().allowUnsafeEnchantments());
-        itemStack.setItemMeta(itemMeta);
+        EnchantmentStorageMeta enchantmentStorageMeta = (EnchantmentStorageMeta) itemMeta;
+        enchantmentStorageMeta.addStoredEnchant(enchantmentWrapper.getEnchantment(), enchantmentWrapper.getEnchantmentLevel(), ExperienceConfig.getInstance().allowUnsafeEnchantments());
+        itemStack.setItemMeta(enchantmentStorageMeta);
         return itemStack;
     }