Click head tp, help please!

Discussion in 'Spigot Plugin Development' started by yeison, Aug 3, 2017.

  1. Good morning, I need to click on that slot to do tp.

    Code (Text):
        @EventHandler
        public void onInventoryClick(final InventoryClickEvent event) {
            final Player player = (Player)event.getWhoClicked();
            if (event.getInventory().getTitle().equals("")) {
                event.setCancelled(true);
            }
            final Player target = (player);
            final int slot = event.getSlot();
            if (slot == 8) {
                player.closeInventory();
                Bukkit.dispatchCommand((CommandSender) event.getWhoClicked(), "tp " + target.getName());
            }
        }
     
  2. Instead of dispatching the command, you can use
    Code (Text):
    player.teleport(target.getLocation());
     
  3. Not working any other idea ? :/
     
  4. What is wrong with the code, is this

    Code (Text):
    Player target = (player);
    I do not know how to fix it :8
     
  5. Where are you actually trying to teleport? Doesn't make sense to teleport to the player who clicked.
     
  6. You aren't actually casting player to anything.
     
  7. Then you've to get the name of the itemstack clicked and get the player voa Bukkit#getPlayer.

    Now you're teleporting X to X.
     
  8. Don't forget to remove the colors!