Jump to content

Recommended Posts

Posted

Hello,

I'm trying to make a small Update Check for my mod. I already have a .txt File on my Server, but now i don't know how to check the lines with Forge and then check it with my mod_version. I only want to do that, when the player joins in the world. The Function for that I already have, because I've there some other steps.

 

Could somebody help me?

Posted

I created a class named UpdateCheck:

 

package test.misc;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Map;

import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;

public class UpdateCheck {

private final String updateURL = "MyURL";

private class UpdateCheckThread extends Thread
    {
        @Override
        public void run()
        {            
            try
            {
                
                Map<String, ModContainer> modMap = Loader.instance().getIndexedModList();
                ModContainer Mod;
                
                URL versionDataFile = new URL(updateURL);
                BufferedReader reader = new BufferedReader(new InputStreamReader(versionDataFile.openStream()));
                String curLine;
                while ((curLine = reader.readLine()) != null)
                {
                    String[] tokens = curLine.split("=");
                    if ((Mod = modMap.get(tokens[0].trim())) != null)
                    {
                        if (!isModUpToDate(Mod.getVersion(), tokens[1].trim()))
                        {
                        	FMLClientHandler.instance().getClient().ingameGUI.getChatGUI().printChatMessage("A newer version of Test is available: "+tokens[1].trim()+", get it at test.net");
                        }
                    }
                    else if (tokens[0].trim().equals("mc"))
                    {
                        if (!Loader.instance().getMCVersionString().equals(tokens[1].trim()))
                        {
                            System.out.println("According to website, current mcversion is: "+tokens[1].trim());
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.err.println("Error while checking for updates:");
                e.printStackTrace();
            }
        }

        private boolean isModUpToDate(String localVersion, String webVersion)
        {
            boolean newer = false;

            for (int i = 0; i < Math.min(localVersion.length(), webVersion.length()); i++)
            {
                int comparedchar = webVersion.substring(i, i + 1).compareTo(localVersion.substring(i, i + 1));
                
                if (comparedchar < 0)
                    newer = true;
                
                if (!newer && comparedchar > 0)
                    return false;
            }

            if (webVersion.length() > localVersion.length() && !newer)
                return false;

            return true;
        }
    }
}

 

How can I initialize it when the player joins at OnPlayerLogin(EntityPlayer player) ?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.