I'm getting two errors in my plugin

Discussion in 'Plugin Development' started by PwnsomeWin, Dec 23, 2011.

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

    PwnsomeWin

    I'm new to developing plugins (but not to Java), and I have two errors that I can't fix no matter what I do.

    Here's the first one...
    Code:
    package me.pwnsomewin.acheev;
    
    import java.util.logging.Logger;
    
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class AchMain extends JavaPlugin {
        private final AchBlockListener blockListener = [COLOR=rgb(255, 0, 0)]new AchBlockListener();[/COLOR]
        Logger log = Logger.getLogger("Minecraft");
    
        @Override
        public void onDisable() {
            log.info("Acheev has been disabled.");
        }
    
        @Override
        public void onEnable() {
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Event.Priority.Normal, this);
            log.info("Acheev has been enabled.");
        }
    
    }
    ...and the second one.
    Code:
    package me.pwnsomewin.acheev;
    
    import java.io.*;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockListener;
    
    public class AchBlockListener extends BlockListener {
        public AchMain plugin;
        double achCount = 0;
        double amountOfBlocksBroken = 0;
    
        public AchBlockListener(AchMain instance) {
            plugin = instance;
            public void [COLOR=rgb(255, 0, 0)]onBlockBreak([/COLOR]BlockBreakEvent event[COLOR=rgb(255, 0, 0)])[/COLOR] {
                           //lots of code
            }
        }
    }
    Help please? Thanks.
     
  2. Offline

    ItsHarry

    This is a JAVA error. The problem is you're creating a new instance, but the constructor is missing an argument.

    use "new AchBlockListener(this);" instead

    The second problem is

    Code:
    public void [COLOR=rgb(255, 0, 0)]onBlockBreak([/COLOR]BlockBreakEvent event[COLOR=rgb(255, 0, 0)])[/COLOR] {
    
    should be outside the constructor.

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

    PwnsomeWin

    Thanks man! Both solutions worked.
     
  4. Offline

    ItsHarry

    No problem :D
     
  5. Offline

    PwnsomeWin

    I also have a question.
    How do I make a yml file and put stuff in it?
     
  6. Offline

    ItsHarry

    If you're using Eclipse:
    1. Right click on the project
    2. Select add file
    3. Then typ in plugin.yml in the window where it asks you for the name
     
  7. Offline

    unicode21B9

  8. Offline

    PwnsomeWin

    Sorry, I wasn't very clear, but unicode got what I was saying. Reading the article now.
     
  9. Offline

    ItsHarry

    Oh k :p
     
Thread Status:
Not open for further replies.

Share This Page