ConstructorHeaderName expected error when registering event

Discussion in 'Plugin Development' started by TNOMCat, Jul 28, 2011.

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

    TNOMCat

    I get "Syntax error on tokens, ConstructorHeaderName expected instead" error when i try to register event:
    Code:
    pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this);
    
    How can i fix this?
     
  2. Offline

    bergerkiller

    Is your playerListener constructed this way?:
    Code:
    private final <name>PlayerListener playerListener = new <name>PlayerListener(this);
    And also, your PlayerListener extending class has this header:?
    Code:
    public class <name>PlayerListener extends PlayerListener {
        private final <name> plugin;
    
        public <name>PlayerListener(<name> instance) {
            plugin = instance;
        }
    }
    Other than this nothing comes to mind.
     
  3. Offline

    TNOMCat

    Yes they are like that, except that second thing was bit diffrent, i tried using that but i still get the same error from
    that registerevent line.
     
  4. Offline

    bergerkiller

    Perhaps it is an error in your playerlistener code? For example, an error like this:
     
  5. Offline

    TNOMCat

    I dont think so. But theres mah code:
    PlayerListener.java

    Code:
        PluginManager pm = this.getServer().getPluginManager();
        private final PlayerListenerPlayerListener playerListener = new PlayerListenerPlayerListener(this);
    
        public void onEnable(){
            logger.info("");
        }
    
        public void onDisable(){
            logger.info("");
        }
    
        pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this);
    PlayerListenerPlayerListener.java

    Code:
    public class PlayerListenerPlayerListener extends PlayerListener {
    private final PlayerListener plugin;
    
    public PlayerListenerPlayerListener(PlayerListener instance) {
    plugin = instance;
    }
    public void onPlayerMove(PlayerListenerPlayerListener event){
    
    }
    }
    
    The whole
    pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this);
    is red underlined with the error ConstructorHeaderName expected instead
     
  6. Offline

    bassfader

    Well the register event is outside of any function, I guess you wanted it to be in the onEnable() method (thats at least were it makes the most sense xD), something like this:

    Code:
        PluginManager pm = this.getServer().getPluginManager();
        private final PlayerListenerPlayerListener playerListener = new PlayerListenerPlayerListener(this);
    
        public void onEnable(){
            pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this);
            logger.info("");
        }
    
        public void onDisable(){
            logger.info("");
        }
     
  7. Offline

    TNOMCat

    it is inside the main class function thingy, lol, i just didnt copy the whole thing to that reply, just the important stuff
     
  8. Offline

    bassfader

    Yeah but beeing inside the class only won't work, you cant execute commands inside a class withouth them beeing inside a function / method. Try to put it into the onEnable(), it should work.
     
  9. Offline

    TNOMCat

    I put it now in onEnable, doesnt give me the error anymore :D
     
  10. Offline

    bassfader

    For example this will work:
    Code:
    public class SomePlugin extends JavaPlugin {    
        // ...
        
        public void onEnable(){
            pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this);
            logger.info("");
        }
        
        // ...    
    }
    This will NOT work:
    Code:
    public class SomePlugin extends JavaPlugin {    
        // ...
        
        public void onEnable(){        
            logger.info("");
        }
        
        pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Event.Priority.Normal, this);
        
        // ...    
    }
     
Thread Status:
Not open for further replies.

Share This Page