How to make inventory gui players online

Discussion in 'Spigot Plugin Development' started by CrystalDev, May 12, 2015.

  1. I have all code,
    i need function to add player head when player connect to server

    Help? Is ++?
     
  2. You have all the code but still need functions? Isn't that contradicting itself?
     
  3. I need only that function ...
     
  4. Not giving you the code but what you need

    • Listen to the join event
    • Add a skull to the GUI with the Owner of the player
    • ???
    • Profit
     
  5. Publish the code when I get to my house
     
    • Optimistic Optimistic x 1
  6. Code (Text):
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.SkullMeta;

    public class command implements CommandExecutor {
        private final Main plugin;
        Inventory inv = Bukkit.createInventory(null, 36, ChatColor.RED + "Menu");
             
        public command(Main plugin) {
            this.plugin = plugin;
        }
       @Override
       public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
          Player player = (Player)sender;
           if ((label.equalsIgnoreCase("menu")) &&
              ((sender instanceof Player)))
        {
          int i = 0;
          this.inv.clear();
          Player[] arrayOfPlayer;
          int j = (arrayOfPlayer = Bukkit.getOnlinePlayers()).length;
         // for (int i = 0; i < j; i++)
          {
            int ping = ((CraftPlayer)player).getHandle().ping;
            Player p = arrayOfPlayer[i];
            ItemStack is = new ItemStack(Material.SKULL_ITEM, 1, (short)3);
            SkullMeta im = (SkullMeta)is.getItemMeta();
            im.setOwner(p.getName());
            im.setDisplayName(p.getName() + " " + ping);
            is.setItemMeta(im);
            this.inv.setItem(i, is);
            if (i < this.inv.getSize()) {
              i++;
            }
          }
          ((Player)sender).openInventory(this.inv);
        }
        return false;
      }

      @EventHandler
      public void onInventoryClick(InventoryClickEvent e)
      {
        if (e.getInventory().getTitle().equalsIgnoreCase(this.inv.getName())) {
          e.setCancelled(true);
        }
        String s = ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName());
      }

    }