Change Name/Lore of item based on players permission

Discussion in 'Plugin Development' started by glasseater, Jun 26, 2016.

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

    glasseater

    Hey guys,

    So basically I have a kit shop GUI plugin. What I am wondering how to do is change the lore/name of the item based on the players permission. For example if they don't have the permission kit.cow the name will be red or the lore will say Locked. If they do however have the permission kit.cow it will appear green and the lore would say unlocked. Is there an easy way to do this because I have many ItemStacks, and I would like if I can just create a method to do it instead of adding a check for every item. Thanks for your help!
     
  2. Offline

    Zombie_Striker

    @glasseater
    Here's some Psudocode
    Code:
    ChatColor nameColor;
    List<String> lore ;
    if(player.hasPermission("Perm")){
     lore = "locked"; 
     nameColor = RED
    }else{
     lore = "not - locked";
     nameColor = GREEN
    }
    ItemStack.setName(nameColor+"name");
    ItemStack.setLore(lore);
     
  3. Offline

    glasseater

    @Zombie_Striker

    Hmmm, is there away to incorporate it into a private static?

    I tried something like this:

    Code:
    private static ItemStack item1(String name, Player player) {
    
        ItemStack i = new ItemStack(new ItemStack(Material.MUSHROOM_SOUP, 1));
        ItemMeta im = i.getItemMeta();
        im.setDisplayName(name);
        if(player.hasPermission("kit.noob")) {
        im.setLore(Arrays.asList("&a&lUNLCOKED"));
        }else{
            im.setLore(Arrays.asList("&c&lLOCKED"));
        }
        i.setItemMeta(im);
        return i;
    }
    Now there are no errors in that section, but above where I declare the item name, there is:
    Code:
    noob = item1("&6&lNoob");
    Where it says item1 above this there is an error:

    The method item1(String, Player) in the type Shop is not applicable for the arguments (String)

    Or if there is a way to make a method? Because I have many ItemStacks and it would be easier. If not its no big deal.
     
  4. Offline

    Zombie_Striker

    @glasseater
    The reason you got the error is because you forgot to provide a Player instance. (Notice the "item1(String,Player)"). Just provide the player who opened the inventory and your problem should be solved.

    For your first question: yes. All you need to do is write the code that I provided.
     
  5. Offline

    glasseater

    @Zombie_Striker
    But how/where would I provide the player instance here
    Code:
    noob = item1("&6&lNoob");
     
  6. Offline

    Zombie_Striker

    @glasseater
     
  7. Offline

    glasseater

    @Zombie_Striker
    I will test

    EDIT: Ok I tested. No luck
    noob = item1("§6§lNoob", player);
    How can I declare player for the whole class?

    @Zombie_Striker
    So I found out the error is coming from String name, Player player.
    But its not letting me declare it. Which leads me to think something is misplaced...

    bumppppp

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 27, 2016
  8. @glasseater
    1. No need for the static
    2. I guess you are trying to get this statically from a different class, remove the word static, pass the instance and access it like that.
     
Thread Status:
Not open for further replies.

Share This Page