multiple classes

Discussion in 'Plugin Development' started by letmedl, Apr 20, 2014.

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

    letmedl

    Hello, Im wondering how you could use scoreboards and multiple classes for example be able to access this in one class
    publicstaticvoid test(){
    ScoreboardManager sbManager = Bukkit.getScoreboardManager();
    Scoreboard sBoard = sbManager.getNewScoreboard();
    final Team red = sBoard.registerNewTeam("red");
    final Team blue = sBoard.registerNewTeam("blue");
    int reds = red.getSize();
    int blues = blue.getSize();
    int Bothteams = red.getSize() + blue.getSize();

    int bothteams = reds + blues;

    and access those ints and teams in another.
     
  2. Offline

    TheMcScavenger

    If it's static, just use:
    Code:
    classname.methodname();
    If it's not static, use:
    Code:
    classname name = new classname();
    name.methodname();
     
  3. Offline

    coasterman10

    Avoid static variables if you don't have a specific and good reason to use it. Automatically making anything static will quickly lead you down the path to unmaintainable code.

    That being said, you can create them as public instance variables, and then pass class 1 to your other class, and have the other class access them that way. You can also use getter and setter methods which are arguably the most failsafe way to share data.

    This is still highly dependent on what the classes are supposed to do. Usually, a class should handle its own as much as it can and share as little with other classes as possible, otherwise you end up with global variables which are almost always a bad idea.

    What are the functions of the multiple classes? If we knew why you're sharing data between them we could give you much better guidance in building a good object structure.
     
    PogoStick29 likes this.
  4. Offline

    Not2EXceL

    You should never give examples without following Java's code conventions
     
  5. Offline

    TheMcScavenger

    Considering the code he presented didn't show much knowledge of the subject, I figured I might as well put as much effort into the answer as he most likely put into his question.
     
  6. Offline

    Not2EXceL

    Valid point XD
     
  7. Offline

    samus1221

    My suggestion is to watch tutorials on youtube on java, learn the syntax, learn how to "code" in a sense.
     
  8. Offline

    Wizehh

    Yes, I recommend watching 'TheBCBroz'; I've heard that they're much loved and respected by the Bukkit community.
     
    samus1221 likes this.
  9. Offline

    mazentheamazin

    Wizehh
    Actually, you're incorrect, many experience developers recommended NOT to watch TheBCBroz as they teach outdated methods.
     
  10. Offline

    Onlineids

    You mispelled PogoStick29
    and mazentheamazin the reason I and i think others don't watch them is because the obvious bad conventions and two he is always lazy and trying to rush videos
     
  11. Offline

    PogoStick29

    I have heard the same thing, but I've never watched any of their videos. Don't judge unless you can confirm ;). I'd hate it if people insulted my videos unless they told me what I did wrong so I could improve them.
     
    Wizehh likes this.
  12. Offline

    Onlineids

    He doesn't show what the plugin does or explain any of it because he's always in a damn rush, also he doesn't upload frequently he started a year before you and your only like 10 vids away.
     
  13. Offline

    PogoStick29

    Fair enough.
     
  14. Offline

    Onlineids

    i luv u
     
  15. Offline

    PogoStick29

    Ok then.
     
  16. Offline

    Wizehh

    Well, I was being sarcastic ;)
     
    PogoStick29 likes this.
Thread Status:
Not open for further replies.

Share This Page