Player teleporting and getItemInHand

Discussion in 'Plugin Development' started by zZolt, Aug 23, 2016.

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

    zZolt

    I dont know why this doesn't work, I tried it without testing the item in the hand, and it worked except it also didnt set the pitch to 0 on teleport. please help :p
    Code:
    @EventHandler
        public void onClick(PlayerInteractEvent event){
            Player player = event.getPlayer();
                Action action = event.getAction();
            if(action == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK){
                ItemStack item = new ItemStack(Material.STONE_SWORD, 1);
                if(player.getItemInHand().equals(item)){
                if(player.getLevel()==100){
                    Location loc = player.getLocation();
                    Vector dir = loc.getDirection();
                    float pitch = loc.getPitch();
                    loc.add(dir);
                    loc.setPitch(0);
                    for (int i = 0; i < 10; i++) {
                    player.getLocation().setPitch(0);
                    player.teleport(loc);
                    }
                    loc.setPitch(pitch);
                    player.setLevel(0);
                }}}}
    EDIT: I fixed the iteminhand thing I just need teleporting help(changing the pitch to 0 then back to where it was)
     
    Last edited: Aug 23, 2016
  2. Offline

    DuaneTheDev_

    @zZolt

    Pitch is a float. Therefore you must cast it as a float.

    [EDIT]
    (float) 0.0 should work.
     
    Last edited: Aug 23, 2016
  3. Offline

    zZolt

    @DuaneTheDev_ Thanks, but it still doesn't change the pitch back to the original
     
    Last edited: Aug 23, 2016
  4. Offline

    DuaneTheDev_

    @zZolt

    Code:
    loc.setPitch((float) 0.0);
     
  5. Compare the type instead, also getItemInHand is deprecated (assuming you are 1.9+)
     
Thread Status:
Not open for further replies.

Share This Page