Solved Refreshing the Scoreboard on kill or on death

Discussion in 'Spigot Plugin Development' started by ItzDCraft_, Nov 28, 2018.

  1. Hey guys, I was wondering if anyone can help me with this.
    All I want, it's just refresh the scoreboard on kill or on death, could anyone send me the code?
    Thank you :D
     
  2. #SpoonfeedingIsShit

    Use this event PlayerDeathEvent to listen for the kills/deaths and then do whatever you want with your scoreboard.
     
  3. I know right, I just want to refresh the scoreboard.
    I've done two ints who calls the kills and the deaths using a FileConfiguration.
    What should I do?
    Thank you for your quick answer! :)
     
  4. Do you already have a scoreboard? (Just update the values there?)
     
  5. Yep, code:
    Code (Java):

                    ScoreboardManager m = Bukkit.getScoreboardManager();
                    Scoreboard b = m.getNewScoreboard();
                    PermissionUser jugador = PermissionsEx.getUser(pr);
                    String pexprefix = jugador.getPrefix().replace("&", "§");

                    Objective o = b.registerNewObjective("Nombre", "dummy");
                    o.setDisplaySlot(DisplaySlot.SIDEBAR);
                    o.setDisplayName("§f§lKit§4§lPvP");
                    Score espacio1 = o.getScore("");
                    Score nombre = o.getScore("§7 Nombre: " + "§b" + pr.getName() + " ");
                    Score rango = o.getScore("§7 Rango: " + pexprefix + " ");
                    Score espacio2 = o.getScore(" ");
                    Score kills = o.getScore("§7 Asesinatos: §a"
                            + Integer.valueOf(cfgm.getConfigJugadores().getInt("Jugadores. " + pr.getName() + ".Asesinatos ")));
                    Score espacio3 = o.getScore("  ");
                    Score muertes = o.getScore("§7 Muertes: §c"
                            + Integer.valueOf(cfgm.getConfigJugadores().getInt("Jugadores." + pr.getName() + ".Muertes ")));
                    Score espacio4 = o.getScore("   ");
                    Score ip = o.getScore("§e  mc.woolcraft.gq");
                    Score espacio5 = o.getScore("    ");
                    espacio1.setScore(10);
                    nombre.setScore(9);
                    rango.setScore(8);
                    espacio2.setScore(7);
                    kills.setScore(6);
                    espacio3.setScore(5);
                    muertes.setScore(4);
                    espacio4.setScore(3);
                    ip.setScore(2);
                    espacio5.setScore(1);
                   
                    pr.setScoreboard(b);

     
    PST: I'm Spanish.
     
  6. Code (Text):
                    Score kills = o.getScore("§7 Asesinatos: §a"
                            + Integer.valueOf(cfgm.getConfigJugadores().getInt("Jugadores. " + pr.getName() + ".Asesinatos ")));
                    kills.setScore(6);
    Just call this code again and increase the value by 1.
     
  7. Didn't work, code?
     
  8. Forums are not here to ask for code. Only for help. :D
     
  9. Sorry, I meant what part of my code I've to put, I've copied all my scoreboard code and then pasted it on a refresh void method.
    And didn't work.
     
  10. Did you want that the scoreboard update with packets or not?
     
  11. Just refresh the scoreboard by some way.
     
  12. Ok I think the standard method is better for the first.
    Use the Method where you show him the scoreboard and yeah finished.
     
  13. You can also use teams in your scoreboard and update the prefix or suffix, getting the player scoreboard an then the teamname
     
  14. Could you specify please, I'm Spanish as well.
     
  15. Still doesn't work, I've added the example of the tutorial and I added a runnable to refresh it every 2 secs and now it's showing the error of:
    ERROR:
    Code (Text):

    org.apache.commons.lang.UnhandledException: Plugin KitPvP v1.0 generated an exception while executing task 5
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            at java.lang.Thread.run(Thread.java:748)
    Caused by: java.lang.IllegalStateException: Asynchronous scoreboard creation!
            at org.spigotmc.AsyncCatcher.catchOp(AsyncCatcher.java:14)
            at org.bukkit.craftbukkit.v1_8_R3.scoreboard.CraftScoreboardManager.getNewScoreboard(CraftScoreboardManager.java:45)
            at org.bukkit.craftbukkit.v1_8_R3.scoreboard.CraftScoreboardManager.getNewScoreboard(CraftScoreboardManager.java:1)
            at me.woolcraft.es.Scoreboard.Scoreboard_KitPvP$1.run(Scoreboard_KitPvP.java:30)
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71)
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
            ... 3 more
     
    me.woolcraft.es.Scoreboard.Scoreboard_KitPvP - Line 30:
    Code (Java):

                        PermissionUser jugador = PermissionsEx.getUser(pr);
     
    Code of all the class of me.woolcraft.es.Scoreboard.Scoreboard_KitPvP:
    Code (Java):

        public static void enviarScore(Player pr) {
            try {
                Bukkit.getScheduler().scheduleSyncRepeatingTask(KitPvP.getInstance(), new Runnable() {
                 
                    @Override
                    public void run() {
                        ScoreboardManager m = Bukkit.getScoreboardManager();
                        Scoreboard b = m.getNewScoreboard();
                        PermissionUser jugador = PermissionsEx.getUser(pr);
                        String pexprefix = jugador.getPrefix().replace("&", "§");
                     
                        Objective o = b.registerNewObjective("Nombre", "dummy");
                        o.setDisplaySlot(DisplaySlot.SIDEBAR);
                        o.setDisplayName("§f§lKit§4§lPvP");
                        Team onlineCount = b.registerNewTeam("contador");
                        onlineCount.addEntry(ChatColor.BLACK + "" + ChatColor.WHITE + "");
                        if(Bukkit.getOnlinePlayers().size() == 0) {
                            onlineCount.setPrefix(ChatColor.DARK_RED + "" + "0" + ChatColor.GRAY + "/" + ChatColor.GREEN + Bukkit.getMaxPlayers());
                        } else {
                            onlineCount.setPrefix(String.valueOf(ChatColor.DARK_RED + "" + Bukkit.getOnlinePlayers().size() + "" + ChatColor.GRAY + "/" + ChatColor.GREEN + Bukkit.getOnlinePlayers().size()));
                        }
                        Score espacio1 = o.getScore("");
                        Score nombre = o.getScore("§7 Nombre: " + "§b" + pr.getName() + " ");
                        Score rango = o.getScore("§7 Rango: " + pexprefix + " ");
                        Score espacio2 = o.getScore(" ");
                        Score kills = o.getScore("§7 Asesinatos: §a" + (ConfigManager.getInstance().getConfigJugadores().getInt("Jugadores. " + pr.getName() + ".Asesinatos ")));
                        Score espacio3 = o.getScore("  ");
                        Score muertes = o.getScore(
                                "§7 Muertes: §c" + (ConfigManager.getInstance().getConfigJugadores().getInt("Jugadores." + pr.getName() + ".Muertes ")));
                        Score espacio4 = o.getScore("   ");
                        Score online = o.getScore("§7Online » §a");
                        Score espacio5 = o.getScore("    ");
                        Score ip = o.getScore("§e  mc.woolcraft.gq");
                        Score espacio6 = o.getScore("     ");
                     
                        espacio1.setScore(11);
                        nombre.setScore(10);
                        rango.setScore(9);
                        espacio2.setScore(8);
                        kills.setScore(7);
                        espacio3.setScore(6);
                        muertes.setScore(5);
                        espacio4.setScore(4);
                        ip.setScore(3);
                        espacio5.setScore(2);
                        online.setScore(1);

                        pr.setScoreboard(b);
                    }
                 
                }, 0L, 40L);


            } catch (NullPointerException ex) {
                System.out.println("");
                System.out.println("§cNo se ha podido poner la scoreboard.");
                System.out.println("");
                ex.printStackTrace();
            }

        }

    }

     
    EDIT: I've seen the error of the asynschronously, I've fixed it, now I'm not getting the variables of the yml file of "jugadores.yml", Is there anything wrong in the current code?
    Thank you again :)
     
  16. isnt better doing the deserialization in a class apart and saving players data in cache?
     
  17. I've done it already, It's the "ConfigManager" class, in this one, I only wrote the code of the Scoreboard.
    I don't know if it's what you're meaning
     
  18. also look at this, you have some spaces
    (ConfigManager.getInstance().getConfigJugadores().getInt("Jugadores.{space}" + pr.getName() + ".Asesinatos{space}")));
    try removing those spaces and check if there isnt others
     
  19. Thank you, I'm trying it out.
    EDIT: Solved, thank you bro :)