Solved Inventory manipulation (Custom inventory and ItemStacks)

Discussion in 'Plugin Development' started by Sargock, Jul 7, 2015.

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

    Sargock

    I was working on a custom inventory, and I've got a problem
    My idea was that there were some states ( a, b, c, for example) and when you open the custom inventory, depending on your state, it shows one or another ItemStacks.

    This is the code I got, but it doesn't work (it always show ItemStack form the first state), any idea? Thanks

    Code:
        @EventHandler
        public void onPlayerOpen(PlayerInteractEvent e){
          
            String world = (String) plugin.config.getString("esponja.world");
            World worldset = Bukkit.getWorld(world);
            int x = plugin.config.getInt("esponja.X");
            int y = plugin.config.getInt("esponja.Y");
            int z = plugin.config.getInt("esponja.Z");
            
            Location loc1 = new Location (worldset, x, y, z);
          
            e.getAction();
            if(Action.RIGHT_CLICK_BLOCK != null){
                if(e.getClickedBlock().getType().equals(Material.SPONGE)){
                    if(e.getClickedBlock().getLocation().equals(loc1)){
                      
                        Player p = e.getPlayer();
                      
                        Inventory quests = Bukkit.createInventory(null, 27, "Misiones");
                      
                        if(plugin.quests.getInt("usuarios." + e.getPlayer() + ".mision1.estado") == 0){
                        
                            ItemStack mision1_0 = new ItemStack(Material.NETHER_STAR,1);
                            ItemMeta mision1_0_meta = mision1_0.getItemMeta();
                            mision1_0_meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.AQUA + "A por madera!");
                            List<String> mision1_0_loreList = new ArrayList<String>();
                            mision1_0_loreList.add(ChatColor.YELLOW + "Tala" + ChatColor.AQUA + " 500 " + ChatColor.YELLOW + "bloques de madera.");
                            mision1_0_loreList.add(ChatColor.GRAY + "Click para empezar la mision!");
                            mision1_0_meta.setLore(mision1_0_loreList);
                            mision1_0.setItemMeta(mision1_0_meta);
                      
                        quests.setItem(0, new ItemStack(mision1_0));
                      
                        }
                      
                        else if(plugin.quests.getInt("usuarios." + e.getPlayer() + ".mision1.estado") == 1){
                          
                            int M1 = plugin.quests.getInt("usuarios." + e.getPlayer() + ".mision1.progreso");
                            
                            ItemStack mision1_1 = new ItemStack(Material.NETHER_STAR,1);
                            ItemMeta mision1_1_meta = mision1_1.getItemMeta();
                            mision1_1_meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.AQUA + "A por madera!");
                            List<String> mision1_1_loreList = new ArrayList<String>();
                            mision1_1_loreList.add(ChatColor.GREEN + "Mision en progreso!");
                            mision1_1_loreList.add(ChatColor.AQUA + "Progreso: " + ChatColor.GRAY + "(" + M1 + "/500)");
                            mision1_1_meta.setLore(mision1_1_loreList);
                            mision1_1.setItemMeta(mision1_1_meta);
                          
                            quests.setItem(0, new ItemStack(mision1_1));
                          
                            }                  
                      
                        else if(plugin.quests.getInt("usuarios." + e.getPlayer().getName() + ".mision1.estado") == 2){
                                
                                ItemStack mision1_2 = new ItemStack(Material.NETHER_STAR,1);
                                ItemMeta mision1_2_meta = mision1_2.getItemMeta();
                                mision1_2_meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.AQUA + "A por madera!");
                                List<String> mision1_2_loreList = new ArrayList<String>();
                                mision1_2_loreList.add(ChatColor.GREEN + "Mision finalizada!");
                                mision1_2_loreList.add(ChatColor.GRAY + "Click para recoger la recompensa!");
                                mision1_2_meta.setLore(mision1_2_loreList);
                                mision1_2.setItemMeta(mision1_2_meta);
                              
                                quests.setItem(0, new ItemStack(mision1_2));
                              
                                }
                      
                        else if(plugin.quests.getInt("usuarios." + e.getPlayer() + ".mision1.estado") == 3){
                            
                            ItemStack mision1_3 = new ItemStack(Material.NETHER_STAR,1);
                            ItemMeta mision1_3_meta = mision1_3.getItemMeta();
                            mision1_3_meta.setDisplayName(ChatColor.BOLD + "" + ChatColor.AQUA + "A por madera!");
                            List<String> mision1_3_loreList = new ArrayList<String>();
                            mision1_3_loreList.add(ChatColor.GREEN + "Mision finalizada!");
                            mision1_3_meta.setLore(mision1_3_loreList);
                            mision1_3.setItemMeta(mision1_3_meta);
                          
                            quests.setItem(0, new ItemStack(mision1_3));
                          
                            }
    
                       p.openInventory(quests); 
                      
                    }
                }
            }
        }
     
  2. Print this value to the console.
    I think the code should be e.getPlayer().getName().
     
    Sargock and KingFaris11 like this.
  3. Offline

    Sargock

    Thanks
     
Thread Status:
Not open for further replies.

Share This Page