Exemplo n.º 1
0
 @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);
   }
 }
Exemplo n.º 2
0
 @SuppressWarnings("deprecation")
 @EventHandler(priority = EventPriority.LOWEST)
 public void onFurnaceInsert(InventoryClickEvent e) {
   if (e.getInventory().getType() == InventoryType.FURNACE
       && e.getCursor() != null
       && (e.getRawSlot() == 0 || e.getSlot() == 1)) {
     if (!e.isShiftClick()) {
       ItemStack item = e.getCurrentItem();
       e.setCurrentItem(e.getCursor());
       e.setCursor(item);
       e.setCancelled(true);
       PlayerInventory.update((Player) e.getWhoClicked());
     }
   }
 }
Exemplo n.º 3
0
  @EventHandler
  public void onBlockPlace(BlockPlaceEvent e) {
    ItemStack item = e.getItemInHand();

    if (Variables.cancelPlace.contains(e.getPlayer().getUniqueId())) {
      e.setCancelled(true);
      Variables.cancelPlace.remove(e.getPlayer().getUniqueId());
    }
    if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BASIC_CIRCUIT_BOARD, true))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.ADVANCED_CIRCUIT_BOARD, true))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_SMALL, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_MEDIUM, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_LARGE, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.WOVEN_BACKPACK, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GILDED_BACKPACK, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BOUND_BACKPACK, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.DURALUMIN_ENERGY_CELL, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BILLON_ENERGY_CELL, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.SOLDER_ENERGY_CELL, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.STEEL_ENERGY_CELL, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.DAMASCUS_STEEL_ENERGY_CELL, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(
        item, SlimefunItems.REINFORCED_ALLOY_ENERGY_CELL, false)) e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.CARBONADO_ENERGY_CELL, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.DURALUMIN_CAPACITOR, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BILLON_CAPACITOR, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.SOLDER_CAPACITOR, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.STEEL_CAPACITOR, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.DAMASCUS_STEEL_CAPACITOR, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.REINFORCED_ALLOY_CAPACITOR, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.CARBONADO_CAPACITOR, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BROKEN_SPAWNER, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GPS_MODULE, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GPS_SECURITY_MODULE, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GPS_TRANSMISSION_MODULE, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GPS_ANTENNA, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GPS_MARKER, false)) {
      Satellites.addWaypoint(e.getPlayer(), e.getBlockPlaced().getLocation());
      e.setCancelled(true);
    } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.SATELLITE, false)) {
      e.setCancelled(true);
      PlayerInventory.consumeItemInHand(e.getPlayer());
      Messages.local.sendTranslation(e.getPlayer(), "satellites.launched", false);
      Satellites.add(e.getPlayer());
    } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.PORTABLE_GPS_TRACKER, false))
      e.setCancelled(true);
    else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.PRESENT, false)) {
      e.setCancelled(true);
      PlayerInventory.consumeItemInHand(e.getPlayer());
      FireworkShow.launchRandom(e.getPlayer(), 3);
      List<ItemStack> gifts = new ArrayList<ItemStack>();
      for (int i = 0; i < 2; i++) {
        gifts.add(new CustomItem(SlimefunItems.HOT_CHOCOLATE, 1));
        gifts.add(new CustomItem(SlimefunItems.CHOCOLATE_APPLE, 4));
        gifts.add(new CustomItem(SlimefunItems.CARAMEL_APPLE, 4));
        gifts.add(new CustomItem(SlimefunItems.CHRISTMAS_CAKE, 4));
        gifts.add(new CustomItem(SlimefunItems.CHRISTMAS_COOKIE, 8));
        gifts.add(new CustomItem(SlimefunItems.PRESENT, 1));
        gifts.add(new CustomItem(SlimefunItems.EGG_NOG, 1));
        gifts.add(new CustomItem(SlimefunItems.MILK, 1));
        gifts.add(new CustomItem(SlimefunItems.APPLE_CIDER, 1));
        gifts.add(new CustomItem(SlimefunItems.FRUIT_CAKE, 4));
        gifts.add(new CustomItem(SlimefunItems.APPLE_PIE, 4));
      }
      gifts.add(new SkullItem("mrCookieSlime"));
      gifts.add(new SkullItem("timtower"));
      gifts.add(new SkullItem("bwfcwalshy"));
      gifts.add(new SkullItem("jadedcat"));
      gifts.add(new SkullItem("ZeldoKavira"));
      gifts.add(new SkullItem("eyamaz"));
      gifts.add(new SkullItem("Kaelten"));
      gifts.add(new SkullItem("ahamling27"));
      gifts.add(new SkullItem("Myrathi"));

      new String(
          "Good day to whoever is just looking through my code."
              + "Since it is Christmas, I wanted to add some Christmas flavour to this Plugin."
              + "So, I hope you don't mind that I implemented some of your Heads >.>"
              + "Merry Christmas everyone!"
              + ""
              + "- mrCookieSlime");
      e.getBlockPlaced()
          .getWorld()
          .dropItemNaturally(
              e.getBlockPlaced().getLocation(), gifts.get(main.randomize(gifts.size())));
    }
  }
Exemplo n.º 4
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);
  }