Solved Please help me with my plugin !

Discussion in 'Plugin Development' started by MaroHD, Oct 16, 2014.

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

    MaroHD

    Hello im making a hub plugin for my server and i have a problem with seting the scoreboard
    Please help me
    i ll post you the error and my scoreboard.java
    http://pastebin.com/82fAXx6s
    and here's the code
    Code:java
    1. package maro.got;
    2.  
    3. import net.milkbowl.vault.Vault;
    4. import net.milkbowl.vault.economy.Economy;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.plugin.RegisteredServiceProvider;
    10. import org.bukkit.scoreboard.DisplaySlot;
    11. import org.bukkit.scoreboard.Objective;
    12. import org.bukkit.scoreboard.Score;
    13. import org.bukkit.scoreboard.ScoreboardManager;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class Scoreboard implements Listener {
    17. public static Economy econ = null;
    18.  
    19. public Vault getVault() {
    20. return getVault();
    21. }
    22. static String scname = "§6GotCraft";
    23.  
    24. @SuppressWarnings({ "deprecation", "rawtypes" })
    25. public static void regScoreboard(Player p) {
    26. getServer();
    27. RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
    28. Economy econ = (Economy)rsp.getProvider();
    29. String balance = econ.format(econ.getBalance(p.getName())).replace("$", "");
    30. double newBalance = Double.parseDouble(balance);
    31. int finalBalance = (int)newBalance;
    32. int numpl = Bukkit.getOnlinePlayers().length;
    33. int maxpl = Bukkit.getMaxPlayers();
    34. String rankstring = "§7Nqmash rank";
    35. if (p.hasPermission("got.user")) rankstring = "§eUser";
    36. if (p.hasPermission("got.vip")) rankstring = "§3VIP";
    37. if (p.hasPermission("got.super")) rankstring = "§bSuper";
    38. if (p.hasPermission("got.donator")) rankstring = "§6§lDonator";
    39. if (p.hasPermission("got.testmod")) rankstring = "§9TestMOD";
    40. if (p.hasPermission("got.mod")) rankstring = "§9§lMOD";
    41. if (p.hasPermission("got.admin")) rankstring = "§a§lAdmin";
    42. if (p.hasPermission("got.head")) rankstring = "§c§lHead-Admin";
    43. if (p.hasPermission("got.op")) rankstring = "§4§lOP";
    44. try {
    45.  
    46. ScoreboardManager manager = Bukkit.getScoreboardManager();
    47. org.bukkit.scoreboard.Scoreboard board = manager.getNewScoreboard();
    48.  
    49. final Objective objective = board.registerNewObjective("GotCraft", "dummy");
    50. objective.setDisplayName("GotCraft");
    51. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    52.  
    53. Score spacer3 = objective.getScore(Bukkit.getOfflinePlayer("§a§lMoney:"));
    54. spacer3.setScore(8);
    55.  
    56. Score ddd3 = objective.getScore(Bukkit.getOfflinePlayer("§f" + finalBalance));
    57. ddd3.setScore(7);
    58.  
    59. Score news = objective.getScore(Bukkit.getOfflinePlayer("§e§lNews:"));
    60. news.setScore(6);
    61.  
    62. Score news2 = objective.getScore(Bukkit.getOfflinePlayer("§f" + Got.news));
    63. news2.setScore(5);
    64.  
    65. Score rank = objective.getScore(Bukkit.getOfflinePlayer("§6§lRank:"));
    66. rank.setScore(4);
    67.  
    68. Score rank2 = objective.getScore(Bukkit.getOfflinePlayer(rankstring));
    69. rank2.setScore(3);
    70.  
    71. Score website = objective.getScore(Bukkit.getOfflinePlayer("§b§lSite:"));
    72. website.setScore(2);
    73.  
    74. Score website2 = objective.getScore(Bukkit.getOfflinePlayer("[url="http://www.gotcraft.eu"]www.gotcraft.eu[/url]"));
    75. website2.setScore(1);
    76.  
    77. p.setScoreboard(board);
    78. } finally {
    79. }
    80. }
    81.  
    82.  
    83. @SuppressWarnings({ "rawtypes", "deprecation" })
    84. public static void enableScoreboard(Player p) {
    85. getServer();
    86. RegisteredServiceProvider rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
    87. Economy econ = (Economy)rsp.getProvider();
    88. String balance = econ.format(econ.getBalance(p)).replace("$", "");
    89. double newBalance = Double.parseDouble(balance);
    90. int finalBalance = (int)newBalance;
    91. int numpl = Bukkit.getOnlinePlayers().length;
    92. int maxpl = Bukkit.getMaxPlayers();
    93. String rankstring = "В§7Everyone";
    94. if (p.hasPermission("got.user")) rankstring = "§eUser";
    95. if (p.hasPermission("got.vip")) rankstring = "§3VIP";
    96. if (p.hasPermission("got.super")) rankstring = "§bSuper";
    97. if (p.hasPermission("got.donator")) rankstring = "§6§lDonator";
    98. if (p.hasPermission("got.testmod")) rankstring = "§9TestMOD";
    99. if (p.hasPermission("got.mod")) rankstring = "§9§lMOD";
    100. if (p.hasPermission("got.admin")) rankstring = "§a§lAdmin";
    101. if (p.hasPermission("got.head")) rankstring = "§c§lHead-Admin";
    102. if (p.hasPermission("got.op")) rankstring = "§4§lOP";
    103. try {
    104.  
    105. ScoreboardManager manager = Bukkit.getScoreboardManager();
    106. org.bukkit.scoreboard.Scoreboard board = manager.getMainScoreboard();
    107.  
    108. Objective objective = board.getObjective("GotCraft");
    109.  
    110.  
    111. if (objective.getScore(Bukkit.getOfflinePlayer("§a§lMoney:")) != null);
    112. Score spacer3 = objective.getScore(Bukkit.getOfflinePlayer("§a§lMoney:"));
    113. spacer3.setScore(8);
    114. if (objective.getScore(Bukkit.getOfflinePlayer("§a§lMoney:")) != null);
    115. Score ddd3 = objective.getScore(Bukkit.getOfflinePlayer("§f" + finalBalance));
    116. ddd3.setScore(7);
    117.  
    118. if (objective.getScore(Bukkit.getOfflinePlayer("§e§lNews:")) != null);
    119. Score news = objective.getScore(Bukkit.getOfflinePlayer("§e§lNews:"));
    120. news.setScore(6);
    121.  
    122. if (objective.getScore(Bukkit.getOfflinePlayer("§f" + Got.news)) != null);
    123. Score news2 = objective.getScore(Bukkit.getOfflinePlayer("§f" + Got.news));
    124. news2.setScore(5);
    125.  
    126. if (objective.getScore(Bukkit.getOfflinePlayer("§6§lRank:")) != null);
    127. Score rank = objective.getScore(Bukkit.getOfflinePlayer("§6§lRank:"));
    128. rank.setScore(4);
    129.  
    130. if (objective.getScore(Bukkit.getOfflinePlayer("rankstring")) != null);
    131. Score rank2 = objective.getScore(Bukkit.getOfflinePlayer(rankstring));
    132. rank2.setScore(3);
    133.  
    134. if (objective.getScore(Bukkit.getOfflinePlayer("§b§lSite:")) != null);
    135. Score website = objective.getScore(Bukkit.getOfflinePlayer("§b§lSite:"));
    136. website.setScore(2);
    137.  
    138. if (objective.getScore(Bukkit.getOfflinePlayer("[url="http://www.gotcraft.eu"]www.gotcraft.eu[/url]")) != null);
    139. Score website2 = objective.getScore(Bukkit.getOfflinePlayer("[url="http://www.gotcraft.eu"]www.gotcraft.eu[/url]"));
    140. website2.setScore(1);
    141.  
    142. p.setScoreboard(board);
    143. }
    144. finally {
    145. }
    146. }
    147. private static Bukkit getServer() {
    148. Bukkit.getServerId();
    149. return null;
    150. }
    151.  
    152. static int num = 0;
    153. public static void StartName() {
    154. ScoreboardManager manager = Bukkit.getScoreboardManager();
    155. org.bukkit.scoreboard.Scoreboard board = manager.getMainScoreboard();
    156.  
    157. final Objective objective = board.getObjective("GotCraft");
    158. Bukkit.getScheduler().scheduleSyncRepeatingTask(Bukkit.getPluginManager().getPlugin("Got"), new Runnable() {
    159. public void run() {
    160. if (num == 0) {
    161. objective.setDisplayName("§6GotCraft");
    162. num ++;
    163. }else if (num == 1) {
    164. objective.setDisplayName("§eG§6otCraft");
    165. num ++;
    166. }else if (num == 2) {
    167. objective.setDisplayName("§fG§6otCraft");
    168. num ++;
    169. }else if (num == 3) {
    170. objective.setDisplayName("§fG§eo§6tCraft");
    171. num ++;
    172. }else if (num == 4) {
    173. objective.setDisplayName("§fGo§6tCraft");
    174. num ++;
    175. }else if (num == 5) {
    176. objective.setDisplayName("§fGo§et§6Craft");
    177. num ++;
    178. }else if (num == 6) {
    179. objective.setDisplayName("§fGot§6Craft");
    180. num ++;
    181. }else if (num == 7) {
    182. objective.setDisplayName("§fGot§eC§6raft");
    183. num ++;
    184. }else if (num == 8) {
    185. objective.setDisplayName("§fGotC§6raft");
    186. num ++;
    187. }else if (num == 9) {
    188. objective.setDisplayName("§fGotC§er§6aft");
    189. num ++;
    190. }else if (num == 10) {
    191. objective.setDisplayName("§fGotCr§6aft");
    192. num ++;
    193. }else if (num == 11) {
    194. objective.setDisplayName("§fGotCr§ea§6ft");
    195. num ++;
    196. }else if (num == 12) {
    197. objective.setDisplayName("§fGotCra§6ft");
    198. num ++;
    199. }else if (num == 13) {
    200. objective.setDisplayName("§fGotCra§ef§6t");
    201. num ++;
    202. }else if (num == 14) {
    203. objective.setDisplayName("§fGotCraf§6t");
    204. num ++;
    205. }else if (num == 15) {
    206. objective.setDisplayName("§fGotCraf§et");
    207. num ++;
    208. }else if (num == 16) {
    209. objective.setDisplayName("§fGotCraft");
    210. num ++;
    211. }else if (num == 17) {
    212. objective.setDisplayName("§6GotCraft");
    213. num ++;
    214. }else if (num == 18) {
    215. objective.setDisplayName("§eG§fotCraft");
    216. num ++;
    217. }else if (num == 19) {
    218. objective.setDisplayName("§6G§fotCraft");
    219. num ++;
    220. }else if (num == 20) {
    221. objective.setDisplayName("§6G§eo§ftCraft");
    222. num ++;
    223. }else if (num == 21) {
    224. objective.setDisplayName("§6Go§ftCraft");
    225. num ++;
    226. }else if (num == 22) {
    227. objective.setDisplayName("§6Go§et§fCraft");
    228. num ++;
    229. }else if (num == 23) {
    230. objective.setDisplayName("§6Got§fCraft");
    231. num ++;
    232. }else if (num == 24) {
    233. objective.setDisplayName("§6Got§eC§fraft");
    234. num ++;
    235. }else if (num == 25) {
    236. objective.setDisplayName("§6GotC§fraft");
    237. num ++;
    238. }else if (num == 26) {
    239. objective.setDisplayName("§6GotC§er§faft");
    240. num ++;
    241. }else if (num == 27) {
    242. objective.setDisplayName("§6GotCr§faft");
    243. num ++;
    244. }else if (num == 28) {
    245. objective.setDisplayName("§6GotCr§ea§fft");
    246. num ++;
    247. }else if (num == 29) {
    248. objective.setDisplayName("§6GotCra§fft");
    249. num ++;
    250. }else if (num == 30) {
    251. objective.setDisplayName("§6GotCra§ef§ft");
    252. num ++;
    253. }else if (num == 31) {
    254. objective.setDisplayName("§6GotCraf§ft");
    255. num ++;
    256. }else if (num == 32) {
    257. objective.setDisplayName("§6GotCraf§et");
    258. num ++;
    259. }else if (num == 33) {
    260. objective.setDisplayName("§6GotCraft");
    261. num = 0;
    262. }
    263. updateStandalone();
    264. }
    265. }, 0L, 10L);
    266. }
    267. @SuppressWarnings("deprecation")
    268. public static void updateStandalone() {
    269. for (Player p : Bukkit.getServer().getOnlinePlayers()) {
    270. if (p != null)
    271. enableScoreboard(p);
    272. }
    273. }
    274. }
    275.  

    Please ;)
     
  2. Offline

    JWhy

    Line 108,
    Code:java
    1. Objective objective = board.getObjective("GotCraft");

    seems to be null
     
  3. Offline

    Plo124

    MaroHD
    Did you board.registerObjective() yet?
     
  4. Offline

    es359

    Code:java
    1. public Vault getVault() {
    2. return getVault();
    3. }


    Uhh... What..? MaroHD

    Also a crazy use of Static.
     
    Born2PvP likes this.
  5. Offline

    MaroHD

    @ Plo457
    yes i registered the scoreboard here but i cannot put this on the onenable method


    Code:java
    1. final Objective objective = board.registerNewObjective("GotCraft", "dummy");
    2. objective.setDisplayName("GotCraft");
    3. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    4.  
    5. Score spacer3 = objective.getScore(Bukkit.getOfflinePlayer("§a§lMoney:"));
    6. spacer3.setScore(8);
    7.  
    8. Score ddd3 = objective.getScore(Bukkit.getOfflinePlayer("§f" + finalBalance));
    9. ddd3.setScore(7);
    10.  
    11. Score news = objective.getScore(Bukkit.getOfflinePlayer("§e§lNews:"));
    12. news.setScore(6);
    13.  
    14. Score news2 = objective.getScore(Bukkit.getOfflinePlayer("§f" + Got.news));
    15. news2.setScore(5);
    16.  
    17. Score rank = objective.getScore(Bukkit.getOfflinePlayer("§6§lRank:"));
    18. rank.setScore(4);
    19.  
    20. Score rank2 = objective.getScore(Bukkit.getOfflinePlayer(rankstring));
    21. rank2.setScore(3);
    22.  
    23. Score website = objective.getScore(Bukkit.getOfflinePlayer("§b§lSite:"));
    24. website.setScore(2);
    25.  
    26. Score website2 = objective.getScore(Bukkit.getOfflinePlayer("[url="http://www.gotcraft.eu"]www.gotcraft.eu[/url]"));
    27. website2.setScore(1);
    28.  
    29. p.setScoreboard(board);
    30. } finally {
    31. }
    32. }
    33.  
    34.  


    im making this
    Code:java
    1. final Objective objective = board.registerNewObjective("GotCraft", "dummy");

    and this
    Code:java
    1. Objective objective = board.getObjective("GotCraft");

    because on my updatestandalone method the getobjective() will nat create a new scoeboard every time and the board will not flashing

    (bad english)

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

    CheesyFreezy

    Normally you can't use a player in a onEnable or onDisable method. But there is a way you can do this
    For all the online players on the server:
    Code:java
    1. public void onEnable() {
    2. for(Player players : Bukkit.getOnlinePlayers()) { // make a loop that's whats inside is only for all the online players
    3. //do your scoreboard code here
    4. //use 'players' for the player variable
    5. }
    6. }


    Code:java
    1. if(CheesyFreezy.helped == true) {
    2. isSolved = true;
    3.  
    4. like++;
    5. }

    :D
     
  7. Offline

    MaroHD

    i ll try this and post here if is working
     
  8. Offline

    fireblast709

    MaroHD
    • Don't use OfflinePlayer for scores, use Strings
    • You have ; after the if statements that check for null, remove those.
    • Now you probably run into issues with creating variables in single line if statements. Wrap all code concerning those in {}.
    • Now remove the redundant getServer(); lines.
    • Next remove the infinitely recursive getVault();
    • When that's all done, initialize econ once, not every time you run the method.
    • Then remove all the magical section characters and use the ChatColor enum for the love of all things.
    • After that, remove the useless try-finally
    • Last but most certainly not least, get rid of all the [swear word] static keywords
     
    Hawktasard likes this.
  9. Offline

    MaroHD

    @Fireblast709 il ll try this
    @CheesyFreezy my onEnable() methot is not working now
    Code:java
    1. public void onEnable() {
    2. for(Player players : Bukkit.getOnlinePlayers()) {
    3. Bukkit.getPluginManager().registerEvents(new HideShow(), this);
    4. Bukkit.getPluginManager().registerEvents(new Compass(), this);
    5. Bukkit.getPluginManager().registerEvents(new StoreDiamond(), this);
    6. Bukkit.getPluginManager().registerEvents(new Chat(), this);
    7. Bukkit.getPluginManager().registerEvents(this, this);
    8.  
    9. spawn.setYaw(-88F);
    10. spawn.setPitch(3F);
    11.  
    12. Scoreboard.regScoreboard(players);
    13. Scoreboard.enableScoreboard(players);
    14. Scoreboard.updateStandalone();
    15. Scoreboard.StartName();
    16.  
    17. getLogger().info("The plugin is on!");
    18. }
    19. }
     
  10. Offline

    Dudemister1999

    MaroHD That code will definitely cause a whole lot of problems. Definitely go with fireblast709 's advice. And please, stop (stop) using §, use either ChatColor.translateAlternateColorCodes('&', "&aGreen Text"), or ChatColor.GREEN + "Green Text". It's killing me just staring at it!
     
  11. Offline

    MaroHD

    my onenable() method is not working now

    Code:java
    1. public void onEnable() {
    2. for(Player players : Bukkit.getOnlinePlayers()) {
    3. Bukkit.getPluginManager().registerEvents(new HideShow(), this);
    4. Bukkit.getPluginManager().registerEvents(new Compass(), this);
    5. Bukkit.getPluginManager().registerEvents(new StoreDiamond(), this);
    6. Bukkit.getPluginManager().registerEvents(new Chat(), this);
    7. Bukkit.getPluginManager().registerEvents(this, this);
    8.  
    9. spawn.setYaw(-88F);
    10. spawn.setPitch(3F);
    11.  
    12. Scoreboard.regScoreboard(players);
    13. Scoreboard.enableScoreboard(players);
    14. Scoreboard.updateStandalone();
    15. Scoreboard.StartName();
    16.  
    17. getLogger().info("The plugin is on!");
    18. }
    19. }

    the scoreboard code is on Scoreboard.java

    guys i ll remove the scoreboard for my plugin and i ll use Info-Board :D
    i think that is my solution for now

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
Thread Status:
Not open for further replies.

Share This Page