Solved Sub/Inner methods?

Discussion in 'Plugin Development' started by Awesomedanguy, Aug 25, 2014.

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


    Hello Bukkit!

    I am working on a bukkit plugin, & I was wondering if I could make sub methods like,
    "hi().sayTwice()" or something like that.

    Because I cannot do,

    1. public void hi(Player p){
    2. p.sendMessage("ohai");
    3. public void sayTwice(Player p){
    4. p.sendMessage("ohai.. ohai..")
    5. }
    6. }

    Or like how Bukkit does it, for example. But I know that is with "extends JavaPlugin"

    1. Bukkit.getServer().getConfig();

    Dan :)
  2. Offline


    Sub-methods aren't defined like that. For example, you could make a public void yes(); that returns an instance of a class called No. public No yes(); In the No class, you could have a method called why();. If you had a public No yes(); you could then do:
    1. yes().why();

    Or (even better) learn Java.
    indyetoile likes this.
  3. Offline


    I suggest learning Java...
  4. Offline


    Don't start Bukkit if you've barely started Java
  5. Offline


    Oh wait, SmooshCakez do you mean,

    1. public void yes(){
    2. Bukkit.broadcastMessage("yes");
    3. class no{
    4. private void why(){
    5. Bukkit.broadcastMessage("Cause I can");
    6. }
    7. }
    8. }

    Sorry If I am in correct.. :p

    xTrollxDudex I mean I am not the BEST at java..

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


    Don't make the class inside the void, make it somewhere else. You can't make classes inside voids. Otherwise, yes. Also, change it to public No yes(){} if you want the sub methods.
  7. Offline


    Trying to program bukkit plugins without knowing java is like trying to learn a new language without knowing how to speak/write. Impossible.

    Many people spend 99% of their time they "work" on their plugins by goorgling, copy'n'pasting other ones' code, and asking for help on this forums. Just because they don't know basic java.

    Your sub methods doesn't exist.
    Java is OO (object oriented).
    If you know what classes / objects are, you understand how Bukkit.getServer().xxx() works.

    And no, you can't declare enums/methods/classes in methods.
  8. Offline


    :D SmooshCakez Thanks so much for the help! You da man!

    Zupsub I don't do that... ;-; That's cheap...

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

    ZeusAllMighty11 Retired Staff

    class Message
      String msg;
      public Message(String msg) { this.msg = msg; }
      public void sayTwice(Player p){ p.sendMessage(msg); p.sendMessage(msg); }
    // use with 'new Message("Hello world").sayTwice(player); '
    Something like that would work.. but it'd be silly, no?
  10. Offline


    This is basic stuff, defining methods, should be the second thing you learn after classes and primitives.
  11. Offline


    Yeah xTrollxDudex I know about methods, & that stuff. I didn't know about this though
  12. Offline


    ... Return types? That's questionable. You probably already know it.
Thread Status:
Not open for further replies.

Share This Page