Solved PlayerJoinEvent

Discussion in 'Plugin Help/Development/Requests' started by MinecraftChickenNL, Apr 2, 2016.

Thread Status:
Not open for further replies.
  1. Hello!

    I am developing a plugin that uses a PlayerJoinEvent, but for some reason it doesn't work.
    Can somebody please look at this?

    Main class:
    public class Main extends JavaPlugin {
        private PluginManager pm;
        private PlayerListener playerListener = new PlayerListener(this);
        public void onEnable() {
            pm = getServer().getPluginManager();
            pm.registerEvents(playerListener, this);
    PlayerListener class:
    public class PlayerListener implements Listener {
        public Main plugin;
        public PlayerListener(Main instance) {
            plugin = instance;
        //onPlayerJoin Listener
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
    It looks good to me. Am I missing something?
    Because it does not work at all.
  2. Online

    timtower Moderator Moderator

  3. Online

    timtower Moderator Moderator

    @MinecraftChickenNL Then initialize the listener class in the onEnable, and not before that.
  4. Offline


      public void onEnable() {
          PluginManager  pm = getServer().getPluginManager();
            pm.registerEvents(new PlayerListener(), this);
    There's no real reason to make a private variable for both the PlayerListener and the PluginManager, unless there is one I'm not aware of. I never did. If what I said doesn't work, then yea the error log will help.
  5. Online

    timtower Moderator Moderator

    @xaanit Saving it could be a habit.
    Or it does more than just handing the event.
  6. Offline


    "Saving it could be a habit"
    If it's a bad habit, it should be broken. I used to make everything static. *shudders*. Now it could be a fine habit, I'm not as experienced as, say, you.

    "Or it does more than just handling the event."
    Possibly, in this case it doesn't so my way is valid but yes I didn't really think of that. Even with my way you could use a command sender, another listener, etc... Just gave a possible fix in the way that I always coded.
  7. Online

    timtower Moderator Moderator

    @xaanit Saving:
    Saving also gives a way to clean it up when you are done with it. And it could give more insight in what is used in the plugin.
    Doing more:
    In this case: no, it doesn't do more, not visible at least.

    Your way will do fine, just responded on the text below ;)
  8. I unfortunatly can't try that today because it is a little too late for that xd

    Anyways, what I wanted to say was that I am using other eventlisteners in the same class that do work,
    So that makes this even more weird..

    I treid that.
    Still no errors and it still doesn't work.
    Other eventlisteners in the same class do work.. As if the join method doesn't even exist

    Should I try placing the method in my main class?

    It also didn't work in the main class. I really don't know any reason why it isn't working xd
    Last edited: Apr 3, 2016
  9. Well, I reinstalled my testing server, and now I at least got an error.

    [19:48:25 ERROR]: Error occurred while enabling McCPlugin v3.7.PRE (Is it up to
            at me.maarten.McCPlugin.PlayerListener.<init>( ~[
            at me.maarten.McCPlugin.Main.onEnable( ~[?:?]
            at ~[s
    .java:340) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.jav
    a:357) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.
    java:317) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.s(
    14) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.k(
    78) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(
    33) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.jav
    a:263) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
    :525) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at Source) [?:1.8.0_73]
  10. Online

    timtower Moderator Moderator

    Now I don't know what is on line 26 but it is probably something bad.
  11. There is nothing on that line..

    package me.maarten.McCPlugin;
    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.scheduler.BukkitScheduler;
    import mkremins.fanciful.FancyMessage;
    import static org.bukkit.ChatColor.*;
    public class PlayerListener implements Listener {
        public Main plugin;
        public PlayerListener(Main instance) {
            plugin = instance;
        final String ServerName = GOLD + "[" + DARK_RED + "MinecraftChicken" + GOLD + "]: ";
        FileConfiguration config = plugin.getConfig();
  12. Online

    timtower Moderator Moderator

    @MinecraftChickenNL Then it is line 25, you can't call getConfig before your constructor is called.
  13. @timtower
    Could you explain that a bit further for me?
    I'm still learning Java a bit..
  14. Online

    timtower Moderator Moderator

  15. Thank you so much! :)
Thread Status:
Not open for further replies.

Share This Page