Making kills and deaths display as integers, and have the kdr still be accurate.

Discussion in 'Plugin Development' started by Cyber_Pigeon, May 10, 2014.

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

    Cyber_Pigeon

    Hello, I am coding a plugin, and when I do /stats it displays my kdr correctly, but it displays my kills and deaths as a decimal too. Can I have some help? Here is my code:
    Code:java
    1. package me.mono.commands;
    2.  
    3. import java.text.DecimalFormat;
    4.  
    5. import me.mono.Main;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandExecutor;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12.  
    13. public class Stats implements CommandExecutor {
    14.  
    15. public Stats(Main plugin) {
    16. this.plugin = plugin;
    17. }
    18.  
    19. private Main plugin;
    20.  
    21. public boolean onCommand(CommandSender sender, Command cmd, String Label, String args[]){
    22. if(cmd.getName().equals("stats")){
    23. Player p = (Player) sender;
    24.  
    25. double kills = this.plugin.getConfig().getDouble("Kills." + p.getName() + ".Ammount", Double.valueOf(this.plugin.getConfig().getDouble("Kills." + p.getName() + ".Ammount")));
    26. double deaths = this.plugin.getConfig().getDouble("Deaths." + p.getName() + ".Ammount", Double.valueOf(this.plugin.getConfig().getDouble("Deaths." + p.getName() + ".Ammount")));
    27. double kdr = kills / deaths;
    28. String credits = this.plugin.getConfig().getString(new StringBuilder("Credits.").append(p.getName()).append(".Ammount").toString());
    29.  
    30. DecimalFormat decimalFormat = new DecimalFormat("#.##");
    31. decimalFormat.format(kdr);
    32.  
    33. p.sendMessage(ChatColor.GOLD + "=====[" + ChatColor.WHITE + "Stats: "
    34. + p.getName() + ChatColor.GOLD + "]=====");
    35. p.sendMessage(ChatColor.GOLD + "Kills: " + ChatColor.WHITE + kills);
    36. p.sendMessage(ChatColor.GOLD + "Deaths: " + ChatColor.WHITE + deaths);
    37. p.sendMessage(ChatColor.GOLD + "KDR: " + ChatColor.WHITE + decimalFormat.format(kdr));
    38. p.sendMessage(ChatColor.GOLD + "Credits: " + ChatColor.WHITE + credits);
    39. p.sendMessage(ChatColor.GOLD + "=========================");
    40. }
    41. return false;
    42. }
    43. }
     
  2. Offline

    Gater12

    Cyber_Pigeon
    Parse kills and deaths as Integer whilst kdr is a double with kills / deaths.
     
  3. Offline

    1Rogue

    Code:java
    1. double kdr = (double) kills / (double) deaths
     
  4. Offline

    Cyber_Pigeon

    When I do that, the KDR becomes an integer.
    When I do that, it stays the same.
     
  5. Offline

    Gater12

    Cyber_Pigeon
    Did you try both of those at the same time?
     
  6. Offline

    Cyber_Pigeon

Thread Status:
Not open for further replies.

Share This Page