public void NBTJsonSerializerTests_DeserializeTest()
        {
            ListTag list = new ListTag("list", NBTTagType.INT);

            list.Add(new IntTag(12345));
            list.Add(new IntTag(67890));
            CompoundTag subTag = new CompoundTag();

            subTag.PutBool("bool", true);
            subTag.PutByte("byte", 123);
            CompoundTag tag = new CompoundTag();

            tag.PutBool("bool", true);
            tag.PutByte("byte", 123);
            tag.PutByteArray("byteArray", ArrayUtils.CreateArray <byte>(200));
            tag.PutShort("short", 12345);
            tag.PutInt("int", 12345678);
            tag.PutIntArray("intArray", ArrayUtils.CreateArray <int>(200));
            tag.PutLong("long", 123456789123456);
            tag.PutLongArray("longArray", ArrayUtils.CreateArray <long>(200));
            tag.PutFloat("float", 12.3456f);
            tag.PutDouble("double", 12.3456789);
            tag.PutList(list);
            tag.PutCompound("com", subTag);

            JObject json = NBTJsonSerializer.Serialize(tag);

            Console.WriteLine(NBTJsonSerializer.Serialize(NBTJsonSerializer.Deserialize(json)).ToString());
        }
Esempio n. 2
0
        public override bool Execute(CommandSender sender, params string[] args)
        {
            if (args.Length < 2)
            {
                sender.SendMessage("/give <target> <itemName/id> ...");
                return(false);
            }

            if (args[0] == "@e")
            {
                this.SendTargetNotPlayerMessage(sender);
                return(false);
            }

            Player[] players = this.GetPlayerFromSelector(args[0], sender);
            if (players == null)
            {
                this.SendNoTargetMessage(sender);
                return(false);
            }

            Item item = Item.Get(args[1]);

            if (args.Length > 2)
            {
                int count;
                int.TryParse(args[2], out count);
                if (count == 0)
                {
                    count = 1;
                }
                item.Count = count;
            }

            if (args.Length > 3)
            {
                int damage;
                int.TryParse(args[3], out damage);
                item.Damage = damage;
            }

            if (args.Length > 4)
            {
                string tag = args[4];
                try
                {
                    item.SetNamedTag(NBTJsonSerializer.Deserialize(JObject.Parse(tag)));
                }
                catch
                {
                    sender.SendMessage(new TranslationMessage(ColorText.RED, "commands.give.tagError", tag));
                    return(false);
                }
            }

            for (int i = 0; i < players.Length; ++i)
            {
                players[i].Inventory.AddItem(item.Clone());
                sender.SendMessage(new TranslationMessage("commands.give.successRecipient", item.Name, item.Count));
                Server.Instance.BroadcastMessageAndLoggerSend(new TranslationMessage("commands.give.success", item.Name, item.Count, players[i].Name));
            }

            return(true);
        }