Posted July 31, 201312 yr 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?
July 31, 201312 yr have you tried normal Java I/O read the file with InputStream then check if it matches anything
August 1, 201312 yr 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) ?
August 1, 201312 yr 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.