Cannot Spot Problem...

Discussion in 'Plugin Development' started by ReadySetPawn, Jul 6, 2014.

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

    ReadySetPawn

    @EventHandler
    public void check(PlayerInteractEvent event){
    Player player = event.getPlayer();
    Action action = event.getAction();
    Block block = event.getClickedBlock();
    if (action.equals(Action.RIGHT_CLICK_BLOCK)){
    if (block.equals(Material.EMERALD_BLOCK)){
    player.setBedSpawnLocation(player.getLocation());
    player.playSound(player.getLocation(), Sound.CLICK, 1, 100);
    }
    if (block.equals(Material.DIAMOND_BLOCK)){
    player.teleport(player.getBedSpawnLocation());
    player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1, 100);
    }
    }
    }

    No error messages popping up anywhere and I'm positive the class is registered. Anybody see the problem? =/
     
  2. Offline

    dsouzamatt

    ReadySetPawn I'm pretty sure you'll need to do block.getType() to return it's material, and then check whether that's Emerald.
     
  3. Offline

    ReadySetPawn

  4. Offline

    dsouzamatt

    ReadySetPawn Do you know what part of it's not working? Put in some debug messages and work out where the problem is.
     
  5. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

  6. Offline

    ReadySetPawn

    dsouzamatt

    When I right click the block, nothing happens =/ Not even the sound. I'm think there's something wrong with the if statements.


    mbaxter

    Thanks :D
     
  7. Offline

    unrealdesign

    Send to player/log to console different debug messages and see how far the code parses those messages. None show up, then you didn't mess up the event. And yes you do need to do block.getType().equals(Material.MATERIAL)
     
  8. Offline

    ReadySetPawn

    unrealdesign

    I did some further testing and it appears that when I right click the emerald block, it's not setting my bed spawn location. I tried sleeping in a bed and right clicking the diamond block and it teleports me to the bed so that's good =/
    Now I can't figure out why it's not setting my bed location. Could it possibly be a 1.7.9 craftbukkit bug?
     
  9. Offline

    zack6849

    I's because you're using.equals to compare type, you need ==
    if(event.getGetClickedBlock().getType() == Material.STONE){
     
  10. Offline

    ReadySetPawn

    zack6849

    Yeah, I tried that too and no luck =/
    The system still can't set my bed spawn for some reason.
     
  11. Offline

    unrealdesign

    Haha nope. You can compare enums either way. Yes == is better, but .equals works the same exact same way except it would throw npe.
     
  12. Offline

    zack6849

    Uh, no?
    == and equals are totally different, do you even understand how java works?
    on topic, try this.
    Code:
    @EventHandler
    public void check(PlayerInteractEvent event){
      Player player = event.getPlayer();
      Action action = event.getAction();
      if (action == Action.RIGHT_CLICK_BLOCK)){
        //don't assign event.getClickedBlock to a variable if you aren't sure if the event even *has* a clicked block
        Block block = event.getClickedBlock();
        if (block.getType() == Material.EMERALD_BLOCK)){
          player.setBedSpawnLocation(player.getLocation());
          player.playSound(player.getLocation(), Sound.CLICK, 1, 100);
        }
        if (block.getType() == Material.DIAMOND_BLOCK){
          player.teleport(player.getBedSpawnLocation());
          player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 1, 100);
        }
      }
    }
    
     
  13. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    tommyhoogstra and unrealdesign like this.
  14. Offline

    xTigerRebornx

    zack6849 Enum#equals() calls ==
    Meaning you could call either, the difference being == is null-safe
    Edit: Ninja'd by an Admin :p
     
  15. Offline

    unrealdesign

Thread Status:
Not open for further replies.

Share This Page