Last active
July 27, 2017 21:36
-
-
Save cchudant/5e66dcff6a66daf1083b631248a19f5d to your computer and use it in GitHub Desktop.
Utility class to create items easily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bukkit.*; | |
import org.bukkit.block.BlockState; | |
import org.bukkit.block.banner.Pattern; | |
import org.bukkit.enchantments.Enchantment; | |
import org.bukkit.inventory.ItemFlag; | |
import org.bukkit.inventory.ItemStack; | |
import org.bukkit.inventory.meta.*; | |
import org.bukkit.material.MaterialData; | |
import org.bukkit.potion.PotionData; | |
import org.bukkit.potion.PotionEffect; | |
import org.bukkit.potion.PotionEffectType; | |
import java.util.*; | |
/* ============================= */ | |
/* == ItemMeta Implementation == */ | |
/* ============================= */ | |
@SuppressWarnings("ALL") //Don't bother about my warning(s) ("meta is not in toString()") | |
public class ItemBuilder { | |
public final ItemStack item; | |
public final ItemMeta meta; | |
private ItemBuilder(ItemStack item) { | |
this.item = item; | |
meta = item.getItemMeta(); | |
} | |
public ItemBuilder(ItemBuilder clone) { | |
item = clone.item; | |
meta = clone.meta; | |
} | |
/* | |
* Static constructors | |
*/ | |
public static ItemBuilder of(ItemStack item) { | |
return new ItemBuilder(item); | |
} | |
@Deprecated | |
public static ItemBuilder of(int type) { | |
return of(new ItemStack(type)); | |
} | |
public static ItemBuilder of(Material type) { | |
return of(new ItemStack(type)); | |
} | |
@Deprecated | |
public static ItemBuilder of(int type, int amount) { | |
return of(new ItemStack(type, amount)); | |
} | |
public static ItemBuilder of(Material type, int amount) { | |
return of(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static ItemBuilder of(int type, int amount, short damage) { | |
return of(new ItemStack(type, amount, damage)); | |
} | |
public static ItemBuilder of(Material type, int amount, short damage) { | |
return of(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static ItemBuilder of(int type, int amount, short damage, Byte data) { | |
return of(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static ItemBuilder of(Material type, int amount, short damage, Byte data) { | |
return of(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* Utils | |
*/ | |
@SafeVarargs | |
private static <T> List<T> list(T... items) { | |
switch (items.length) { | |
case 0: | |
return Collections.emptyList(); | |
case 1: | |
return Collections.singletonList(items[0]); | |
default: | |
return Arrays.asList(items); | |
} | |
} | |
@Override | |
public boolean equals(Object o) { //Handwritten | |
return this == o || (o instanceof ItemBuilder && ((ItemBuilder) o).item.equals(item)); | |
} | |
@Override | |
public int hashCode() { //Handwritten | |
return item.hashCode(); | |
} | |
@Override | |
public String toString() { //Handwritten | |
return getClass().getSimpleName() + '{' + item + '}'; | |
} | |
@Override | |
public ItemBuilder clone() { | |
return new ItemBuilder(this); | |
} | |
/* | |
* Build | |
*/ | |
public ItemStack build() { | |
item.setItemMeta(meta); | |
return item; | |
} | |
/* | |
* ItemStack methods | |
*/ | |
//Type ID | |
@Deprecated | |
public int typeID() { | |
return item.getTypeId(); | |
} | |
//Type | |
public Material type() { | |
return item.getType(); | |
} | |
//Amount | |
public ItemBuilder amount(int amount) { | |
item.setAmount(amount); | |
return this; | |
} | |
public int amount() { | |
return item.getAmount(); | |
} | |
//Data | |
@Deprecated | |
public ItemBuilder data(MaterialData data) { | |
item.setData(data); | |
return this; | |
} | |
@Deprecated | |
public MaterialData data() { | |
return item.getData(); | |
} | |
//Durability | |
public ItemBuilder damage(short damage) { | |
return durability(damage); | |
} | |
public ItemBuilder durability(short durability) { | |
item.setDurability(durability); | |
return this; | |
} | |
public short damage() { | |
return durability(); | |
} | |
public short durability() { | |
return item.getDurability(); | |
} | |
/* | |
* ItemMeta methods | |
*/ | |
//Enchant | |
public ItemBuilder enchant(Enchantment ench, int lvl) { | |
return enchant(ench, lvl, true); | |
} | |
public ItemBuilder enchant(Enchantment ench, int level, boolean ignoreLvlRestriction) { | |
meta.addEnchant(ench, level, ignoreLvlRestriction); | |
return this; | |
} | |
public ItemBuilder disenchant(Enchantment ench) { | |
meta.removeEnchant(ench); | |
return this; | |
} | |
public ItemBuilder disenchant() { | |
for (Enchantment ench : meta.getEnchants().keySet()) | |
meta.removeEnchant(ench); | |
return this; | |
} | |
public boolean has(Enchantment ench) { | |
return meta.hasEnchant(ench); | |
} | |
public boolean hasEnchants() { | |
return meta.hasEnchants(); | |
} | |
public int getEnchant(Enchantment ench) { | |
return meta.getEnchantLevel(ench); | |
} | |
public Map<Enchantment, Integer> enchants() { | |
return meta.getEnchants(); | |
} | |
public int numEnchants() { | |
return meta.getEnchants().size(); | |
} | |
public boolean conflict(Enchantment ench) { | |
return meta.hasConflictingEnchant(ench); | |
} | |
//Item Flags | |
public ItemBuilder itemFlags(ItemFlag... itemFlags) { | |
clearItemFlags(); | |
meta.addItemFlags(itemFlags); | |
return this; | |
} | |
public ItemBuilder addItemFlags(ItemFlag... itemFlags) { | |
meta.addItemFlags(itemFlags); | |
return this; | |
} | |
public ItemBuilder removeItemFlags(ItemFlag... itemFlags) { | |
meta.removeItemFlags(itemFlags); | |
return this; | |
} | |
public ItemBuilder clearItemFlags() { | |
for (ItemFlag flag : meta.getItemFlags()) | |
meta.removeItemFlags(flag); | |
return this; | |
} | |
public boolean has(ItemFlag itemFlag) { | |
return meta.getItemFlags().contains(itemFlag); | |
} | |
public boolean hasItemFlags() { | |
return !meta.getItemFlags().isEmpty(); | |
} | |
public Set<ItemFlag> itemFlags(ItemFlag itemFlag) { | |
return meta.getItemFlags(); | |
} | |
public int numItemFlags() { | |
return meta.getItemFlags().size(); | |
} | |
//Display Name | |
public ItemBuilder name(String displayName) { | |
meta.setDisplayName(displayName); | |
return this; | |
} | |
public ItemBuilder clearName() { | |
meta.setDisplayName(null); | |
return this; | |
} | |
public String name() { | |
return meta.getDisplayName(); | |
} | |
public boolean hasName() { | |
return meta.hasDisplayName(); | |
} | |
//Lore | |
public ItemBuilder lore(String... lore) { | |
meta.setLore(list(lore)); | |
return this; | |
} | |
public ItemBuilder lore(int index, String lore) { | |
List<String> currentLore = meta.getLore(); | |
currentLore.set(index, lore); | |
meta.setLore(currentLore); | |
return this; | |
} | |
public ItemBuilder addLore(String... lore) { | |
List<String> currentLore = meta.getLore(); | |
currentLore.addAll(list(lore)); | |
meta.setLore(currentLore); | |
return this; | |
} | |
public ItemBuilder removeLore(String lore) { | |
List<String> currentLore = meta.getLore(); | |
currentLore.remove(lore); | |
meta.setLore(currentLore); | |
return this; | |
} | |
public ItemBuilder removeLore(int index) { | |
List<String> currentLore = meta.getLore(); | |
currentLore.remove(index); | |
meta.setLore(currentLore); | |
return this; | |
} | |
public ItemBuilder clearLore() { | |
meta.setLore(null); | |
return this; | |
} | |
public boolean hasLore() { | |
return meta.hasLore(); | |
} | |
public boolean hasLore(String lore) { | |
return meta.getLore().contains(lore); | |
} | |
public boolean hasLore(int index) { | |
return meta.getLore().size() > index; | |
} | |
public List<String> lore() { | |
return meta.getLore(); | |
} | |
public int numLore() { | |
return meta.getLore().size(); | |
} | |
//Unbreakable | |
//Spigot only (remove if bukkit) | |
public ItemBuilder unbreakable() { | |
meta.spigot().setUnbreakable(true); | |
return this; | |
} | |
public ItemBuilder breakable() { | |
meta.spigot().setUnbreakable(false); | |
return this; | |
} | |
public ItemBuilder unbreakable(boolean unbreakable) { | |
meta.spigot().setUnbreakable(unbreakable); | |
return this; | |
} | |
public boolean isUnbreakable() { | |
return meta.spigot().isUnbreakable(); | |
} | |
public boolean isBreakable() { | |
return !meta.spigot().isUnbreakable(); | |
} | |
/* =============================== */ | |
/* == BannerMeta Implementation == */ | |
/* =============================== */ | |
/* | |
* Static constructors | |
*/ | |
public static BannerMetaBuilder banner(ItemStack item) { | |
return new BannerMetaBuilder(item); | |
} | |
@Deprecated | |
public static BannerMetaBuilder banner(int type) { | |
return banner(new ItemStack(type)); | |
} | |
public static BannerMetaBuilder banner(Material type) { | |
return banner(new ItemStack(type)); | |
} | |
@Deprecated | |
public static BannerMetaBuilder banner(int type, int amount) { | |
return banner(new ItemStack(type, amount)); | |
} | |
public static BannerMetaBuilder banner(Material type, int amount) { | |
return banner(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static BannerMetaBuilder banner(int type, int amount, short damage) { | |
return banner(new ItemStack(type, amount, damage)); | |
} | |
public static BannerMetaBuilder banner(Material type, int amount, short damage) { | |
return banner(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static BannerMetaBuilder banner(int type, int amount, short damage, Byte data) { | |
return banner(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static BannerMetaBuilder banner(Material type, int amount, short damage, Byte data) { | |
return banner(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* BannerMeta subclass | |
*/ | |
public static class BannerMetaBuilder extends ItemBuilder { | |
private final BannerMeta meta; | |
private BannerMetaBuilder(ItemStack item) { | |
super(item); | |
meta = (BannerMeta) super.meta; | |
} | |
public BannerMetaBuilder(BannerMetaBuilder clone) { | |
super(clone); | |
meta = (BannerMeta) super.meta; | |
} | |
@Override | |
public BannerMetaBuilder clone() { | |
return new BannerMetaBuilder(this); | |
} | |
/* | |
* Methods | |
*/ | |
//Patterns | |
public BannerMetaBuilder bannerPatterns(Pattern... patterns) { | |
meta.setPatterns(list(patterns)); | |
return this; | |
} | |
public BannerMetaBuilder bannerPattern(int index, Pattern pattern) { | |
meta.setPattern(index, pattern); | |
return this; | |
} | |
public BannerMetaBuilder addBannerPatterns(Pattern... patterns) { | |
for (Pattern pattern : patterns) | |
meta.addPattern(pattern); | |
return this; | |
} | |
public BannerMetaBuilder removeBannerPattern(Pattern pattern) { | |
List<Pattern> patterns = meta.getPatterns(); | |
patterns.remove(pattern); | |
meta.setPatterns(patterns); | |
return this; | |
} | |
public BannerMetaBuilder removeBannerPattern(int index) { | |
meta.removePattern(index); | |
return this; | |
} | |
public BannerMetaBuilder clearBannerPatterns() { | |
meta.setPatterns(null); | |
return this; | |
} | |
public boolean hasBannerPatterns() { | |
return meta.getPatterns().isEmpty(); | |
} | |
public boolean hasBannerPattern(Pattern pattern) { | |
return meta.getPatterns().contains(pattern); | |
} | |
public boolean hasBannerPattern(int index) { | |
return meta.getPatterns().size() > index; | |
} | |
public List<Pattern> bannerPatterns() { | |
return meta.getPatterns(); | |
} | |
public Pattern bannerPattern(int index) { | |
return meta.getPattern(index); | |
} | |
public int numBannerPatterns() { | |
return meta.numberOfPatterns(); | |
} | |
//Base Color | |
@Deprecated | |
public BannerMetaBuilder bannerBaseColor(DyeColor color) { | |
meta.setBaseColor(color); | |
return this; | |
} | |
@Deprecated | |
public DyeColor bannerBaseColor() { | |
return meta.getBaseColor(); | |
} | |
} | |
/* =================================== */ | |
/* == BlockStateMeta Implementation == */ | |
/* =================================== */ | |
/* | |
* Static constructors | |
*/ | |
public static BlockStateMetaBuilder blockState(ItemStack item) { | |
return new BlockStateMetaBuilder(item); | |
} | |
@Deprecated | |
public static BlockStateMetaBuilder blockState(int type) { | |
return blockState(new ItemStack(type)); | |
} | |
public static BlockStateMetaBuilder blockState(Material type) { | |
return blockState(new ItemStack(type)); | |
} | |
@Deprecated | |
public static BlockStateMetaBuilder blockState(int type, int amount) { | |
return blockState(new ItemStack(type, amount)); | |
} | |
public static BlockStateMetaBuilder blockState(Material type, int amount) { | |
return blockState(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static BlockStateMetaBuilder blockState(int type, int amount, short damage) { | |
return blockState(new ItemStack(type, amount, damage)); | |
} | |
public static BlockStateMetaBuilder blockState(Material type, int amount, short damage) { | |
return blockState(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static BlockStateMetaBuilder blockState(int type, int amount, short damage, Byte data) { | |
return blockState(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static BlockStateMetaBuilder blockState(Material type, int amount, short damage, Byte data) { | |
return blockState(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* BlockStateMeta subclass | |
*/ | |
public static class BlockStateMetaBuilder extends ItemBuilder { | |
private final BlockStateMeta meta; | |
private BlockStateMetaBuilder(ItemStack item) { | |
super(item); | |
meta = (BlockStateMeta) super.meta; | |
} | |
public BlockStateMetaBuilder(BlockStateMetaBuilder clone) { | |
super(clone); | |
meta = (BlockStateMeta) super.meta; | |
} | |
@Override | |
public BlockStateMetaBuilder clone() { | |
return new BlockStateMetaBuilder(this); | |
} | |
/* | |
* Methods | |
*/ | |
//Block State | |
public BlockStateMetaBuilder blockState(BlockState blockState) { | |
meta.setBlockState(blockState); | |
return this; | |
} | |
public BlockState blockState() { | |
return meta.getBlockState(); | |
} | |
public boolean hasBlockState() { | |
return meta.hasBlockState(); | |
} | |
} | |
/* ============================= */ | |
/* == BookMeta Implementation == */ | |
/* ============================= */ | |
/* | |
* Static constructors | |
*/ | |
public static BookMetaBuilder book(ItemStack item) { | |
return new BookMetaBuilder(item); | |
} | |
@Deprecated | |
public static BookMetaBuilder book(int type) { | |
return book(new ItemStack(type)); | |
} | |
public static BookMetaBuilder book(Material type) { | |
return book(new ItemStack(type)); | |
} | |
@Deprecated | |
public static BookMetaBuilder book(int type, int amount) { | |
return book(new ItemStack(type, amount)); | |
} | |
public static BookMetaBuilder book(Material type, int amount) { | |
return book(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static BookMetaBuilder book(int type, int amount, short damage) { | |
return book(new ItemStack(type, amount, damage)); | |
} | |
public static BookMetaBuilder book(Material type, int amount, short damage) { | |
return book(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static BookMetaBuilder book(int type, int amount, short damage, Byte data) { | |
return book(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static BookMetaBuilder book(Material type, int amount, short damage, Byte data) { | |
return book(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* BookMeta subclass | |
*/ | |
public static class BookMetaBuilder extends ItemBuilder { | |
private final BookMeta meta; | |
private BookMetaBuilder(ItemStack item) { | |
super(item); | |
meta = (BookMeta) super.meta; | |
} | |
public BookMetaBuilder(BookMetaBuilder clone) { | |
super(clone); | |
meta = (BookMeta) super.meta; | |
} | |
@Override | |
public BookMetaBuilder clone() { | |
return new BookMetaBuilder(this); | |
} | |
/* | |
* Methods | |
*/ | |
//Pages | |
public BookMetaBuilder bookPages(String... pages) { | |
meta.setPages(pages); | |
return this; | |
} | |
public BookMetaBuilder bookPage(int index, String page) { | |
meta.setPage(index, page); | |
return this; | |
} | |
public BookMetaBuilder addBookPage(String... pages) { | |
meta.addPage(pages); | |
return this; | |
} | |
public BookMetaBuilder removeBookPage(String page) { | |
List<String> pages = meta.getPages(); | |
pages.remove(page); | |
meta.setPages(pages); | |
return this; | |
} | |
public BookMetaBuilder removeBookPage(int index) { | |
List<String> pages = meta.getPages(); | |
pages.remove(index); | |
meta.setPages(pages); | |
return this; | |
} | |
public BookMetaBuilder clearPages(int index) { | |
meta.setPages(Collections.emptyList()); | |
return this; | |
} | |
public boolean hasBookPages() { | |
return meta.hasPages(); | |
} | |
public boolean hasBookPage(String page) { | |
return meta.getPages().contains(page); | |
} | |
public boolean hasBookPage(int index) { | |
return meta.getPages().size() > index; | |
} | |
public List<String> bookPages() { | |
return meta.getPages(); | |
} | |
public String bookPage(int index) { | |
return meta.getPage(index); | |
} | |
public int numBookPages() { | |
return meta.getPageCount(); | |
} | |
//Author | |
public BookMetaBuilder bookAuthor(String author) { | |
meta.setAuthor(author); | |
return this; | |
} | |
public BookMetaBuilder clearBookAuthor() { | |
meta.setAuthor(null); | |
return this; | |
} | |
public boolean hasBookAuthor() { | |
return meta.hasAuthor(); | |
} | |
public String bookAuthor() { | |
return meta.getAuthor(); | |
} | |
//Generation | |
public BookMetaBuilder bookGeneration(BookMeta.Generation generation) { | |
meta.setGeneration(generation); | |
return this; | |
} | |
public BookMetaBuilder clearBookGeneration() { | |
meta.setGeneration(null); | |
return this; | |
} | |
public boolean hasBookGeneration() { | |
return meta.hasGeneration(); | |
} | |
public BookMeta.Generation bookGeneration() { | |
return meta.getGeneration(); | |
} | |
//Title | |
public BookMetaBuilder bookTitle(String title) { | |
meta.setTitle(title); | |
return this; | |
} | |
public BookMetaBuilder clearBookTitle() { | |
meta.setTitle(null); | |
return this; | |
} | |
public boolean hasBookTitle() { | |
return meta.hasTitle(); | |
} | |
public String bookTitle() { | |
return meta.getTitle(); | |
} | |
} | |
/* =========================================== */ | |
/* == EnchantmentStorageMeta Implementation == */ | |
/* =========================================== */ | |
/* | |
* Static constructors | |
*/ | |
public static EnchantmentStorageMetaBuilder enchantmentStorage(ItemStack item) { | |
return new EnchantmentStorageMetaBuilder(item); | |
} | |
@Deprecated | |
public static EnchantmentStorageMetaBuilder enchantmentStorage(int type) { | |
return enchantmentStorage(new ItemStack(type)); | |
} | |
public static EnchantmentStorageMetaBuilder enchantmentStorage(Material type) { | |
return enchantmentStorage(new ItemStack(type)); | |
} | |
@Deprecated | |
public static EnchantmentStorageMetaBuilder enchantmentStorage(int type, int amount) { | |
return enchantmentStorage(new ItemStack(type, amount)); | |
} | |
public static EnchantmentStorageMetaBuilder enchantmentStorage(Material type, int amount) { | |
return enchantmentStorage(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static EnchantmentStorageMetaBuilder enchantmentStorage(int type, int amount, short damage) { | |
return enchantmentStorage(new ItemStack(type, amount, damage)); | |
} | |
public static EnchantmentStorageMetaBuilder enchantmentStorage(Material type, int amount, short damage) { | |
return enchantmentStorage(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static EnchantmentStorageMetaBuilder enchantmentStorage(int type, int amount, short damage, Byte data) { | |
return enchantmentStorage(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static EnchantmentStorageMetaBuilder enchantmentStorage(Material type, int amount, short damage, Byte data) { | |
return enchantmentStorage(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* EnchantmentStorageMeta subclass | |
*/ | |
public static class EnchantmentStorageMetaBuilder extends ItemBuilder { | |
private final EnchantmentStorageMeta meta; | |
private EnchantmentStorageMetaBuilder(ItemStack item) { | |
super(item); | |
meta = (EnchantmentStorageMeta) super.meta; | |
} | |
public EnchantmentStorageMetaBuilder(EnchantmentStorageMetaBuilder clone) { | |
super(clone); | |
meta = (EnchantmentStorageMeta) super.meta; | |
} | |
@Override | |
public EnchantmentStorageMetaBuilder clone() { | |
return new EnchantmentStorageMetaBuilder(this); | |
} | |
/* | |
* Methods | |
*/ | |
//Stored Enchantment | |
public EnchantmentStorageMetaBuilder storeEnchant(Enchantment ench, int lvl) { | |
return storeEnchant(ench, lvl, true); | |
} | |
public EnchantmentStorageMetaBuilder storeEnchant(Enchantment ench, int level, boolean ignoreLvlRestriction) { | |
meta.addStoredEnchant(ench, level, ignoreLvlRestriction); | |
return this; | |
} | |
public EnchantmentStorageMetaBuilder removeStoredEnchant(Enchantment ench) { | |
meta.removeStoredEnchant(ench); | |
return this; | |
} | |
public EnchantmentStorageMetaBuilder removeStoredEnchants() { | |
for (Enchantment ench : meta.getEnchants().keySet()) | |
meta.removeStoredEnchant(ench); | |
return this; | |
} | |
public boolean hasStored(Enchantment ench) { | |
return meta.hasStoredEnchant(ench); | |
} | |
public boolean hasStoredEnchants() { | |
return meta.hasStoredEnchants(); | |
} | |
public int getStoredEnchant(Enchantment ench) { | |
return meta.getStoredEnchantLevel(ench); | |
} | |
public Map<Enchantment, Integer> storedEnchants() { | |
return meta.getStoredEnchants(); | |
} | |
public int numStoredEnchants() { | |
return meta.getStoredEnchants().size(); | |
} | |
public boolean storedConflict(Enchantment ench) { | |
return meta.hasConflictingStoredEnchant(ench); | |
} | |
} | |
/* ======================================= */ | |
/* == FireworkEffectMeta Implementation == */ | |
/* ======================================= */ | |
/* | |
* Static constructors | |
*/ | |
public static FireworkEffectMetaBuilder fireworkEffect(ItemStack item) { | |
return new FireworkEffectMetaBuilder(item); | |
} | |
@Deprecated | |
public static FireworkEffectMetaBuilder fireworkEffect(int type) { | |
return fireworkEffect(new ItemStack(type)); | |
} | |
public static FireworkEffectMetaBuilder fireworkEffect(Material type) { | |
return fireworkEffect(new ItemStack(type)); | |
} | |
@Deprecated | |
public static FireworkEffectMetaBuilder fireworkEffect(int type, int amount) { | |
return fireworkEffect(new ItemStack(type, amount)); | |
} | |
public static FireworkEffectMetaBuilder fireworkEffect(Material type, int amount) { | |
return fireworkEffect(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static FireworkEffectMetaBuilder fireworkEffect(int type, int amount, short damage) { | |
return fireworkEffect(new ItemStack(type, amount, damage)); | |
} | |
public static FireworkEffectMetaBuilder fireworkEffect(Material type, int amount, short damage) { | |
return fireworkEffect(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static FireworkEffectMetaBuilder fireworkEffect(int type, int amount, short damage, Byte data) { | |
return fireworkEffect(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static FireworkEffectMetaBuilder fireworkEffect(Material type, int amount, short damage, Byte data) { | |
return fireworkEffect(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* FireworkEffectMeta subclass | |
*/ | |
public static class FireworkEffectMetaBuilder extends ItemBuilder { | |
private final FireworkEffectMeta meta; | |
private FireworkEffectMetaBuilder(ItemStack item) { | |
super(item); | |
meta = (FireworkEffectMeta) super.meta; | |
} | |
public FireworkEffectMetaBuilder(FireworkEffectMetaBuilder clone) { | |
super(clone); | |
meta = (FireworkEffectMeta) super.meta; | |
} | |
@Override | |
public FireworkEffectMetaBuilder clone() { | |
return new FireworkEffectMetaBuilder(this); | |
} | |
/* | |
* Methods | |
*/ | |
//Firework Effect | |
public FireworkEffectMetaBuilder fireworkEffect(FireworkEffect author) { | |
meta.setEffect(author); | |
return this; | |
} | |
public FireworkEffectMetaBuilder clearFireworkEffect() { | |
meta.setEffect(null); | |
return this; | |
} | |
public boolean hasFireworkEffect() { | |
return meta.hasEffect(); | |
} | |
public FireworkEffect fireworkEffect() { | |
return meta.getEffect(); | |
} | |
} | |
/* ================================= */ | |
/* == FireworkMeta Implementation == */ | |
/* ================================= */ | |
/* | |
* Static constructors | |
*/ | |
public static FireworkMetaBuilder firework(ItemStack item) { | |
return new FireworkMetaBuilder(item); | |
} | |
@Deprecated | |
public static FireworkMetaBuilder firework(int type) { | |
return firework(new ItemStack(type)); | |
} | |
public static FireworkMetaBuilder firework(Material type) { | |
return firework(new ItemStack(type)); | |
} | |
@Deprecated | |
public static FireworkMetaBuilder firework(int type, int amount) { | |
return firework(new ItemStack(type, amount)); | |
} | |
public static FireworkMetaBuilder firework(Material type, int amount) { | |
return firework(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static FireworkMetaBuilder firework(int type, int amount, short damage) { | |
return firework(new ItemStack(type, amount, damage)); | |
} | |
public static FireworkMetaBuilder firework(Material type, int amount, short damage) { | |
return firework(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static FireworkMetaBuilder firework(int type, int amount, short damage, Byte data) { | |
return firework(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static FireworkMetaBuilder firework(Material type, int amount, short damage, Byte data) { | |
return firework(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* FireworkMeta subclass | |
*/ | |
public static class FireworkMetaBuilder extends ItemBuilder { | |
private final FireworkMeta meta; | |
private FireworkMetaBuilder(ItemStack item) { | |
super(item); | |
meta = (FireworkMeta) super.meta; | |
} | |
public FireworkMetaBuilder(FireworkMetaBuilder clone) { | |
super(clone); | |
meta = (FireworkMeta) super.meta; | |
} | |
@Override | |
public FireworkMetaBuilder clone() { | |
return new FireworkMetaBuilder(this); | |
} | |
/* | |
* Methods | |
*/ | |
//Effects | |
public FireworkMetaBuilder fireworkEffects(FireworkEffect... effects) { | |
meta.clearEffects(); | |
meta.addEffects(effects); | |
return this; | |
} | |
public FireworkMetaBuilder fireworkEffect(int index, FireworkEffect effect) { | |
List<FireworkEffect> effects = meta.getEffects(); | |
effects.set(index, effect); | |
meta.clearEffects(); | |
meta.addEffects(effects); | |
return this; | |
} | |
public FireworkMetaBuilder addFireworkEffects(FireworkEffect... effects) { | |
meta.addEffects(effects); | |
return this; | |
} | |
public FireworkMetaBuilder removeFireworkEffect(FireworkEffect effect) { | |
List<FireworkEffect> effects = meta.getEffects(); | |
effects.remove(effect); | |
meta.clearEffects(); | |
meta.addEffects(effects); | |
return this; | |
} | |
public FireworkMetaBuilder removeFireworkEffect(int index) { | |
meta.removeEffect(index); | |
return this; | |
} | |
public FireworkMetaBuilder clearFireworkEffects() { | |
meta.clearEffects(); | |
return this; | |
} | |
public boolean hasFireworkEffects() { | |
return meta.hasEffects(); | |
} | |
public boolean hasFireworkEffect(FireworkEffect effect) { | |
return meta.getEffects().contains(effect); | |
} | |
public boolean hasFireworkEffect(int index) { | |
return meta.getEffects().size() > index; | |
} | |
public List<FireworkEffect> fireworkEffects() { | |
return meta.getEffects(); | |
} | |
public FireworkEffect getFireworkEffect(int index) { | |
return meta.getEffects().get(index); | |
} | |
public int numFireworkEffects() { | |
return meta.getEffectsSize(); | |
} | |
//Power | |
public FireworkMetaBuilder fireworkPower(int power) { | |
meta.setPower(power); | |
return this; | |
} | |
public int fireworkPower() { | |
return meta.getPower(); | |
} | |
} | |
/* ===================================== */ | |
/* == LeatherArmorMeta Implementation == */ | |
/* ===================================== */ | |
/* | |
* Static constructors | |
*/ | |
public static LeatherArmorMetaBuilder leatherArmor(ItemStack item) { | |
return new LeatherArmorMetaBuilder(item); | |
} | |
@Deprecated | |
public static LeatherArmorMetaBuilder leatherArmor(int type) { | |
return leatherArmor(new ItemStack(type)); | |
} | |
public static LeatherArmorMetaBuilder leatherArmor(Material type) { | |
return leatherArmor(new ItemStack(type)); | |
} | |
@Deprecated | |
public static LeatherArmorMetaBuilder leatherArmor(int type, int amount) { | |
return leatherArmor(new ItemStack(type, amount)); | |
} | |
public static LeatherArmorMetaBuilder leatherArmor(Material type, int amount) { | |
return leatherArmor(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static LeatherArmorMetaBuilder leatherArmor(int type, int amount, short damage) { | |
return leatherArmor(new ItemStack(type, amount, damage)); | |
} | |
public static LeatherArmorMetaBuilder leatherArmor(Material type, int amount, short damage) { | |
return leatherArmor(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static LeatherArmorMetaBuilder leatherArmor(int type, int amount, short damage, Byte data) { | |
return leatherArmor(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static LeatherArmorMetaBuilder leatherArmor(Material type, int amount, short damage, Byte data) { | |
return leatherArmor(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* LeatherArmorMeta subclass | |
*/ | |
public static class LeatherArmorMetaBuilder extends ItemBuilder { | |
private final LeatherArmorMeta meta; | |
private LeatherArmorMetaBuilder(ItemStack item) { | |
super(item); | |
meta = (LeatherArmorMeta) super.meta; | |
} | |
public LeatherArmorMetaBuilder(LeatherArmorMetaBuilder clone) { | |
super(clone); | |
meta = (LeatherArmorMeta) super.meta; | |
} | |
@Override | |
public LeatherArmorMetaBuilder clone() { | |
return new LeatherArmorMetaBuilder(this); | |
} | |
/* | |
* Methods | |
*/ | |
//Color | |
public LeatherArmorMetaBuilder armorColor(Color color) { | |
meta.setColor(color); | |
return this; | |
} | |
public Color armorColor() { | |
return meta.getColor(); | |
} | |
} | |
/* ===================================== */ | |
/* == MapMeta Implementation == */ | |
/* ===================================== */ | |
/* | |
* Static constructors | |
*/ | |
public static MapMetaBuilder map(ItemStack item) { | |
return new MapMetaBuilder(item); | |
} | |
@Deprecated | |
public static MapMetaBuilder map(int type) { | |
return map(new ItemStack(type)); | |
} | |
public static MapMetaBuilder map(Material type) { | |
return map(new ItemStack(type)); | |
} | |
@Deprecated | |
public static MapMetaBuilder map(int type, int amount) { | |
return map(new ItemStack(type, amount)); | |
} | |
public static MapMetaBuilder map(Material type, int amount) { | |
return map(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static MapMetaBuilder map(int type, int amount, short damage) { | |
return map(new ItemStack(type, amount, damage)); | |
} | |
public static MapMetaBuilder map(Material type, int amount, short damage) { | |
return map(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static MapMetaBuilder map(int type, int amount, short damage, Byte data) { | |
return map(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static MapMetaBuilder map(Material type, int amount, short damage, Byte data) { | |
return map(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* MapMeta subclass | |
*/ | |
public static class MapMetaBuilder extends ItemBuilder { | |
private final MapMeta meta; | |
private MapMetaBuilder(ItemStack item) { | |
super(item); | |
meta = (MapMeta) super.meta; | |
} | |
public MapMetaBuilder(MapMetaBuilder clone) { | |
super(clone); | |
meta = (MapMeta) super.meta; | |
} | |
@Override | |
public MapMetaBuilder clone() { | |
return new MapMetaBuilder(this); | |
} | |
/* | |
* Methods | |
*/ | |
//Color | |
public MapMetaBuilder scaleMap() { | |
meta.setScaling(true); | |
return this; | |
} | |
public MapMetaBuilder scaleMap(boolean scaling) { | |
meta.setScaling(scaling); | |
return this; | |
} | |
public boolean mapScaling() { | |
return meta.isScaling(); | |
} | |
} | |
/* ================================ */ | |
/* == PotionMeta Implementation == */ | |
/* ================================ */ | |
/* | |
* Static constructors | |
*/ | |
public static PotionMetaBuilder potion(ItemStack item) { | |
return new PotionMetaBuilder(item); | |
} | |
@Deprecated | |
public static PotionMetaBuilder potion(int type) { | |
return potion(new ItemStack(type)); | |
} | |
public static PotionMetaBuilder potion(Material type) { | |
return potion(new ItemStack(type)); | |
} | |
@Deprecated | |
public static PotionMetaBuilder potion(int type, int amount) { | |
return potion(new ItemStack(type, amount)); | |
} | |
public static PotionMetaBuilder potion(Material type, int amount) { | |
return potion(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static PotionMetaBuilder potion(int type, int amount, short damage) { | |
return potion(new ItemStack(type, amount, damage)); | |
} | |
public static PotionMetaBuilder potion(Material type, int amount, short damage) { | |
return potion(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static PotionMetaBuilder potion(int type, int amount, short damage, Byte data) { | |
return potion(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static PotionMetaBuilder potion(Material type, int amount, short damage, Byte data) { | |
return potion(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* PotionMeta subclass | |
*/ | |
public static class PotionMetaBuilder extends ItemBuilder { | |
private final PotionMeta meta; | |
private PotionMetaBuilder(ItemStack item) { | |
super(item); | |
meta = (PotionMeta) super.meta; | |
} | |
public PotionMetaBuilder(PotionMetaBuilder clone) { | |
super(clone); | |
meta = (PotionMeta) super.meta; | |
} | |
@Override | |
public PotionMetaBuilder clone() { | |
return new PotionMetaBuilder(this); | |
} | |
/* | |
* Methods | |
*/ | |
//Effects | |
public PotionMetaBuilder potionEffects(PotionEffect... effects) { | |
meta.clearCustomEffects(); | |
for (PotionEffect effect : effects) | |
meta.addCustomEffect(effect, true); | |
return this; | |
} | |
public PotionMetaBuilder potionEffect(int index, PotionEffect effect) { | |
List<PotionEffect> effects = meta.getCustomEffects(); | |
effects.set(index, effect); | |
meta.clearCustomEffects(); | |
for (PotionEffect eff : effects) | |
meta.addCustomEffect(eff, true); | |
return this; | |
} | |
public PotionMetaBuilder addPotionEffects(PotionEffect effect, boolean overwrite) { | |
meta.addCustomEffect(effect, overwrite); | |
return this; | |
} | |
public PotionMetaBuilder addPotionEffects(PotionEffect... effects) { | |
for (PotionEffect effect : effects) | |
meta.addCustomEffect(effect, true); | |
return this; | |
} | |
public PotionMetaBuilder removePotionEffect(PotionEffect effect) { | |
List<PotionEffect> effects = meta.getCustomEffects(); | |
effects.remove(effect); | |
meta.clearCustomEffects(); | |
for (PotionEffect eff : effects) | |
meta.addCustomEffect(eff, true); | |
return this; | |
} | |
public PotionMetaBuilder removePotionEffect(PotionEffectType type) { | |
meta.removeCustomEffect(type); | |
return this; | |
} | |
public PotionMetaBuilder clearPotionEffects() { | |
meta.clearCustomEffects(); | |
return this; | |
} | |
public boolean hasPotionEffects() { | |
return meta.hasCustomEffects(); | |
} | |
public boolean hasPotionEffect(PotionEffect effect) { | |
return meta.getCustomEffects().contains(effect); | |
} | |
public boolean hasPotionEffect(PotionEffectType type) { | |
return meta.hasCustomEffect(type); | |
} | |
public boolean hasPotionEffect(int index) { | |
return meta.getCustomEffects().size() > index; | |
} | |
public List<PotionEffect> potionEffects() { | |
return meta.getCustomEffects(); | |
} | |
public int numPotionEffects() { | |
return meta.getCustomEffects().size(); | |
} | |
//Base Potion Data | |
public PotionMetaBuilder basePotionData(PotionData data) { | |
meta.setBasePotionData(data); | |
return this; | |
} | |
public PotionData basePotionData() { | |
return meta.getBasePotionData(); | |
} | |
//Main Effect | |
@Deprecated | |
public PotionMetaBuilder mainEffect(PotionEffectType type) { | |
meta.setMainEffect(type); | |
return this; | |
} | |
} | |
/* ============================== */ | |
/* == SkullMeta Implementation == */ | |
/* ============================== */ | |
/* | |
* Static constructors | |
*/ | |
public static SkullMetaBuilder skull(ItemStack item) { | |
return new SkullMetaBuilder(item); | |
} | |
@Deprecated | |
public static SkullMetaBuilder skull(int type) { | |
return skull(new ItemStack(type)); | |
} | |
public static SkullMetaBuilder skull(Material type) { | |
return skull(new ItemStack(type)); | |
} | |
@Deprecated | |
public static SkullMetaBuilder skull(int type, int amount) { | |
return skull(new ItemStack(type, amount)); | |
} | |
public static SkullMetaBuilder skull(Material type, int amount) { | |
return skull(new ItemStack(type, amount)); | |
} | |
@Deprecated | |
public static SkullMetaBuilder skull(int type, int amount, short damage) { | |
return skull(new ItemStack(type, amount, damage)); | |
} | |
public static SkullMetaBuilder skull(Material type, int amount, short damage) { | |
return skull(new ItemStack(type, amount, damage)); | |
} | |
@Deprecated | |
public static SkullMetaBuilder skull(int type, int amount, short damage, Byte data) { | |
return skull(new ItemStack(type, amount, damage, data)); | |
} | |
@Deprecated | |
public static SkullMetaBuilder skull(Material type, int amount, short damage, Byte data) { | |
return skull(new ItemStack(type, amount, damage, data)); | |
} | |
/* | |
* BlockStateMeta subclass | |
*/ | |
public static class SkullMetaBuilder extends ItemBuilder { | |
private final SkullMeta meta; | |
private SkullMetaBuilder(ItemStack item) { | |
super(item); | |
meta = (SkullMeta) super.meta; | |
} | |
public SkullMetaBuilder(SkullMetaBuilder clone) { | |
super(clone); | |
meta = (SkullMeta) super.meta; | |
} | |
@Override | |
public SkullMetaBuilder clone() { | |
return new SkullMetaBuilder(this); | |
} | |
/* | |
* Methods | |
*/ | |
//Skull Owner | |
public SkullMetaBuilder skullOwner(String owner) { | |
meta.setOwner(owner); | |
return this; | |
} | |
public SkullMetaBuilder clearSkullOwner() { | |
meta.setOwner(null); | |
return this; | |
} | |
public String skullOwner() { | |
return meta.getOwner(); | |
} | |
public boolean hasSkullOwner() { | |
return meta.hasOwner(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment