So I got some help from ChaseChocolate and Cubix Coders, and have this code, to check player stats. I honestly have no idea if this should work or not, but I want it so when players do /stats it shows kills, deaths killstreak and kdr. I was just messing around with the message thing. Code:java if(commandLabel.equalsIgnoreCase("stats") && args.length == 0){ int kills = playerKills.get(player.getName()); int deaths = playerDeaths.get(player.getName()); int killStreak = playerKillStreaks.get(player.getName()); double kdr = kills / deaths; int kdrRound = Math.round(kdr); player.sendMessage(ChatColor.GOLD + "You have" + playerKills.get(player.getName()) + "total kills"); player.sendMessage(ChatColor.GOLD + "You have" + playerDeaths.get(player.getName()) + "total deaths"); player.sendMessage(ChatColor.GOLD + "You have a killstreak of " + playerKillStreaks.get(player.getName()) + "kills"); } Oops! These are my hash maps and other stuff: Code:java public HashMap<String, Integer> playerKills = new HashMap<String, Integer>(); public HashMap<String, Integer> playerKillStreaks = new HashMap<String, Integer>(); public HashMap<String, Integer> playerDeaths = new HashMap<String, Integer>(); Code:java @EventHandler public void onPlayerKill(PlayerDeathEvent event) { Player victim = event.getEntity(); Player p = event.getEntity(); if (victim.getKiller() instanceof Player) { Bukkit.broadcastMessage(ChatColor.RED +p.getDisplayName() + ChatColor.WHITE +" Just got "+ ChatColor.BOLD+ "Killed "+ ChatColor.WHITE+ "By "+ ChatColor.RED + victim.getKiller().getName()); playerKills.put(p.getName(), +1); playerKillStreaks.put(p.getName(), +1); } } Code:java @EventHandler public void onPlayerDeath(PlayerDeathEvent e) { Player victim = e.getEntity(); if(victim.getKiller() instanceof Player) { playerDeaths.put(victim.getName() + 1, null); playerKillStreaks.remove(victim.getName()); } } Code:java @EventHandlerpublic void onPlayerKillstreak(PlayerDeathEvent event){if(event.getEntity().getKiller() instanceof Player){Player killer = event.getEntity().getKiller();int numKills = kills.get(killer.getName());kills.put(killer.getName(), +1);killer.sendMessage(ChatColor.GREEN + "You have a killstreak of " + numKills + " so far!");killer.getInventory().addItem(new ItemStack(Material.MUSHROOM_SOUP, numKills * 2));}} EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I dont really know, I just know this wont work. only error I get is on this line. Code:java int kdrRound = Math.round(kdr); It says: Type mismatch: Can not convert from long to int.
lcpvp So at what line would that be? Because I don't see you doing that anywhere in the code you've posted.
Code:java if(commandLabel.equalsIgnoreCase("stats") && args.length == 0){int kills = playerKills.get(player.getName());int deaths = playerDeaths.get(player.getName());int killStreak = playerKillStreaks.get(player.getName());double kdr = kills / deaths;long kdrRound = Math.round(kdr);player.sendMessage(ChatColor.GOLD + "You have" + playerKills.get(player.getName()) + "total kills");player.sendMessage(ChatColor.GOLD + "You have" + playerDeaths.get(player.getName()) + "total deaths");player.sendMessage(ChatColor.GOLD + "You have a killstreak of " + playerKillStreaks.get(player.getName()) + "kills"); } Errors on Code:java int killStreak = playerKillStreaks.get(player.getName()); and Code:java long kdrRound = Math.round(kdr); Both saying the local variable is not used, how can I add it so it tells the player the KDR?
Take another look at your code. You are doing playerKillStreaks.get(...) in the player.sendMessage() on line 9. So, exactly as your IDE is telling you, you are not using the killStreak variable you created. You could either remove the killStreak variable, or use it in your player.sendMessage() instead of playerKillStreaks.get(...). The same looks to be true for line 6. You really need to learn how to troubleshoot and maintain your own code, you are literally giving the answers to your own questions.
You have a fine example already . Code:java if(commandLabel.equalsIgnoreCase("stats") && args.length == 0){int kills = playerKills.get(player.getName());int deaths = playerDeaths.get(player.getName());int killStreak = playerKillStreaks.get(player.getName());double kdr = kills / deaths;long kdrRound = Math.round(kdr);player.sendMessage(ChatColor.GOLD + "You have" + playerKills.get(player.getName()) + "total kills");player.sendMessage(ChatColor.GOLD + "You have" + playerDeaths.get(player.getName()) + "total deaths");player.sendMessage(ChatColor.GOLD + "You have a killstreak of " + playerKillStreaks.get(player.getName()) + "kills"); } You could simply add: Code:java player.sendMessage(ChatColor.GOLD + "You have a killstreak of " +killStreak+ "kills"); AND/OR Code:java player.sendMessage(ChatColor.GOLD + "You have a kdrRound of " +kdrRound + "kills"); Java can get upset about converting number types when doing math (understandably so), but when converting numeric values to strings it's actually pretty easy.