Last active
June 19, 2017 21:20
-
-
Save effective-light/f25e92eb4f46970fef2e to your computer and use it in GitHub Desktop.
Item Creator
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.ChatColor; | |
| import org.bukkit.Material; | |
| import org.bukkit.inventory.ItemStack; | |
| import org.bukkit.inventory.meta.ItemMeta; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| public class ItemCreator | |
| { | |
| private ItemStack itemStack; | |
| private ItemMeta itemMeta; | |
| private List<String> lores = new ArrayList<>(); | |
| public ItemCreator(Material material) | |
| { | |
| this.itemStack = new ItemStack( material ); | |
| this.itemMeta = itemStack.getItemMeta(); | |
| } | |
| /** | |
| * @return Returns the created Item in the form of an {@link ItemStack}. | |
| */ | |
| public ItemStack toItemStack() | |
| { | |
| itemMeta.setLore( lores ); | |
| itemStack.setItemMeta( itemMeta ); | |
| return itemStack; | |
| } | |
| /** | |
| * Sets the {@link ItemMeta#setDisplayName(String)} option with color code translation. | |
| */ | |
| public ItemCreator name(String name) | |
| { | |
| itemMeta.setDisplayName( colorize( name ) ); | |
| return this; | |
| } | |
| /** | |
| * Adds a lore to {@link ItemCreator#lores} after translating color codes. | |
| */ | |
| public ItemCreator lore(String lore) | |
| { | |
| lores.add( colorize( lore ) ); | |
| return this; | |
| } | |
| /** | |
| * Adds a multiple lores to {@link ItemCreator#lores} after translating color codes. | |
| */ | |
| public ItemCreator lores(String... lores) | |
| { | |
| for ( String lore : lores ) | |
| { | |
| lore( lore ); | |
| } | |
| return this; | |
| } | |
| /** | |
| * Sets the {@link org.bukkit.inventory.meta.ItemMeta.Spigot#setUnbreakable(boolean)} option. | |
| */ | |
| public ItemCreator setUnbreakable(boolean value) | |
| { | |
| itemMeta.spigot().setUnbreakable( value ); | |
| return this; | |
| } | |
| private String colorize(String str) | |
| { | |
| return ChatColor.translateAlternateColorCodes( '&', str ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment