Solved Change Name/Lore of item based on permission

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

  1. 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. So, the best option is use while creating item:

    Code (Text):
    if(player.hasPermission(/*I recommend use method getPermission() defined in your class that return right permission per kit*/)){
      //add green lore
    } else {
      //add red lore
    If you mean this, cause i do not understand your text so much. What you want.
  3. Ah I see. Is there away to apply it to all ItemStacks because say I have 60+ of these
    Code (Text):
    private static ItemStack cow(String name) {
        ItemStack i = new ItemStack(new ItemStack(Material.MUSHROOM_SOUP, 1));
        ItemMeta im = i.getItemMeta();
        im.setLore(Arrays.asList("&7Click to purchase the &aCow &7kit!","&7for &e10,000 &7coins!"));
        return i;
  4. I'd use player.hasPermission("bliep") ? Green : red
  5. You do not want to add the lore there. You'll want to add it when you are creating the gui.
    • Agree Agree x 1
  6. What do you mean?
    That is where I create the GUI how can I define player there? I tried
    Code (Text):
    private static ItemStack cow(String name, Player player)
    But it gives me an error where I define the Name of the item:

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

    I format it like this

    cow = cow("&6&lCow");
  7. You need to add the player to the constructor when calling it for initializing your cow variable
  8. Which constructor?

    Sent from my iPhone using Tapatalk
  9. The constructor you used when initializing the cow variable

    cow = cow("");

    You need to add a player variable to that
  10. How/Where in that would I add the player variable?? I tried a few things, none seemed to work..
  11. So if I am right, you have 60+ methods for every one itemstack/kit ? are you MAD ?; sorry if I am bad. And what about private static, that has no sense to use it.
  12. Each private static is for a different item/lore.
    Also I tried this:

    noob = item1("§6§lNoob", player); to declare the player instance. No luck. Do I need to declare player for the whole class?
  13. Code (Text):
    //change the item's lore
    // change the item's lore to something else

  14. Either:
    Code (Java):
    if (Player#hasPermission(Permission))
        // Player has permission! Hooray! Set the lore!
    } else {
        // Player doesn't have permission! Rip :( Set the lore to something else.
    Code (Java):
    ItemMeta.setLore(Collections.asSingletonList("Permission: " + (player.hasPermission(perm) ? ChatColor.GREEN + "Yes! :D" : ChatColor.RED + "No :(")));
    I'd go for the last if you're simply going to say if he has permission or not.
  15. Thanks guys :) I tried some of these by putting them in my private item stack, but no luck. I set up the private Item Stack like this:

    (String name, Player player)

    to define player, and it defines it but then I get an error where I set the display name of the item:

    Code (Text):
    cow = item1("&6&lCow");
    I get the item at item1 and there error is

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

    and I tried creating a player instance.
  16. Create a new item stack like this:
    Code (Text):
    //Create a new item stack with a lore, and set that item in the gui/menu
    //Create a new item stack with a different lore, and set that item in the gui/menu
    #16 RedNinjaPlaysMC, Jun 28, 2016
    Last edited: Jun 28, 2016
  17. Hmmmm, but how would I define player like that? I tried Player player;
  18. When are you opening the inventory? Using PlayerInteractEvent, or a command?
  19. Command

    Sent from my iPhone using Tapatalk
  20. Use
    Code (Text):
    Player player = (Player) sender;