org.bukkit.event.inventory.BrewEvent Java Examples
The following examples show how to use
org.bukkit.event.inventory.BrewEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayerListener.java From civcraft with GNU General Public License v2.0 | 6 votes |
@EventHandler(priority = EventPriority.LOW) public void OnBrewEvent(BrewEvent event) { /* Hardcoded disables based on ingredients used. */ if (event.getContents().contains(Material.SPIDER_EYE) || event.getContents().contains(Material.GOLDEN_CARROT) || event.getContents().contains(Material.GHAST_TEAR) || event.getContents().contains(Material.FERMENTED_SPIDER_EYE) || event.getContents().contains(Material.BLAZE_POWDER) || event.getContents().contains(Material.SULPHUR)) { event.setCancelled(true); } if (event.getContents().contains(Material.POTION)) { ItemStack potion = event.getContents().getItem(event.getContents().first(Material.POTION)); if (potion.getDurability() == CivData.MUNDANE_POTION_DATA || potion.getDurability() == CivData.MUNDANE_POTION_EXT_DATA || potion.getDurability() == CivData.THICK_POTION_DATA) { event.setCancelled(true); } } }
Example #2
Source File: AcidInventory.java From askyblock with GNU General Public License v2.0 | 6 votes |
/** * This event makes sure that any acid bottles become potions without the * warning * * @param e - event */ @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++; } } }
Example #3
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onBrewing(BrewEvent e) { ItemStack[] cont = e.getContents().getContents(); for (int i = 0; i < cont.length; i++) { if (RedProtect.get().getUtil().denyPotion(cont[i], e.getBlock().getWorld())) { e.getContents().setItem(i, new ItemStack(Material.AIR)); } } }
Example #4
Source File: LugolsIodinePotion.java From CraftserveRadiation with Apache License 2.0 | 4 votes |
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBrew(BrewEvent event) { if (!config.recipe.enabled) { return; } BrewerInventory inventory = event.getContents(); BrewingStandWindow window = BrewingStandWindow.fromArray(inventory.getContents()); if (!window.ingredient.getType().equals(config.recipe.ingredient)) { return; } boolean[] modified = new boolean[BrewingStandWindow.SLOTS]; for (int i = 0; i < BrewingStandWindow.SLOTS; i++) { ItemStack result = window.results[i]; if (result == null) { continue; // nothing in this slot } ItemMeta itemMeta = result.getItemMeta(); if (!(itemMeta instanceof PotionMeta)) { continue; } PotionMeta potionMeta = (PotionMeta) itemMeta; if (potionMeta.getBasePotionData().getType().equals(config.recipe.basePotion)) { result.setItemMeta(this.convert(potionMeta)); modified[i] = true; } } // delay this, because nms changes item stacks after BrewEvent is called this.plugin.getServer().getScheduler().runTask(this.plugin, () -> { for (int i = 0; i < BrewingStandWindow.SLOTS; i++) { if (modified[i]) { ItemStack[] contents = inventory.getContents(); contents[i] = window.getResult(i); inventory.setContents(contents); } } }); }
Example #5
Source File: BrewingTaskType.java From Quests with MIT License | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlace(BrewEvent event) { UUID uuid; if ((uuid = brewingStands.get(event.getBlock().getLocation())) != null) { Player player = Bukkit.getPlayer(uuid); if (player == null) { return; } QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId(), true); QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile(); for (Quest quest : super.getRegisteredQuests()) { if (questProgressFile.hasStartedQuest(quest)) { QuestProgress questProgress = questProgressFile.getQuestProgress(quest); for (Task task : quest.getTasksOfType(super.getType())) { TaskProgress taskProgress = questProgress.getTaskProgress(task.getId()); if (taskProgress.isCompleted()) { continue; } int potionsNeeded = (int) task.getConfigValue("amount"); int progress; if (taskProgress.getProgress() == null) { progress = 0; } else { progress = (int) taskProgress.getProgress(); } ItemStack potion1 = event.getContents().getItem(0); ItemStack potion2 = event.getContents().getItem(1); ItemStack potion3 = event.getContents().getItem(2); taskProgress.setProgress(progress + (potion1 == null ? 0 : 1) + (potion2 == null ? 0 : 1) + (potion3 == null ? 0 : 1)); if (((int) taskProgress.getProgress()) >= potionsNeeded) { taskProgress.setCompleted(true); } } } } } }
Example #6
Source File: BrewObjective.java From BetonQuest with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void onBrew(final BrewEvent event) { final String playerID = locations.remove(event.getBlock().getLocation()); if (playerID == null) return; final PotionData data = ((PotionData) dataMap.get(playerID)); // this tracks how many potions there are in the stand before brewing int alreadyExistingTemp = 0; for (int i = 0; i < 3; i++) if (checkPotion(event.getContents().getItem(i))) alreadyExistingTemp++; // making it final for the runnable final int alreadyExisting = alreadyExistingTemp; new BukkitRunnable() { @Override public void run() { // unfinaling it for modifications boolean brewed = false; int alreadyExistingFinal = alreadyExisting; for (int i = 0; i < 3; i++) { // if there were any potions before, don't count them to // prevent cheating if (checkPotion(event.getContents().getItem(i))) { if (alreadyExistingFinal <= 0 && checkConditions(playerID)) { data.brew(); } alreadyExistingFinal--; brewed = true; } } // check if the objective has been completed if (data.getAmount() >= amount) { completeObjective(playerID); } else if (notify && data.getAmount() % notifyInterval == 0) { Config.sendNotify(playerID, "potions_to_brew", new String[]{String.valueOf(amount - data.getAmount())}, "potions_to_brew,info"); } } }.runTask(BetonQuest.getInstance()); }