Solved setJoinMessage won't modify the join message

Discussion in 'Plugin Development' started by Leyxo, Jul 14, 2021.

  1. Offline

    Leyxo

    Ok. Either I am an absolute idiot or I am really doing something wrong.
    So I am learning plugin coding on paper right now (which shouldn't be that much of a difference towards bukkit or spigot).
    I started by modifying the join message using setJoinMessage like this:

    Code:
    @EventHandler
        public void onJoinEvent(PlayerJoinEvent event){
            Player player = event.getPlayer();
            event.setJoinMessage(player + " joined.");
    }
    When I tried out the plugin (I did not forget the other parts of the code!) and wanted to join my test-server, the join message was not changed.
    I watched plenty of tutorials and posts in the forums but I still can't figure out what's wrong. So if anyone could possibly help me - I would really appreciate it.

    As additional info, the setJoinMessage command is stroken through in my IDE (I use Intellij with the Minecraft plugin).
    It says something about deprecated API usage options and adding a method contract. What shall I do?
     
  2. Offline

    KarimAKL

    @Leyxo Did you register the listener?

    What version of the API are you using?
     
  3. Offline

    Leyxo

    So - I don't exactly know what the API is, but I registered the listener using this:
    Code:
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    If I did something wrong/forgot something when registering the listener or if I didin't quite understand, what registering means, please correct me. And please tell me what the API is and how to use it.
     
  4. Offline

    KarimAKL

    Those are just imports. You have to register the listener using:
    Code:Java
    1. Bukkit.getPluginManager().registerEvents(Listener, Plugin)

    Here is a link to the Javadocs.

    The API is Bukkit, so you are already using it. The version of the API would be the version of Minecraft you are building for (e.g. 1.8, 1.9, ..., 1.16, 1.17).
     
  5. Offline

    Leyxo

    Ok so that would mean I am using 1.17.1 API?
    And where does the code with the registration of the listener go?

    So would this work:
    Code:
    getServer().getPluginManager().registerEvents(this, this);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 15, 2021
  6. Offline

    KarimAKL

    Yes.

    In the onEnable, either directly or indirectly.

    Yes, if "this" refers to your main class and your main class is the listener as well.
     

Share This Page