The method getOnlinePlayers() from the type Bukkit is deprecated?

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

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

    Josh014

    Hello,
    As the title says "The method getOnlinePlayers() from the type Bukkit is deprecated". This was not a problem on my localhost server. When I gave my friend the plugin with a command, which has the "Bukkit.getOnlinePlayers()" in it. The command just doesn't work. And there are no errors in the console at all.

    My code:
    Code:java
    1. if (label.equalsIgnoreCase("sc")) {
    2. if (player.hasPermission("pcommands.staffchat")) {
    3. String sc = "";
    4.  
    5. if (args.length < 1) {
    6. player.sendMessage("§cUsage: /sc <message>");
    7. return true;
    8. } else {
    9. for (String a : args) {
    10. sc = sc + a + " ";
    11. }
    12. for (Player allP : Bukkit.getOnlinePlayers()) {
    13. if (allP.hasPermission("pcommands.staffchat")) {
    14. allP.sendMessage("§7[§6StaffChat§7]§3 "
    15. + player.getName() + ": §c" + sc);
    16. return true;
    17. } else {
    18. return true;
    19. }
    20. }
    21. }
    22. } else {
    23. player.sendMessage("§4You don't have access to this command.");
    24. return true;
    25. }
    26. }


    I hope someone could help me out with this.
     
  2. Offline

    justin_393

    Josh014
    What's the version of your localhost and the one it doesn't work on.
     
  3. Offline

    Josh014

    justin_393
    Localhost is the newest craftbukkit and my friend use a Cauldron build 1.7.10
     
  4. Offline

    justin_393

    Josh014
    Have him use craftbukkit and the problem will be solved.
     
  5. Offline

    Josh014

    justin_393
    Yeah there is a little problem. He wants to use this for his Pixelmon server and he says that he needs to use Cauldron for Pixelmon.
     
  6. Offline

    justin_393

    Josh014
    Then you'll need to build the plugin against Cauldron, not Bukkit.
     
  7. Offline

    Josh014

    justin_393
    Is there a different way to get all the online players?
     
  8. Offline

    justin_393

    Josh014
    Not within Bukkit, because the method getOnlinePlayers() is invoked by Bukkit.
     
  9. Offline

    BeastCraft3

    Josh014
    Use the Bukkit api, Dont code with craftbukkit. Then you wont get a yellow line under getOnlinePlayers.
     
  10. Offline

    Josh014

    justin_393
    Well.. Thanks for helping me tho. I tried something different instead. I used first Bukkit.getOnlinePlayer() now I changed it to plugin.getServer().getOnlinePlayer(). But now I get an error:

    Error:
    Code:
    24.08 20:37:07 [Server] INFO ... 13 more
    24.08 20:37:07 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[PluginCommand.class:git-Cauldron-MCPC-Plus-1.7.10-1.1187.01.127]
    24.08 20:37:07 [Server] INFO at me.Josh.pCommands.Main.onCommand(Main.java:85) ~[?:?]
    24.08 20:37:07 [Server] INFO Caused by: java.lang.NullPointerException
    24.08 20:37:07 [Server] INFO at java.lang.Thread.run(Unknown Source) [?:1.7.0_55]
    24.08 20:37:07 [Server] INFO at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:663) [MinecraftServer.class:?]
    24.08 20:37:07 [Server] INFO at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:803) [MinecraftServer.class:?]
    24.08 20:37:07 [Server] INFO at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:422) [lt.class:?]
    24.08 20:37:07 [Server] INFO at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:973) [MinecraftServer.class:?]
    24.08 20:37:07 [Server] INFO at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:173) [nc.class:?]
    24.08 20:37:07 [Server] INFO at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:244) [ej.class:?]
    24.08 20:37:07 [Server] INFO at net.minecraft.network.play.client.C01PacketChatMessage.func_148833_a(C01PacketChatMessage.java:53) [ir.class:?]
    24.08 20:37:07 [Server] INFO at net.minecraft.network.play.client.C01PacketChatMessage.func_148833_a(C01PacketChatMessage.java:38) [ir.class:?]
    24.08 20:37:07 [Server] INFO at net.minecraft.network.NetHandlerPlayServer.func_147354_a(NetHandlerPlayServer.java:1129) [nh.class:?]
    24.08 20:37:07 [Server] INFO at net.minecraft.network.NetHandlerPlayServer.func_147361_d(NetHandlerPlayServer.java:1347) [nh.class:?]
    24.08 20:37:07 [Server] INFO at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:715) ~[CraftServer.class:git-Cauldron-MCPC-Plus-1.7.10-1.1187.01.127]
    24.08 20:37:07 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[SimpleCommandMap.class:git-Cauldron-MCPC-Plus-1.7.10-1.1187.01.127]
    24.08 20:37:07 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[PluginCommand.class:git-Cauldron-MCPC-Plus-1.7.10-1.1187.01.127]
    24.08 20:37:07 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'sc' in plugin pCommands v1.0
    24.08 20:37:07 [Server] ERROR null
    BeastCraft3
    Alright gonna check that out.

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

    justin_393

    Josh014
    24.08 20:37:07 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[PluginCommand.class:git-Cauldron-MCPC-Plus-1.7.10-1.1187.01.127]
    24.08 20:37:07 [Server] INFO at me.Josh.pCommands.Main.onCommand(Main.java:85) ~[?:?]
     
  12. Offline

    Josh014

    justin_393 Line 85 is the line with plugin.getServer().getOnlinePlayer()
     
  13. Offline

    justin_393

    Josh014
    Can you paste your entire class?
     
  14. Offline

    Josh014

    justin_393
    Sure,

    Code:
    Code:java
    1. package me.Josh.pCommands;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.plugin.PluginDescriptionFile;
    11. import org.bukkit.plugin.PluginManager;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class Main extends JavaPlugin implements Listener {
    15. public final Logger logger = Logger.getLogger("Minecraft");
    16. public static Main plugin;
    17.  
    18. public static boolean muteChat = false;
    19.  
    20. public void onDisable() {
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. this.logger.info(pdfFile.getName() + " Has been Disabled!");
    23. }
    24.  
    25. public void onEnable() {
    26. PluginDescriptionFile pdfFile = this.getDescription();
    27. this.logger.info(pdfFile.getName() + " v" + pdfFile.getVersion()
    28. + " has been Enabled!");
    29. PluginManager pm = Bukkit.getServer().getPluginManager();
    30. pm.registerEvents(this, this);
    31. pm.registerEvents(new Listeners(), this);
    32. }
    33.  
    34. @SuppressWarnings("deprecation")
    35. @Override
    36. public boolean onCommand(CommandSender sender, Command command,
    37. String label, String[] args) {
    38. if (sender instanceof Player) {
    39. Player player = (Player) sender;
    40.  
    41. if (label.equalsIgnoreCase("cc")) {
    42. if (player.hasPermission("pcommands.clearchat")) {
    43. for (int i = 0; i < 100; i++) {
    44. Bukkit.broadcastMessage("");
    45. if (i == 99)
    46. Bukkit.broadcastMessage("§7[§c!!!§7]§cThe chat has been cleared.");
    47. }
    48. return true;
    49. } else {
    50. player.sendMessage("§4You don't have access to this command.");
    51. return true;
    52. }
    53. }
    54.  
    55. if (label.equalsIgnoreCase("rc")) {
    56. if (player.hasPermission("pcommands.chat.togglemute")) {
    57. if (muteChat == false) {
    58. muteChat = true;
    59. Bukkit.broadcastMessage("§7[§c!!!§7]§cThe chat has been muted, only staff members are able to talk.");
    60. return true;
    61. } else {
    62. if (muteChat == true) {
    63. muteChat = false;
    64. Bukkit.broadcastMessage("§7[§a!!!§7]§aThe chat has been unmuted, everyone can talk now.");
    65. return true;
    66. }
    67. }
    68. } else {
    69. player.sendMessage("§4You don't have access to this command.");
    70. return true;
    71. }
    72. }
    73.  
    74. if (label.equalsIgnoreCase("sc")) {
    75. if (player.hasPermission("pcommands.staffchat")) {
    76. String sc = "";
    77.  
    78. if (args.length < 1) {
    79. player.sendMessage("§cUsage: /sc <message>");
    80. return true;
    81. } else {
    82. for (String a : args) {
    83. sc = sc + a + " ";
    84. }
    85. for (Player allP : plugin.getServer().getOnlinePlayers()) {
    86. if (allP.hasPermission("pcommands.staffchat")) {
    87. allP.sendMessage("§7[§6StaffChat§7]§3 "
    88. + player.getName() + ": §c" + sc);
    89. return true;
    90. } else {
    91. return true;
    92. }
    93. }
    94. }
    95. } else {
    96. player.sendMessage("§4You don't have access to this command.");
    97. return true;
    98. }
    99. }
    100.  
    101. } else {
    102. if (label.equalsIgnoreCase("cc")) {
    103. for (int i = 0; i < 100; i++) {
    104. Bukkit.broadcastMessage("");
    105. if (i == 99)
    106. Bukkit.broadcastMessage("§7[§c!!!§7]§cThe chat has been cleared.");
    107. }
    108. return true;
    109. }
    110.  
    111. if (label.equalsIgnoreCase("rc")) {
    112. if (muteChat == false) {
    113. muteChat = true;
    114. Bukkit.broadcastMessage("§7[§c!!!§7]§cThe chat has been muted, only staff members are able to talk.");
    115. return true;
    116. } else {
    117. if (muteChat == true) {
    118. muteChat = false;
    119. Bukkit.broadcastMessage("§7[§a!!!§7]§aThe chat has been unmuted, everyone can talk now.");
    120. return true;
    121. }
    122. }
    123. }
    124.  
    125. if (label.equalsIgnoreCase("sc")) {
    126. String sc = "";
    127.  
    128. if (args.length < 1) {
    129. sender.sendMessage("§cUsage: /sc <message>");
    130. return true;
    131. } else {
    132. for (String a : args) {
    133. sc = sc + a + " ";
    134. }
    135. for (Player allP : plugin.getServer().getOnlinePlayers()) {
    136. if (allP.hasPermission("pcommands.staffchat")) {
    137. allP.sendMessage("§7[§6StaffChat§7]§d CONSOLE: §c"
    138. + sc);
    139. return true;
    140. } else {
    141. return true;
    142. }
    143. }
    144. }
    145. }
    146.  
    147. sender.sendMessage("This is an ingame command!");
    148. return true;
    149. }
    150. return false;
    151. }
    152. }
    153.  
     
  15. Offline

    Necrodoom

    Josh014 justin_393 unofficial builds are not supported here. Seek support elsewhere.
     
  16. Offline

    Josh014

    Necrodoom Well I use the normal Craftbukkit and changed to Bukkit.

    BeastCraft3
    Well I changed to the latest Bukkit version and still I got the same problem.

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

    Necrodoom

     
  18. Offline

    Josh014

    BeastCraft3 justin_393
    Alright got it fixed now. I used instead of plugin.getServer().getOnlinePlayers(), this.getServer().getOnlinePlayers().

    justin_393
    Well nvm... Only one person gets the message now ._.
    Necrodoom
    This happens now on my own craftbukkit server too. And there is just the official build installed.

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

    JaguarJo

    Locked. These forums only support CraftBukkit servers. For troubleshooting problems related to other server software, seek support from the makers of that software.

    Do not come here trying to get support for other software and then when you're called out on it make the excuse that you also have a CraftBukkit server too. You are clearly developing for a Cauldron server and we do not support Cauldron here. At the risk of sounding like a broken record, "seek support from the makers of that software".
     
Thread Status:
Not open for further replies.

Share This Page