Solved plugin adds 66 infront of number [withdraw]

Discussion in 'Spigot Plugin Development' started by KiranHart, Aug 30, 2016.

  1. hey so In trying to make a withdraw/deposit plugin I got the withdraw part working but Ive ran into an issue I can't seem to fix.
    So say I do /withdraw 50 it gives me a paper with $50 on it but when I redeem it, it will give me $6650

    Can you guys help me out here I'm legit confused. If you can edit the code to work that will be great.

    /Withdraw Class: https://gist.github.com/anonymous/37adcb961d171c6dccb791e5cdbb05d6
    Withdraw Events: https://gist.github.com/anonymous/0f748b446498bee8e97351805e0194c9
    Code (Text):
    ############################################
    #+----------------------------------------+#
    #|                                        |#                                    
    #|         Withdraw Configuration         |#                                
    #|                                        |#
    #+----------------------------------------+#
    ############################################
    #Displays this if the money field in command is empty. ( /Withdraw <empty> )
    Invalid-Money-Amount: "&b&lUsage> &f&l/&eWithdraw &eAmt"
    Min-Amount: "&eThe minimum amount of money you can withdraw is &a$%MinAmount%"
    Max-Amount: "&eThe maximum amount of money you can withdraw is &a$%MaxAmount%"
    Withdrawed-Amount: "&c&l- &c&l$%WithdrawAmount%"
    Deposit-Amount: "&a&l+ &a&l$%DepositAmount%"
    BankNote:
      Withdraw:
        Min: 5
        Max: 2000000000
      #Any item can be used, NO SUPPORT FOR META DATA (stone:6) etc.
      Item: "paper"
      #Name of the bank note
      Name: "&6&lBank &e&lNote" # %PlayerName% can be used in title and lore.
      Lore:
        - "&eWithdrawed by: &6%PlayerName%"
    And yes, everything is registered in my main class. Vault is also setup.
     
  2. "import net.md_5.bungee.api.ChatColor;" in Withdraw.java isn't needed (wrong import)

    Code (Text):
                if (!(sender instanceof Player)) {
                    sender.sendMessage(
                            ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Player-only")));
                }

                if (sender instanceof Player) {
    Instead just use
    Code (Text):
    return;
    after sending the player the message instead of checking again if the sender is instanceof Player (or, you should just use IF sender instanceof Player){
    //code
    } else {
    //send user the message
    return;
    }
    It helps developers understand a lot better if you have one main path that executes the command successfully whereas the "else" parts generally mean there is something wrong like no permission, incorrect args, doesn't exist etc.

    another thing
    Code (Text):
    int amount = Integer.parseInt(args[0]);
    You're assuming it's an integer, you could get a NumberFormatException! Check if it is an integer first!


    Code (Text):
    public static boolean isInteger(String s){
    try{
    Integer.parseInt(s);
    } catch (NumberFormatException e){
    return false;
    }
    return true;
    }
    Now, I must ask how do you "redeem" one of these paper notes?
     
  3. You just right click it and it will remove the note and add the money that's where the problem is, it keeps adding 66 in front of the number
     
  4. Can you show me PlayerInteractEvent, it's what you're using yes?
     
  5. The regex you're using is leaving the 6 in there from the chat color, which is getting prefixed to your total amount. Use ChatColor.stripColor() to remove the color before using your regex.
     
    • Agree Agree x 1
  6. Tysm it worked
     
  7. Mark as solved please ;-; Clicked on it but its already solved. Wasted my time ;-;
     
    • Like Like x 2