Search in sources :

Example 1 with ItemDisplay

use of io.github.bananapuncher714.crafters.display.ItemDisplay in project PublicCrafters by BananaPuncher714.

the class InventoryOpenListener method onEntityInteractEvent.

/**
 * See {@link ItemDisplay} for registering and unregistering entities that open a workbench on interaction.
 *
 * @param event
 * The PlayerInteractEvent
 */
@EventHandler(priority = EventPriority.LOWEST)
private void onEntityInteractEvent(PlayerInteractAtEntityEvent event) {
    Entity entity = event.getRightClicked();
    ItemDisplay display = ItemDisplay.getItemDisplay(entity.getUniqueId());
    if (display == null) {
        return;
    }
    event.setCancelled(true);
    Player player = event.getPlayer();
    PlayerInteractEvent PIE = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, player.getItemInHand(), display.getCraftDisplay().getLocation().getBlock(), BlockFace.UP);
    Bukkit.getPluginManager().callEvent(PIE);
}
Also used : HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) ItemDisplay(io.github.bananapuncher714.crafters.display.ItemDisplay) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ItemDisplay

use of io.github.bananapuncher714.crafters.display.ItemDisplay 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 3 with ItemDisplay

use of io.github.bananapuncher714.crafters.display.ItemDisplay in project PublicCrafters by BananaPuncher714.

the class CraftingListener method onCraftDisplayUpdateEvent.

@EventHandler
public void onCraftDisplayUpdateEvent(CraftDisplayUpdateEvent event) {
    CraftDisplay craftDisplay = event.getDisplay();
    ItemDisplay display = craftDisplay.getItemDisplays().get(4);
    if (display == null) {
        return;
    }
    Material result = craftDisplay.getInventory().getResult().getType();
    if ((result != Material.DIAMOND_CHESTPLATE && display instanceof CustomItemDisplay) || (!(display instanceof CustomItemDisplay) && display.getItem().getType() == Material.DIAMOND && result == Material.DIAMOND_CHESTPLATE)) {
        event.getDisplay().update(1, 1, true);
    }
}
Also used : CustomItemDisplay(io.github.bananapuncher714.crafters.example.objects.CustomItemDisplay) CraftDisplay(io.github.bananapuncher714.crafters.display.CraftDisplay) ItemDisplay(io.github.bananapuncher714.crafters.display.ItemDisplay) CustomItemDisplay(io.github.bananapuncher714.crafters.example.objects.CustomItemDisplay) Material(org.bukkit.Material) EventHandler(org.bukkit.event.EventHandler)

Example 4 with ItemDisplay

use of io.github.bananapuncher714.crafters.display.ItemDisplay 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 5 with ItemDisplay

use of io.github.bananapuncher714.crafters.display.ItemDisplay 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

ItemDisplay (io.github.bananapuncher714.crafters.display.ItemDisplay)3 EventHandler (org.bukkit.event.EventHandler)3 ItemDisplayDestroyEvent (io.github.bananapuncher714.crafters.events.ItemDisplayDestroyEvent)2 CraftDisplay (io.github.bananapuncher714.crafters.display.CraftDisplay)1 VirtualItemDisplay (io.github.bananapuncher714.crafters.display.VirtualItemDisplay)1 CraftDisplayDestroyEvent (io.github.bananapuncher714.crafters.events.CraftDisplayDestroyEvent)1 ItemDisplayCreateEvent (io.github.bananapuncher714.crafters.events.ItemDisplayCreateEvent)1 CustomItemDisplay (io.github.bananapuncher714.crafters.example.objects.CustomItemDisplay)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 Entity (org.bukkit.entity.Entity)1 HumanEntity (org.bukkit.entity.HumanEntity)1 Player (org.bukkit.entity.Player)1 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)1 ItemStack (org.bukkit.inventory.ItemStack)1