Server status

Discussion in 'Plugin Development' started by Nojus, May 18, 2014.

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

    Nojus

    Why is this not working the error:

    Code:
    [17:31:54] [Server thread/WARN]: java.io.IOException: Server returned HTTP response code: 403 for URL: http://minecraft-api.com/v1/get/?server=mc.ender.lt
    [17:31:54] [Server thread/WARN]:    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    [17:31:54] [Server thread/WARN]:    at java.net.URL.openStream(Unknown Source)
    [17:31:54] [Server thread/WARN]:    at pingserver.main.pingServer(main.java:43)
    [17:31:54] [Server thread/WARN]:    at pingserver.main.lol(main.java:27)
    [17:31:54] [Server thread/WARN]:    at pingserver.main.onCommand(main.java:61)
    [17:31:54] [Server thread/WARN]:    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    [17:31:54] [Server thread/WARN]:    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180)
    [17:31:54] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:728)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerConnection.java:985)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:830)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java:28)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat.java:65)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:180)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.ServerConnection.c(ServerConnection.java:81)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:713)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:283)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:576)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:482)
    [17:31:54] [Server thread/WARN]:    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628)
    and the code:
    Code:java
    1. package pingserver;
    2.  
    3. import com.google.gson.Gson;
    4. import com.google.gson.internal.LinkedTreeMap;
    5. import java.io.BufferedReader;
    6. import java.io.IOException;
    7. import java.io.InputStreamReader;
    8. import java.net.MalformedURLException;
    9. import java.net.URL;
    10. import java.util.HashMap;
    11.  
    12. import org.bukkit.command.Command;
    13. import org.bukkit.command.CommandSender;
    14. import org.bukkit.entity.Player;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class main extends JavaPlugin implements Listener {
    19.  
    20. public void onEnable() {
    21. getServer().getPluginManager().registerEvents(this, this);
    22. }
    23.  
    24. @SuppressWarnings("rawtypes")
    25. public static void lol(Player player)
    26. {
    27. HashMap JSON = pingServer("mc.ender.lt");
    28.  
    29. if (JSON == null || JSON.get("error") != null) {
    30. player.sendMessage("The server is offline :(");
    31. } else {
    32. LinkedTreeMap players = (LinkedTreeMap) JSON.get("players");
    33. player.sendMessage("There are " + players.get("online") + " out of " + players.get("max") + " online!");
    34. player.sendMessage("MoTD is (" + JSON.get("motd") + ")");
    35. }
    36. }
    37.  
    38. @SuppressWarnings("rawtypes")
    39. public static HashMap pingServer(String server)
    40. {
    41. try {
    42. URL url = new URL("[url]http://minecraft-api.com/v1/get/?server=[/url]" + server);
    43. try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()))) {
    44. String data = reader.readLine();
    45.  
    46. Gson gson = new Gson();
    47. return gson.fromJson(data, HashMap.class);
    48. }
    49. } catch (MalformedURLException e) {
    50. e.printStackTrace();
    51. } catch (IOException e) {
    52. e.printStackTrace();
    53. }
    54. return null;
    55. }
    56.  
    57. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    58. Player player = (Player) sender;
    59.  
    60. if(label.equalsIgnoreCase("ping-that")) {
    61. lol(player);
    62. }
    63.  
    64. return false;
    65. }
    66.  
    67. }
     
  2. Offline

    Smerfa

    try use https and why you have [.url] tag? :p
     
  3. Offline

    Nojus

    Smerfa
    Oh the tag is from these forums when i pasted the code its there for some reason but in my code theres is no [.url] tag and with https there is the same error.

    Can someone help me?

    bump

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

    Nghtmr9999

    Are you sure the value of 'server' is what you expect?
     
  5. Offline

    Nojus

    This code is from website http://minecraft-api.com/getting-started

    So can anyone help?

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

Share This Page