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

    Jayjay110

    in.close(); is underlined red for me, help plox lol
     
  2. Either your file input stream variable is not 'in' or hasn't been set or maybe your not using a try catch. Post your code and exactly where your getting errors and what your IDE says.
     
  3. Offline

    Jayjay110

    Code:
    package com.servegame.n1p.Drawbridge;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    import java.util.logging.Logger;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Drawbridge extends JavaPlugin {
    
        Logger log = Logger.getLogger("Minecraft");
    
        static String mainDirectory = "plugins/Drawbridge";
        static File DrawbridgeFile = new File(mainDirectory + File.separator + "Drawbridge.dat");
        static Properties prop = new Properties();
    
        boolean drawbCreation;
    
        private final DrawbridgePlayerListener playerListener = new DrawbridgePlayerListener(this);
        private final DrawbridgeBlockListener blockListener = new DrawbridgeBlockListener(this);
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(commandLabel.equalsIgnoreCase("drawbrige create")){
    
                drawbCreation = true;
    
                return true;
            }else{
        return false;
            }
        }
    
        public void onEnable(){
    
            new File(mainDirectory).mkdir();
    
            if(!DrawbridgeFile.exists()){
                try {
                    DrawbridgeFile.createNewFile();
                    FileOutputStream out = new FileOutputStream(DrawbridgeFile);
                    prop.put("Version", "1");
                    prop.store(out, "Do NOT edit this config!");
                    out.flush();
                    out.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            } else {
                loadProcedure();
            }
    
            PluginManager pm = this.getServer().getPluginManager();
    
            pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this);
            pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Event.Priority.Normal, this);
    
            log.info(this.getDescription().getName() + " Version " + this.getDescription().getVersion() + "has been enabled.");
    
        }
    
        public void loadProcedure(){
            FileInputStream in = new FileInputStream(DrawbridgeFile);
                prop.load(in);
                }
     in.close(); //im getting the error here, its just one
    
    
        public void onDisable(){
    
            log.info(this.getDescription().getName() + " Version " + this.getDescription().getVersion() + "has been disabled.");
    
        }
    
    }
    thanks for the fast reply ;)

    Im getting the error at only the line that says, in.close();

    This is the error the ide says: Syntax error on token "close", VariableDeclarator expected after this token

    p.s: im using eclipse :)

    (the only commented line)

     
  4. Offline

    SpikeMeister

    Thanks, I've spent the whole evening trying to get started and it's amazing how hard it was to find any up to date information on a starting template. There are so many threads with out of date information and plugin generator tools that are deprecated. This really should go toward replacing this wiki page: http://wiki.bukkit.org/Programming_A_Plugin (probably would make more sense under a different URL though).

    One note, the line:
    should read:
     
  5. Offline

    Acrobot

    @Jayjay110
    You forgot to move the "}"

    You have
    Code:
    public void loadProcedure(){
            FileInputStream in = new FileInputStream(DrawbridgeFile);
                prop.load(in);
                }
     in.close(); //im getting the error here, its just one
    
    when it should be
    Code:
    
    public void loadProcedure(){
            FileInputStream in = new FileInputStream(DrawbridgeFile);
                prop.load(in);
     in.close();
    }
    
     
  6. Offline

    Jonni

    Oh you missunderstood me :p
    I wanted to sort them, because i want to have an easy way to modify the variables by hand in the file.
    And for that it would be nice to have them sorted ;)
     
  7. Offline

    Jayjay110

    T
    THANKYOU :) I also needed the try/catch thing to :3 lol
     
  8. Offline

    Ancetras

    Can you make a tutorial on how to place blocks or interact with them?
     
  9. Maybe consider creating a yml config file instead.

    I'm working on lots of thing at the moment, I'll add that to the list :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 14, 2016
  10. Offline

    Jonni

    If i knew how i would try it.
    I have to find a tutorial for that first.
     
  11. I'll try to make one soon, in between everything else :p
     
  12. Offline

    Unscrewed

    @Plague
    Plague, the Bukkit wiki is completely outdated and this is perfect material for it.
    Could you add this to the Bukkit wiki with Adamki11s permission?
    :D
     
  13. Offline

    Plague

    Bukkit wiki is independent from this forum in terms of users, I don't have an account there.
     
  14. Offline

    Unscrewed

    Pff I tought I was alone. :3
    @Plague
    Okay, but the wiki is really, really, really outdated and I can't even look at it.
    Sorry :p
     
  15. Offline

    Plague

    What's stopping you from registering and making contribution?
     
  16. I've registered an account on the wiki and am moving the tutorial over there but the formatting takes a while :p

    Anyway, I finished my plugin :D

    Plugin is now COMPLETE
    _________
    Get Regions!
     
  17. Offline

    Jayjay110

    Congrats :)
     
  18. Offline

    GardenGnomer

  19. Offline

    littleleeroy

    Awesome tutorial. Helped alot :D could you maybe add a section on reading/writing to excel files and searching certain columns then returning what the row says? or something like that. thanks :)
    edit: oops just realized i was meant to say this as a pm
     
  20. :p I also tried to find out how to work with excel but the API's I found didn't look very friendly :(
     
  21. Offline

    nossr50

    I'll definitely be showing this to people I know interested in learning to program for bukkit
     
  22. Offline

    neromir

    My only suggestion so far would be to add IntelliJ IDEA Community Edition to the list of main Java IDEs; it's widely used commercially.

    You can find it here: http://www.jetbrains.com/idea/free_java_ide.html

    Also, where is this on the wiki? Once it gets added there, I would possibly be able to do a quick set-up tutorial on how to get your project going with IntelliJ.
     
  23. I've never used IntelliJ but if you could provide some pictures and a brief guide that would be great :D. As for the wiki I am migrating the rest of it over today, I just need to format everything.
     
  24. Offline

    cholo71796

    Shouldn't in.close(); be within the block? If not, why not?
     
  25. Yes it should, thank you for pointing that out.
     
  26. Offline

    kman2010

  27. It's really hard to read all that unformatted code. I am working on writing a bunch of simple plugins and releasing the source for free so when I get that done you'll be able to learn from that also :D
     
  28. Offline

    kman2010

    i put the new paste bin files on a post
     
  29. Sorry, I really don't have the time to trawl through all the code.
     
Thread Status:
Not open for further replies.

Share This Page