Calling FileConfiguration in the PlayerLoginEvent event

Discussion in 'Plugin Development' started by OverSpeed, Nov 4, 2012.

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


    Hello all,

    I have a question : can I search some informations in the configuration file of my plugin while the player try to log in ?

    I ask this question because i try to fetch some integer from my configuration file while the player try to log in, and Bukkit returns me an error : "Could not pass event PlayerLoginEvent to ******* v1.0".

    And, this is my part of code :

        @EventHandler(priority = EventPriority.LOWEST)
        public void onPlayerLogin(PlayerLoginEvent e){
            String player = e.getPlayer().getDisplayName();
            FileConfiguration config = plugin.getConfig();
            String path = "User."+player;
            if(config.get(path) != null){
                int timeMax = config.getInt("maxTimeOfConnection");
                int firstConnection = config.getInt(path+"firstConnection");
                int timeSpent = config.getInt(path+"timeSpent");
                if(timeSpent > timeMax){
                    e.disallow(null, ChatColor.RED+"Merci de laisser la place aux autres afin que tout le monde puisse venir !");
                    log.warning("Le joueur " + player + "a tenté de se connecter mais il s'est fait éjecter");
                config.set(path+"firstConnection", 0);
                config.set(path+"timeSpent", 0);
                config.set(path+"ip", e.getPlayer().getAddress().getAddress().getHostAddress());
       +"[Plugin Event *****]"+ChatColor.WHITE+" Un nouveau joueur est arrive (pseudo :"+player+"");
    Ideas ?
    Thanks by advance ! :)

  2. Offline


    Perhaps it's the priority? Just an idea, it's probably not.
  3. Offline


    No, this is not the priority, but thanks ! :)
    PS : error gives me line 41, and the line 41 is :
    FileConfiguration config = plugin.getConfig();
  4. Offline


    Remove that, and add this under your "implements Listener"
    FileConfiguration config; 
    Then you can use
    Also, try to wait a tick or two on join.
  5. Offline


    Thanks for your reply ! :) I don't have undestant something, but the code don't work :/

    This is my file, entirely :

    I don't understand : plugin.config.getSomething -> Why use plugin. and not directly config. ?
  6. Offline


    OverSpeed you already have the plugin, but you never defined it.
    1. public DiversListener(EventPlugin plugin)
    2. {
    3. this.plugin = plugin;
    4. }

    And where you do:
    1. new DiversListener();

    you now do:
    1. new DiversListener(this);

    (assuming you register the even in onEnable(); )

    From then on, use plugin.getConfig() to access the config
  7. Offline


    Thanks, i have understand and it works perfectly. But i have another question (sorry ... :/) with timers.
    My timer add +1 in the timeSpent node in my configuration file, every minutes. But the timer return me a nullPointerException error. (60 and 200 are for testing purposes)

        int task = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
            public void run() {
        },60L, 200L);
    This is a basic code, but it returns a nullPointerException and i don't know why ?

    Any ideas ? Thanks ! :D

    PS : Rapid responses, GG guys ! :)
Thread Status:
Not open for further replies.

Share This Page