Solved {Easy?} Changing a Lore.

Discussion in 'Plugin Development' started by MordorKing78, Sep 3, 2014.

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

    MordorKing78

    Problem: What I'm trying to do is, I am trying to make it when you right click a sign it will add a lore. But dont know how to do it. I made something up but it didnt work. can someone give me a solution?

    (The Code I am now going to give is maybe not proper, Sorry)
    Code:java
    1. if (e.getClickedBlock().getState() instanceof Sign) {
    2. Player p = (Player)e.getPlayer();
    3. Sign s = (Sign) e.getClickedBlock().getState();
    4. if (s.getLine(0).equalsIgnoreCase("§4[§eLevelUp§4]")) {
    5. if (s.getLine(1).equalsIgnoreCase("Explode")) {
    6. if(p.getInventory().getItemInHand().getType().equals(Material.DIAMOND_PICKAXE)){
    7. if(newConfigz.getInt(p.getUniqueId() + ".Tokens") >= Integer.parseInt(s.getLine(2))){
    8. p.sendMessage("Works!");
    9. ItemStack item = p.getItemInHand();
    10. ItemMeta meta = item.getItemMeta();
    11. ArrayList<String> lore = (ArrayList<String>) meta.getLore();
    12. meta.setLore(lore);
    13. item.setItemMeta(meta);
    14. p.sendMessage("Not!");
    15. }else{
    16. p.sendMessage("§cYou do not have enough eTokens!");
    17. }
    18. }
    19. }
    20. }
     
  2. Offline

    Peter25715

    Hey there, MordorKing78.
    can you tell me what exactly you want? Do you just want to change the lore?
    Take this example :
    Code:java
    1. meta.setDisplayName(ChatColor.DARK_PURPLE + "Chain Helmet");
    2. meta.setLore(Arrays.asList(ChatColor.ITALIC + "§aThis is a crafted helmet!"));
     
  3. MordorKing78
    Code:
    ArrayList<String> lore =(ArrayList<String>)
    meta.getLore();meta.setLore(lore);
    All you are doing is setting the current Lore as the new lore. You need to put something along the lines of
    Code:
    lore.add(NEW_LORE);
     
    MordorKing78 and Peter25715 like this.
  4. Offline

    MordorKing78

    Peter25715 I want to change the lore of the item a player is holing in his hand
     
  5. Offline

    Peter25715

    MordorKing78 try this.
     
Thread Status:
Not open for further replies.

Share This Page