Inventory Problem [Solved]

Discussion in 'Plugin Development' started by Nazeo, Jun 25, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    Nazeo

    Hello guys, I've made a plugin but i have a problem.
    When we click on an emerald it opens an inventory in which there is a diamond chestplate. When we click on that diamond chestplate, it opens another inventory in which there are different items. But in that inventory, there are no conditions that seem to work. can you help me with that?
    Tank's you Guys !

    Code:
    if (it != null && it.getType() == Material.EMERALD && it.getItemMeta().getDisplayName().equalsIgnoreCase("§aShop")){
                Inventory inv = Bukkit.createInventory(null, 54, "§8Shop");
             
                ItemStack gadgets = new ItemStack(Material.BLAZE_ROD);
                ItemMeta gadgetsI = gadgets.getItemMeta();
                gadgetsI.setDisplayName("§9Gadgets");
                gadgets.setItemMeta(gadgetsI);
                ItemStack chestplate = new ItemStack(Material.DIAMOND_CHESTPLATE);
                ItemMeta chestplateI = chestplate.getItemMeta();
                chestplateI.setDisplayName("§aPlastrons");
                chestplateI.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                chestplate.setItemMeta(chestplateI);
                ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
                ItemMeta helmetI = helmet.getItemMeta();
                helmetI.setDisplayName("§aChapeaux");
                helmetI.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                helmet.setItemMeta(helmetI);
                ItemStack pentalons = new ItemStack(Material.IRON_LEGGINGS);
                ItemMeta pentalonsI = pentalons.getItemMeta();
                pentalonsI.setDisplayName("§aPentalons");
                pentalonsI.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                pentalons.setItemMeta(pentalonsI);
                ItemStack bottes = new ItemStack(Material.GOLD_BOOTS);
                ItemMeta bottesI = bottes.getItemMeta();
                bottesI.setDisplayName("§aBottes");
                bottesI.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                bottes.setItemMeta(bottesI);
                ItemStack back = new ItemStack(Material.ARROW);
                ItemMeta backI = back.getItemMeta();
                backI.setDisplayName("§cRetour");
                back.setItemMeta(backI);
                inv.setItem(45, back);
                inv.setItem(20, gadgets);
                inv.setItem(22, chestplate);
                inv.setItem(13, helmet);
                inv.setItem(31, pentalons);
                inv.setItem(40, bottes);
                player.openInventory(inv);
            }
        }
    Code:
    @EventHandler
        public void onMoveItem(InventoryClickEvent event) {
    
            Inventory inv = event.getInventory();
            Player player = (Player) event.getWhoClicked();
            ItemStack current = event.getCurrentItem();
    
            if (current == null)
                return;
         
            if (inv.getName().equalsIgnoreCase("§8Shop")) {
                if (current.getType() == Material.BLAZE_ROD && current.getItemMeta().getDisplayName().equalsIgnoreCase("§9Gadgets")) {
                    event.setCancelled(true);
                    player.closeInventory();
                }
            }
         
            if (inv.getName().equalsIgnoreCase("§8Shop")) {
                if (current.getType() == Material.ARROW && current.getItemMeta().getDisplayName().equalsIgnoreCase("§cRetour")) {
                    event.setCancelled(true);
                    player.closeInventory();
                }
            }
         
            if (inv.getName().equalsIgnoreCase("§8Shop")) {
                if (current.getType() == Material.STAINED_GLASS_PANE && current.getItemMeta().getDisplayName().equalsIgnoreCase(" ")) {
                    event.setCancelled(true);
                }
            }
         
            if (inv.getName().equalsIgnoreCase("§8Shop")) {
                if (current.getType() == Material.DIAMOND_CHESTPLATE && current.getItemMeta().getDisplayName().equalsIgnoreCase("§aPlastrons")) {
                    Inventory chest = Bukkit.createInventory(null, 27, "§8Plastrons");
                 
                    ItemStack bling = new ItemStack(Material.GOLD_CHESTPLATE);
                    ItemMeta blingI = bling.getItemMeta();
                    blingI.setDisplayName("§6Bling§eBling");
                    blingI.setLore(Arrays.asList("§9Soyez Pimp !"));
                    blingI.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                    bling.setItemMeta(blingI);
                    chest.setItem(0, bling);
                    player.closeInventory();
                    player.openInventory(chest);
                }
            }
         
           if (inv.getName().equalsIgnoreCase("§8Plastrons")) {
                if (current.getType() == Material.GOLD_CHESTPLATE && current.getItemMeta().getDisplayName().equalsIgnoreCase("§6Bling§eBling")) {
                    ItemStack bling = new ItemStack(Material.GOLD_CHESTPLATE);
                    ItemMeta blingI = bling.getItemMeta();
                    blingI.setDisplayName("§6Bling§eBling");
                    blingI.setLore(Arrays.asList("§9Soyez Pimp !"));
                    blingI.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                    bling.setItemMeta(blingI);
                  
                    player.getInventory().setChestplate(bling);
                }
            }
    
            if (inv.getName().equalsIgnoreCase("§8Shop")) {
                if (current.getType() == Material.LEATHER_HELMET && current.getItemMeta().getDisplayName().equalsIgnoreCase("§aChapeaux")) {
                    event.setCancelled(true);
                }
            }
    
            if (inv.getName().equalsIgnoreCase("§8Shop")) {
                if (current.getType() == Material.IRON_LEGGINGS && current.getItemMeta().getDisplayName().equalsIgnoreCase("§aPentalons")) {
                    event.setCancelled(true);
                }
            }
    
            if (inv.getName().equalsIgnoreCase("§8Shop")) {
                if (current.getType() == Material.GOLD_BOOTS && current.getItemMeta().getDisplayName().equalsIgnoreCase("§aBottes")) {
                    event.setCancelled(true);
                }
            }
         
            if (player.isOp()) {
                event.setCancelled(false);
            }
            System.out.println(inv.getName());
        }
     
  2. Offline

    yPedx

    @Nazeo
    There's no need for multiple checks if the inventory has a specific name. You could just check the items inside one inventory name check. Example:
    Code:
    if (inv.getName().equalsIgnoreCase("§8Shop")) {
                if (current.getType() == Material.BLAZE_ROD && current.getItemMeta().getDisplayName().equalsIgnoreCase("§9Gadgets")) {
                    event.setCancelled(true);
                    player.closeInventory();
                } else
                if (current.getType() == Material.ARROW && current.getItemMeta().getDisplayName().equalsIgnoreCase("§cRetour")) {
                    event.setCancelled(true);
                    player.closeInventory();
                } else
                if (current.getType() == Material.STAINED_GLASS_PANE && current.getItemMeta().getDisplayName().equalsIgnoreCase(" ")) {
                    event.setCancelled(true);
                }}
    
    Are you saying nothing appears in the diamond_chestplate inventory? (the inventory that opens when you click it)
     
  3. Offline

    Nazeo

    I've try this but it doesn't work too :/

    When I open the Shop Inventory It work perfectly, I can't move items.
    thus when I click on the Diamond chestplate it open the "Plastrons" inventory.
    [​IMG]

    But in the "Plastrons" Inventory I can take the chestplate :/
    [​IMG]

    How can I solve that ?

    Code:
    @EventHandler
        public void onMoveItem(InventoryClickEvent event) {
    
            Inventory inv = event.getInventory();
            Player player = (Player) event.getWhoClicked();
            ItemStack current = event.getCurrentItem();
    
            if (current == null)
                return;
    
            if (inv.getName().equalsIgnoreCase("§8Menu")) {
                if (current.getType() == Material.BOW && current.getItemMeta().getDisplayName().equalsIgnoreCase("§eHunger Games")) {
                    event.setCancelled(true);
                    player.closeInventory();
                }
                else if (current.getType() == Material.BED && current.getItemMeta().getDisplayName().equalsIgnoreCase("§cBedWars")) {
                    event.setCancelled(true);
                    player.closeInventory();
                }
            }
        
            if (inv.getName().equalsIgnoreCase("§8Shop")) {
                if (current.getType() == Material.BLAZE_ROD && current.getItemMeta().getDisplayName().equalsIgnoreCase("§9Gadgets")) {
                    event.setCancelled(true);
                    player.closeInventory();
                }
            
                else if (current.getType() == Material.ARROW && current.getItemMeta().getDisplayName().equalsIgnoreCase("§cRetour")) {
                    event.setCancelled(true);
                    player.closeInventory();
                }
            
                else if (current.getType() == Material.ARROW && current.getItemMeta().getDisplayName().equalsIgnoreCase("§cRetour")) {
                        event.setCancelled(true);
                        player.closeInventory();
                }
            
                else if (current.getType() == Material.DIAMOND_CHESTPLATE && current.getItemMeta().getDisplayName().equalsIgnoreCase("§aPlastrons")) {
                        Inventory chest = Bukkit.createInventory(null, 27, "§8Plastrons");
                    
                        ItemStack bling = new ItemStack(Material.GOLD_CHESTPLATE);
                        ItemMeta blingI = bling.getItemMeta();
                        blingI.setDisplayName("§6Bling§eBling");
                        blingI.setLore(Arrays.asList("§9Soyez Pimp !"));
                        blingI.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                        bling.setItemMeta(blingI);
                        chest.setItem(0, bling);
                        player.closeInventory();
                        player.openInventory(chest);
                }
            
                else if (current.getType() == Material.LEATHER_HELMET && current.getItemMeta().getDisplayName().equalsIgnoreCase("§aChapeaux")) {
                        event.setCancelled(true);
                    }
    
                else if (current.getType() == Material.IRON_LEGGINGS && current.getItemMeta().getDisplayName().equalsIgnoreCase("§aPentalons")) {
                        event.setCancelled(true);
                    }
            
                else if (current.getType() == Material.GOLD_BOOTS && current.getItemMeta().getDisplayName().equalsIgnoreCase("§aBottes")) {
                        event.setCancelled(true);
                    }
                if (inv.getName().equalsIgnoreCase("§8Plastrons")) {
                    if (current.getType() == Material.GOLD_CHESTPLATE && current.getItemMeta().getDisplayName().equalsIgnoreCase("§6Bling§eBling")) {
                        ItemStack bling = new ItemStack(Material.GOLD_CHESTPLATE);
                        ItemMeta blingI = bling.getItemMeta();
                        blingI.setDisplayName("§6Bling§eBling");
                        blingI.setLore(Arrays.asList("§9Soyez Pimp !"));
                        blingI.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
                        bling.setItemMeta(blingI);
                    
                        player.getInventory().setChestplate(bling);
                    }
                }
            }
        
            if (player.isOp()) {
                event.setCancelled(false);
            }
            System.out.println(inv.getName());
        }
     
    Last edited: Jun 25, 2017
Thread Status:
Not open for further replies.

Share This Page