1.14.4 Version Checker does not work

Discussion in 'Spigot Plugin Development' started by Nike_Schuh123, Jan 12, 2020.

  1. Hey Guys!
    Im trying to Code a Version checker that automatically searches for updates.

    Exception :

    [17:16:19] [Server thread/WARN]: java.io.IOException: Server returned HTTP response code: 405 for URL: https://api.spigotmc.org/legacy/update.php?resource=71374
    [17:16:19] [Server thread/WARN]: at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
    [17:16:19] [Server thread/WARN]: at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    [17:16:19] [Server thread/WARN]: at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
    [17:16:19] [Server thread/WARN]: at de.nike.spigot.draconicevolution.npl.pluginhandler.Updater.getNewestVersion(Updater.java:48)
    [17:16:19] [Server thread/WARN]: at de.nike.spigot.draconicevolution.Main.onEnable(Main.java:288)
    [17:16:19] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263)
    [17:16:19] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:352)
    [17:16:19] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417)
    [17:16:19] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugin(CraftServer.java:461)
    [17:16:19] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugins(CraftServer.java:375)
    [17:16:19] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_14_R1.CraftServer.reload(CraftServer.java:810)
    [17:16:19] [Server thread/WARN]: at org.bukkit.Bukkit.reload(Bukkit.java:576)
    [17:16:19] [Server thread/WARN]: at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27)
    [17:16:19] [Server thread/WARN]: at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149)
    [17:16:19] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:710)
    [17:16:19] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchServerCommand(CraftServer.java:695)
    [17:16:19] [Server thread/WARN]: at net.minecraft.server.v1_14_R1.DedicatedServer.handleCommandQueue(DedicatedServer.java:430)
    [17:16:19] [Server thread/WARN]: at net.minecraft.server.v1_14_R1.DedicatedServer.b(DedicatedServer.java:394)
    [17:16:19] [Server thread/WARN]: at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:970)
    [17:16:19] [Server thread/WARN]: at net.minecraft.server.v1_14_R1.Minecraft

    Update Method​
    Code (Java):
    package de.nike.spigot.draconicevolution.npl.pluginhandler;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;

    import org.bukkit.Bukkit;

    public class Updater {

        private static String key = "key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=";

        public static Integer checkVersion(Integer id, String currentVersion) {
            try {
                HttpURLConnection connection = (HttpURLConnection) new URL(
                        "https://api.spigotmc.org/legacy/update.php?resource=" + id).openConnection();
                connection.setDoInput(true);
                connection.setDoOutput(true);
                connection.setRequestMethod("POST");
                connection.getOutputStream().write((key + id).getBytes("UTF-8"));
                String version = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
                if (!(version.equals(currentVersion))) {
                    return 2;
                } else {
                    return 1;
                }
            } catch (MalformedURLException e) {
                return 0;

            } catch (IOException e) {
                return -1;

            }

        }

        public static String getNewestVersion(Integer id) {
            try {
                HttpURLConnection connection = (HttpURLConnection) new URL(
                        "https://api.spigotmc.org/legacy/update.php?resource=" + id).openConnection();
                connection.setDoInput(true);
                connection.setDoOutput(true);
                connection.setRequestMethod("POST");
                connection.getOutputStream().write((key + id).getBytes("UTF-8"));
                String version = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
                return version;

            } catch(Exception e) {
                Bukkit.getConsoleSender().sendMessage(
                        "§c[§7Draconic Evolution§c] §7Updater failed (" + e.toString() + ")");
                e.printStackTrace();
            }

            return null;
        }

    }
     
     
  2. Change
    Code (Text):
      connection.setRequestMethod("POST");
    to

    Code (Text):
      connection.setRequestMethod("GET");