Get an int from an item lore

Discussion in 'Plugin Development' started by Camaloony l DragNet Owner, Jun 2, 2016.

Thread Status:
Not open for further replies.
  1. Hey, so, I'm making a cheque plugin and I've 'almost' got everything working but 1 crucial part, I need to get how much the cheque is worth to deposit that amount. Here is my lore :
    [​IMG]
    So, how would I be able to get the int from after the 'Total value: $' ?

    Thank you in advance for anyone that helps me.
     
  2. Offline

    timtower Moderator Moderator

  3. Code:
    String almostThereString = line.replace("Total value: $", "");
    almostThereString = ChatColor.stripColor(totalValueDeposit);
    return Integer.parseInt(totalValueDeposit);
    Would that work?
     
  4. Offline

    A5H73Y

    My two cents:
    Code:
    stringVariable.replaceAll("[^\\d.]", "");
    This means you would support any currency symbol etc.
     
  5. Offline

    timtower Moderator Moderator

    @Camaloony l DragNet Owner Try it, best way to find out.
    But I would strip the colors before you replace.
    @A5H73Y He could also just make the currency symbol configurable or get it through Vault.
     
  6. Don't suppose you could show me how? I'm really struggling...

    Here is my deposit code so far:
    Code:
        @EventHandler
        public void onUse(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
                if(player.getItemInHand().getType() == Material.PAPER) {
                    if(event.getItem().getItemMeta().getDisplayName().toLowerCase().contains("cheque")) {
                        event.getItem().getItemMeta().getLore().stream().filter(s -> ChatColor.stripColor(s).contains("Right-Click this to deposit it!")).forEach(s -> {
                            TTA_Methods.sendTitle(player, ChatColor.GREEN + "Cheques", 20, 60, 20, ChatColor.GRAY + "You have deposited: " + ChatColor.WHITE + "$" + ChatColor.GREEN + "", 20, 60, 20);
                        });
                    }
                }
            }
        }
     
  7. Offline

    timtower Moderator Moderator

    @Camaloony l DragNet Owner I won't do that.
    It is getting the string, stripping the colors, replacing a part, sending it to the player.
     
  8. Does this look right to you?

    Code:
                            for(String line : event.getItem().getItemMeta().getLore()) {
                                String almostThereValue = ChatColor.stripColor(line);
                                String almostThereValue2 = line.replace("Total value: $", "");
                                int totalDepositValue = Integer.parseInt(almostThereValue);
                            }
     
  9. Offline

    timtower Moderator Moderator

Thread Status:
Not open for further replies.

Share This Page