Solved cannot convert from void to Inventory

Discussion in 'Spigot Plugin Development' started by Loxo, Jun 14, 2018.

  1. Hey,

    I have a problem by defining a variable.
    I need to define p what I tried to do. Is it the right way:
    "Player p = (Player) e.getWhoClicked();"

    But when I do this it says: "cannot convert from void to Inventory"

    Here the part of the code:


    Code (Text):
        @EventHandler
        public void onClick1(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();
            Inventory shop = openShop(p);  // it says: "Type mismatch: cannot convert from void to Inventory"
            Inventory Eff =Bukkit.createInventory(e.getWhoClicked(), 9*1, "§eEffekte");
            fillInventory(Eff, Utils_Item.createItem(Material.STAINED_GLASS_PANE,  1, 7, ""));
            Eff.setItem(2, Utils_Item.createItem(Material.LAVA_BUCKET, 1, 0, "§cLava"));
            Eff.setItem(4, Utils_Item.createItem(Material.RED_ROSE, 1, 0, "§4Herzen"));
            Eff.setItem(6, Utils_Item.createItem(Material.GLOWSTONE_DUST, 1, 0, "§fKon§afetti"));
            Eff.setItem(8, Utils_Item.createItem(Material.BARRIER, 1, 0, "§cZurück"));
            Eff.setItem(0, Utils_Item.createItem(Material.BARRIER, 1, 0, "§cZurück"));
             if(e.getCurrentItem().getType() == (Material.BLAZE_POWDER)) {
                e.getWhoClicked().openInventory(Eff);
                if(e.getCurrentItem().getType() == (Material.BARRIER)) {
                    e.getWhoClicked().openInventory(shop);
                }
            }
         
            }
     
    #1 Loxo, Jun 14, 2018
    Last edited: Jun 14, 2018
  2. Whats your openShop method?
     
  3. My guess is the 'openShop' method is returning void instead of Inventory.
     
  4. Code (Text):
        public static void openShop(Player p) {
            Inventory shop = Bukkit.createInventory(null, 9*3, "§2Extras");
            fillInventory(shop, Utils_Item.createItem(Material.STAINED_GLASS_PANE,  1, 7, ""));
            shop.setItem(10, Utils_Item.createItem(Material.SLIME_BLOCK, 1, 0, "§3Ballons"));
            shop.setItem(12, Utils_Item.createItem(Material.BLAZE_POWDER, 1, 0, "§eEffekte"));
            shop.setItem(14, Utils_Item.createItem(Material.FISHING_ROD, 1, 0, "§aGadgets"));
            shop.setItem(16, Utils_Item.createItem(Material.NAME_TAG, 1, 0, "§bPets"));
         
     
            p.openInventory(shop);
            p.playSound(p.getLocation(), Sound.BLOCK_CHEST_OPEN, 1, 2);
         
        }
    -----
    It is in the same file
     
  5. Try this openShop method:
    Code (Java):
    public static Inventory openShop(Player p) {
            Inventory shop = Bukkit.createInventory(null, 9*3, "§2Extras");
            fillInventory(shop, Utils_Item.createItem(Material.STAINED_GLASS_PANE,  1, 7, ""));
            shop.setItem(10, Utils_Item.createItem(Material.SLIME_BLOCK, 1, 0, "§3Ballons"));
            shop.setItem(12, Utils_Item.createItem(Material.BLAZE_POWDER, 1, 0, "§eEffekte"));
            shop.setItem(14, Utils_Item.createItem(Material.FISHING_ROD, 1, 0, "§aGadgets"));
            shop.setItem(16, Utils_Item.createItem(Material.NAME_TAG, 1, 0, "§bPets"));
         
     
            p.openInventory(shop);
            p.playSound(p.getLocation(), Sound.BLOCK_CHEST_OPEN, 1, 2);

            return shop;
         
        }
     
  6. Then this comes: "Void methods cannot return a value"
     
  7. Don't spoon feed :confused:
     
  8. Never mind. Now it works. Thank you. I had to change the void to "Inventory"
     

Share This Page