Teleportation GUI

Discussion in 'Plugin Development' started by UnstoppableNow, May 1, 2017.

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

    UnstoppableNow

    Hello, I am currently working on a bukkit plugin. I know how to make it so you can teleport in a GUI, and I know how you can make it so you open the GUI with a command. But whenever I try to make a teleportation GUI that gets opened with a command, it never works. If anybody have a solution, please post it here. Thank you :)
     
  2. Offline

    yPedx

    @UnstoppableNow
    1. What did you try to do when you set it so it should open the GUI?
    2. Could you show us your code?
     
  3. Offline

    BananenPupse

    I hope that will work: instead of a command i would use event listener like this:
    Code:
    public class Teleport implements Listener {
    
        @EventHandler
        public void onInteract(PlayerInteractEvent e) {
            if (e.getAction() == Action.RIGHT_CLICK_AIR | e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (e.getMaterial().equals(Material.WATCH) && !e.getMaterial().equals(Material.AIR)) {
                    ItemStack watch = new ItemStack(Material.WATCH, 1);
                    if (e.getItem().equals(watch)) {
                        Inventory inv = Bukkit.createInventory(null, 4 * 9, "§6§lPlayer-Teleporter");
    
                        for (Player ps : Bukkit.getOnlinePlayers()) {
                            if (ps == e.getPlayer()) {
                                ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
                                SkullMeta meta = (SkullMeta) item.getItemMeta();
                                meta.setDisplayName("§r§l§o" + ps.getName());
                                meta.setOwner(ps.getName());
                                item.setItemMeta(meta);
                                inv.addItem(item);
                            }
                        }
                        e.getPlayer().openInventory(inv);
                    }
                }
            }
        }
    
        @EventHandler
        public void onClick(InventoryClickEvent e) {
            Player p = (Player) e.getWhoClicked();
    
            if (e.getInventory().getName().equalsIgnoreCase("§6§lPlayer-Teleporter")) {
                if (e.getSlot() == e.getRawSlot()) {
                    if (e.getCurrentItem() != null && e.getCurrentItem().hasItemMeta()) {
                        String pname = ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
                        Player pp = Bukkit.getPlayerExact(pname);
    
                        if (pp != null) {
                            p.teleport(pp);
                            p.sendMessage(Main.prefix + "§6Teleported to: §2" + pp.getName() + "§6!");
                        }
                    }
                }
            }
        }
    
    }
    
     
Thread Status:
Not open for further replies.

Share This Page