org.bukkit.event.inventory.CraftItemEvent Java Examples
The following examples show how to use
org.bukkit.event.inventory.CraftItemEvent.
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 BedWars with GNU Lesser General Public License v3.0 | 7 votes |
@EventHandler public void onCraft(CraftItemEvent event) { if (event.isCancelled() || !(event.getWhoClicked() instanceof Player)) { return; } Player player = (Player) event.getWhoClicked(); if (Main.isPlayerInGame(player)) { GamePlayer gPlayer = Main.getPlayerGameProfile(player); if (gPlayer.getGame().getStatus() != GameStatus.RUNNING) { event.setCancelled(true); } else if (!gPlayer.getGame().getOriginalOrInheritedCrafting()) { event.setCancelled(true); } } }
Example #2
Source File: PlayerListener.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
@EventHandler public void onCraft(CraftItemEvent event) { if (event.isCancelled() || !(event.getWhoClicked() instanceof Player)) { return; } Player player = (Player) event.getWhoClicked(); if (Main.isPlayerInGame(player)) { GamePlayer gPlayer = Main.getPlayerGameProfile(player); if (gPlayer.getGame().getStatus() != GameStatus.RUNNING) { event.setCancelled(true); } else if (!gPlayer.getGame().getOriginalOrInheritedCrafting()) { event.setCancelled(true); } } }
Example #3
Source File: CraftingObjective.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onCrafting(CraftItemEvent event) { if (event.getWhoClicked() instanceof Player) { Player player = (Player) event.getWhoClicked(); String playerID = PlayerConverter.getID(player); CraftData playerData = (CraftData) dataMap.get(playerID); if (containsPlayer(playerID) && item.compare(event.getRecipe().getResult()) && checkConditions(playerID)) { int absoluteCreations = countPossibleCrafts(event); int remainingSpace = countRemainingSpace(player); playerData.subtract(Math.min(remainingSpace, absoluteCreations)); if (playerData.isZero()) { completeObjective(playerID); } } } }
Example #4
Source File: RegionInteractListener.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onCraftItem(CraftItemEvent event) { NovaPlayer nPlayer = PlayerManager.getPlayer(event.getWhoClicked()); if(event.getRecipe().getResult().getType() != Material.SHIELD || !nPlayer.hasGuild() || nPlayer.getGuild().getBannerMeta().numberOfPatterns() == 0) { return; } for(ItemStack ingredient : event.getInventory().getContents()) { if(ingredient != null && ingredient.getType() == Material.SHIELD && ingredient.hasItemMeta()) { return; } } event.getInventory().setResult(BannerUtils.applyMeta(event.getRecipe().getResult(), nPlayer.getGuild().getBannerMeta())); }
Example #5
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 6 votes |
/** * Prevents crafting of EnderChest unless the player has permission * * @param event */ @EventHandler(priority = EventPriority.LOW) public void onCraft(CraftItemEvent event) { if (DEBUG) { plugin.getLogger().info(event.getEventName()); } Player player = (Player) event.getWhoClicked(); if (inWorld(player) || player.getWorld().equals(ASkyBlock.getNetherWorld())) { if (event.getRecipe().getResult().getType() == Material.ENDER_CHEST) { if (!(player.hasPermission(Settings.PERMPREFIX + "craft.enderchest"))) { Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission); event.setCancelled(true); } } } }
Example #6
Source File: PlayerListener.java From BedwarsRel with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onCraft(CraftItemEvent cie) { Player player = (Player) cie.getWhoClicked(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() == GameState.STOPPED) { return; } if (BedwarsRel.getInstance().getBooleanConfig("allow-crafting", false)) { return; } cie.setCancelled(true); }
Example #7
Source File: BonusGoodieManager.java From civcraft with GNU General Public License v2.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void OnCraftItemEvent(CraftItemEvent event) { Player player; try { player = CivGlobal.getPlayer(event.getWhoClicked().getName()); } catch (CivException e) { e.printStackTrace(); return; } for (ItemStack stack : event.getInventory().getMatrix()) { BonusGoodie goodie = CivGlobal.getBonusGoodie(stack); if (goodie != null) { CivMessage.sendError(player, "Cannot use bonus goodies in a crafting recipe."); event.setCancelled(true); } } }
Example #8
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private CraftItemEvent mockCraftingEvent(ItemStack item) { Recipe recipe = new ShapedRecipe(new NamespacedKey(plugin, "test_recipe"), new ItemStack(Material.EMERALD)); Player player = server.addPlayer(); CraftingInventory inv = Mockito.mock(CraftingInventory.class); Mockito.when(inv.getContents()).thenReturn(new ItemStack[] { item, null, null, null, null, null, null, null, null }); InventoryView view = player.openInventory(inv); CraftItemEvent event = new CraftItemEvent(recipe, view, SlotType.RESULT, 9, ClickType.LEFT, InventoryAction.PICKUP_ALL); listener.onCraft(event); return event; }
Example #9
Source File: CustomItemManager.java From civcraft with GNU General Public License v2.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void OnCraftItemEvent(CraftItemEvent event) { for (ItemStack stack : event.getInventory().getMatrix()) { if (stack != null) { if (LoreMaterial.isCustom(stack)) { LoreMaterial.getMaterial(stack).onItemCraft(event); } } } }
Example #10
Source File: UnitItemMaterial.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void onItemCraft(CraftItemEvent event) { try { CivMessage.sendError(CivGlobal.getPlayer(event.getWhoClicked().getName()), "Cannot craft with a unit item."); } catch (CivException e) { //player offline? } event.setCancelled(true); }
Example #11
Source File: UnitMaterial.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void onItemCraft(CraftItemEvent event) { try { CivMessage.sendError(CivGlobal.getPlayer(event.getWhoClicked().getName()), "Cannot craft with a unit item."); } catch (CivException e) { //player offline? } event.setCancelled(true); }
Example #12
Source File: VanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onCraft(CraftItemEvent e) { for (ItemStack item : e.getInventory().getContents()) { SlimefunItem sfItem = SlimefunItem.getByItem(item); if (sfItem != null && !sfItem.isUseableInWorkbench()) { e.setResult(Result.DENY); SlimefunPlugin.getLocalization().sendMessage((Player) e.getWhoClicked(), "workbench.not-enhanced", true); break; } } }
Example #13
Source File: CraftingObjective.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
private int countPossibleCrafts(CraftItemEvent event) { int possibleCreations = 1; if (event.isShiftClick()) { possibleCreations = Integer.MAX_VALUE; for (ItemStack item : event.getInventory().getMatrix()) { if (item != null && !item.getType().equals(Material.AIR)) { possibleCreations = Math.min(possibleCreations, item.getAmount()); } } } return possibleCreations * event.getRecipe().getResult().getAmount(); }
Example #14
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Test public void testCraftEventWithSlimefunItem() { SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MOCK_DIAMOND", new CustomItem(Material.DIAMOND, "&cMock Diamond")); item.register(plugin); CraftItemEvent event = mockCraftingEvent(item.getItem()); Assertions.assertEquals(Result.DENY, event.getResult()); }
Example #15
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Test public void testCraftEventWithChangingSlimefunItem() { SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CHANGING_ITEM", new CustomItem(Material.DIAMOND, "&dChanging Diamond")); item.register(plugin); item.setUseableInWorkbench(true); CraftItemEvent event = mockCraftingEvent(item.getItem()); Assertions.assertEquals(Result.DEFAULT, event.getResult()); item.setUseableInWorkbench(false); CraftItemEvent event2 = mockCraftingEvent(item.getItem()); Assertions.assertEquals(Result.DENY, event2.getResult()); }
Example #16
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Test public void testCraftEventWithVanillaItem() { VanillaItem item = TestUtilities.mockVanillaItem(plugin, Material.DIAMOND, true); item.register(plugin); CraftItemEvent event = mockCraftingEvent(item.getItem()); Assertions.assertEquals(Result.DEFAULT, event.getResult()); }
Example #17
Source File: WoolObjective.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onCraftWool(CraftItemEvent event) { if (!this.craftable && event.getRecipe().getResult().getType().equals(Material.WOOL) && ((Wool) event.getRecipe().getResult().getData()).getColor().equals(color)) { event.setCancelled(true); } }
Example #18
Source File: Snowflakes.java From CardinalPGM with MIT License | 5 votes |
@EventHandler public void onPlayerCraft(CraftItemEvent event) { Player player = (Player) event.getWhoClicked(); for (DyeColor color : getColors(event.getRecipe())) { if (testDestroy(player, color)) { addDestroyed(player, color); } } }
Example #19
Source File: FlagSnowballs.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onCraftItem(CraftItemEvent event) { SpleefPlayer player = getHeavySpleef().getSpleefPlayer(event.getWhoClicked()); if (!game.isIngame(player)) { return; } Recipe recipe = event.getRecipe(); Material result = recipe.getResult().getType(); if (result == Material.SNOW_BLOCK) { event.setCancelled(true); } }
Example #20
Source File: HasteyBoysListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onPlayerCraft(CraftItemEvent e){ ItemStack item = e.getCurrentItem(); try { item.addEnchantment(Enchantment.DIG_SPEED,3); item.addEnchantment(Enchantment.DURABILITY,1); }catch (IllegalArgumentException ex){ // Nothing } }
Example #21
Source File: ItemModifyMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void onItemCraft(CraftItemEvent event) { ItemStack stack = event.getCurrentItem(); if (applyRules(stack)) { event.setCurrentItem(stack); event.getInventory().setResult(stack); } }
Example #22
Source File: CraftItemListener.java From MineTinker with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onCraft(CraftItemEvent event) { if (!(event.getWhoClicked() instanceof Player)) { return; } Player player = (Player) event.getWhoClicked(); FileConfiguration config = MineTinker.getPlugin().getConfig(); if (config.getBoolean("Sound.OnEveryCrafting")) { player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_USE, 1.0F, 0.5F); return; } ItemStack tool = event.getInventory().getResult(); if (!(modManager.isToolViable(tool) || modManager.isArmorViable(tool) || modManager.isWandViable(tool))) { return; } if (config.getBoolean("Sound.OnCrafting")) { player.playSound(player.getLocation(), Sound.BLOCK_ANVIL_USE, 1.0F, 0.5F); } if (tool != null) { ChatWriter.log(false, player.getName() + " crafted " + ChatWriter.getDisplayName(tool) + "! It is now a MineTinker-Item!"); } }
Example #23
Source File: RaindropListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void handleCraft(final CraftItemEvent event) { ParticipantState player = PGM.getMatchManager().getParticipantState(event.getWhoClicked()); if (player == null) return; for (ItemStack ingredient : event.getInventory().getMatrix()) { if(this.isDestroyableWool(ingredient, player.getParty())) { giveWoolDestroyRaindrops(player, ((Wool) ingredient.getData()).getColor()); } } }
Example #24
Source File: ItemModifyMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void onItemCraft(CraftItemEvent event) { ItemStack stack = event.getCurrentItem(); if(applyRules(stack)) { event.setCurrentItem(stack); event.getInventory().setResult(stack); } }
Example #25
Source File: RodlessListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onCraftItem(CraftItemEvent e) { ItemStack item = e.getCurrentItem(); if (item.getType().equals(Material.FISHING_ROD)) { e.getWhoClicked().sendMessage(Lang.SCENARIO_RODLESS_ERROR); e.setCancelled(true); } }
Example #26
Source File: BowlessListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onCraftItem(CraftItemEvent e) { ItemStack item = e.getCurrentItem(); if (item.getType().equals(Material.BOW) || item.getType().equals(Material.ARROW)) { e.getWhoClicked().sendMessage(Lang.SCENARIO_BOWLESS_ERROR); e.setCancelled(true); } }
Example #27
Source File: MainListener.java From ArmorStandTools with MIT License | 5 votes |
@EventHandler public void onCraftItem(CraftItemEvent event) { if (event.isCancelled()) return; final Player p = (Player) event.getWhoClicked(); CraftingInventory inventory = event.getInventory(); for(ItemStack is : inventory.getContents()) { if(ArmorStandTool.isTool(is)) { event.setCancelled(true); //noinspection deprecation p.updateInventory(); return; } } }
Example #28
Source File: ShieldlessListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onCraftItem(CraftItemEvent e) { ItemStack item = e.getCurrentItem(); if (item.getType() != Material.AIR && item.getType() == UniversalMaterial.SHIELD.getType()){ e.getWhoClicked().sendMessage(Lang.SCENARIO_SHIELDLESS_ERROR); e.setCancelled(true); } }
Example #29
Source File: Archer.java From AnnihilationPro with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void arrowCraftingStopper(CraftItemEvent event) { if(event.getRecipe().getResult().getType() == Material.ARROW && event.getRecipe().getResult().getAmount() == 3) { AnniPlayer player = AnniPlayer.getPlayer(event.getWhoClicked().getUniqueId()); if(player != null && (player.getKit() == null || !player.getKit().equals(this))) event.setCancelled(true); } }
Example #30
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 4 votes |
@Test public void testCraftEventWithoutSlimefunItems() { CraftItemEvent event = mockCraftingEvent(new ItemStack(Material.DIAMOND)); Assertions.assertEquals(Result.DEFAULT, event.getResult()); }