Solved Can't get server to notify user when they drop a diamond

Discussion in 'Plugin Development' started by Lupus, Feb 21, 2014.

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

    Lupus

    Code:java
    1. package us.lupusbukkit.testplugin;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Item;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerDropItemEvent;
    9.  
    10. public final class MyPlayerListener implements Listener {
    11. @EventHandler
    12. public void dropItem (PlayerDropItemEvent event){
    13. Player player = event.getPlayer();
    14. Item item = event.getItemDrop();
    15. if(item.getItemStack().getType() == Material.DIAMOND) {
    16. player.sendMessage("You dropped a diamond");
    17.  
    18.  
    19. }
    20.  
    21.  
    22.  
    23. }
    24. }



    I can't get this message to send to the player when they drop a diamond. What am I doing wrong?
     
  2. Offline

    Drew1080

    Lupus
    Are you getting an error if so could you please paste your stacktrace.
    Also are you registering the event?
     
  3. Offline

    Lupus

    No, I am not getting any error. Just nothing.

    How would I register that specific event?
     
  4. Offline

    tommyhoogstra

    Lupus
    Code:java
    1. public void onEnable()
    2. {
    3. getServer().getPluginManager().registerEvents(this, this);
    4. }

    Will register all of your events
     
  5. Offline

    Drew1080

    tommyhoogstra
    That only would work if his events were in his main class but there not there in a different class.

    Lupus
    Put this in your onEnable method

    Code:java
    1. getServer().getPluginManager().registerEvents(new MyPlayerListener(), this);
     
  6. Offline

    Lupus



    Thank you so much. That worked!
     
  7. Offline

    Drew1080

    Lupus
    Mark your thread as Solved then. :)
     
Thread Status:
Not open for further replies.

Share This Page