Basic Listener Help

Discussion in 'Plugin Development' started by paully104, Dec 13, 2013.

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

    paully104

    Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package paulstestplugin;
     
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    /**
    *
    * @author Paul
    */
    public final class Paulstestplugin extends JavaPlugin implements Listener{
     
        /**
        * @param args the command line arguments
        */
     
       
     
       
        @Override
       
        //onEnable and @ovveride has to be in the public final clas!
       
       
        public void onEnable(){
            // TODO Insert logic to be performed when the plugin is enabled
            getLogger().info("Test plugin has been enabled");
            getServer().getPluginManager().registerEvents(this, this);
           
        }
        @EventHandler
        public void testhandler(PlayerLoginEvent event) {
            //what happens when a player logs on
            event.getPlayer().sendMessage("Welcome to the sever!");
        }
       
       
        @Override
        public void onDisable() {
            // TODO Insert logic to be performed when the plugin is disabled
            getLogger().info("Test plugin has been disabled");
        }
       
       
       
       
        public static void main(String[] args) {
     
           
     
     
           
           
           
           
           
           
           
           
           
           
           
           
        }
    }
    
    Basically the server doesn't communicate, i'm reading the event API but i feel im messing up on something really simple.
     
  2. Offline

    The_Doctor_123

    paully104
    Okay, first off, just to clarify, do you know Java? Secondly, are you getting any errors? Third of all, why do you have a main() method? A Bukkit plugin is not a separate process..
     
  3. Offline

    Chlorek

    Do everything as in Plugins Tutorial and should work fine. Don't hit forums with things that are well explained in basics tutorial.
     
  4. Offline

    paully104

    I know Java, im getting 0 errors. Didn't know it didn't need a main.
     
  5. Offline

    ninja_ace202

    How about your Plugin.yml? Every plugin needs one. Also make sure you're exporting the plugin as a .jar and dropping that .jar in the correct location of your test server.

    Lastly, avoid using PlayerLoginEvent until you're a bit more seasoned at Bukkit programming. Use PlayerJoinEvent.

    Lots of things cause errors when using PlayerLoginEvent since it is fired quite early in the login process.


    Check your console for the enabled/disabled messages and any potential Java Stack Traces.
     
  6. Offline

    paully104

    Copied it verbatim from what is available in the tutorial, looking for an answer if you don't have one don't post

    Here's the yml, the plugin loads, it says enabling paulstestplugin v.01 and it says test plugin has been enabled. On the server i do /plugins and it shows up in green.
    Code:
    name: paulstestplugin
    main: paulstestplugin.Paulstestplugin
    version: 0.01
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  7. Offline

    Wolfey

    Use a PlayerJoinEvent. A PlayerLoginEvent is when the player clicks the connect button.
     
    paully104 likes this.
  8. Offline

    ninja_ace202

    Yup, then it sounds like you're just trying to message the player too soon. :p

    Swap that PlayerLoginEvent to PlayerJoinEvent and boom!
     
  9. Offline

    paully104

    One more quick question can i use try { Thread.sleep(500); }
    catch ( Exception e ) { }, to make the server wait on the PlayerLoginEvent just as a test or does craftbukkit not like try catch statements?
     
  10. Offline

    The_Doctor_123

    paully104
    No.. Do not call sleep(), that sleeps the Thread.
     
  11. Offline

    ninja_ace202

    NEVER NEVER NEVER NEVER NEVER NEVER PUT THE MAIN SERVER THREAD TO SLEEP LIKE THAT! Bit dramatic, but it'll stop everyone on the server, every plugin, every entity, every flowing water, everything for the duration. Not good.
     
    Chlorek likes this.
  12. Offline

    paully104

    Alright well thanks for the help got it working ^^

    Got it _____@!, thanks for the help got it working!

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

    ninja_ace202

    For instances where you want to delay some tasks like that in a SAFE manner use the Bukkit Scheduler to schedule a task for later.

    Code:java
    1. plugin.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    2. public void run() {
    3. //Code to delay here
    4. }
    5. }, delay); //delay = A Long value for how many server ticks to delay the task. 20ticks = 1 second
     
  14. Offline

    Chlorek

    It was my reply. I can and I really like to help, but when I see someone asking thing that I surely covered in tutorial then my reaction is simple. I just told you to go again through tutorial step by step and check if you did not forgot something. It was not like "you stupid dumbass read tutorial idiot", it was pure advice, don't get mad man.

    Also if you would follow everything as it is in tutorial your code would look very different.
     
  15. Offline

    AzubuSan

    paully104 Something like this might help for that "pause" you wanted.
    Code:java
    1. new BukkitRunnable() {
    2. @Override
    3. public void run() {
    4. // Your stuff
    5. }
    6. }.runTaskLater(this, 20); // One second wait as an example, change to w/e.
     
    paully104 likes this.
  16. Offline

    paully104

    Awesome thank you ^^
     
    AzubuSan likes this.
Thread Status:
Not open for further replies.

Share This Page