Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package <YourPackage>;
- import com.sun.istack.internal.NotNull;
- import org.bukkit.*;
- import org.bukkit.Color;
- import org.bukkit.attribute.Attribute;
- import org.bukkit.attribute.AttributeModifier;
- import org.bukkit.block.banner.Pattern;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.entity.EntityType;
- import org.bukkit.entity.TropicalFish;
- import org.bukkit.inventory.ItemFlag;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.*;
- import org.bukkit.inventory.meta.BookMeta.Generation;
- import org.bukkit.map.MapView;
- import org.bukkit.material.MaterialData;
- import org.bukkit.potion.PotionData;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import java.util.List;
- import java.util.Map;
- import java.util.Objects;
- /**
- * Created by Green_Panda
- * Class create at 12.07.2020 15:36
- *
- * Terms Of Use:
- * - You mustn't use this class in profitable projects.
- * This forbids the usage in projects that are for example aimed to be used on a Server that earns any sort of money and ones that are directly sold to any market.
- * - You mustn't claim it as your own work or change the author.
- * This includes classes that are based off of this code. Those have to include a credit to the original author.
- *
- * Feedback:
- * - If you want to give feedback or add a special function to this API for everyone to use, then please write a comment.
- *
- * Support:
- * - If you need support, go to my discord server: https://discord.com/invite/WMFDPbh
- */
- public class ItemAPI {
- private ItemStack item;
- private ItemMeta itemMeta;
- public ItemAPI(Material material) {
- new ItemAPI(material, (byte) 0);
- }
- public ItemAPI(Material material, byte subid) {
- this.item = new ItemStack(material, subid);
- this.itemMeta = item.getItemMeta();
- }
- public ItemAPI(ItemStack item) {
- this.item = item;
- this.itemMeta = item.getItemMeta();
- }
- // -------------------------------- ItemMeta -------------------------------- \\
- public ItemAPI setAmount(@NotNull int amount) {
- item.setAmount(amount);
- return this;
- }
- @Deprecated public ItemAPI setData(@NotNull MaterialData data) {
- item.setData(data);
- return this;
- }
- public ItemAPI setType(@NotNull Material type) {
- item.setType(type);
- return this;
- }
- public ItemAPI setDisplayName(@NotNull String name) {
- itemMeta.setDisplayName(name);
- return this;
- }
- public ItemAPI setCustomModelData(@NotNull int data) {
- itemMeta.setCustomModelData(data);
- return this;
- }
- public ItemAPI setLocalizedName(@NotNull String name) {
- itemMeta.setLocalizedName(name);
- return this;
- }
- public ItemAPI setUnbreakable(@NotNull boolean unbreakable) {
- itemMeta.setUnbreakable(unbreakable);
- return this;
- }
- public ItemAPI addLoreLine(@NotNull String line) {
- Objects.requireNonNull(itemMeta.getLore()).add(line);
- return this;
- }
- public ItemAPI addLoreLines(@NotNull String...lines) {
- for (String line : lines) {
- addLoreLine(line);
- }
- return this;
- }
- public ItemAPI addEnchantment(@NotNull Enchantment enchantment, Integer lvl, @NotNull boolean b) {
- itemMeta.addEnchant(enchantment, lvl, b);
- return this;
- }
- public ItemAPI addEnchantment(@NotNull Enchantment enchantment, Integer lvl) {
- addEnchantment(enchantment, lvl, false);
- return this;
- }
- public ItemAPI addEnchantments(@NotNull Map<Enchantment, Integer> enchants) {
- enchants.forEach(this::addEnchantment);
- return this;
- }
- public ItemAPI addItemFlags(@NotNull ItemFlag...flag) {
- itemMeta.addItemFlags(flag);
- return this;
- }
- public ItemAPI addAtributeModifier(@NotNull Attribute attribute, @NotNull AttributeModifier modefier) {
- itemMeta.addAttributeModifier(attribute, modefier);
- return this;
- }
- // -------------------------------- ItemMeta -------------------------------- \\
- // -------------------------------- BookMeta -------------------------------- \\
- public ItemAPI addBookPage(@NotNull String...strings) {
- ((BookMeta) itemMeta).addPage(strings);
- return this;
- }
- public ItemAPI setBookAuthor(@NotNull String author) {
- ((BookMeta) itemMeta).setAuthor(author);
- return this;
- }
- public ItemAPI setBookGeneration(@NotNull Generation generation) {
- ((BookMeta) itemMeta).setGeneration(generation);
- return this;
- }
- public ItemAPI setBookPage(int i, @NotNull String page) {
- ((BookMeta) itemMeta).setPage(i, page);
- return this;
- }
- public ItemAPI setBookPages(@NotNull String...pages) {
- ((BookMeta) itemMeta).setPages(pages);
- return this;
- }
- public ItemAPI setBookPages(@NotNull List<String> pages) {
- ((BookMeta) itemMeta).setPages(pages);
- return this;
- }
- public ItemAPI setBookTitle(@NotNull String title) {
- ((BookMeta) itemMeta).setTitle(title);
- return this;
- }
- public ItemAPI removeBookPage(int i) {
- List<String> pages = ((BookMeta) itemMeta).getPages();
- pages.remove(i);
- setBookPages(pages);
- return this;
- }
- public ItemAPI removeBookPages(@NotNull int...indexes) {
- List<String> pages = ((BookMeta) itemMeta).getPages();
- for (int i : indexes) {
- pages.remove(i);
- }
- setBookPages(pages);
- return this;
- }
- // -------------------------------- BookMeta -------------------------------- \\
- // --------------------------- KnowledgeBookMeta ---------------------------- \\
- public ItemAPI setKnowledgeBookRecipes(@NotNull List<NamespacedKey> recipes) {
- ((KnowledgeBookMeta) itemMeta).setRecipes(recipes);
- return this;
- }
- public ItemAPI addKnowledgeBookRecipe(@NotNull NamespacedKey recipe) {
- List<NamespacedKey> recipes = ((KnowledgeBookMeta) itemMeta).getRecipes();
- recipes.add(recipe);
- ((KnowledgeBookMeta) itemMeta).setRecipes(recipes);
- return this;
- }
- public ItemAPI addKnowledgeBookRecipes(@NotNull NamespacedKey...recipes) {
- for (NamespacedKey recipe : recipes) {
- addKnowledgeBookRecipe(recipe);
- }
- return this;
- }
- public ItemAPI removeKnowledgeBookRecipe(@NotNull NamespacedKey recipe) {
- List<NamespacedKey> recipes = ((KnowledgeBookMeta) itemMeta).getRecipes();
- recipes.remove(recipe);
- ((KnowledgeBookMeta) itemMeta).setRecipes(recipes);
- return this;
- }
- public ItemAPI removeKnowledgeBookRecipes(@NotNull NamespacedKey...recipes) {
- for (NamespacedKey recipe : recipes) {
- addKnowledgeBookRecipe(recipe);
- }
- return this;
- }
- // --------------------------- KnowledgeBookMeta ---------------------------- \\
- // ------------------------------- PotionMeta ------------------------------- \\
- public ItemAPI setPotionColor(@NotNull Color color) {
- ((PotionMeta) itemMeta).setColor(color);
- return this;
- }
- public ItemAPI setBasePotionData(@NotNull PotionData data) {
- ((PotionMeta) itemMeta).setBasePotionData(data);
- return this;
- }
- public ItemAPI addCustomPotionEffect(@NotNull PotionEffect effect, @NotNull boolean b) {
- ((PotionMeta) itemMeta).addCustomEffect(effect, b);
- return this;
- }
- public ItemAPI addCustomPotionEffects(@NotNull Map<PotionEffect, Boolean> effects) {
- effects.forEach(this::addCustomPotionEffect);
- return this;
- }
- public ItemAPI removeCustomPotionEffect(@NotNull PotionEffectType effect) {
- ((PotionMeta) itemMeta).removeCustomEffect(effect);
- return this;
- }
- // ------------------------------- PotionMeta ------------------------------- \\
- // ------------------------- EnchantmentStorageMeta ------------------------- \\
- public ItemAPI addStoredEnchantment(@NotNull Enchantment ench, int lvl, @NotNull boolean ignore) {
- ((EnchantmentStorageMeta) itemMeta).addStoredEnchant(ench, lvl, ignore);
- return this;
- }
- public ItemAPI addStoredEnchantment(@NotNull Map<Enchantment, Integer> enchants) {
- enchants.forEach((ench, lvl) -> {
- ((EnchantmentStorageMeta) itemMeta).addStoredEnchant(ench, lvl, false);
- });
- return this;
- }
- public ItemAPI removeStoredEnchantment(@NotNull Enchantment ench) {
- ((EnchantmentStorageMeta) itemMeta).removeStoredEnchant(ench);
- return this;
- }
- // ------------------------- EnchantmentStorageMeta ------------------------- \\
- // ------------------------------ SpawnEggMeta ------------------------------ \\
- @Deprecated public ItemAPI setSpawnEggType(@NotNull EntityType type) {
- ((SpawnEggMeta) itemMeta).setSpawnedType(type);
- return this;
- }
- // ------------------------------ SpawnEggMeta ------------------------------ \\
- // ------------------------------ FireworkMeta ------------------------------ \\
- public ItemAPI addFireworkEffect(@NotNull FireworkEffect effect) {
- ((FireworkMeta) itemMeta).addEffect(effect);
- return this;
- }
- public ItemAPI addFireWorkEffects(@NotNull FireworkEffect...effects) {
- for (FireworkEffect effect : effects) {
- addFireworkEffect(effect);
- }
- return this;
- }
- public ItemAPI removeFireworkEffect(int i) {
- ((FireworkMeta) itemMeta).removeEffect(i);
- return this;
- }
- public ItemAPI removeFireworkEffects(@NotNull int...indexes) {
- for (int i : indexes) {
- removeFireworkEffect(i);
- }
- return this;
- }
- public ItemAPI setPower(int power) {
- ((FireworkMeta) itemMeta).setPower(power);
- return this;
- }
- // ------------------------------ FireworkMeta ------------------------------ \\
- // ------------------------------- BannerMeta ------------------------------- \\
- public ItemAPI addBannerPattern(@NotNull Pattern pattern) {
- ((BannerMeta) itemMeta).addPattern(pattern);
- return this;
- }
- public ItemAPI addBannerPatterns(@NotNull Pattern...patterns) {
- for (Pattern pattern : patterns) {
- addBannerPattern(pattern);
- }
- return this;
- }
- public ItemAPI removeBannerPattern(int i) {
- ((BannerMeta) itemMeta).removePattern(i);
- return this;
- }
- public ItemAPI removeBannerPatterns(@NotNull int...indexes) {
- for (int i : indexes) {
- removeBannerPattern(i);
- }
- return this;
- }
- public ItemAPI setBannerPattern(int i, @NotNull Pattern pattern) {
- ((BannerMeta) itemMeta).setPattern(i, pattern);
- return this;
- }
- public ItemAPI setBannerPatterns(@NotNull List<Pattern> patterns) {
- ((BannerMeta) itemMeta).setPatterns(patterns);
- return this;
- }
- // ------------------------------- BannerMeta ------------------------------- \\
- // ---------------------------- LeatherArmorMeta ---------------------------- \\
- public ItemAPI setLeatherColor(@NotNull Color color) {
- ((LeatherArmorMeta) itemMeta).setColor(color);
- return this;
- }
- // ---------------------------- LeatherArmorMeta ---------------------------- \\
- // ------------------------------ CrossbowMeta ------------------------------ \\
- public ItemAPI setChargedCrossbowProjectiles(@NotNull List<ItemStack> projectiles) {
- ((CrossbowMeta) itemMeta).setChargedProjectiles(projectiles);
- return this;
- }
- public ItemAPI addChargedCrossbowProjectile(@NotNull ItemStack projectile) {
- ((CrossbowMeta) itemMeta).addChargedProjectile(projectile);
- return this;
- }
- public ItemAPI addChargedCrossbowProjectiles(@NotNull ItemStack...projectiles) {
- for (ItemStack projectile : projectiles) {
- addChargedCrossbowProjectile(projectile);
- }
- return this;
- }
- // ------------------------------ CrossbowMeta ------------------------------ \\
- // -------------------------------- SkullMeta ------------------------------- \\
- @Deprecated public ItemAPI setSkullOwner(@NotNull String owner) {
- ((SkullMeta) itemMeta).setOwner(owner);
- return this;
- }
- public ItemAPI setSkullOwningPlayer(@NotNull OfflinePlayer player) {
- ((SkullMeta) itemMeta).setOwningPlayer(player);
- return this;
- }
- // -------------------------------- SkullMeta ------------------------------- \\
- // --------------------------- SuspiciousStewMeta --------------------------- \\
- public ItemAPI setCustomStewEffect(@NotNull Map<PotionEffect, Boolean> effects) {
- ((SuspiciousStewMeta) itemMeta).getCustomEffects().clear();
- addCustomPotionEffects(effects);
- return this;
- }
- public ItemAPI addCustomStewEffect(@NotNull PotionEffect effect, @NotNull boolean overwrite) {
- ((SuspiciousStewMeta) itemMeta).addCustomEffect(effect, overwrite);
- return this;
- }
- public ItemAPI addCustomStewEffects(@NotNull Map<PotionEffect, Boolean> effects) {
- effects.forEach(this::addCustomStewEffect);
- return this;
- }
- public ItemAPI removeCustomStewEffect(@NotNull PotionEffectType type) {
- ((SuspiciousStewMeta) itemMeta).removeCustomEffect(type);
- return this;
- }
- public ItemAPI removeCustomStewEffects(@NotNull PotionEffectType...types) {
- for (PotionEffectType type : types) {
- removeCustomStewEffect(type);
- }
- return this;
- }
- // --------------------------- SuspiciousStewMeta --------------------------- \\
- // ------------------------- TropicalFishBucketMeta ------------------------- \\
- public ItemAPI setTropicalFishBodyColor(@NotNull DyeColor color) {
- ((TropicalFishBucketMeta) itemMeta).setBodyColor(color);
- return this;
- }
- public ItemAPI setTropicalFishPattern(@NotNull TropicalFish.Pattern pattern) {
- ((TropicalFishBucketMeta) itemMeta).setPattern(pattern);
- return this;
- }
- public ItemAPI setTropicalFishPatternColor(@NotNull DyeColor color) {
- ((TropicalFishBucketMeta) itemMeta).setPatternColor(color);
- return this;
- }
- // ------------------------- TropicalFishBucketMeta ------------------------- \\
- // --------------------------------- MapMeta -------------------------------- \\
- public ItemAPI setMapColor(@NotNull Color color) {
- ((MapMeta) itemMeta).setColor(color);
- return this;
- }
- public ItemAPI setMapLocationName(@NotNull String name) {
- ((MapMeta) itemMeta).setLocationName(name);
- return this;
- }
- @Deprecated public ItemAPI setMapId(int id) {
- ((MapMeta) itemMeta).setMapId(id);
- return this;
- }
- public ItemAPI setMapView(@NotNull MapView view) {
- ((MapMeta) itemMeta).setMapView(view);
- return this;
- }
- public ItemAPI setMapScaling(@NotNull boolean value) {
- ((MapMeta) itemMeta).setScaling(value);
- return this;
- }
- // --------------------------------- MapMeta -------------------------------- \\
- // ---------------------------- FireworkEffectMeta -------------------------- \\
- public ItemAPI setFireworkEffect(@NotNull FireworkEffect effect) {
- ((FireworkEffectMeta) itemMeta).setEffect(effect);
- return this;
- }
- // ---------------------------- FireworkEffectMeta -------------------------- \\
- public ItemStack build() {
- item.setItemMeta(itemMeta);
- return item;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement