Vault economy scoreboard support

Discussion in 'Plugin Development' started by GalaxyCraft, Sep 3, 2014.

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

    GalaxyCraft

    Hello Bukkit,
    I have made previous posts about this but they are a few weeks old and i believe its against the rules to revive an old topic? or everybody gets annoyed from it. So i decided to make a new one with my most updated code.

    This is my main class:
    Code:java
    1. package me.unique.scoreboard;
    2.  
    3. import net.milkbowl.vault.chat.Chat;
    4. import net.milkbowl.vault.economy.Economy;
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.plugin.PluginDescriptionFile;
    12. import org.bukkit.plugin.RegisteredServiceProvider;
    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. public class Main extends JavaPlugin implements Listener {
    21.  
    22. public static Economy economy = null;
    23. public static Economy econ = null;
    24. public static Chat chat = null;
    25.  
    26. ScoreboardManager manager = Bukkit.getScoreboardManager();
    27. Scoreboard board = manager.getNewScoreboard();
    28.  
    29. public void onEnable() {
    30. getServer().getPluginManager().registerEvents(this, this);
    31.  
    32. Objective objective = board.registerNewObjective("test", "dummy");
    33.  
    34. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    35.  
    36. objective.setDisplayName("MomentoPrison");
    37.  
    38. for(Player online : Bukkit.getOnlinePlayers()){
    39. online.setScoreboard(board);
    40.  
    41. Score balance = objective.getScore(ChatColor.GREEN + "Balance:");
    42.  
    43. balance.setScore((int)econ.getBalance(online.getName()));
    44. }
    45. }
    46.  
    47. public void onDisable() {
    48. PluginDescriptionFile pdfFile = getDescription();
    49. this.getLogger().info(
    50. pdfFile.getName() + " version: " + pdfFile.getVersion()
    51. + " has been disabled!");
    52. }
    53.  
    54. @Override
    55. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    56.  
    57. Player player = (Player) sender;
    58. if(cmd.getName().equalsIgnoreCase("scoreboard")) {
    59. if(args.length == 0) {
    60. player.sendMessage(ChatColor.GREEN + "Main Command Initialised!");
    61. // sb disable
    62. }else if(args[0].equalsIgnoreCase("disable")) {
    63. player.setScoreboard(manager.getNewScoreboard());
    64. player.sendMessage(ChatColor.GOLD + "Scoreboard is now" + ChatColor.RED + " disabled!");
    65. // sb enable
    66. }else if(args[0].equalsIgnoreCase("enable")) {
    67. player.setScoreboard(board);
    68. player.sendMessage(ChatColor.GOLD + "Scoreboard is now" + ChatColor.GREEN + " enabled!");
    69. }
    70. }
    71. return false;
    72. }
    73.  
    74. private boolean setupEconomy() {
    75. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    76. return false;
    77. }
    78. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    79. if (rsp == null) {
    80. return false;
    81. }
    82. econ = rsp.getProvider();
    83. return econ != null;
    84. }
    85.  
    86. private boolean setupChat() {
    87. RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
    88. chat = rsp.getProvider();
    89. return chat != null;
    90. }
    91. }


    I am getting no errors in eclipse but when i startup my mc server, i get a null pointer exception.
    Pastebin
    I know what line is causing it..
    Code:java
    1. balance.setScore((int)econ.getBalance(online.getName()));


    However if i remove the (int) i get an error "The method setScore(int) in the type Score is not applicable for the arguments (double)".

    So if you have any idea's on how i can fix this then please explain:)

    Thanks in advanced

    GalaxyCraft

    chasechocolate
    The reason why im tagging you is because it was your tutorial i followed, so possibly you know how to fix this? And im guessing from the amount of knowledge & plugins you have created with Java, you know what your talking about:)
     
  2. Offline

    xTigerRebornx

    GalaxyCraft econ is null, you never initialize it.
     
  3. Offline

    GalaxyCraft

  4. Offline

    xTigerRebornx

    GalaxyCraft I assume that the 'setupEconomy()' method may do something.
     
  5. Offline

    GalaxyCraft

    xTigerRebornx
    What do you mean?
    Its this line thats the problem:
    Code:java
    1. balance.setScore((int)econ.getBalance(online.getName()));
     
  6. Offline

    ColonelHedgehog

    Also, just so you know, nobody will see that scoreboard since nobody is on when the server enables. I'd put that in your on join event and perform the functions specifically to the player that joined rather than looping through all players.
     
  7. Offline

    GalaxyCraft

    ColonelHedgehog
    So like this?
    Code:
        public void onPlayerJoin(PlayerJoinEvent event) {
            Objective objective = board.registerNewObjective("test", "dummy");
     
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
     
            objective.setDisplayName("MomentoPrison");
                event.getPlayer().setScoreboard(board);
     
                Score balance = objective.getScore(ChatColor.GREEN + "Balance:");
     
                balance.setScore((int)econ.getBalance(event.getPlayer().getName()));
    }
    
    or
    Code:
    public void onPlayerJoin(PlayerJoinEvent event) {
        event.getPlayer().setScoreboard(board);
    }
     
  8. Offline

    ColonelHedgehog

    Yes, but I'd set the scoreboard to the player after setting the score.
     
  9. Offline

    GalaxyCraft

    ColonelHedgehog
    How would i do that?
    Because when i have this:
    Code:java
    1. public void onPlayerJoin(PlayerJoinEvent event) {
    2. event.getPlayer().setScoreboard(board);
    3.  
    4. Score balance = objective.getScore(ChatColor.GREEN + "Balance:");
    5.  
    6. balance.setScore(100);
    7. }
    8. }

    The scoreboard does not appear when the player joins, instead i have to do /sb enable for it to appear.

    Anyone know how i can get the vault balance working?

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

    mythbusterma

    GalaxyCraft

    Follow the instructions on the Vault page.
     
  11. Offline

    GalaxyCraft

    mythbusterma
    I have,
    Code:
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            econ = rsp.getProvider();
            return econ != null;
        }
    And
    Code:java
    1. public static Economy econ = null;


    But i dont know what else im missing..
     
  12. Offline

    mythbusterma

    GalaxyCraft

    1. You have to CALL setupEconomy(), it won't just run itself.
    2. econ really shouldn't be static
    3. There won't be any players on the server during onEnable(), so don't create scoreboards there.
     
  13. Offline

    GalaxyCraft

    Okay, i am about to create my own method for the scoreboards,
    How would i call setoupEconomy()?
    Sorry this is the first time i have worked with vault :/

    mythbusterma
    Oh wait i believe i have found it
    Code:
    setupEconomy();
    Is that it?

    Okay i have new code now:
    Code:java
    1. public Economy econ = null;
    2. private static final Logger log = Logger.getLogger("Minecraft");
    3.  
    4. public void onEnable() {
    5. if (!setupEconomy() ) {
    6. log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    7. getServer().getPluginManager().disablePlugin(this);
    8. return;
    9. }
    10.  
    11. getServer().getPluginManager().registerEvents(this, this);
    12.  
    13. setupEconomy();
    14. }
    15.  
    16. ScoreboardManager manager = Bukkit.getScoreboardManager();
    17. Scoreboard board = manager.getNewScoreboard();
    18. Objective objective = board.registerNewObjective("test", "dummy");
    19.  
    20. public void onPlayerJoin(PlayerJoinEvent event) {
    21. Player player = event.getPlayer();
    22. player.setScoreboard(board);
    23. }
    24.  
    25. public static void Scoreboard(Objective objective, Economy econ, Player player) {
    26. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    27.  
    28. objective.setDisplayName("MomentoPrison");
    29.  
    30. Score balance = objective.getScore(ChatColor.GREEN + "Balance:");
    31.  
    32. balance.setScore((int) econ.getBalance(player.getName()));
    33. }


    But when i join the server, i get no scoreboard, when i do /sb enable i get no scoreboard.
    Any ideas?

    EDIT:
    I just got null pointer exception, and i only get that when i add this line:
    Code:java
    1. balance.setScore((int) econ.getBalance(player.getName()));
    2.  


    How do i get rid of the null pointer exception?

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

    Necrodoom

    GalaxyCraft why are you calling setupEconomy twice? Also, which variable is null?
     
  15. Offline

    GalaxyCraft

  16. Offline

    Necrodoom

    GalaxyCraft which question?
    First - you are calling setupEconomy twice. Why?

    Second - NPE means you called a method on a null. Which variable in the NPE line is null?
     
  17. Offline

    GalaxyCraft

    Necrodoom
    1 - I have already fixed,
    2 - econ
     
  18. Offline

    GalaxyCraft

    Bump, please i really need help.

    xTigerRebornx
    Do you know how to fix econ/vault return null

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

    xTigerRebornx

    GalaxyCraft Considering you have yet post the full code, all classes, and the full stacktrace, I don't. I only assume its because you've mixed up what you are doing and/or you don't have proper knowledge of Java to understand what you are doing.
     
  20. Offline

    GalaxyCraft

    xTigerRebornx
    Main Class (Only Class):
    Code:java
    1. package me.unique.scoreboard;
    2.  
    3. import net.milkbowl.vault.economy.Economy;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.plugin.RegisteredServiceProvider;
    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. public class Main extends JavaPlugin implements Listener {
    21.  
    22. public Economy econ = null;
    23.  
    24. public void onEnable() {
    25. getServer().getPluginManager().registerEvents(this, this);
    26.  
    27. setupEconomy();
    28. }
    29.  
    30. ScoreboardManager manager = Bukkit.getScoreboardManager();
    31. Scoreboard board = manager.getNewScoreboard();
    32. Objective objective = board.registerNewObjective("test", "dummy");
    33.  
    34. public static void Scoreboard(Objective objective, Economy econ, Player player) {
    35. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    36.  
    37. objective.setDisplayName("MomentoPrison");
    38.  
    39. Score balance = objective.getScore(ChatColor.GREEN + "Balance:");
    40.  
    41. balance.setScore((int) econ.getBalance(player.getName()));
    42. }
    43.  
    44. @Override
    45. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    46.  
    47. Player player = (Player) sender;
    48. if(cmd.getName().equalsIgnoreCase("scoreboard")) {
    49. if(args.length == 0) {
    50. player.sendMessage(ChatColor.GREEN + "Main Command Initialised!");
    51. // sb disable
    52. }else if(args[0].equalsIgnoreCase("disable")) {
    53. if(player.hasPermission("scoreboard.disable")) {
    54. player.setScoreboard(manager.getNewScoreboard());
    55. player.sendMessage(ChatColor.GOLD + "Scoreboard is now" + ChatColor.RED + " disabled!");
    56. }else {
    57. player.sendMessage(ChatColor.RED + "You do not have permission!");
    58. }
    59. // sb enable
    60. }else if(args[0].equalsIgnoreCase("enable")) {
    61. if(player.hasPermission("scoreboard.enable")) {
    62. player.setScoreboard(board);
    63. player.sendMessage(ChatColor.GOLD + "Scoreboard is now" + ChatColor.GREEN + " enabled!");
    64. }else {
    65. player.sendMessage(ChatColor.RED + "You do not have permission!");
    66. }
    67. }
    68. }
    69. return false;
    70. }
    71.  
    72. public void onPlayerJoin(PlayerJoinEvent event) {
    73. Player player = event.getPlayer();
    74. player.setScoreboard(board);
    75. }
    76.  
    77. private boolean setupEconomy() {
    78. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    79. return false;
    80. }
    81. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    82. if (rsp == null) {
    83. return false;
    84. }
    85. econ = rsp.getProvider();
    86. return econ != null;
    87. }
    88. }


    &
    I have never encountered this problem before so i do not know how to fix it.
     
  21. Offline

    xTigerRebornx

    GalaxyCraft First off, review the example Vault posted, as you clearly didn't understand it and have missed some key parts. Secondly, you did not post the full stacktrace.
     
  22. Offline

    GalaxyCraft

    Okay i will upload the full error now.

    EDIT:
    Are you able to tell me which parts im missing because this must of have been at least the 5th time i have gone through the same page and took the parts i thought i needed.

    http://pastebin.com/gittu6TB
     
  23. Offline

    xTigerRebornx

    GalaxyCraft What parts are you missing? The part where you actually LEARN rather then just COPY the code is the main thing you are missing. Other then that, there is a specific snippit that actually shows how setupEconomy() is used.
     
  24. Offline

    GalaxyCraft

    xTigerRebornx
    As i have said i have read through the page at least 5 times. Not just COPYING the code. But reading what he has written. I obviously didn't see the comments if he actually had anything there, because i just checked again 30 seconds ago, and i see no snippet of it explaining it. Just him giving us an example of how to implement Vault, i have done everything he said, but yet its still not working...
     
  25. Offline

    xTigerRebornx

    GalaxyCraft Considering you've missed the part where it actually USES the method setupEconomy(), you clearly haven't learned from it.
     
  26. Offline

    GalaxyCraft

    xTigerRebornx
    What? I already have that..
    Code:java
    1. public void onEnable() {
    2. getServer().getPluginManager().registerEvents(this, this);
    3.  
    4. if (!setupEconomy() ) {
    5. log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    6. getServer().getPluginManager().disablePlugin(this);
    7. return;
    8. }
    9.  
    10. setupEconomy();
    11. }
     
  27. Offline

    xTigerRebornx

    GalaxyCraft
    Code:
    public void onEnable() {
    getServer().getPluginManager().registerEvents(this, this);
     
    setupEconomy();
    }
    I'd say you clearly don't in the code provided.
    Repost a new stacktrace that is actually from the code called, the one you posted points right to a comment.
     
  28. Offline

    GalaxyCraft

    xTigerRebornx
    Okay i will also upload my main class for you to see any changes i have made.
    Main Class:
    Code:java
    1. package me.unique.scoreboard;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import net.milkbowl.vault.chat.Chat;
    6. import net.milkbowl.vault.economy.Economy;
    7. import net.milkbowl.vault.permission.Permission;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.player.PlayerJoinEvent;
    16. import org.bukkit.plugin.RegisteredServiceProvider;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18. import org.bukkit.scoreboard.DisplaySlot;
    19. import org.bukkit.scoreboard.Objective;
    20. import org.bukkit.scoreboard.Score;
    21. import org.bukkit.scoreboard.Scoreboard;
    22. import org.bukkit.scoreboard.ScoreboardManager;
    23.  
    24. public class Main extends JavaPlugin implements Listener {
    25.  
    26. private static final Logger log = Logger.getLogger("Minecraft");
    27. public static Economy econ = null;
    28. public static Permission perms = null;
    29. public static Chat chat = null;
    30.  
    31. @Override
    32. public void onEnable() {
    33. getServer().getPluginManager().registerEvents(this, this);
    34.  
    35. if (!setupEconomy() ) {
    36. log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    37. getServer().getPluginManager().disablePlugin(this);
    38. return;
    39. }
    40.  
    41. setupEconomy();
    42. }
    43.  
    44. @Override
    45. public void onDisable() {
    46. log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
    47. }
    48.  
    49. ScoreboardManager manager = Bukkit.getScoreboardManager();
    50. Scoreboard board = manager.getNewScoreboard();
    51.  
    52. public static void Scoreboard(Player player) {
    53. ScoreboardManager manager = Bukkit.getScoreboardManager();
    54. Scoreboard board = manager.getNewScoreboard();
    55. Objective objective = board.registerNewObjective("test", "dummy");
    56.  
    57. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    58.  
    59. objective.setDisplayName("MomentoPrison");
    60.  
    61. Score balance = objective.getScore(ChatColor.GREEN + "Balance:");
    62.  
    63. balance.setScore((int) econ.getBalance(player.getName()));
    64. }
    65.  
    66. @Override
    67. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    68.  
    69. Player player = (Player) sender;
    70. if(cmd.getName().equalsIgnoreCase("scoreboard")) {
    71. if(args.length == 0) {
    72. player.sendMessage(ChatColor.GREEN + "Main Command Initialised!");
    73. // sb disable
    74. }else if(args[0].equalsIgnoreCase("disable")) {
    75. if(player.hasPermission("scoreboard.disable")) {
    76. player.setScoreboard(manager.getNewScoreboard());
    77. player.sendMessage(ChatColor.GOLD + "Scoreboard is now" + ChatColor.RED + " disabled!");
    78. }else {
    79. player.sendMessage(ChatColor.RED + "You do not have permission!");
    80. }
    81. // sb enable
    82. }else if(args[0].equalsIgnoreCase("enable")) {
    83. if(player.hasPermission("scoreboard.enable")) {
    84. player.setScoreboard(board);
    85. player.sendMessage(ChatColor.GOLD + "Scoreboard is now" + ChatColor.GREEN + " enabled!");
    86. }else {
    87. player.sendMessage(ChatColor.RED + "You do not have permission!");
    88. }
    89. }
    90. }
    91. return false;
    92. }
    93.  
    94. public void onPlayerJoin(PlayerJoinEvent event) {
    95. Player player = event.getPlayer();
    96. player.setScoreboard(board);
    97. }
    98.  
    99. private boolean setupEconomy()
    100. {
    101. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    102. if (economyProvider != null) {
    103. econ = economyProvider.getProvider();
    104. }
    105.  
    106. return (econ != null);
    107. }
    108. }


    Stacktrace:
    Code:
    [01:40:44] [Server thread/INFO]: Starting minecraft server version 1.7.10
    [01:40:44] [Server thread/INFO]: Loading properties
    [01:40:44] [Server thread/INFO]: Default game type: SURVIVAL
    [01:40:44] [Server thread/INFO]: Generating keypair
    [01:40:44] [Server thread/INFO]: Starting Minecraft server on *:25565
    [01:40:45] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT)
    [01:40:45] [Server thread/ERROR]: Could not load 'plugins\Scoreboards.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugins(CraftServer.java:364) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.<init>(CraftServer.java:326) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.PlayerList.<init>(PlayerList.java:68) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.DedicatedServer.init(DedicatedServer.java:133) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:436) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    Caused by: java.lang.NullPointerException
        at me.unique.scoreboard.Main.<init>(Main.java:50) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_65]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_65]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_65]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_65]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_65]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
        ... 9 more
    [01:40:45] [Server thread/INFO]: [Vault] Loading Vault v1.2.31-b411
    [01:40:45] [Server thread/INFO]: [ProtocolLib] Loading ProtocolLib v3.4.0
    [01:40:45] [Server thread/WARN]: [ProtocolLib] Version (MC: 1.7.10) has not yet been tested! Proceed with caution.
    [01:40:45] [Server thread/INFO]: [PermissionsEx] Loading PermissionsEx v1.22.3
    [01:40:45] [Server thread/INFO]: [Essentials] Loading Essentials v2.13.1
    [01:40:45] [Server thread/INFO]: [EssentialsChat] Loading EssentialsChat v2.13.1
    [01:40:45] [Server thread/INFO]: [EssentialsProtect] Loading EssentialsProtect v2.13.1
    [01:40:45] [Server thread/INFO]: [EssentialsSpawn] Loading EssentialsSpawn v2.13.1
    [01:40:45] [Server thread/INFO]: [EssentialsAntiBuild] Loading EssentialsAntiBuild v2.13.1
    [01:40:45] [Server thread/INFO]: [Vault] Enabling Vault v1.2.31-b411
    [01:40:45] [Server thread/INFO]: [Vault] [Vault][Economy] Essentials Economy found: Waiting
    [01:40:45] [Server thread/INFO]: [Vault] [Vault][Permission] PermissionsEx found: Waiting
    [01:40:45] [Server thread/INFO]: [Vault] [Vault][Permission] SuperPermissions loaded as backup permission system.
    [01:40:45] [Server thread/INFO]: [Vault] [Vault][Chat] PermissionsEx found: Waiting
    [01:40:45] [Server thread/INFO]: [Vault] [Vault] Enabled Version 1.2.31-b411
    [01:40:45] [Server thread/INFO]: [ProtocolLib] Enabling ProtocolLib v3.4.0
    [01:40:45] [Server thread/INFO]: [ProtocolLib] Started structure compiler thread.
    [01:40:45] [Server thread/INFO]: Preparing level "world"
    [01:40:45] [Server thread/INFO]: Preparing start region for level 0 (Seed: 6639343975012175801)
    [01:40:45] [Thread-7/WARN]: Could not get information about this CraftBukkit version; perhaps you are running a custom one?: IOException
    [01:40:46] [Thread-7/WARN]: Could not get latest artifact information: IOException
    [01:40:46] [Server thread/INFO]: Preparing spawn area: 45%
    [01:40:47] [Server thread/INFO]: Preparing start region for level 1 (Seed: 6639343975012175801)
    [01:40:48] [Server thread/INFO]: Preparing spawn area: 82%
    [01:40:48] [Server thread/INFO]: Preparing start region for level 2 (Seed: 6639343975012175801)
    [01:40:48] [Server thread/INFO]: [PermissionsEx] Enabling PermissionsEx v1.22.3
    [01:40:48] [Server thread/INFO]: [PermissionsEx] Initializing file backend
    [01:40:48] [Server thread/INFO]: [PermissionsEx] Permissions file successfully reloaded
    [01:40:48] [Server thread/INFO]: [Vault][Permission] PermissionsEx hooked.
    [01:40:48] [Server thread/INFO]: [Vault][Chat] PermissionsEx_Chat hooked.
    [01:40:48] [Server thread/INFO]: [Essentials] Enabling Essentials v2.13.1
    [01:40:49] [Server thread/INFO]: [Vault][Economy] Essentials Economy hooked.
    [01:40:49] [Server thread/INFO]: Essentials: Using PermissionsEx based permissions.
    [01:40:49] [Server thread/INFO]: [PingMessage] Enabling PingMessage v1
    [01:40:49] [Server thread/INFO]: [EssentialsChat] Enabling EssentialsChat v2.13.1
    [01:40:49] [Server thread/INFO]: [EssentialsProtect] Enabling EssentialsProtect v2.13.1
    [01:40:49] [Server thread/INFO]: [EssentialsSpawn] Enabling EssentialsSpawn v2.13.1
    [01:40:49] [Server thread/INFO]: [EssentialsAntiBuild] Enabling EssentialsAntiBuild v2.13.1
    [01:40:49] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [01:40:49] [Server thread/INFO]: Done (3.662s)! For help, type "help" or "?"
    [01:40:50] [pool-3-thread-3/INFO]: [Vault] Checking for Updates:
    [01:40:50] [pool-3-thread-3/WARN]: [Vault] Stable Version: 1.4.1 is out! You are still running version: 1.2.31
    [01:40:50] [pool-3-thread-3/WARN]: [Vault] Update at: http://dev.bukkit.org/server-mods/vault
    
    Btw, i appreciate your patience with me, i have never worked with scoreboards & vault before :)
     
  29. Offline

    xTigerRebornx

    GalaxyCraft Move the instantiation inside a method (onEnable() probably)
     
  30. Offline

    GalaxyCraft

    xTigerRebornx
    Okay i am not getting anymore null pointers with this class:
    Code:java
    1. package me.unique.scoreboard;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import net.milkbowl.vault.chat.Chat;
    6. import net.milkbowl.vault.economy.Economy;
    7. import net.milkbowl.vault.permission.Permission;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.ChatColor;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.player.PlayerJoinEvent;
    16. import org.bukkit.plugin.RegisteredServiceProvider;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18. import org.bukkit.scoreboard.DisplaySlot;
    19. import org.bukkit.scoreboard.Objective;
    20. import org.bukkit.scoreboard.Score;
    21. import org.bukkit.scoreboard.Scoreboard;
    22. import org.bukkit.scoreboard.ScoreboardManager;
    23.  
    24. public class Main extends JavaPlugin implements Listener {
    25.  
    26. private static final Logger log = Logger.getLogger("Minecraft");
    27. public static Economy econ = null;
    28. public static Permission perms = null;
    29. public static Chat chat = null;
    30.  
    31. ScoreboardManager manager = Bukkit.getScoreboardManager();
    32. Scoreboard board = manager.getNewScoreboard();
    33.  
    34. @Override
    35. public void onEnable() {
    36. getServer().getPluginManager().registerEvents(this, this);
    37.  
    38. if (!setupEconomy() ) {
    39. log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    40. getServer().getPluginManager().disablePlugin(this);
    41. return;
    42. }
    43.  
    44. setupEconomy();
    45. }
    46.  
    47. @Override
    48. public void onDisable() {
    49. log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
    50. }
    51.  
    52. public static void Scoreboard(Player player) {
    53. ScoreboardManager manager = Bukkit.getScoreboardManager();
    54. Scoreboard board = manager.getNewScoreboard();
    55. Objective objective = board.registerNewObjective("test", "dummy");
    56.  
    57. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    58.  
    59. objective.setDisplayName("MomentoPrison");
    60.  
    61. Score balance = objective.getScore(ChatColor.GREEN + "Balance:");
    62.  
    63. balance.setScore(100);
    64. }
    65.  
    66. @Override
    67. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    68. Player player = (Player) sender;
    69. if(cmd.getName().equalsIgnoreCase("scoreboard")) {
    70. if(args.length == 0) {
    71. player.sendMessage(ChatColor.GREEN + "Main Command Initialised!");
    72. // sb disable
    73. }else if(args[0].equalsIgnoreCase("disable")) {
    74. if(player.hasPermission("scoreboard.disable")) {
    75. player.setScoreboard(manager.getNewScoreboard());
    76. player.sendMessage(ChatColor.GOLD + "Scoreboard is now" + ChatColor.RED + " disabled!");
    77. }else {
    78. player.sendMessage(ChatColor.RED + "You do not have permission!");
    79. }
    80. // sb enable
    81. }else if(args[0].equalsIgnoreCase("enable")) {
    82. if(player.hasPermission("scoreboard.enable")) {
    83. player.setScoreboard(board);
    84. player.sendMessage(ChatColor.GOLD + "Scoreboard is now" + ChatColor.GREEN + " enabled!");
    85. }else {
    86. player.sendMessage(ChatColor.RED + "You do not have permission!");
    87. }
    88. }
    89. }
    90. return false;
    91. }
    92.  
    93. public void onPlayerJoin(PlayerJoinEvent event) {
    94. ScoreboardManager manager = Bukkit.getScoreboardManager();
    95. Scoreboard board = manager.getNewScoreboard();
    96.  
    97. Player player = event.getPlayer();
    98. player.setScoreboard(board);
    99. }
    100.  
    101. private boolean setupEconomy()
    102. {
    103. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    104. if (economyProvider != null) {
    105. econ = economyProvider.getProvider();
    106. }
    107.  
    108. return (econ != null);
    109. }
    110. }


    However when the player joins the game, the scoreboard doesnt show, even when the player does /sb enable it still doesnt show, and there is no errors in the console.

    Any ideas on how i can fix this, thanks.

    GalaxyCraft :)
     
Thread Status:
Not open for further replies.

Share This Page