Solved Uses Plugin

Discussion in 'Plugin Development' started by mehboss, Feb 18, 2019.

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

    mehboss

    I'm making a random plugin because I got bored, and I'm trying to remove 1 use from the lore after it becomes used; however, it works perfectly except for the color of the line keeps changing, and I can't find out a solution.

    CODE:
    Code:
                            List<String> handlore = e.getPlayer().getItemInHand().getItemMeta().getLore();
    
                            boolean oneUse = false;
                            for (String handl : handlore) {
    
                                if (handl.contains("Uses:")) {
    
                                    String hand1 = ChatColor.stripColor(handl).replaceAll("Uses: ", "");
                                    Integer uses = Integer.valueOf(hand1);
                                    if (uses <= 1) {
                                        oneUse = true;
                                        break;
    
                                    } else {
                                        uses--;
                                        String newline = handl.replaceAll(hand1, String.valueOf(uses));
                                     
                                        ItemMeta itemm = e.getPlayer().getItemInHand().getItemMeta();
                                        List<String> lore  = itemm.getLore();
                                        lore.set(loreline - 1, newline);
                                     
                                        itemm.setLore(lore);
                                        e.getPlayer().getItemInHand().setItemMeta(itemm);
                                        break;
    
                                    }
                                }
                            }
    
                            if (oneUse == true) {
                                    e.getPlayer().getInventory().removeItem(e.getPlayer().getItemInHand());
                                }
    Start Item:
    Click here
    End Items:
    Click here
    Click here
    Click here

    Also I made one hand variable with a 1 and the other with an L, so don't get confuzzled.
     
  2. Offline

    MightyOne

    If you add a ChatColor to a String it is simply a paragraph sign with a letter or number behind. So when you replace all int uses in String handl also the number of the ChatColor gets replaced and it's a new chatcolor. Maybe use the method subString instead of replaceAll
     
  3. Offline

    mehboss

    So, you confused me. Could you explain better? lol
     
  4. Offline

    MightyOne

    Code:
    ChatColor.GRAY + "Uses " + ChatColor.RESET + "7" = "§7Uses §r7"
    If you replace all 7 on this string you also replace the one from the color code. Therefore it will become a different color.


    LOL
     
    KarimAKL likes this.
  5. Offline

    mehboss

    Oh haha. I understand now smh. Thank you.
     
Thread Status:
Not open for further replies.

Share This Page