@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityExplode(EntityExplodeEvent e) { Iterator<Block> blocks = e.blockList().iterator(); while (blocks.hasNext()) { Block block = blocks.next(); SlimefunItem item = BlockStorage.check(block); if (item != null && item.getName().equalsIgnoreCase("HARDENED_GLASS")) blocks.remove(); else if (item != null) BlockStorage.retrieve(block); } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent e) { List<ItemStack> drops = new ArrayList<ItemStack>(); SlimefunItem sfItem = BlockStorage.check(e.getBlock()); ItemStack item = e.getPlayer().getItemInHand(); int fortune = 1; if (sfItem != null && !(sfItem instanceof HandledBlock)) drops.add(BlockStorage.retrieve(e.getBlock())); else if (item != null) { if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) { fortune = main.randomize(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1; if (fortune <= 0) fortune = 1; fortune = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + main.randomize(5) : 1) * (fortune + 1); } for (ItemHandler handler : SlimefunItem.getHandlers("BlockBreakHandler")) { if (((BlockBreakHandler) handler).onBlockBreak(e, item, fortune, drops)) break; } } if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && e.getBlock().getType().toString().endsWith("_ORE")) { if (Talisman.checkFor(e, SlimefunItem.getByName("MINER_TALISMAN"))) { if (drops.isEmpty()) drops = (List<ItemStack>) e.getBlock().getDrops(); for (ItemStack drop : new ArrayList<ItemStack>(drops)) { if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2)); } } } if (!drops.isEmpty()) { e.getBlock().setType(Material.AIR); for (ItemStack drop : drops) { e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), drop); } } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockRegister(BlockPlaceEvent e) { ItemStack item = e.getItemInHand(); if (SlimefunItem.getByItem(item) != null && !(SlimefunItem.getByItem(item) instanceof ExcludedBlock) && !(SlimefunItem.getByItem(item) instanceof ExcludedGadget)) { BlockStorage.store(e.getBlock(), item); if (SlimefunItem.getByItem(item) instanceof EnhancedFurnace) EnhancedFurnace.furnaces.add(e.getBlock().getLocation()); } else { for (ItemHandler handler : SlimefunItem.getHandlers("BlockPlaceHandler")) { if (((BlockPlaceHandler) handler).onBlockPlace(e, item)) break; } } }
@SuppressWarnings("deprecation") @EventHandler public void onRightClick(ItemUseEvent e) { final Player p = e.getPlayer(); ItemStack item = e.getItem(); if (SlimefunManager.isItemSimiliar(item, SlimefunGuide.getItem(), true)) SlimefunGuide.openGuide(p); else if (Slimefun.hasUnlocked(p, item, true)) { for (ItemHandler handler : SlimefunItem.getHandlers("ItemInteractionHandler")) { if (((ItemInteractionHandler) handler).onRightClick(e, p, item)) break; } if (SlimefunManager.isItemSimiliar(item, SlimefunItems.DURALUMIN_MULTI_TOOL, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.SOLDER_MULTI_TOOL, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.BILLON_MULTI_TOOL, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.STEEL_MULTI_TOOL, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.DAMASCUS_STEEL_MULTI_TOOL, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.REINFORCED_ALLOY_MULTI_TOOL, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.CARBONADO_MULTI_TOOL, false)) { e.setCancelled(true); ItemStack tool = null; for (ItemStack mTool : new ItemStack[] { SlimefunItems.DURALUMIN_MULTI_TOOL, SlimefunItems.SOLDER_MULTI_TOOL, SlimefunItems.BILLON_MULTI_TOOL, SlimefunItems.STEEL_MULTI_TOOL, SlimefunItems.DAMASCUS_STEEL_MULTI_TOOL, SlimefunItems.REINFORCED_ALLOY_MULTI_TOOL, SlimefunItems.CARBONADO_MULTI_TOOL }) { if (mTool .getItemMeta() .getLore() .get(0) .equalsIgnoreCase(item.getItemMeta().getLore().get(0))) { tool = mTool; break; } } if (tool != null) { List<Integer> modes = ((MultiTool) SlimefunItem.getByItem(tool)).getModes(); int index = 0; if (Variables.mode.containsKey(p.getUniqueId())) index = Variables.mode.get(p.getUniqueId()); if (!p.isSneaking()) { double charge = Double.valueOf( ChatColor.stripColor(p.getItemInHand().getItemMeta().getLore().get(1)) .replace("Charge: ", "") .replace(" J", "")); double cost = 0.3; if (charge >= cost) { double newcharge = Double.valueOf( new DecimalFormat("##.##").format(charge - cost).replace(",", ".")); ItemStack hand = p.getItemInHand().clone(); ItemMeta im = hand.getItemMeta(); List<String> lore = im.getLore(); lore.set( 1, ChatColor.translateAlternateColorCodes('&', "&7Charge: &b" + newcharge + " J")); im.setLore(lore); hand.setItemMeta(im); p.setItemInHand(hand); Bukkit.getPluginManager() .callEvent( new ItemUseEvent( p, SlimefunItem.getByName( (String) Slimefun.getItemValue( SlimefunItem.getByItem(tool).getName(), "mode." + modes.get(index) + ".item")) .getItem(), e.getClickedBlock())); } } else { index++; if (index == modes.size()) index = 0; Messages.local.sendTranslation( p, "messages.mode-change", true, new Variable("%device%", "Multi Tool"), new Variable( "%mode%", (String) Slimefun.getItemValue( SlimefunItem.getByItem(tool).getName(), "mode." + modes.get(index) + ".name"))); Variables.mode.put(p.getUniqueId(), index); } } } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.DURALUMIN_CAPACITOR, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.SOLDER_CAPACITOR, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.BILLON_CAPACITOR, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.STEEL_CAPACITOR, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.DAMASCUS_STEEL_CAPACITOR, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.REINFORCED_ALLOY_CAPACITOR, false) || SlimefunManager.isItemSimiliar(item, SlimefunItems.CARBONADO_CAPACITOR, false)) { double charge = Double.valueOf( ChatColor.stripColor(p.getItemInHand().getItemMeta().getLore().get(1)) .replace("Charge: ", "") .replace(" J", "")); charge = ChargeUtils.chargeArmor(p, charge); ItemStack hand = p.getItemInHand().clone(); ItemMeta im = hand.getItemMeta(); List<String> lore = im.getLore(); lore.set(1, ChatColor.translateAlternateColorCodes('&', "&7Charge: &b" + charge + " J")); im.setLore(lore); hand.setItemMeta(im); p.setItemInHand(hand); p.updateInventory(); } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.HEAVY_CREAM, true)) e.setCancelled(true); if (e.getClickedBlock() != null && BlockStorage.check(e.getClickedBlock()) != null) { if (BlockStorage.check(e.getClickedBlock()).getName().equalsIgnoreCase("SOUL_FORGE")) { e.setCancelled(true); if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BROKEN_SPAWNER, false)) { final ItemStack spawner = SlimefunItems.REPAIRED_SPAWNER.clone(); ItemMeta im = spawner.getItemMeta(); im.setLore(Arrays.asList(item.getItemMeta().getLore().get(0))); spawner.setItemMeta(im); PlayerInventory.consumeItemInHand(p); p.getWorld().dropItemNaturally(e.getClickedBlock().getLocation().add(0, 1, 0), spawner); p.getWorld().playSound(p.getLocation(), Sound.BLAZE_DEATH, 2F, 2F); p.getWorld().playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 1); Variables.cancelPlace.add(p.getUniqueId()); PlayerInventory.update(p); } } else if (BlockStorage.check(e.getClickedBlock()) .getName() .equalsIgnoreCase("CHUNK_LOADER")) e.setCancelled(true); } } else e.setCancelled(true); }