Classes Question

Discussion in 'Plugin Development' started by greaperc4, Sep 14, 2013.

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

    greaperc4

    Hello,

    I am working on a plugin.. and I want it to be organized..
    so I have a class that spawns bosses..
    but how do i get that class.. because it doesn't extends or implements something

    Main Class: Main
    Class name: BossSpawner

    thanks for helping
     
  2. greaperc4
    What do you mean get that class?
     
  3. Offline

    Axe2760

    You can do a few things...

    You can create a new instance of the class
    PHP:
    BossSpawner bs = new BossSpawner();
    bs.spawnHerobrine();
    You can make the method static
    PHP:
    BossSpawner.spawnHerobrine();
     
  4. Offline

    greaperc4

    omg i failed so hard XDDDD.... didnt do the bs for BossSpawner.. thanks for helping :)

    and how to register the BossSpawner class to the Main class?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  5. Offline

    Axe2760

    greaperc4 What do you mean by register? Import?
     
  6. Offline

    greaperc4

    i mean main into BossSpawner class..
     
  7. Offline

    Axe2760

    You mean get an instance of the main class from inside the boss spawner class? You could use a constructor, or just add it as an argument to the method you are using.
     
  8. Offline

    greaperc4

    well actually i got already something like that.. but it gives me an error @
    new BossSpawner();
     
  9. Offline

    Axe2760

    Code?
     
  10. Offline

    greaperc4

    be detailed.. you say code.. but what code.. of which of my 100 classes
     
  11. Offline

    Axe2760

    The code that is giving you the error ?
     
  12. Offline

    greaperc4

    that is what I said.......
     
  13. greaperc4
    Use something like this
    Code:java
    1. public class CLASS {
    2.  
    3. MAINCLASS plugin;
    4.  
    5. public CLASS(MAINCLASS plugin){
    6. this.pluigin = plugin;
    7. }
    8. //do whatever you want here
    9. }
    10.  
     
  14. Offline

    Axe2760

    You cannot give two lines and say that gives you an error. It's more than possible to create that class and have it work errorlessly, and it's possible to create that class and have those two lines throw errors.

    Post your mob spawning class..? as well as code around it. It can easily be caused by a missing bracket in front of the code. If done properly that code doesn't throw errors.
     
  15. Offline

    greaperc4

    Found it.. had to remove the public "Main plugin" in: public BossSpawner(Main plugin);
     
Thread Status:
Not open for further replies.

Share This Page