Solved Adding defined integers

Discussion in 'Plugin Development' started by PbJBOSS, Mar 9, 2014.

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

    PbJBOSS

    I need to add two integers that are defined so that the remaining number can be added to my "players.yml" This is the basic gist of it:
    Code:java
    1.  
    2. Player giveto = Bukkit.getServer().getPlayer(args[1]);
    3. Integer existingpoints = players.getInt("players." + giveto);
    4. Integer givepoints = args[1];
    5. if (args[0].equalsIgnoreCase("give")){
    6. if (giveto != null){
    7. players.set("players." + giveto.getName(), existingpoints += giveto);
    8.  
     
  2. Offline

    tissin

    You can just say:
    Code:java
    1. players.set("players." + giveto.getName(), existingpoints+giveto);


    You should also check if args[1] is a number.
     
    PbJBOSS likes this.
  3. Offline

    PbJBOSS

    tissin How do I check if its a number? Something like:
    Code:java
    1. if (args[1].isInt){
     
  4. Offline

    tissin


    Code:java
    1. try {
    2. Integer.parseInt(args[1]);
    3. } catch(NumberFormatException ex) {
    4. player.sendMessage("That is not a number.");
    5. return true;
    6. }
    7. Integer givePoints = args[1];
    8.  
     
    PbJBOSS likes this.
Thread Status:
Not open for further replies.

Share This Page