Plugin Development - A HUGE tutorial!

Discussion in 'Plugin Development' started by Adamki11s, Apr 29, 2011.

?

Was this helpful to you?

  1. Yes!

    78.4%
  2. No, but it was a good tutorial :)

    16.1%
  3. No.

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

    DrBowe

    Would greatly appreciate it. :)
     
  2. Offline

    kuzi117

    I'm with you. That's exactly what I need.
    And personally, @Admaki11s, I think Github's set up' tutorial thing is amazing. It tells you how to do all of it. You really should just supply the link to their help section. Which I ould find if you need it, though I'm sure you can.
     
  3. Yeah their help is really good but some people don't know how to set their environment variables which I'll explain.
     
  4. Offline

    kuzi117

    Totally up to you man, you're doing a great job. Just consider that more indepth thing if you get the time. Thanks :)
     
  5. Offline

    DrBowe

    I dont suppose you could add a more indepth section solely for the Bukkit Scheduler, could you? I tried looking through your Zombie source to learn how it works, but to no avail. :(
     
  6. I will soon, I'm not in the mood to write a tutorial now, maybe tomorrow or over the weekend :D
     
  7. Offline

    DrBowe

    No problem, take your time. Its not necessary, I only need it (currently) to add a more 'immserive' feel to my Compass plug-in. For example, when it starts scanning and displays a 'Scanning for Mobs/Players...', it'd be nice to make it wait 5 seconds before returning the results :)
     
  8. Offline

    SpikeMeister

    I just spent about three hours cleaning up the wiki page. I'm new to wikis so I hope I didn't fuck up somehow:
    • Got rid of the useless whitespace
    • Put things into paragraphs
    • Added a few more headings for clarity
    • Put code in the middle of text into <code> brackets
    • Fixed the indentation and of the code examples (there were quite a few missing closing braces as well)
    • Fixed up the grammar in most places (not all sections, noticably hashmaps)
    OCD
     
  9. Offline

    PatrickFreed

    looks good :p
     
  10. Offline

    Lolmewn

    Can you maybe add how to handle Inventories? I'm having huge trouble using them.
     
  11. Offline

    SpikeMeister

    I think another good section to add would be deployment - how to make a .jar and get it working with CraftBukkit etc
     
  12. I've already covered exporting.
    I'm going to put aside a few hours of my time today and write up some more stuff ;)
     
  13. Offline

    Lolmewn

    Hooray!
     
  14. Offline

    HolyRane

    Any ideas why it won't let me import things from the jar when I hover over code? Like 50% of the time I can import things from bukkit but sometimes I can't... :(
     
  15. Offline

    icomeinpieces

    This tutorial is awesome, a feature request though is perhaps a section on YAML configuration would be great.
     
  16. Offline

    HolyRane

    This tut needs to more in depth of where to put things haha I don't know where to put half the code
     
  17. Yeah, I want to do some more write ups, I might do loads while I'm away on holiday :p
    This tutorial assumes a basic knowledge of Java.
     
  18. Offline

    icomeinpieces

    That would be great, but don't forget to enjoy your holidays some as well lol.

    also I think Holy Rane meant that he might not know where to put bukkit specific code like the event registrations or the on(something)Events. just my guess though, that was my issue at first when learning (till i found your guide at any rate :D).
     
  19. Offline

    DrBowe

    I'm not sure if I'm understanding your question right or not, but if you're reffering to where you put the majority of your 'custom' coding (aka, what actually makes the plugin do something), then I tend to find that it depends solely on the type of plugin you're writing.

    For example, if your plugin is heavily command-based, and really has no internal listening for events, most of your code (if not all) will be in the <plugin>.jar

    However, if you want a plugin that runs more internally, and requires less command usage, most of your code will be lodged in a <plugin>PlayerListener(or BlockListener, etc).java

    It all depends on what you're trying to make.
     
  20. Offline

    killgoblen

    Hey, I am trying to make a plugin on B860. I followed your tutorial and ended up with:

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(cmd.getName().equalsIgnoreCase("tpblock")){
                if(args[1].equalsIgnoreCase("set")){
                    if(args[2].equalsIgnoreCase("main")){
                        if(tping.setMain(args[3], sender)){
                            return true;
                        }else{
                            return false;
                        }
                    }else if(args[2].equalsIgnoreCase("dest")){
                        if(tping.setDest(args[3], args[4])){
                            return true;
                        }else{return false;}
                    }else{return false;}
                }else{return false;}
            }
    But when I do the command /tpblock set main blah (or just /tpblock) I get an unknown command and a message in the console:
    Code:
    [SEVERE] Nag author: '<NoAuthorGiven>' of 'TeleportBlocks' about the following: onPlayerCommandPreprocess has been replaced with a new signature, (PlayerCommandPreprocessEvent)
    
    So what am I doing wrong?

    BTW, thanks for the tutorial, it has been extremely helpful!
     
  21. Offline

    icomeinpieces

    do you have a plugin.yml file? it needs to be in the source folder along side your plugin package.
    here is mine from my plugin to help you along:
    plugin.yml (open)

    name: UndroppableDroppables
    main: com.icomeinpieces.UndroppableDroppables.UndroppableDroppables
    version: 1.16
    description: makes most things that don't drop something like bookcases well drop something like a bookcase
    author: icomeinpieces
    commands:
    udreload:
    description: reloads the configuration file
    usage: /<command>

    make sure you use 4 spaces and not tabs <-- very important, won't work otherwise.

    hope that helps
     
  22. Offline

    killgoblen

    I realized that a little bit ago and felt stupid.

    But after fixing that, it has almost the same problem. I'm still getting the nag, and no matter what I do, it gives me the usage thing as if the method returned false. The method does not return false anywhere under any circumstances, though. (Replaced all return false; with return true)
     
  23. Offline

    icomeinpieces

    can you post the whole error and the onCommand method you have in your main java class?
     
  24. Offline

    killgoblen

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(cmd.getName().equalsIgnoreCase("tpblocks")){
                return true;
            }else{return true;}
        }
    That is what I am using just to test it.

    Code:
    [SEVERE] Nag author: '<NoAuthorGiven>' of 'TeleportBlocks' about the following: onPlayerCommandPreprocess has been replaced with a new signature, (PlayerCommandPreprocessEvent)
    
    That is the only error.

    When I type "/tpblocks" in-game it tells me the 'usage' info in the plugin.yml. From what I understand, that is only supposed to happen if the onCommand returns false.

    I registered the onCommand in the main class with
    Code:
    pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.Normal, this);
    Is that what's wrong?

    Thanks for any help.

    EDIT: For the record, I also tried this as my onCommand method with the same result:
    Code:
    public boolean onCommand(PlayerCommandPreprocessEvent event){
            String[] cmd = event.toString().split(" ");
            if(cmd[0].equalsIgnoreCase("tpblocks")){
                event.getPlayer().sendMessage("Hurray!");
                return true;
            }
            return false;
        }
     
  25. Offline

    SpikeMeister

    There's the problem. You don't need to register to listen for command events, your onCommand method is called automatically whenever a command is given.
     
  26. Offline

    icomeinpieces

    well to things i did different in my plugins.
    i didn't register any events with the plugin manager, just had the onCommand method, so stop using PLAYER_COMMAND_PREPROCESS or anything like that just have the onCommand method in your main java file.
    the second thing i did was i used the String commandLabel for figuring out what command was given not the command cmd. sure if that makes a difference though i just went with what worked for me at the time.

    I had to write this out pretty quickly before going away from my computer, so i may have missed something.
     
  27. Offline

    killgoblen

    Thanks for the help. I got it working finally! It's not the prettiest code ever, but it works.

    EDIT: So now I have a problem. I'm trying to save a HashMap containing Locations to a flatfile, but I keep getting this error:

    java.io.NotSerializableException: org.bukkit.Location

    So how could I save locations to a flatfile?
     
  28. Offline

    icomeinpieces

    I would like to help you with that but I haven't the need (yet) for HashMaps so I have no experience with them.
     
  29. Can you guys start a different thread where you can discuss your problems. I appreciate that your'e having difficulty but this posts in this thread should really on be for feedback, appreciation or suggestions.
     
  30. Offline

    icomeinpieces

    ah yes, sorry bout that.
     
Thread Status:
Not open for further replies.

Share This Page