Need help with a plugin

Discussion in 'Plugin Development' started by AdmiralAqua, Nov 30, 2015.

Thread Status:
Not open for further replies.
  1. Hi all. This is my first ever post on the Bukkit forums, so I apologize for any mistakes I may have made. I've been learning Java in classes for a while now, and consider myself pretty good at it. Since I have a love for Minecraft, I tried basic mod development, it worked, and now I am trying plugin development. I do not have the most knowledge when it comes to Java, but I am happy to learn more.

    I need help with a Christmas-themed plugin I need done by the 20th of December. The plugin basically makes it so that you can craft presents, which when broken, drops the items you have added. So in the recipe, if I put a diamond in the middle box in the crafting grid, when broken, it would drop a diamond item. I know how to make recipes, and rename items, I'm just unsure how I would 'save' these items in a variable, and make it so that when broken, it will drop these items. Additionally, I thought it would be cool to make it so that players can rename their presents in an anvil with the name of the player they designated the gift to, and when right-clicked, it tells the name of the player the gift is meant for.

    Also, if anyone knows any good text-based tutorials (I like YouTube tutorials, it's just I usually do coding in a library, and I don't wish to disturb other people), please do suggest some. I'm learning how to make plugins, and I'd love to add more to it.

    EDIT: Forgot to mention, I'm coding for a server running 1.8.7

    I appreciate any help, thanks for reading.
  2. Offline


    @AdmiralAqua So is it only diamonds that can be gifted? What if I put for example a bone in the middle?
  3. Offline



    It's good that you've learned Java beforehand, far too many don't. It's also good that you want text tutorials, as learning from YouTube videos is about the worst way to learn (just behind being in the same room looking away from someone as they program something completely unrelated, but ahead of stealing other people's code and claiming it as your own).

    Bukkit has text tutorials here:

    That link, all the pages it links to, these forums, and the Bukkit Javadocs are all you need. Any other tutorials are a waste of your time (especially ones on YouTube).

    One trick I've seen used to do this is to add invisible text to the lore of an item to store what would be contained in your "present."
  4. Offline


    If one were to learn from a video tutorial, I would recommend Pogostick29Dev (now Pogo), he has actual Java knowledge (and some Java tutorials), and his tutorials are pretty decent (most of them at least). They are a bit outdated but they still work. He is also making a new, more updated series of Bukkit tutorials.
    cococow123 likes this.
  5. Diamonds were just my example. I want it so that ANY item you put in there will be stored and opened later

    Thanks for your suggestion, do you know how I could possibly do this?
    Last edited by a moderator: Nov 30, 2015
  6. Offline


    @AdmiralAqua So you craft a custom place-able block right? Any particular block if so to represent the present?
  7. Yes, right now I think it will be a playerhead with a present skin, but also perhaps a chest
  8. Offline


    Playerheads work pretty well for this, i use them for a christmas event too.
  9. Oh, cool. How would I create an item for them though? Could you share some of your code?
  10. Offline


    Im not at home and dont have any code right here, but i try to explain how it should work. First create an ItemStack with skull_item as material, and get the ItemMeta. This you can cast to an SkullMeta where you can change the owner of the skull. That should be enough ;)
    AdmiralAqua likes this.
  11. OK, I'll try to do that. Thanks for your help :)

    This might be a dumb question, does anyone know how to use dyes? I'm trying to add cactus green to my recipe, what I have so far is
                 craftpresent.setIngredient('%', Material.INK_SACK);
    I don't know how to continue, as the wiki makes no mention of it (as far I as I have found). The things I've Googled up aren't exactly helpful either.

    Also, any suggestions on how to store an item for the present? EG, I craft the present and put a diamond sword in the middle of the crafting recipe. When the present is broken, it drops a diamond sword. However, if someone else crafts the present with redstone in the middle, the present they place drops redstone instead.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited: Dec 1, 2015
    Lordloss likes this.
  12. Offline


    Since you're a new developer, you might not have this link:
    This contains all of the classes and method for 1.8 bukkit. Whenever you don't know what to use for a specific task, or how to go about something, look it up there.

    I looked down the list till I reached "Shaped Recipe" (in the bottom left hand corner) and found this:
    setIngredient(char key, Material ingredient, int raw)
    Magic value
    Raw refers to the Raw Data (Which you can use for Dye meta). Just repalce "raw" with "DyeColor.[YOUR COLOUR]"
    BTW: it looks like you're going to have a problem with DRY (Don't Repeat Yourself). What you have is fine, but a better way to go about this (although you will need some knowledge in Java) would be the following.
    • Use Hashmaps to store the Material as the keys, and if they should have any "raw data"(Boolean) as the value (Learn how to use Hashmaps here)
    • When your plugin first starts up, add all the values to the hashmap.
    • After that, Iterate through all the keys and use the keys and use those for the recipes. If the recipe requires all the "raw" types, such as dyes,( the boolean would be true) you would loop through all dye values (0 to 15). If you would not need to do that (Boolean is false), then you would just have it go through once with a value of 0 (E.G. .setIngredient('%', IteratedObject, the raw values); )
    Again, you will need some knowledge in Java in order to do this.
    AdmiralAqua likes this.
  13. @Zombie_Striker Thanks so much for your help!

    I have a problem now though. When I try entering this code
    craftpresent.setIngredient('%', Material.INK_SACK, 1 DyeColor.GREEN);
    It doesn't work. It gives me a 'syntax error, delete token 'DyeColor.GREEN'.
    EDIT: Fixed now, thanks for the help
    Last edited: Dec 2, 2015
Thread Status:
Not open for further replies.

Share This Page