Java Code Examples for org.inventivetalent.update.spiget.SpigetUpdate#checkForUpdate()

The following examples show how to use org.inventivetalent.update.spiget.SpigetUpdate#checkForUpdate() . 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: Wild.java    From WildernessTp with MIT License 6 votes vote down vote up
private void checkUpdate(){
    SpigetUpdate updater = new SpigetUpdate(this,18431);
    updater.setVersionComparator(VersionComparator.SEM_VER);
    updater.checkForUpdate(new UpdateCallback() {
        @Override
        public void updateAvailable(String newVersion, String downloadUrl, boolean hasDirectDownload) {
            if(instance.getConfig().getBoolean("AutoUpdate")) {
                if (hasDirectDownload) {
                    if (updater.downloadUpdate()) {
                        getLogger().info("New version of the plugin downloaded and will be loaded on restart");
                    } else {
                        getLogger().warning("Update download failed, reason is " + updater.getFailReason());
                    }
                }
            }else{
                getLogger().info("There is an update available please go download it");
            }
        }

        @Override
        public void upToDate() {
            getLogger().info("You are using the latest version thanks");
        }
    });
}
 
Example 2
Source File: PacketListenerPlugin.java    From PacketListenerAPI with MIT License 5 votes vote down vote up
@Override
public void onEnable() {
	if (!packetListenerAPI.injected) {
		getLogger().warning("Injection failed. Disabling...");
		Bukkit.getPluginManager().disablePlugin(this);
		return;
	}

	try {
		SpigetUpdate updater = new SpigetUpdate(this, 2930);
		updater.setUserAgent("PacketListenerAPI/" + getDescription().getVersion()).setVersionComparator(VersionComparator.SEM_VER_SNAPSHOT);
		updater.checkForUpdate(new UpdateCallback() {
			@Override
			public void updateAvailable(String s, String s1, boolean b) {
				getLogger().info("There is a new version available: https://r.spiget.org/2930");
			}

			@Override
			public void upToDate() {
				getLogger().info("Plugin is up-to-date");
			}
		});
	} catch (Exception e) {
		e.printStackTrace();	
	}

	new Metrics(this, 225);

	//Initialize this API if the plugin got enabled
	APIManager.initAPI(PacketListenerAPI.class);
}
 
Example 3
Source File: SpigetUpdater.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check is a new version is available
 *
 * @param sender
 * @param silent - if true the player will not get the status in Game
 */
public void checkForUpdate(final CommandSender sender, final boolean silent) {
    if (!silent)
        sender.sendMessage("[RedProtect] Checking for updates ...");
    if (updateAvailable != UpdateStatus.RESTART_NEEDED) {
        spigetUpdate = new SpigetUpdate(plugin, 15841);
        spigetUpdate.setVersionComparator(VersionComparator.EQUAL);
        spigetUpdate.setUserAgent("RedProtect-" + plugin.getDescription().getVersion());

        spigetUpdate.checkForUpdate(new UpdateCallback() {

            @Override
            public void updateAvailable(String newVersion, String downloadUrl, boolean hasDirectDownload) {
                //// VersionComparator.EQUAL handles all updates as new, so I have to check the
                //// version number manually
                updateAvailable = isUpdateNewerVersion(newVersion);
                if (updateAvailable == UpdateStatus.AVAILABLE) {
                    newDownloadVersion = newVersion;
                    sender.sendMessage(ChatColor.GOLD + "[RedProtect] New update found: " + ChatColor.GREEN + newVersion);
                    if (plugin.config.configRoot().update.auto_update) {
                        downloadAndUpdateJar(sender);
                        sender.sendMessage(ChatColor.GOLD + "[RedProtect] " + ChatColor.GREEN + "Plugin updated. Restart server to complete the update.");
                    } else
                        sender.sendMessage(ChatColor.GOLD + "[RedProtect] " + ChatColor.GREEN + "Please use '/rp update' to update to " + newDownloadVersion);
                }
            }

            @Override
            public void upToDate() {
                //// Plugin is up-to-date
                if (!silent)
                    sender.sendMessage("[RedProtect] " + ChatColor.RESET + "No update available.");
            }
        });
    }
}