Jump to content

Version checker?


jordsta95

Recommended Posts

Hey there, I had a look at Botania and COFHcore's version checker, and didn't really understand it, but then I found this http://jabelarminecraft.blogspot.co.uk/p/minecraft-forge-1721710-making-mod.html

 

However, I followed that tutorial, and I still can't get it to work. Any ideas why?

 

Here's the code:

 

version checker class:

 

 

package com.aa.mod.updateChecker;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import org.apache.commons.io.IOUtils;

import com.aa.mod.Reference;

public class CheckVersion implements Runnable
{
    private static boolean isLatestVersion = false;
    private static String latestVersion = "";

    @Override
    public void run() 
    {
        InputStream in = null;
        try 
        {
            in = new URL("https://raw.githubusercontent.com/jordsta95/ArcaneArteries/master/aaversion.txt").openStream();
        } 
        catch 
        (MalformedURLException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        try 
        {
            latestVersion = IOUtils.readLines(in).get(0);
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        finally 
        {
            IOUtils.closeQuietly(in);
        }
        System.out.println("Latest version of Arcane Arteries is = "+latestVersion);
        isLatestVersion = Reference.VERSION.equals(latestVersion);
    }
    
    public boolean isLatestVersion()
    {
     return isLatestVersion;
    }
    
    public String getLatestVersion()
    {
     return latestVersion;
    }
}

 

 

 

Here's the client proxy

 

 

package com.aa.mod.proxies;

import net.minecraft.event.ClickEvent;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;

import com.aa.mod.Main;
import com.aa.mod.updateChecker.CheckVersion;
import com.aa.mod.updateChecker.VersionChecker;

import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;


public class ClientProxy extends CommonProxy {

    @EventHandler
    public void Init(FMLInitializationEvent event){

    	

    	Main.versionChecker = new CheckVersion();
    	Thread versionCheckThread = new Thread(Main.versionChecker, "Version Check");
    	versionCheckThread.start();
    	
    	
    	
    }



}

 

 

 

And the 2 lines in the main file are:

public static CheckVersion versionChecker;
public static boolean haveWarnedVersionOutOfDate = false;

 

 

I've never even thought about this before, and I learn most of what I do through tutorials (even if they are outdated, as long as it is similar, I can understand it) but that's the only tutorial I could find on version checkers, and I don't know what I am doing wrong.

 

Thanks

-Jordan

 

 

Why bother?

Link to comment
Share on other sites

Is the Init method in ClientProxy called?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Is the Init method in ClientProxy called?

 

Is that not what the "public static CheckVersion versionChecker;" does?

As I said, I followed the example I linked to the tee, and it never mentioned anything about calling the Init, or anything.

 

I will admit, that tutorial was pretty crap at explaining what everything does and how it works, which is why I came here. Because it doesn't work, and there is no troubleshooting, or reasons why it may not work.

Why bother?

Link to comment
Share on other sites

Hey, I'm the author of the tutorial.

 

I admit it is prorbaly a bit hard to follow because it assumes you're comfortable with Java multi-threading, file I/O, and modding proxy stuff. I'll see if there is a way to link to more info on each topic for those who need it.

 

The first question is: what do you mean it isn't working? Do you mean it never prints anything to the console at all? Or do you mean it doesn't find correct version from your URL? Or do you mean it isn't displaying a chat message?

 

I'm interested actually in larsgerrit's comment. Can you post the rest of how you set up your client proxy? For proxy to work you need to have the @Mod annotation in your main class reference it, and you also need to handle the post-init event in your main class and that should point to the related proxy method. So it would help if you could post that.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Here's the only things I have in the main class that talk about proxies:

@Mod(modid = Reference.MODID, version = Reference.VERSION)
public class Main {

@SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.COMMON_PROXY)
public static CommonProxy proxy;

public static Configuration config;
public static Logger logger;
@Mod.Instance(Reference.MODID)
public static Main instance;

public static CheckVersion versionChecker;
public static boolean haveWarnedVersionOutOfDate = false;

 

As for it not working...

No console message, no message when you log in; not working As for getting the version number, I can only assume it finds that, as that seemed pretty simple.

 

 

And RealMcrafter, I tried it in the Init, not PostInit, just to see if that was the issue. I tried it there, and it didn't work.

Why bother?

Link to comment
Share on other sites

The run() method has a console statement: System.out.println("Latest mod version = "+latestVersion);

 

That should print out no matter whether your version is old or up to date. It may not print out if you get one of the exceptions in that method, but in that case you should also see some console exception output.

 

So if you're really not seeing the "Latest mod version =" console output I think that implies that the run() method isn't being called.

 

I suggest you add additional console statements to trace the execution. I'd add a console statement in the version checking class constructor to prove it is getting constructed, I'd add one in the client proxy method to prove it is getting called.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

The only log stuff I get that contains anything to do with versions and my mod is:

 

 

[17:46:50] [Client thread/TRACE] [arcanearteries/arcanearteries]: Sending event FMLConstructionEvent to mod arcanearteries

[17:46:50] [Client thread/TRACE] [FML/arcanearteries]: Mod arcanearteries is using network checker : Accepting version 3

[17:46:50] [Client thread/TRACE] [FML/arcanearteries]: Testing mod arcanearteries to verify it accepts its own version in a remote connection

[17:46:50] [Client thread/TRACE] [FML/arcanearteries]: The mod arcanearteries accepts its own version (3)

[17:46:50] [Client thread/DEBUG] [FML/arcanearteries]: Attempting to inject @SidedProxy classes into arcanearteries

 

 

 

And that is obviously not it.

 

So, I added:

public void run(){

System.out.println("Client Proxy Loaded");

}

To the client proxy, just as a test. But it doesn't print anything... So I would assume it is that, however, I don't know what it wouldn't get called.

 

As I have the same proxy calling thing as I have seen in dozens of other places:

@SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.COMMON_PROXY)

public static CommonProxy proxy;

with the correct folder structure in Reference for them:

public static final String CLIENT_PROXY = "com.aa.mod.proxies.ClientProxy";

public static final String COMMON_PROXY = "com.aa.mod.proxies.CommonProxy";

 

I have never had to use the client proxy before, so I never knew about this not working. But I don't get why it doesn't work.

Why bother?

Link to comment
Share on other sites

Does your Reference.CLIENT_PROXY point to the right class? Maybe it is accidentally pointing to your common proxy or something.

 

The way the client proxy usually works:

1) You annotate using @SidedProxy to point to path to the class for your client and common proxy. You have that, although you should check that it's referencing the right classes.

2) You instantiate a proxy field using the common proxy. You already did that properly.

3) Your main class handles each FMLInit, FMLPreInit, etc. and calls the method in your proxy (it will decide to call client proxy or common proxy depending on mode the program is running in) that handles those same events.

4) Your client proxy extends common proxy (you did that already) and implements @Override methods for any place the client needs to do something different/additional to client proxy.

 

I think you're close, but for some reason your client proxy isn't going so the thread isn't starting...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

It's probably easier to link the full thing, because it may be something unrelated: https://github.com/ThisIsASuperAwesomeAccount/AMod/tree/master/main/java/com/aa/mod

 

Ignore the fact there's two separate version checker thingies (I was trying to get yours to work, so that I could figure out how to get the other to work -- If that makes sense)

 

Why bother?

Link to comment
Share on other sites

Okay, you're not using the proxies properly. Here's what you need to do.

 

Create methods for the pre-init, init and post-init in the common proxy. So your common proxy should look like this:

 

 

public class CommonProxy {

   

    public void preInit(FMLPreInitializationEvent event){

        //Config

        config = new Configuration(event.getSuggestedConfigurationFile());

        logger = event.getModLog();

        MinecraftForge.EVENT_BUS.register(this);

        ConfigFile.INSTANCE.syncConfig();

    }

   

    public void init(FMLInitializationEvent event){

        //Recipes

        recipeRegist.Register();

    }

   

    public void postInit(FMLPostInitializationEvent event){

        //Thaumcraft Shit

        if(Loader.isModLoaded("Thaumcraft")){

            thaumRegist.Register(event);

        }

    }

}

 

 

Then in your Main class, you should just call the proxy method for each of these events, like this:

 

 

    @EventHandler

    public void preInit(FMLPreInitializationEvent event){

        proxy.preInit(event);

    }

   

    @EventHandler

    public void init(FMLInitializationEvent event){

        proxy.init(event);

    }

   

    @EventHandler

    public void postInit(FMLPostInitializationEvent event){

        proxy.postInit(event);

    }

 

 

 

Then your client proxy should @Override any of these methods where you need to do something additional on client side by calling super method then do anything special for client side, like this:

 

 

public class ClientProxy extends CommonProxy {

   

    @Override

    public void postInit(FMLPostInitializationEvent event){

        super.postInit(event);

    Main.versionChecker = new CheckVersion();

    Thread versionCheckThread = new Thread(Main.versionChecker, "Version Check");

    versionCheckThread.start();

    }

}

 

 

 

Note also that you should only have the @EventHandler annotation on the methods in the Main class. Then those methods simply call the methods in the proxy. Make sense?

 

It is important to get a good understanding of this in order to do effective modding.

 

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Okay, you're not using the proxies properly. Here's what you need to do.

 

Create methods for the pre-init, init and post-init in the common proxy. So your common proxy should look like this:

 

 

public class CommonProxy {

   

    public void preInit(FMLPreInitializationEvent event){

        //Config

        config = new Configuration(event.getSuggestedConfigurationFile());

        logger = event.getModLog();

        MinecraftForge.EVENT_BUS.register(this);

        ConfigFile.INSTANCE.syncConfig();

    }

   

    public void init(FMLInitializationEvent event){

        //Recipes

        recipeRegist.Register();

    }

   

    public void postInit(FMLPostInitializationEvent event){

        //Thaumcraft Shit

        if(Loader.isModLoaded("Thaumcraft")){

            thaumRegist.Register(event);

        }

    }

}

 

 

Then in your Main class, you should just call the proxy method for each of these events, like this:

 

 

    @EventHandler

    public void preInit(FMLPreInitializationEvent event){

        proxy.preInit(event);

    }

   

    @EventHandler

    public void init(FMLInitializationEvent event){

        proxy.init(event);

    }

   

    @EventHandler

    public void postInit(FMLPostInitializationEvent event){

        proxy.postInit(event);

    }

 

 

 

Then your client proxy should @Override any of these methods where you need to do something additional on client side by calling super method then do anything special for client side, like this:

 

 

public class ClientProxy extends CommonProxy {

   

    @Override

    public void postInit(FMLPostInitializationEvent event){

        super.postInit(event);

    Main.versionChecker = new CheckVersion();

    Thread versionCheckThread = new Thread(Main.versionChecker, "Version Check");

    versionCheckThread.start();

    }

}

 

 

 

Note also that you should only have the @EventHandler annotation on the methods in the Main class. Then those methods simply call the methods in the proxy. Make sense?

 

It is important to get a good understanding of this in order to do effective modding.

 

I did as you said here, everything still works as it did before... and that includes the update checker not working... It prints to the Log, but not in game

Why bother?

Link to comment
Share on other sites

So now the log shows it printing out "Latest version is ..."? That is better than before, right? Does it give the right version as listed on your URL that you pointed to?

 

For it printing a message in the game, the problem would be that your PlayerTick event isn't firing any more. That is because the registration of on the event bus refers to "this" but since it is in the CommonProxy it doesn't see the methods with the @SubscribeEvent.

 

So you need to move your @SubscribeEvent methods from your Main class to your CommonProxy.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Alright, so this is in the client proxy:

 

@Override

    public void postInit(FMLPostInitializationEvent event){

        super.postInit(event);

      Main.versionChecker = new CheckVersion();

      Thread versionCheckThread = new Thread(Main.versionChecker, "Version Check");

      versionCheckThread.start();

    }

 

 

    @SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)

public void onEvent(PlayerTickEvent event1)

{

 

    if (!Main.haveWarnedVersionOutOfDate && event1.player.worldObj.isRemote

          && !Main.versionChecker.isLatestVersion())

    {

        ClickEvent versionCheckChatClickEvent = new ClickEvent(ClickEvent.Action.OPEN_URL,

              "http://jabelarminecraft.blogspot.com");

        ChatStyle clickableChatStyle = new ChatStyle().setChatClickEvent(versionCheckChatClickEvent);

        ChatComponentText versionWarningChatComponent =

              new ChatComponentText("Your Magic Beans Mod is not latest version!  Click here to update.");

        versionWarningChatComponent.setChatStyle(clickableChatStyle);

        event1.player.addChatMessage(versionWarningChatComponent);

        Main.haveWarnedVersionOutOfDate = true;

    }

}

 

However, it still doesn't notify (it gets the version number "4" from the URL, and I have the version number set to 3, to test.) So it should notify now, but it doesn't :/

Why bother?

Link to comment
Share on other sites

I think I said to put it in your CommonProxy not your ClientProxy. The point is that when you registered the event handler you referred to "this" so that means you need to have the @SubscribeEvent method in the same class that you register the event handler, which I believe in your case is the CommonProxy.

 

Anyway, the key point is that wherever you register the event handler you need to reference the proper class that contains the event handling method.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

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.