/*
 * Copyright  2014 - 2017 | Wurst-Imperium | All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package net.wurstclient.features.commands;

import net.minecraft.client.entity.EntityOtherPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketCreativeInventoryAction;
import net.wurstclient.compatibility.WConnection;
import net.wurstclient.compatibility.WMinecraft;
import net.wurstclient.utils.ChatUtils;

@Cmd.Info(
	description = "Allows you to copy items that other people are holding\n"
		+ "or wearing. Requires creative mode.",
	name = "copyitem",
	syntax = {"<player> (hand|head|chest|legs|feet)"},
	help = "Commands/copyitem")
public final class CopyItemCmd extends Cmd
{
	@Override
	public void execute(String[] args) throws CmdError
	{
		if(args.length != 2)
			syntaxError();
		if(!WMinecraft.getPlayer().capabilities.isCreativeMode)
			error("Creative mode only.");
		
		// find item
		ItemStack item = null;
		for(Object entity : WMinecraft.getWorld().loadedEntityList)
			if(entity instanceof EntityOtherPlayerMP)
			{
				EntityOtherPlayerMP player = (EntityOtherPlayerMP)entity;
				if(player.getName().equalsIgnoreCase(args[0]))
				{
					switch(args[1].toLowerCase())
					{
						case "hand":
						item = player.inventory.getCurrentItem();
						break;
						case "head":
						item = player.inventory.armorItemInSlot(3);
						break;
						case "chest":
						item = player.inventory.armorItemInSlot(2);
						break;
						case "legs":
						item = player.inventory.armorItemInSlot(1);
						break;
						case "feet":
						item = player.inventory.armorItemInSlot(0);
						break;
						default:
						syntaxError();
						break;
					}
					break;
				}
			}
		if(item == null)
			error("Player \"" + args[0] + "\" could not be found.");
		
		// copy item
		for(int i = 0; i < 9; i++)
			if(WMinecraft.getPlayer().inventory.getStackInSlot(i) == null)
			{
				WConnection.sendPacket(
					new CPacketCreativeInventoryAction(36 + i, item));
				ChatUtils.message("Item copied.");
				return;
			}
		error("Please clear a slot in your hotbar.");
	}
}

@@ -412,131 +412,8 @@
 ck;%0A
-import net.minecraft.network.play.client.CPacketCreativeInventoryAction;%0Aimport net.wurstclient.compatibility.WConnection;%0A
 impo
@@ -496,16 +496,61 @@
 atUtils;
+%0Aimport net.wurstclient.utils.InventoryUtils;
 %0A%0A@Cmd.I
@@ -1910,20 +1910,20 @@
 %09// 
-copy
+give
  item%0A%09%09
 for(
@@ -1922,191 +1922,52 @@
 m%0A%09%09
-for(int i = 0; i %3C 9; i++)%0A%09%09%09if(WMinecraft.getPlayer().inventory.getStackInSlot(i) == null)%0A%09%09%09%7B%0A%09%09%09%09WConnection.sendPacket(%0A%09%09%09%09%09new CPacketCreativeInventoryAction(36 + i, 
+if(InventoryUtils.placeStackInHotbar(
 item))
-;%0A%09
+%0A
 %09%09%09C
@@ -2006,23 +2006,14 @@
 ;%0A%09%09
-%09%09return;%0A%09%09%09%7D%0A
+else%0A%09
 %09%09er

Update CopyItemCmd