Changing item in custom inventory for a player depending on a variable

Discussion in 'Plugin Development' started by AnOrangeGamer, Dec 1, 2015.

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

    AnOrangeGamer

    Hello! I've been working on a plugin that has to deal with custom inventories and stuff, and I want to make it so when a player opens up this custom inventory, it'll show them an item depending on whether or not they're supposed to. For example, I want a player to see a pumpkin pie in the custom inventory only if their name is in a string list, but if their name is not in that string list they will not be shown the pumpkin pie. I want this to be custom for each individual player, so if Player A has their name in a string list, but Player B does not, only Player A will be able to see the pumpkin pie. This is what I have so far:

    Code:
    private static Inventory inv;
       
        public MapMenu(Main m) {
           
            inv = Bukkit.getServer().createInventory(null, 36, "Food");
           
            ItemStack pie = new ItemStack(Material.PUMPKIN_PIE);
            ItemMeta pieMeta = pie.getItemMeta();
            pieMeta.setDisplayName(ChatColor.GREEN + "Pie");
            pie.setItemMeta(pieMeta);
           
            inv.setItem(0, pie);
        }
       
        public void show(Player p) {
            p.openInventory(inv);
        }
     
  2. Offline

    Zombie_Striker

    @AnOrangeGamer
    I've heard stories of the mystical "if" operator. It's said that you can use them to check if a statement is true or not. If all the requirements are met, they can read a specific piece of code. The best part of this is that there is also rumors that there is an "else" clause that would only get triggered if the if statement's requirements are not met. If the "if" operator existed, you could check if the arraylist contains the player, and if so set the 1st slot to pie.

    Too bad there's nothing like that.

    </Sarcasm>
    Create a new inventory for each player, and if the player is in the arraylist, add the pie.

    [Edit] You should remove the static modifier from "inv".
     
    Mrs. bwfctower likes this.
  3. Offline

    AnOrangeGamer

    @Zombie_Striker
    In my show(Player p) method, do you think it would work if I put the if statement in there and if it's true, I add the pie there?

    EDIT: Although, I think the pie would be there for everyone though, I'll just use your method.
     
  4. Offline

    Zombie_Striker

    @AnOrangeGamer
     
  5. Offline

    MCMatters

    @AnOrangeGamer instead of pre making the inv, just construct it when you show it, and put the if statement in the show method.
     
Thread Status:
Not open for further replies.

Share This Page