// Path: src/main/java/cn/mccraft/chinacraft/util/Utils.java
// public final class Utils {
// 
//     private Utils(){}
// 
//     public static EntityPlayer getPlayerByUUID(UUID uuid) {
//         return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(uuid);
//     }
// 
//     public static EntityPlayer getPlayerByName(String name) {
//         return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(name);
//     }
// 
//     public static GameProfile getOfflinePlayerByName(String name) {
//        for(GameProfile player:FMLCommonHandler.instance().getMinecraftServerInstance().getServerStatusResponse().getPlayers().getPlayers())
//            if(player.getName().equalsIgnoreCase(name))
//                return player;
//        return null;
//     }
// 
//     public static GameProfile getOfflinePlayerByUUID(UUID uuid) {
//         for(GameProfile player:FMLCommonHandler.instance().getMinecraftServerInstance().getServerStatusResponse().getPlayers().getPlayers())
//             if(player.getId().equals(uuid))
//                 return player;
//         return null;
//     }
// }


import cn.mccraft.chinacraft.util.Utils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
        return sender;
    }

    public String getWish() {
        return wish;
    }

    public static class Handler implements IMessageHandler<RedPacketMessage, IMessage> {

        @Override
        public IMessage onMessage(RedPacketMessage message, MessageContext ctx) {
            EntityPlayer player = ctx.getServerHandler().player;
            ItemStack itemStack = player.inventory.getCurrentItem();

//          FIXME  if (itemStack == null || itemStack.getItem() != ChinaCraft.redPacket)return null;

            player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Blocks.AIR));

            itemStack = itemStack.copy();
            NBTTagCompound nbt = new NBTTagCompound();
            nbt.setTag("wish", new NBTTagString(message.getWish()));
            nbt.setTag("sender", new NBTTagString(message.getSender()));
            itemStack.setTagInfo("redpacket", nbt);

            String  receiver = message.getReceiver();
            if (!message.isSend() || receiver == null || receiver.isEmpty()) {
                player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack);
                return null;
            }

// Path: src/main/java/cn/mccraft/chinacraft/util/Utils.java
// public final class Utils {
// 
//     private Utils(){}
// 
//     public static EntityPlayer getPlayerByUUID(UUID uuid) {
//         return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(uuid);
//     }
// 
//     public static EntityPlayer getPlayerByName(String name) {
//         return FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(name);
//     }
// 
//     public static GameProfile getOfflinePlayerByName(String name) {
//        for(GameProfile player:FMLCommonHandler.instance().getMinecraftServerInstance().getServerStatusResponse().getPlayers().getPlayers())
//            if(player.getName().equalsIgnoreCase(name))
//                return player;
//        return null;
//     }
// 
//     public static GameProfile getOfflinePlayerByUUID(UUID uuid) {
//         for(GameProfile player:FMLCommonHandler.instance().getMinecraftServerInstance().getServerStatusResponse().getPlayers().getPlayers())
//             if(player.getId().equals(uuid))
//                 return player;
//         return null;
//     }
// }


// Path: src/main/java/cn/mccraft/chinacraft/network/RedPacketMessage.java
import cn.mccraft.chinacraft.util.Utils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

        return sender;
    }

    public String getWish() {
        return wish;
    }

    public static class Handler implements IMessageHandler<RedPacketMessage, IMessage> {

        @Override
        public IMessage onMessage(RedPacketMessage message, MessageContext ctx) {
            EntityPlayer player = ctx.getServerHandler().player;
            ItemStack itemStack = player.inventory.getCurrentItem();

//          FIXME  if (itemStack == null || itemStack.getItem() != ChinaCraft.redPacket)return null;

            player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(Blocks.AIR));

            itemStack = itemStack.copy();
            NBTTagCompound nbt = new NBTTagCompound();
            nbt.setTag("wish", new NBTTagString(message.getWish()));
            nbt.setTag("sender", new NBTTagString(message.getSender()));
            itemStack.setTagInfo("redpacket", nbt);

            String  receiver = message.getReceiver();
            if (!message.isSend() || receiver == null || receiver.isEmpty()) {
                player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack);
                return null;
            }

            EntityPlayer reciverPlayer = Utils.getPlayerByName(receiver);