Player Interact

Discussion in 'Plugin Development' started by ImPhantom, Mar 28, 2014.

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

    ImPhantom

    I am creating a simple drug plugin (Private use) and i am making a "shift-click" option to use the drugs and for some reason when i shift and right click on an item nothing happens. I'm not too great with events yet, so can anyone help me?

    Event Code:
    Code:java
    1. package net.imphantom.drugs.event;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.block.Action;
    8. import org.bukkit.event.player.PlayerInteractEvent;
    9. import org.bukkit.inventory.ItemStack;
    10. import org.bukkit.potion.PotionEffect;
    11. import org.bukkit.potion.PotionEffectType;
    12.  
    13. public class Consume implements Listener{
    14.  
    15.  
    16. @EventHandler
    17. public void onPlayerInteract(PlayerInteractEvent e) {
    18.  
    19. Player p = e.getPlayer();
    20. ItemStack green = p.getItemInHand();
    21.  
    22. if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
    23. if(p.getItemInHand().equals(Material.SUGAR)) {
    24. p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 240, 10));
    25. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 15, 4));
    26. p.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 6, 1));
    27. }
    28.  
    29. if(p.getItemInHand().equals(Material.WHEAT) || green.getDurability() == 2) {
    30. p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, 120, 1));
    31. p.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 25, 2));
    32. p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 15, 1));
    33. }
    34. }
    35. }
    36. }


    Registering the Event in my onEnable:
    Code:java
    1. this.getServer().getPluginManager().registerEvents(new Consume(), this);


    Note: My consume class is in a separate package.
     
  2. Offline

    2MBKindiegames

    Change line 22 into:
    and line 29 into:
    Note: You know your cheking for: Item is Wheat OR Durability is 2, right?
     
  3. Offline

    ImPhantom


    2MBKindiegames
    I am still having issues. When i right click nothing happens.

    And with the durability thing. I thought that was how you got access to the Cactus Green item, since theres no material for it.
     
  4. Offline

    xMrPoi

    Put in debug messages
     
Thread Status:
Not open for further replies.

Share This Page