Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

have you tried normal Java I/O

 

read the file with InputStream then check if it matches anything

  • Author

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) ?

  • Author

I'm using IPlayerTracker for that. The problem is when I add that to OnPlayerLogin, nothing happens:

 

new UpdateCheck();

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.