コード例 #1
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());
     }
   }
 }
コード例 #2
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);
  }