Problem with calling a method from another class

Discussion in 'Plugin Development' started by RBHB16, Nov 1, 2015.

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

    RBHB16

    So I made some switch cases and I'm trying to call them in another class but the name of the case says it cannot be resolved to a variable. Any ideas/solutions?

    DrugStorage Class (cases)
    Code:
    package com.redstery11.prisondrugs;
    
    import java.util.Arrays;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class DrugStorage {
       
    
        //create your drug itemstacks and lore lists here
        private ItemStack unrolledblunt = new ItemStack(Material.INK_SACK, 1, (short)3);
      
        private ItemMeta unrolledbluntmeta = unrolledblunt.getItemMeta();
       
       
       
        private ItemStack rolledblunt = new ItemStack(Material.STICK);
       
        private ItemMeta bluntmeta = rolledblunt.getItemMeta();
       
      
       
        private ItemStack emptypipe = new ItemStack(Material.BLAZE_ROD);
       
        private ItemMeta emptypipemeta = emptypipe.getItemMeta();
       
       
        private ItemStack pipe = new ItemStack(Material.BLAZE_ROD);
       
        private ItemMeta pipemeta = pipe.getItemMeta();
       
       
        private ItemStack coke = new ItemStack(Material.SUGAR);
       
        private ItemMeta cokemeta = coke.getItemMeta();
      
        
        //This will update all these itemstacks with the correct lore
        public void updateDruglores() {
          
            unrolledbluntmeta.setDisplayName(ChatColor.DARK_GREEN + "Blunt");
          
            unrolledbluntmeta.setLore(Arrays.asList(ChatColor.GOLD + "Use this to craft a blunt!"));
           
            unrolledblunt.setItemMeta(unrolledbluntmeta);
           
          
            bluntmeta.setDisplayName(ChatColor.DARK_GREEN + "Blunt");
           
            bluntmeta.setLore(Arrays.asList(ChatColor.GOLD + "Shift + Right Click to get baked!", ChatColor.GRAY + "Unstack blunts before consuming!"));
           
            rolledblunt.setItemMeta(bluntmeta);
           
           
            emptypipemeta.setDisplayName(ChatColor.YELLOW + "Pipe");
           
            emptypipemeta.setLore(Arrays.asList(ChatColor.GOLD + "Use this to craft a functioning pipe!"));
           
            emptypipe.setItemMeta(emptypipemeta);
           
           
           
            pipemeta.setDisplayName(ChatColor.DARK_BLUE + "Pipe");
           
            pipemeta.setLore(Arrays.asList(ChatColor.GOLD + "Shift + Right click to hit it!", ChatColor.GRAY + "Unstack pipes before consuming!"));
           
            pipe.setItemMeta(pipemeta);
           
           
            cokemeta.setDisplayName(ChatColor.BLUE + "Pure Cocaine");
           
            cokemeta.setLore(Arrays.asList(ChatColor.GOLD + "Purest of all cocaine"));
           
            coke.setItemMeta(cokemeta);
          
            //More drugs go here for instance
        }
      
        // You can call this method anywhere in your code by creating an instance of this class and calling it.
        // Side note: You can use ENUMs for the search, but strings are easier to understand.
        public ItemStack getDrug(String drugname) {
          
            //Initialize the drug lore
          
            switch(drugname) {
                case "unrolledblunt":
                    return this.unrolledblunt;
                   
                case "emptypipe":
                    return this.emptypipe;
                   
                case "pipe":
                    return this.pipe;
                   
                case "coke":
                    return this.coke;
                //More drugs here again
                default:
                    return null;
            }
          
        }
      
    }
    
    
    CraftingBlunt class (where i want to call the method)
    Code:
    package com.redstery11.prisondrugs.events.player;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.CraftItemEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;
    import org.bukkit.inventory.ShapelessRecipe;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import com.redstery11.prisondrugs.DrugStorage;
    import com.redstery11.prisondrugs.MainClass;
    
    public class CraftingBlunt implements Listener {
        public DrugStorage drugstorage = new DrugStorage();
       
        public CraftingBlunt(MainClass mainClass) {
        }
       
    
       
       
       
    
        @EventHandler
        public void bRecipe(CraftItemEvent evt) {
            DrugStorage drugstorage = new DrugStorage();
            ItemStack beans = new ItemStack(Material.INK_SACK, 1, (short) 3);
            /*Player p = (Player) evt.getWhoClicked();
            ItemStack unrolledblunt = new ItemStack(Material.INK_SACK, 1, (short) 3);
           
            ItemMeta meta = unrolledblunt.getItemMeta();
            meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.BLUE + "Unrolled Blunt");
            List<String> lore = new ArrayList<String>();
            lore.add(ChatColor.GRAY + "Use this to craft a rolled blunt!");
            meta.setLore(lore);
            unrolledblunt.setItemMeta(meta);
            ShapedRecipe unrolledrecipe = new ShapedRecipe(unrolledblunt);
            unrolledrecipe.shape("   ", "PPP", "   ");
            unrolledrecipe.setIngredient('P', Material.PAPER);
           
            ItemStack rolledblunt = new ItemStack(Material.STICK);
           
            ItemMeta meta2 = rolledblunt.getItemMeta();
            meta2.setDisplayName(ChatColor.BOLD + "" + ChatColor.GREEN + "Blunt");
            meta2.setLore(Arrays.asList(ChatColor.GRAY + "Shift + Right Click to get baked", (ChatColor.GOLD + "Unstack blunts before consuming!")));
            rolledblunt.setItemMeta(meta2);       
           
            ShapelessRecipe rolledrecipe = new ShapelessRecipe(rolledblunt);
            rolledrecipe.addIngredient(Material.SUGAR_CANE);
            rolledrecipe.addIngredient(unrolledblunt.getData());*/
           
            if(!evt.getInventory().contains(drugstorage.getDrug(unrolledblunt))) {
               
            }
    
    
    }
    }
       
    
     
  2. Offline

    87pen

    Extend?
     
  3. Offline

    RBHB16

    I created an instance of it though.

    I made the top of it extend to DrugStorage and implement listener, but it still gives an error
     
  4. Offline

    Scimiguy

    Yeah I have no idea what you're asking for
     
  5. Offline

    RBHB16

    I made cases in the drug storage class so I can call them in another class to use them to check the lores of the items used to be crafted. So I want to prevent players from using regular coco beans to craft a custom item because I made a custom lore for coco beans. So basically I want to be able to check if the coco beans with the custom lore are being used, and if they aren't it will cancel the event.
     
  6. Offline

    87pen

    @RBHB16 get craftingblunt to extend drugstorage and get one of them to be a JavaPlugin. Make sure all variables and methods you are trying to grab is public.
     
  7. Offline

    mythbusterma

    @87pen

    Make sure all variables have public getter methods*
     
    87pen likes this.
  8. Offline

    RBHB16

    I realized what I did wrong, I just needed to write it as a string, not an item stack :p
     
Thread Status:
Not open for further replies.

Share This Page