Solved If a player has a certain set lore to "Unlocked"

Discussion in 'Spigot Plugin Help' started by MaxNatural, May 12, 2016.

  1. Hello! I am trying to make it so that if a player has a particle unlocked it will change the lore to it saying "Unlocked" same thing if they don't have it unlocked.

    This is the code to make the item in the GUI for the particles.

    Code (Text):
            ItemStack star = new ItemStack(Material.FIREWORK);
            ItemMeta sMeta = star.getItemMeta();
            sMeta.setDisplayName(ChatColor.GRAY + "" + ChatColor.BOLD + "Fireworks");
            List<String> sLore = new ArrayList<String>();
            //sLore.add(ChatColor.GRAY + "" + ChatColor.ITALIC + "Cool firework!");
            //sMeta.setLore(sLore);
            star.setItemMeta(sMeta);
            if (player.hasPermission("ch.particles.firework")) {
                sMeta.setLore(Arrays.asList(new String[] { ChatColor.GRAY + "" + ChatColor.ITALIC + "Hello" , ChatColor.GREEN + "" + ChatColor.ITALIC + "Unlocked" }));
            } else {
                sMeta.setLore(Arrays.asList(new String[] { ChatColor.GRAY + "" + ChatColor.ITALIC + "Hello" , ChatColor.RED + "" + ChatColor.ITALIC + "Locked" }));
            }
           
    This is the code if the player has the permission or not. It activates the particle.

    Code (Text):
        @EventHandler
        public void onPlayerMove5(PlayerEvent e) {
        if (e.getPlayer().hasPermission("ch.particles.firework")) {
            if (star.contains(e.getPlayer().getUniqueId())) {
                if (star.contains(e.getPlayer().getUniqueId())) {
                ParticleEffect.FIREWORKS_SPARK.display(10, 15, 20, 0, 0, e.getPlayer().getLocation().add(0,0.1,0), 70);
               
        } else {
            e.getPlayer().sendMessage(Hub.noperm);
        }
            }
        }
           
    If you can help I would be very grateful! :D
     
  2. Make the permission of them plugin.items name, then cycle thru all of the items in the inv and check if he has permission of plugin.items name do add lore unlocked, else do not unlocked

    Edit: remember to strip chatcolor when doing this
     
  3. Is there anyway you can make a quick example? I don't need all the code just the start.
    Thank you!
     
  4. if (p.hasPermission("permission")) {
    make the lore unlocked
    } else {
    make the lore locked }
     
  5. I tried that and it doesn't work for me. the lore doesn't show up.

    Code (Text):
        if (player.hasPermission("ch.particles.firework")) {
                seLore.add(ChatColor.GREEN + "" + ChatColor.ITALIC + "Unlocked");
                seMeta.setLore(seLore);
                //sMeta.setLore(Arrays.asList(new String[] { ChatColor.GRAY + "" + ChatColor.ITALIC + "Hello" , ChatColor.GREEN + "" + ChatColor.ITALIC + "Unlocked" }));
            } else {
             
                sLore.add(ChatColor.RED + "" + ChatColor.ITALIC + "Locked");
                sMeta.setLore(sLore);
                //sMeta.setLore(Arrays.asList(new String[] { ChatColor.GRAY + "" + ChatColor.ITALIC + "Hello" , ChatColor.RED + "" + ChatColor.ITALIC + "Locked" }));
            }
           

    EDIT: I have fixed it! I forgot to set the item meta to the item :p
    Thanks everyone!
     
    #5 MaxNatural, May 12, 2016
    Last edited: May 12, 2016