My First Plugin Any Advice?

Discussion in 'Plugin Development' started by Gust09, Aug 14, 2014.

Thread Status:
Not open for further replies.
  1. Hi!

    I'm Gust09, from Portugal, and i'm new here... I'm also new at programming.

    I started to learn java a week or two ago, and i decided to put my knowledge in action by creating my first plugin... Well, this isn't really the first, but the others were really useless :p

    I made it for my Prison Server, so people earn a little bonus after mining X number of certain types of blocks... I'm very limited right now so i got to keep learning java and the bukkit api.

    At the config i can configure up to 16 blocks, i don't know (yet) how to make those configs that you add stuff and the plugin use it... (Sorry for my english, if you don't understand what i'm trying to say tell xD)
    And the reward item it's not configurable yet... The String at the config is configuable but i cant use "&2" codes.

    As you can see, im very noob :p
    I DON'T want spoon feed. I want to learn, not copy... Cant learn using CTRL + C / CTRL + V.

    If you got any advices for me they will be very appreciated! :D

    Here is my Plugin for you to test it if you like : http://plussycraft.net/files/plugins/BreakBonus.jar
    Here is my main : http://pastebin.com/0MPmZWtx

    -- EDIT(S)--
    Thanks to the awesome feedback i was able to learn a bit more and improve my code! Thank you all!
    Main Edit-1 - http://pastebin.com/mmq3Fqsk
    --
    New stuff :D
    Color Code Support
    Multiple "Bonus Found" Strings, configurable at the config... (printed randomly)
    Configurable Reward Item, with name and lore (also with colors o/)
    Main Edit-2 - http://pastebin.com/47UCcnMc
    Jar file - Download
    --
    Rewrote the whole plugin. New Features:
    Different rewards, objective and "BonusFound" string for each type of block.
    Main Edit-3 - http://pastebin.com/ykSC4uSM
    Jar file - Download
    --
    The permissions are:
    To get the rewards - breakbonus.reward
    To reload the config (/bbreload) - breakbonus.reload
     
    Totom3 likes this.
  2. Offline

    teej107

    Not too bad coming from a new developer. I've seen some scary things from new developers. From the things that I noticed:
    Code:java
    1. int blockId1 = getConfig().getInt("Config.BLOCK1");
    2. int blockId2 = getConfig().getInt("Config.BLOCK2");
    3. int blockId3 = getConfig().getInt("Config.BLOCK3");
    4. int blockId4 = getConfig().getInt("Config.BLOCK4");
    5. int blockId5 = getConfig().getInt("Config.BLOCK5");
    6. int blockId6 = getConfig().getInt("Config.BLOCK6");
    7. int blockId7 = getConfig().getInt("Config.BLOCK7");
    8. int blockId8 = getConfig().getInt("Config.BLOCK8");
    9. int blockId9 = getConfig().getInt("Config.BLOCK9");
    10. int blockId10 = getConfig().getInt("Config.BLOCK10");
    11. int blockId11 = getConfig().getInt("Config.BLOCK11");
    12. int blockId12 = getConfig().getInt("Config.BLOCK12");
    13. int blockId13 = getConfig().getInt("Config.BLOCK13");
    14. int blockId14 = getConfig().getInt("Config.BLOCK14");
    15. int blockId15 = getConfig().getInt("Config.BLOCK15");
    16. int blockId16 = getConfig().getInt("Config.BLOCK16");

    And this here as well.
    Code:java
    1. if((blockBroken == (blockId1)) || (blockBroken == (blockId2)) || (blockBroken == (blockId3)) || (blockBroken == (blockId4))
    2. || (blockBroken == (blockId5)) || (blockBroken == (blockId6)) || (blockBroken == (blockId7)) || (blockBroken == (blockId8))
    3. || (blockBroken == (blockId9)) || (blockBroken == (blockId10)) || (blockBroken == (blockId11)) || (blockBroken == (blockId12))
    4. || (blockBroken == (blockId13)) || (blockBroken == (blockId14)) || (blockBroken == (blockId15)) || (blockBroken == (blockId16)))
     
    Windy Day and AlexHH251997 like this.
  3. Awesome! I'm already taking notes! I'll try to improve that :D
     
  4. Nice, not bad for the first plugin! [cake]
     
  5. Offline

    MCMastery

    Gust09 Use a list of the block ids that can be broken so the plugin is not limited.
    config.yml example:
    Code:
    blocks:
      - 1
      - 2
      - 3
    This would allow stone, grass, and dirt.
    To get a list from a config, and check the block:
    Code:java
    1. List<String> blockIDStrings = getConfig().getStringList("blocks");
    2. // if the block broken is in the block id list
    3. if (blockIDStrings.contains(String.valueOf(blockBroken) {
    4. // your code here...
    5. }


    This replaces this piece of code:
    Code:java
    1. int blockId1 = getConfig().getInt("Config.BLOCK1");
    2. int blockId2 = getConfig().getInt("Config.BLOCK2");
    3. int blockId3 = getConfig().getInt("Config.BLOCK3");
    4. int blockId4 = getConfig().getInt("Config.BLOCK4");
    5. int blockId5 = getConfig().getInt("Config.BLOCK5");
    6. int blockId6 = getConfig().getInt("Config.BLOCK6");
    7. int blockId7 = getConfig().getInt("Config.BLOCK7");
    8. int blockId8 = getConfig().getInt("Config.BLOCK8");
    9. int blockId9 = getConfig().getInt("Config.BLOCK9");
    10. int blockId10 = getConfig().getInt("Config.BLOCK10");
    11. int blockId11 = getConfig().getInt("Config.BLOCK11");
    12. int blockId12 = getConfig().getInt("Config.BLOCK12");
    13. int blockId13 = getConfig().getInt("Config.BLOCK13");
    14. int blockId14 = getConfig().getInt("Config.BLOCK14");
    15. int blockId15 = getConfig().getInt("Config.BLOCK15");
    16. int blockId16 = getConfig().getInt("Config.BLOCK16");

    AND it replaces this:
    Code:java
    1. if((blockBroken == (blockId1)) || (blockBroken == (blockId2)) || (blockBroken == (blockId3)) || (blockBroken == (blockId4))
    2. || (blockBroken == (blockId5)) || (blockBroken == (blockId6)) || (blockBroken == (blockId7)) || (blockBroken == (blockId8))
    3. || (blockBroken == (blockId9)) || (blockBroken == (blockId10)) || (blockBroken == (blockId11)) || (blockBroken == (blockId12))
    4. || (blockBroken == (blockId13)) || (blockBroken == (blockId14)) || (blockBroken == (blockId15)) || (blockBroken == (blockId16))){
     
    coasterman10 and AlexHH251997 like this.
  6. Offline

    _Cookie_

    In your main class instead of,
    Logger myLogger = Bukkit.getLogger();
    public final Logger logger = Logger.getLogger("Minecraft);
     
  7. Offline

    LordVakar

    _Cookie_
    Go home and think about what you have posted.
     
  8. Offline

    Funergy

    OFF TOPIC: you forgot a quote :p
    sorry for that I'm a really detailed guy...
    public final Logger logger = Logger.getLogger("Minecraft");
     
  9. Offline

    Skionz

    Gust09 Way better then my first plugin. My first plugin let you execute a command and it would give you a potion... and I uploaded it to bukkit haha.
     
  10. I posted the improved main at the main post. I really appreciate the help and im motivated to continue :cool:


    Whats the difference between one and another?
     
  11. Offline

    Funergy

    My first plugin was for a Prison server when you do /block
    it gets all the ore and makes it to a block
    bv 18 diamonds = 2 blocks
    19 diamonds = 2 blocks and 1 diamond
    :eek:
    PS: I watched a lot of tutorials at the beginning for creating a command and stuff, Shoutout to PogoStick29 and TheBCBroz
     
    PogoStick29 likes this.
  12. Skionz Nice to "hear" that ! :D
    I will upload it to bukkit when it's finished, im using this project to practice my coding, but i want it to be usefull for someone.
     
  13. Offline

    Skionz

    Funergy One of my later plugins was similar to that except it smelted ores... and it didn't work... and i uploaded it to bukkit v_v
     
  14. Offline

    Funergy

    a plugin that secretly crashes you're server xD
     
  15. Offline

    Skionz

    Funergy I can't believe they accepted all of my awful plugins, I was really bad then but I took comp sci in highschool and got better.
     
  16. Offline

    Funergy

    I'm not even learning this in school. and I'm already that far.
    Currently I'm learning for Graphics like Photoshop and stuff for 2 years and after that I learn making websites with php Html5,...
     
    Skionz likes this.
  17. Offline

    Skionz

    Funergy I used to love HTML and all that, then nobody used my websites because i sucked at advertising
     
  18. Offline

    Funergy

    :p
    PS: and ty for follow I'll follow you back
     
    Skionz likes this.
  19. Offline

    ZanderMan9

    Gust09 The String at the config is configuable but i cant use "&2" codes.
    To use those, get the string. Then set a new string as the output of...
    ChatColor.translateAlternateColorCodes('character you want to activate color codes, like &', FirstString)
    That will effectively add a ChatColor.(code) everywhere there is that character and then a valid code.

    And on the subject of first plugins...
    Mine was ChatInsert. Effectively it allowed you to insert something directly into the chat, unlike /say, which has the tag. I added sending the message to only one player and coloring it. I still use it to fool people by typing
    [Member] Name: Stupid message
    xD It actually came out of a want to be able to send messages without a tag in front of them.

    EDIT: And then I discovered Batch lol. Since then it's been the Bukkit Tools section for me.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  20. ZanderMan9 Thank you for your feedback. I'll take a look into that! :D
     
  21. Offline

    teej107

  22. Offline

    FabeGabeMC

    Gust09
    If you are going to use ChatColor codes (&6 = gold, &b = aqua, &k = wobbly letters, etc)...
    You can use the translateAlternateColorCodes(char, String); method from the ChatColor class.
    for example:

    Code:java
    1. String myPrefix = "&6&l[&bMy &3Awesome &cPlugin&6&l]&r";
    2.  
    3.  
    4.  
    5. public void send() {
    6.  
    7. Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', myPrefix) + "The plugin works!");
    8.  
    9. }


    P.S. Links will bring you to the Documentation and usage for each class.
     
  23. Offline

    MineStein

    PogoStick29 makes tutorials that are up to date. He still makes tutorials on an (almost) daily basis.
     
    PogoStick29 likes this.
  24. Offline

    LordVakar

    Gust09
    Do not ever do:
    public final Logger logger = Logger.getLogger("Minecraft");
    It is unsupported and craftbukkit calls it. Use the bukkit api.
     
  25. Offline

    EnderTroll68

    LordVakar
    Half of your statement is true. It IS much better to do Bukkit.getLogger() rather than Logger.getLogger("Minecraft"), but using Craftbukkit instead of the Bukkit API is not always better, as if he ever wants to work with NMS or custom mobs way down the road, he will already be in the habit of using the API rather than CraftBukkit.

    Personally, I recommend downloading the version that is for use in servers and using that as your basis for coding.
     
  26. So... I'm confused. Which one should i use? Both works for now :p
     
  27. Offline

    teej107

    Gust09 Build against CraftBukkit if you are going to use NMS. If you don't know what NMS is, just build with Bukkit.
     
  28. Offline

    Necrodoom

    Gust09 do not use the minecraft logger, use the plugin logger, as LordVakar said.
     
  29. Offline

    Funergy

    I know I always use that Bukkit.getLogger().Info("poop");
    but its just if he wanted to do that way he forgot the "

    Hes a really good Youtuber

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

    AoH_Ruthless

    EnderTroll68
    On a technical level, you should not be using NMS at all because it goes against API and is not endorsed by Bukkit team. For this reason, on a "good practice" terms, you shouldn't be using NMS, which is the same level of basis we are discussing the logger alternatives.
     
Thread Status:
Not open for further replies.

Share This Page