org.inventivetalent.update.spiget.comparator.VersionComparator Java Examples

The following examples show how to use org.inventivetalent.update.spiget.comparator.VersionComparator. 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.");
            }
        });
    }
}
 
Example #4
Source File: NickNamerPlugin.java    From NickNamer with MIT License 4 votes vote down vote up
@Override
public void onEnable() {
	instance = this;
	APIManager.initAPI(PacketListenerAPI.class);
	APIManager.initAPI(NickNamerAPI.class);

	Bukkit.getPluginManager().registerEvents(this, this);

	saveDefaultConfig();
	reload();

	if (featureCommandGeneral) {
		PluginAnnotations.COMMAND.registerCommands(this, generalCommands = new GeneralCommands(this));
	} else {
		getLogger().info("General commands disabled");
	}
	if (featureCommandNick) {
		PluginAnnotations.COMMAND.registerCommands(this, nickCommands = new NickCommands(this));
	} else {
		getLogger().info("Nick commands disabled");
	}
	if (featureCommandSkin) {
		PluginAnnotations.COMMAND.registerCommands(this, skinCommands = new SkinCommands(this));
	} else {
		getLogger().info("Skin commands disabled");
	}

	if (bungeecord) {
		if (Bukkit.getOnlineMode()) {
			getLogger().warning("Bungeecord is enabled, but server is in online mode!");
		}
		Bukkit.getMessenger().registerIncomingPluginChannel(this, channelIdentifier, this);
		Bukkit.getMessenger().registerOutgoingPluginChannel(this, channelIdentifier);
	}

	//Replace the default NickManager
	new PluginNickManager(this);

	switch (storageType.toLowerCase()) {
		case "temporary":
			getLogger().info("Using temporary storage");
			break;
		case "local":
			initStorageLocal();
			break;
		case "sql":
			getLogger().info("Using SQL storage (" + sqlUser + "@" + sqlAddress + ")");
			initStorageSQL();
			break;
		case "redis":
			throw new RuntimeException("Redis storage is currently not supported.");
			//				getLogger().info("Using Redis storage (" + redisHost + ":" + redisPort + ")");
			//				initStorageRedis();
			//				break;
	}

	new Metrics(this);

	spigetUpdate = new SpigetUpdate(this, 5341).setUserAgent("NickNamer/" + getDescription().getVersion()).setVersionComparator(VersionComparator.SEM_VER_SNAPSHOT);
	spigetUpdate.checkForUpdate(new UpdateCallback() {
		@Override
		public void updateAvailable(String s, String s1, boolean b) {
			getLogger().info("A new version is available (" + s + "). Download it from https://r.spiget.org/5341");
		}

		@Override
		public void upToDate() {
			getLogger().info("The plugin is up-to-date.");
		}
	});

	if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
		getLogger().info("Registering placeholders.");
		new NickNamerPlaceholders().register();
	}
	;
}
 
Example #5
Source File: AnimatedFramesPlugin.java    From AnimatedFrames with MIT License 4 votes vote down vote up
@Override
public void onEnable() {
	if (!Bukkit.getPluginManager().isPluginEnabled("MapManager")) {
		getLogger().warning("**************************************************");
		getLogger().warning("  ");
		getLogger().warning("         This plugin depends on MapManager        ");
		getLogger().warning("             https://r.spiget.org/19198            ");
		getLogger().warning("  ");
		getLogger().warning("**************************************************");
		Bukkit.getPluginManager().disablePlugin(this);
		return;
	}

	saveDefaultConfig();
	PluginAnnotations.CONFIG.load(this, this);
	PluginAnnotations.COMMAND.load(this, new Commands(this));

	maxAnimateDistanceSquared = maxAnimateDistance * maxAnimateDistance;

	frameManager = new FrameManager(this);
	frameExecutor = Executors.newCachedThreadPool();

	Bukkit.getPluginManager().registerEvents(interactListener = new InteractListener(this), this);
	Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
	Bukkit.getPluginManager().registerEvents(new ClickListener(this), this);

	File cacheDir = new File(getDataFolder(), "cache");
	if (!cacheDir.exists()) { cacheDir.mkdirs(); }

	getLogger().fine("Waiting 2 seconds before loading data...");
	Bukkit.getScheduler().runTaskLaterAsynchronously(this, new Runnable() {
		@Override
		public void run() {
			getLogger().info("Loading data...");
			frameExecutor.execute(new Runnable() {
				@Override
				public void run() {
					frameManager.readFramesFromFile();
					getLogger().info("Loaded " + frameManager.size() + " frames.");
				}
			});
		}
	}, 40);

	new Metrics(this);

	spigetUpdate = new SpigetUpdate(this, 5583).setUserAgent("AnimatedFrames/" + getDescription().getVersion()).setVersionComparator(VersionComparator.SEM_VER_SNAPSHOT);
	spigetUpdate.checkForUpdate(new UpdateCallback() {
		@Override
		public void updateAvailable(String s, String s1, boolean b) {
			updateAvailable = true;
			getLogger().info("A new version is available (" + s + "). Download it from https://r.spiget.org/5583");
			//					getLogger().info("(If the above version is lower than the installed version, you are probably up-to-date)");
		}

		@Override
		public void upToDate() {
			getLogger().info("The plugin is up-to-date.");
		}
	});
}
 
Example #6
Source File: SpigetUpdate.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
@Override
public SpigetUpdate setVersionComparator(VersionComparator comparator) {
    super.setVersionComparator(comparator);
    return this;
}
 
Example #7
Source File: SpigetUpdateAbstract.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public SpigetUpdateAbstract setVersionComparator(VersionComparator comparator) {
    this.versionComparator = comparator;
    return this;
}