@Override
 protected void onInventoryClick(InventoryClickEvent event, Player player) {
   event.setCancelled(true);
   final int slot = event.getRawSlot();
   if (slot >= 0 && slot <= 7) {
     // handle changing sell stack size
     ItemStack item = event.getCurrentItem();
     if (item != null && item.getType() != Material.AIR) {
       int amount = item.getAmount();
       amount = this.getNewAmountAfterEditorClick(event, amount);
       if (amount <= 0) amount = 1;
       if (amount > item.getMaxStackSize()) amount = item.getMaxStackSize();
       item.setAmount(amount);
     }
   } else if ((slot >= 9 && slot <= 16) || (slot >= 18 && slot <= 25)) {
     if (((TradingPlayerShopkeeper) shopkeeper).clickedItem != null) {
       // placing item
       final Inventory inventory = event.getInventory();
       Bukkit.getScheduler()
           .runTaskLater(
               ShopkeepersPlugin.getInstance(),
               new Runnable() {
                 public void run() {
                   inventory.setItem(slot, ((TradingPlayerShopkeeper) shopkeeper).clickedItem);
                   ((TradingPlayerShopkeeper) shopkeeper).clickedItem = null;
                 }
               },
               1);
     } else {
       // changing stack size
       ItemStack item = event.getCurrentItem();
       if (item != null && item.getType() != Material.AIR) {
         int amount = item.getAmount();
         amount = this.getNewAmountAfterEditorClick(event, amount);
         if (amount <= 0) {
           event.getInventory().setItem(slot, null);
         } else {
           if (amount > item.getMaxStackSize()) amount = item.getMaxStackSize();
           item.setAmount(amount);
         }
       }
     }
   } else if (slot >= 27) {
     // clicking in player inventory
     if (event.isShiftClick() || !event.isLeftClick()) {
       return;
     }
     ItemStack cursor = event.getCursor();
     if (cursor != null && cursor.getType() != Material.AIR) {
       return;
     }
     ItemStack current = event.getCurrentItem();
     if (current != null && current.getType() != Material.AIR) {
       ((TradingPlayerShopkeeper) shopkeeper).clickedItem = current.clone();
       ((TradingPlayerShopkeeper) shopkeeper).clickedItem.setAmount(1);
     }
   } else {
     super.onInventoryClick(event, player);
   }
 }
Beispiel #2
0
 /**
  * Cancel players from removing, picking the hat in their inventory.
  *
  * @param EVENT
  */
 @EventHandler
 public void cancelHatClick(final InventoryClickEvent EVENT) {
   if (EVENT.getCurrentItem() != null
       && EVENT.getCurrentItem().hasItemMeta()
       && EVENT.getCurrentItem().getItemMeta().hasDisplayName()
       && EVENT.getCurrentItem().getItemMeta().getDisplayName().equals("§8§oHat")) {
     EVENT.setCancelled(true);
     EVENT.setResult(Event.Result.DENY);
     EVENT.getWhoClicked().closeInventory();
     Bukkit.getScheduler()
         .runTaskLaterAsynchronously(
             Core.getPlugin(),
             new Runnable() {
               @Override
               public void run() {
                 for (ItemStack itemStack : EVENT.getWhoClicked().getInventory().getContents()) {
                   if (itemStack != null
                       && itemStack.hasItemMeta()
                       && itemStack.getItemMeta().hasDisplayName()
                       && itemStack.getItemMeta().getDisplayName().equals("§8§oHat")
                       && itemStack != EVENT.getWhoClicked().getInventory().getHelmet())
                     EVENT.getWhoClicked().getInventory().remove(itemStack);
                 }
               }
             },
             1);
   }
 }
  protected static List<Entry<ItemStack, Integer>> getChangesClick(InventoryClickEvent event) {
    // Create
    List<Entry<ItemStack, Integer>> ret = new MassiveList<>();

    // Fill
    final InventoryAlter alter = InventoryUtil.getAlter(event);
    final InventoryAction action = event.getAction();
    ItemStack item;
    int amount;

    // Give
    if (alter.isGiving()) {
      // Special > MOVE_TO_OTHER_INVENTORY
      if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
        item = event.getCurrentItem();

        ItemStack compare = item.clone();
        compare.setAmount(1);
        amount = InventoryUtil.roomLeft(event.getInventory(), compare, item.getAmount());
      }
      // Special > HOTBAR_SWAP
      else if (action == InventoryAction.HOTBAR_SWAP) {
        item = event.getView().getBottomInventory().getItem(event.getHotbarButton());

        amount = item.getAmount();
      }
      // Normal
      else {
        item = event.getCursor();

        amount = item.getAmount();
        if (action == InventoryAction.PLACE_ONE) {
          amount = 1;
        } else if (action == InventoryAction.PLACE_SOME) {
          int max = event.getCurrentItem().getType().getMaxStackSize();
          amount = max - event.getCurrentItem().getAmount();
        }
      }

      amount *= -1;
      ret.add(new SimpleEntry<ItemStack, Integer>(item, amount));
    }

    // Take
    if (alter.isTaking()) {
      item = event.getCurrentItem();

      amount = item.getAmount();
      if (action == InventoryAction.PICKUP_ONE) amount = 1;
      if (action == InventoryAction.PICKUP_HALF) amount = (int) Math.ceil(amount / 2.0);

      ret.add(new SimpleEntry<ItemStack, Integer>(item, amount));
    }

    // Return
    return ret;
  }
Beispiel #4
0
  @EventHandler
  public void onInventroyClick(InventoryClickEvent event) {
    if (!ChatColor.stripColor(event.getInventory().getName()).equalsIgnoreCase("Offical MD Links"))
      ;
    return;

    Player player = (Player) event.getWhoClicked();
    event.setCancelled(true);

    if (event.getCurrentItem() == null
        || event.getCurrentItem().getType() == Material.AIR
        || !event.getCurrentItem().hasItemMeta()) {
      player.closeInventory();
      return;
    }

    switch (event.getCurrentItem().getType()) {
      case BEACON:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;

      case ANVIL:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;

      case MINECART:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;

      case DIAMOND:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;

      case WOOL:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;

      case COMPASS:
        player.closeInventory();
        player.sendMessage("&6&lClick to submit a application: http://magicaldreams.us/apply/");
        break;
      default:
        player.closeInventory();
        break;
    }
  }
Beispiel #5
0
 @SuppressWarnings("deprecation")
 @EventHandler
 public void click(InventoryClickEvent event) {
   Player player = (Player) event.getView().getPlayer();
   OpenQuestLog oql = getOpenQuestLog(player);
   if (oql == null) return;
   event.setCancelled(true);
   if (event.getView() != oql.getInventoryView()) {
     player.updateInventory();
     return;
   }
   if (event.getCurrentItem() == null) {
     player.updateInventory();
     return;
   }
   Quest sel = oql.getSelected();
   if (sel == null) {
     if (event.getSlot() == 27) {
       oql.setViewingCompleted(!oql.isViewingCompleted());
       oql.update();
     } else {
       int index = (oql.getPage() - 1) * 27 + event.getSlot();
       Quest[] q =
           oql.isViewingCompleted() ? oql.getCurrentCompletedList() : oql.getCurrentQuestList();
       if (index < q.length) {
         oql.setSelected(q[index]);
         oql.update();
       }
     }
   } else if (event.getSlot() == 27) {
     oql.setSelected(null);
     oql.update();
   }
   player.updateInventory();
 }
  @EventHandler
  public void onInterfaceInteract(InventoryClickEvent event) {
    if (event.getView() != this) return;

    ItemStack itemClicked = event.getCurrentItem();
    if (itemClicked == null || itemClicked.getType() == Material.AIR) return;

    event.setCancelled(true);

    // If not right or left-click.
    if (!(event.getClick() == ClickType.RIGHT || event.getClick() == ClickType.LEFT)) return;

    if (this.ACCEPT_OBJECT.equals(itemClicked)) {
      onAcceptPressed();
      return;
    }

    if (this.BACK_OBJECT.equals(itemClicked)) {
      if (onBackPressed()) scheduleCloseOfInventory();
      return;
    }

    int rawSlot = event.getRawSlot();
    int slotNumber = event.getSlot();
    boolean usedTopInv = rawSlot < getTopInventory().getSize();

    if (usedTopInv) onSelectionItemPressed(slotNumber, itemClicked);
    else onControlItemPressed(slotNumber, itemClicked);
  }
Beispiel #7
0
 @EventHandler(priority = EventPriority.MONITOR)
 void onInventoryClick(InventoryClickEvent event) {
   if (event.getInventory().getTitle().equals(name)) {
     event.setCancelled(true);
     int slot = event.getRawSlot();
     if (slot >= 0 && slot < size && optionNames[slot] != null) {
       Plugin plugin = this.plugin;
       OptionClickEvent e =
           new OptionClickEvent(
               (Player) event.getWhoClicked(), event.getCurrentItem(), slot, optionNames[slot]);
       handler.onOptionClick(e);
       if (e.willClose()) {
         final Player p = (Player) event.getWhoClicked();
         Bukkit.getScheduler()
             .scheduleSyncDelayedTask(
                 plugin,
                 new Runnable() {
                   public void run() {
                     p.closeInventory();
                   }
                 },
                 1);
       }
       if (e.willDestroy()) {
         destroy();
       }
     }
   }
 }
  @SuppressWarnings("deprecation")
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Options menu")) {
      return;
    }
    if (currentItem.getType() != Material.HARD_CLAY) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Floor block")) {
      return;
    }

    for (Block block : plot.getFloor().getAllBlocks()) {
      block.setType(e.getCursor().getType());
      block.setData(e.getCursor().getData().getData());
    }

    e.setCancelled(true);
  }
Beispiel #9
0
  @Override
  @SuppressWarnings(
      "deprecation") // Player.updateInventory has been deprecated for a while with no alternative
                     // available yet
  public void onClick(final InventoryClickEvent click) {
    final int last = click.getView().getTopInventory().getSize() - 1;

    // cancel shift clicks on items outside of delivery inventory to prevent indirect moving of
    // items into delivery inventory
    if (click.isShiftClick()
        && (click.getCurrentItem().getTypeId() != Material.AIR.getId())
        && (click.getRawSlot() > last)) click.setCancelled(true);

    // cancel clicks with item on cursor in delivery inventory to prevent direct placement of items
    // into delivery inventory
    if ((click.getCursor().getTypeId() != Material.AIR.getId())
        && (click.getRawSlot() >= 0)
        && (click.getRawSlot() <= last)) click.setCancelled(true);

    if (click.isCancelled()) {
      click.setCursor(click.getCursor());
      ((Player) click.getWhoClicked()).updateInventory();
      this.courier.send((Player) click.getWhoClicked(), "withdraw-only");
    }
  }
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Particles")) {
      return;
    }
    if (currentItem.getType() != Material.LAVA_BUCKET) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Lava drip")) {
      return;
    }

    plot.addParticle(new Particle(player.getLocation(), ParticleType.LAVA_DRIP));
    e.setCancelled(true);
  }
  @SuppressWarnings("deprecation")
  private void onLobbyInventoryClick(InventoryClickEvent ice, Player player, Game game) {
    Inventory inv = ice.getInventory();
    ItemStack clickedStack = ice.getCurrentItem();

    if (!inv.getTitle().equals(Main._l("lobby.chooseteam"))) {
      ice.setCancelled(true);
      return;
    }

    if (clickedStack == null) {
      ice.setCancelled(true);
      return;
    }

    if (clickedStack.getType() != Material.WOOL) {
      return;
    }

    ice.setCancelled(true);
    Team team = game.getTeamByDyeColor(DyeColor.getByData(clickedStack.getData().getData()));
    if (team == null) {
      return;
    }

    game.playerJoinTeam(player, team);
    player.closeInventory();
  }
Beispiel #12
0
 public static void debug(InventoryClickEvent event) {
   System.out.println("===== DEBUG START =====");
   System.out.println("event.getAction() " + event.getAction());
   System.out.println("event.isLeftClick() " + event.isLeftClick());
   System.out.println("event.isRightClick() " + event.isRightClick());
   System.out.println("event.isShiftClick() " + event.isShiftClick());
   System.out.println("event.getClick() " + event.getClick());
   System.out.println("event.getCurrentItem() " + event.getCurrentItem());
   System.out.println("event.getCursor() " + event.getCursor());
   System.out.println("event.getHotbarButton() " + event.getHotbarButton());
   System.out.println("getInventory().getType() " + event.getInventory().getType());
   System.out.println("event.getRawSlot() " + event.getRawSlot());
   System.out.println("event.getResult() " + event.getResult());
   System.out.println("event.getSlot() " + event.getSlot());
   System.out.println("event.getSlotType() " + event.getSlotType());
   System.out.println(
       "getView().getTopInventory().getType() " + event.getView().getTopInventory().getType());
   System.out.println("getView().getType() " + event.getView().getType());
   System.out.println(
       "getView().getBottomInventory().getType() "
           + event.getView().getBottomInventory().getType());
   System.out.println("event.getWhoClicked() " + event.getWhoClicked());
   System.out.println("-----");
   System.out.println("isOutside(event) " + isOutside(event));
   System.out.println("isTopInventory(event) " + isTopInventory(event));
   System.out.println("isBottomInventory(event) " + isBottomInventory(event));
   System.out.println("getAlter(event) " + getAlter(event));
   System.out.println("isAltering(event) " + isAltering(event));
   System.out.println("isEquipping(event) " + isEquipping(event));
   System.out.println("===== DEBUG END =====");
 }
Beispiel #13
0
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Time selection")) {
      return;
    }
    if (currentItem.getType() != Material.WATCH) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "2 AM")) {
      return;
    }

    plot.setTime(Time.AM2);
    e.setCancelled(true);
  }
 @EventHandler
 public void onClick(InventoryClickEvent e) {
   if (e.getInventory() == null) return;
   if (e.getCurrentItem() == null) return;
   if (e.getCurrentItem().getType().equals(Material.AIR)) return;
   if (e.getInventory().getTitle() == null) return;
   if (e.getInventory().getTitle().equals(INV_TITLE)) {
     e.setCancelled(true);
     e.getWhoClicked().openInventory(e.getInventory());
   }
 }
  @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
  public void onInventoryClick(InventoryClickEvent event) {
    if (!(event.getInventory().getHolder() instanceof Player)) return;
    Player p = (Player) event.getInventory().getHolder();
    ItemStack i = event.getCurrentItem();
    if (p == null) return;
    if (i == null) return;
    if (!p.hasPermission("orbia.keepitems") && !p.getGameMode().equals(GameMode.CREATIVE)) return;

    if (!itemHandler.isCustomItem(i) && remove.contains(i.getType())) p.getInventory().remove(i);
  }
Beispiel #16
0
 @EventHandler
 public void onInventoryClickAmmo(final InventoryClickEvent event) {
   if (event.getWhoClicked() == getPlayer()
       && inv != null
       && isSameInventory(event.getWhoClicked().getOpenInventory().getTopInventory(), inv)) {
     event.setCancelled(true);
     if (event.getCurrentItem() != null
         && event.getCurrentItem().hasItemMeta()
         && event.getCurrentItem().getItemMeta().hasDisplayName()) {
       String displayName = event.getCurrentItem().getItemMeta().getDisplayName();
       String purchase = MessageManager.getMessage("Purchase");
       String cancel = MessageManager.getMessage("Cancel");
       if (displayName.equals(purchase)) {
         if (Core.getCustomPlayer((Player) event.getWhoClicked()).getBalance() >= getPrice()) {
           Core.economy.withdrawPlayer((Player) event.getWhoClicked(), getPrice());
           Core.getCustomPlayer((Player) event.getWhoClicked())
               .addAmmo(type.toString().toLowerCase(), getResultAmmoAmount());
           event.getWhoClicked().sendMessage(MessageManager.getMessage("Successful-Purchase"));
           if (openGadgetsInvAfterAmmo)
             Bukkit.getScheduler()
                 .runTaskLater(
                     Core.getPlugin(),
                     new Runnable() {
                       @Override
                       public void run() {
                         GadgetManager.openMenu((Player) event.getWhoClicked(), lastPage);
                         openGadgetsInvAfterAmmo = false;
                         lastPage = 1;
                       }
                     },
                     1);
         } else {
           getPlayer().sendMessage(MessageManager.getMessage("Not-Enough-Money"));
         }
         event.getWhoClicked().closeInventory();
       } else if (displayName.equals(cancel)) {
         event.getWhoClicked().closeInventory();
       }
     }
   }
 }
Beispiel #17
0
  @EventHandler
  public void onInventoryClick(InventoryClickEvent event) {
    if (event.getInventory().getName() == "Choose a metal") {
      if (event.getRawSlot() <= 8) {
        event.getWhoClicked().getInventory().addItem(new ItemStack(event.getCurrentItem()));

        event.getWhoClicked().closeInventory();
        event.setCancelled(true);
      }
      event.setCancelled(true);
    }
  }
Beispiel #18
0
 @EventHandler
 public void onInventoryClickEvent(InventoryClickEvent event) {
   if ((isEnabled()) && (event.getInventory().getType().equals(InventoryType.BREWING))) {
     boolean disableSplash =
         UHCutils.getMainConfig().getBoolean("features.potionNerfs.disableSplash");
     boolean disableGlowstone =
         UHCutils.getMainConfig().getBoolean("features.potionNerfs.disableGlowstone");
     if (event.isShiftClick()) {
       if ((disableSplash) && (event.getCurrentItem().getType().equals(Material.SULPHUR)))
         cancel(event);
       if ((disableGlowstone)
           && (event.getCurrentItem().getType().equals(Material.GLOWSTONE_DUST))) cancel(event);
     } else if (event.getSlotType().equals(InventoryType.SlotType.FUEL)) {
       if ((disableSplash) && (event.getView().getCursor().getType().equals(Material.SULPHUR)))
         cancel(event);
       if ((disableGlowstone)
           && (event.getView().getCursor().getType().equals(Material.GLOWSTONE_DUST)))
         cancel(event);
     }
   }
 }
  // Handles buying items.
  @EventHandler(priority = EventPriority.NORMAL)
  public void buyClick(InventoryClickEvent event) {
    Player player = (Player) event.getWhoClicked();

    if (player != null) {
      // Makes sure there is an item that was clicked.
      if (event.getCurrentItem() == null) return;

      ItemStack clicked = event.getCurrentItem();

      boolean checks = false;

      if (event.getInventory().getName() != null)
        if (!(event.getClickedInventory().getName().equalsIgnoreCase("container.inventory")))
          checks = itemChecker(event.getInventory().getName(), player, clicked);

      // Make sure items can't be take from the shop if the item clicked checks (is part of the
      // shop).
      if (checks) event.setCancelled(true);
    } // End of null check.
  } // End of inventory click.
Beispiel #20
0
 /**
  * Cancel players from removing, picking the item in their inventory.
  *
  * @param event
  */
 @EventHandler(priority = EventPriority.LOWEST)
 public void cancelMove(InventoryClickEvent event) {
   Player player = (Player) event.getWhoClicked();
   if (player == getPlayer()) {
     if (event.getClick() == ClickType.SHIFT_LEFT
         || event.getClick() == ClickType.SHIFT_RIGHT
         || event.getClick() == ClickType.NUMBER_KEY
         || event.getClick() == ClickType.UNKNOWN) {
       event.setCancelled(true);
       player.updateInventory();
       return;
     }
     if (event.getCurrentItem() != null) {
       if (event.getCurrentItem().equals(itemStack)) {
         event.setCancelled(true);
         player.updateInventory();
         return;
       }
     }
   }
 }
 @Override
 public void onClick(Player player, InventoryClickEvent event) {
   if (event.getCurrentItem() != null && !event.getCurrentItem().getType().equals(Material.AIR)) {
     if (event.getRawSlot() <= event.getSlot()) {
       int slot = event.getSlot();
       PlayerShopOffer offer = shop.getOffers().get(slot);
       if (offer != null) {
         if (event.isLeftClick()) {
           if (player.getName().equalsIgnoreCase(shop.getOwnerName())) {
             handleOfferEdit(player, event, offer);
           } else {
             handleTrade(player, event, offer);
           }
         } else if (event.isRightClick()) {
           if (getSession().getPermissionsProvider().has(player, ASPermissionKey.MANAGER)) {
             handleOfferEdit(player, event, offer);
           }
         }
       }
     }
   }
 }
Beispiel #22
0
  @EventHandler
  public void onSpawnTeam(InventoryClickEvent e) {
    Player p = (Player) e.getWhoClicked();
    if (e.getCurrentItem() == null) {
      return;
    }
    if (Bedwars_Command.editMap.containsKey(p)) {
      if (e.getInventory().getName().contains("§6Team Spawns")) {
        e.setCancelled(true);
        File files = new File("plugins/Bedwars/Maps/" + Bedwars_Command.editMap.get(p) + ".yml");
        FileConfiguration cfg = YamlConfiguration.loadConfiguration(files);

        if (e.getCurrentItem().getType() == Material.WOOL) {

          Location loc = p.getLocation();
          int i = e.getCurrentItem().getData().getData();
          cfg.set("Spawn." + i + ".world", loc.getWorld().getName());
          cfg.set("Spawn." + i + ".x", loc.getX());
          cfg.set("Spawn." + i + ".y", loc.getY());
          cfg.set("Spawn." + i + ".z", loc.getZ());
          cfg.set("Spawn." + i + ".pitch", loc.getYaw());
          cfg.set("Spawn." + i + ".yaw", loc.getPitch());

          try {
            cfg.save(files);
            p.sendMessage(
                Main.pr
                    + "§eDu hast den Spawn von Team "
                    + TeamSettings.teamsName.get(i)
                    + " §egesetzt.");
            openSpawns(p);
          } catch (IOException e1) {
            e1.printStackTrace();
          }
        }
      }
    }
  }
 @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());
     }
   }
 }
 @EventHandler(ignoreCancelled = true)
 public void onFurnaceInsert(final InventoryClickEvent event) {
   if (event.getInventory().getType() != InventoryType.FURNACE) {
     return;
   }
   if (event.getRawSlot() == 0 && event.getCursor().getType() != Material.AIR) {
     if (!validateSmeltingIngredient(event.getCursor())) {
       event.setCancelled(true);
     }
   } else if (event.getRawSlot() >= event.getView().getTopInventory().getSize()) {
     if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
       if (!validateSmeltingIngredient(event.getCurrentItem())
           && !STBUtil.isFuel(event.getCurrentItem().getType())) {
         event.setCancelled(true);
         int newSlot = findNewSlot(event);
         if (newSlot >= 0) {
           event.getWhoClicked().getInventory().setItem(newSlot, event.getCurrentItem());
           event.setCurrentItem(null);
         }
       }
     }
   } else if (event.getRawSlot() == 2
       && SensibleToolbox.getItemRegistry().isSTBItem(event.getCurrentItem())) {
     // work around CB bug where shift-clicking custom items out of furnace seems
     // to cause a de-sync, leaving phantom items in the furnace
     Bukkit.getScheduler()
         .runTask(
             plugin,
             new Runnable() {
               @Override
               public void run() {
                 STBUtil.forceInventoryRefresh(event.getInventory());
               }
             });
   }
 }
Beispiel #25
0
 @EventHandler
 public void onInventoryClick(InventoryClickEvent event) {
   Inventory inventory = event.getInventory();
   if (inventory.getName().equals(i.getName())) {
     event.setCancelled(true);
     Player player = (Player) event.getWhoClicked();
     ItemStack stack = event.getCurrentItem();
     if (stack == null || !stack.hasItemMeta()) return;
     if (stack.getItemMeta().getDisplayName().equals("Une pomme g閚iale !")) {
       player.closeInventory();
       player.sendMessage(
           "Bravo, tu viens de cliquer sur " + stack.getItemMeta().getDisplayName() + " !");
       player.addPotionEffect(PotionEffectType.FIRE_RESISTANCE.createEffect(Integer.MAX_VALUE, 2));
     }
   }
 }
  @EventHandler
  public void InvClickEvent(InventoryClickEvent event) {
    ItemStack selectedItem = event.getCurrentItem();
    Player p = (Player) event.getWhoClicked();
    Inventory inv = event.getInventory();

    if (!inv.getName().equals(ChatColor.GREEN + "" + ChatColor.BOLD + "PLACE ITEMS BELOW")) {
      return;
    }

    if (selectedItem == null) {
      return;
    }
    if (selectedItem.getType().equals(Material.AIR)) {
      return;
    }

    if (selectedItem.getType().equals(Material.NETHER_FENCE)
        && selectedItem
            .getItemMeta()
            .getDisplayName()
            .equals(ChatColor.GRAY + "" + ChatColor.BOLD + "<--")) {
      event.setCancelled(true);
    }

    if (selectedItem.getType().equals(Material.STAINED_GLASS_PANE)) {
      if (selectedItem
          .getItemMeta()
          .getDisplayName()
          .equals(ChatColor.GREEN + "" + ChatColor.BOLD + "ACCEPT TRADE")) {
        event.setCancelled(true);
        tradeCountdown.put(event.getWhoClicked().getUniqueId(), 6);
        if (event
            .getInventory()
            .getItem(41)
            .getItemMeta()
            .getDisplayName()
            .equals(ChatColor.GREEN + "" + ChatColor.BOLD + "TRADE ACCEPTED")) {
          tradeCountdown.put(event.getWhoClicked().getUniqueId(), 6);
        }
      }
    }
  }
Beispiel #27
0
 @Override
 public boolean onClick(InventoryClickEvent event) {
   if (event.getInventory() == null
       || event.getInventory().getTitle() == null
       || !stripFormatting(event.getInventory().getTitle())
           .contains(stripFormatting(getTitle()))) {
     return false;
   }
   if (event.getSlotType() != InventoryType.SlotType.CONTAINER) {
     return true;
   }
   Player player = (Player) event.getWhoClicked();
   Inventory menu = event.getInventory();
   ItemStack returnItem = menu.getItem(getIndex(5, 0));
   String configName = returnItem.getItemMeta().getLore().get(0);
   String path = returnItem.getItemMeta().getLore().get(1);
   int page = getPage(returnItem.getItemMeta().getLore().get(2));
   int slot = event.getSlot();
   int row = slot / 9;
   int col = slot % 9;
   ItemStack clickedItem = event.getCurrentItem();
   if (slot >= getIndex(3, 0) && slot <= getIndex(3, 8)) {
     // increment buttons
     YmlConfiguration config = FileUtil.getYmlConfiguration(configName);
     int value = config.getInt(path, 0);
     int increment = getDisplayNameAsInt(clickedItem);
     if (event.getClick() == ClickType.LEFT) {
       value += increment;
     } else if (event.getClick() == ClickType.RIGHT) {
       value = increment;
     }
     config.set(path, value);
     config.set("dirty", true);
   }
   if (slot != getIndex(5, 0)) {
     player.openInventory(createEditMenu(configName, path, page));
   } else {
     player.openInventory(parent.createEditMenu(configName, path, page));
   }
   return true;
 }
Beispiel #28
0
  /**
   * This method will return the ItemStack the player is trying to equip. If the click event would
   * not result in equipping something null will be returned. Note that this algorithm is not
   * perfect. It's an adequate guess.
   *
   * @param event The InventoryClickEvent to analyze.
   * @return The ItemStack the player is trying to equip.
   */
  public static ItemStack isEquipping(InventoryClickEvent event) {
    boolean isShiftClick = event.isShiftClick();
    InventoryType inventoryType = event.getInventory().getType();
    SlotType slotType = event.getSlotType();
    ItemStack cursor = event.getCursor();
    ItemStack currentItem = event.getCurrentItem();

    if (isShiftClick) {
      if (inventoryType != InventoryType.CRAFTING) return null;
      if (slotType == SlotType.CRAFTING) return null;
      if (slotType == SlotType.ARMOR) return null;
      if (slotType == SlotType.RESULT) return null;
      if (currentItem.getType() == Material.AIR) return null;
      return currentItem;
    } else {
      if (slotType == SlotType.ARMOR) {
        return cursor;
      }
      return null;
    }
  }
 @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);
   }
 }
Beispiel #30
0
  @ClickHandler(
      status = {tNpcStatus.SELL, tNpcStatus.BUY},
      inventory = InventoryType.PLAYER)
  public void buyItems(InventoryClickEvent e) {
    e.setCancelled(true);
    // check permission
    if (!perms.has(player, "dtl.trader.buy")) return;

    clearSelection();
    int slot = e.getSlot();
    if (e.isLeftClick()) {
      if (selectAndCheckItem(e.getCurrentItem(), "buy")) {
        int scale = e.getCurrentItem().getAmount() / getSelectedItem().getAmount();
        if (scale == 0) return;

        if (handleClick(e.getRawSlot())) {
          if (!buyTransaction(scale)) {
            // send message
            locale.sendMessage(
                player,
                "trader-transaction-failed-trader-money",
                "npc",
                settings.getNPC().getName());
          } else {
            // remove the amount from inventory
            removeFromInventory(slot, scale);

            // send the transaction success message
            locale.sendMessage(
                player,
                "trader-transaction-success",
                "trader",
                getNPC().getName(),
                "player",
                player.getName(),
                "action",
                "#sold",
                "item",
                getSelectedItem().getName(),
                "amount",
                String.valueOf(getSelectedItem().getAmount() * scale),
                "price",
                String.valueOf(stock.parsePrice(getSelectedItem(), 0) * scale));

            // update the inventory lore
            updatePlayerInventory();
          }
        } else {
          // send the information message
          locale.sendMessage(
              player,
              "trader-transaction-item",
              "item",
              getSelectedItem().getName(),
              "amount",
              String.valueOf(getSelectedItem().getAmount()),
              "price",
              String.valueOf(stock.parsePrice(getSelectedItem(), 0)));
        }
      }
    } else {
      if (selectAndCheckItem(e.getCurrentItem(), "buy")) {
        int scale = e.getCurrentItem().getAmount() / getSelectedItem().getAmount();
        if (scale == 0) return;

        if (handleClick(e.getRawSlot())) {
          if (!buyTransaction()) {
            // send message
            locale.sendMessage(
                player,
                "trader-transaction-failed-trader-money",
                "npc",
                settings.getNPC().getName());
          } else {
            // remove the amount from inventory
            removeFromInventory(slot);

            // send the transaction success message
            locale.sendMessage(
                player,
                "trader-transaction-success",
                "trader",
                getNPC().getName(),
                "player",
                player.getName(),
                "action",
                "#sold",
                "item",
                getSelectedItem().getName(),
                "amount",
                String.valueOf(getSelectedItem().getAmount()),
                "price",
                String.valueOf(stock.parsePrice(getSelectedItem(), 0)));

            // update the inventory lore
            updatePlayerInventory();
          }
        } else {
          // send the information message
          locale.sendMessage(
              player,
              "trader-transaction-item",
              "item",
              getSelectedItem().getName(),
              "amount",
              String.valueOf(getSelectedItem().getAmount()),
              "price",
              String.valueOf(stock.parsePrice(getSelectedItem(), 0)));
        }
      }
    }
  }