Sueta

MVdWUpdater

1.7.2

Plugin updater API for spigot premium plugins

·Plugin

MVdWUpdater
Update Spigot premium plugins

Supports Premium plugins
Supports Two factory Auth. login

1. About
This plugin is made to allow Spigot users to update their premium plugins without developers needing to upload their plugins at insecure locations.

2. Installation

  1. Drag and drop the plugin to the plugins folder
  2. Start the server once until it generated the plugins/MVdWUpdater directory
  3. You will see a file credentials.yml
  4. ## ---------------------------------------- # 
    ## SpigotMC.org credentials 
    ##   Enter your SpigotMC.org credentials in 
    ##   this yaml file and restart the plugin 
    ##   The plugin will log you in and store 
    ##   the session cookies. 
    ## ---------------------------------------- # 
    
    # DO NOT EDIT THE CONFIG VERSION! 
    config: 2 
    
    
    # Enter your SpigotMC.org username 
    username: '' 
    
    # Enter the corresponding password 
    password: '' 
    
    # Enter the 2FA Secret if you have 2FA enabled 
    # See plugin page for more info 
    2fasecret: ''
  5. Enter your Spigot username and password and restart the server
  6. After the restart and if the credentials are correct the yml will contain the cookies.
  7. If all is fine you will see a confirmation message in the console and your purchased resources will be shown.

3. Usage

3.1. Server owners

  • Install the plugin
  • Log in using your credentials
  • If you have 2FA. You need to add the key in the config. If you did not store this, reset your 2FA and click "code" instead of the QR code. There will be a code you can also enter on Google Authenticator and the config of this plugin.

3.2. Developers
Updater Java Docs: http://ci.mvdw-software.com/job/MVdWUpdater/javadoc/
CI Server: http://ci.mvdw-software.com/job/MVdWUpdater/
Source: https://github.com/Maximvdw/MVdWUpdater
Spigot Site API: https://github.com/Maximvdw/SpigotSite-API
Spigot Site Implementation: https://github.com/Maximvdw/SpigotSite
Spigot Site API Java Docs: http://ci.mvdw-software.com/job/SpigotSite-API/javadoc/

  • Your version syntax must be major.minor.release if you want to use the auto updater functionality. This applies to both the version in the plugins.yml of your plugin but also the version on your update description!
  • Optionally your version syntax can contain a " b" behind ( 1.0.0b ) to indicate a beta release. This applies to both the version in the plugins.yml of your plugin but also the version on your update description!
  • When the major version is 0 the version will considered an alpha release. This applies to both the version in the plugins.yml of your plugin but also the version on your update description!
  • Make sure to softdepend on the plugin

3.2.1 Example implementation
Basic Example:

MVdWUpdater updater = (MVdWUpdater) Bukkit.getPluginManager().getPlugin("MVdWUpdater"); 
if (updater.hasBought(updater.getSpigotUser(), RESOURCEID)) { 
    updater.updatePlugin(plugin, RESOURCEID, UpdateMethod.INSTALL_ON_RESTART, updater.getSpigotUser()); 
}

Advanced Example:
Do not update when the major version is different

try { 
    MVdWUpdater updater = (MVdWUpdater) Bukkit.getPluginManager().getPlugin("MVdWUpdater"); 
    if (updater.hasBought(updater.getSpigotUser(), resourceId)) { 
        SendConsole.info("Hooked into MVdWUpdater!"); 
  
        List<Resource> premiums = updater.getPurchasedResources(updater.getSpigotUser()); 
        for (Resource premium : premiums) { 
            if (premium.getResourceId() == resourceId) { 
                // Resource id found 
                SendConsole.info("Checking for new updates for: " + plugin.getName() + " ..."); 

                // Compare versions 
                Version currentPluginVersion = new Version(plugin.getDescription().getVersion()); 
                Version newPluginVersion = new Version(updater.getResourceVersionString(resourceId)); 
    
                if (currentPluginVersion.compare(newPluginVersion) == 1) { 
                    SendConsole.info("An update for '" + plugin.getName() + "' is available"); 
        
                    // Do not update if the update is a major version 
                    if (currentPluginVersion.getMajor() != newPluginVersion.getMajor()){ 
                        SendConsole.info("Update is a major update! Manual updating is required!"); 
                        return; 
                    } 

                    SendConsole.info("Getting download link ..."); 
                    Resource premiumResource = updater.getSpigotSiteAPI().getResourceManager() 
                            .getResourceById(premium.getResourceId(),updater.getSpigotUser()); 

                    // Download the plugin to the update folder 
                    File pluginFile = null; 
                    try { 
                        pluginFile = new File(URLDecoder.decode( 
                                plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), 
                                "UTF-8")); 
                    } catch (UnsupportedEncodingException e) { 

                    } 
        
                    File outputFile = null; 
                    try{ 
                        outputFile = new File(Bukkit.getUpdateFolderFile(), pluginFile.getName()); 
                    }catch (Exception ex){ 
            
                    } 

                    if (pluginFile != null && outputFile != null) { 
                        SendConsole.info("Downloading '" + plugin.getName() + "' ..."); 
                        premiumResource.downloadResource(updater.getSpigotUser(), outputFile); 

                        SendConsole.info("An new update for " + plugin.getName() + " is ready to be installed on next restart!"); 
                    } 
                } 

                break; 
            } 
        } 
  
        setUpdated(true); 
    } 
} catch (Exception e) { 
    e.printStackTrace(); 
}

3.2.2 Maven dependency
Repository:

<repository> 
    <id>public</id> 
    <name>Public Repositories</name> 
    <url>http://repo.mvdw-software.be/content/groups/public/</url> 
</repository>

Dependency:

<dependency> 
    <groupId>be.maximvdw</groupId> 
    <artifactId>MVdWUpdater</artifactId> 
    <version>1.2.0-SNAPSHOT</version> 
   <exclusions> 
       <exclusion> 
           <groupId>*</groupId> 
           <artifactId>*</artifactId> 
       </exclusion> 
   </exclusions> 
</dependency>

4. Disclaimer
The plugin requires your credentials. These are inside a config file so make sure that file can not be read by other users.

Authors of plugins can access the logged in user in this API. This means they can see the cookies , username and use the account to update plugins using their own steps, file locations ,... . Again it is your job to make sure the plugins you put on your server are not malicious.

The plugin loading time can time between 30-40 seconds the very first time .

Similar projects

Plugin →