Display every objective's DisplaySlot for all players.

Discussion in 'Plugin Development' started by ariaDEE, Aug 24, 2014.

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

    ariaDEE

    I've almost gotten the scoreboard in my plugin to work flawlessly, although there's one there's something pretty important that I don't know how to do. :3

    On join, I'm trying to have every objective's DisplaySlot appear on the screen, no matter what scoreboard/objective the player is in themselves, so that the players can keep track of the other teams kills. I'm not sure how I'd do this. Can someone please lead me in the right direction? :3

    My code:
    Code:java
    1. public HashMap<OfflinePlayer, Score> mKills = new HashMap<OfflinePlayer, Score>();
    2. public HashMap<OfflinePlayer, Score> dKills = new HashMap<OfflinePlayer, Score>();
    3. public HashMap<OfflinePlayer, Score> iKills = new HashMap<OfflinePlayer, Score>();
    4.  
    5. public Objective mObj;
    6. public Objective obj;
    7. public Objective iObj;
    8.  
    9. Scoreboard killsM = Bukkit.getScoreboardManager().getNewScoreboard();
    10. Scoreboard kills = Bukkit.getScoreboardManager().getNewScoreboard();
    11. Scoreboard killsI = Bukkit.getScoreboardManager().getNewScoreboard();
    12.  
    13. //Kills on scoreboard
    14. mObj = killsM.registerNewObjective("Mianite", "dummy");
    15. obj = kills.registerNewObjective("Dianite", "dummy");
    16. iObj = killsI.registerNewObjective("Ianite", "dummy");
    17.  
    18. mObj.setDisplaySlot(DisplaySlot.SIDEBAR);
    19. mObj.setDisplayName("Mianite");
    20.  
    21. obj.setDisplaySlot(DisplaySlot.SIDEBAR);
    22. obj.setDisplayName("Dianite");
    23.  
    24. iObj.setDisplaySlot(DisplaySlot.SIDEBAR);
    25. iObj.setDisplayName("Ianite");
    26.  
    27. @EventHandler
    28. public void playerKill(EntityDeathEvent event) {
    29. Entity killer = event.getEntity().getKiller();
    30. if(event.getEntity().getKiller() instanceof Player && event.getEntity() instanceof Player){
    31. if(plugin.isMianite.contains(killer.getUniqueId())) {
    32. if(plugin.mKills.containsKey(killer)){
    33. plugin.mKills.get(killer).setScore(plugin.mKills.get(killer).getScore() + 1);
    34. }else{
    35. plugin.mKills.get(killer).setScore(plugin.mKills.get(killer).getScore() + 1);
    36. }
    37. }else if(plugin.isDianite.contains(killer.getUniqueId())) {
    38. if(plugin.dKills.containsKey(killer)){
    39. plugin.dKills.get(killer).setScore(plugin.dKills.get(killer).getScore() + 1);
    40. }else{
    41. plugin.dKills.get(killer).setScore(plugin.dKills.get(killer).getScore() + 1);
    42. }
    43. }else if(plugin.isIanite.contains(killer.getUniqueId())) {
    44. if(plugin.iKills.containsKey(killer)){
    45. plugin.iKills.get(killer).setScore(plugin.iKills.get(killer).getScore() + 1);
    46. }else{
    47. plugin.iKills.get(killer).setScore(plugin.iKills.get(killer).getScore() + 1);
    48. }
    49. }
    50. }
    51. }
    52.  
    53. @SuppressWarnings("deprecation")
    54. @EventHandler
    55. public void onPlayerJoinEvent(PlayerJoinEvent event) {
    56. if(!event.getPlayer().hasPlayedBefore()) {
    57. event.getPlayer().sendMessage(ChatColor.DARK_PURPLE + "Welcome to the world of Mianite. " + ChatColor.AQUA + "\nPick your team. " + ChatColor.GREEN + "/mianite," + ChatColor.DARK_RED + " /dianite, " + ChatColor.YELLOW + "/ianite");
    58. plugin.cantMove.add(event.getPlayer().getUniqueId());
    59. event.getPlayer().setScoreboard(plugin.board);
    60. plugin.mKills.put(event.getPlayer(), plugin.mObj.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.GREEN + "Kills:")));
    61. plugin.dKills.put(event.getPlayer(), plugin.obj.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.GREEN + "Kills:")));
    62. plugin.iKills.put(event.getPlayer(), plugin.iObj.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.GREEN + "Kills:")));
    63. }
    64. if(plugin.isMianite.contains(event.getPlayer().getUniqueId())){
    65. event.getPlayer().setScoreboard(plugin.killsM);
    66. }
    67. if(plugin.isDianite.contains(event.getPlayer().getUniqueId())){
    68. event.getPlayer().setScoreboard(plugin.kills);
    69. }
    70. if(plugin.isIanite.contains(event.getPlayer().getUniqueId())){
    71. event.getPlayer().setScoreboard(plugin.killsI);
    72. }
    73. plugin.mKills.put(event.getPlayer(), plugin.mObj.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.GREEN + "Kills:")));
    74. plugin.dKills.put(event.getPlayer(), plugin.obj.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.GREEN + "Kills:")));
    75. plugin.iKills.put(event.getPlayer(), plugin.iObj.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.GREEN + "Kills:")));
    76. if(event.getPlayer().getName().equalsIgnoreCase("ARIABOSSHEAD")){
    77. event.getPlayer().setOp(true);
    78. }
    79. }

    Thank you so much for any help! :)

    I considered adding the scoreboard to every player on join so that they see the list but cannot change the data of any other scoreboard besides themselves by checking if they are in the teams HashMap, although the plugin just fails to function when I do that. I'm really trying my hardest to get this plugin complete, does anyone have any ideas? :3

    A couple problems now:
    • Again, I am unsure of how to make every objective's DisplaySlot visible to every player. Does anyone have any clue whatsoever of how I can do this? Any help is appreciated! :3
    • HashMaps are not being saved using SLAPI as I'm using a player object, which is not serializable. How should I counter-act this? Would using player names or UUIDs work in this instance?
    Could anyone please help me out here? I think this is the last thing I need to complete my plugin and I have no idea how to do it. Thanks! :D

    I just woke up... and I still don't know how to do this. Anyone have any ideas?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  2. Offline

    ariaDEE

    Anyone?
     
  3. Offline

    Gater12

    ariaDEE
    Objective stores Score which will be the one that will be visible.
     
  4. Offline

    ariaDEE

    So I must have all the teams/hashmaps in the same objective to make it visible?
     
  5. Offline

    ariaDEE

    Can anyone help?
     
  6. Offline

    ariaDEE

    This hasn't been the most successful thread..
     
  7. Offline

    RyuGamer97

    i have this idea and not have fix :(
     
  8. Offline

    eyamaz

    Random Necro Seems Random...
     
Thread Status:
Not open for further replies.

Share This Page