Scoreboard showing wrong player

Discussion in 'Spigot Plugin Development' started by GoRoK, Jun 2, 2017.

  1. Hey there,

    so i created a plugin with a BELOW_NAME scoreboard thingy.

    The problem is, when i set the scoreboard on join, Player A has as name Player B and Player B has got Player A.
    Im don't know how to fix this issue. Here's my code to make the boards:

    Code (Text):

    public void registerHealth(Player p){

        try{
            Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();



            Objective o = board.registerNewObjective("obj-"+p.getPlayerListName(), "health");

            Team t = s.registerNewTeam(p.getDisplayName());
            t.setPrefix(ChatColor.BLUE + "");


            o.setDisplayName(ChatColor.RED + "❤ | " + ChatColor.DARK_AQUA + "Punkte " + sql.getPoints(p.getUniqueId().toString()) );
            o.setDisplaySlot(DisplaySlot.BELOW_NAME);

            p.setScoreboard(board);

            playerScoreboards.put(p, board);

        }catch(IllegalArgumentException e){
            p.getScoreboard().getObjective("obj-"+p.getPlayerListName()).unregister();
            if(p.getScoreboard().getObjective("obj-"+p.getPlayerListName()) == null){
                registerHealth(p);
            }
            return;
        }catch(Exception ex){
            ex.printStackTrace();
        }

    }
     
    When i want to change the points for example i do this:

    Code (Text):

    Scoreboard board = RisingPvP.getInstance().playerScoreboards.get(killer);
    Objective obj = board.getObjective("obj-" + killer.getPlayerListName());
    obj.setDisplayName(ChatColor.RED + "❤ | " + ChatColor.DARK_AQUA + "Punkte " +  RisingPvP.getInstance().getSql().getPoints(killer.getUniqueId().toString()));

    killer.setScoreboard(board);
     
    What am I doing wrong so that it mixes the boards?..
    Thanks for any help
     
  2. i don't really get what you are trying to / meaning with Player A & B.
    Could you show that in Images from InGame?
     
  3. So, look at that album
    http://imgur.com/a/Y3ey0

    Jeff got 107 Points and Jeb got 93. But it needs to be the other way around. So Jeb sees his points above the head of the other guy. Vice versa.
     
  4. bump,
    still haven't found a solution
     
  5. Code (Text):
    obj.setDisplayName(ChatColor.RED + "❤ | " + ChatColor.DARK_AQUA + "Punkte " +  RisingPvP.getInstance().getSql().getPoints(killer.getUniqueId().toString()));
    You get the points of the killer. Not of the Killed one.
     
  6. yeah, because the killer gets his scoreboard set there.
     
  7. Let me clear it up

    Code (Text):
    Scoreboard board = RisingPvP.getInstance().playerScoreboards.get(killer);
    Objective obj = board.getObjective("obj-" + killer.getPlayerListName());
    obj.setDisplayName(ChatColor.RED + "❤ | " + ChatColor.DARK_AQUA + "Punkte " +  RisingPvP.getInstance().getSql().getPoints(killer.getUniqueId().toString()));

    killer.setScoreboard(board);
    Here you get the Scoreboard of the killer, set the killer's scoreboard of his points. Than you set the scoreboard to the killer. You are not getting the points of your killed person.
     
  8. So i should just change the killer to p and then it would work? Totally not understanding it right now. If you mean that the dead player doesnt get his points set, he gets it set @RespawnEvent
     
  9. You are getting the killer's scoreboard, get the points of the killer, set the scoreboard of the killer. Where are you even getting the points of the killed player?
     
  10. Here:

    Killer (after the player got killed)

    Code (Text):

    Scoreboard board = RisingPvP.getInstance().playerScoreboards.get(killer);
    Objective obj = board.getObjective("obj-" + killer.getPlayerListName());
    obj.setDisplayName(ChatColor.RED + "❤ | " + ChatColor.DARK_AQUA + "Punkte " +  RisingPvP.getInstance().getSql().getPoints(killer.getUniqueId().toString()));

    killer.setScoreboard(board);
     
    Dead guy, after respawn:

    Code (Text):


    //p is e.getPlayer from RespawnEvent

    Scoreboard board = RisingPvP.getInstance().playerScoreboards.get(p);
    Objective obj = board.getObjective("obj-" + p.getPlayerListName());
    obj.setDisplayName(ChatColor.RED + "❤ | " + ChatColor.DARK_AQUA + "Punkte " +  RisingPvP.getInstance().getSql().getPoints(p.getUniqueId().toString()));

    p.setScoreboard(board);

     
     
  11. I don't think you understand it. Let me explain;


    Code (Text):
    Scoreboard board = RisingPvP.getInstance().playerScoreboards.get(killer);
    Objective obj = board.getObjective("obj-" + killer.getPlayerListName());
    obj.setDisplayName(ChatColor.RED + "❤ | " + ChatColor.DARK_AQUA + "Punkte " +  RisingPvP.getInstance().getSql().getPoints(killer.getUniqueId().toString()));

    killer.setScoreboard(board);
    For example, if player A kills player B, Player A is the killer and playerB is the killed.
    In this piece of code you set the Killer's scoreboard (Player A). But you are setting it with the points of Player A, not player B.
     
  12. Uhm, i still don't understand it lol.
    Guess im dumb.
    Ill just try it
     
  13. Well, thanks it worked. Still dont understand it though :p
     
  14. This is because you are getting the scoreboard of the Killer, edit the scoreboard of the Killer, get the points of the Killer and than you set the scoreboard of the Killer with the Killer's points.