Solved Events/Commands in Another Package

Discussion in 'Plugin Development' started by LandonTheGeek, Nov 16, 2013.

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

    LandonTheGeek

    Hey guys. I have been coding for a while now on this plugin, and I am having quite an issue. This is my first time using another command/event in this package (noting I never have before), and it doesn't work in game.

    What does it do? It is a simple onJoin messager. I am trying to get it from the other package I mentioned, but I feel like I left something out because it isn't working correctly.

    Here is my onJoin Class (The one in the other package)

    Code:
    public class onJoin implements Listener {
       
        @EventHandler
        public void onPlayerJoin(PlayerLoginEvent e){
            Player p = e.getPlayer();
            p.sendMessage(ChatColor.AQUA + "Welcome to the server " + p + "!");
        }
     
    }
    Here is my main class(in my main package). you can see I tried registering it, but no go.

    Code:
        public void onEnable(){
            // Config Saving
            // My Enable Message
           
            // Register Commands
           
            // Register Events
            getServer().getPluginManager().registerEvents(new onJoin(), this); 
           
        }
     
  2. Offline

    Chinwe

    Try PlayerJoinEvent instead, PlayerLoginEvent fires before they have joined properly (as you can .disallow() it), so they're getting the message too early to see it :)
     
  3. Offline

    tenowg

    try using PlayerJoinEvent... I am not sure if sending a message to a player on login works (I have noticed that it doesnt in past plugins)
     
  4. Offline

    LandonTheGeek

    Chinwe tenowg
    Thank you. :p Just a silly mistake. Lol

    tenowg Chinwe

    I actually have one more thing if that is okay. I am trying to perform the method plugin.getConfig() for my onPlayerJoin and my public static Main doesn't seem to be working in my different package. Here it is:

    Code:
          public static Main plugin;
         
          public onJoin(Main main)
          {
              plugin = main;
          }
    In my Main class, this highlights.
    [​IMG]

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  5. Offline

    Chinwe

    You need to pass in an instance of 'Main', which will be 'this':
    (new onJoin(this), this)
     
  6. Offline

    LandonTheGeek

    Chinwe
    OH. :p I am stupid.
    Sorry for my dumbness!
    Thank you!
     
  7. Offline

    Chinwe

    No problem! :rolleyes:
     
    HelpfulBeast likes this.
  8. Offline

    amhokies

    1) You really shouldn't make your class fields public or static without good reason.
    2) Your class names should be "upper camel case" (OnJoin instead of onJoin). The name you're using now makes it look like a method. the name itself also makes it sound like a method as well.
    3) You need to pass an instance of your plugin class into your Listener class's constructor when you register it.
     
Thread Status:
Not open for further replies.

Share This Page