Player Join Boss Bar Apperes

Discussion in 'Spigot Plugin Development' started by BenThunder, May 6, 2015.

  1. Hi I need a little help with this code. When a player joins the boss bar is supposed to appear but it doesn't. But I see the plugin when I do /pl

    package me.BenThunderBoss;

    import me.confuser.barapi.BarAPI;

    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class MyFirstPlugin extends JavaPlugin{

    @Override
    public void onEnable() {
    getLogger().info("Has Been Enabled");
    }

    @Override
    public void onDisable() {

    }
    @EventHandler public void onPlayerJoin(PlayerJoinEvent event){
    BarAPI.setMessage("This is a Boss Bar test");
    }
    }


    And this is the plugin.yml

    name: SCFirstPlugin
    main: me.BenThunderBoss.MyFirstPlugin
    version: 1.0
     
  2. gigosaurus

    Supporter

    #2 gigosaurus, May 6, 2015
    Last edited: May 6, 2015
    • Agree Agree x 1
  3. Ok thank you I am still learning all the plugin coding so yeah really helps. :)
     
  4. Never registered events...

    Edit: May also want to add BarAPI as a dependency on your plugin.yml to make sure you get no errors
     
  5. Is there something else I am doing wrong?

    package me.BenThunderBoss;

    import me.confuser.barapi.BarAPI;

    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class MyFirstPlugin extends JavaPlugin implements Listener{

    @Override
    public void onEnable() {
    getLogger().info("Has Been Enabled");
    }

    @Override
    public void onDisable() {

    }
    @EventHandler
    public void onLogin(PlayerLoginEvent event) {
    BarAPI.setMessage("This is a Boss Bar test");
    }
    }
     
  6. gigosaurus

    Supporter

    You're half way there. You still need to register that class to bukkit. Check the link before for something you should add to your onEnable method.

    Plus this:
     
  7. Put this in your on enable
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    Also remove the @Override annotations
     
  8. register your events and next time, post your code on pastebin and then give us the link.
    www.pastebin.com
     
  9. Yeah also add the pastebin
     
  10. gigosaurus

    Supporter

    Actually don't. The entire point of the @Override annotation is to make it clear that you are overriding a method from a superclass/interface. The IDE will help ensure that you are actually overriding and not overloading the method.
     
    • Agree Agree x 1
  11. Why? I never use it in any of my plugins and it dosent make a difference for me
     
  12. You avoid debugging typos, that's all (but it's pretty useful)
     
  13. Ok here is my code http://pastebin.com/ETyfc9MU and it still doesn't show the bar when I join I also have the BarAPI plugin in my plugins folder.
     
  14. Did you ever set the bar to the player? That might help , also try Bukkit.getServer idk I'm not on a laptop so I couldn't be sure

    Edit: Did you add BarAPI to a dependency in your plugin.yml
     
  15. gigosaurus

    Supporter

    Try using BarAPI.setMessage(Player, String) in a PlayerJoinEvent instead of BarAPI.setMessage(String) in a PlayerLoginEvent.
    If that then works, try and think why.
     
  16. I don't believe you ever set the bar to the player
    Player p = e.getPlayer():
    Then there's a method I believe that you set the bar directly to the player
     
  17. O well that will help :p
     
  18. gigosaurus

    Supporter

    Try doing what I said, plus you should be passing the variable to BarAPI.setMessage, not the class.
    Code (Java):
    BarAPI.setMessage(p, "Testing");