Dragon_egg teleport

Discussion in 'Plugin Development' started by Badwolf330, Feb 9, 2016.

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

    Badwolf330

    Hey, i did made a code if a player clicks on a dragon_egg it should cancel the teleport event but it isn't working

    code:
    Code:
        @EventHandler
        public void dragonClick(PlayerInteractEvent e)
        {
            if(e.getPlayer().getWorld().getName().equals("sw_hub"))
            {
                if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock().getType().equals(Material.DRAGON_EGG))
                {
                    e.setCancelled(true);
                    e.getPlayer().sendMessage("don't!!!");
                }
            }
        }
    
     
  2. Offline

    mcdorli

    type is not an object, you can use == on it, same with action.

    Do you right click the egg!
     
  3. Offline

    Badwolf330

    @mcdorli

    thats not the problem xD
    and yes i'm clicking on the egg xD
     
  4. Offline

    mcdorli

    With the right mouse button?

    Is the event registered?
     
  5. Offline

    Badwolf330

    @mcdorli yes
    i do get the message... but it doesn't cancel hem, i also got a problem with this:

    Code:
         @EventHandler
         public void soilChangePlayer(PlayerInteractEvent event)
         {
           if ((event.getAction() == Action.PHYSICAL) && (event.getClickedBlock().getType() == Material.SOIL)) {
             event.setCancelled(true);
           }
         }
         
         @EventHandler
         public void soilChangeEntity(EntityInteractEvent event)
         {
           if ((event.getEntityType() != EntityType.PLAYER) && (event.getBlock().getType() == Material.SOIL)) {
             event.setCancelled(true);
           }
         }
    
     
  6. Btw you could also left-click it. It teleports then, too.
     
  7. Offline

    teej107

    @Badwolf330 Do you have any other plugins on your test server? Are you in your code "un-cancelling" an event?
     
  8. Offline

    Konato_K

    Type IS an object

    Your code checks for right click, but it doesn't check for left click.
     
  9. Offline

    teej107

    Facepalms at the ready.
     
  10. Offline

    mcdorli

    Type is an enum, enum is not an object.
     
  11. Offline

    DS_STORE

    Not sure but the items of an enum may be objects.
     
  12. Offline

    teej107

    Enums are an object. If it isn't a primitive then it's an Object and enums are definitely not primitives. The reason why == works is because enums are a constant.

    And if that doesn't convince you then run this code. xD
    Code:
    public class Main
    {
        public static void main(String[] args)
        {
            System.out.println(Abc.One23 instanceof Object);
        }
      
        enum Abc
        {
            One23
        }
    }
     
    Last edited: Feb 12, 2016
    Konato_K likes this.
Thread Status:
Not open for further replies.

Share This Page