Super Duper Easy Question

Discussion in 'Plugin Development' started by ShredNyx, Dec 5, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ShredNyx

    What method do I add to have one class work with another? Implement (Classname)?
    Like class called main works with class funny
     
  2. ShredNyx
    You can do something like this:

    Code:java
    1. public class SomeClass{
    2.  
    3. SomeOtherClass p;
    4.  
    5. public SomeClass(SomeOtherClass instance){
    6. p = instance;
    7. }
    8.  
    9. //use p.SOMETHING to get a reference to methods in the other class
    10. }
    11.  
    12.  
     
  3. Offline

    kreashenz

    You mean a constructor or something? I use this in my classes for static reasons
    Code:java
    1. private static Main clazz;
    2.  
    3. public void onEnable(){
    4. clazz = this;
    5. // other stuff
    6. }
    7.  
    8. public static Main getInstance(){
    9. return clazz;
    10. }


    and if you don't want to do that use constructors
    Code:java
    1.  
    2. private Main plugin;
    3.  
    4. public Funny(Main plugin){
    5. this.plugin = plugin;
    6. }


    [EDIT] Ninja'd above.
     
  4. Offline

    ShredNyx

    kreashenz so i can apply everything into from funny to main?
     
  5. Offline

    kreashenz

  6. Offline

    ShredNyx

    Mkay kreashenz wuts the diff between constructors and no constructors
     
  7. Offline

    kreashenz

    ShredNyx Well.. Depends, you might not need a constructor because you're not calling anything in it. Having no constructor for this may lead to NullPointerExceptions. If you used the first code I gave you, there's no need to use a constructor as you can just use
    Code:java
    1. private Main plugin = Main.getInstance();
     
  8. Offline

    1Rogue

    Wingzzz and Garris0n like this.
Thread Status:
Not open for further replies.

Share This Page