Search in sources :

Example 1 with ItemDisplayCreateEvent

use of io.github.bananapuncher714.crafters.events.ItemDisplayCreateEvent in project PublicCrafters by BananaPuncher714.

the class PlayerListener method onItemDisplayCreateEvent.

@EventHandler(priority = EventPriority.HIGHEST)
private void onItemDisplayCreateEvent(ItemDisplayCreateEvent event) {
    if (!plugin.isVirtual()) {
        return;
    }
    ItemDisplay display = event.getItemDisplay();
    VirtualItemDisplay vDisplay = new VirtualItemDisplay(display.getCraftDisplay(), display.getLocation(), display.getItem(), display.getSlot());
    event.setItemDisplay(vDisplay);
}
Also used : VirtualItemDisplay(io.github.bananapuncher714.crafters.display.VirtualItemDisplay) ItemDisplay(io.github.bananapuncher714.crafters.display.ItemDisplay) VirtualItemDisplay(io.github.bananapuncher714.crafters.display.VirtualItemDisplay) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ItemDisplayCreateEvent

use of io.github.bananapuncher714.crafters.events.ItemDisplayCreateEvent in project PublicCrafters by BananaPuncher714.

the class CraftDisplay method update.

/**
 * Don't call this from the ItemDisplayCreateEvent or the ItemDisplayDestroyEvent, as it will cause a stackOverflowException;
 *
 * @param col
 * The columns of a workbench, from left to right, counting 0 to 2
 * @param row
 * The rows of a workbench, from top to bottom, counting 0 to 2
 * @param force
 * Whether or not to force an update if the items in the current slot are similar
 */
public void update(int col, int row, boolean force) {
    List<ItemStack> bukkitItems = inventory.getBukkitItems();
    int index = col + 3 * row;
    ItemStack item = bukkitItems.get(index);
    ItemDisplay display = displays.get(index);
    if (display != null && (display.getItem().getType() == Material.AIR || item.getType() == Material.AIR)) {
        ItemDisplayDestroyEvent event = new ItemDisplayDestroyEvent(display);
        Bukkit.getPluginManager().callEvent(event);
        display.remove();
        displays.set(index, null);
        return;
    }
    if (item.getType() == Material.AIR) {
        return;
    }
    if (force || display == null || !item.isSimilar(display.getItem())) {
        Location newLoc;
        if (item.getType().isBlock()) {
            newLoc = blockLoc.clone().add(.33125 + .2 * (2 - col), height, .13125 + .2 * (2 - row));
        } else {
            newLoc = blockLoc.clone().add(.49125 + .2 * (2 - col), height, .14125 + .2 * (2 - row));
        }
        if (display != null) {
            ItemDisplayDestroyEvent event = new ItemDisplayDestroyEvent(display);
            Bukkit.getPluginManager().callEvent(event);
            display.remove();
        }
        display = new ItemDisplay(this, newLoc, item, index);
        ItemDisplayCreateEvent event = new ItemDisplayCreateEvent(blockLoc.clone(), display);
        Bukkit.getPluginManager().callEvent(event);
        if (event.isCancelled()) {
            displays.set(index, null);
            return;
        }
        display = event.getItemDisplay();
        display.init();
        displays.set(index, display);
    }
}
Also used : ItemDisplayCreateEvent(io.github.bananapuncher714.crafters.events.ItemDisplayCreateEvent) ItemStack(org.bukkit.inventory.ItemStack) ItemDisplayDestroyEvent(io.github.bananapuncher714.crafters.events.ItemDisplayDestroyEvent) Location(org.bukkit.Location)

Aggregations

ItemDisplay (io.github.bananapuncher714.crafters.display.ItemDisplay)1 VirtualItemDisplay (io.github.bananapuncher714.crafters.display.VirtualItemDisplay)1 ItemDisplayCreateEvent (io.github.bananapuncher714.crafters.events.ItemDisplayCreateEvent)1 ItemDisplayDestroyEvent (io.github.bananapuncher714.crafters.events.ItemDisplayDestroyEvent)1 Location (org.bukkit.Location)1 EventHandler (org.bukkit.event.EventHandler)1 ItemStack (org.bukkit.inventory.ItemStack)1