What's wrong with this code?

Discussion in 'Plugin Development' started by Jellydude, Jul 15, 2013.

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

    Jellydude

    Code:java
    1. @EventHandler
    2. public void OnPlayerFly(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4. if(event.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    5. if(player.getItemInHand().getType() -- Material.BLAZE_ROD){
    6. player.setVelocity(new Vector(0, 2, 0));
    7. player.sendMessage(ChatColor.DARK_BLUE + "POOF");
    8. }
    9. }
    10. }


    I get an error on (player.getItemInHand().getType() --
    Please can someone fix the code for me! :3
     
  2. Offline

    seemethere

    Jellydude and xTrollxDudex like this.
  3. Offline

    Jellydude

  4. Offline

    ZeusAllMighty11

    I'm a bit confused why you compare Bukkit's "Action" enum with .equals(), then decide to check the material with ==.
     
  5. Offline

    Jellydude

    TheGreenGamerHD
    I'm not sure that how I learnt to do it and that's the way I do it.
     
  6. Offline

    ZeusAllMighty11

    Use .equals() when comparing enums, use == when comparing primitives
     
  7. Offline

    xTrollxDudex

    TheGreenGamerHD
    (Raises hand)
    Mr. GreenGamerHD? Why does that matter?

    Edit: it goes hilariously well with my avatar :p
     
  8. Offline

    microgeek

    Because you when comparing Object's with the == operator, it checks if the instance's are the same, not the values.
     
  9. Offline

    xTrollxDudex

    microgeek
    (Raises hand)
    Mr. microgeek,
    Why is there an instanceof operator and an == operator?
     
  10. Offline

    microgeek

    For supertypes and subtypes =)
     
    TheGreenGamerHD likes this.
  11. Offline

    ZeusAllMighty11

    xTrollxDudex
    If you raise your hand again, I'm going to raise mine. And there's no questions going to be asked. :D
     
  12. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page