Solved Grabbing methods from other classes? Help!

Discussion in 'Plugin Development' started by xYourFreindx, Jun 8, 2014.

Thread Status:
Not open for further replies.
  1. So, I'm trying to announce to admins that there is a new update, when they join.

    The only way I've found to do this is to make my update class implement Listener and registerit in my onEnable.
    I'd rather not make a class just for one event and be able to use the onPlayerJoin in my main listener class.
    I'm not sure, however, how to grab the methods from the Updater class while in my Listener class.

    Yes, I'm new to java. And this seems like something very simple and basic that I'm not getting, and I'd REALLY like to know how. So...
    Any help you can give me would be greatly appreciated. ​
     
  2. Offline

    Gater12

    xYourFreindx
    Make your updater object > invoke methods.
     
  3. Gater12
    ...
    :(
    I hate to ask.....
    But is there any further explanation you can give me?
    Like... How I am to do this, and why?
    I know why, like.... To make use of my updater... But obviously that reason will change throughout the programs I make, and I cannot hope to be able to use it if I do not yet understand it.
     
  4. Offline

    AoH_Ruthless

    Learn Java. That's the best advice we could ever hope to give you.
     
  5. Offline

    Gater12

    xYourFreindx [Not going to in depth about Objects, classes, and methods. You should have already understand that]

    Alrighty, Updater is a class. It has methods. When you make a new Updater object, it creates it, and you get access to these methods.

    Code:java
    1. Updater updater = new Updater(params);
    2.  
    3. updater.getResult();
    4.  
    5. /* etc. */
     
  6. Gater12 I was instructed by the updater tutorial to put that in my onEnable, would it be bad practice to use in in my onEnable and to also make an instance of the class at the top of my main?
     
  7. Offline

    AoH_Ruthless

    xYourFreindx
    Only make one instance of the Updater class. Yes, it would be better to have a globalized variable that creates the new instance for you, then call it in your onEnable(). Personally I don't like having a cluttered onEnable() and I make a new method (which is called in the onEnable()) but it's up to you.

    I can't really tell you if it's bad practice because I don't really quite understand what you are saying (therefore I can't visualize it).

    Since you're new to Java, if you don't understand something that someone says, it's generally because it's a java term that you don't know. You aren't an idiot, so we aren't going to change our vocabulary. You're smart, if you are motivated to understand what we say then you should Google anything you don't understand.
     
    xYourFreindx likes this.
  8. AoH_Ruthless Gater12 I've tried this, but the way the updater works, is that you define whether or not you want the updater to update or not in those params, and I have to make it flexible so that the server owner can decide whether or not they want it to automatically update, in the provided config.
    Code:java
    1.  
    2. if (getConfig().getBoolean("CameraMode.AutoUpdate") == true){
    3. Updater updater = new Updater(this, 80542, getFile(), Updater.UpdateType.DEFAULT, true);
    4. }else{
    5. Updater updater = new Updater(this, 80542, getFile(), Updater.UpdateType.NO_DOWNLOAD, true);
    6.  

    So I use this in my on enable, (and register the Updater class as a listener)
    How would I make updater object available for use without making the UpdateType a static value?
     
  9. Offline

    AoH_Ruthless

    xYourFreindx
    Code:
    Updater updater;
     
    if (boolean)
        updater = new Updater(...);
    else
        updater = new Updater(...);
    By the way, that will be denied on BukkitDev because player might not want to receive any notifications at ALL.
     
    xYourFreindx likes this.
  10. Offline

    teej107

    xYourFreindx
    Parameters in constructors and methods. For example:
    Code:java
    1. public class BigClass
    2. {
    3. public BigClass()
    4. {
    5. new SmallerClass(this);
    6. }
    7. }

    Code:java
    1. public class SmallerClass
    2. {
    3. public SmallerClass(BigClass bigClass)
    4. {
    5. //You now have access to the public methods and variables in BigClass.
    6. }
    7. {
     
    xYourFreindx likes this.
  11. AoH_Ruthless Thanks so much! Exactly what I was looking for.
     
Thread Status:
Not open for further replies.

Share This Page