confused with making a plugin - help a noob?

Discussion in 'Plugin Development' started by Musketeer925, Aug 13, 2012.

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

    Musketeer925

    It's my first time trying to make a plugin, and I got stuck pretty quick.

    I was using this tutorial (http://wiki.bukkit.org/Introduction_to_the_New_Event_System), and just kind of playing around.

    I added the OnEnable and OnDisable events, and then an event handler.

    The plugin loads alright and reports that it's been loaded in the server's console, but it doesn't seem to react to any events -- I figure I must be registering it wrong. I tried both registering it in a separate class and in the main class, and tried a few different events, but nothing seems to happen.

    As far as I can tell, when a player places a block it ought to say "player placed block", and then if it's wool it'll turn it into dirt, sending another message accordingly.

    Code:
    package com.gmail.musketeer925.SuperRightClicks;
     
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SuperRightClicks extends JavaPlugin implements Listener{
     
    public void OnEnable(){
    getLogger().info("Your plugin has been enabled.");
    getServer().getPluginManager().registerEvents(this, this);
     
    }
    public void OnDisable(){
    getLogger().info("Your plugin has been disabled.");
     
    }
     
    @EventHandler
    public void onPlayerInteractBlock(BlockPlaceEvent evt){
    evt.getPlayer().sendMessage("Player placed block!");
     
    Block b = evt.getBlock();
    if(b.getType() == Material.WOOL){
    evt.getPlayer().sendMessage("Player placed wool, changed to dirt!");
    b.setType(Material.DIRT);
     
    }
     
    }
     
    }
     
  2. Offline

    nala3

    Musketeer925 you should overriding onEnable() and onDisable() (also On shouldn't be capitalized).

    So...

    @Override
    public void onEnable() {
    }
     
    Musketeer925 likes this.
  3. Offline

    Musketeer925

    Thanks a lot! That fixed it.
     
  4. Offline

    Firefly

    As far as I know you don't need @Override, it just you have the have the methods named correctly.
     
  5. Offline

    Musketeer925

    Yeah, I tried it first without adding override and that worked, so I didn't add it, as it didn't show that in the original tutorial.
     
Thread Status:
Not open for further replies.

Share This Page