My code doesn't work?

Discussion in 'Plugin Development' started by Zombeh_Kwer, Aug 15, 2014.

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


    Okay, so i'm very new at plugin development, and as practice i've decided to make a basic plugin that uses exp as health instead of the default hearts. I only wrote code that you receive exp when joining and respawning and die when your exp reaches zero, however it doesn't work when i test it on my server.
    Here is my code:

    package me.zombehkwer.fantasyonlinehealth;

    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;

    public final class FantasyOnlineHealth extends JavaPlugin{
    public void onDisable() {
    getLogger().info("onDisable has been invoked.");


    public void onEnable() {
    getLogger().info("onEnable has been invoked.");
    public void onPlayerJoinEvent(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    float exp = player.getExp();
    if (exp == 0); {
    public void onPlayerRespawnEvent(PlayerRespawnEvent event) {
    Player player = event.getPlayer();

    Eclipse says that there are no errors, could you please tell me why this code doesn't work, or if i need to put something in my plugin.yml.
  2. Offline


    Zombeh_Kwer What are the errors? It may also be useful to see your plugin.yml
  3. Offline


    You did not register your Listeners, and you didn't implement Listener.
  4. Offline


    Two notes:
    1. Final class? why
    2. Not needed SuppressWarnings("deprecation")?
    Other than these, it is mainly due to what Dealyise noticed :)
  5. Offline


    Because you should under no circumstances extend your main class (or extend JavaPlugin more than once) and I would assume OP is following the plugin tutorial.
  6. Offline


    Garris0n isn't that his main class .-.
  7. Offline


    Yes, exactly. Which should not be extended. Hence the final keyword...
  8. Offline


    1. You didn't register the Listener, code below.
    2. You didn't implement the Listener(In this case, located in your Main class, though, I highly recommend using multiple classes for stuff like this).
    3. No need for the class to be final...
    4. Example code to help you out in the future:
    1. public class <YourClass> extends JavaPlugin implements Listener {
    2. // import these
    3. @Override
    4. public void onEnable()
    5. {
    6. getPluginManager().registerEvents(this, this);
    7. //register the Listener!
    8. }
    10. @EventHandler
    11. public void onPlayerJoin(PlayerJoinEvent event)
    12. {
    13. Player p = event.getPlayer();
    14. // Do desired code here, too lazy to do it myself :P
    16. // May contain mistakes, written by hand.
    17. }
    DinosParkour likes this.
Thread Status:
Not open for further replies.

Share This Page