/** * This event makes sure that any acid bottles become potions without the * warning * * @param e */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBrewComplete(final BrewEvent e) { if (DEBUG) plugin.getLogger().info("DEBUG: " + e.getEventName()); if (e.getBlock().getWorld().getName().equalsIgnoreCase(Settings.worldName)) { //if (Settings.acidBottle && Settings.acidDamage>0 && e.getBlock().getWorld().getName().equalsIgnoreCase(Settings.worldName)) { plugin.getLogger().info("DEBUG: Brew Event called"); BrewerInventory inv = e.getContents(); int i = 0; for (ItemStack item : inv.getContents()) { if (item != null) { // Remove lore ItemMeta meta = item.getItemMeta(); plugin.getLogger().info("DEBUG: " + meta.getDisplayName()); meta.setDisplayName(null); inv.setItem(i, item); } i++; } } }
private boolean fillWaterBottle(BrewerInventory brewingInventory, InventoryManager manager) { if (!(manager.findMaterial(Material.WATER_BUCKET) && manager.findMaterial(Material.GLASS_BOTTLE))) return false; for (int i = 0; i < 3; i++) { ItemStack item = brewingInventory.getItem(i); if (item == null || item.getType() == Material.AIR) { // Add potion to the first empty potion slot in the brewing // stand. item = new ItemStack(Material.POTION); brewingInventory.setItem(i, item); manager.decrement(); age = 0; return true; } } return false; }
private static boolean removeIngredient(BrewerInventory inventory, Player player) { ItemStack ingredient = inventory.getIngredient() == null ? null : inventory.getIngredient().clone(); if (isEmpty(ingredient) || !isValidIngredient(player, ingredient)) { return false; } else if (ingredient.getAmount() <= 1) { inventory.setIngredient(null); return true; } else { ingredient.setAmount(ingredient.getAmount() - 1); inventory.setIngredient(ingredient); return true; } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onBrew(BrewEvent event) { /* * if (!testValidity(event.getContents().getContents())) { event.setCancelled(true); event.getContents().getHolder().setBrewingTime(EMPTY_BREW_TIME); } */ // *** Version that works with a Spigot version that does not // *** have a BrewEvent#getResults() method: BrewerInventory inventory = event.getContents(); ItemStack[] contents = inventory.getContents(); int length = contents.length; ItemStack[] cloned = new ItemStack[length]; for (int i = 0; i < length; i++) { ItemStack previous = contents[i]; cloned[i] = (previous == null ? null : previous.clone()); } BrewingStand stand = inventory.getHolder(); Bukkit.getScheduler().runTask(HCF.getPlugin(), () -> { if (!testValidity(inventory.getContents())) { stand.setBrewingTime(EMPTY_BREW_TIME); inventory.setContents(cloned); } }); }
@EventHandler public void onBrew(BrewEvent event) { BrewerInventory inv = event.getContents(); // if the inventory doesn't contain glowstone AND a strength potion, return. if (!containsStrengthOrGlowstone(inv)) { return; } // cancel. event.setCancelled(true); Block block = event.getBlock(); Location blockL = block.getLocation(); // loop thru everyone online. for (Player online : Bukkit.getOnlinePlayers()) { Location playerL = online.getLocation(); // if they're within a radius send them a message. if (block.getWorld() == online.getWorld() && playerL.distance(blockL) < 15) { online.sendMessage(ChatColor.RED + "Strength II is disabled, brewing cancelled."); } } }
/** * Check if the given inventory contains the ingrediens for strength 2. * * @param inv The inventory checking. * @return True if it does, false otherwise. */ public boolean containsStrengthOrGlowstone(BrewerInventory inv) { boolean glowstone = false; boolean potion = false; // loop thru all items in the inventory. for (ItemStack item : inv.getContents()) { // if the item is null, hop over it. if (item == null) { continue; } // the item is a glowstone, set that to true. if (item.getType() == Material.GLOWSTONE_DUST) { glowstone = true; } // from now we don't want to care if its not a potion. if (item.getType() != Material.POTION) { continue; } // if the potion has the durability of a strength potion, set potion to true. if (item.getDurability() == 8265 || item.getDurability() == 8201) { potion = true; } } // return true if it had glowstone AND a strenght potion return glowstone && potion; }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onInventoryDragEvent(InventoryDragEvent event) { Inventory inventory = event.getInventory(); if (!(inventory instanceof BrewerInventory)) { return; } InventoryHolder holder = inventory.getHolder(); if (!(holder instanceof BrewingStand)) { return; } HumanEntity whoClicked = event.getWhoClicked(); if (!UserManager.hasPlayerDataKey(event.getWhoClicked()) || !Permissions.secondaryAbilityEnabled(whoClicked, SecondaryAbility.CONCOCTIONS)) { return; } if (!event.getInventorySlots().contains(Alchemy.INGREDIENT_SLOT)) { return; } ItemStack cursor = event.getCursor(); ItemStack ingredient = ((BrewerInventory) inventory).getIngredient(); if (AlchemyPotionBrewer.isEmpty(ingredient) || ingredient.isSimilar(cursor)) { Player player = (Player) whoClicked; if (AlchemyPotionBrewer.isValidIngredient(player, cursor)) { // Not handled: dragging custom ingredients over ingredient slot (does not trigger any event) AlchemyPotionBrewer.scheduleCheck(player, (BrewingStand) holder); return; } event.setCancelled(true); AlchemyPotionBrewer.scheduleUpdate(inventory); } }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onInventoryMoveItemEvent(InventoryMoveItemEvent event) { Inventory inventory = event.getDestination(); if (!(inventory instanceof BrewerInventory)) { return; } InventoryHolder holder = inventory.getHolder(); if (!(holder instanceof BrewingStand)) { return; } ItemStack item = event.getItem(); if (Config.getInstance().getPreventHopperTransferIngredients() && item.getType() != Material.POTION) { event.setCancelled(true); return; } if (Config.getInstance().getPreventHopperTransferBottles() && item.getType() == Material.POTION) { event.setCancelled(true); return; } if (Config.getInstance().getEnabledForHoppers() && AlchemyPotionBrewer.isValidIngredient(null, item)) { AlchemyPotionBrewer.scheduleCheck(null, (BrewingStand) holder); } }
@EventHandler(priority = EventPriority.NORMAL) public void onInventoryMoveItem (InventoryMoveItemEvent event) { if ( ! (event.getInitiator() instanceof PlayerInventory) || ! (event.getDestination() instanceof BrewerInventory)) return; if (event.getItem().getType() != Material.QUARTZ) return; event.setCancelled(true); int amount = event.getItem().getAmount(); ItemStack[] inv = event.getInitiator().getContents(); for (int i = 0; i < inv.length; i++) { ItemStack item = inv[i]; if (item.getType() != Material.QUARTZ) continue; if (item.getAmount() == amount) { inv[i] = null; } else { item.setAmount(item.getAmount() - amount); } } event.getInitiator().setContents(inv); event.getDestination().setItem(3, new ItemStack(Material.QUARTZ, amount)); }
public BrewerInventory getInventory() { return new CraftInventoryBrewer(brewingStand); }
@EventHandler public void onOpen(InventoryOpenEvent e) { if(e.getInventory().getType() == InventoryType.BREWING) { ((BrewerInventory)e.getInventory()).setFuel(new ItemStack(Material.BLAZE_POWDER, 64)); } }
public BrewEvent(Block brewer, BrewerInventory contents) { super(brewer); this.contents = contents; }
@SuppressWarnings("unchecked") @Override public boolean init(Expression<?>[] e, int matchedPattern, Kleenean isDelayed, ParseResult parser) { inventory = (Expression<BrewerInventory>) e[0]; return true; }
@Override public Class<? extends BrewerInventory> getReturnType() { return BrewerInventory.class; }
@Override @Nullable protected BrewerInventory[] get(Event e) { return new BrewerInventory[]{((BrewEvent)e).getContents()}; }
public FakeBrewEvent(Block brewer, BrewerInventory contents) { super(brewer, contents); }
@Override public BrewerInventory getInventory() { return PoreBrewerInventory.of(getTileEntity().getInventory()); }
@Override public BrewerInventory getContents() { return PoreBrewerInventory.of(this.getHandle().getInventory()); }