0

如何将字符串转换为(自定义类型)附魔?以下代码警报“类型不匹配:无法从字符串转换为附魔

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 );
4

2 回答 2

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.

于 2012-12-22T15:57:36.360 回答
0

知道了:

Enchantment enchantTYPE = Enchantment.getByName(enchantINFO[0]);
于 2012-12-22T16:08:43.403 回答