Java 类org.bukkit.event.inventory.PrepareAnvilEvent 实例源码

项目:Enhanced-Items    文件:EnhancedItemsEvents.java   
@EventHandler
public void onPrepareAnvil(PrepareAnvilEvent event)
{
    ItemStack itemStack = event.getInventory().getItem(0);

    if(itemStack != null)
    {
        EnhancedItem item = EnhancedItemUtil.getItem(itemStack);

        if(item != null)
        {
            if(!Boolean.parseBoolean(item.getProperty("canModify")))
            {
                event.setResult(new ItemStack(Material.AIR));

                ((Player)event.getView().getPlayer()).updateInventory();
            }
        }
    }
}
项目:SharpSK    文件:ExprEventAnvilCost.java   
@Override
public boolean init(Expression<?>[] e, int arg1, Kleenean arg2, ParseResult arg3) {
    if (!ScriptLoader.isCurrentEvent(PrepareAnvilEvent.class)) {
        return false;
    } else {
        return true;
    }
}
项目:SharpSK    文件:ExprEventAnvilCost.java   
@Override
@Nullable
protected Number[] get(Event e) {
    try {
        AnvilInventory a = ((PrepareAnvilEvent) e).getInventory();
        return new Number[] { a.getRepairCost() };
    } catch (NullPointerException ex) {
        return new Number[] { 0 };
    }
}
项目:Skellett    文件:ExprAnvilPrepareInventory.java   
@Override
public boolean init(Expression<?>[] e, int arg1, Kleenean arg2, ParseResult arg3) {
    if (!ScriptLoader.isCurrentEvent(PrepareAnvilEvent.class)) {
        Skript.error("You can not use anvil inventory expression in any event but anvil prepare event!");
        return false;
    }
    return true;
}
项目:EnchantmentAPI    文件:AnvilListener.java   
@EventHandler
public void onCombine(final PrepareAnvilEvent event) {
    final ItemStack first = event.getInventory().getItem(0);
    final ItemStack second = event.getInventory().getItem(1);
    if (isSingle(first) && isSingle(second)) {
        final ItemStack result = select(first, second, true).clone();
        final EnchantmentMerger merger = getMerger(event.getInventory());
        if (merger.getCustomCost() != 0 || merger.getVanillaCost() != 0) {
            event.setResult(merger.apply(result));
            event.getInventory().setRepairCost(merger.getCost());
        }
    }

    if (isPresent(event.getResult())) {
        String text = event.getInventory().getRenameText();

        final ItemStack primary = select(first, second, true);
        if (primary.hasItemMeta()) {
            final ItemMeta primaryMeta = primary.getItemMeta();
            if (primaryMeta.hasDisplayName()) {
                final String withoutColorChar = primaryMeta.getDisplayName().replace("" + ChatColor.COLOR_CHAR, "");
                if (withoutColorChar.equals(event.getInventory().getRenameText())) {
                    text = primaryMeta.getDisplayName();
                }
            }
        }


        final ItemMeta meta = event.getResult().getItemMeta();
        meta.setDisplayName(colored ? TextFormatter.colorString(text) : text);
        event.getResult().setItemMeta(meta);
    }
}
项目:Skellett    文件:ExprAnvilPrepareInventory.java   
@Override
@Nullable
protected AnvilInventory[] get(Event e) {
    return new AnvilInventory[]{((PrepareAnvilEvent)e).getInventory()};
}
项目:SpigotSource    文件:CraftEventFactory.java   
public static PrepareAnvilEvent callPrepareAnvilEvent(InventoryView view, ItemStack item) {
    PrepareAnvilEvent event = new PrepareAnvilEvent(view, CraftItemStack.asCraftMirror(item).clone());
    event.getView().getPlayer().getServer().getPluginManager().callEvent(event);
    event.getInventory().setItem(2, event.getResult());
    return event;
}