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

    OverSpeed

    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 :

    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");
                }
            }
            else{
               
                config.set(path+"firstConnection", 0);
                config.set(path+"timeSpent", 0);
                config.set(path+"ip", e.getPlayer().getAddress().getAddress().getHostAddress());
                log.info(ChatColor.RED +"[Plugin Event *****]"+ChatColor.WHITE+" Un nouveau joueur est arrive (pseudo :"+player+"");
               
                plugin.saveConfig();
            }
        }
    Ideas ?
    Thanks by advance ! :)

    OverSpeed301.
     
  2. Offline

    Rprrr

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

    OverSpeed

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

    Woobie

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

    OverSpeed

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

    This is my file, entirely : http://pastebin.com/9zZZst5a

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

    fireblast709

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

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

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

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

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

    OverSpeed

    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)

    Code:
        int task = plugin.getServer().getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
     
            @Override
            public void run() {
                log.info("test");
               
            }
           
        },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