Getting Highest int from Config.yml

Discussion in 'Plugin Development' started by HCMatt, Apr 20, 2019.

  1. Offline

    KarimAKL

    @HCMatt You simply add players to the map using this:
    Code:Java
    1. map.put(player.getUniqueId(), kills);

    Then pass that map to the method and it'll return the top players from the map.
    EDIT: To get the UUID and Kills you could create a new class with a uuid variable and an integer variable, something like this:
    Code:Java
    1. public class Killer {
    2. private UUID uuid;
    3. private int kills;
    4.  
    5. public Killer(UUID uuid, int kills) {
    6. this.uuid = uuid;
    7. this.kills = kills;
    8. }
    9.  
    10. public UUID getUUID() {return uuid;}
    11. public int getKills() {return uuid;}
    12. }

    Then change the code a little so that it returns an array of 'killers'.
     
  2. Offline

    HCMatt

    Im getting an error on line 13 of your code:
    Code:
     entries.get(i).getKey(); 
     
  3. Offline

    KarimAKL

    @HCMatt What is the error? Also, could you paste your current code?
     
  4. Offline

    HCMatt

    Its underlined in red..

    Code:
        // Create Leaderboard Sign
        @EventHandler
        public void createLeaderboardSign(final PlayerInteractEvent e) {
            Player p = e.getPlayer();
            Action a = e.getAction();
    
            if (a == Action.RIGHT_CLICK_BLOCK) {
                Block b = e.getClickedBlock();
                if (b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN) {
                    Sign s = (Sign) b.getState();
                    if (s.getLine(0).equalsIgnoreCase("lboard")) {
                        if (!p.hasPermission("rev.lboard.createsign")) {
                            p.sendMessage(ChatColor.RED + "You do not have permission to create a Leaderboard Sign.");
                            return;
                        } else if (s.getLine(1).isEmpty()) {
                            p.sendMessage(ChatColor.RED + "You must specify a position for this sign.");
                            return;
                        } else {
    
                            int maxKills1 = 0;
                            int maxKills2 = 0;
                            int maxKills3 = 0;
                           
                            String maxKillsPlayer1 = "";
                            String maxKillsPlayer2 = "";
                            String maxKillsPlayer3 = "";
                           
                            for (String uuid : getConfig().getConfigurationSection("Revelation.Stats.").getKeys(false)) {
                                int kills = getConfig().getInt("Revelation.Stats." + uuid +  ".Kills");
                                if (kills > maxKills1) {
                                    maxKills1 = kills;
                                    maxKillsPlayer1 = getConfig().getString("Revelation.Stats." + uuid + ".Name");
                                    }
                                if(kills > maxKills2 && maxKills1 > maxKills2) {
                                    maxKills2 = kills;
                                    maxKillsPlayer2 = getConfig().getString("Revelation.Stats." + uuid + ".Name");
                                }
                            }
                            String killsString1 = String.valueOf(maxKills1);
                            String first = maxKillsPlayer1;
                           
                            String killsString2 = String.valueOf(maxKills2);
                            String second = maxKillsPlayer2;
                           
                            String killsString3 = String.valueOf(maxKills3);
                            String third = maxKillsPlayer3; 
                           
                           
                           if (s.getLine(1).equalsIgnoreCase("create")) {
                                    s.setLine(0, ChatColor.GREEN + "[Leaderboard]");
                                    s.setLine(1, ChatColor.BLUE + "First Place");
                                    p.sendMessage(ChatColor.GREEN + "You created the Leaderboard Signs");
                                   
    
                                    Location loc2 = new Location (b.getWorld(), b.getX()-1, b.getY()-1, b.getZ());
                                    loc2.getBlock().setType(Material.WALL_SIGN);
                                    Block b2 = loc2.getBlock();
                                    Sign s2 = (Sign) b2.getState();
                                    Location loc3 = new Location (b.getWorld(), b.getX()+1, b.getY()-1, b.getZ());
                                    loc3.getBlock().setType(Material.WALL_SIGN);
                                    Block b3 = loc3.getBlock();
                                    Sign s3 = (Sign) b3.getState();
                                   
                                   
                                    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                                        @Override
                                        public void run() {
                                            Bukkit.broadcastMessage(ChatColor.GRAY + "[" + ChatColor.DARK_AQUA + "Leaderboard" + ChatColor.GRAY + "]" + ChatColor.AQUA + " The Leaderboard has been updated!");
                                            s.setLine(2, ChatColor.AQUA + first);
                                            s.setLine(3, ChatColor.DARK_AQUA + killsString1);
                                            s.update(true);
                                           
                                            s2.setLine(0, ChatColor.GREEN + "[Leaderboard]");
                                            s2.setLine(1, ChatColor.BLUE + "Second Place");
                                            s2.setLine(2, ChatColor.AQUA + second);
                                            s2.setLine(3, ChatColor.DARK_AQUA + killsString2);
                                            s2.update(true);
                                           
                                            s3.setLine(0, ChatColor.GREEN + "[Leaderboard]");
                                            s3.setLine(1, ChatColor.BLUE + "Third Place");
                                            s3.setLine(2, ChatColor.AQUA + third);
                                            s3.setLine(3, ChatColor.DARK_AQUA + killsString3);
                                            s3.update(true);*/
                                           
                                            p.sendMessage("First Place = " + first + " with " + killsString1);
                                            p.sendMessage("Second Place = " + second + " with " + killsString2);
                                            p.sendMessage("Third Place = " + third + " with " + killsString3); */
                                            return;
                                        }
                                    }, 20, 200);                           
                            }
                         }
                    }
                }
            }
        }
    That is my current code, which now doesnt work properly with the UUID.
     
  5. Offline

    timtower Ninja on the waves Moderator

    @HCMatt Hover your mouse over it.
     
  6. Offline

    KarimAKL

    As timtower said, hover your mouse over it, it'll show the error.
    I don't see you use the method, or any UUID other than the string you've saved in the config.
     
  7. Offline

    HCMatt

    Ive attached an image to this reply of the error. Ive tried clicking the error and it creates another error.

    The reason i havent used the method yet is because as I said I don't really know how to, and 2 How can i use a method that has an error?
     
  8. Offline

    KarimAKL

    I don't see any attached image.
    What do you mean?
    I gave an idea here: https://bukkit.org/threads/getting-highest-int-from-config-yml.478938/#post-3601408
    You can't, you have to fix the error.
     
  9. @HCMatt The best option for making any kind of leaderboard is to use a SQL Database.
    You could look into SQLite if you don't have access to a SQL Server.
     

Share This Page