PlayerInteractEntityEvent Help

Discussion in 'Plugin Development' started by someguyonthestreet, Aug 8, 2014.

Thread Status:
Not open for further replies.
  1. Code:java
    1. @EventHandler
    2. public void onPigClick(PlayerInteractEntityEvent e)
    3. {
    4. if(e.getRightClicked() instanceof Pig)
    5. {
    6. Player player = e.getPlayer();
    7.  
    8. player.sendMessage("test");
    9.  
    10. openMenu(player);
    11. }
    12. }


    I have no idea why this isnt working and there are no errors in console nor in the code itself. It would be great if somebody could help me :)
     
  2. Offline

    fireblast709

  3. Offline

    MCMatters

    It doesn't work I've already made an issue on github
     
  4. Offline

    fireblast709

    Wat?
     
  5. Offline

    macboinc

    I would say instead of using
    Code:java
    1. if(e.getRightClicked() instanceof Pig)
    I would say
    Code:java
    1. Entity entity = (Entity) e.getEntity();
    2. if (entity instanceof Pig) {
    3. if (!(e.getAction() == Action.RIGHT_CLICK)) return;
    4. //Do stuff
    5. }
    6.  


    Hope this helps! :)
     
  6. Offline

    fireblast709

    macboinc uses right click entity event, suggests to check if OP is right clicking xD.
    someguyonthestreet your inventory title contains more than 32 chars (note: colours count for 2)
     
  7. fireblast709
    Yea thanks, it works now :p

    EDIT: Also, do u know how i would make the pig not be able to move?
     
  8. someguyonthestreet Well you could add a massive slowness effect to the pig. (easiest way)
    Or you could set it's velocity to zero.
     
  9. Offline

    fireblast709

  10. My Code : LivingEntity.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 999999, 999999));

    It says : Cannot make a static reference to the non-static method addPotionEffect(PotionEffect) from the type LivingEntity
     
  11. Offline

    ZodiacTheories

  12. You can't add potion effects to "LivingEntity". LivingEntity is a class. You have to get the living entity. e.getRightClicked, cast LivingEntity to it, and then add potion effects to it.
    Look up how to cast, if you don't know how.
     
  13. I figured out how to set the slowness to the entity but is it possible to prevent players from pushing the mob and hit it (when they hit it, it says in one place without moving)?
     
  14. I suppose that, with the entity interact event, you could check and see if the entity being interacted with is (that entity ) and create some if statements to cancel out any interactions you don't want to occur. (with the e.setCanceled(true))
     
  15. xYourFreindx

    And how would i do that? Can you possible send me some code of it?
     
  16. someguyonthestreet
    I've been in your position before. Really, I have. Many a times.
    And... I'm going to do you a favor here and have you figure it out.
    I've given you everything you need. Now you do the creating.
    Ask anyone here, code feeding is not what this support forum is for.
    But, good luck. I know you'll get it.
     
Thread Status:
Not open for further replies.

Share This Page