Spectator Gui

Discussion in 'Plugin Development' started by RoBaMe, Jul 22, 2015.

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

    RoBaMe

    Hi! so I want to create a Spectator Gui, so when they die they can open a gui with all the players online and they can tp to them. so how do i do that? plz help
     
  2. Offline

    Proffesor_Diggi

  3. Offline

    RoBaMe

    @Proffesor_Diggi I Know how to make Gui's but I need to make a Gui with all the players that online, that is the part that i'm asking about.
     
  4. @RoBaMe
    Server#getOnlinePlayers() returns all the online players on the server.
     
  5. Offline

    poepdrolify

    Code:
    public Inventory SpectatorInv() {
            Inventory inv = Bukkit.createInventory(null, 36, "Spectators");
            for (Player online : Bukkit.getOnlinePlayers()) {
                ItemStack item = new ItemStack(Material.SKULL_ITEM, 1);
                SkullMeta meta = (SkullMeta) item.getItemMeta();
                meta.setOwner(online.getName());
                meta.setDisplayName(online.getName());
                meta.setLore(Arrays.asList("Click to teleport to player",
                        online.getName()));
                item.setItemMeta(meta);
                inv.addItem(item);
            }
            return inv;
    
        }
    
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onInventoryClick(InventoryClickEvent e) {
            if (!(e.getInventory().getTitle().equals("Spectators"))) {
                return;
            }
            e.setCancelled(true);
            e.getWhoClicked().teleport(
                    Bukkit.getPlayer(e.getCurrentItem().getItemMeta()
                            .getDisplayName()));
        }
    Something like this, but this creates a new inventory every time you call SpectatorInv, you can also create one inventory for everybody in onEnable and then update that every x seconds using a scheduler
     
Thread Status:
Not open for further replies.

Share This Page