use of org.bukkit.inventory.meta.SkullMeta in project LandLord by SpatiumPrinceps.
the class AbstractManage method createSkull.
private ItemStack createSkull(String owner, String displayname, List<String> lore) {
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
skullMeta.setOwner(owner);
skullMeta.setDisplayName(displayname);
skullMeta.setLore(lore);
skull.setItemMeta(skullMeta);
return skull;
}
use of org.bukkit.inventory.meta.SkullMeta in project Prism-Bukkit by prism.
the class ItemStackAction method setItem.
/**
* Set the item.
* @param item ItemStack
* @param quantity int
* @param enchantments Map of enchants.
*/
public void setItem(ItemStack item, int quantity, Map<Enchantment, Integer> enchantments) {
actionData = new ItemStackActionData();
if (enchantments != null) {
this.enchantments = enchantments;
}
if (item == null || item.getAmount() <= 0) {
this.setCanceled(true);
return;
}
this.item = item;
if (enchantments == null) {
this.enchantments = item.getEnchantments();
}
// Set basics
setMaterial(item.getType());
actionData.durability = (short) ItemUtils.getItemDamage(item);
if (tempDurability >= 0) {
actionData.durability = tempDurability;
tempDurability = -1;
}
actionData.amt = quantity;
final ItemMeta meta = item.hasItemMeta() ? item.getItemMeta() : null;
if (meta != null) {
actionData.name = meta.getDisplayName();
}
if (meta instanceof LeatherArmorMeta) {
final LeatherArmorMeta lam = (LeatherArmorMeta) meta;
actionData.color = lam.getColor().asRGB();
} else if (meta instanceof SkullMeta) {
final SkullMeta skull = (SkullMeta) meta;
if (skull.hasOwner()) {
actionData.owner = Objects.requireNonNull(skull.getOwningPlayer()).getUniqueId().toString();
}
} else if (meta instanceof PotionMeta) {
final PotionMeta potion = (PotionMeta) meta;
actionData.potionType = potion.getBasePotionData().getType().toString().toLowerCase();
actionData.potionExtended = potion.getBasePotionData().isExtended();
actionData.potionUpgraded = potion.getBasePotionData().isUpgraded();
}
// Written books
if (meta instanceof BookMeta) {
final BookMeta bookMeta = (BookMeta) meta;
actionData.by = bookMeta.getAuthor();
actionData.title = bookMeta.getTitle();
actionData.content = bookMeta.getPages().toArray(new String[0]);
}
// Lore
if (meta != null && meta.hasLore()) {
actionData.lore = Objects.requireNonNull(meta.getLore()).toArray(new String[0]);
}
// Enchantments
if (!this.enchantments.isEmpty()) {
final String[] enchs = new String[this.enchantments.size()];
int i = 0;
for (final Entry<Enchantment, Integer> ench : this.enchantments.entrySet()) {
// This is silly
enchs[i] = ench.getKey().getKey().getKey() + ":" + ench.getValue();
i++;
}
actionData.enchs = enchs;
} else if (meta instanceof EnchantmentStorageMeta) {
final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) meta;
if (bookEnchantments.hasStoredEnchants()) {
if (bookEnchantments.getStoredEnchants().size() > 0) {
final String[] enchs = new String[bookEnchantments.getStoredEnchants().size()];
int i = 0;
for (final Entry<Enchantment, Integer> ench : bookEnchantments.getStoredEnchants().entrySet()) {
// This is absolutely silly
enchs[i] = ench.getKey().getKey().getKey() + ":" + ench.getValue();
i++;
}
actionData.enchs = enchs;
}
}
}
if (meta instanceof FireworkEffectMeta) {
applyFireWorksMetaToActionData(meta);
}
if (meta instanceof BannerMeta) {
List<Pattern> patterns = ((BannerMeta) meta).getPatterns();
Map<String, String> stringyPatterns = new HashMap<>();
patterns.forEach(pattern -> stringyPatterns.put(pattern.getPattern().getIdentifier(), pattern.getColor().name()));
actionData.bannerMeta = stringyPatterns;
}
}
use of org.bukkit.inventory.meta.SkullMeta in project Denizen-For-Bukkit by DenizenScript.
the class HeadCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
Deprecations.headCommand.warn(scriptEntry);
List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
ElementTag skin = scriptEntry.getElement("skin");
MaterialTag material = scriptEntry.getObjectTag("material");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("entities", entities), skin, material);
}
ItemStack item = null;
if (skin != null) {
item = new ItemStack(Material.PLAYER_HEAD);
ItemMeta itemMeta = item.getItemMeta();
((SkullMeta) itemMeta).setOwner(skin.asString());
item.setItemMeta(itemMeta);
} else if (material != null) {
item = new ItemStack(material.getMaterial());
}
for (EntityTag entity : entities) {
if (entity.isCitizensNPC()) {
if (!entity.getDenizenNPC().getCitizen().hasTrait(Equipment.class)) {
entity.getDenizenNPC().getCitizen().addTrait(Equipment.class);
}
Equipment trait = entity.getDenizenNPC().getCitizen().getOrAddTrait(Equipment.class);
trait.set(1, item);
} else if (entity.isPlayer()) {
entity.getPlayer().getInventory().setHelmet(item);
} else {
if (entity.isLivingEntity() && entity.getLivingEntity().getEquipment() != null) {
entity.getLivingEntity().getEquipment().setHelmet(item);
} else {
Debug.echoError(scriptEntry, entity.identify() + " is not a living entity!");
}
}
}
}
use of org.bukkit.inventory.meta.SkullMeta in project FunnyGuilds by FunnyGuilds.
the class Parser method parseItem.
public static ItemStack parseItem(String string) {
String[] split = string.split(" ");
String[] typeSplit = split[1].split(":");
String subtype = typeSplit.length > 1 ? typeSplit[1] : "0";
Material mat = parseMaterial(typeSplit[0], false);
int stack;
int data;
try {
stack = Integer.parseInt(split[0]);
data = Integer.parseInt(subtype);
} catch (NumberFormatException e) {
FunnyLogger.parser("Unknown size: " + split[0]);
stack = 1;
data = 0;
}
ItemBuilder item = new ItemBuilder(mat, stack, data);
for (int i = 2; i < split.length; i++) {
String str = split[i];
if (str.contains("name")) {
String[] splitName = str.split(":");
item.setName(StringUtils.replace(StringUtils.colored(String.join(":", Arrays.copyOfRange(splitName, 1, splitName.length))), "_", " "), true);
} else if (str.contains("lore")) {
String[] splitLore = str.split(":");
String loreArgs = String.join(":", Arrays.copyOfRange(splitLore, 1, splitLore.length));
String[] lores = loreArgs.split("#");
List<String> lore = new ArrayList<>();
for (String s : lores) {
lore.add(StringUtils.replace(StringUtils.replace(StringUtils.colored(s), "_", " "), "{HASH}", "#"));
}
item.setLore(lore);
} else if (str.contains("enchant")) {
String[] parse = str.split(":");
String enchantName = parse[1];
int level;
try {
level = Integer.parseInt(parse[2]);
} catch (NumberFormatException e) {
FunnyLogger.parser("Unknown enchant level: " + split[2]);
level = 1;
}
Enchantment enchant = Enchantment.getByName(enchantName.toUpperCase());
if (enchant == null) {
FunnyLogger.parser("Unknown enchant: " + parse[1]);
}
item.addEnchant(enchant, level);
} else if (str.contains("skullowner")) {
if (item.getMeta() instanceof SkullMeta) {
((SkullMeta) item.getMeta()).setOwner(str.split(":")[1]);
item.refreshMeta();
}
} else if (str.contains("armorcolor")) {
if (item.getMeta() instanceof LeatherArmorMeta) {
String[] color = str.split(":")[1].split("_");
try {
((LeatherArmorMeta) item.getMeta()).setColor(Color.fromRGB(Integer.parseInt(color[0]), Integer.parseInt(color[1]), Integer.parseInt(color[2])));
item.refreshMeta();
} catch (NumberFormatException e) {
FunnyLogger.parser("Unknown armor color: " + str.split(":")[1]);
}
}
} else if (str.contains("eggtype")) {
if (EggTypeChanger.needsSpawnEggMeta()) {
EntityType type = null;
try {
type = EntityType.valueOf(str.split(":")[1].toUpperCase());
} catch (Exception e) {
FunnyLogger.parser("Unknown entity type: " + str.split(":")[1].toUpperCase());
}
if (type != null) {
EggTypeChanger.applyChanges(item.getMeta(), type);
item.refreshMeta();
}
} else {
FunnyLogger.info("This MC version supports metadata for spawn egg type, no need to use eggtype in item creation!");
}
}
}
return item.getItem();
}
use of org.bukkit.inventory.meta.SkullMeta in project EliteMobs by MagmaGuy.
the class ItemStackGenerator method generateSkullItemStack.
public static ItemStack generateSkullItemStack(String owner, String name, List<String> lore) {
ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD);
SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
skullMeta.setOwner(owner);
skullMeta.setDisplayName(name);
skullMeta.setLore(lore);
itemStack.setItemMeta(skullMeta);
return itemStack;
}
Aggregations