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);
}
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);
}
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);
}
}
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);
}
}
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();
}
}
Aggregations