Solved Can't interact with ender crystal?

Discussion in 'Spigot Plugin Development' started by FroZenKeyboard, Apr 27, 2017.

  1. Why can't i interact with ender crystal? I have registrerd my listener btw. And this is in a player interact event. Code:
    Code (Text):
            if(e.getClickedBlock().getType() == Material.END_CRYSTAL) {
                e.getPlayer().sendMessage("§7T");
                    }
     
  2. Are you sure the event is getting triggered?
     
  3. No, no, that's not even nearly how you do it. Ender crystals are entities, not blocks. (EDIT: Nor items.)
    Use 'PlayerInteractEntityEvent' instead and check if the type of the clicked entity equals endercrystal.
     
    • Agree Agree x 1
  4. I was just about to post, but looks like @jetp250 beat me to it. Anyways, they're right. As a general rule, you should always use a check for the type of interaction.

    Code (Text):
    public void onInteract(PlayerInteractEvent e) {
            if(e.getAction == Action.RIGHT_CLICK_BLOCK) {
                    // check block type and run your code
            }
    }
     
  5. Eexcept PlayerInteractEvent doesn't trigger when right-clicking mobs. Other than that, yes, if you're working with blocks.
     
    • Like Like x 1
  6. How can i check if it's a ender crystal? Entity doesn't work.
     
  7. Have you tried using playerInteractEntityEvent?
     
    #7 _diam, Apr 27, 2017
    Last edited: Apr 27, 2017
  8. As I said earlier, use PlayerInteractEntityEvent instead.
    If there isn't a method that'd return EntityType of the target, you can use the instanceof -operator. Get the clicked entity and check if it's an instanceof Ender Crystal and you're good to go.
     
    • Like Like x 1
    • Winner Winner x 1
  9. Thanks! Its working.