[Help] What is wrong with this mounting code! D:

Discussion in 'Plugin Development' started by finalblade1234, Jan 13, 2013.

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

    finalblade1234

    Hello does anyone know whats rong with this code
    Code:
        public void onMobSpawn(PlayerInteractEntityEvent event){
            Player p = event.getPlayer();
           
            Entity mob = event.getRightClicked();
            if(p.getItemInHand().equals(Material.BLAZE_ROD));
                mob.setPassenger(p);
                    p.sendMessage("You just mounted a" + mob);
     
  2. Offline

    colony88

    did you add @EventHandler and register the event in onEnable?
     
  3. Offline

    chasechocolate

    And make that class that the code is in implement Listener?
     
  4. Offline

    colony88

    Well you can't register the event if you don't let the class implement Listener :p
     
  5. Offline

    chasechocolate

  6. Offline

    finalblade1234

    Oh shoot i always forget the @Eventhandler [sheep]

    ok im done all that but i can still mount mobs with any item D;
    code:
    Code:
    @EventHandler
        public void onMobSpawn(PlayerInteractEntityEvent event){
        Player p = event.getPlayer();
        if(p.getItemInHand().equals(Material.BLAZE_ROD));
            Entity mob = event.getRightClicked();
                mob.setPassenger(p);
                //lawl
                    p.sendMessage("You just mounted a" + mob);
                   
                   
           
        }
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  7. Offline

    chasechocolate

    getItemInHand() returns an ItemStack, not a material. Try this:
    Code:java
    1. @EventHandler
    2. public void onMobSpawn(PlayerInteractEntityEvent event){
    3. Player p = event.getPlayer();
    4. if(p.getItemInHand().getType() == Material.BLAZE_ROD){
    5. Entity mob = event.getRightClicked();
    6. mob.setPassenger(p);
    7. //lawl
    8. p.sendMessage("You just mounted a " + mob);
    9. }
    10. }
     
Thread Status:
Not open for further replies.

Share This Page