Skip to content

Instantly share code, notes, and snippets.

@whilb
Created February 12, 2014 22:56
Show Gist options
  • Save whilb/8966264 to your computer and use it in GitHub Desktop.
Save whilb/8966264 to your computer and use it in GitHub Desktop.
ItemStackManager example
package net.aerenserve.example;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
public class ItemStackManager {
HashMap<ItemType, ItemStack> items;
private Inventory inv;
public ItemStack kitBook;
public ItemStack mvpSword;
public ItemStack mvpChestplate;
public ItemStackManager(Plugin p) {
items = constructItemStacks();
fillItemStacks(items);
}
public void fillItemStacks(HashMap<ItemType, ItemStack> hm) {
Iterator<Entry<ItemType, ItemStack>> it = hm.entrySet().iterator();
ItemStack tempItem = null;
while (it.hasNext()) {
Map.Entry<ItemType, ItemStack> entry = (Entry<ItemType, ItemStack>) it.next();
switch(entry.getKey()) {
case kitBook:
ItemMeta meta = (ItemMeta) entry.getValue().getItemMeta();
meta.setDisplayName(ChatColor.YELLOW + "Kit Book!");
entry.getValue().setItemMeta(meta);
break;
case mvpSword:
//do the stuff
break;
}
}
}
public ItemStack getItem(ItemType type) {
return items.get(type);
}
public HashMap<ItemType, ItemStack> constructItemStacks() {
kitBook = new ItemStack(Material.BOOK, 1);
mvpSword = new ItemStack(Material.IRON_SWORD, 1);
mvpChestplate = new ItemStack(Material.IRON_CHESTPLATE, 1);
HashMap<ItemType, ItemStack> hm = new HashMap<ItemType, ItemStack>();
hm.put(ItemType.kitBook, kitBook);
return hm;
}
public enum ItemType {
kitBook,
mvpSword,
mvpChestplate,
vipSword,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment