Search in sources :

Example 1 with ItemDisplayDestroyEvent

use of io.github.bananapuncher714.crafters.events.ItemDisplayDestroyEvent 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)

Example 2 with ItemDisplayDestroyEvent

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

the class CraftDisplay method stop.

/**
 * Simply stops each of the 9 ItemDisplays this is responsible for
 */
public void stop() {
    Bukkit.getPluginManager().callEvent(new CraftDisplayDestroyEvent(this));
    for (ItemDisplay display : displays) {
        if (display != null) {
            ItemDisplayDestroyEvent event = new ItemDisplayDestroyEvent(display);
            Bukkit.getPluginManager().callEvent(event);
            display.remove();
        }
    }
    if (resultDisplay != null) {
        resultDisplay.remove();
    }
}
Also used : CraftDisplayDestroyEvent(io.github.bananapuncher714.crafters.events.CraftDisplayDestroyEvent) ItemDisplayDestroyEvent(io.github.bananapuncher714.crafters.events.ItemDisplayDestroyEvent)

Aggregations

ItemDisplayDestroyEvent (io.github.bananapuncher714.crafters.events.ItemDisplayDestroyEvent)2 CraftDisplayDestroyEvent (io.github.bananapuncher714.crafters.events.CraftDisplayDestroyEvent)1 ItemDisplayCreateEvent (io.github.bananapuncher714.crafters.events.ItemDisplayCreateEvent)1 Location (org.bukkit.Location)1 ItemStack (org.bukkit.inventory.ItemStack)1