Example #1
0
        public void Execute(IRocketPlayer caller, string[] command)
        {
            UnturnedPlayer player = (UnturnedPlayer)caller;

            if (command.Length == 0 || command.Length > 2)
            {
                UnturnedChat.Say(player, U.Translate("command_generic_invalid_parameter"));
                return;
            }

            ushort id     = 0;
            byte   amount = 1;

            string itemString = command[0].ToString();

            if (!ushort.TryParse(itemString, out id))
            {
                ItemAsset asset = UnturnedItems.GetItemAssetByName(itemString.ToLower());
                if (asset != null)
                {
                    id = asset.Id;
                }
                if (String.IsNullOrEmpty(itemString.Trim()) || id == 0)
                {
                    UnturnedChat.Say(player, U.Translate("command_generic_invalid_parameter"));
                    return;
                }
            }

            Asset a = SDG.Unturned.Assets.find(EAssetType.ITEM, id);

            if (command.Length == 2 && !byte.TryParse(command[1].ToString(), out amount) || a == null)
            {
                UnturnedChat.Say(player, U.Translate("command_generic_invalid_parameter"));
                return;
            }

            string assetName = ((ItemAsset)a).Name;

            if (!player.IsAdmin && player.HasPermission("i." + id))
            {
                UnturnedChat.Say(player, Plugin.Instance.Translate("text_block"));
                return;
            }
            if (player.GiveItem(id, amount))
            {
                Logger.Log(U.Translate("command_i_giving_console", player.DisplayName, id, amount));
                UnturnedChat.Say(player, U.Translate("command_i_giving_private", amount, assetName, id));
            }
            else
            {
                UnturnedChat.Say(player, U.Translate("command_i_giving_failed_private", amount, assetName, id));
            }
        }