[Newb] Creating a simple Method/Api

Discussion in 'Plugin Development' started by ChipDev, Jul 22, 2014.

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

    ChipDev

    Hey guys today I'm showing you how to create a simple method!
    This method will be 'tntTroll'
    Thanks for the idea, joeygallegos
    What this does is:
    Set a tnt block above the player to blow up.
    For those who have not created a method before, Its very simple!
    (Actually, you treat it as if it was already a method.)
    Code:java
    1. public void TNTtroll(Player player, int ticks, boolean message) {
    2. }
    3.  

    This is the main function, You will be able to use it in the end!
    Player player = (player can be changed to anything in the function/method! That was just for the main base of the function. You could call it 'player' here, and others can call it 'p', or 'event.getPlayer()'!) - The player that will be used.
    int ticks = (Don't put ticks when you use the method easily, use a int (Number)) - The ticks that the TNT will have until it goes Boom! (Tick = 1/20 of a second, ticks * seconds = Ticks = seconds)
    boolean message - (Don't put 'Message' when you use the method easily, use true or false!) - Little message I added just for fun, Put false if you don't want it!
    Code:java
    1. public void TNTtroll(Player player, int ticks, boolean message) {
    2. Entity tnt = (TNTPrimed) player.getWorld().spawn(player.getLocation().add(0,2,0), TNTPrimed.class);
    3. player.setPassenger(tnt);
    4. tnt.setFuseTicks(ticks);
    5. if(message == true) {
    6. player.sendMessage(ChatColor.RED + "You got Trolled!");
    7. }
    8. }

    setPassenger - The used item will stack onto player.
    setFuseTicks - Fuse of the PrimedTnt before it blows Up.
    If(message == true) - If perimeter 3 = 'True'

    EXAMPLE USAGE:
    Code:java
    1. TNTtroll(target, 20 * 5, true);


    Trolls 'Target', Fuse is 5 seconds, and it sends the message.

    Thanks for reading! Hopefully this helped.
    This is a full example! :D
     
  2. Offline

    xTigerRebornx

    ChipDev This shouldn't be considered a resource.
    - It won't even compile, you've forgotten a " and I doubt the type Int would be recognized (capital I)
    - Naming conventions
    - Use of Boolean rather then primitive boolean
    - You made a tutorial for creating a method. If someone's knowledge of Java is limited enough to the extend that they need a tutorial on creating a method, they shouldn't be trying to work with a 3rd party API without properly learning Java.
    - '== true' is redundant, it generally looks bad, and can simply be changed into if(boolean) rather then if(boolean == true).

    I'm sure others will find things other then this.
    The effort of helping others is appreciate it, but you should at least make sure your code works and will actually help rather then hinder people (teaching bad habits)

    Edit: Can't tell if this was originally posted in resources, or was intended as a resource, but the above is feedback for if it was considered a resource. If it wasn't, take them as pointers and make sure your code is in a state that actually compiles.
     
  3. Offline

    ChipDev

    Oops, wrote this too fast, edited.
     
  4. Offline

    RawCode

    you really should read what is API before trying to write "tutorial" about it.
     
  5. ChipDev
    xTigerRebornx already stated everything I was going to say, but I also want to point out that your naming conventions are off. Methods are written in camelcase.
     
  6. Offline

    ChipDev

    RawCode , Just stating as an API for others who may type it in. That is why i put [Newb] in front.
    @TheGamingGrunts - Example, Knew that was off. But java doesn't say 'You must write this in camelcase!', So it was for this example. Just always bringing in the hate.
     
  7. Offline

    DannyDog

    ChipDev if you're going to teach newbs how to name their methods.
    You should do it properly.
    Or it won't be a very good tutorial...
     
  8. Offline

    ChipDev

    mbaxter
    Remove this and the tut. post please, I guess people don't like it.
     
  9. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    ChipDev Please report posts for rule infractions, don't tag staff for requests. Also, we don't remove posts on request if they don't break the rules.
     
  10. Offline

    DannyDog

    ChipDev Just edit it and fix it up a bit.
     
    Skyost likes this.
  11. Offline

    AoH_Ruthless

    ChipDev
    • Your tutorial covers aspects of an API, while the intention of this tutorial is one that teaches Java. This only serves to confuse the user. When making a Java tutorial, never incorporate aspects of an unendorsed API. That being said, this is so basic, anyone who doesn't know how to make a method shouldn't be on these forums.
    • When explaining the "message == true" part, that is bad practice. You don't need the primitive check. Also, it's parameter, not perimeter. Learn Java terminology yourself before trying to pass on your supposed knowledge to others.
    • The above bullet also applies to your parameter types. 'Int' and 'Boolean' should be lowercase. I don't think Java will recognize 'Int', but it will recognize Integer. However, use lowercase int and boolean.
    • A tutorial on creating a method should cover the identifiers you use. You should cover the use of public, private, protected, and the default none (package-private). You should also cover the return type (void, boolean, int, etc...). This would also be decent if you cover concurrency and multi-threading (with the use of synchronized and volatile), and if you cover abstractness. This tutorial is also bad because your method is public. A method should always be private unless you need it in another class design.
    • Follow method naming conventions (lower camel case). This has already been stated by others, but to have a complete analysis of your 'resource', I had to include it.
    While I and many other people on these forums appreciate that you tried to make a resource to help people (and we aren't trying to tell you to get the hell out of here or bring you down), it would be good if you realize the mistakes and bounce back and improve your resources. Resources need to be of help to many people, and on these forums, preferably a Bukkit related topic (not always the case). It's great that you tried, but you need to work on your teaching-skills.
     
    Skyost, ZodiacTheories and Traks like this.
  12. Offline

    Dragonphase

    I think he understands now.
     
    AoH_Ruthless likes this.
  13. Offline

    ChipDev

    Ok. Ill just start working now :D
     
  14. Offline

    Skyost

    Show Spoiler

    [​IMG]

     
    stormneo7 and ZodiacTheories like this.
  15. Offline

    Konkz

    Can we have a 'How to create a Getter and Setter' tutorial?
     
  16. Offline

    ChipDev

    Bro, Those are evil.
     
  17. Offline

    DannyDog

    I have a feeling you read the same article i did a few minutes ago.
    hue
     
    ChipDev likes this.
  18. Offline

    ChipDev

    Last edited by a moderator: Jun 9, 2016
  19. Offline

    AoH_Ruthless

    ChipDev
    I frankly don't agree with that statement. In getters and setters, you can
    • Perform validation
    • Change the set value
    • You don't have to change multiple files in the plugin to set a new value
    • Hide internals being shown
    • You can use Reflection and Serialization
    • Variety of access levels
    • Lazy loading
    • Insulation of Public interface
    • A lot more things I bet.
    That whole page tries to claim that getter and setter methods aren't object oriented programming for several reasons, but I disagree (I only really read most of the first page ... didn't want to read 3 whole pages of it). There are indeed times where you don't need getters and setters, and I don't approve of creating them just for the sake of creating them, but they offer lots of amazing features.
     
  20. Offline

    DannyDog

  21. Offline

    ChipDev

    It was a joke.
     
  22. Offline

    AoH_Ruthless

    ChipDev
    Sorry, my mind reading ability was disabled at the time. -.-
     
    Skyost likes this.
  23. Offline

    Konkz

    When can we catch the reading ability enabled? :3
     
  24. Offline

    ChipDev

    I read that.
    I also knew what you were thinking.
    You were thinking about mind reading
    or reading :3

    How could something in java be evil..?
    Also: You didn't have mind reading enabled?
    [​IMG]

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

    AoH_Ruthless

    ChipDev
    Evil is what you make of something, but only exists inside of us. Something cannot actually be evil, ever; but we can feel something as evil. It is possible that you feel getters and setters are evil, as that blog writer did.

    On a side note, the mind reading ability comment was sarcasm.
     
  26. Offline

    joeygallegos

    Well that escalated quickly..
     
  27. Offline

    macboinc

  28. Offline

    ChipDev

    This post has gotten WAY out of hand :p
    Keep it on topic now please.
     
Thread Status:
Not open for further replies.

Share This Page