use of org.bukkit.inventory.meta.ItemMeta in project MagicPlugin by elBukkit.
the class NMSUtils method addGlow.
public static void addGlow(ItemStack stack) {
if (NMSUtils.isEmpty(stack))
return;
try {
ItemMeta meta = stack.getItemMeta();
meta.addEnchant(Enchantment.LUCK, 1, true);
stack.setItemMeta(meta);
} catch (Throwable ex) {
ex.printStackTrace();
}
}
use of org.bukkit.inventory.meta.ItemMeta in project MagicPlugin by elBukkit.
the class BaseShopAction method clicked.
@Override
public void clicked(InventoryClickEvent event) {
event.setCancelled(true);
ItemStack item = event.getCurrentItem();
Mage mage = context.getMage();
if (item == null || !InventoryUtils.hasMeta(item, "shop")) {
if (!autoClose) {
mage.deactivateGUI();
}
return;
}
int slotIndex = Integer.parseInt(InventoryUtils.getMetaString(item, "shop"));
MageController controller = context.getController();
Wand wand = mage.getActiveWand();
ShopItem shopItem = showingItems.get(slotIndex);
if (shopItem == null) {
return;
}
String unpurchasableMessage = InventoryUtils.getMetaString(shopItem.getItem(), "unpurchasable");
if (unpurchasableMessage != null && !unpurchasableMessage.isEmpty()) {
context.showMessage(unpurchasableMessage);
mage.deactivateGUI();
return;
}
boolean hasCosts = sell ? hasItem(controller, mage, shopItem.getItem()) : hasItemCosts(context, shopItem);
if (!hasCosts) {
String costString = context.getMessage("insufficient", getDefaultMessage(context, "insufficient"));
if (sell) {
costString = costString.replace("$cost", formatItemAmount(controller, item, shopItem.getItem().getAmount()));
} else {
costString = costString.replace("$cost", getItemCost(context, shopItem));
}
context.showMessage(costString);
} else {
String itemName = formatItemAmount(controller, item, item.getAmount());
if (InventoryUtils.hasMeta(item, "confirm")) {
String inventoryTitle = context.getMessage("confirm_title", getDefaultMessage(context, "confirm_title")).replace("$item", itemName);
Inventory confirmInventory = CompatibilityUtils.createInventory(null, 9, inventoryTitle);
InventoryUtils.removeMeta(item, "confirm");
for (int i = 0; i < 9; i++) {
if (i != 4) {
ItemStack filler = confirmFillMaterial.getItemStack(1);
ItemMeta meta = filler.getItemMeta();
if (meta != null) {
meta.setDisplayName(ChatColor.DARK_GRAY + (i < 4 ? "-->" : "<--"));
filler.setItemMeta(meta);
}
confirmInventory.setItem(i, filler);
} else {
confirmInventory.setItem(i, item);
}
}
mage.deactivateGUI();
isActive = true;
mage.activateGUI(this, confirmInventory);
return;
}
String costString = context.getMessage("deducted", getDefaultMessage(context, "deducted"));
if (sell) {
costString = costString.replace("$cost", getItemCost(context, shopItem));
removeItems(controller, mage, item, shopItem.getItem().getAmount());
giveCosts(context, shopItem);
} else {
costString = costString.replace("$cost", getItemCost(context, shopItem));
item = shopItem.getItem();
if (requireWand) {
if (wand == null) {
context.showMessage("no_wand", getDefaultMessage(context, "no_wand"));
mage.deactivateGUI();
return;
}
if (applyToWand && !wand.addItem(item)) {
String inapplicable = context.getMessage("not_applicable", getDefaultMessage(context, "not_applicable")).replace("$item", itemName);
context.showMessage(inapplicable);
mage.deactivateGUI();
return;
}
}
CasterProperties caster = getCaster(context);
if (applyToCaster && !caster.addItem(item)) {
String inapplicable = context.getMessage("not_applicable", getDefaultMessage(context, "not_applicable")).replace("$item", itemName);
context.showMessage(inapplicable);
mage.deactivateGUI();
return;
}
if (castsSpells) {
Spell spell = null;
String spellKey = controller.getSpell(item);
String spellArgs = controller.getSpellArgs(item);
spell = mage.getSpell(spellKey);
if (spell != null && (spellArgs != null ? !spell.cast(StringUtils.split(spellArgs, ' ')) : !spell.cast())) {
context.showMessage("cast_fail", getDefaultMessage(context, "cast_fail"));
mage.deactivateGUI();
return;
}
}
if (!takeCosts(context, shopItem)) {
costString = context.getMessage("insufficient", getDefaultMessage(context, "insufficient"));
costString = costString.replace("$cost", getItemCost(context, shopItem));
context.showMessage(costString);
return;
}
if (!castsSpells && !applyToWand && !applyToCaster) {
ItemStack copy = InventoryUtils.getCopy(item);
if (filterBound && com.elmakers.mine.bukkit.wand.Wand.isBound(copy)) {
Wand bindWand = controller.getWand(copy);
mage.tryToOwn(bindWand);
}
if (showActiveIcons && controller.getAPI().isWand(copy)) {
Wand newWand = controller.getWand(copy);
com.elmakers.mine.bukkit.api.block.MaterialAndData inactiveIcon = newWand.getInactiveIcon();
if (inactiveIcon != null) {
inactiveIcon.applyToItem(copy);
}
}
Player player = mage.getPlayer();
if (putInHand) {
context.getController().giveItemToPlayer(player, copy);
} else {
PlayerInventory inventory = player.getInventory();
ItemStack inHand = inventory.getItemInMainHand();
Integer freeSlot = null;
if (InventoryUtils.isEmpty(inHand)) {
for (int i = 0; i < inventory.getSize() && freeSlot == null; i++) {
if (i != inventory.getHeldItemSlot() && InventoryUtils.isEmpty(inventory.getItem(i))) {
freeSlot = i;
}
}
}
if (freeSlot == null) {
context.getController().giveItemToPlayer(player, copy);
} else {
inventory.setItem(freeSlot, copy);
}
}
}
}
costString = costString.replace("$item", itemName);
context.showMessage(costString);
if (!sell && wand != null && autoUpgrade) {
if (upgradeLevels <= 0) {
com.elmakers.mine.bukkit.api.wand.WandUpgradePath path = wand.getPath();
WandUpgradePath nextPath = path != null ? path.getUpgrade() : null;
if (nextPath != null && path.checkUpgradeRequirements(wand, null) && !path.canEnchant(wand)) {
path.upgrade(wand, mage);
}
} else {
wand.enchant(upgradeLevels, mage, false);
}
}
finalResult = SpellResult.CAST;
onPurchase(context, item);
}
if (autoClose) {
mage.deactivateGUI();
} else {
// update title
mage.continueGUI(this, getInventory(context));
}
}
use of org.bukkit.inventory.meta.ItemMeta in project MagicPlugin by elBukkit.
the class BaseShopAction method showItems.
public SpellResult showItems(CastContext context, List<ShopItem> items) {
Mage mage = context.getMage();
this.context = context;
Player player = mage.getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
this.showingItems = new HashMap<>();
// Load items
itemStacks = new ArrayList<>();
String costString = context.getMessage("cost_lore", "Costs: $cost");
for (ShopItem shopItem : items) {
int currentSlot = itemStacks.size();
if (filterBound && shopItem != null) {
String template = com.elmakers.mine.bukkit.wand.Wand.getWandTemplate(shopItem.getItem());
if (template != null && mage.getBoundWand(template) != null) {
shopItem = null;
}
}
if (shopItem == null) {
this.showingItems.put(currentSlot, null);
itemStacks.add(new ItemStack(Material.AIR));
continue;
}
ItemStack item = InventoryUtils.getCopy(shopItem.getItem());
if (item == null)
continue;
String permission = shopItem.getPermission();
if (permission != null && !permission.isEmpty() && !player.hasPermission(permission)) {
continue;
}
ItemMeta meta = item.getItemMeta();
if (meta == null) {
itemStacks.add(item);
continue;
}
List<String> lore = meta.getLore();
if (lore == null) {
lore = new ArrayList<>();
}
String costs = costString.replace("$cost", getItemCost(context, shopItem));
lore.add(ChatColor.GOLD + costs);
meta.setLore(lore);
item.setItemMeta(meta);
item = InventoryUtils.makeReal(item);
InventoryUtils.setMeta(item, "shop", Integer.toString(currentSlot));
if (showConfirmation) {
InventoryUtils.setMeta(item, "confirm", "true");
}
this.showingItems.put(currentSlot, shopItem);
itemStacks.add(item);
}
if (itemStacks.size() == 0) {
context.showMessage("no_items", getDefaultMessage(context, "no_items"));
return SpellResult.FAIL;
}
isActive = true;
finalResult = SpellResult.NO_ACTION;
Inventory displayInventory = getInventory(context);
mage.activateGUI(this, displayInventory);
return SpellResult.PENDING;
}
use of org.bukkit.inventory.meta.ItemMeta in project MagicPlugin by elBukkit.
the class InventoryUtils method getURLSkull.
@SuppressWarnings("deprecation")
public static ItemStack getURLSkull(URL url, String ownerName, UUID id, String itemName) {
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 0, (byte) 3);
if (itemName != null) {
ItemMeta meta = skull.getItemMeta();
meta.setDisplayName(itemName);
skull.setItemMeta(meta);
}
try {
skull = makeReal(skull);
Object skullOwner = createNode(skull, "SkullOwner");
setMeta(skullOwner, "Name", ownerName);
setSkullURL(skull, url, id);
} catch (Exception ex) {
ex.printStackTrace();
}
return skull;
}
use of org.bukkit.inventory.meta.ItemMeta in project MassiveCore by MassiveCraft.
the class MsonEvent method getItemSanitizedForTooltip.
private static ItemStack getItemSanitizedForTooltip(ItemStack item) {
if (item == null)
throw new NullPointerException("item");
if (!item.hasItemMeta())
return item;
ItemMeta meta = item.getItemMeta();
if (meta instanceof BookMeta) {
BookMeta book = (BookMeta) meta;
book.setPages();
item = item.clone();
item.setItemMeta(meta);
return item;
}
return item;
}
Aggregations