use of org.bukkit.enchantments.EnchantmentWrapper in project xAuth by CypherX.
the class PlayerDataHandler method buildItemStack.
private ItemStack[] buildItemStack(String str) {
ItemStack[] items = null;
String[] itemSplit = str.split(";");
String[] itemid = itemSplit[0].split(",");
String[] amount = itemSplit[1].split(",");
String[] durability = itemSplit[2].split(",");
String[] enchants = itemSplit[3].split(",", -1);
items = new ItemStack[itemid.length];
for (int i = 0; i < items.length; i++) {
items[i] = new ItemStack(Integer.parseInt(itemid[i]), Integer.parseInt(amount[i]), Short.parseShort(durability[i]));
if (!enchants[i].isEmpty()) {
String[] itemEnchants = enchants[i].split("-");
for (String enchant : itemEnchants) {
String[] enchantSplit = enchant.split(":");
int id = Integer.parseInt(enchantSplit[0]);
int level = Integer.parseInt(enchantSplit[1]);
Enchantment e = new EnchantmentWrapper(id);
items[i].addUnsafeEnchantment(e, level);
}
}
}
return items;
}
use of org.bukkit.enchantments.EnchantmentWrapper in project Glowstone by GlowstoneMC.
the class EnchantmentTest method effect.
@Test
public void effect() throws ReflectiveOperationException {
EnchantmentWrapper wrapper = (EnchantmentWrapper) field.get(null);
GlowEnchantment enchant = (GlowEnchantment) wrapper.getEnchantment();
assertThat("missing enchantment for " + field.getName(), enchant, notNullValue());
assertThat("wrong name on wrapped effect", enchant.getName(), is(field.getName()));
assertThat("missing from byName", Enchantment.getByName(enchant.getName()), is(enchant));
assertThat("missing from byId", Enchantment.getById(enchant.getId()), is(enchant));
assertThat("wrong start level", enchant.getStartLevel(), is(1));
assertThat("weird max level: " + enchant.getMaxLevel(), enchant.getMaxLevel() >= 1 && enchant.getMaxLevel() <= 5, is(true));
assertThat("missing item target", enchant.getItemTarget(), notNullValue());
}
use of org.bukkit.enchantments.EnchantmentWrapper in project Dragonet-Legacy by DragonetMC.
the class EnchantmentTest method effect.
@Test
public void effect() throws ReflectiveOperationException {
EnchantmentWrapper wrapper = (EnchantmentWrapper) field.get(null);
GlowEnchantment enchant = (GlowEnchantment) wrapper.getEnchantment();
assertNotNull("missing enchantment for " + field.getName(), enchant);
assertEquals("wrong name on wrapped effect", field.getName(), enchant.getName());
assertEquals("missing from byName", enchant, Enchantment.getByName(enchant.getName()));
assertEquals("missing from byId", enchant, Enchantment.getById(enchant.getId()));
assertEquals("wrong start level", 1, enchant.getStartLevel());
assertTrue("weird max level: " + enchant.getMaxLevel(), enchant.getMaxLevel() >= 1 && enchant.getMaxLevel() <= 5);
assertNotNull("missing item target", enchant.getItemTarget());
}
Aggregations