ScoreBoard Problems

Discussion in 'Plugin Development' started by MCTutorialist, Oct 20, 2013.

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

    MCTutorialist

    Okay, so I am trying to make a plugin helpful to prison servers that use PaidRanks for ranking etc.

    Code:java
    1. package com.gmail.mctutorialist.prisonscoreboard;
    2.  
    3. import me.messageofdeath.PaidRanks.PaidRanks;
    4. import net.milkbowl.vault.Vault;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.PluginDescriptionFile;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.scoreboard.DisplaySlot;
    12. import org.bukkit.scoreboard.Objective;
    13. import org.bukkit.scoreboard.Score;
    14. import org.bukkit.scoreboard.Scoreboard;
    15. import org.bukkit.scoreboard.ScoreboardManager;
    16.  
    17.  
    18. public class ScoreBoard extends JavaPlugin {
    19.  
    20. public static Vault getVault(){
    21. return PaidRanks.vault;
    22. }
    23.  
    24. public void onEnable()
    25. {
    26. PluginDescriptionFile pdfFile = getDescription();
    27. this.getLogger().info(pdfFile.getName() + " version: " + pdfFile.getVersion() + " has been enabled!");
    28. }
    29.  
    30. public void onDisable()
    31. {
    32. PluginDescriptionFile pdfFile = getDescription();
    33. this.getLogger().info(pdfFile.getName() + " version: " + pdfFile.getVersion() + " has been disabled!");
    34. }
    35.  
    36. public void onScoreBoardEvent() {
    37. ScoreboardManager manager = Bukkit.getScoreboardManager();
    38. Scoreboard board = manager.getNewScoreboard();
    39.  
    40. Objective objective = board.registerNewObjective("test", "econ");
    41. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    42. objective.setDisplayName("§5League§4PvP §aStats");
    43.  
    44. Score score = objective.getScore(Bukkit.getPlayer("§cNext rank price:"));
    45. score.setScore(PaidRanks.vault().getRankPrice); // i have no idea if this is correct or not <>
    46. }
    47.  
    48. }
    49.  


    this is my current code, I am getting errors on the PaidRanks.vault()

    can any1 help me fix this and get it to display the amount to next rank :)
     
  2. Offline

    1Rogue

    You're calling the method "vault()" but it's labeled as "getVault()".
     
    MCTutorialist likes this.
  3. Offline

    MCTutorialist

    ok thats fixed, but I still get an error on the "return PaidRanks.vault;"
    its telling me to change the return type to 'Vault' :/

    (I'm new to the whole scoreboard thing, and still new to java)
     
  4. Offline

    1Rogue


    Why are you using Vault? Where is the variable "vault" even defined?
     
  5. Offline

    MCTutorialist

    Because I'm making a plugin dependant on vault, I'm basically trying to re-make a custom plugin I've seen on some prison server:

    [​IMG]
     
  6. Offline

    1Rogue

  7. Offline

    MCTutorialist

  8. Offline

    Janmm14

    MCTutorialist
    You have to get the price of the new rank and use price - moneyofplayer
     
  9. Offline

    MCTutorialist

    How the hell do I do that? Whats the method, whats the code?

    My current code:

    Code:java
    1. package com.gmail.mctutorialist.prisonscoreboard;
    2.  
    3. import me.messageofdeath.PaidRanks.PaidRanks;
    4. import me.messageofdeath.PaidRanks.Engine.Vault;
    5. import net.milkbowl.vault.economy.Economy;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.bukkit.scoreboard.DisplaySlot;
    15. import org.bukkit.scoreboard.Objective;
    16. import org.bukkit.scoreboard.Score;
    17. import org.bukkit.scoreboard.Scoreboard;
    18. import org.bukkit.scoreboard.ScoreboardManager;
    19.  
    20.  
    21. public class ScoreBoard extends JavaPlugin implements Listener {
    22.  
    23. public static Economy econ = null;
    24. public Vault getVault() {
    25. return PaidRanks.vault;
    26. }
    27.  
    28. @EventHandler
    29. public void onPlayerJoin(PlayerJoinEvent e){
    30. onScoreBoardEvent(e.getPlayer());
    31. }
    32.  
    33. public void onEnable()
    34.  
    35. {
    36. PluginDescriptionFile pdfFile = getDescription();
    37. this.getLogger().info(pdfFile.getName() + " version: " + pdfFile.getVersion() + " has been enabled!");
    38. getServer().getPluginManager().registerEvents(this, this);
    39.  
    40. }
    41.  
    42. public void onDisable()
    43. {
    44. PluginDescriptionFile pdfFile = getDescription();
    45. this.getLogger().info(pdfFile.getName() + " version: " + pdfFile.getVersion() + " has been disabled!");
    46. }
    47.  
    48.  
    49. public void onScoreBoardEvent(Player player) {
    50. ScoreboardManager manager = Bukkit.getScoreboardManager();
    51. Scoreboard board = manager.getNewScoreboard();
    52.  
    53. Objective objective = board.registerNewObjective("test", "dummy");
    54. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    55. objective.setDisplayName("§5League§4PvP §aStats");
    56.  
    57. Score nextrank = objective.getScore(Bukkit.getPlayer("§cNext rank price:"));
    58. nextrank.setScore((int) player.getHealth()/2);
    59.  
    60. Score playersonline = objective.getScore(Bukkit.getPlayer("§bPlayers online:"));
    61. playersonline.setScore(Bukkit.getOnlinePlayers().length);
    62.  
    63. Score balance = objective.getScore(Bukkit.getOfflinePlayer("§bYour current balance:"));
    64. balance.setScore((int) econ.getBalance(player.getName()));
    65.  
    66. }
    67.  
    68. }
    69.  


    Its not showing the scoreboard at all in-game :/

    chasechocolate can you help? :3

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

    SkillSam

    MCTutorialist You are forgetting to set the player's scoreboard. This line will be added at the end of setting all of your scores.

    Code:java
    1. player.setScoreboard(board);
     
  11. Offline

    MCTutorialist

    ah thank you! I'll give it a test :)

    EDIT: I added the player.setScoreBoard(board) at the end of the scores, but I am now getting a PlayerJoinEvent in console
    [​IMG]
     
  12. Offline

    amhokies

    Use the Bukkit.getOfflinePlayer() instead of Bukkit.getPlayer()
     
  13. Offline

    MCTutorialist

    still nothing... no scoreboard is showing up in-game :(
     
  14. Offline

    chasechocolate

    MCTutorialist is PaidRanks.vault() returning null? Can't see the image, on my school computer which has web filters... :/
     
  15. Offline

    MCTutorialist

    Nope, all the code is fine no errors or anything, its just that the scoreboard isnt showing up and the PlayerJoinEvent is giving some errors on console
     
  16. Offline

    Garris0n

    Post the full stack trace as text.
     
  17. Offline

    MCTutorialist

    And, how do I do that ?
     
  18. Offline

    Garris0n

    Let me rephrase that. Copy-paste the big error into the forum box and press "post reply".
     
  19. Offline

    MCTutorialist

    Garris0n
    Code:
    [SEVERE] Could not pass event PlayerJoinEvent to PrisonScoreBoard v1.0.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    at net.minecraft.server.v1_6_R3.PlayerList.c(PlayerList.java:207)
    at net.minecraft.server.v1_6_R3.PlayerList.a(PlayerList.java:103)
    at net.minecraft.server.v1_6_R3.PendingConnection.e(PendingConnection.java:132)
    at net.minecraft.server.v1_6_R3.PendingConnection.d(PendingConnection.java:43)
    at net.minecraft.server.v1_6_R3.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:41)
    at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:29)
    at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
    at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
    at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
    at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
    at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: java.lang.IllegalArgumentException: Player cannot be null
    at org.apache.commons.lang.Validate.notNull(Validate.java:203)
    at org.bukkit.craftbukkit.v1_6_R3.scoreboard.CraftObjective.getScore(CraftObjective.java:90)
    at com.gmail.mctutorialist.prisonscoreboard.ScoreBoard.onScoreBoardEvent(ScoreBoard.java:56)
    at com.gmail.mctutorialist.prisonscoreboard.ScoreBoard.onPlayerJoin(ScoreBoard.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    ... 14 more
     
  20. Offline

    5pHiNxX

    @MCTutorialist:

    what exactly should the following do?
    Code:java
    1. Bukkit.getPlayer("§cNext rank price:")


    Bukkit.getPlayer(String name) returns a player from the server ... but do you have players that have the name
    "§cNext rank price:" so this method everytimes returns null (as an indicator that no player with the given name was found)
     
  21. Offline

    Garris0n

    Yes, it should be Bukkit(.getServer()).getOfflinePlayer(ChatColor.RED + "Next Rank Price:");
    That name, however, is too long, so you'll probably want to use team prefixes/suffixes to shorten it. Also, I don't think that was the full stacktrace, but it doesn't really matter anymore.
     
  22. Offline

    njb_said

    Oh now thats nasty :( copying me. (That is my server and my plugin xD)

    The server is custom coded you are correct, the code I made for the scoreboard is as follows:
    Code:
    public void updateEco(Player player) {
            Scores s = get(player);
            if (s != null) {
                Economy.get().updateScores(player);
                s.addScore("Needed to rank",  (pr.getNext(player) == 0 ? 0 : (pr.getNext(player) - Economy.get().getBalance(player))));
                s.addScore("Next rank price", pr.getNext(player));
            }
        }
    Get balance, get the next rank price check if its 0 if it isnt then do a simple calcualation
    - Sorry if this has already been solved, had to make a point about it :p
     
  23. Offline

    MCTutorialist

    Ahhh, man you are good! And I am not going to make your plugin public so dont worry :p its just use for my server :3

    And any way I can contact you if I have any problems? Like your skype ?

    I'm still having the problem of the scoreboard not showing up :/
     
  24. Offline

    njb_said

    player.setScoreboard(yourScoreboard);
     
  25. Offline

    MCTutorialist

    I did that already... but its not working

    Whats your skype?
     
Thread Status:
Not open for further replies.

Share This Page