Forcing command depending on first join or not.

Discussion in 'Plugin Development' started by SleepyDog, Apr 19, 2015.

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

    SleepyDog

    Hello, I want to be able to set an option in the conig to decide what args to run on the help command depending on wether it's the users first time joining the server or not.


    This is the code:

    Code:
      public void onEnable()
      {
        getServer().getPluginManager().registerEvents(this, this);
        getConfig().options().copyDefaults(true);
        saveConfig();
        reloadConfig();
        if (this.getConfig().getInt("Config_Version") != 2.0) {
            Bukkit.getLogger().warning("#========================================================#");
            Bukkit.getLogger().warning("#             OCELAHELP - WARNING - UPDATE               #");
            Bukkit.getLogger().warning("#  Your config is out of date! Please backup and delete  #");
            Bukkit.getLogger().warning("#        the current config to allow changes.            #");
            Bukkit.getLogger().warning("#========================================================#");
        }
      }
     
      public void onDisable() {}
     
      @EventHandler(priority = EventPriority.HIGHEST)
      public void onPlayerJoinEvent(PlayerJoinEvent event) {
        if(!event.getPlayer().hasPlayedBefore()) {
            event.getPlayer().performCommand("help " + getConfig().getString("firstJoinPage").toLowerCase());
        }
        else {
            event.getPlayer().performCommand("help " + getConfig().getString("joinPage").toLowerCase());
        }
      }
    At this time it is not doing anything, I know it's not my first time joining the testing server but it should change to the else code if I am the second user.

    Some information:

    The args are set in the config, for examle if they choose 'first' for their join args in the config it should run /help first for the user.

    Here is the relevent config section:

    Code:
    firstJoinPage: ''
    secondJoinPage: ''
    By default these will be blank, they can set the join message later (optional)

    Thank you.
     
  2. Does your class implement Listener?
     
  3. Offline

    SleepyDog

    Yes it does. I followed other tutorials but this is not working. I cant seem to find what's wrong.
     
  4. Offline

    stormneo7

    Show your plugin.yml as well as the help onCommand please.
     
  5. Offline

    Code01

    @SleepyDog You can always find out if it's the config or the code that causes the problem to do something like Player#performCommand("suicide") or something like that. See if that works.
     
Thread Status:
Not open for further replies.

Share This Page