2013-08-06 02:09:42 +02:00
|
|
|
package me.blackvein.quests;
|
2013-04-22 23:06:28 +02:00
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import org.bukkit.enchantments.Enchantment;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
public class ItemUtil {
|
2013-08-06 01:18:44 +02:00
|
|
|
|
2013-04-22 23:06:28 +02:00
|
|
|
public static Quests plugin = null;
|
2013-08-06 01:18:44 +02:00
|
|
|
|
2013-04-22 23:06:28 +02:00
|
|
|
//Format - id-id:amount-amount:data-data:enchantment-enchantment level:name-name:lore-lore:
|
|
|
|
public static ItemStack parseItem(String s){
|
2013-08-06 01:18:44 +02:00
|
|
|
|
2013-04-22 23:06:28 +02:00
|
|
|
String[] args = s.split(":");
|
|
|
|
ItemStack stack = null;
|
|
|
|
LinkedList<String> lore = new LinkedList<String>();
|
2013-08-06 01:18:44 +02:00
|
|
|
|
2013-04-22 23:06:28 +02:00
|
|
|
for(String arg : args){
|
2013-08-06 01:18:44 +02:00
|
|
|
|
2013-04-22 23:06:28 +02:00
|
|
|
if(arg.startsWith("id-"))
|
|
|
|
stack = new ItemStack(Integer.parseInt(arg.substring(3)));
|
|
|
|
else if(arg.startsWith("amount-"))
|
|
|
|
stack.setAmount(Integer.parseInt(arg.substring(7)));
|
|
|
|
else if(arg.startsWith("data-"))
|
|
|
|
stack.setDurability(Short.parseShort(arg.substring(5)));
|
|
|
|
else if(arg.startsWith("enchantment-")){
|
|
|
|
String[] ench = arg.substring(12).split(" ");
|
|
|
|
Enchantment e = Quests.getEnchantment(ench[0]);
|
|
|
|
stack.addEnchantment(e, Integer.parseInt(ench[1]));
|
|
|
|
}else if(arg.startsWith("name-"))
|
|
|
|
stack.getItemMeta().setDisplayName(arg.substring(5));
|
|
|
|
else if(arg.startsWith("lore-"))
|
|
|
|
lore.add(arg.substring(5));
|
2013-08-06 01:18:44 +02:00
|
|
|
|
|
|
|
|
2013-04-22 23:06:28 +02:00
|
|
|
}
|
2013-08-06 01:18:44 +02:00
|
|
|
|
2013-04-22 23:06:28 +02:00
|
|
|
if(lore.isEmpty() == false)
|
|
|
|
stack.getItemMeta().setLore(lore);
|
2013-08-06 01:18:44 +02:00
|
|
|
|
2013-04-22 23:06:28 +02:00
|
|
|
return stack;
|
2013-08-06 01:18:44 +02:00
|
|
|
|
2013-04-22 23:06:28 +02:00
|
|
|
}
|
2013-08-06 01:18:44 +02:00
|
|
|
|
2013-04-22 23:06:28 +02:00
|
|
|
}
|