Creating a big plugin with many classes like essentials

Discussion in 'Plugin Development' started by Lightspeed, Apr 1, 2015.

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

    Lightspeed

    If you look at most big plugins they use supers.
    How can I do somthing like these plugins so I don't have to do stuff like
    Code:
    Class c = new Class(this);
     
  2. Offline

    nverdier

    @Lightspeed Well you can't do that for everything, you only do that when a class extends another.
     
  3. Offline

    Lightspeed

    Last edited by a moderator: Apr 1, 2015
  4. Offline

    nverdier

  5. Offline

    Lightspeed

    Can you help me understand how this works and what exactly it's doing
     
  6. Offline

    Gamecube762

    @Lightspeed
    Here is a small example
    Code:
    public class Animal {
       private final String noise;
    
       protected Animal(String noise) {
          this.noise = noise;
       }
    
       public void makeNoise() {
          System.out.println(noise);
       }
    }
    
    public class Cat extends Animal {//Cat extends Animal
        public Cat() {
           super("Meow");//call the original constructor with this value
        }
    }
    
    public class Pig extends Animal {
        public Pig() {
           super("Oink");
        }
    }
    Search around on Google, there is a lot about Super.
     
  7. Offline

    Lightspeed

  8. Offline

    Zombie_Striker

    Unless you want to make methods that will react the same between classes, there is no use in doing this.
     
  9. Offline

    Lightspeed

    SO i look through there code trying to understand how everthing works and I see this . . .
    Code:
    package net.ess3.api;
    
    
    public interface IWarps extends com.earth2me.essentials.api.IWarps
    {
    
    }
    
    What is this? It looks like it does nothing.
     
  10. @Lightspeed You should learn Java if you haven't already. If you learned Java, you would know what all this stuff is and what it does. ;)
     
  11. Offline

    Europia79

    https://github.com/essentials/Essen.../com/earth2me/essentials/EconomyTest.java#L26

    Code:java
    1.  
    2. public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials
    3. {
    4. public Essentials(final Server server)
    5. {
    6. super(new JavaPluginLoader(server), new PluginDescriptionFile("Essentials", "", "com.earth2me.essentials.Essentials"), null, null);
    7. }


    I'm pretty sure they have this for testing purposes. But to understand this: just realize that super() is passing information to the parent class. In this case, it's passing dependencies to JavaPlugin.

    Generally, you need to worry about super() at all... Just be aware that anytime you extend a class, you might need to supply that Parent Class with information via super()... (so that its fields can get initialized).

    It's really that simple: Is the Parent Class requesting dependencies ? If so, call super(). If not, don't worry about it.

    Here's another example:
    https://github.com/Europia79/Demolition/tree/master/src/main/java/mc/euro/demolition/arenas

    There are 3 classes: Two child classes SndArena & BombArena that are VERY SIMILAR. All of the shared code is in the parent class: EodArena.

    I started with only BombArena, which is a Sabotage rule-set. Then lots of people requested Search N Destroy rule-set. I added SndArena. Then I noticed a lot of duplication of code (which is bad), so I refactored the duplicated code into a parent class that they could share (EodArena).

    As far as creating a big plugin or application, i think a lot of developers use UML for this ?
     
  12. Offline

    Derpiee

  13. Offline

    1Rogue

    super is just a keyword for referring to the parent instance (just like using "this", but it's the parent class(es) you're extending from). When you see a subclass call super(...) in the constructor it's initalizing the parent class first before continuing its own creation.

    https://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
    https://docs.oracle.com/javase/tutorial/java/IandI/super.html
     
    dlange likes this.
  14. Offline

    nverdier

    @Lightspeed It doesn't make any sense to use this everywhere... Why do you want do so badly?
     
  15. Offline

    Lightspeed

    @nverdier Most errors I get need to access many classes for different things hubloc, vanished? and a few secret things to make it so I can catch hackers without staff hehe
     
  16. Offline

    nverdier

    @Lightspeed But why do you want to use supers everywhere?
     
  17. Offline

    mythbusterma

    @Lightspeed

    I don't see how "secret" things require you to utilise a language construct that is not at all applicable to your use case is helping.
     
    nverdier likes this.
  18. Offline

    Lightspeed

    @mythbusterma No no supers wont help these "secret" things. . .
    @nverdier It will make it so I can access things easier. Example
    Class Hub can get the location of hub CommandsPkg:HubCommand to create if it dosent exist or teleport.
    MiniGamesPkgOrsomthing: when the game is over they get tped to hub. Don't hate I like my code organized. :p
    EDIT: and yes i said the classes in the wrong order.
     
  19. Offline

    nverdier

    @Lightspeed That doesn't make it organized... I suggest you learn what they are used for and only use it when applicable.
     
  20. Offline

    1Rogue

    Inheritence is not a substitute nor tool for project structure.
     
    Europia79 likes this.
  21. Offline

    Lightspeed

    I'm not good at explaining . . . as you can see

    @nverdier Ok got it can you just explain to me why there are supers for eveything in essentials plugin every class exept for interfaces or barley any regular classes don't have super

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

    mythbusterma

    @Lightspeed

    Because they have a structure that all dependant classes inherit from the same type because that makes sense to them.
     
  23. Offline

    Lightspeed

    ragequit I will solve this latur solved for now[cake] to you for all yoru replies and some liquid cheese[lava] enjoy
     
  24. Offline

    nverdier

    Mhmmm... Well then.
     
  25. Offline

    MCMatters

  26. Offline

    Lightspeed

    Ok I understand everything exept for: In the essentials plugin there are multiple command with a super("nameofcmd") and that the name of the cmd is it getting the name? super?
     
  27. Offline

    1Rogue

    That's just passing the string "nameofcmd" to the parent class constructor, which most likely uses it to register the command.
     
  28. Offline

    Lightspeed

    ik but where in the class does it take that and make it the cmd I can't find it
     
  29. Offline

    1Rogue

     
    Lightspeed and nverdier like this.
  30. Offline

    Lightspeed

    Sorry I didn't see that i read too fast XD

    @1Rogue The question I ment to ask instead of the one before was How are all the command classes loaded/initialized?


    {{Posts merged by Myrathi}}
     
    Last edited by a moderator: Apr 4, 2015
Thread Status:
Not open for further replies.

Share This Page