@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
 public void onCraft(CraftItemEvent e) {
   for (ItemStack item : e.getInventory().getContents()) {
     if (SlimefunItem.getByItem(item) != null && !(SlimefunItem.getByItem(item).isReplacing())) {
       e.setCancelled(true);
       Messages.local.sendTranslation((Player) e.getWhoClicked(), "workbench.not-enhanced", true);
       break;
     }
   }
 }
 @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;
     }
   }
 }
 @EventHandler
 public void onEat(PlayerItemConsumeEvent e) {
   if (e.getItem() != null) {
     final Player p = e.getPlayer();
     ItemStack item = e.getItem();
     if (Slimefun.hasUnlocked(p, item, true)) {
       if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MONSTER_JERKY, true)) {
         PlayerInventory.consumeItemInHand(p);
         e.setItem(new ItemStack(Material.APPLE));
       } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.FORTUNE_COOKIE, true))
         p.sendMessage(
             Messages.local
                 .getTranslation("messages.fortune-cookie")
                 .get(
                     CSCoreLib.randomizer()
                         .nextInt(
                             Messages.local.getTranslation("messages.fortune-cookie").size())));
       else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BEEF_JERKY, true))
         p.setSaturation((Integer) Slimefun.getItemValue("BEEF_JERKY", "Saturation"));
       else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GRILLED_CHEESE, true))
         p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 8, 0));
       else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BUTTERED_POTATO, true))
         p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, 8, 0));
       else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.MEDICINE, true)) {
         if (p.hasPotionEffect(PotionEffectType.POISON))
           p.removePotionEffect(PotionEffectType.POISON);
         if (p.hasPotionEffect(PotionEffectType.WITHER))
           p.removePotionEffect(PotionEffectType.WITHER);
         if (p.hasPotionEffect(PotionEffectType.SLOW)) p.removePotionEffect(PotionEffectType.SLOW);
         if (p.hasPotionEffect(PotionEffectType.SLOW_DIGGING))
           p.removePotionEffect(PotionEffectType.SLOW_DIGGING);
         if (p.hasPotionEffect(PotionEffectType.WEAKNESS))
           p.removePotionEffect(PotionEffectType.WEAKNESS);
         if (p.hasPotionEffect(PotionEffectType.CONFUSION))
           p.removePotionEffect(PotionEffectType.CONFUSION);
         if (p.hasPotionEffect(PotionEffectType.BLINDNESS))
           p.removePotionEffect(PotionEffectType.BLINDNESS);
         p.setFireTicks(0);
       } else if (item.getType() == Material.POTION) {
         SlimefunItem sfItem = SlimefunItem.getByItem(item);
         if (sfItem != null && sfItem instanceof Juice) {
           Bukkit.getScheduler()
               .scheduleSyncDelayedTask(
                   main.instance,
                   new Runnable() {
                     @Override
                     public void run() {
                       p.getInventory().removeItem(new ItemStack(Material.GLASS_BOTTLE, 1));
                     }
                   },
                   1L);
         }
       }
     } else e.setCancelled(true);
   }
 }
 @EventHandler
 public void onArrowSuccessfulHit(EntityDamageByEntityEvent e) {
   if (!(e.getDamager() instanceof Arrow)) return;
   if (Variables.arrows.containsKey(e.getDamager().getUniqueId())
       && e.getEntity() instanceof LivingEntity) {
     for (ItemHandler handler : SlimefunItem.getHandlers("BowShootHandler")) {
       if (((BowShootHandler) handler).onHit(e, (LivingEntity) e.getEntity())) break;
     }
     Variables.arrows.remove(e.getDamager().getUniqueId());
   }
 }
 @EventHandler
 public void onAnvil(InventoryClickEvent e) {
   if (e.getRawSlot() == 2
       && e.getWhoClicked() instanceof Player
       && e.getInventory().getType() == InventoryType.ANVIL) {
     if (SlimefunItem.getByItem(e.getInventory().getContents()[0]) != null) {
       e.setCancelled(true);
       Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true);
     }
   }
 }
  @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
 public void onClick(InventoryClickEvent e) {
   if (Variables.backpack.containsKey(e.getWhoClicked().getUniqueId())) {
     ItemStack item = Variables.backpack.get(e.getWhoClicked().getUniqueId());
     if (SlimefunManager.isItemSimiliar(item, SlimefunItems.COOLER, false)) {
       SlimefunItem sfItem = SlimefunItem.getByItem(e.getCurrentItem());
       if (sfItem == null) e.setCancelled(true);
       else if (!(sfItem instanceof Juice)) e.setCancelled(true);
     } else if (SlimefunManager.isItemSimiliar(e.getCurrentItem(), item, true))
       e.setCancelled(true);
     else if (SlimefunManager.isItemSimiliar(
         e.getCurrentItem(), SlimefunItems.BACKPACK_SMALL, false)) e.setCancelled(true);
     else if (SlimefunManager.isItemSimiliar(
         e.getCurrentItem(), SlimefunItems.BACKPACK_MEDIUM, false)) e.setCancelled(true);
     else if (SlimefunManager.isItemSimiliar(
         e.getCurrentItem(), SlimefunItems.BACKPACK_LARGE, false)) e.setCancelled(true);
     else if (SlimefunManager.isItemSimiliar(
         e.getCurrentItem(), SlimefunItems.WOVEN_BACKPACK, false)) e.setCancelled(true);
     else if (SlimefunManager.isItemSimiliar(
         e.getCurrentItem(), SlimefunItems.GILDED_BACKPACK, false)) e.setCancelled(true);
     else if (SlimefunManager.isItemSimiliar(
         e.getCurrentItem(), SlimefunItems.BOUND_BACKPACK, false)) e.setCancelled(true);
   }
 }
 @EventHandler
 public void onBowUse(EntityShootBowEvent e) {
   if (!(e.getEntity() instanceof Player) || !(e.getProjectile() instanceof Arrow)) return;
   if (SlimefunItem.getByItem(e.getBow()) != null)
     Variables.arrows.put(e.getProjectile().getUniqueId(), e.getBow());
 }
示例#10
0
  @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);
  }