[Tutorial] Creating Methods

Discussion in 'Plugin Development' started by ko47374737, Jun 27, 2014.

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

    ko47374737

    Hope you enjoy :D
    Code:java
    1.  
    2. */
    3. // Ok so im creating the method, it will contain Player , Enchantment and int for level
    4. public void enchantItem(Player p, Enchantment enchantment, int level)
    5. {
    6. // So now get the players item in hand then add Enchantment which is enchantmant and the Level is the int level
    7. p.getItemInHand().addEnchantment(enchantment, level);
    8. }
    9. /*
    10.   * Ok so thats our first basic method now how to use it.
    11.   */
    12. @Override
    13. public boolean onCommand(CommandSender sender, Command command,
    14. String label, String[] args) {
    15. Player p = (Player) sender;
    16. Noob n = new Noob();
    17. if(label.equalsIgnoreCase("enchantme")){
    18. n.enchantItem(p, Enchantment.ARROW_FIRE, 2);
    19. }
    20. return false;
    21. }
    22. /*Ok so thats done now lets go to a more advanced method
    23.   *
    24.   */
    25. public void setConfigString(String path, String string){
    26. getConfig().set(path, string);
    27. }
    28. // Ok so thats obvious how you use that ^
    29. public ItemStack createItem(Material material, int amount, short shrt,
    30. String displayname, String lore) {
    31. ItemStack item = new ItemStack(material, amount, (short) shrt);
    32. ItemMeta meta = item.getItemMeta();
    33. meta.setDisplayName(displayname);
    34. ArrayList<String> Lore = new ArrayList<String>();
    35. Lore.add(lore);
    36. meta.setLore(Lore);
    37. item.setItemMeta(meta);
    38. return item;
    39.  
    40. }
    41. // How to use this you ask? Well ill show you
    42. static Inventory poo;
    43. {
    44.  
    45. poo= Bukkit.createInventory(null, 9, "§0§nTokenShop");
    46.  
    47. poo.setItem(
    48. 0,
    49. createItem(Material.BONE, 1, (short) 0 , "Super bone", "5 tokens"));
    50. poo.setItem(1,
    51. createItem(Material.SEEDS, 5, (short) 0 , "Magical seeds", "10 tokens"));
    52. }
    53. // The first part for the method is the material, then ammount, then the short, then name and finaly the lore
    54.  
    55.  
    56. }
    57.  
    58. *
     
  2. Offline

    Bloxcraft

    I'm not sure what this is but I'm positive it doesn't belong here.
     
  3. Offline

    xTrollxDudex

    ko47374737
    1. That file isn't complete
    2. Ad.fly not allowed... Read ToS...
    3. Wat
     
    Skyost likes this.
  4. Offline

    ZodiacTheories

  5. Offline

    ko47374737

    How do I close it because it didn't put all the code I wanted!
     
  6. Offline

    ZodiacTheories

  7. Offline

    ko47374737

    Edited post hopefully you enjoy it
     
  8. Offline

    DevRosemberg

  9. So you're "explaining" one of the absolute basics of any programming language. Why? I don't mean to be cruel at all, but it is highly unlikely this will be of any use for developers. Now, you might say that there are some people on here that could find this useful, but to be honest, those people shouldn't be working with the API in the first place without knowing the basics of Java.
     
    mazentheamazin likes this.
  10. Offline

    Skyost

  11. Offline

    EgyptianKing

    You should probably teach people what methods actually are, what those parameters mean, how to call methods, and OOP in general.

    But thanks for posting
     
  12. Offline

    Not2EXceL

    What the actual eff is this?
    Code:java
    1.  
    2. static Inventory poo;
    3. {
    4.  
    5. poo= Bukkit.createInventory(null, 9, "§0§nTokenShop");
    6.  
    7. poo.setItem(
    8. 0,
    9. createItem(Material.BONE, 1, (short) 0 , "Super bone", "5 tokens"));
    10. poo.setItem(1,
    11. createItem(Material.SEEDS, 5, (short) 0 , "Magical seeds", "10 tokens"));
    12. }
    13.  
     
    Sabersamus likes this.
  13. Offline

    ko47374737

    Not2EXceL Sorry Lol its my inventory name xD
    Skyost I don't get what the eff that is that's not what I want.... Im not that nooby
    The Gaming Grunts I understand but that was an example I just please do you know how?
     
  14. Offline

    Not2EXceL

    That's not what I was saying at all. That statement isn't even a statement.
     
  15. Offline

    ko47374737

    That doesn't make sense That "statement" is not a "statement" how is a statement not a statement

    Anyway not that it matters! really I don't need help for that I need help for the thing I requested!

    Look in my [HELP] Creating methods please

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

    Skye

    You missed a line for the "enchantme" command:
    Code:java
    1. n.setName("ko47374737");

    Maybe you could break the methods down and explain what they do and how they work?
     
Thread Status:
Not open for further replies.

Share This Page