net.minecraftforge.common.ForgeVersion Java Examples

The following examples show how to use net.minecraftforge.common.ForgeVersion. 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: ObfMapping.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static File confDirectoryGuess(int i, ConfigTag tag) {
    File mcDir = (File) FMLInjectionData.data()[6];
    switch (i) {
        case 0:
            return tag.value != null ? new File(tag.getValue()) : null;
        case 1:
            return new File(mcDir, "../conf");
        case 2:
            return new File(mcDir, "../build/unpacked/conf");
        case 3:
            return new File(System.getProperty("user.home"), ".gradle/caches/minecraft/net/minecraftforge/forge/"+
                FMLInjectionData.data()[4]+"-"+ ForgeVersion.getVersion()+"/unpacked/conf");
        default:
            JFileChooser fc = new JFileChooser(mcDir);
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fc.setDialogTitle("Select an mcp conf dir for the deobfuscator.");
            int ret = fc.showDialog(null, "Select");
            return ret == JFileChooser.APPROVE_OPTION ? fc.getSelectedFile() : null;
    }
}
 
Example #2
Source File: StringReplacer.java    From Custom-Main-Menu with MIT License 5 votes vote down vote up
public static String replacePlaceholders(String source)
{
	int tModCount = Loader.instance().getModList().size();
	int aModCount = Loader.instance().getActiveModList().size();
	Calendar calendar = Calendar.getInstance();

	String clock = timeFormat.format(calendar.getTime());

	DateFormat formatter = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault());

	String date = formatter.format(new Date());

	return source.replace("#date#", date).replace("#time#", clock).replace("#mcversion#", mcversion).replace("#fmlversion#", Loader.instance().getFMLVersionString()).replace("#mcpversion#", mcpversion).replace("#modsloaded#", tModCount + "").replace("#modsactive#", aModCount + "").replace("#forgeversion#", ForgeVersion.getVersion()).replace("#username#", Minecraft.getMinecraft().getSession().getUsername());
}
 
Example #3
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 #4
Source File: ForgeVersionCheck.java    From LunatriusCore with MIT License 5 votes vote down vote up
public static void notify(final ModContainer container, final ForgeVersion.Status status, final ComparableVersion target, final Map<ComparableVersion, String> changes, final String url) {
    try {
        final Map<ModContainer, ForgeVersion.CheckResult> versionMap = getVersionMap();
        final ForgeVersion.CheckResult checkResult = getCheckResult(status, target, changes, url);

        if (versionMap != null && checkResult != null) {
            versionMap.put(container, checkResult);
        }
    } catch (final Throwable t) {
        Reference.logger.error("Failed to notify Forge!", t);
    }
}
 
Example #5
Source File: ForgeVersionCheck.java    From LunatriusCore with MIT License 5 votes vote down vote up
@SuppressWarnings({ "unchecked" })
private static Map<ModContainer, ForgeVersion.CheckResult> getVersionMap() throws ReflectiveOperationException {
    try {
        final Field field = ForgeVersion.class.getDeclaredField("results");
        field.setAccessible(true);
        return (Map<ModContainer, ForgeVersion.CheckResult>) field.get(null);
    } catch (final Throwable t) {
        Reference.logger.error("Failed to get the version map!", t);
    }

    return null;
}
 
Example #6
Source File: ForgeVersionCheck.java    From LunatriusCore with MIT License 5 votes vote down vote up
private static ForgeVersion.CheckResult getCheckResult(final ForgeVersion.Status status, final ComparableVersion target, final Map<ComparableVersion, String> changes, final String url) throws ReflectiveOperationException {
    try {
        final Constructor<?> constructor = ForgeVersion.CheckResult.class.getDeclaredConstructor(ForgeVersion.Status.class, ComparableVersion.class, Map.class, String.class);
        constructor.setAccessible(true);
        return (ForgeVersion.CheckResult) constructor.newInstance(status, target, changes, url);
    } catch (final Throwable t) {
        Reference.logger.error("Failed to construct the CheckResult object!", t);
    }

    return null;
}
 
Example #7
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);
        }
    }
}
 
Example #8
Source File: VersionCommand.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender)) return true;

    if (args.length == 0) {
        sender.sendMessage("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " with Forge version " + ForgeVersion.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")");
        sendVersion(sender);
    } else {
        StringBuilder name = new StringBuilder();

        for (String arg : args) {
            if (name.length() > 0) {
                name.append(' ');
            }

            name.append(arg);
        }

        String pluginName = name.toString();
        Plugin exactPlugin = Bukkit.getPluginManager().getPlugin(pluginName);
        if (exactPlugin != null) {
            describeToSender(exactPlugin, sender);
            return true;
        }

        boolean found = false;
        pluginName = pluginName.toLowerCase(java.util.Locale.ENGLISH);
        for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
            if (plugin.getName().toLowerCase(java.util.Locale.ENGLISH).contains(pluginName)) {
                describeToSender(plugin, sender);
                found = true;
            }
        }

        if (!found) {
            sender.sendMessage("This server is not running any plugin by that name.");
            sender.sendMessage("Use /plugins to get a list of plugins.");
        }
    }
    return true;
}