コード例 #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);
   }
 }
コード例 #2
0
 @EventHandler
 public void onInteract(PlayerInteractEvent e) {
   if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
     ItemStack item = e.getItem();
     Player p = e.getPlayer();
     if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_SMALL, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.BACKPACK_SMALL, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 9)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_MEDIUM, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.BACKPACK_MEDIUM, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 18)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BACKPACK_LARGE, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.BACKPACK_LARGE, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 27)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.WOVEN_BACKPACK, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.WOVEN_BACKPACK, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 36)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GILDED_BACKPACK, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.GILDED_BACKPACK, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 45)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.BOUND_BACKPACK, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.BOUND_BACKPACK, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 36)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     } else if (SlimefunManager.isItemSimiliar(item, SlimefunItems.COOLER, false)) {
       e.setCancelled(true);
       if (Slimefun.hasUnlocked(p, SlimefunItems.COOLER, true)) {
         if (item.getAmount() == 1) {
           for (int line = 0; line < item.getItemMeta().getLore().size(); line++) {
             if (item.getItemMeta().getLore().get(line).equals("§7ID: <ID>")) {
               ItemMeta im = item.getItemMeta();
               List<String> lore = im.getLore();
               lore.set(line, lore.get(line).replace("<ID>", Backpacks.createBackpack(p, 27)));
               im.setLore(lore);
               item.setItemMeta(im);
               break;
             }
           }
           Backpacks.openBackpack(p, item);
           p.playSound(p.getLocation(), Sound.HORSE_ARMOR, 1F, 1F);
           Variables.backpack.put(p.getUniqueId(), item);
         } else Messages.local.sendTranslation(p, "backpack.no-stack", true);
       }
     }
   }
 }
コード例 #3
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);
  }