0

How to convert String to (custom Type) Enchantment? Following code alerts "Type mismatch: cannot convert from String to Enchantment"

String s = "DAMAGE_ALL.2";
String[] enchantINFO = s.split(".");

Enchantment enchantTYPE = enchantINFO[0]; //TODO Type mismatch: cannot convert from String to Enchantment
int enchantLVL = enchantINFO[1];

player.getItemInHand().addEnchantment( enchantTYPE , enchantLVL );
John Smith
  • 321
  • 1
  • 3
  • 10

2 Answers2

0

You are trying to fit a String object into an Enchantment object. Unfortunately, a String is not an Enchantment.

I'm not intimately familiar with the Bukkit API, however you will need to use one of the Enchantment constructors. I would recommend you become more familiar with the Java programming language basics before writing your own mods and plugins, though, as a general rule.

asteri
  • 11,402
  • 13
  • 60
  • 84
0

Got it:

Enchantment enchantTYPE = Enchantment.getByName(enchantINFO[0]);
John Smith
  • 321
  • 1
  • 3
  • 10
  • 2
    Please accept your answer, so that people know your problem is solved and will not attempt to answer further. – Xyene Jan 06 '13 at 20:53