Problem with getting what a slot contains

Discussion in 'Spigot Plugin Development' started by HockeyFreak062, Apr 16, 2017.

  1. Hey! this is my code:
    Code (Java):
     
        @EventHandler
        public void onCraft(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked();

            if (player.getOpenInventory().getTitle().equals(ChatColor.GREEN + "" + ChatColor.BOLD + "Crafting Table")) {
                if (player.getOpenInventory().getItem(12) == new ItemStack(Material.STONE)) {

                    ItemStack glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 5);
                    ItemMeta meta = glass.getItemMeta();
                    meta.setDisplayName(ChatColor.GOLD + "Yes");
                    glass.setItemMeta(meta);

                    ItemStack glass1 = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 14);
                    ItemMeta meta1 = glass1.getItemMeta();
                    meta1.setDisplayName(ChatColor.GOLD + "No");
                    glass1.setItemMeta(meta1);

                    Inventory crafting2 = Bukkit.createInventory(null, 27,
                            ChatColor.GREEN + "" + ChatColor.BOLD + "Want to craft Slabs?");
                    crafting2.setItem(12, glass1);
                    crafting2.setItem(14, glass1);

                    player.openInventory(crafting2);
                }
            }
        }
    But this doenst work. Can someone help me find the problem? No errors are shown in the console and yes i registered the event.
     
  2. maybe try this:
    if (player.getInventory().getName().equals(ChatColor.GREEN + "" + ChatColor.BOLD + "Crafting Table")) {
    }
    instead
    if (player.getOpenInventory().getTitle().equals(ChatColor.GREEN + "" + ChatColor.BOLD + "Crafting Table")) {
    }
     
    • Agree Agree x 2
  3. Code (Java):
     
        @EventHandler
        public void onInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            Block block = event.getClickedBlock();
            Material material = block.getType();

            if (material == Material.WORKBENCH) {
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                    event.setCancelled(true);

                    ItemStack glass = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 15);
                    ItemMeta meta = glass.getItemMeta();
                    meta.setDisplayName(ChatColor.GOLD + "Crafing Table");
                    glass.setItemMeta(meta);

                    Inventory crafting = Bukkit.createInventory(null, 45, ChatColor.GREEN + "" + ChatColor.BOLD + "Crafting Table");
                    crafting.setItem(0, glass);
                    crafting.setItem(1, glass);
                    crafting.setItem(2, glass);
                    crafting.setItem(3, glass);
                    crafting.setItem(4, glass);
                    crafting.setItem(5, glass);
                    crafting.setItem(6, glass);
                    crafting.setItem(7, glass);
                    crafting.setItem(8, glass);
                    crafting.setItem(9, glass);
                    crafting.setItem(10, glass);
                    crafting.setItem(11, glass);
                    crafting.setItem(15, glass);
                    crafting.setItem(16, glass);
                    crafting.setItem(17, glass);
                    crafting.setItem(18, glass);
                    crafting.setItem(19, glass);
                    crafting.setItem(20, glass);
                    crafting.setItem(24, glass);
                    crafting.setItem(25, glass);
                    crafting.setItem(26, glass);
                    crafting.setItem(27, glass);
                    crafting.setItem(28, glass);
                    crafting.setItem(29, glass);
                    crafting.setItem(33, glass);
                    crafting.setItem(34, glass);
                    crafting.setItem(35, glass);
                    crafting.setItem(36, glass);
                    crafting.setItem(37, glass);
                    crafting.setItem(38, glass);
                    crafting.setItem(39, glass);
                    crafting.setItem(40, glass);
                    crafting.setItem(41, glass);
                    crafting.setItem(42, glass);
                    crafting.setItem(43, glass);
                    crafting.setItem(44, glass);

                    player.openInventory(crafting);
                }
            }
        }[/CODE
    ]
     
  4. that does not work either
     
  5. did that work for you? because it doesnt work for me
     
  6. yes i did register it
     
  7. yes it opens when you click it
     
  8. i know but if i do that it doesnt work