enchantments) > 0; } public function hasEnchantment(Enchantment $enchantment, int $level = -1) : bool{ $id = spl_object_id($enchantment); return isset($this->enchantments[$id]) && ($level === -1 || $this->enchantments[$id]->getLevel() === $level); } public function getEnchantment(Enchantment $enchantment) : ?EnchantmentInstance{ return $this->enchantments[spl_object_id($enchantment)] ?? null; } /** * @return $this */ public function removeEnchantment(Enchantment $enchantment, int $level = -1) : self{ $instance = $this->getEnchantment($enchantment); if($instance !== null && ($level === -1 || $instance->getLevel() === $level)){ unset($this->enchantments[spl_object_id($enchantment)]); } return $this; } /** * @return $this */ public function removeEnchantments() : self{ $this->enchantments = []; return $this; } /** * @return $this */ public function addEnchantment(EnchantmentInstance $enchantment) : self{ $this->enchantments[spl_object_id($enchantment->getType())] = $enchantment; return $this; } /** * @return EnchantmentInstance[] */ public function getEnchantments() : array{ return $this->enchantments; } /** * Returns the level of the enchantment on this item with the specified ID, or 0 if the item does not have the * enchantment. */ public function getEnchantmentLevel(Enchantment $enchantment) : int{ return ($instance = $this->getEnchantment($enchantment)) !== null ? $instance->getLevel() : 0; } }