Tutorial Beginner's tips for Bukkit

Discussion in 'Resources' started by BaconStripzMan, Sep 29, 2015.

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

    BaconStripzMan

    Hello,

    I find it really annoying when people post their problems with useless/wrong code or don't read their problems, so here's a Beginner's tips for Bukkit guide!

    1.
    TheBCBroz: When learning Bukkit for the first time don't watch the youtube channel, TheBCBroz. It's got so many things wrong with it I can't begin to tell you..

    2.
    Bukkit before Java: When learning Bukkit for the first time, learn Java first. It makes everything so much easier and you won't be posting about problems or solving them yourself so much. You can also make better plugins with this experience.

    3.
    Minecraft's logger: You shouldn't steal Minecraft's logger (public static final Logger logger = Logger.getLogger("Minecraft");) Use getLogger().whatever;

    4.
    Enable/Disable message: You don't need plugin enable/disable messages. Bukkit already does this for you.

    5.
    Read the log: When you get errors on your plugins and they don't work, read the log and try and solve it yourself first. It's so much easier. If you still can't get it then post...
    http://bukkit.org/threads/how-to-re...ubleshoot-your-own-plugins-by-yourself.32457/

    6. Advertising: Don't advertise your "Custom Coded" servers on other servers/in forums (unless there's a specific set section). Use websites made for advertising servers instead.

    7. Casting player to sender: When using the line Player p = (Player) sender; make sure you check if the sender is a player first

    Code:
    if(sender instanceof Player) {
                Player p = (Player) sender;
                // do stuff
    }
    8. Do not abuse unnecessary statics, it is VERY bad programming practice with OOP.

    9. When posting for help once your done with help add a solved tag for the thread, if you need help on something completely different make a new thread!

    10. Don't save[​IMG] lists, configs or hashmaps using player name, use the player UUID instead. If you haven't noticed people can change their names but their UUID (UniqueID) Doesn't change.

    11. Don't use unnecessary player casting eg.

    Code:
    if(sender instanceof Player) {
        Player p = (Player) sender;
        p.sendMessage("There are " + Bukkit.getOnlinePlayers().size + " online!");
    }
    You can use sender.sendMessage("") as well...

    12. .equals/==. When checking for things, use the correct thing. It will show no error if you get it wrong but it will not work! Use .equals for Object checks and == for primitives and null checks!



    Thank you for reading, I hope you learnt something new from this guide!

    If you have any suggestions just reply below with your suggestion and I'll add it!

    Thanks for contributions:
    BaconStripsMan
    ChipDev
    FabeGabeMC
    Tecno_Wizard
    FisheyLP
    bwfcwalshy
    teej107
     
    Last edited: Oct 4, 2015
    jyhsu, FabeGabeMC and ChipDev like this.
  2. Offline

    ChipDev

    Also, don't post
    JOIN MY MC SERVER ITS BEST JOJN ANOANO IH PEH IZ LOCALHOST
     
    mcnultyb and BaconStripzMan like this.
  3. Offline

    BaconStripzMan

    Added 6. Advertising @ChipDev and 7. Casting sender to player
     
  4. Offline

    ChipDev

    Hehe. I just looked at your profile picture and had to post that.
     
  5. Offline

    BaconStripzMan

    haha
     
  6. Offline

    teej107

    So this resource is basically most, if not everything that is in the stickies and wiki?
     
  7. Offline

    FabeGabeMC

    @BaconStripzMan
    8. If you are going to ask for help in the forums, mark your thread as 'solved' when the issue has been fixed.
    9. NEVER EVER call a method inside the same method unless it is NECESSARY.
    Example:
    Code:java
    1. public void randomVoidIWillNotCareAboutJoinMyServerPlsIFna() {
    2. randomVoidIWillNotCareAboutJoinMyServerPlsIFna();
    3. }

    10. Don't abuse static. It's a really ambiguous thing to do.
     
  8. Offline

    Tecno_Wizard

  9. Offline

    FisheyLP

    What about unnecessary casting to Player like in this example:
    Code:
    if (!(sender instanceof Player)) return false; //sending message would be better but I'm lazy in this example :P
    Player p = (Player sender);
    p.sendMessage("there are x online players");
    Most people either
    • directly cast to Player without checking
    • or just cast to Player even if it's not necessary (when only sending messages for example).
    And a very rare thing that I only used 1 time in a plugin is: Adding support for BlockCommandSender for locations & area management instead of just the Player
     
  10. Offline

    BaconStripzMan

    Nobody seems to read them. It just gets annoying, so I hoped this would get noticed.
    I'll add them now :)
    Already added the player casting

    @Tecno_Wizard Wizard thanks for the link! Will add now

    Wait, I see what you mean. Yeah I'll add it.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 29, 2015
  11. Offline

    Tecno_Wizard

    @BaconStripzMan, I disagree with this in it's current form. There is nothing wrong with calling a method in a method, but having a method that it's only function is to call another I disagree with. There are privacy exceptions to this such as
    Object#clone(), probably the the only thing this does not apply to.

    Unnecessary statics don't slow things down to my knowledge, but they are a VERY bad programming practice with OOP.

    EDIT: For 3, add in the preferred way.
     
  12. Offline

    Lolmewn Retired Staff

    Agreed fully. Heck, it may even be a case of recursion.
    This, too, is correct. It doesn't slow things down, but is extremely bad for OOP practices. Do note that Singletons are usually okay (It's a design pattern, folks!), but obviously don't over-do it.
     
    bwfcwalshy likes this.
  13. Offline

    FabeGabeMC

    LOL!
     
  14. Offline

    BaconStripzMan

    Alright will fix now
     
  15. Offline

    bwfcwalshy Retired Staff

    @BaconStripzMan Maybe add when to use == and .equals() a lot of people use them wrong
     
    BaconStripzMan likes this.
  16. Offline

    blok601

    Pogostick29dev has pretty good tuts. He understands java so he uses that knowledge for bukkit.
     
    BaconStripzMan likes this.
  17. Offline

    teej107

    Now that's a Java problem rather than a Bukkit one :p
     
  18. Offline

    Tecno_Wizard

    @teej107, agreed. It amazes me how so many people mess this up. To me it just proves one thing: the person doesn't know intermediate Java. I wouldn't call it beginner Java because it can get a bit confusing.
     
  19. Offline

    teej107

    I would call it beginner because for beginners you only need to know one thing. == for primitives and null checks. #equals() for Objects. There is more too it, but 99.9% of the time, that is all you need to know.
     
    BaconStripzMan likes this.
  20. Offline

    BaconStripzMan

    Added!
     
  21. Offline

    Cirno

    Remember to close I/O streams you open (OutputStreams and InputStreams)
    Don't use Java 8 features or compile for Java 8 just yet; Java 7 is still wildly used (iirc)
     
  22. Offline

    bwfcwalshy Retired Staff

    @BaconStripzMan Maybe add "Don't leave unused/useless code", I have seen a few times were people have methods and variables unused.
     
  23. Offline

    FabeGabeMC

    Unless it's part of an API. :p
    Also, rather than using a Thread and while loop instead of a BukkitRunnable, that's why it exists, after all.
    [​IMG]
     
  24. Offline

    mcdorli

    Maybe a "Create a variable reference for classes, you going to use a lot." or a "Don't create variables of classes, if you going to use them only once." would be nice.
     
  25. Offline

    FisheyLP

    Thats more a general java problem
     
  26. Offline

    mcdorli

    the 8. and 12. are that too.
     
  27. Offline

    Lordloss

    Remember to register your Events :)
     
    FabeGabeMC likes this.
  28. Offline

    mythbusterma

    It's a design anti-pattern.


    Ah you see, but he actually doesn't.
    In general, you should use Java 8, as we really need to push for the new adoption, but there are quite a few (misguided) hosts who still use 7.
     
  29. Offline

    FisheyLP

    Just a question: Does it work to run Java 7 compiled plugins on a server with Java 8? Because the other way around it doesn't work
     
  30. Offline

    FabeGabeMC

    I've already tested it and surely enough, it works ^^
     
Thread Status:
Not open for further replies.

Share This Page