Java Code Examples for org.bukkit.Bukkit#getUpdateFolderFile()

The following examples show how to use org.bukkit.Bukkit#getUpdateFolderFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UpdateDownloader.java    From SkinsRestorerX with GNU General Public License v3.0 6 votes vote down vote up
public Properties getUpdaterProperties() {
    File file = new File(Bukkit.getUpdateFolderFile(), "spiget.properties");
    Properties properties = new Properties();
    if (!file.exists()) {
        try {
            if (!file.createNewFile()) {
                return null;
            }
            properties.setProperty("externalDownloads", "false");
            properties.store(new FileWriter(file), "Configuration for the Spiget auto-updater. https://spiget.org | https://github.com/InventivetalentDev/SpigetUpdater\n"
                    + "Use 'externalDownloads' if you want to auto-download resources hosted on external sites\n"
                    + "");
        } catch (Exception ignored) {
            return null;
        }
    }
    try {
        properties.load(new FileReader(file));
    } catch (IOException e) {
        return null;
    }
    return properties;
}
 
Example 2
Source File: SpigetUpdate.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
public Properties getUpdaterProperties() {
    File file = new File(Bukkit.getUpdateFolderFile(), "spiget.properties");
    Properties properties = new Properties();
    if (!file.exists()) {
        try {
            if (!file.createNewFile()) {
                return null;
            }
            properties.setProperty("externalDownloads", "false");
            properties.store(new FileWriter(file), "Configuration for the Spiget auto-updater. https://spiget.org | https://github.com/InventivetalentDev/SpigetUpdater\n"
                    + "Use 'externalDownloads' if you want to auto-download resources hosted on external sites\n"
                    + "");
        } catch (Exception ignored) {
            return null;
        }
    }
    try {
        properties.load(new FileReader(file));
    } catch (IOException e) {
        return null;
    }
    return properties;
}
 
Example 3
Source File: Updater.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
private void downloadUpdate() throws QuestRuntimeException {
    LogUtils.getLogger().log(Level.INFO, "(Autoupdater) Updater started download of new version...");
    if (!config.enabled) {
        throw new QuestRuntimeException("The updater is disabled in the config! Check config entry 'update.enabled'.");
    }
    if (latest.getValue() == null) {
        throw new QuestRuntimeException("The updater did not find an update! This can depend on your update_strategy, check config entry 'update.update_strategy'.");
    }
    LogUtils.getLogger().log(Level.INFO, "(Autoupdater) The target version is '" + latest.getKey().getVersion() + "'...");
    try {
        URL remoteFile = new URL(latest.getValue());
        try (ReadableByteChannel rbc = Channels.newChannel(remoteFile.openStream())) {
            File folder = Bukkit.getUpdateFolderFile();
            if (!folder.exists()) {
                folder.mkdirs();
            }
            File file = new File(folder, fileName);
            if (!file.exists()) {
                file.createNewFile();
            }
            try (FileOutputStream fos = new FileOutputStream(file)) {
                fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
            }
        }
        latest = Pair.of(new Version(plugin.getDescription().getVersion()), null);
        LogUtils.getLogger().log(Level.INFO, "(Autoupdater) Download finished.");
    } catch (IOException e) {
        throw new QuestRuntimeException("Could not download the file. Try again or update manually.", e);
    }
}
 
Example 4
Source File: UpdateDownloaderGithub.java    From SkinsRestorerX with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean downloadUpdate() {
    this.releaseInfo = (GitHubReleaseInfo) plugin.getUpdateChecker().getLatestResourceInfo();

    if (releaseInfo == null) {
        failReason = DownloadFailReason.NOT_CHECKED;
        return false;// Update not yet checked
    }
    if (!plugin.getUpdateChecker().isVersionNewer(plugin.getUpdateChecker().currentVersion, releaseInfo.tag_name)) {
        failReason = DownloadFailReason.NO_UPDATE;
        return false;// Version is no update
    }

    File pluginFile = getPluginFile();// /plugins/XXX.jar
    if (pluginFile == null) {
        failReason = DownloadFailReason.NO_PLUGIN_FILE;
        return false;
    }
    File updateFolder = Bukkit.getUpdateFolderFile();
    if (!updateFolder.exists()) {
        if (!updateFolder.mkdirs()) {
            failReason = DownloadFailReason.NO_UPDATE_FOLDER;
            return false;
        }
    }
    final File updateFile = new File(updateFolder, pluginFile.getName());

    plugin.getLogger().info("[GitHubUpdate] Downloading update...");
    Bukkit.getScheduler().runTaskAsynchronously(plugin, GitHubUpdateDownloader.downloadAsync(releaseInfo, updateFile, plugin.getUpdateChecker().getUserAgent(), new DownloadCallback() {
        @Override
        public void finished() {
            plugin.getLogger().info("[GitHubUpdate] Update saved as " + updateFile.getPath());
        }

        @Override
        public void error(Exception exception) {
            plugin.getLogger().log(Level.WARNING, "[GitHubUpdate] Could not download update", exception);
        }
    }));

    return true;
}
 
Example 5
Source File: UpdateDownloader.java    From SkinsRestorerX with GNU General Public License v3.0 4 votes vote down vote up
public boolean downloadUpdate() {
    this.latestResourceInfo = plugin.getUpdateChecker().getLatestResourceInfo();

    if (latestResourceInfo == null) {
        failReason = DownloadFailReason.NOT_CHECKED;
        return false;// Update not yet checked
    }
    if (!plugin.getUpdateChecker().isVersionNewer(plugin.getUpdateChecker().currentVersion, latestResourceInfo.latestVersion.name)) {
        failReason = DownloadFailReason.NO_UPDATE;
        return false;// Version is no update
    }
    if (latestResourceInfo.external) {
        failReason = DownloadFailReason.NO_DOWNLOAD;
        return false;// No download available
    }

    File pluginFile = getPluginFile();// /plugins/XXX.jar
    if (pluginFile == null) {
        failReason = DownloadFailReason.NO_PLUGIN_FILE;
        return false;
    }
    File updateFolder = Bukkit.getUpdateFolderFile();
    if (!updateFolder.exists()) {
        if (!updateFolder.mkdirs()) {
            failReason = DownloadFailReason.NO_UPDATE_FOLDER;
            return false;
        }
    }
    final File updateFile = new File(updateFolder, pluginFile.getName());

    Properties properties = getUpdaterProperties();
    boolean allowExternalDownload = properties != null && properties.containsKey("externalDownloads") && Boolean.valueOf(properties.getProperty("externalDownloads"));

    if (!allowExternalDownload && latestResourceInfo.external) {
        failReason = DownloadFailReason.EXTERNAL_DISALLOWED;
        return false;
    }

    plugin.getSrLogger().logAlways("[SpigetUpdate] Downloading update...");
    Bukkit.getScheduler().runTaskAsynchronously(plugin, org.inventivetalent.update.spiget.download.UpdateDownloader.downloadAsync(latestResourceInfo, updateFile, plugin.getUpdateChecker().getUserAgent(), new DownloadCallback() {
        @Override
        public void finished() {
            plugin.getSrLogger().logAlways("[SpigetUpdate] Update saved as " + updateFile.getPath());
        }

        @Override
        public void error(Exception exception) {
            plugin.getSrLogger().logAlways(Level.WARNING, "[SpigetUpdate] Could not download update", exception);
        }
    }));

    return true;
}
 
Example 6
Source File: SpigetUpdate.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public boolean downloadUpdate() {
    if (latestResourceInfo == null) {
        failReason = DownloadFailReason.NOT_CHECKED;
        return false;// Update not yet checked
    }
    if (!isVersionNewer(currentVersion, latestResourceInfo.latestVersion.name)) {
        failReason = DownloadFailReason.NO_UPDATE;
        return false;// Version is no update
    }
    if (latestResourceInfo.external) {
        failReason = DownloadFailReason.NO_DOWNLOAD;
        return false;// No download available
    }

    File pluginFile = getPluginFile();// /plugins/XXX.jar
    if (pluginFile == null) {
        failReason = DownloadFailReason.NO_PLUGIN_FILE;
        return false;
    }
    File updateFolder = Bukkit.getUpdateFolderFile();
    if (!updateFolder.exists()) {
        if (!updateFolder.mkdirs()) {
            failReason = DownloadFailReason.NO_UPDATE_FOLDER;
            return false;
        }
    }
    final File updateFile = new File(updateFolder, pluginFile.getName());

    Properties properties = getUpdaterProperties();
    boolean allowExternalDownload = properties != null && properties.containsKey("externalDownloads") && Boolean.valueOf(properties.getProperty("externalDownloads"));

    if (!allowExternalDownload && latestResourceInfo.external) {
        failReason = DownloadFailReason.EXTERNAL_DISALLOWED;
        return false;
    }

    log.info("[SpigetUpdate] Downloading update...");
    dispatch(UpdateDownloader.downloadAsync(latestResourceInfo, updateFile, getUserAgent(), new DownloadCallback() {
        @Override
        public void finished() {
            log.info("[SpigetUpdate] Update saved as " + updateFile.getPath());
        }

        @Override
        public void error(Exception exception) {
            log.log(Level.WARNING, "[SpigetUpdate] Could not download update", exception);
        }
    }));

    return true;
}