Java Code Examples for net.minecraftforge.fml.common.versioning.ComparableVersion#compareTo()

The following examples show how to use net.minecraftforge.fml.common.versioning.ComparableVersion#compareTo() . 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: ForgeVersionCheck.java    From LunatriusCore with MIT License 5 votes vote down vote up
public static ForgeVersion.Status getStatus(final ComparableVersion versionRemote, final ComparableVersion versionLocal) {
    final int diff = versionRemote.compareTo(versionLocal);

    if (diff == 0) {
        return ForgeVersion.Status.UP_TO_DATE;
    }

    if (diff > 0) {
        return ForgeVersion.Status.OUTDATED;
    }

    return ForgeVersion.Status.AHEAD;
}
 
Example 2
Source File: Updater.java    From SkyblockAddons with MIT License 4 votes vote down vote up
/**
 * Processes the update checker result from the Forge Update Checker and sets the correct message to be displayed.
 */
public void processUpdateCheckResult() {
    SkyblockAddons main = SkyblockAddons.getInstance();

    ComparableVersion current = new ComparableVersion(SkyblockAddons.VERSION);
    boolean isCurrentBeta = SkyblockAddons.VERSION.contains("b");
    ComparableVersion latest = new ComparableVersion(isCurrentBeta ? main.getOnlineData().getLatestBeta() : main.getOnlineData().getLatestVersion());
    main.getLogger().info("Checking to see if an update is available. Current version is "+current.toString()+". Latest version is "+latest.toString());

    ForgeVersion.Status status;
    int versionDifference = latest.compareTo(current);
    if (versionDifference == 0) {
        status = UP_TO_DATE;
    } else if (versionDifference < 0) {
        status = AHEAD;
    } else {
        status = OUTDATED;
    }

    if (status == ForgeVersion.Status.OUTDATED) {
        hasUpdate = true;

        String currentVersion = current.toString();
        String latestVersion = latest.toString();

        main.getLogger().info("Found an update: "+latestVersion);

        try {
            Matcher currentMatcher = VERSION_PATTERN.matcher(currentVersion);
            Matcher latestMatcher = VERSION_PATTERN.matcher(latestVersion);

            // Its a patch if the major & minor numbers are the same & the player isn't upgrading out of a beta.
            if (currentMatcher.matches() && latestMatcher.matches() &&
                    currentMatcher.group("major").equals(latestMatcher.group("major")) &&
                    currentMatcher.group("minor").equals(latestMatcher.group("minor")) &&
                    !(currentVersion.contains("beta") && !latestVersion.contains("beta"))) {
                isPatch = true;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            main.getLogger().warn("Couldn't parse update version numbers... This shouldn't affect too much.");
        }

        if (isPatch) {
            messageToRender = Message.UPDATE_MESSAGE_PATCH.getMessage(latestVersion);
        } else {
            messageToRender = Message.UPDATE_MESSAGE_MAJOR.getMessage(latestVersion);
        }
    }
}